Improved account handling.

This commit is contained in:
Scharel Clemens 2018-12-07 00:30:18 +01:00
parent 32f3fe3479
commit f9ee0021ef
12 changed files with 399 additions and 264 deletions

View file

@ -12,12 +12,12 @@ CoverBackground {
CoverActionList { CoverActionList {
id: coverAction id: coverAction
enabled: appSettings.currentAccount >= 0 enabled: appSettings.currentAccount.length > 0
CoverAction { CoverAction {
iconSource: "image://theme/icon-cover-new" iconSource: "image://theme/icon-cover-new"
onTriggered: { onTriggered: {
nextcloudAccounts.itemAt(appSettings.currentAccount).createNote({'content': ""}) api.createNote({'content': ""})
appWindow.activate() appWindow.activate()
} }
} }

View file

@ -7,21 +7,90 @@ ApplicationWindow
{ {
id: appWindow id: appWindow
ConfigurationValue {
id: accounts
key: appSettings.path + "/accountIDs"
defaultValue: [ ]
}
ConfigurationGroup { ConfigurationGroup {
id: appSettings id: appSettings
path: "/apps/harbour-nextcloudnotes/settings" path: "/apps/harbour-nextcloudnotes/settings"
//synchronous: true //synchronous: true
property int currentAccount: value("currentAccount", -1) property string currentAccount: value("currentAccount", "")
property var accountIDs: value("accountIDs", [ ])
property int autoSyncInterval: value("autoSyncInterval", 0) property int autoSyncInterval: value("autoSyncInterval", 0)
property int previewLineCount: value("previewLineCount", 4) property int previewLineCount: value("previewLineCount", 4)
property string sortBy: value("sortBy", "date") property string sortBy: value("sortBy", "date")
property bool showSeparator: value("showSeparator", false) property bool showSeparator: value("showSeparator", false)
property bool useMonoFont: value("useMonoFont", false) property bool useMonoFont: value("useMonoFont", false)
property bool useCapitalX: value("useCapitalX", false) property bool useCapitalX: value("useCapitalX", false)
onCurrentAccountChanged: api.uuid = currentAccount
function addAccount() {
var uuid = uuidv4()
var tmpIDs = accounts.value
tmpIDs.push(uuid)
accounts.value = tmpIDs
accounts.sync()
return uuid
}
function removeAccount(uuid) {
autoSyncTimer.stop()
var tmpAccouunt = currentAccount
currentAccount = uuid
api.clear()
currentAccount = tmpAccouunt
var newIds = [ ]
accountIDs.forEach(function(currentValue) {
if (currentValue !== uuid) {
newIds.push(currentValue)
}
})
accounts.value = newIds
for (var i = accountIDs.length-1; i > 0; i--) {
if (accountIDs[i] !== uuid) {
api.uuid = accountIDs[i]
break
}
}
autoSyncTimer.start()
}
function uuidv4() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
} }
ConfigurationValue { Timer {
id: autoSyncTimer
interval: appSettings.autoSyncInterval * 1000
repeat: true
running: interval > 0 && appWindow.visible
triggeredOnStart: true
onTriggered: {
if (!api.busy) {
api.getNotes()
}
else {
triggeredOnStart = false
restart()
triggeredOnStart = true
}
}
onIntervalChanged: console.log("Auto-Sync every " + interval / 1000 + " seconds")
}
NotesApi {
id: api
uuid: appSettings.currentAccount
}
/*ConfigurationValue {
id: nextcloudUUIDs id: nextcloudUUIDs
key: "/apps/harbour-nextcloudnotes/settings/accountIDs" key: "/apps/harbour-nextcloudnotes/settings/accountIDs"
defaultValue: [] defaultValue: []
@ -53,6 +122,8 @@ ApplicationWindow
} }
}) })
nextcloudUUIDs.value = newIds nextcloudUUIDs.value = newIds
if (nextcloudUUIDs.value[appSettings.currentAccount] === uuid)
appSettings.currentAccount = nextcloudUUIDs.value.length-1
} }
function push(uuid) { function push(uuid) {
var accountIDs = nextcloudUUIDs.value var accountIDs = nextcloudUUIDs.value
@ -64,14 +135,7 @@ ApplicationWindow
accountIDs.pop() accountIDs.pop()
nextcloudUUIDs.value = accountIDs nextcloudUUIDs.value = accountIDs
} }
} }*/
function uuidv4() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
initialPage: Component { NotesPage { } } initialPage: Component { NotesPage { } }
cover: Qt.resolvedUrl("cover/CoverPage.qml") cover: Qt.resolvedUrl("cover/CoverPage.qml")

View file

@ -5,31 +5,29 @@ import Nemo.Notifications 1.0
Dialog { Dialog {
id: page id: page
property var account
property var note property var note
onAccepted: { onAccepted: {
account.updateNote(note.id, { 'category': categoryField.text, 'content': contentArea.text, 'favorite': favoriteButton.selected } ) api.updateNote(note.id, { 'category': categoryField.text, 'content': contentArea.text, 'favorite': favoriteButton.selected } )
} }
onStatusChanged: { onStatusChanged: {
if (status === PageStatus.Active) { if (status === PageStatus.Active) {
note = account.getNote(note.id, false) //note = api.getNote(note.id, false)
favoriteButton.selected = note.favorite favoriteButton.selected = note.favorite
categoryRepeater.model = account.categories categoryRepeater.model = api.categories
} }
} }
SilicaFlickable { SilicaFlickable {
id: flickable
anchors.fill: parent anchors.fill: parent
contentHeight: column.height contentHeight: mainColumn.height
PullDownMenu { PullDownMenu {
MenuItem { MenuItem {
text: qsTr("Reset") text: qsTr("Reset")
onClicked: { onClicked: {
note = account.getNote(note.id, false) note = api.getNote(note.id, false)
favoriteButton.selected = note.favorite favoriteButton.selected = note.favorite
} }
} }
@ -40,11 +38,21 @@ Dialog {
} }
Column { Column {
id: column id: mainColumn
width: parent.width// - 2*x width: parent.width
DialogHeader { DialogHeader {
//title: account.model.get(noteIndex).title title: note.title
}
Column {
width: parent.width
spacing: Theme.paddingLarge
Separator {
width: parent.width
color: Theme.primaryColor
horizontalAlignment: Qt.AlignHCenter
} }
TextArea { TextArea {
@ -83,6 +91,7 @@ Dialog {
preTextLength = text.length preTextLength = text.length
} }
} }
}
Flow { Flow {
x: Theme.horizontalPageMargin x: Theme.horizontalPageMargin
@ -94,7 +103,7 @@ Dialog {
Repeater { Repeater {
id: categoryRepeater id: categoryRepeater
model: account.categories model: api.categories
BackgroundItem { BackgroundItem {
id: categoryBackground id: categoryBackground
width: categoryRectangle.width width: categoryRectangle.width
@ -127,7 +136,9 @@ Dialog {
width: Theme.iconSizeMedium width: Theme.iconSizeMedium
icon.source: (selected ? "image://theme/icon-m-favorite-selected?" : "image://theme/icon-m-favorite?") + icon.source: (selected ? "image://theme/icon-m-favorite-selected?" : "image://theme/icon-m-favorite?") +
(favoriteButton.highlighted ? Theme.secondaryHighlightColor : Theme.secondaryColor) (favoriteButton.highlighted ? Theme.secondaryHighlightColor : Theme.secondaryColor)
onClicked: selected = !selected onClicked: {
api.updateNote(note.id, {'favorite': !note.favorite})
}
} }
TextField { TextField {
id: categoryField id: categoryField
@ -135,7 +146,22 @@ Dialog {
text: note.category text: note.category
placeholderText: qsTr("No category") placeholderText: qsTr("No category")
label: qsTr("Category") label: qsTr("Category")
EnterKey.iconSource: "image://theme/icon-m-enter-accept"
EnterKey.onClicked: {
categoryField.focus = false
} }
onFocusChanged: {
if (focus === false && text !== note.category) {
api.updateNote(note.id, {'content': note.content, 'category': text}) // This does not seem to work without adding the content
}
}
}
}
DetailItem {
id: modifiedDetail
label: qsTr("Modified")
value: new Date(note.modified * 1000).toLocaleString(Qt.locale(), Locale.ShortFormat)
} }
} }

View file

@ -5,16 +5,34 @@ import Nemo.Configuration 1.0
Dialog { Dialog {
id: loginDialog id: loginDialog
property int account property string accountId
ConfigurationGroup {
id: account
path: "/apps/harbour-nextcloudnotes/accounts/" + accountId
Component.onCompleted: {
nameField.text = value("name", "", String)
serverField.text = value("server", "https://", String)
usernameField.text = value("username", "", String)
passwordField.text = value("password", "", String)
}
}
canAccept: (nameField.text.length > 0 && serverField.acceptableInput && usernameField.text.length > 0 && passwordField.text.length > 0) canAccept: (nameField.text.length > 0 && serverField.acceptableInput && usernameField.text.length > 0 && passwordField.text.length > 0)
onDone: {
account.setValue("name", nameField.text)
account.setValue("server", serverField.text)
account.setValue("username", usernameField.text)
account.setValue("password", passwordField.text)
//account.setValue("unsecureConnection", unsecureConnectionTextSwitch.checked)
//account.setValue("unencryptedConnection", unencryptedConnectionTextSwitch.checked)
account.sync()
}
onAccepted: { onAccepted: {
nextcloudAccounts.itemAt(account).name = nameField.text api.uuid = accountId
nextcloudAccounts.itemAt(account).server = serverField.text }
nextcloudAccounts.itemAt(account).username = usernameField.text onRejected: {
nextcloudAccounts.itemAt(account).password = passwordField.text appSettings.removeAccount(accountId)
//dnextcloudAccounts.itemAt(account).unsecureConnection = unsecureConnectionTextSwitch.checked
//dnextcloudAccounts.itemAt(account).unencryptedConnection = unencryptedConnectionTextSwitch.checked
} }
SilicaFlickable { SilicaFlickable {
@ -41,7 +59,7 @@ Dialog {
id: nameField id: nameField
focus: true focus: true
width: parent.width width: parent.width
text: nextcloudAccounts.itemAt(account).name.length <= 0 ? qsTr("Unnamed account") : nextcloudAccounts.itemAt(account).name text: account.value("name", "", String)
placeholderText: qsTr("Account name") placeholderText: qsTr("Account name")
label: placeholderText label: placeholderText
errorHighlight: text.length === 0// && focus === true errorHighlight: text.length === 0// && focus === true
@ -53,7 +71,7 @@ Dialog {
TextField { TextField {
id: serverField id: serverField
width: parent.width width: parent.width
text: nextcloudAccounts.itemAt(account).server.length <= 0 ? "https://" : nextcloudAccounts.itemAt(account).server text: account.value("server", "https://", String)
placeholderText: qsTr("Nextcloud server") placeholderText: qsTr("Nextcloud server")
label: placeholderText + " " + qsTr("(starting with \"https://\")") label: placeholderText + " " + qsTr("(starting with \"https://\")")
inputMethodHints: Qt.ImhUrlCharactersOnly inputMethodHints: Qt.ImhUrlCharactersOnly
@ -68,7 +86,7 @@ Dialog {
TextField { TextField {
id: usernameField id: usernameField
width: parent.width width: parent.width
text: nextcloudAccounts.itemAt(account).username text: account.value("name", "", String)
placeholderText: qsTr("Username") placeholderText: qsTr("Username")
label: placeholderText label: placeholderText
inputMethodHints: Qt.ImhNoPredictiveText | Qt.ImhNoAutoUppercase inputMethodHints: Qt.ImhNoPredictiveText | Qt.ImhNoAutoUppercase
@ -81,7 +99,8 @@ Dialog {
PasswordField { PasswordField {
id: passwordField id: passwordField
width: parent.width width: parent.width
text: nextcloudAccounts.itemAt(account).password text: account.value("password", "", String)
placeholderText: qsTr("Password")
label: placeholderText label: placeholderText
errorHighlight: text.length === 0// && focus === true errorHighlight: text.length === 0// && focus === true
EnterKey.enabled: text.length > 0 EnterKey.enabled: text.length > 0

View file

@ -5,7 +5,6 @@ import Sailfish.Silica 1.0
Dialog { Dialog {
id: noteDialog id: noteDialog
property var account
property var note property var note
property var showdown: ShowDown.showdown property var showdown: ShowDown.showdown
@ -20,26 +19,29 @@ Dialog {
emoji: true } ) emoji: true } )
acceptDestination: Qt.resolvedUrl("EditPage.qml") acceptDestination: Qt.resolvedUrl("EditPage.qml")
acceptDestinationProperties: { account: account; note: note } acceptDestinationProperties: { note: note }
Component.onCompleted: { Component.onCompleted: {
acceptDestinationProperties = { account: account, note: note } note = api.getNote(note.id)
//showdown.setFlavor('original') reloadContent()
parseContent()
} }
Connections { Connections {
target: account target: api
onBusyChanged: { onBusyChanged: {
if (account.busy === false) { if (api.busy === false) {
note = account.getNote(note.id, false) note = api.getNote(note.id, false)
categoryRepeater.model = account.categories reloadContent()
acceptDestinationProperties = { account: account, note: note }
parseContent()
} }
} }
} }
function reloadContent() {
acceptDestinationProperties = { note: note }
categoryRepeater.model = api.categories
parseContent()
}
function parseContent() { function parseContent() {
note = account.getNote(note.id, false) //note = api.getNote(note.id, false)
var convertedText = converter.makeHtml(note.content) var convertedText = converter.makeHtml(note.content)
var occurence = -1 var occurence = -1
convertedText = convertedText.replace(/^<li>(<p>)?\[ \] (.*)(<.*)$/gmi, convertedText = convertedText.replace(/^<li>(<p>)?\[ \] (.*)(<.*)$/gmi,
@ -75,31 +77,30 @@ Dialog {
onTriggered: pageStack.pop() onTriggered: pageStack.pop()
} }
PullDownMenu { PullDownMenu {
busy: account ? account.busy : false busy: api.busy
MenuItem { MenuItem {
text: qsTr("Delete") text: qsTr("Delete")
enabled: account ? true : false onClicked: remorse.execute("Deleting", function() { api.deleteNote(note.id) } )
onClicked: remorse.execute("Deleting", function() { account.deleteNote(notey.id) } )
} }
MenuItem { MenuItem {
text: enabled ? qsTr("Reload") : qsTr("Updating...") text: enabled ? qsTr("Reload") : qsTr("Updating...")
enabled: account ? !account.busy : false enabled: !api.busy
onClicked: account.getNote(note.id) onClicked: api.getNote(note.id)
} }
MenuLabel { MenuLabel {
visible: appSettings.currentAccount >= 0 visible: appSettings.currentAccount.length >= 0
text: account ? ( text: qsTr("Last update") + ": " + (
qsTr("Last update") + ": " + ( new Date(api.update).valueOf() !== 0 ?
new Date(account.update).valueOf() !== 0 ? new Date(api.update).toLocaleString(Qt.locale(), Locale.ShortFormat) :
new Date(account.update).toLocaleString(Qt.locale(), Locale.ShortFormat) : qsTr("never"))
qsTr("never"))) : ""
} }
} }
DialogHeader { DialogHeader {
id: dialogHeader id: dialogHeader
dialog: noteDialog dialog: noteDialog
title: note.title
acceptText: qsTr("Edit") acceptText: qsTr("Edit")
cancelText: qsTr("Notes") cancelText: qsTr("Notes")
} }
@ -108,6 +109,12 @@ Dialog {
width: parent.width width: parent.width
spacing: Theme.paddingLarge spacing: Theme.paddingLarge
Separator {
width: parent.width
color: Theme.primaryColor
horizontalAlignment: Qt.AlignHCenter
}
LinkedLabel { LinkedLabel {
id: contentLabel id: contentLabel
x: Theme.horizontalPageMargin x: Theme.horizontalPageMargin
@ -129,7 +136,7 @@ Dialog {
} ) } )
note.content = newContent note.content = newContent
parseContent() parseContent()
account.updateNote(note.id, { 'content': note.content } ) api.updateNote(note.id, { 'content': note.content } )
} }
else if (/^tasklist:uncheckbox_(\d+)$/m.test(link)) { else if (/^tasklist:uncheckbox_(\d+)$/m.test(link)) {
newContent = newContent.replace(/- \[[xX]\] (.*)$/gm, newContent = newContent.replace(/- \[[xX]\] (.*)$/gm,
@ -141,7 +148,7 @@ Dialog {
} ) } )
note.content = newContent note.content = newContent
parseContent() parseContent()
account.updateNote(note.id, { 'content': note.content } ) api.updateNote(note.id, { 'content': note.content } )
} }
else { else {
Qt.openUrlExternally(link) Qt.openUrlExternally(link)
@ -150,15 +157,11 @@ Dialog {
} }
Separator { Separator {
id: separator
width: parent.width width: parent.width
color: Theme.primaryColor color: Theme.primaryColor
horizontalAlignment: Qt.AlignHCenter horizontalAlignment: Qt.AlignHCenter
} }
Column {
width: parent.width
Flow { Flow {
x: Theme.horizontalPageMargin x: Theme.horizontalPageMargin
width: parent.width - 2*x width: parent.width - 2*x
@ -169,7 +172,7 @@ Dialog {
Repeater { Repeater {
id: categoryRepeater id: categoryRepeater
model: account.categories model: api.categories
BackgroundItem { BackgroundItem {
id: categoryBackground id: categoryBackground
width: categoryRectangle.width width: categoryRectangle.width
@ -193,6 +196,8 @@ Dialog {
} }
} }
} }
}
Row { Row {
x: Theme.horizontalPageMargin x: Theme.horizontalPageMargin
width: parent.width - x width: parent.width - x
@ -203,7 +208,7 @@ Dialog {
icon.source: (selected ? "image://theme/icon-m-favorite-selected?" : "image://theme/icon-m-favorite?") + icon.source: (selected ? "image://theme/icon-m-favorite-selected?" : "image://theme/icon-m-favorite?") +
(favoriteButton.highlighted ? Theme.secondaryHighlightColor : Theme.secondaryColor) (favoriteButton.highlighted ? Theme.secondaryHighlightColor : Theme.secondaryColor)
onClicked: { onClicked: {
account.updateNote(note.id, {'favorite': !note.favorite}) api.updateNote(note.id, {'favorite': !note.favorite})
} }
} }
TextField { TextField {
@ -217,20 +222,19 @@ Dialog {
categoryField.focus = false categoryField.focus = false
} }
onFocusChanged: { onFocusChanged: {
if (focus === false) { if (focus === false && text !== note.category) {
account.updateNote(note.id, {'content': note.content, 'category': text}) // This does not seem to work without adding the content api.updateNote(note.id, {'content': note.content, 'category': text}) // This does not seem to work without adding the content
} }
} }
} }
} }
DetailItem { DetailItem {
id: modifiedDetail id: modifiedDetail
label: qsTr("Modified") label: qsTr("Modified")
value: new Date(note.modified * 1000).toLocaleString(Qt.locale(), Locale.ShortFormat) value: new Date(note.modified * 1000).toLocaleString(Qt.locale(), Locale.ShortFormat)
} }
} }
}
}
VerticalScrollDecorator {} VerticalScrollDecorator {}
} }

View file

@ -21,13 +21,28 @@ Item {
property bool saveFile: false property bool saveFile: false
property bool busy: false property bool busy: false
property bool searchActive: false property bool searchActive: false
property var apiReq: new XMLHttpRequest
property int status: 204 property int status: 204
property string statusText: "No Content" property string statusText: "No Content"
Component.onCompleted: {
refreshConfig()
}
onStatusChanged: { onStatusChanged: {
console.log("Network status: " + statusText + " (" + status + ")") console.log("Network status: " + statusText + " (" + status + ")")
} }
onUuidChanged: {
onUuidChanged: console.log("Account : " + uuid)
account.path = "/apps/harbour-nextcloudnotes/accounts/" + uuid
refreshConfig()
modelData = []
model.clear()
appSettings.currentAccount = uuid
//getNotes()
}
Connections { Connections {
target: appSettings target: appSettings
onSortByChanged: _mapDataToModel() onSortByChanged: _mapDataToModel()
@ -36,9 +51,14 @@ Item {
ConfigurationGroup { ConfigurationGroup {
id: account id: account
path: "/apps/harbour-nextcloudnotes/accounts/" + uuid path: "/apps/harbour-nextcloudnotes/accounts/" + uuid
onValuesChanged: refreshConfig()
} }
Component.onCompleted: { function refreshConfig() {
if (busy) {
apiReq.abort()
}
account.sync()
name = account.value("name", "", String) name = account.value("name", "", String)
server = account.value("server", "", String) server = account.value("server", "", String)
url = server + "/index.php/apps/notes/api/" + version + "/notes" url = server + "/index.php/apps/notes/api/" + version + "/notes"
@ -49,16 +69,18 @@ Item {
unencryptedConnection = account.value("unencryptedConnection", false, Boolean) unencryptedConnection = account.value("unencryptedConnection", false, Boolean)
} }
onUuidChanged: account.setValue("uuid", uuid) /*onUuidChanged: account.setValue("uuid", uuid)
onNameChanged: account.setValue("name", name) onNameChanged: account.setValue("name", name)
onServerChanged: account.setValue("server", server) onServerChanged: account.setValue("server", server)
onUsernameChanged: account.setValue("username", username) onUsernameChanged: account.setValue("username", username)
onPasswordChanged: account.setValue("password", password) onPasswordChanged: account.setValue("password", password)
onUpdateChanged: account.setValue("update", update) onUpdateChanged: account.setValue("update", update)
onUnsecureConnectionChanged: account.setValue("unsecureConnection", unsecureConnection) onUnsecureConnectionChanged: account.setValue("unsecureConnection", unsecureConnection)
onUnencryptedConnectionChanged: account.setValue("unencryptedConnection", unencryptedConnection) onUnencryptedConnectionChanged: account.setValue("unencryptedConnection", unencryptedConnection)*/
function clear() { function clear() {
apiReq.abort()
modelData = []
model.clear() model.clear()
account.clear() account.clear()
} }
@ -73,7 +95,7 @@ Item {
} }
} }
var apiReq = new XMLHttpRequest console.log("Calling " + endpoint)
apiReq.open(method, endpoint, true) apiReq.open(method, endpoint, true)
apiReq.setRequestHeader('User-Agent', 'SailfishOS/harbour-nextcloudnotes') apiReq.setRequestHeader('User-Agent', 'SailfishOS/harbour-nextcloudnotes')
apiReq.setRequestHeader('OCS-APIRequest', 'true') apiReq.setRequestHeader('OCS-APIRequest', 'true')
@ -100,6 +122,9 @@ Item {
case "POST": case "POST":
console.log("Created a note via API: " + endpoint) console.log("Created a note via API: " + endpoint)
_addToModelData(json) _addToModelData(json)
pageStack.push(Qt.resolvedUrl("NotePage.qml"), { note: json } )
pageStack.completeAnimation()
pageStack.navigateForward()
break; break;
case "PUT": case "PUT":
console.log("Updated a note via API: " + endpoint) console.log("Updated a note via API: " + endpoint)
@ -241,7 +266,9 @@ Item {
searchActive = true searchActive = true
model.clear() model.clear()
for (var element in modelData) { for (var element in modelData) {
if (modelData[element].title.toLowerCase().indexOf(query) >= 0 | modelData[element].content.toLowerCase().indexOf(query) >= 0) { if (modelData[element].title.toLowerCase().indexOf(query) >= 0 |
modelData[element].content.toLowerCase().indexOf(query) >= 0 |
modelData[element].category.toLowerCase().indexOf(query) >= 0) {
model.append(modelData[element]) model.append(modelData[element])
} }
} }

View file

@ -6,23 +6,13 @@ Page {
onStatusChanged: { onStatusChanged: {
if (status === PageStatus.Active) { if (status === PageStatus.Active) {
if (nextcloudAccounts.count > 0) { if (appSettings.accountIDs.length <= 0) {
autoSyncTimer.restart()
}
else {
addAccountHint.restart() addAccountHint.restart()
} }
else {
autoSyncTimer.restart()
} }
} }
Timer {
id: autoSyncTimer
interval: appSettings.autoSyncInterval * 1000
repeat: true
running: interval > 0 && appWindow.visible
triggeredOnStart: true
onTriggered: nextcloudAccounts.itemAt(appSettings.currentAccount).getNotes()
onIntervalChanged: console.log("Auto-Sync every " + interval / 1000 + " seconds")
} }
SilicaListView { SilicaListView {
@ -30,7 +20,7 @@ Page {
anchors.fill: parent anchors.fill: parent
PullDownMenu { PullDownMenu {
busy: nextcloudAccounts.itemAt(appSettings.currentAccount) ? nextcloudAccounts.itemAt(appSettings.currentAccount).busy : false busy: api.busy
MenuItem { MenuItem {
text: qsTr("Settings") text: qsTr("Settings")
@ -38,23 +28,20 @@ Page {
} }
MenuItem { MenuItem {
text: qsTr("Add note") text: qsTr("Add note")
enabled: nextcloudAccounts.itemAt(appSettings.currentAccount) ? true : false enabled: appSettings.currentAccount.length > 0
visible: appSettings.currentAccount >= 0 onClicked: api.createNote({'content': ""})
onClicked: nextcloudAccounts.itemAt(appSettings.currentAccount).createNote({'content': ""})
} }
MenuItem { MenuItem {
text: enabled ? qsTr("Reload") : qsTr("Updating...") text: enabled ? qsTr("Reload") : qsTr("Updating...")
enabled: nextcloudAccounts.itemAt(appSettings.currentAccount) ? !nextcloudAccounts.itemAt(appSettings.currentAccount).busy : false enabled: appSettings.currentAccount.length > 0 && !api.busy
visible: appSettings.currentAccount >= 0 onClicked: api.getNotes()
onClicked: nextcloudAccounts.itemAt(appSettings.currentAccount).getNotes()
} }
MenuLabel { MenuLabel {
visible: appSettings.currentAccount >= 0 visible: appSettings.currentAccount.length > 0
text: nextcloudAccounts.itemAt(appSettings.currentAccount) ? ( text: qsTr("Last update") + ": " + (
qsTr("Last update") + ": " + ( new Date(api.update).valueOf() !== 0 ?
new Date(nextcloudAccounts.itemAt(appSettings.currentAccount).update).valueOf() !== 0 ? new Date(api.update).toLocaleString(Qt.locale(), Locale.ShortFormat) :
new Date(nextcloudAccounts.itemAt(appSettings.currentAccount).update).toLocaleString(Qt.locale(), Locale.ShortFormat) : qsTr("never"))
qsTr("never"))) : ""
} }
} }
@ -63,10 +50,10 @@ Page {
SearchField { SearchField {
id: searchField id: searchField
width: parent.width width: parent.width
placeholderText: nextcloudAccounts.itemAt(appSettings.currentAccount).name placeholderText: api.name
EnterKey.iconSource: "image://theme/icon-m-enter-close" EnterKey.iconSource: "image://theme/icon-m-enter-close"
EnterKey.onClicked: focus = false EnterKey.onClicked: focus = false
onTextChanged: nextcloudAccounts.itemAt(appSettings.currentAccount).search(text.toLowerCase()) onTextChanged: api.search(text.toLowerCase())
} }
Label { Label {
id: description id: description
@ -76,23 +63,23 @@ Page {
anchors.bottomMargin: Theme.paddingMedium anchors.bottomMargin: Theme.paddingMedium
color: Theme.secondaryHighlightColor color: Theme.secondaryHighlightColor
font.pixelSize: Theme.fontSizeSmall font.pixelSize: Theme.fontSizeSmall
text: nextcloudAccounts.itemAt(appSettings.currentAccount).username + "@" + nextcloudAccounts.itemAt(appSettings.currentAccount).server text: api.username + "@" + api.server
} }
BusyIndicator { BusyIndicator {
anchors.verticalCenter: searchField.verticalCenter anchors.verticalCenter: searchField.verticalCenter
anchors.right: parent.right anchors.right: parent.right
anchors.rightMargin: Theme.horizontalPageMargin anchors.rightMargin: Theme.horizontalPageMargin
size: BusyIndicatorSize.Medium size: BusyIndicatorSize.Medium
running: nextcloudAccounts.itemAt(appSettings.currentAccount) ? nextcloudAccounts.itemAt(appSettings.currentAccount).busy && !busyIndicator.running : false running: api.busy && !busyIndicator.running
} }
} }
currentIndex: -1 currentIndex: -1
model: nextcloudAccounts.itemAt(appSettings.currentAccount)? nextcloudAccounts.itemAt(appSettings.currentAccount).model : 0 model: api.model
Connections { Connections {
target: appSettings target: api
onCurrentAccountChanged: notesList.model = nextcloudAccounts.itemAt(appSettings.currentAccount)? nextcloudAccounts.itemAt(appSettings.currentAccount).model : 0 onUuidChanged: notesList.model = api.model
} }
delegate: BackgroundItem { delegate: BackgroundItem {
@ -125,7 +112,7 @@ Page {
icon.source: (favorite ? "image://theme/icon-m-favorite-selected?" : "image://theme/icon-m-favorite?") + icon.source: (favorite ? "image://theme/icon-m-favorite-selected?" : "image://theme/icon-m-favorite?") +
(note.highlighted ? Theme.secondaryHighlightColor : Theme.secondaryColor) (note.highlighted ? Theme.secondaryHighlightColor : Theme.secondaryColor)
onClicked: { onClicked: {
nextcloudAccounts.itemAt(appSettings.currentAccount).updateNote(id, {'favorite': !favorite} ) api.updateNote(id, {'favorite': !favorite} )
} }
} }
@ -185,8 +172,7 @@ Page {
} }
onClicked: pageStack.push(Qt.resolvedUrl("NotePage.qml"), onClicked: pageStack.push(Qt.resolvedUrl("NotePage.qml"),
{ account: nextcloudAccounts.itemAt(appSettings.currentAccount), { note: api.model.get(index)} )
note: nextcloudAccounts.itemAt(appSettings.currentAccount).model.get(index)} )
onPressAndHold: menu.open(note) onPressAndHold: menu.open(note)
ContextMenu { ContextMenu {
@ -200,7 +186,7 @@ Page {
text: qsTr("Delete") text: qsTr("Delete")
onClicked: { onClicked: {
remorse.execute(note, qsTr("Deleting note"), function() { remorse.execute(note, qsTr("Deleting note"), function() {
nextcloudAccounts.itemAt(appSettings.currentAccount).deleteNote(id) api.deleteNote(id)
}) })
} }
} }
@ -218,26 +204,26 @@ Page {
id: busyIndicator id: busyIndicator
anchors.centerIn: parent anchors.centerIn: parent
size: BusyIndicatorSize.Large size: BusyIndicatorSize.Large
running: nextcloudAccounts.itemAt(appSettings.currentAccount) ? (notesList.count === 0 && nextcloudAccounts.itemAt(appSettings.currentAccount).busy) : false running: notesList.count === 0 && api.busy
} }
ViewPlaceholder { ViewPlaceholder {
id: noLoginPlaceholder id: noLoginPlaceholder
enabled: nextcloudUUIDs.value.length <= 0 enabled: appSettings.accountIDs.length <= 0
text: qsTr("No account yet") text: qsTr("No account yet")
hintText: qsTr("Got to the settings to add an account") hintText: qsTr("Got to the settings to add an account")
} }
ViewPlaceholder { ViewPlaceholder {
id: noNotesPlaceholder id: noNotesPlaceholder
enabled: nextcloudAccounts.itemAt(appSettings.currentAccount) ? (nextcloudAccounts.itemAt(appSettings.currentAccount).status === 204 && !busyIndicator.running && !noLoginPlaceholder.enabled) : false enabled: api.status === 204 && !busyIndicator.running && !noLoginPlaceholder.enabled
text: qsTr("No notes yet") text: qsTr("No notes yet")
hintText: qsTr("Pull down to add a note") hintText: qsTr("Pull down to add a note")
} }
ViewPlaceholder { ViewPlaceholder {
id: noSearchPlaceholder id: noSearchPlaceholder
enabled: nextcloudAccounts.itemAt(appSettings.currentAccount) ? (notesList.count === 0 && nextcloudAccounts.itemAt(appSettings.currentAccount).modelData.length > 0) : false enabled: notesList.count === 0 && api.searchActive
text: qsTr("No result") text: qsTr("No result")
hintText: qsTr("Try another query") hintText: qsTr("Try another query")
} }
@ -246,7 +232,7 @@ Page {
id: errorPlaceholder id: errorPlaceholder
enabled: notesList.count === 0 && !busyIndicator.running && !noSearchPlaceholder.enabled && !noNotesPlaceholder.enabled && !noLoginPlaceholder.enabled enabled: notesList.count === 0 && !busyIndicator.running && !noSearchPlaceholder.enabled && !noNotesPlaceholder.enabled && !noLoginPlaceholder.enabled
text: qsTr("An error occurred") text: qsTr("An error occurred")
hintText: nextcloudAccounts.itemAt(appSettings.currentAccount).statusText hintText: api.statusText
} }
TouchInteractionHint { TouchInteractionHint {

View file

@ -31,47 +31,53 @@ Page {
} }
Label { Label {
id: noAccountsLabel id: noAccountsLabel
visible: nextcloudAccounts.count <= 0 visible: appSettings.accountIDs.length <= 0
text: qsTr("No Nextcloud account yet") text: qsTr("No Nextcloud account yet")
font.pixelSize: Theme.fontSizeLarge font.pixelSize: Theme.fontSizeLarge
color: Theme.secondaryHighlightColor color: Theme.secondaryHighlightColor
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
} }
Repeater { Repeater {
model: nextcloudAccounts.count id: accountRepeater
model: appSettings.accountIDs
delegate: ListItem { delegate: ListItem {
id: accountListItem id: accountListItem
contentHeight: accountTextSwitch.height contentHeight: accountTextSwitch.height
highlighted: accountTextSwitch.down highlighted: accountTextSwitch.down
ConfigurationGroup {
id: account
path: "/apps/harbour-nextcloudnotes/accounts/" + modelData
Component.onCompleted: {
accountTextSwitch.text = value("name", qsTr("Unnamed account"), String)
accountTextSwitch.description = account.value("username", qsTr("unknown"), String) + "@" + account.value("server", qsTr("unknown"), String)
}
}
TextSwitch { TextSwitch {
id: accountTextSwitch id: accountTextSwitch
automaticCheck: false automaticCheck: false
checked: index === appSettings.currentAccount checked: modelData === api.uuid
text: nextcloudAccounts.itemAt(index).name.length <= 0 ? qsTr("Unnamed account") : nextcloudAccounts.itemAt(index).name onClicked: {
description: nextcloudAccounts.itemAt(index).username + "@" + nextcloudAccounts.itemAt(index).server// : qsTr("Press and hold to configure") api.uuid = modelData
onClicked: appSettings.currentAccount = index api.getNotes()
}
onPressAndHold: openMenu() onPressAndHold: openMenu()
} }
menu: ContextMenu { menu: ContextMenu {
MenuItem { MenuItem {
text: qsTr("Edit") text: qsTr("Edit")
onClicked: { onClicked: {
var login = pageStack.push(Qt.resolvedUrl("LoginDialog.qml"), { account: index }) var login = pageStack.replace(Qt.resolvedUrl("LoginDialog.qml"), { accountId: modelData })
login.accepted.connect(function() {
})
login.rejected.connect(function() {
})
} }
} }
MenuItem { MenuItem {
text: qsTr("Delete") text: qsTr("Delete")
onClicked: { onClicked: {
accountListItem.remorseAction(qsTr("Deleting account"), function() { accountListItem.remorseAction(qsTr("Deleting account"), function() {
console.log("Deleting " + nextcloudAccounts.itemAt(index).uuid) console.log("Deleting " + modelData)
nextcloudAccounts.remove(nextcloudAccounts.itemAt(index).uuid) appSettings.removeAccount(modelData)
//nextcloudAccounts.itemAt(index).clear()
//nextcloudAccounts.pop()
}) })
} }
} }
@ -82,17 +88,8 @@ Page {
text: qsTr("Add account") text: qsTr("Add account")
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
onClicked: { onClicked: {
nextcloudAccounts.add() var newAccountID = appSettings.addAccount()
var login = pageStack.push(Qt.resolvedUrl("LoginDialog.qml"), { account:nextcloudAccounts.count-1 }) var login = pageStack.replace(Qt.resolvedUrl("LoginDialog.qml"), { accountId: newAccountID })
login.accepted.connect(function() {
console.log("Adding account " + nextcloudAccounts.itemAt(login.account).name)
if (appSettings.currentAccount < 0)
appSettings.currentAccount = nextcloudUUIDs.value.length-1
appWindow.update()
})
login.rejected.connect(function() {
nextcloudAccounts.pop()
})
} }
} }

View file

@ -12,6 +12,10 @@
# * date Author's Name <author's email> version-release # * date Author's Name <author's email> version-release
# - Summary of changes # - Summary of changes
* Thu Dec 06 2018 Scharel Clemens <harbour-nextcloudnotes@scharel.name> 0.2-1
- Improved account handling
- Directly go to edit page when creating a new note
* Thu Dec 06 2018 Scharel Clemens <harbour-nextcloudnotes@scharel.name> 0.1-8 * Thu Dec 06 2018 Scharel Clemens <harbour-nextcloudnotes@scharel.name> 0.1-8
- Fix for #19 "Strikethrough is not shown" - Fix for #19 "Strikethrough is not shown"
- Added #20 "List of existing categories" - Added #20 "List of existing categories"

View file

@ -13,8 +13,8 @@ Name: harbour-nextcloudnotes
%{!?qtc_make:%define qtc_make make} %{!?qtc_make:%define qtc_make make}
%{?qtc_builddir:%define _builddir %qtc_builddir} %{?qtc_builddir:%define _builddir %qtc_builddir}
Summary: Nextcloud Notes Summary: Nextcloud Notes
Version: 0.1 Version: 0.2
Release: 8 Release: 1
Group: Qt/Qt Group: Qt/Qt
License: LICENSE License: LICENSE
URL: http://example.org/ URL: http://example.org/

View file

@ -1,7 +1,7 @@
Name: harbour-nextcloudnotes Name: harbour-nextcloudnotes
Summary: Nextcloud Notes Summary: Nextcloud Notes
Version: 0.1 Version: 0.2
Release: 8 Release: 1
# The contents of the Group field should be one of the groups listed here: # The contents of the Group field should be one of the groups listed here:
# https://github.com/mer-tools/spectacle/blob/master/data/GROUPS # https://github.com/mer-tools/spectacle/blob/master/data/GROUPS
Group: Qt/Qt Group: Qt/Qt

View file

@ -61,6 +61,10 @@
<source>No category</source> <source>No category</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Modified</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>GPLLicense</name> <name>GPLLicense</name>
@ -100,11 +104,11 @@
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<source>Unnamed account</source> <source>&lt;strong&gt;CAUTION: Your password will be saved without any encryption on the device!&lt;/strong&gt;&lt;br&gt;Please consider creating a dedicated app password! Open your Nextcloud in a browser and go to &lt;i&gt;Settings&lt;/i&gt; &lt;i&gt;Security&lt;/i&gt;.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<source>&lt;strong&gt;CAUTION: Your password will be saved without any encryption on the device!&lt;/strong&gt;&lt;br&gt;Please consider creating a dedicated app password! Open your Nextcloud in a browser and go to &lt;i&gt;Settings&lt;/i&gt; &lt;i&gt;Security&lt;/i&gt;.</source> <source>Password</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
</context> </context>
@ -179,10 +183,22 @@
<source>Add note</source> <source>Add note</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Reload</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Updating...</source>
<translation type="unfinished"></translation>
</message>
<message> <message>
<source>Last update</source> <source>Last update</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>never</source>
<translation type="unfinished"></translation>
</message>
<message> <message>
<source>Modified</source> <source>Modified</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
@ -191,6 +207,18 @@
<source>Delete</source> <source>Delete</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Deleting note</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>No account yet</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Got to the settings to add an account</source>
<translation type="unfinished"></translation>
</message>
<message> <message>
<source>No notes yet</source> <source>No notes yet</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
@ -200,27 +228,11 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<source>Reload</source> <source>No result</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<source>never</source> <source>Try another query</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>No account yet</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Open the settings to configure your Nextcloud accounts</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Deleting note</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Got to the settings to add an account</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
@ -228,15 +240,7 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<source>Updating...</source> <source>Open the settings to configure your Nextcloud accounts</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>No result</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Try another query</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
</context> </context>
@ -366,6 +370,10 @@
<source>For interoperability with other apps such as Joplin</source> <source>For interoperability with other apps such as Joplin</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>unknown</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>UnencryptedDialog</name> <name>UnencryptedDialog</name>