diff --git a/qml/components/NotesApi.qml b/qml/components/NotesApi.qml index df5354f..cc8e8a8 100644 --- a/qml/components/NotesApi.qml +++ b/qml/components/NotesApi.qml @@ -5,6 +5,7 @@ import Nemo.Configuration 1.0 Item { property string uuid + property string response property var model: ListModel { } property var categories: [ ] property string file: StandardPaths.data + "/" + uuid + ".json" @@ -67,7 +68,8 @@ Item { status = apiReq.status if (apiReq.status === 200) { //console.log(apiReq.responseText) - var json = JSON.parse(apiReq.responseText) + response = apiReq.responseText + var json = JSON.parse(response) switch(method) { case "GET": if (Array.isArray(json)) { diff --git a/qml/harbour-nextcloudnotes.qml b/qml/harbour-nextcloudnotes.qml index 673d884..a828145 100644 --- a/qml/harbour-nextcloudnotes.qml +++ b/qml/harbour-nextcloudnotes.qml @@ -39,7 +39,7 @@ ApplicationWindow property int autoSyncInterval: value("autoSyncInterval", 0) property int previewLineCount: value("previewLineCount", 4) property bool favoritesOnTop: value("favoritesOnTop", true, Boolean) - property string sortBy: value("sortBy", "date", Date) + property string sortBy: value("sortBy", "date", String) property bool showSeparator: value("showSeparator", false, Boolean) property bool useMonoFont: value("useMonoFont", false, Boolean) property bool useCapitalX: value("useCapitalX", false, Boolean) @@ -109,8 +109,15 @@ ApplicationWindow NotesApi { id: api uuid: appSettings.currentAccount + //onResponseChanged: noteListModel.applyJSON(response) } + /*NotesModel { + id: noteListModel + sortBy: 0 + favoritesOnTop: appSettings.favoritesOnTop + }*/ + NoteDelegateModel { id: noteListModel model: api.model diff --git a/qml/pages/SettingsPage.qml b/qml/pages/SettingsPage.qml index f579f93..ba969df 100644 --- a/qml/pages/SettingsPage.qml +++ b/qml/pages/SettingsPage.qml @@ -63,7 +63,7 @@ Page { checked: modelData === api.uuid onClicked: { api.uuid = modelData - api.getNotes() + api.getNotesFromApi() } onPressAndHold: openMenu() } diff --git a/src/notesmodel.cpp b/src/notesmodel.cpp index 7762ce9..e0e393e 100644 --- a/src/notesmodel.cpp +++ b/src/notesmodel.cpp @@ -2,6 +2,7 @@ #include #include #include +#include const QHash noteRoles = QHash{ {NotesModel::visible, "visible"}, @@ -104,28 +105,35 @@ void NotesModel::setFavoritesOnTop(bool favoritesOnTop) { } bool NotesModel::applyJSON(QString json, bool replaceIfArray) { + qDebug() << "Applying JSON...";// << json; QJsonDocument jdoc = QJsonDocument::fromJson(json.toUtf8()); int notesModified = 0; if (!jdoc.isNull()) { if (jdoc.isArray()) { + qDebug() << "It's an array..."; QJsonArray jarr = jdoc.array(); QList notesToRemove; QList > notesToAdd; for (int i = 0; i < m_notes.size(); i++) notesToRemove << i; while (!jarr.empty()) { + qDebug() << jarr.count() << "JSON Objects to handle..."; QJsonValue jval = jarr.first(); if (jval.isObject()) { + qDebug() << "It's an object, all fine..."; QJsonObject jobj = jval.toObject(); if (!jobj.isEmpty() && !jobj.value(noteRoles[errorRole]).toBool(true)) { + qDebug() << "Adding it to the model..."; Note note = Note::fromjson(jobj); int position = indexOf(note.id); if (position >= 0 && replaceIfArray) { + qDebug() << "Replacing note" << note.title << "on position" << position; m_notes[position].note = note; emit dataChanged(index(position), index(position)); notesToRemove.removeAt(position); } else { + qDebug() << "New note" << note.title << "adding it to the notes to add..."; position = insertPosition(note); //beginInsertRows(QModelIndex(), position, position); ModelNote noteToAdd; @@ -136,23 +144,30 @@ bool NotesModel::applyJSON(QString json, bool replaceIfArray) { } notesModified++; } + else { + qDebug() << "Something is wrong, skipping it..."; + } } jarr.pop_front(); } - for (int i = 0; i < notesToRemove.size(); i++) { + // TODO the current implementation does not respect the changement of the index + /*for (int i = 0; i < notesToRemove.size(); i++) { + qDebug() << "Removing note" << m_notes[notesToRemove[i]].note.title; beginRemoveRows(QModelIndex(), notesToRemove[i], notesToRemove[i]); m_notes.removeAt(notesToRemove[i]); endRemoveRows(); - } + }*/ for (int i = 0; i < notesToAdd.size(); i++) { beginInsertRows(QModelIndex(), notesToAdd[i].param, notesToAdd[i].param); ModelNote note; note.note = notesToAdd[i].note; + qDebug() << "Adding note"<< note.note.title; m_notes.insert(notesToAdd[i].param, note); endInsertRows(); } } else if (jdoc.isObject()) { + qDebug() << "It's a single object..."; QJsonObject jobj = jdoc.object(); if (!jobj.isEmpty() && !jobj.value(noteRoles[errorRole]).toBool(true)) { Note note; diff --git a/translations/harbour-nextcloudnotes.ts b/translations/harbour-nextcloudnotes.ts index 49b7fdb..58b9687 100644 --- a/translations/harbour-nextcloudnotes.ts +++ b/translations/harbour-nextcloudnotes.ts @@ -272,17 +272,17 @@ NotesApi - + Unable to connect - + Today - + Yesterday