2020-01-14 16:47:42 +03:00
|
|
|
import QtQuick 2.2
|
2018-10-16 18:50:58 +03:00
|
|
|
import Sailfish.Silica 1.0
|
|
|
|
import Nemo.Configuration 1.0
|
2020-01-03 16:00:07 +03:00
|
|
|
import Nemo.Notifications 1.0
|
2021-06-20 22:02:10 +03:00
|
|
|
import harbour.nextcloudapi 1.0
|
|
|
|
import harbour.nextcloudapi.notes 1.0
|
2018-10-16 18:50:58 +03:00
|
|
|
import "pages"
|
|
|
|
|
|
|
|
ApplicationWindow
|
|
|
|
{
|
|
|
|
id: appWindow
|
2020-03-27 01:22:45 +03:00
|
|
|
|
2021-06-20 22:02:10 +03:00
|
|
|
property var nextcloudApi: Nextcloud
|
|
|
|
property var notesApp: Notes
|
|
|
|
property NotesModel notesModel: notesApp.model()
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
//console.log("Current account: ", appSettings.currentAccount)
|
|
|
|
}
|
|
|
|
|
2021-07-25 19:28:58 +03:00
|
|
|
// Workaround as ConfigurationGroup does not store arrays
|
|
|
|
ConfigurationValue {
|
|
|
|
id: accountList
|
|
|
|
key: appSettings.path + "/accountList"
|
|
|
|
defaultValue: []
|
|
|
|
}
|
|
|
|
|
2020-03-29 19:03:05 +03:00
|
|
|
// General settings of the app
|
2018-10-16 18:50:58 +03:00
|
|
|
ConfigurationGroup {
|
|
|
|
id: appSettings
|
2021-01-03 21:07:47 +03:00
|
|
|
path: "/apps/harbour-nextcloudnotes"
|
2018-11-15 00:13:47 +03:00
|
|
|
|
2019-11-11 01:04:42 +03:00
|
|
|
property bool initialized: false
|
2021-07-25 19:28:58 +03:00
|
|
|
//property var accountList: value("accountList", [], Array)
|
2021-01-06 19:09:09 +03:00
|
|
|
property string currentAccount: value("currentAccount", "", String)
|
2019-03-10 22:20:41 +03:00
|
|
|
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
|
|
|
|
2020-04-11 16:40:47 +03:00
|
|
|
onSortByChanged: {
|
2021-06-20 22:02:10 +03:00
|
|
|
if (sortBy == "none") Notes.model.invalidate()
|
2020-04-11 16:40:47 +03:00
|
|
|
}
|
|
|
|
onFavoritesOnTopChanged: {
|
2021-06-20 22:02:10 +03:00
|
|
|
Notes.model.favoritesOnTop = favoritesOnTop
|
2020-04-11 16:40:47 +03:00
|
|
|
}
|
|
|
|
|
2021-01-06 19:09:09 +03:00
|
|
|
function createAccount(username, password, url, name) {
|
2021-07-25 19:28:58 +03:00
|
|
|
var hash = nextcloudApi.accountHash(username, url)
|
|
|
|
var tmpAccountList = accountList.value
|
|
|
|
tmpAccountList.push(hash)
|
|
|
|
accountList.value = tmpAccountList
|
2021-01-06 19:09:09 +03:00
|
|
|
|
|
|
|
tmpAccount.path = appSettings.path + "/accounts/" + hash
|
|
|
|
tmpAccount.url = url
|
|
|
|
tmpAccount.username = username
|
|
|
|
tmpAccount.passowrd = password
|
|
|
|
tmpAccount.name = name
|
|
|
|
|
|
|
|
console.log("Hash(" + username + "@" + url + ") = " + hash)
|
2021-01-03 21:07:47 +03:00
|
|
|
return hash
|
2018-12-07 02:30:18 +03:00
|
|
|
}
|
2021-01-03 21:07:47 +03:00
|
|
|
function removeAccount(hash) {
|
2021-06-20 22:02:10 +03:00
|
|
|
Nextcloud.deleteAppPassword(appSettings.value("accounts/" + hash + "/password"),
|
2021-01-06 19:09:09 +03:00
|
|
|
appSettings.value("accounts/" + hash + "/username"),
|
|
|
|
appSettings.value("accounts/" + hash + "/url"))
|
2021-07-25 19:28:58 +03:00
|
|
|
var tmpAccountList = accountList.value
|
|
|
|
tmpAccountList.pop(hash)
|
|
|
|
accountList.value = tmpAccountList
|
2021-01-06 19:09:09 +03:00
|
|
|
|
|
|
|
tmpAccount.path = appSettings.path + "/accounts/" + hash
|
|
|
|
tmpAccount.clear()
|
2021-07-25 19:28:58 +03:00
|
|
|
if (accountList.value[-1]) {
|
|
|
|
currentAccount = accountList.value[-1]
|
2021-06-21 01:17:10 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
currentAccount = ""
|
|
|
|
}
|
2021-01-05 23:40:53 +03:00
|
|
|
}
|
2018-11-15 00:13:47 +03:00
|
|
|
}
|
|
|
|
|
2021-01-06 19:09:09 +03:00
|
|
|
ConfigurationGroup {
|
|
|
|
id: account
|
|
|
|
Connections {
|
|
|
|
target: appSettings
|
2021-06-21 01:17:10 +03:00
|
|
|
onCurrentAccountChanged: {
|
2021-07-01 20:10:12 +03:00
|
|
|
account.path = appSettings.path + "/accounts/" + appSettings.currentAccount
|
2021-07-25 19:28:58 +03:00
|
|
|
console.log("Current account: " + account.username + "@" + String(account.url).split('//')[1])
|
2021-06-21 01:17:10 +03:00
|
|
|
}
|
2021-01-05 23:40:53 +03:00
|
|
|
}
|
2021-01-06 19:09:09 +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)
|
2021-06-20 22:02:10 +03:00
|
|
|
|
|
|
|
onUrlChanged: Nextcloud.server = url
|
|
|
|
onUsernameChanged: Nextcloud.username = username
|
|
|
|
onPassowrdChanged: Nextcloud.password = passowrd
|
2021-01-06 19:09:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
2021-01-03 21:07:47 +03:00
|
|
|
|
2020-01-03 16:00:07 +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 {
|
2020-04-13 20:13:14 +03:00
|
|
|
id: storeErrorNotification
|
2020-01-05 15:25:13 +03:00
|
|
|
appName: offlineNotification.appName
|
2020-04-13 20:13:14 +03:00
|
|
|
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()
|
2020-01-03 16:00:07 +03:00
|
|
|
}
|
|
|
|
|
2018-12-07 02:30:18 +03:00
|
|
|
Timer {
|
|
|
|
id: autoSyncTimer
|
|
|
|
interval: appSettings.autoSyncInterval * 1000
|
|
|
|
repeat: true
|
2021-06-20 22:02:10 +03:00
|
|
|
running: interval > 0 && appSettings.currentAccount !== "" && Nextcloud.networkAccessible && appWindow.visible
|
2020-03-29 19:03:05 +03:00
|
|
|
triggeredOnStart: true
|
2018-12-07 02:30:18 +03:00
|
|
|
onTriggered: {
|
2021-06-20 22:02:10 +03:00
|
|
|
Notes.getAllNotes()
|
2018-12-07 02:30:18 +03:00
|
|
|
}
|
2019-03-10 22:20:41 +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")
|
|
|
|
}
|
2019-03-10 22:20:41 +03:00
|
|
|
}
|
2018-12-07 02:30:18 +03:00
|
|
|
}
|
|
|
|
|
2020-04-13 20:13:14 +03:00
|
|
|
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")
|
2021-04-12 19:58:39 +03:00
|
|
|
|
|
|
|
allowedOrientations: debug ? Orientation.All : defaultAllowedOrientations
|
2018-10-16 18:50:58 +03:00
|
|
|
}
|