From 829660271af665816e7b69cfa1808aa69d8787df Mon Sep 17 00:00:00 2001 From: scharel Date: Fri, 9 Jul 2021 08:27:42 +0200 Subject: [PATCH] Remove Notes array in NotesApp class as the NotesModel hadles it. --- qml/harbour-nextcloudnotes.qml | 2 +- src/apps/notes/notesapp.cpp | 49 +++++++--------------------------- src/apps/notes/notesapp.h | 3 --- 3 files changed, 10 insertions(+), 44 deletions(-) diff --git a/qml/harbour-nextcloudnotes.qml b/qml/harbour-nextcloudnotes.qml index a49de71..7b565dd 100644 --- a/qml/harbour-nextcloudnotes.qml +++ b/qml/harbour-nextcloudnotes.qml @@ -80,8 +80,8 @@ ApplicationWindow Connections { target: appSettings onCurrentAccountChanged: { - console.log("Current account: " + account.username + "@" + account.url) account.path = appSettings.path + "/accounts/" + appSettings.currentAccount + console.log("Current account: " + account.username + "@" + account.url) notesApp.model().account = appSettings.currentAccount } } diff --git a/src/apps/notes/notesapp.cpp b/src/apps/notes/notesapp.cpp index 2f14b44..03b64e3 100644 --- a/src/apps/notes/notesapp.cpp +++ b/src/apps/notes/notesapp.cpp @@ -46,12 +46,12 @@ bool NotesApp::getAllNotes(const QStringList& exclude) { QNetworkReply* reply = m_api->get(QString(NOTES_APP_ENDPOINT).append("/notes"), query); if (reply->error() == QNetworkReply::NoError) { m_replies << reply; - return true; } else { reply->deleteLater(); return false; } + return true; } bool NotesApp::getNote(const int id) { @@ -59,94 +59,63 @@ bool NotesApp::getNote(const int id) { QNetworkReply* reply = m_api->get(QString(NOTES_APP_ENDPOINT).append("/notes/%1").arg(id)); if (reply->error() == QNetworkReply::NoError) { m_replies << reply; - return true; } else { reply->deleteLater(); return false; } + return true; } bool NotesApp::createNote(const QJsonObject& note, bool local) { qDebug() << "Creating note"; QJsonValue value = QJsonValue(note); - if (!m_notes.contains(value)) { - m_notes.append(value); - } if (!local) { QNetworkReply* reply = m_api->post(QString(NOTES_APP_ENDPOINT).append("/notes"), QJsonDocument(note).toJson()); if (reply->error() == QNetworkReply::NoError) { m_replies << reply; - return true; } else { reply->deleteLater(); return false; } } + // TODO update model + m_notesModel.insert(-1, note); return true; } bool NotesApp::updateNote(const int id, const QJsonObject& note, bool local) { qDebug() << "Updating note:" << id; - bool done = true; - if (!m_notes.contains(QJsonValue(note))) { - done = false; - QJsonArray::iterator i; - for (i = m_notes.begin(); i != m_notes.end() && !done; ++i) { - QJsonObject localNote = i->toObject(); - int localId = localNote.value("id").toInt(-1); - if (localId > 0) { - if (localId == id) { - *i = QJsonValue(note); - done = true; - } - } - else { - if (localNote.value("content") == note.value("content")) { - *i = QJsonValue(note); - done = true; - } - } - } - } if (!local) { QNetworkReply* reply = m_api->put(QString(NOTES_APP_ENDPOINT).append("/notes/%1").arg(id), QJsonDocument(note).toJson()); if (reply->error() == QNetworkReply::NoError) { m_replies << reply; - return true; + // TODO update model } else { reply->deleteLater(); return false; } } - return done; + m_notesModel.update(-1, note); + return true; } bool NotesApp::deleteNote(const int id, bool local) { qDebug() << "Deleting note: " << id; - bool done = false; - QJsonArray::iterator i; - for (i = m_notes.begin(); i != m_notes.end() && !done; ++i) { - QJsonObject localNote = i->toObject(); - if (localNote.value("id").toInt() == id) { - m_notes.erase(i); - done = true; - } - } if (!local) { QNetworkReply* reply = m_api->del(QString(NOTES_APP_ENDPOINT).append("/notes/%1").arg(id)); if (reply->error() == QNetworkReply::NoError) { m_replies << reply; - return true; } else { reply->deleteLater(); return false; } } - return done; + m_notesModel.remove(id); + return false; } void NotesApp::updateReply(QNetworkReply* reply) { diff --git a/src/apps/notes/notesapp.h b/src/apps/notes/notesapp.h index 7bf7b84..1529f12 100644 --- a/src/apps/notes/notesapp.h +++ b/src/apps/notes/notesapp.h @@ -59,9 +59,6 @@ private: NotesModel m_notesModel; NotesProxyModel m_notesProxy; - - QJsonArray m_notes; - QJsonObject m_settings; }; #endif // NOTESAPP_H