Worked on mutli-account settings
This commit is contained in:
parent
0deafe6b08
commit
e05d583959
9 changed files with 209 additions and 36 deletions
|
@ -29,7 +29,9 @@ DISTFILES += qml/harbour-nextcloudnotes.qml \
|
|||
qml/pages/NotesPage.qml \
|
||||
qml/pages/LoginDialog.qml \
|
||||
qml/pages/EditPage.qml \
|
||||
qml/pages/SettingsPage.qml
|
||||
qml/pages/SettingsPage.qml \
|
||||
qml/pages/AboutPage.qml \
|
||||
qml/pages/MarkdownPage.qml
|
||||
|
||||
SAILFISHAPP_ICONS = 86x86 108x108 128x128 172x172
|
||||
|
||||
|
|
|
@ -10,28 +10,39 @@ ApplicationWindow
|
|||
ConfigurationGroup {
|
||||
id: appSettings
|
||||
path: "/apps/harbour-nextcloudnotes/settings"
|
||||
property var accounts: value("accounts", [])
|
||||
property int currentAccount: 0
|
||||
property var accounts: [ ] // FIXME
|
||||
property int currentAccount: 0 // FIXME
|
||||
// For testing
|
||||
Component.onCompleted: {
|
||||
//appSettings.clear()
|
||||
appSettings.clear()
|
||||
//accounts[0] = { server: "127.0.0.1", username: "fu", password: "bar", lastUpdate: new Date(0) }
|
||||
//accounts[1] = { server: "127.0.0.2", username: "fu", password: "bar", lastUpdate: new Date(0) }
|
||||
//accounts[2] = { server: "127.0.0.3", username: "fu", password: "bar", lastUpdate: new Date(0) }
|
||||
console.log("Configured accounts: " + accounts.length)
|
||||
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)
|
||||
console.log("Account " + i + (i === currentAccount ? " (active):" : ":"))
|
||||
console.log("- Server: " + accounts[i].server)
|
||||
console.log("- Username: " + accounts[i].username)
|
||||
console.log("- Password: " + accounts[i].password)
|
||||
}
|
||||
if (typeof(accounts[currentAccount]) !== 'undefined') {
|
||||
notes.account = appSettings.accounts[appSettings.currentAccount]
|
||||
}
|
||||
else {
|
||||
currentAccount = 0
|
||||
notes.account = appSettings.accounts[0]
|
||||
}
|
||||
//notes.account = appSettings.accounts[appSettings.currentAccount]
|
||||
}
|
||||
}
|
||||
|
||||
property var notes: NotesApi {
|
||||
name: "notes"
|
||||
account: appSettings.accounts[appSettings.currentAccount]
|
||||
//account: appSettings.accounts[appSettings.currentAccount]
|
||||
saveFile: false
|
||||
}
|
||||
Connections {
|
||||
target: notes
|
||||
onLastUpdateChanged: appSettings.lastUpdate = notes.lastUpdate
|
||||
//onLastUpdateChanged: appSettings.lastUpdate = notes.lastUpdate
|
||||
}
|
||||
|
||||
initialPage: Component { NotesPage { } }
|
||||
|
|
30
qml/pages/AboutPage.qml
Normal file
30
qml/pages/AboutPage.qml
Normal file
|
@ -0,0 +1,30 @@
|
|||
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("About")
|
||||
}
|
||||
}
|
||||
|
||||
VerticalScrollDecorator {}
|
||||
}
|
||||
|
||||
ViewPlaceholder {
|
||||
enabled: true // TODO
|
||||
text: qsTr("Nextcloud Notes")
|
||||
hintText: qsTr("for Sailfish OS")
|
||||
}
|
||||
}
|
|
@ -11,6 +11,13 @@ Page {
|
|||
anchors.fill: parent
|
||||
contentHeight: column.height
|
||||
|
||||
PullDownMenu {
|
||||
MenuItem {
|
||||
text: qsTr("Markdown Cheatsheet")
|
||||
onClicked: pageStack.push(Qt.resolvedUrl("MarkDownPage.qml"))
|
||||
}
|
||||
}
|
||||
|
||||
Column {
|
||||
id: column
|
||||
width: parent.width// - 2*x
|
||||
|
|
30
qml/pages/MarkdownPage.qml
Normal file
30
qml/pages/MarkdownPage.qml
Normal file
|
@ -0,0 +1,30 @@
|
|||
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("Markdown Cheatsheet")
|
||||
}
|
||||
}
|
||||
|
||||
VerticalScrollDecorator {}
|
||||
}
|
||||
|
||||
ViewPlaceholder {
|
||||
enabled: true // TODO
|
||||
text: qsTr("Markdown Cheatsheet")
|
||||
hintText: qsTr("https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet")
|
||||
}
|
||||
}
|
|
@ -10,7 +10,7 @@ Item {
|
|||
property string file: StandardPaths.data + "/" + name + ".json"
|
||||
property bool saveFile: false
|
||||
property bool busy: false
|
||||
property date lastUpdate: new Date(0)
|
||||
//property date lastUpdate: new Date(0)
|
||||
|
||||
function callApi(method, data) {
|
||||
busy = true
|
||||
|
@ -36,7 +36,7 @@ Item {
|
|||
for (var element in elements) {
|
||||
model.append(elements[element])
|
||||
}
|
||||
}
|
||||
}/*
|
||||
else if (apiReq.status === 304) {
|
||||
console.log("ETag does not differ!")
|
||||
}
|
||||
|
@ -45,9 +45,9 @@ Item {
|
|||
}
|
||||
else if (apiReq.status === 404) {
|
||||
console.log("Note does not exist!")
|
||||
}
|
||||
}*/
|
||||
else {
|
||||
console.log("Unknown error: " + apiReq.statusText + " (" + apiReq.status + ")")
|
||||
console.log("Networking error: " + apiReq.statusText + " (" + apiReq.status + ")")
|
||||
}
|
||||
busy = false
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ Item {
|
|||
filePut.open("PUT", file)
|
||||
filePut.send(json)
|
||||
model.clear()
|
||||
lastUpdate = new Date(0)
|
||||
account.lastUpdate = new Date(0)
|
||||
status = 200
|
||||
}
|
||||
|
||||
|
|
|
@ -13,12 +13,16 @@ Page {
|
|||
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) : ""
|
||||
visible: appSettings.accounts.length > 0
|
||||
text: appSettings.accounts.length > 0 ?
|
||||
(qsTr("Last update") + ": " +
|
||||
(appSettings.accounts[appSettings.currentAccount].lastUpdate.value === 0 ?
|
||||
appSettings.accounts[appSettings.currentAccount].lastUpdate.toLocaleString(Qt.locale(), Locale.ShortFormat) :
|
||||
qsTr("never"))) : ""
|
||||
}
|
||||
MenuItem {
|
||||
text: qsTr("Reload")
|
||||
visible: typeof(appSettings.accounts[appSettings.currentAccount]) !== 'undefined'
|
||||
visible: appSettings.accounts.length > 0
|
||||
onClicked: notes.getNotes()
|
||||
}
|
||||
MenuItem {
|
||||
|
@ -27,7 +31,7 @@ Page {
|
|||
}
|
||||
MenuItem {
|
||||
text: qsTr("Add note")
|
||||
enabled: typeof(appSettings.accounts[appSettings.currentAccount]) !== 'undefined'
|
||||
enabled: appSettings.accounts.length > 0
|
||||
onClicked: console.log("Add note")
|
||||
}
|
||||
}
|
||||
|
@ -160,7 +164,7 @@ Page {
|
|||
}
|
||||
InteractionHintLabel {
|
||||
anchors.fill: parent
|
||||
text: qsTr("Open the settings to add a new Nextcloud account")
|
||||
text: qsTr("Open the settings to add a Nextcloud account")
|
||||
opacity: addAccountHint.running ? 1.0 : 0.0
|
||||
Behavior on opacity { FadeAnimation {} }
|
||||
width: parent.width
|
||||
|
|
|
@ -9,6 +9,13 @@ Page {
|
|||
anchors.fill: parent
|
||||
contentHeight: column.height
|
||||
|
||||
PullDownMenu {
|
||||
MenuItem {
|
||||
text: qsTr("About")
|
||||
onClicked: pageStack.push(Qt.resolvedUrl("AboutPage.qml"))
|
||||
}
|
||||
}
|
||||
|
||||
Column {
|
||||
id: column
|
||||
width: parent.width
|
||||
|
@ -23,20 +30,28 @@ Page {
|
|||
}
|
||||
Label {
|
||||
id: noAccountsLabel
|
||||
visible: typeof(appSettings.accounts) !== 'undefined'
|
||||
visible: appSettings.accounts.length === 0
|
||||
text: qsTr("No Nextcloud account yet")
|
||||
font.pixelSize: Theme.fontSizeExtraLarge
|
||||
font.pixelSize: Theme.fontSizeLarge
|
||||
color: Theme.secondaryHighlightColor
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
}
|
||||
Repeater {
|
||||
model: appSettings.accounts
|
||||
delegate: BackgroundItem {
|
||||
Label {
|
||||
delegate: ListItem {
|
||||
id: listItem
|
||||
TextSwitch {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
automaticCheck: false
|
||||
checked: index === appSettings.currentAccount
|
||||
text: appSettings.accounts[index].username + "@" + appSettings.accounts[index].server
|
||||
x: Theme.horizontalPageMargin
|
||||
width: parent.width - 2*x
|
||||
description: checked ? qsTr("Press and hold to edit") : qsTr("Click to choose as active account")
|
||||
onClicked: appSettings.currentAccount = index
|
||||
onPressAndHold: listItem.openMenu()
|
||||
}
|
||||
menu: ContextMenu {
|
||||
MenuItem {
|
||||
text: qsTr("Edit")
|
||||
onClicked: {
|
||||
var login = pageStack.push(Qt.resolvedUrl("LoginDialog.qml"), { account: appSettings.accounts[index] } )
|
||||
login.accepted.connect(function() {
|
||||
|
@ -45,21 +60,34 @@ Page {
|
|||
})
|
||||
}
|
||||
}
|
||||
MenuItem {
|
||||
text: qsTr("Delete")
|
||||
visible: false // TODO
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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())
|
||||
var list = appSettings.accounts
|
||||
list.push(login.account)
|
||||
appSettings.accounts = list
|
||||
appSettings.sync()
|
||||
appSettings.currentAccount = appSettings.accounts.length
|
||||
appSettings.accounts[appSettings.currentAccount] = login.account
|
||||
appSettings.sync()
|
||||
notes.account = appSettings.accounts[appSettings.currentAccount]
|
||||
notes.getNotes()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
SectionHeader {
|
||||
text: qsTr("Security")
|
||||
}
|
||||
}
|
||||
|
||||
VerticalScrollDecorator {}
|
||||
|
|
|
@ -1,6 +1,21 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE TS>
|
||||
<TS version="2.1">
|
||||
<context>
|
||||
<name>AboutPage</name>
|
||||
<message>
|
||||
<source>About</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Nextcloud Notes</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>for Sailfish OS</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>CoverPage</name>
|
||||
<message>
|
||||
|
@ -8,6 +23,13 @@
|
|||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>EditPage</name>
|
||||
<message>
|
||||
<source>Markdown Cheatsheet</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>LoginDialog</name>
|
||||
<message>
|
||||
|
@ -27,6 +49,17 @@
|
|||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>MarkdownPage</name>
|
||||
<message>
|
||||
<source>Markdown Cheatsheet</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>NotePage</name>
|
||||
<message>
|
||||
|
@ -77,7 +110,11 @@
|
|||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Open the settings to add a new Nextcloud account</source>
|
||||
<source>never</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Open the settings to add a Nextcloud account</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
|
@ -99,5 +136,29 @@
|
|||
<source>No Nextcloud account yet</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>About</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Press and hold to edit</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Click to choose as active account</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Edit</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Delete</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Security</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
||||
|
|
Loading…
Reference in a new issue