From fc8072bb60ce875d10ad2718abacc2ad61d9b0c9 Mon Sep 17 00:00:00 2001 From: Scharel Clemens Date: Sun, 24 Feb 2019 16:40:47 +0100 Subject: [PATCH] Just some small changes. --- qml/components/NotesApi.qml | 40 +------------------------- qml/harbour-nextcloudnotes.qml | 1 + qml/pages/EditPage.qml | 5 ++-- qml/pages/NotePage.qml | 5 ++-- src/notesmodel.cpp | 17 +++++++---- src/notesmodel.h | 1 + translations/harbour-nextcloudnotes.ts | 38 ++++++++++++------------ 7 files changed, 39 insertions(+), 68 deletions(-) diff --git a/qml/components/NotesApi.qml b/qml/components/NotesApi.qml index b944b4b..0fab928 100644 --- a/qml/components/NotesApi.qml +++ b/qml/components/NotesApi.qml @@ -20,7 +20,6 @@ Item { onUuidChanged: { appSettings.currentAccount = uuid account.path = "/apps/harbour-nextcloudnotes/accounts/" + uuid - model.clear() onUuidChanged: console.log("Account : " + account.name) } /*function clear() { @@ -34,11 +33,9 @@ Item { if (data) { if (method === "POST" || method === "PUT") { console.log("Adding note...") - //addToModel(data) } else if (data.id && method === "DELETE") { console.log("Deleting note...") - //removeFromModel(data.id) } if (method === "GET" || method === "PUT" || method === "DELETE") { if (data.id) { @@ -61,43 +58,8 @@ Item { statusText = apiReq.statusText status = apiReq.status if (apiReq.status === 200) { - //console.log(apiReq.responseText) response = apiReq.responseText - var json = JSON.parse(response) - switch(method) { - case "GET": - if (Array.isArray(json)) { - console.log("Received all notes via API: " + endpoint) - model.clear() - for (var element in json) { - addToModel(json[element]) - } - account.update = new Date() - } - else { - console.log("Received a single note via API: " + endpoint) - addToModel(json) - } - break - case "POST": - console.log("Created a note via API: " + endpoint) - addToModel(json) - pageStack.push(Qt.resolvedUrl("../pages/NotePage.qml"), { note: json } ) - //pageStack.completeAnimation() - //pageStack.navigateForward() - break - case "PUT": - console.log("Updated a note via API: " + endpoint) - addToModel(json) - break - case "DELETE": - console.log("Deleted a note via API: " + endpoint) - removeFromModel(data.id) - break - default: - console.log("Unsupported method: " + method) - break - } + //console.log(response) } else if(apiReq.status === 0) { statusText = qsTr("Unable to connect") diff --git a/qml/harbour-nextcloudnotes.qml b/qml/harbour-nextcloudnotes.qml index ac48857..bc2eb85 100644 --- a/qml/harbour-nextcloudnotes.qml +++ b/qml/harbour-nextcloudnotes.qml @@ -110,6 +110,7 @@ ApplicationWindow id: api uuid: appSettings.currentAccount onResponseChanged: noteListModel.applyJSON(response) + onUuidChanged: noteListModel.clear() } NotesModel { diff --git a/qml/pages/EditPage.qml b/qml/pages/EditPage.qml index a10f505..f8eccb6 100644 --- a/qml/pages/EditPage.qml +++ b/qml/pages/EditPage.qml @@ -13,12 +13,13 @@ Dialog { } function reloadContent() { - note = api.getNote(note.id) + api.getNoteFromApi(note.id) + /*note = api.getNote(note.id) dialogHeader.title = note.title contentArea.text = note.content favoriteButton.selected = note.favorite categoryField.text = note.category - modifiedDetail.modified = note.modified + modifiedDetail.modified = note.modified*/ } SilicaFlickable { diff --git a/qml/pages/NotePage.qml b/qml/pages/NotePage.qml index 3a2c66a..deffbe5 100644 --- a/qml/pages/NotePage.qml +++ b/qml/pages/NotePage.qml @@ -50,12 +50,13 @@ Dialog { } function reloadContent() { - note = api.getNote(note.id) + api.getNoteFromApi(note.id) + /*note = api.getNote(note.id) dialogHeader.title = note.title favoriteButton.selected = note.favorite categoryField.text = note.category modifiedDetail.modified = note.modified - parseContent() + parseContent()*/ } function parseContent() { diff --git a/src/notesmodel.cpp b/src/notesmodel.cpp index c619574..d30c140 100644 --- a/src/notesmodel.cpp +++ b/src/notesmodel.cpp @@ -12,12 +12,7 @@ NotesModel::NotesModel(QObject *parent) : QAbstractListModel(parent) } NotesModel::~NotesModel() { - beginRemoveRows(QModelIndex(), 0, rowCount()); - for (int i = 0; i < m_notes.size(); i++) { - delete m_notes[i].note; - } - m_notes.clear(); - endRemoveRows(); + clear(); } void NotesModel::setSortBy(int sortBy) { @@ -147,6 +142,16 @@ bool NotesModel::removeNote(int id) { return noteRemoved; } +void NotesModel::clear() { + m_searchText.clear(); + beginRemoveRows(QModelIndex(), 0, rowCount()); + for (int i = 0; i < m_notes.size(); i++) { + delete m_notes[i].note; + } + m_notes.clear(); + endRemoveRows(); +} + void NotesModel::search(QString searchText) { if (m_searchText != searchText) { m_searchText = searchText; diff --git a/src/notesmodel.h b/src/notesmodel.h index f3da322..36a2f4f 100644 --- a/src/notesmodel.h +++ b/src/notesmodel.h @@ -31,6 +31,7 @@ public: Q_INVOKABLE bool applyJSON(QString json, bool replaceIfArray = true); Q_INVOKABLE bool removeNote(int id); + Q_INVOKABLE void clear(); Q_INVOKABLE void search(QString searchText); Q_INVOKABLE void clearSearch(); diff --git a/translations/harbour-nextcloudnotes.ts b/translations/harbour-nextcloudnotes.ts index 44f0278..ae97265 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 @@ -219,52 +219,52 @@ NotePage - + Delete - + Reload - + Updating... - + Last update - + never - + Edit - + Notes - + No category - + Category - + Modified @@ -272,17 +272,17 @@ NotesApi - + Unable to connect - + Today - + Yesterday