harbour-nextcloudnotes/qml/harbour-nextcloudnotes.qml

158 lines
4.8 KiB
QML
Raw Normal View History

import QtQuick 2.2
2018-10-16 18:50:58 +03:00
import Sailfish.Silica 1.0
import Nemo.Configuration 1.0
import Nemo.Notifications 1.0
import NextcloudApi 1.0
2018-10-16 18:50:58 +03:00
import "pages"
ApplicationWindow
{
id: appWindow
2020-03-29 19:03:05 +03:00
// General settings of the app
2018-10-16 18:50:58 +03:00
ConfigurationGroup {
id: appSettings
path: "/apps/harbour-nextcloudnotes"
property bool initialized: false
property var accounts: value("accounts", [], Array)
property string currentAccount: value("currentAccount", "", String)
property int autoSyncInterval: value("autoSyncInterval", 0, Number)
property int previewLineCount: value("previewLineCount", 4, Number)
2018-12-27 22:38:14 +03:00
property bool favoritesOnTop: value("favoritesOnTop", true, Boolean)
2020-03-29 19:03:05 +03:00
property string sortBy: value("sortBy", "modifiedString", String)
2018-12-27 22:38:14 +03:00
property bool showSeparator: value("showSeparator", false, Boolean)
property bool useMonoFont: value("useMonoFont", false, Boolean)
property bool useCapitalX: value("useCapitalX", false, Boolean)
2018-12-07 02:30:18 +03:00
onCurrentAccountChanged: {
console.log("Current account: " + currentAccount)
}
onSortByChanged: {
if (sortBy == "none") notesModel.invalidate()
}
onFavoritesOnTopChanged: {
notesModel.favoritesOnTop = favoritesOnTop
}
function createAccount(username, password, url, name) {
var hash = accountHash.hash(username, url)
var tmpaccounts = accounts
tmpaccounts.push(hash)
accounts = tmpaccounts
tmpAccount.path = appSettings.path + "/accounts/" + hash
tmpAccount.url = url
tmpAccount.username = username
tmpAccount.passowrd = password
tmpAccount.name = name
console.log("Hash(" + username + "@" + url + ") = " + hash)
return hash
2018-12-07 02:30:18 +03:00
}
function removeAccount(hash) {
notesApi.deleteAppPassword(appSettings.value("accounts/" + hash + "/password"),
appSettings.value("accounts/" + hash + "/username"),
appSettings.value("accounts/" + hash + "/url"))
var tmpaccounts = accounts
tmpaccounts.pop(hash)
accounts = tmpaccounts
tmpAccount.path = appSettings.path + "/accounts/" + hash
tmpAccount.clear()
currentAccount = accounts[-1]
2021-01-05 23:40:53 +03:00
}
}
ConfigurationGroup {
id: account
Connections {
target: appSettings
onCurrentAccountChanged: account.path = appSettings.path + "/accounts/" + appSettings.currentAccount
2021-01-05 23:40:53 +03:00
}
property url url: value("url", "", String)
property string username: value("username", "", String)
property string passowrd: value("password", "", String)
property string name: value("name", "", String)
property var update: value("update", new Date(0), Date)
}
ConfigurationGroup {
id: tmpAccount
property url url
property string username
property string passowrd
property string name
property var update
}
function clearApp() {
appSettings.clear()
2021-01-05 23:40:53 +03:00
}
Notification {
id: offlineNotification
expireTimeout: 0
appName: "Nextcloud " + qsTr("Notes")
summary: qsTr("Offline")
2020-01-05 15:25:13 +03:00
body: qsTr("Synced") + ": " + new Date(account.update).toLocaleString(Qt.locale())
2020-03-29 19:03:05 +03:00
Component.onDestruction: close()
2020-01-05 15:25:13 +03:00
}
Notification {
id: storeErrorNotification
2020-01-05 15:25:13 +03:00
appName: offlineNotification.appName
summary: qsTr("File error")
Component.onDestruction: close()
}
Notification {
id: apiErrorNotification
appName: offlineNotification.appName
summary: qsTr("API error")
2020-03-29 19:03:05 +03:00
Component.onDestruction: close()
}
2018-12-07 02:30:18 +03:00
Timer {
id: autoSyncTimer
interval: appSettings.autoSyncInterval * 1000
repeat: true
2019-12-07 15:42:37 +03:00
running: interval > 0 && notesApi.networkAccessible && appWindow.visible
2020-03-29 19:03:05 +03:00
triggeredOnStart: true
2018-12-07 02:30:18 +03:00
onTriggered: {
notesApi.getAllNotes()
2018-12-07 02:30:18 +03:00
}
onIntervalChanged: {
if (interval > 0) {
console.log("Auto-Sync every " + interval / 1000 + " seconds")
}
2021-01-05 23:40:53 +03:00
else {
console.log("Auto-Sync disabled")
}
}
2018-12-07 02:30:18 +03:00
}
Nextcloud {
id: notesApi
server: account.url
username: account.username
password: account.passowrd
2020-05-05 20:44:31 +03:00
}
Component.onCompleted: {
}
Component.onDestruction: {
offlineNotification.close()
storeErrorNotification.close()
apiErrorNotification.close()
}
2018-10-21 02:44:23 +03:00
initialPage: Component { NotesPage { } }
2018-10-16 18:50:58 +03:00
cover: Qt.resolvedUrl("cover/CoverPage.qml")
allowedOrientations: debug ? Orientation.All : defaultAllowedOrientations
2018-10-16 18:50:58 +03:00
}