2018-10-16 18:50:58 +03:00
|
|
|
import QtQuick 2.0
|
|
|
|
import Sailfish.Silica 1.0
|
|
|
|
import Nemo.Configuration 1.0
|
2019-11-10 05:35:33 +03:00
|
|
|
import harbour.nextcloudnotes.notesapi 1.0
|
2018-10-16 18:50:58 +03:00
|
|
|
import "pages"
|
|
|
|
|
|
|
|
ApplicationWindow
|
|
|
|
{
|
|
|
|
id: appWindow
|
|
|
|
|
2018-12-07 02:30:18 +03:00
|
|
|
ConfigurationValue {
|
|
|
|
id: accounts
|
|
|
|
key: appSettings.path + "/accountIDs"
|
|
|
|
defaultValue: [ ]
|
|
|
|
}
|
|
|
|
|
2018-12-27 22:38:14 +03:00
|
|
|
ConfigurationGroup {
|
|
|
|
id: account
|
2018-12-29 03:40:11 +03:00
|
|
|
path: "/apps/harbour-nextcloudnotes/accounts/" + appSettings.currentAccount
|
2019-03-10 22:20:41 +03:00
|
|
|
|
2018-12-27 22:38:14 +03:00
|
|
|
property string name: value("name", "", String)
|
|
|
|
property url server: value("server", "", String)
|
|
|
|
property string version: value("version", "v0.2", String)
|
|
|
|
property string username: value("username", "", String)
|
|
|
|
property string password: account.value("password", "", String)
|
2019-11-11 01:04:42 +03:00
|
|
|
property bool doNotVerifySsl: account.value("doNotVerifySsl", false, Boolean)
|
|
|
|
property bool allowUnecrypted: account.value("allowUnecrypted", false, Boolean)
|
2018-12-27 22:38:14 +03:00
|
|
|
property date update: value("update", "", Date)
|
|
|
|
onValuesChanged: console.log("A property of the current account has changed")
|
2019-03-10 22:20:41 +03:00
|
|
|
onNameChanged: console.log("Account: " + name)
|
2018-12-27 22:38:14 +03:00
|
|
|
}
|
|
|
|
|
2018-10-16 18:50:58 +03:00
|
|
|
ConfigurationGroup {
|
|
|
|
id: appSettings
|
2018-10-17 00:52:28 +03:00
|
|
|
path: "/apps/harbour-nextcloudnotes/settings"
|
2018-11-15 00:13:47 +03:00
|
|
|
|
2019-11-11 01:04:42 +03:00
|
|
|
property bool initialized: false
|
2019-03-10 22:20:41 +03:00
|
|
|
property string currentAccount: value("currentAccount", "", String)
|
|
|
|
property var accountIDs: value("accountIDs", [ ], Array)
|
|
|
|
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)
|
2019-11-14 02:47:38 +03:00
|
|
|
property string sortBy: value("sortBy", "prettyDate", 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)
|
2019-03-10 22:20:41 +03:00
|
|
|
onCurrentAccountChanged: {
|
|
|
|
account.path = "/apps/harbour-nextcloudnotes/accounts/" + currentAccount
|
2019-11-11 01:04:42 +03:00
|
|
|
account.sync()
|
|
|
|
if (initialized)
|
|
|
|
notesApi.getAllNotes();
|
|
|
|
autoSyncTimer.restart()
|
2019-03-10 22:20:41 +03:00
|
|
|
}
|
2019-11-11 01:04:42 +03:00
|
|
|
Component.onCompleted: initialized = true
|
2018-12-07 02:30:18 +03:00
|
|
|
|
|
|
|
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 newIds = [ ]
|
|
|
|
accountIDs.forEach(function(currentValue) {
|
|
|
|
if (currentValue !== uuid) {
|
|
|
|
newIds.push(currentValue)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
accounts.value = newIds
|
2019-03-10 22:20:41 +03:00
|
|
|
for (var i = accountIDs.length-1; i >= 0; i--) {
|
2018-12-07 02:30:18 +03:00
|
|
|
if (accountIDs[i] !== uuid) {
|
2019-10-27 19:53:38 +03:00
|
|
|
appSettings.currentAccount = uuid
|
2018-12-07 02:30:18 +03:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2019-03-10 22:20:41 +03:00
|
|
|
if (autoSyncInterval > 0 && appWindow.visible) {
|
|
|
|
autoSyncTimer.start()
|
|
|
|
}
|
2018-12-07 02:30:18 +03:00
|
|
|
}
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
}
|
2018-11-15 00:13:47 +03:00
|
|
|
}
|
|
|
|
|
2018-12-07 02:30:18 +03:00
|
|
|
Timer {
|
|
|
|
id: autoSyncTimer
|
|
|
|
interval: appSettings.autoSyncInterval * 1000
|
|
|
|
repeat: true
|
|
|
|
running: interval > 0 && appWindow.visible
|
2019-11-11 01:04:42 +03:00
|
|
|
triggeredOnStart: false
|
2018-12-07 02:30:18 +03:00
|
|
|
onTriggered: {
|
2019-11-11 01:04:42 +03:00
|
|
|
if (!notesApi.busy) {
|
|
|
|
notesApi.getAllNotes();
|
2018-12-07 02:30:18 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
restart()
|
|
|
|
}
|
|
|
|
}
|
2019-03-10 22:20:41 +03:00
|
|
|
onIntervalChanged: {
|
|
|
|
if (interval > 0) {
|
|
|
|
console.log("Auto-Sync every " + interval / 1000 + " seconds")
|
|
|
|
}
|
|
|
|
}
|
2018-12-07 02:30:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NotesApi {
|
2019-11-11 01:04:42 +03:00
|
|
|
id: notesApi
|
|
|
|
scheme: account.allowUnecrypted ? "http" : "https"
|
2019-11-10 05:35:33 +03:00
|
|
|
host: account.server
|
|
|
|
path: "/index.php/apps/notes/api/" + account.version
|
|
|
|
username: account.username
|
2019-11-11 01:04:42 +03:00
|
|
|
password: account.password
|
|
|
|
sslVerify: !account.doNotVerifySsl
|
|
|
|
Component.onCompleted: getAllNotes()
|
2019-11-10 05:35:33 +03:00
|
|
|
}
|
|
|
|
|
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: defaultAllowedOrientations
|
|
|
|
}
|