Worked on login handling. Still in early development.
This commit is contained in:
parent
6262b35302
commit
0deafe6b08
7 changed files with 144 additions and 53 deletions
|
@ -28,7 +28,8 @@ DISTFILES += qml/harbour-nextcloudnotes.qml \
|
|||
qml/pages/NotePage.qml \
|
||||
qml/pages/NotesPage.qml \
|
||||
qml/pages/LoginDialog.qml \
|
||||
qml/pages/EditPage.qml
|
||||
qml/pages/EditPage.qml \
|
||||
qml/pages/SettingsPage.qml
|
||||
|
||||
SAILFISHAPP_ICONS = 86x86 108x108 128x128 172x172
|
||||
|
||||
|
|
|
@ -10,24 +10,23 @@ ApplicationWindow
|
|||
ConfigurationGroup {
|
||||
id: appSettings
|
||||
path: "/apps/harbour-nextcloudnotes/settings"
|
||||
property string lastUpdate: qsTr("never")
|
||||
property url server: ""
|
||||
property string username: ""
|
||||
property string password: ""
|
||||
property bool unsecureConnection: false
|
||||
property var accounts: value("accounts", [])
|
||||
property int currentAccount: 0
|
||||
// For testing
|
||||
Component.onCompleted: {
|
||||
//server = ""
|
||||
//username = ""
|
||||
//password = ""
|
||||
console.log("Server: " + server)
|
||||
console.log("Username: " + username)
|
||||
console.log("Password: " + password)
|
||||
//appSettings.clear()
|
||||
for(var i=0; i<accounts.length; i++) {
|
||||
console.log("Server: " + accounts[i].server)
|
||||
console.log("Username: " + accounts[i].username)
|
||||
console.log("Password: " + accounts[i].password)
|
||||
}
|
||||
//notes.account = appSettings.accounts[appSettings.currentAccount]
|
||||
}
|
||||
}
|
||||
|
||||
property var notes: NotesApi {
|
||||
name: "notes"
|
||||
account: appSettings.accounts[appSettings.currentAccount]
|
||||
saveFile: false
|
||||
}
|
||||
Connections {
|
||||
|
|
|
@ -4,15 +4,16 @@ import Sailfish.Silica 1.0
|
|||
Dialog {
|
||||
id: loginDialog
|
||||
|
||||
property url server
|
||||
property string username
|
||||
property string password
|
||||
property var account
|
||||
|
||||
canAccept: (serverField.acceptableInput && usernameField.text.length > 0 && passwordField.text.length > 0)
|
||||
onAccepted: {
|
||||
server = serverField.text
|
||||
username = usernameField.text
|
||||
password = passwordField.text
|
||||
account = {
|
||||
server: serverField.text,
|
||||
username: usernameField.text,
|
||||
password: passwordField.text,
|
||||
lastUpdate: new Date(0)
|
||||
}
|
||||
}
|
||||
|
||||
Column {
|
||||
|
@ -35,7 +36,7 @@ Dialog {
|
|||
id: serverField
|
||||
focus: true
|
||||
width: parent.width
|
||||
text: (server.toString().length > 0) ? server : "https://"
|
||||
text: (typeof(account) !== 'undefined' && account.server.toString().length > 0) ? account.server : "https://"
|
||||
placeholderText: qsTr("Nextcloud server")
|
||||
label: placeholderText + " " + qsTr("(starting with \"https://\")")
|
||||
inputMethodHints: Qt.ImhUrlCharactersOnly
|
||||
|
@ -49,7 +50,7 @@ Dialog {
|
|||
TextField {
|
||||
id: usernameField
|
||||
width: parent.width
|
||||
text: (username.length > 0) ? username : ""
|
||||
text: (typeof(account) !== 'undefined' && account.username.length > 0) ? account.username : ""
|
||||
placeholderText: qsTr("Username")
|
||||
label: placeholderText
|
||||
inputMethodHints: Qt.ImhNoPredictiveText | Qt.ImhNoAutoUppercase
|
||||
|
@ -62,7 +63,7 @@ Dialog {
|
|||
PasswordField {
|
||||
id: passwordField
|
||||
width: parent.width
|
||||
text: (password.length > 0) ? password : ""
|
||||
text: (typeof(account) !== 'undefined' && account.password.length > 0) ? account.password : ""
|
||||
label: placeholderText
|
||||
errorHighlight: text.length === 0 && focus === true
|
||||
EnterKey.enabled: text.length > 0
|
||||
|
|
|
@ -3,6 +3,7 @@ import Sailfish.Silica 1.0
|
|||
|
||||
Item {
|
||||
property string name
|
||||
property var account
|
||||
property var model: ListModel { }
|
||||
|
||||
property string json
|
||||
|
@ -14,7 +15,7 @@ Item {
|
|||
function callApi(method, data) {
|
||||
busy = true
|
||||
|
||||
var endpoint = appSettings.server + "/index.php/apps/notes/api/v0.2/notes"
|
||||
var endpoint = account.server + "/index.php/apps/notes/api/v0.2/notes"
|
||||
if (data && (method === "GET" || method === "PUT" || method === "DELETE"))
|
||||
if (data.id)
|
||||
endpoint = endpoint + "/" + data.id
|
||||
|
@ -24,7 +25,7 @@ Item {
|
|||
apiReq.setRequestHeader('User-Agent', 'SailfishOS/harbour-nextcloudnotes')
|
||||
apiReq.setRequestHeader('OCS-APIRequest', 'true')
|
||||
apiReq.setRequestHeader("Content-Type", "application/json")
|
||||
apiReq.setRequestHeader("Authorization", "Basic " + Qt.btoa(appSettings.username + ":" + appSettings.password))
|
||||
apiReq.setRequestHeader("Authorization", "Basic " + Qt.btoa(account.username + ":" + account.password))
|
||||
apiReq.onreadystatechange = function() {
|
||||
if (apiReq.readyState === XMLHttpRequest.DONE) {
|
||||
if (apiReq.status === 200) {
|
||||
|
|
|
@ -11,30 +11,25 @@ Page {
|
|||
|
||||
PullDownMenu {
|
||||
busy: notes.busy
|
||||
|
||||
MenuLabel {
|
||||
visible: typeof(appSettings.accounts[appSettings.currentAccount]) !== 'undefined'
|
||||
text: visible ? qsTr("Last update") + ": " + new Date(appSettings.accounts[appSettings.currentAccount].lastUpdate).toLocaleString(Qt.locale(), Locale.ShortFormat) : ""
|
||||
}
|
||||
MenuItem {
|
||||
text: qsTr("Reload")
|
||||
visible: typeof(appSettings.accounts[appSettings.currentAccount]) !== 'undefined'
|
||||
onClicked: notes.getNotes()
|
||||
}
|
||||
MenuItem {
|
||||
text: qsTr("Settings")
|
||||
onClicked: {
|
||||
var login = pageStack.push(Qt.resolvedUrl("LoginDialog.qml"), { server: appSettings.server, username: appSettings.username, password: appSettings.password } )
|
||||
login.accepted.connect(function() {
|
||||
console.log(login.username + ":" + login.password + "@" + login.server)
|
||||
appSettings.server = login.server
|
||||
appSettings.username = login.username
|
||||
appSettings.password = login.password
|
||||
notes.getNotes()
|
||||
})
|
||||
}
|
||||
onClicked: pageStack.push(Qt.resolvedUrl("SettingsPage.qml"))
|
||||
}
|
||||
MenuItem {
|
||||
text: qsTr("Add note")
|
||||
enabled: typeof(appSettings.accounts[appSettings.currentAccount]) !== 'undefined'
|
||||
onClicked: console.log("Add note")
|
||||
}
|
||||
MenuItem {
|
||||
text: qsTr("Update")
|
||||
onClicked: notes.getNotes()
|
||||
}
|
||||
MenuLabel {
|
||||
text: qsTr("Last update") + ": " + new Date(appSettings.lastUpdate).toLocaleString(Qt.locale(), Locale.ShortFormat)
|
||||
}
|
||||
}
|
||||
|
||||
header: SearchField {
|
||||
|
@ -49,8 +44,9 @@ Page {
|
|||
|
||||
currentIndex: -1
|
||||
Component.onCompleted: {
|
||||
if (appSettings.server.toString().length > 0 && appSettings.username.length > 0 && appSettings.password.length > 0)
|
||||
if (appSettings.accounts.length > 0) {
|
||||
notes.getNotes()
|
||||
}
|
||||
}
|
||||
|
||||
//Component.onCompleted: notes.getNotes()
|
||||
|
@ -141,19 +137,33 @@ Page {
|
|||
running: visible
|
||||
}
|
||||
|
||||
ViewPlaceholder {
|
||||
id: noLoginPlaceholder
|
||||
enabled: (appSettings.accounts.length === 0)
|
||||
text: qsTr("No accounts yet")
|
||||
}
|
||||
|
||||
ViewPlaceholder {
|
||||
enabled: notesList.count === 0 && !notes.busy && !noLoginPlaceholder.enabled
|
||||
text: qsTr("No notes yet")
|
||||
hintText: qsTr("Pull down to add a note")
|
||||
}
|
||||
|
||||
ViewPlaceholder {
|
||||
id: noLoginPlaceholder
|
||||
enabled: (appSettings.server.length === 0 || appSettings.username.length === 0 || appSettings.password.length === 0)
|
||||
text: qsTr("No Nextcloud account")
|
||||
hintText: qsTr("Pull down to go to the settings")
|
||||
}
|
||||
|
||||
VerticalScrollDecorator { flickable: notesList }
|
||||
}
|
||||
|
||||
TouchInteractionHint {
|
||||
id: addAccountHint
|
||||
Component.onCompleted: if (appSettings.accounts.length === 0) restart()
|
||||
interactionMode: TouchInteraction.Pull
|
||||
direction: TouchInteraction.Down
|
||||
}
|
||||
InteractionHintLabel {
|
||||
anchors.fill: parent
|
||||
text: qsTr("Open the settings to add a new Nextcloud account")
|
||||
opacity: addAccountHint.running ? 1.0 : 0.0
|
||||
Behavior on opacity { FadeAnimation {} }
|
||||
width: parent.width
|
||||
}
|
||||
|
||||
}
|
||||
|
|
67
qml/pages/SettingsPage.qml
Normal file
67
qml/pages/SettingsPage.qml
Normal file
|
@ -0,0 +1,67 @@
|
|||
import QtQuick 2.0
|
||||
import Sailfish.Silica 1.0
|
||||
|
||||
Page {
|
||||
id: page
|
||||
|
||||
SilicaFlickable {
|
||||
id: flickable
|
||||
anchors.fill: parent
|
||||
contentHeight: column.height
|
||||
|
||||
Column {
|
||||
id: column
|
||||
width: parent.width
|
||||
spacing: Theme.paddingMedium
|
||||
|
||||
PageHeader {
|
||||
title: qsTr("Settings")
|
||||
}
|
||||
|
||||
SectionHeader {
|
||||
text: qsTr("Accounts")
|
||||
}
|
||||
Label {
|
||||
id: noAccountsLabel
|
||||
visible: typeof(appSettings.accounts) !== 'undefined'
|
||||
text: qsTr("No Nextcloud account yet")
|
||||
font.pixelSize: Theme.fontSizeExtraLarge
|
||||
color: Theme.secondaryHighlightColor
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
}
|
||||
Repeater {
|
||||
model: appSettings.accounts
|
||||
delegate: BackgroundItem {
|
||||
Label {
|
||||
text: appSettings.accounts[index].username + "@" + appSettings.accounts[index].server
|
||||
x: Theme.horizontalPageMargin
|
||||
width: parent.width - 2*x
|
||||
}
|
||||
onClicked: {
|
||||
var login = pageStack.push(Qt.resolvedUrl("LoginDialog.qml"), { account: appSettings.accounts[index] } )
|
||||
login.accepted.connect(function() {
|
||||
console.log(login.account.username + ":" + login.account.password + "@" + login.account.server.toString())
|
||||
appSettings.accounts[index] = login.account
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
text: qsTr("Add account")
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
onClicked: {
|
||||
var login = pageStack.push(Qt.resolvedUrl("LoginDialog.qml"))
|
||||
login.accepted.connect(function() {
|
||||
console.log(login.account.username + ":" + login.account.password + "@" + login.account.server.toString())
|
||||
appSettings.currentAccount = appSettings.accounts.length
|
||||
appSettings.accounts[appSettings.currentAccount] = login.account
|
||||
notes.getNotes()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
VerticalScrollDecorator {}
|
||||
}
|
||||
}
|
|
@ -69,22 +69,34 @@
|
|||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Update</source>
|
||||
<source>Reload</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>No Nextcloud account</source>
|
||||
<source>No accounts yet</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Pull down to go to the settings</source>
|
||||
<source>Open the settings to add a new Nextcloud account</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>harbour-nextcloudnotes</name>
|
||||
<name>SettingsPage</name>
|
||||
<message>
|
||||
<source>never</source>
|
||||
<source>Settings</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Accounts</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Add account</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>No Nextcloud account yet</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
|
|
Loading…
Reference in a new issue