2018-10-16 18:50:58 +03:00
|
|
|
import QtQuick 2.0
|
|
|
|
import Sailfish.Silica 1.0
|
|
|
|
|
|
|
|
Page {
|
|
|
|
id: page
|
|
|
|
|
2018-11-18 00:28:25 +03:00
|
|
|
onStatusChanged: {
|
|
|
|
if (status === PageStatus.Active) {
|
|
|
|
if (nextcloudAccounts.count > 0) {
|
2018-11-24 21:34:01 +03:00
|
|
|
autoSyncTimer.restart()
|
2018-11-18 00:28:25 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
addAccountHint.restart()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-04 01:08:41 +03:00
|
|
|
Timer {
|
|
|
|
id: autoSyncTimer
|
|
|
|
interval: appSettings.autoSyncInterval * 1000
|
|
|
|
repeat: true
|
|
|
|
running: interval > 0 && appWindow.visible
|
|
|
|
triggeredOnStart: true
|
|
|
|
onTriggered: nextcloudAccounts.itemAt(appSettings.currentAccount).getNotes()
|
|
|
|
onIntervalChanged: console.log("Auto-Sync every " + interval / 1000 + " seconds")
|
|
|
|
}
|
|
|
|
|
2018-10-16 18:50:58 +03:00
|
|
|
SilicaListView {
|
|
|
|
id: notesList
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
PullDownMenu {
|
2018-11-18 00:28:25 +03:00
|
|
|
busy: nextcloudAccounts.itemAt(appSettings.currentAccount) ? nextcloudAccounts.itemAt(appSettings.currentAccount).busy : false
|
2018-10-22 23:53:14 +03:00
|
|
|
|
2018-10-16 18:50:58 +03:00
|
|
|
MenuItem {
|
|
|
|
text: qsTr("Settings")
|
2018-10-22 23:53:14 +03:00
|
|
|
onClicked: pageStack.push(Qt.resolvedUrl("SettingsPage.qml"))
|
2018-10-16 18:50:58 +03:00
|
|
|
}
|
|
|
|
MenuItem {
|
|
|
|
text: qsTr("Add note")
|
2018-11-24 21:34:01 +03:00
|
|
|
enabled: nextcloudAccounts.itemAt(appSettings.currentAccount) ? true : false
|
2018-11-18 00:28:25 +03:00
|
|
|
visible: appSettings.currentAccount >= 0
|
2018-12-04 13:24:07 +03:00
|
|
|
onClicked: nextcloudAccounts.itemAt(appSettings.currentAccount).createNote({'content': ""})
|
2018-10-16 18:50:58 +03:00
|
|
|
}
|
2018-11-15 00:13:47 +03:00
|
|
|
MenuItem {
|
2018-11-24 21:34:01 +03:00
|
|
|
text: enabled ? qsTr("Reload") : qsTr("Updating...")
|
2018-11-18 00:28:25 +03:00
|
|
|
enabled: nextcloudAccounts.itemAt(appSettings.currentAccount) ? !nextcloudAccounts.itemAt(appSettings.currentAccount).busy : false
|
|
|
|
visible: appSettings.currentAccount >= 0
|
|
|
|
onClicked: nextcloudAccounts.itemAt(appSettings.currentAccount).getNotes()
|
2018-11-15 00:13:47 +03:00
|
|
|
}
|
|
|
|
MenuLabel {
|
2018-11-18 00:28:25 +03:00
|
|
|
visible: appSettings.currentAccount >= 0
|
|
|
|
text: nextcloudAccounts.itemAt(appSettings.currentAccount) ? (
|
|
|
|
qsTr("Last update") + ": " + (
|
|
|
|
new Date(nextcloudAccounts.itemAt(appSettings.currentAccount).update).valueOf() !== 0 ?
|
|
|
|
new Date(nextcloudAccounts.itemAt(appSettings.currentAccount).update).toLocaleString(Qt.locale(), Locale.ShortFormat) :
|
|
|
|
qsTr("never"))) : ""
|
2018-11-15 00:13:47 +03:00
|
|
|
}
|
2018-10-16 18:50:58 +03:00
|
|
|
}
|
|
|
|
|
2018-11-18 13:25:28 +03:00
|
|
|
header: PageHeader {
|
2018-12-03 22:33:37 +03:00
|
|
|
SearchField {
|
|
|
|
id: searchField
|
|
|
|
width: parent.width
|
|
|
|
placeholderText: nextcloudAccounts.itemAt(appSettings.currentAccount).name
|
|
|
|
EnterKey.iconSource: "image://theme/icon-m-enter-close"
|
|
|
|
EnterKey.onClicked: focus = false
|
|
|
|
onTextChanged: nextcloudAccounts.itemAt(appSettings.currentAccount).search(text.toLowerCase())
|
2018-11-25 16:08:00 +03:00
|
|
|
}
|
2018-12-04 17:22:57 +03:00
|
|
|
//title: nextcloudAccounts.itemAt(appSettings.currentAccount).name //qsTr("Nextclound Notes")
|
|
|
|
description: searchField.text === "" ? nextcloudAccounts.itemAt(appSettings.currentAccount).username + "@" + nextcloudAccounts.itemAt(appSettings.currentAccount).server :
|
|
|
|
searchField.placeholderText
|
2018-10-16 18:50:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
currentIndex: -1
|
|
|
|
|
2018-11-18 00:28:25 +03:00
|
|
|
model: nextcloudAccounts.itemAt(appSettings.currentAccount)? nextcloudAccounts.itemAt(appSettings.currentAccount).model : 0
|
|
|
|
Connections {
|
|
|
|
target: appSettings
|
|
|
|
onCurrentAccountChanged: notesList.model = nextcloudAccounts.itemAt(appSettings.currentAccount)? nextcloudAccounts.itemAt(appSettings.currentAccount).model : 0
|
|
|
|
}
|
2018-10-16 18:50:58 +03:00
|
|
|
|
2018-11-25 16:08:00 +03:00
|
|
|
delegate: BackgroundItem {
|
2018-10-16 18:50:58 +03:00
|
|
|
id: note
|
2018-10-17 13:58:55 +03:00
|
|
|
contentHeight: titleLabel.height + previewLabel.height + 2*Theme.paddingSmall
|
2018-11-25 16:08:00 +03:00
|
|
|
height: contentHeight + menu.height
|
|
|
|
width: parent.width
|
|
|
|
highlighted: down || menu.active
|
2018-12-03 22:33:37 +03:00
|
|
|
/*ListView.onAdd: AddAnimation {
|
2018-11-25 16:08:00 +03:00
|
|
|
target: note
|
|
|
|
}
|
|
|
|
ListView.onRemove: RemoveAnimation {
|
|
|
|
target: note
|
2018-12-03 22:33:37 +03:00
|
|
|
}*/
|
2018-11-25 16:08:00 +03:00
|
|
|
RemorseItem {
|
|
|
|
id: remorse
|
|
|
|
}
|
2018-10-16 18:50:58 +03:00
|
|
|
|
2018-11-24 21:34:01 +03:00
|
|
|
Separator {
|
|
|
|
width: parent.width
|
|
|
|
color: Theme.primaryColor
|
|
|
|
anchors.top: titleLabel.top
|
|
|
|
visible: appSettings.showSeparator && index !== 0
|
|
|
|
}
|
|
|
|
|
2018-10-16 18:50:58 +03:00
|
|
|
IconButton {
|
|
|
|
id: isFavoriteIcon
|
2018-10-17 13:58:55 +03:00
|
|
|
anchors.left: parent.left
|
2018-10-21 02:44:23 +03:00
|
|
|
anchors.top: parent.top
|
2018-10-16 18:50:58 +03:00
|
|
|
icon.source: (favorite ? "image://theme/icon-m-favorite-selected?" : "image://theme/icon-m-favorite?") +
|
|
|
|
(note.highlighted ? Theme.secondaryHighlightColor : Theme.secondaryColor)
|
|
|
|
onClicked: {
|
2018-11-18 15:20:17 +03:00
|
|
|
nextcloudAccounts.itemAt(appSettings.currentAccount).updateNote(id, {'favorite': !favorite} )
|
2018-10-16 18:50:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Label {
|
|
|
|
id: titleLabel
|
|
|
|
anchors.left: isFavoriteIcon.right
|
|
|
|
anchors.leftMargin: Theme.paddingSmall
|
2018-11-25 16:08:00 +03:00
|
|
|
anchors.right: categoryRectangle.visible ? categoryRectangle.left : parent.right
|
2018-10-17 13:58:55 +03:00
|
|
|
anchors.top: parent.top
|
2018-10-16 18:50:58 +03:00
|
|
|
text: title
|
|
|
|
truncationMode: TruncationMode.Fade
|
|
|
|
color: note.highlighted ? Theme.highlightColor : Theme.primaryColor
|
|
|
|
}
|
|
|
|
|
2018-11-24 21:34:01 +03:00
|
|
|
Rectangle {
|
|
|
|
id: categoryRectangle
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.rightMargin: Theme.horizontalPageMargin
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.topMargin: Theme.paddingSmall
|
|
|
|
width: categoryLabel.width + Theme.paddingLarge
|
|
|
|
height: categoryLabel.height + Theme.paddingSmall
|
|
|
|
color: "transparent"
|
|
|
|
border.color: Theme.highlightColor
|
|
|
|
radius: height / 4
|
2018-11-25 16:08:00 +03:00
|
|
|
visible: appSettings.sortBy !== "category" && categoryLabel.text.length > 0
|
2018-11-24 21:34:01 +03:00
|
|
|
Label {
|
|
|
|
id: categoryLabel
|
|
|
|
anchors.centerIn: parent
|
|
|
|
text: category
|
|
|
|
color: Theme.secondaryColor
|
|
|
|
font.pixelSize: Theme.fontSizeExtraSmall
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-16 18:50:58 +03:00
|
|
|
Label {
|
2018-10-17 13:58:55 +03:00
|
|
|
id: previewLabel
|
2018-10-16 18:50:58 +03:00
|
|
|
anchors.left: isFavoriteIcon.right
|
|
|
|
anchors.leftMargin: Theme.paddingSmall
|
|
|
|
anchors.right: parent.right
|
2018-10-17 13:58:55 +03:00
|
|
|
anchors.rightMargin: Theme.horizontalPageMargin
|
|
|
|
anchors.top: titleLabel.bottom
|
2018-11-26 19:21:02 +03:00
|
|
|
text: parseText(content)
|
2018-10-16 18:50:58 +03:00
|
|
|
font.pixelSize: Theme.fontSizeExtraSmall
|
2018-10-21 02:44:23 +03:00
|
|
|
textFormat: Text.PlainText
|
2018-10-17 13:58:55 +03:00
|
|
|
wrapMode: Text.Wrap
|
|
|
|
elide: Text.ElideRight
|
2018-11-24 21:34:01 +03:00
|
|
|
maximumLineCount: appSettings.previewLineCount > 0 ? appSettings.previewLineCount : 1
|
|
|
|
visible: appSettings.previewLineCount > 0
|
2018-10-17 13:58:55 +03:00
|
|
|
color: note.highlighted ? Theme.secondaryHighlightColor : Theme.secondaryColor
|
2018-11-26 19:21:02 +03:00
|
|
|
function parseText (preText) {
|
|
|
|
var lines = preText.split('\n')
|
2018-11-24 21:34:01 +03:00
|
|
|
lines.splice(0,1);
|
2018-11-26 19:21:02 +03:00
|
|
|
var newText = lines.join('\n');
|
|
|
|
return newText.replace(/^\s*$(?:\r\n?|\n)/gm, "")
|
2018-11-24 21:34:01 +03:00
|
|
|
}
|
2018-10-16 18:50:58 +03:00
|
|
|
}
|
|
|
|
|
2018-11-25 16:08:00 +03:00
|
|
|
onClicked: pageStack.push(Qt.resolvedUrl("NotePage.qml"),
|
2018-11-30 20:40:03 +03:00
|
|
|
{ account: nextcloudAccounts.itemAt(appSettings.currentAccount),
|
|
|
|
note: nextcloudAccounts.itemAt(appSettings.currentAccount).modelData[index]} )
|
2018-11-25 16:08:00 +03:00
|
|
|
onPressAndHold: menu.open(note)
|
2018-10-17 00:52:28 +03:00
|
|
|
|
2018-11-25 16:08:00 +03:00
|
|
|
ContextMenu {
|
|
|
|
id: menu
|
|
|
|
MenuLabel {
|
2018-10-17 13:58:55 +03:00
|
|
|
id: modifiedLabel
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
text: qsTr("Modified") + ": " + new Date(modified * 1000).toLocaleString(Qt.locale(), Locale.ShortFormat)
|
2018-10-16 18:50:58 +03:00
|
|
|
}
|
|
|
|
MenuItem {
|
|
|
|
text: qsTr("Delete")
|
2018-11-18 15:11:22 +03:00
|
|
|
onClicked: {
|
2018-11-25 16:08:00 +03:00
|
|
|
remorse.execute(note, qsTr("Deleting note"), function() {
|
2018-11-18 15:11:22 +03:00
|
|
|
nextcloudAccounts.itemAt(appSettings.currentAccount).deleteNote(id)
|
|
|
|
})
|
|
|
|
}
|
2018-10-16 18:50:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-25 16:08:00 +03:00
|
|
|
section.property: appSettings.sortBy
|
|
|
|
section.criteria: appSettings.sortBy === "title" ? ViewSection.FirstCharacter : ViewSection.FullString
|
|
|
|
section.labelPositioning: appSettings.sortBy === "title" ? ViewSection.FirstCharacter : ViewSection.InlineLabels
|
2018-10-16 18:50:58 +03:00
|
|
|
section.delegate: SectionHeader {
|
2018-10-17 00:52:28 +03:00
|
|
|
text: section
|
2018-10-16 18:50:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
BusyIndicator {
|
|
|
|
id: busyIndicator
|
|
|
|
anchors.centerIn: parent
|
|
|
|
size: BusyIndicatorSize.Large
|
2018-11-25 16:08:00 +03:00
|
|
|
running: nextcloudAccounts.itemAt(appSettings.currentAccount) ? (notesList.count === 0 && nextcloudAccounts.itemAt(appSettings.currentAccount).busy) : false
|
2018-10-16 18:50:58 +03:00
|
|
|
}
|
|
|
|
|
2018-10-21 02:44:23 +03:00
|
|
|
ViewPlaceholder {
|
2018-11-24 21:34:01 +03:00
|
|
|
id: noLoginPlaceholder
|
|
|
|
enabled: nextcloudUUIDs.value.length <= 0
|
|
|
|
text: qsTr("No account yet")
|
|
|
|
hintText: qsTr("Got to the settings to add an account")
|
|
|
|
}
|
|
|
|
|
|
|
|
ViewPlaceholder {
|
|
|
|
id: noNotesPlaceholder
|
|
|
|
enabled: nextcloudAccounts.itemAt(appSettings.currentAccount) ? (nextcloudAccounts.itemAt(appSettings.currentAccount).status === 204 && !busyIndicator.running && !noLoginPlaceholder.enabled) : false
|
2018-10-22 23:53:14 +03:00
|
|
|
text: qsTr("No notes yet")
|
|
|
|
hintText: qsTr("Pull down to add a note")
|
2018-10-21 02:44:23 +03:00
|
|
|
}
|
|
|
|
|
2018-12-03 22:33:37 +03:00
|
|
|
ViewPlaceholder {
|
|
|
|
id: noSearchPlaceholder
|
|
|
|
enabled: nextcloudAccounts.itemAt(appSettings.currentAccount) ? (notesList.count === 0 && nextcloudAccounts.itemAt(appSettings.currentAccount).modelData.length > 0) : false
|
|
|
|
text: qsTr("No result")
|
|
|
|
hintText: qsTr("Try another query")
|
|
|
|
}
|
|
|
|
|
2018-11-15 00:13:47 +03:00
|
|
|
ViewPlaceholder {
|
2018-11-24 21:34:01 +03:00
|
|
|
id: errorPlaceholder
|
2018-12-03 22:33:37 +03:00
|
|
|
enabled: notesList.count === 0 && !busyIndicator.running && !noSearchPlaceholder.enabled && !noNotesPlaceholder.enabled && !noLoginPlaceholder.enabled
|
2018-11-24 21:34:01 +03:00
|
|
|
text: qsTr("An error occurred")
|
|
|
|
hintText: nextcloudAccounts.itemAt(appSettings.currentAccount).statusText
|
2018-11-15 00:13:47 +03:00
|
|
|
}
|
2018-10-22 23:53:14 +03:00
|
|
|
|
2018-11-15 00:13:47 +03:00
|
|
|
TouchInteractionHint {
|
|
|
|
id: addAccountHint
|
|
|
|
interactionMode: TouchInteraction.Pull
|
|
|
|
direction: TouchInteraction.Down
|
|
|
|
}
|
|
|
|
InteractionHintLabel {
|
|
|
|
anchors.fill: parent
|
|
|
|
text: qsTr("Open the settings to configure your Nextcloud accounts")
|
|
|
|
opacity: addAccountHint.running ? 1.0 : 0.0
|
|
|
|
Behavior on opacity { FadeAnimation {} }
|
|
|
|
width: parent.width
|
|
|
|
}
|
2018-10-22 23:53:14 +03:00
|
|
|
|
2018-11-15 00:13:47 +03:00
|
|
|
VerticalScrollDecorator { flickable: notesList }
|
|
|
|
}
|
2018-10-16 18:50:58 +03:00
|
|
|
}
|