diff --git a/qml/pages/EditPage.qml b/qml/pages/EditPage.qml index 08d4da2..89f89b5 100644 --- a/qml/pages/EditPage.qml +++ b/qml/pages/EditPage.qml @@ -6,6 +6,18 @@ Dialog { id: editDialog property int id + property var note + + onIdChanged: note = notesModel.getNoteById(id) + onNoteChanged: { + dialogHeader.title = note["title"] + contentArea.text = note["content"] + favoriteButton.selected = note["favorite"] + categoryField.text = note["category"] + modifiedDetail.modified = note["modified"] + //parseContent() + } + property int modified property string title property string category @@ -19,16 +31,6 @@ Dialog { notesApi.updateNote(id, { 'category': categoryField.text, 'content': contentArea.text, 'favorite': favoriteButton.selected, 'modified': new Date().valueOf() / 1000 } ) } - function reloadContent() { - //notesApi.getNoteFromApi(id) - /*note = notesApi.getNote(id) - dialogHeader.title = title - contentArea.text = content - favoriteButton.selected = favorite - categoryField.text = category - modifiedDetail.modified = modified*/ - } - SilicaFlickable { anchors.fill: parent contentHeight: mainColumn.height + Theme.paddingLarge @@ -169,8 +171,8 @@ Dialog { DetailItem { id: modifiedDetail label: qsTr("Modified") - property int modified//: modified - value: new Date(modified * 1000).toLocaleString(Qt.locale(), Locale.ShortFormat) + property int modified + onModifiedChanged: value = new Date(modified * 1000).toLocaleString(Qt.locale(), Locale.ShortFormat) } } diff --git a/qml/pages/LoginPage.qml b/qml/pages/LoginPage.qml index 3d4fc79..47fe0f8 100644 --- a/qml/pages/LoginPage.qml +++ b/qml/pages/LoginPage.qml @@ -1,4 +1,4 @@ -import QtQuick 2.5 +import QtQuick 2.2 import Sailfish.Silica 1.0 import Nemo.Configuration 1.0 diff --git a/qml/pages/NotePage.qml b/qml/pages/NotePage.qml index e4aaa36..d2617a2 100644 --- a/qml/pages/NotePage.qml +++ b/qml/pages/NotePage.qml @@ -1,4 +1,4 @@ -import QtQuick 2.5 +import QtQuick 2.2 import Sailfish.Silica 1.0 import "../js/showdown/dist/showdown.js" as ShowDown @@ -6,8 +6,22 @@ Dialog { id: noteDialog property int id - //property var note: notesProxyModel.getNote(notesProxyModel.index(index, 0)) - property var note: notesModel.getNoteById(id) + property var note + + onIdChanged: note = notesModel.getNoteById(id) + onNoteChanged: { + if (note["content"].split('\n')[0].indexOf(note["title"]) > 0) { + dialogHeader.title = "" + } + else { + dialogHeader.title = note["title"] + } + favoriteButton.selected = note["favorite"] + categoryField.text = note["category"] + modifiedDetail.modified = note["modified"] + parseContent() + } + Connections { target: notesModel onNoteUpdated: { @@ -17,6 +31,18 @@ Dialog { } } + acceptDestination: Qt.resolvedUrl("EditPage.qml") + onAcceptPendingChanged: { + if (acceptPending) + acceptDestinationInstance.id = id + } + onStatusChanged: { + if (status === PageStatus.Activating) { + notesModel.getNote(id) + } + } + + property var showdown: ShowDown.showdown property var converter: new showdown.Converter( { simplifiedAutoLink: true, @@ -29,57 +55,7 @@ Dialog { simpleLineBreaks: true, emoji: true } ) - - acceptDestination: Qt.resolvedUrl("EditPage.qml") - acceptDestinationProperties: ( - { id: id, - modified: modified, - title: title, - category: category, - content: content, - favorite: favorite, - etag: etag, - error: error, - errorMessage: errorMessage - } ) - onAccepted: { - //acceptDestinationInstance.note = note - acceptDestinationInstance.reloadContent() - } - onStatusChanged: { - if (status === DialogStatus.Opened) { - //notesApi.getNoteFromApi(id) - } - } - Component.onCompleted: { - parseContent() - } - Connections { - target: notesProxyModel - onDataChanged: { - console.log(topLeft, bottomRight, index) - if (notesProxyModel.index(topLeft, bottomRight) === index) { - console.log("This note changed") - } - else { - console.log("Another note changed") - } - } - } - - - function reloadContent() { - //notesApi.getNoteFromApi(id) - /*note = notesApi.getNote(id) - dialogHeader.title = title - favoriteButton.selected = favorite - categoryField.text = category - modifiedDetail.modified = modified - parseContent()*/ - } - function parseContent() { - //note = notesApi.getNoteFromApi(id, false) var convertedText = converter.makeHtml(note["content"]) var occurence = -1 convertedText = convertedText.replace(/^
  • (

    )?\[ \] (.*)(<.*)$/gmi, @@ -130,6 +106,11 @@ Dialog { enabled: !notesApi.busy onClicked: notesApi.getNote(note["id"]) } + /*MenuItem { + text: qsTr("Edit") + onClicked: pageStack.push(Qt.resolvedUrl("../pages/NotePage.qml"), { id: id } ) + }*/ + MenuLabel { visible: appSettings.currentAccount.length >= 0 text: qsTr("Last update") + ": " + ( @@ -141,7 +122,6 @@ Dialog { DialogHeader { id: dialogHeader - //title: noteDialog.title acceptText: qsTr("Edit") cancelText: qsTr("Notes") } @@ -157,12 +137,6 @@ Dialog { width: parent.width spacing: Theme.paddingLarge - /*Separator { - width: parent.width - color: Theme.primaryColor - horizontalAlignment: Qt.AlignHCenter - }*/ - LinkedLabel { id: contentLabel x: Theme.horizontalPageMargin @@ -251,7 +225,7 @@ Dialog { width: parent.width - x IconButton { id: favoriteButton - property bool selected: note["favorite"] + property bool selected: false width: Theme.iconSizeMedium icon.source: (selected ? "image://theme/icon-m-favorite-selected?" : "image://theme/icon-m-favorite?") + (favoriteButton.highlighted ? Theme.secondaryHighlightColor : Theme.secondaryColor) @@ -262,7 +236,6 @@ Dialog { TextField { id: categoryField width: parent.width - favoriteButton.width - text: note["category"] placeholderText: qsTr("No category") label: qsTr("Category") EnterKey.iconSource: "image://theme/icon-m-enter-accept" @@ -270,7 +243,7 @@ Dialog { categoryField.focus = false } onFocusChanged: { - if (focus === false && text !== category) { + if (focus === false && text !== note["category"]) { notesApi.updateNote(id, {'content': content, 'category': text, 'modified': new Date().valueOf() / 1000}) // This does not seem to work without adding the content } } @@ -280,7 +253,8 @@ Dialog { DetailItem { id: modifiedDetail label: qsTr("Modified") - value: new Date(note["modified"] * 1000).toLocaleString(Qt.locale(), Locale.ShortFormat) + property int modified + onModifiedChanged: value = new Date(modified * 1000).toLocaleString(Qt.locale(), Locale.ShortFormat) } } diff --git a/qml/pages/NotesPage.qml b/qml/pages/NotesPage.qml index 6c6425d..b2835d2 100644 --- a/qml/pages/NotesPage.qml +++ b/qml/pages/NotesPage.qml @@ -106,7 +106,7 @@ Page { id: remorse } - onClicked: pageStack.push(Qt.resolvedUrl("../pages/NotePage.qml"), { id: id } ) + onClicked: pageStack.push(Qt.resolvedUrl("NotePage.qml"), { id: id } ) onPressAndHold: menu.open(note) Separator { diff --git a/src/notesmodel.cpp b/src/notesmodel.cpp index ce6be79..691b2e1 100644 --- a/src/notesmodel.cpp +++ b/src/notesmodel.cpp @@ -130,8 +130,8 @@ void NotesModel::setAccount(const QString &account) { mp_notesStore->setAccount(account); } -const QJsonObject NotesModel::getNoteById(const int id) const { - return m_notes[id]; +const QVariantMap NotesModel::getNoteById(const int id) const { + return m_notes[id].toVariantMap(); } bool NotesModel::getAllNotes(const QStringList &exclude) { @@ -197,6 +197,12 @@ void NotesModel::insert(const int id, const QJsonObject& note) { //emit noteInserted(id, note); qDebug() << "Note inserted"; } + if (sender() == mp_notesApi) { + // TODO + } + if (sender() == mp_notesStore) { + // TODO + } } void NotesModel::update(const int id, const QJsonObject ¬e) { @@ -216,6 +222,12 @@ void NotesModel::update(const int id, const QJsonObject ¬e) { qDebug() << "Note changed"; } } + if (sender() == mp_notesApi) { + // TODO + } + if (sender() == mp_notesStore) { + // TODO + } } void NotesModel::remove(const int id) { @@ -230,6 +242,12 @@ void NotesModel::remove(const int id) { } endRemoveRows(); } + if (sender() == mp_notesApi) { + // TODO + } + if (sender() == mp_notesStore) { + // TODO + } } void NotesModel::clear() { diff --git a/src/notesmodel.h b/src/notesmodel.h index 33adb2a..cae242f 100644 --- a/src/notesmodel.h +++ b/src/notesmodel.h @@ -72,7 +72,7 @@ public: QString account() const; void setAccount(const QString& account); - const QJsonObject getNoteById(const int id) const; + Q_INVOKABLE const QVariantMap getNoteById(const int id) const; public slots: Q_INVOKABLE bool getAllNotes(const QStringList& exclude = QStringList()); diff --git a/src/notesstore.cpp b/src/notesstore.cpp index e61c69e..7ddf9c6 100644 --- a/src/notesstore.cpp +++ b/src/notesstore.cpp @@ -191,7 +191,8 @@ bool NotesStore::getNote(const int id, const QStringList& exclude) { } bool NotesStore::createNote(const QJsonObject& note) { -/* qDebug() << "Creating note: " << id; + int id = note.value("id").toInt(-1); + qDebug() << "Creating note: " << id; if (id < 0) { // TODO probably crate files with an '.json..new' extension qDebug() << "Creating notes without the server API is not supported yet!"; @@ -204,7 +205,7 @@ bool NotesStore::createNote(const QJsonObject& note) { } else { qDebug() << "Note already exists"; - }*/ + } return false; } diff --git a/translations/harbour-nextcloudnotes.ts b/translations/harbour-nextcloudnotes.ts index e743e58..c282d52 100644 --- a/translations/harbour-nextcloudnotes.ts +++ b/translations/harbour-nextcloudnotes.ts @@ -84,32 +84,32 @@ EditPage - + Reset - + Markdown syntax - + No content - + No category - + Category - + Modified @@ -143,17 +143,17 @@ - + Username - + Password - + Abort @@ -179,57 +179,57 @@ - + Enforce legacy login - + Login - + Re-Login - + Test Login - + Note - + The <a href="https://apps.nextcloud.com/apps/notes">Notes</a> app needs to be installed on the Nextcloud server for this app to work. - + Security - + <strong>CAUTION: Your password will be saved without any encryption on the device!</strong><br>Please consider creating a dedicated app password! Open your Nextcloud in a browser and go to <i>Settings</i> → <i>Security</i>. - + Do not check certificates - + Enable this option to allow selfsigned certificates - + Allow unencrypted connections @@ -263,52 +263,52 @@ NotePage - + Delete - + Reload - + Updating... - + Last update - + never - + Edit - + Notes - + No category - + Category - + Modified