diff --git a/harbour-nextcloudnotes.pro b/harbour-nextcloudnotes.pro index 1f6989a..8a2aed0 100644 --- a/harbour-nextcloudnotes.pro +++ b/harbour-nextcloudnotes.pro @@ -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 diff --git a/qml/harbour-nextcloudnotes.qml b/qml/harbour-nextcloudnotes.qml index 9b0db9f..62197e6 100644 --- a/qml/harbour-nextcloudnotes.qml +++ b/qml/harbour-nextcloudnotes.qml @@ -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 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 diff --git a/qml/pages/NotesApi.qml b/qml/pages/NotesApi.qml index df475cd..155bffa 100644 --- a/qml/pages/NotesApi.qml +++ b/qml/pages/NotesApi.qml @@ -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) { diff --git a/qml/pages/NotesPage.qml b/qml/pages/NotesPage.qml index 7b4e349..460b893 100644 --- a/qml/pages/NotesPage.qml +++ b/qml/pages/NotesPage.qml @@ -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 + } + } diff --git a/qml/pages/SettingsPage.qml b/qml/pages/SettingsPage.qml new file mode 100644 index 0000000..3fbb903 --- /dev/null +++ b/qml/pages/SettingsPage.qml @@ -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 {} + } +} diff --git a/translations/harbour-nextcloudnotes.ts b/translations/harbour-nextcloudnotes.ts index 9dd5d46..cd18006 100644 --- a/translations/harbour-nextcloudnotes.ts +++ b/translations/harbour-nextcloudnotes.ts @@ -69,22 +69,34 @@ - Update + Reload - No Nextcloud account + No accounts yet - Pull down to go to the settings + Open the settings to add a new Nextcloud account - harbour-nextcloudnotes + SettingsPage - never + Settings + + + + Accounts + + + + Add account + + + + No Nextcloud account yet