2018-10-16 18:50:58 +03:00
|
|
|
import QtQuick 2.0
|
|
|
|
import Sailfish.Silica 1.0
|
|
|
|
import Nemo.Configuration 1.0
|
2018-12-29 03:40:11 +03:00
|
|
|
import harbour.nextcloudnotes.notesmodel 1.0
|
|
|
|
import harbour.nextcloudnotes.sslconfiguration 1.0
|
2018-10-16 18:50:58 +03:00
|
|
|
import "pages"
|
2018-12-20 20:53:29 +03:00
|
|
|
import "components"
|
2018-10-16 18:50:58 +03:00
|
|
|
|
|
|
|
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
|
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)
|
|
|
|
property bool unsecureConnection: account.value("unsecureConnection", false, Boolean)
|
|
|
|
property bool unencryptedConnection: account.value("unencryptedConnection", false, Boolean)
|
|
|
|
property date update: value("update", "", Date)
|
|
|
|
onValuesChanged: console.log("A property of the current account has changed")
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2018-12-07 02:30:18 +03:00
|
|
|
property string currentAccount: value("currentAccount", "")
|
|
|
|
property var accountIDs: value("accountIDs", [ ])
|
2018-11-24 21:34:01 +03:00
|
|
|
property int autoSyncInterval: value("autoSyncInterval", 0)
|
|
|
|
property int previewLineCount: value("previewLineCount", 4)
|
2018-12-27 22:38:14 +03:00
|
|
|
property bool favoritesOnTop: value("favoritesOnTop", true, Boolean)
|
2019-01-26 20:09:28 +03:00
|
|
|
property string sortBy: value("sortBy", "date", 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: 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);
|
|
|
|
});
|
|
|
|
}
|
2018-11-15 00:13:47 +03:00
|
|
|
}
|
|
|
|
|
2018-12-23 03:59:01 +03:00
|
|
|
SslConfiguration {
|
|
|
|
id: ssl
|
2018-12-27 22:38:14 +03:00
|
|
|
checkCert: !account.unsecureConnection
|
2018-12-23 03:59:01 +03:00
|
|
|
}
|
|
|
|
|
2018-12-07 02:30:18 +03:00
|
|
|
Timer {
|
|
|
|
id: autoSyncTimer
|
|
|
|
interval: appSettings.autoSyncInterval * 1000
|
|
|
|
repeat: true
|
|
|
|
running: interval > 0 && appWindow.visible
|
|
|
|
triggeredOnStart: true
|
|
|
|
onTriggered: {
|
|
|
|
if (!api.busy) {
|
2018-12-20 20:53:29 +03:00
|
|
|
api.getNotesFromApi()
|
2018-12-07 02:30:18 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
triggeredOnStart = false
|
|
|
|
restart()
|
|
|
|
triggeredOnStart = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
onIntervalChanged: console.log("Auto-Sync every " + interval / 1000 + " seconds")
|
|
|
|
}
|
|
|
|
|
|
|
|
NotesApi {
|
|
|
|
id: api
|
|
|
|
uuid: appSettings.currentAccount
|
2019-01-29 01:15:53 +03:00
|
|
|
onResponseChanged: noteListModel.applyJSON(response)
|
2019-02-24 18:40:47 +03:00
|
|
|
onUuidChanged: noteListModel.clear()
|
2018-12-07 02:30:18 +03:00
|
|
|
}
|
|
|
|
|
2019-01-29 01:15:53 +03:00
|
|
|
NotesModel {
|
2019-01-26 20:09:28 +03:00
|
|
|
id: noteListModel
|
2019-01-29 01:15:53 +03:00
|
|
|
sortBy: 0 // TODO
|
2019-01-26 20:09:28 +03:00
|
|
|
favoritesOnTop: appSettings.favoritesOnTop
|
2019-01-29 01:15:53 +03:00
|
|
|
}
|
2019-01-26 20:09:28 +03:00
|
|
|
|
2019-01-29 01:15:53 +03:00
|
|
|
/*NoteDelegateModel {
|
2018-12-27 22:38:14 +03:00
|
|
|
id: noteListModel
|
|
|
|
model: api.model
|
|
|
|
favoritesOnTop: appSettings.favoritesOnTop
|
|
|
|
sortBy: appSettings.sortBy
|
|
|
|
showSeparator: appSettings.showSeparator
|
|
|
|
previewLineCount: appSettings.previewLineCount
|
2019-01-29 01:15:53 +03:00
|
|
|
}*/
|
2018-12-27 22:38:14 +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
|
|
|
|
}
|