From 5156f1e629bd7b99b448753804ac1c2c0e63e0c0 Mon Sep 17 00:00:00 2001 From: Scharel Clemens Date: Fri, 21 Jun 2019 17:49:54 +0200 Subject: [PATCH] Improved C++ NotedModel and some small visual thinks --- qml/pages/EditPage.qml | 12 +++- qml/pages/NotePage.qml | 15 ++++- qml/pages/NotesPage.qml | 16 ++++- src/notesmodel.cpp | 78 ++++++++++------------- src/notesmodel.h | 2 +- translations/harbour-nextcloudnotes-de.ts | 4 ++ translations/harbour-nextcloudnotes-sv.ts | 4 ++ translations/harbour-nextcloudnotes.ts | 59 +++++++++-------- 8 files changed, 112 insertions(+), 78 deletions(-) diff --git a/qml/pages/EditPage.qml b/qml/pages/EditPage.qml index f8eccb6..6d231aa 100644 --- a/qml/pages/EditPage.qml +++ b/qml/pages/EditPage.qml @@ -5,8 +5,16 @@ import Nemo.Notifications 1.0 Dialog { id: editDialog - //property int noteID - property var note + property int id + property int modified + property string title + property string category + property string content + property bool favorite + property string etag + property bool error + property string errorMessage + property string date onAccepted: { api.updateNote(note.id, { 'category': categoryField.text, 'content': contentArea.text, 'favorite': favoriteButton.selected } ) diff --git a/qml/pages/NotePage.qml b/qml/pages/NotePage.qml index d290614..83719a3 100644 --- a/qml/pages/NotePage.qml +++ b/qml/pages/NotePage.qml @@ -6,6 +6,8 @@ import "../js/showdown/dist/showdown.js" as ShowDown Dialog { id: noteDialog + property Note note + property int id property int modified property string title @@ -31,7 +33,17 @@ Dialog { acceptDestination: Qt.resolvedUrl("EditPage.qml") - acceptDestinationProperties: { note: note } + acceptDestinationProperties: ( + { id: id, + modified: modified, + title: title, + category: category, + content: content, + favorite: favorite, + etag: etag, + error: error, + errorMessage: errorMessage, + date: date } ) onAccepted: { acceptDestinationInstance.note = note acceptDestinationInstance.reloadContent() @@ -42,6 +54,7 @@ Dialog { } } Component.onCompleted: { + console.log(note.title) parseContent() } diff --git a/qml/pages/NotesPage.qml b/qml/pages/NotesPage.qml index 933a115..bd10784 100644 --- a/qml/pages/NotesPage.qml +++ b/qml/pages/NotesPage.qml @@ -55,7 +55,7 @@ Page { SearchField { id: searchField width: parent.width - enabled: appSettings.accountIDs.length > 0 + enabled: !busyIndicator.running && !noLoginPlaceholder.enabled && !errorPlaceholder.enabled && !noNotesPlaceholder.enabled placeholderText: account.name.length > 0 ? account.name : qsTr("Nextcloud Notes") EnterKey.iconSource: "image://theme/icon-m-enter-close" EnterKey.onClicked: focus = false @@ -103,7 +103,8 @@ Page { } onClicked: pageStack.push(Qt.resolvedUrl("../pages/NotePage.qml"), - { id: id, + { note: noteListModel.get(index), + id: id, modified: modified, title: title, category: category, @@ -220,6 +221,17 @@ Page { size: BusyIndicatorSize.Large running: notesList.count === 0 && api.busy } + Label { + id: busyLabel + anchors.top: busyIndicator.bottom + anchors.topMargin: Theme.paddingMedium + visible: busyIndicator.running + width: parent.width + color: Theme.highlightColor + font.pixelSize: Theme.fontSizeExtraLarge + horizontalAlignment: Qt.AlignHCenter + text: qsTr("Loading notes...") + } ViewPlaceholder { id: noLoginPlaceholder diff --git a/src/notesmodel.cpp b/src/notesmodel.cpp index d89d29e..9c8628b 100644 --- a/src/notesmodel.cpp +++ b/src/notesmodel.cpp @@ -57,6 +57,35 @@ void NotesModel::clearSearch() { search(); } +bool NotesModel::applyJSONobject(const QJsonObject &jobj) { + if (!jobj.isEmpty()) { + Note note = Note::fromjson(jobj); // TODO connect signals + if (!note.error()) { + int position = indexOf(note.id()); + Note oldNote = get(position); + if (position >= 0 && note.etag() != oldNote.etag()) { + qDebug() << "-- Existing note " << note.title() << "changed, updating the model."; + replaceNote(note); + } + else if (position < 0) { + qDebug() << "-- New note" << note.title() << ", adding it to the model."; + insertNote(note); + } + else { + qDebug() << "-- Existing note " << note.title() << "unchanged, nothing to do."; + } + } + else { + qDebug() << "Note contains an error:" << note.errorMessage(); + } + } + else { + qDebug() << "Unknown JSON object. This message should never occure!"; + return false; + } + return true; +} + bool NotesModel::applyJSON(const QString &json) { qDebug() << "Applying new JSON input";// << json; QJsonParseError error; @@ -70,55 +99,14 @@ bool NotesModel::applyJSON(const QString &json) { QJsonValue jval = jarr.first(); if (jval.isObject()) { //qDebug() << "It's an object, all fine..."; - QJsonObject jobj = jval.toObject(); - if (!jobj.isEmpty()) { - //qDebug() << "Adding it to the model..."; - Note note = Note::fromjson(jobj); // TODO connect signals - if (!note.error()) { - int position = indexOf(note.id()); - Note oldNote = get(position); - if (position >= 0 && note.etag() != oldNote.etag()) { - qDebug() << "-- Existing note " << note.title() << "changed, updating the model..."; - replaceNote(note); - } - else if (position < 0) { - qDebug() << "-- New note" << note.title() << ", adding it to the model..."; - insertNote(note); - } - //qDebug() << "Adding note"<< note.title << "on position" << position; - //beginInsertRows(QModelIndex(), position, position); - //m_notes.insert(position, note); - //endInsertRows(); - } - else { - qDebug() << "Note contains an error:" << note.errorMessage(); - } - } - else { - qDebug() << "Unknown JSON object. This message should never occure!"; - } + applyJSONobject(jval.toObject()); } jarr.pop_front(); } } else if (jdoc.isObject()) { - qDebug() << "It's a single object..."; - QJsonObject jobj = jdoc.object(); - if (!jobj.isEmpty() && !jobj.value(roleNames()[ErrorRole]).toBool(true)) { - Note note = Note::fromjson(jobj); // TODO connect signals - int position = indexOf(note.id()); - if (position >= 0) { - m_notes[position].note = note; - } - else { - position = insertPosition(note); - ModelNote noteToInsert; - noteToInsert.note = note; noteToInsert.param = true; - beginInsertRows(index(position), position, position); - m_notes.insert(position, noteToInsert); - endInsertRows(); - } - } + qDebug() << "- It's a single object..."; + return applyJSONobject(jdoc.object()); } else { qDebug() << "Unknown JSON document. This message should never occure!"; @@ -127,7 +115,7 @@ bool NotesModel::applyJSON(const QString &json) { } else { - qDebug() << error.errorString(); + qDebug() << "Unable to parse the JSON input:" << error.errorString(); } return error.error == QJsonParseError::NoError; } diff --git a/src/notesmodel.h b/src/notesmodel.h index 36258bc..e18ff43 100644 --- a/src/notesmodel.h +++ b/src/notesmodel.h @@ -95,7 +95,7 @@ private: void sort(); //void update(); - //void insertJnote(const QJsonObject &jobj); + bool applyJSONobject(const QJsonObject &jobj); int insertPosition(const Note &n) const; bool noteLessThan(const Note &n1, const Note &n2) const; /*static bool noteLessThanByDate(const Note &n1, const Note &n2); diff --git a/translations/harbour-nextcloudnotes-de.ts b/translations/harbour-nextcloudnotes-de.ts index 5ad36d2..9d87965 100644 --- a/translations/harbour-nextcloudnotes-de.ts +++ b/translations/harbour-nextcloudnotes-de.ts @@ -313,6 +313,10 @@ Deleting note Lösche Notiz + + Loading notes... + + SettingsPage diff --git a/translations/harbour-nextcloudnotes-sv.ts b/translations/harbour-nextcloudnotes-sv.ts index eac464a..58d885b 100644 --- a/translations/harbour-nextcloudnotes-sv.ts +++ b/translations/harbour-nextcloudnotes-sv.ts @@ -313,6 +313,10 @@ Deleting note Tar bort anteckning + + Loading notes... + + SettingsPage diff --git a/translations/harbour-nextcloudnotes.ts b/translations/harbour-nextcloudnotes.ts index 750166b..d5baf70 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 @@ -232,52 +232,52 @@ NotePage - + Delete - + Reload - + Updating... - + Last update - + never - + Edit - + Notes - + No category - + Category - + Modified @@ -328,57 +328,62 @@ - + Modified - + Delete - + Deleting note - + + Loading notes... + + + + No account yet - + Got to the settings to add an account - + No notes yet - + Pull down to add a note - + No result - + Try another query - + An error occurred - + Open the settings to configure your Nextcloud accounts