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
|
2018-10-16 18:50:58 +03:00
|
|
|
import "pages"
|
|
|
|
|
|
|
|
ApplicationWindow
|
|
|
|
{
|
|
|
|
id: appWindow
|
2020-03-27 01:22:45 +03:00
|
|
|
|
2020-03-29 19:03:05 +03:00
|
|
|
// All configured accounts
|
2018-12-07 02:30:18 +03:00
|
|
|
ConfigurationValue {
|
|
|
|
id: accounts
|
|
|
|
key: appSettings.path + "/accountIDs"
|
|
|
|
defaultValue: [ ]
|
|
|
|
}
|
2020-03-27 01:22:45 +03:00
|
|
|
|
2020-03-29 19:03:05 +03:00
|
|
|
// Current account in use
|
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)
|
2020-03-29 19:03:05 +03:00
|
|
|
onServerChanged: notesApi.server = server
|
2020-04-11 20:34:28 +03:00
|
|
|
onUsernameChanged: {
|
|
|
|
console.log("Username: " + username)
|
|
|
|
notesApi.username = username
|
|
|
|
}
|
2020-03-29 19:03:05 +03:00
|
|
|
onPasswordChanged: notesApi.password = password
|
2020-04-10 21:40:23 +03:00
|
|
|
onDoNotVerifySslChanged: notesApi.verifySsl = !doNotVerifySsl
|
2020-04-11 20:34:28 +03:00
|
|
|
onNameChanged: console.log("Using account: " + name)
|
2018-12-27 22:38:14 +03:00
|
|
|
}
|
|
|
|
|
2020-03-29 19:03:05 +03:00
|
|
|
// General settings of the app
|
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 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 17:39:30 +03:00
|
|
|
onCurrentAccountChanged: {
|
2020-04-15 09:31:04 +03:00
|
|
|
notesProxyModel.sourceModel.clear()
|
2020-04-11 17:39:30 +03:00
|
|
|
account.path = "/apps/harbour-nextcloudnotes/accounts/" + currentAccount
|
|
|
|
notesStore.account = currentAccount
|
|
|
|
notesStore.getAllNotes()
|
|
|
|
notesApi.getAllNotes()
|
|
|
|
}
|
|
|
|
|
2020-04-11 16:40:47 +03:00
|
|
|
onSortByChanged: {
|
|
|
|
if (sortBy == "none")
|
2020-04-15 09:31:04 +03:00
|
|
|
notesProxyModel.invalidate()
|
2020-04-11 16:40:47 +03:00
|
|
|
else
|
2020-04-15 09:31:04 +03:00
|
|
|
notesProxyModel.sortRole = notesProxyModel.roleFromName(sortBy)
|
2020-04-11 16:40:47 +03:00
|
|
|
}
|
|
|
|
onFavoritesOnTopChanged: {
|
2020-04-15 09:31:04 +03:00
|
|
|
notesProxyModel.favoritesOnTop = favoritesOnTop
|
2020-04-11 16:40:47 +03:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
2020-03-29 19:03:05 +03:00
|
|
|
ConfigurationGroup {
|
|
|
|
id: removeHelperConfGroup
|
|
|
|
}
|
2018-12-07 02:30:18 +03:00
|
|
|
function removeAccount(uuid) {
|
|
|
|
autoSyncTimer.stop()
|
2020-03-29 19:03:05 +03:00
|
|
|
var tmpIDs = accounts.value
|
|
|
|
removeHelperConfGroup.path = "/apps/harbour-nextcloudnotes/accounts/" + uuid
|
|
|
|
for (var i = tmpIDs.length-1; i >= 0; i--) {
|
|
|
|
console.log(tmpIDs)
|
|
|
|
console.log("Checking:" + tmpIDs[i])
|
|
|
|
if (tmpIDs[i] === uuid) {
|
|
|
|
console.log("Found! Removing ...")
|
|
|
|
tmpIDs.splice(i, 1)
|
2019-12-18 22:21:47 +03:00
|
|
|
}
|
2020-03-29 19:03:05 +03:00
|
|
|
console.log(tmpIDs)
|
2019-12-18 22:21:47 +03:00
|
|
|
}
|
|
|
|
if (appSettings.currentAccount === uuid) {
|
|
|
|
appSettings.currentAccount = ""
|
2020-03-29 19:03:05 +03:00
|
|
|
for (var i = tmpIDs.length-1; i >= 0 && appSettings.currentAccount === ""; i--) {
|
|
|
|
if (tmpIDs[i] !== uuid) {
|
|
|
|
appSettings.currentAccount = tmpIDs[i]
|
|
|
|
}
|
|
|
|
}
|
2018-12-07 02:30:18 +03:00
|
|
|
}
|
2020-03-29 19:03:05 +03:00
|
|
|
removeHelperConfGroup.clear()
|
2019-03-10 22:20:41 +03:00
|
|
|
if (autoSyncInterval > 0 && appWindow.visible) {
|
|
|
|
autoSyncTimer.start()
|
|
|
|
}
|
2020-03-29 19:03:05 +03:00
|
|
|
accounts.value = tmpIDs
|
|
|
|
accounts.sync()
|
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
|
|
|
}
|
|
|
|
|
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
|
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: {
|
2020-04-05 23:59:18 +03:00
|
|
|
notesStore.getAllNotes()
|
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
|
|
|
}
|
|
|
|
|
2020-04-13 20:13:14 +03:00
|
|
|
Connections {
|
|
|
|
target: notesStore
|
|
|
|
|
|
|
|
onNoteError: {
|
|
|
|
storeErrorNotification.close()
|
|
|
|
if (error) {
|
|
|
|
console.log("Notes Store error (" + error + "): " + notesStore.errorMessage(error))
|
|
|
|
storeErrorNotification.body = notesStore.errorMessage(error)
|
|
|
|
storeErrorNotification.publish()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-10 21:40:23 +03:00
|
|
|
Connections {
|
|
|
|
target: notesApi
|
2020-03-27 01:22:45 +03:00
|
|
|
|
2020-01-03 16:00:07 +03:00
|
|
|
onNetworkAccessibleChanged: {
|
2020-04-10 21:40:23 +03:00
|
|
|
console.log("Device is " + (accessible ? "online" : "offline"))
|
2020-04-19 20:01:03 +03:00
|
|
|
if (accessible) {
|
|
|
|
offlineNotification.close(Notification.Closed)
|
|
|
|
getAllNotes()
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
offlineNotification.publish()
|
|
|
|
}
|
2020-01-03 16:00:07 +03:00
|
|
|
}
|
2020-04-13 20:13:14 +03:00
|
|
|
onNoteError: {
|
|
|
|
apiErrorNotification.close()
|
2020-04-05 23:59:18 +03:00
|
|
|
if (error)
|
2020-04-13 20:13:14 +03:00
|
|
|
console.log("Notes API error (" + error + "): " + notesApi.errorMessage(error))
|
2020-04-10 21:40:23 +03:00
|
|
|
if (error && notesApi.networkAccessible) {
|
2020-04-13 20:13:14 +03:00
|
|
|
apiErrorNotification.body = notesApi.errorMessage(error)
|
|
|
|
apiErrorNotification.publish()
|
2020-01-05 15:25:13 +03:00
|
|
|
}
|
|
|
|
}
|
2020-01-03 16:00:07 +03:00
|
|
|
onLastSyncChanged: account.update = lastSync
|
2019-11-10 05:35:33 +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")
|
|
|
|
allowedOrientations: defaultAllowedOrientations
|
|
|
|
}
|