From 84d720c7cacc1bfa82dd8f4e3d03d07066b74a82 Mon Sep 17 00:00:00 2001 From: Scharel Clemens Date: Mon, 20 Apr 2020 22:48:56 +0200 Subject: [PATCH] Connected signals and slots throught the NotesModel, so this can later handle the synchronisation --- harbour-nextcloudnotes.pro | 1 + src/harbour-nextcloudnotes.cpp | 8 +- src/notesapi.cpp | 15 +- src/notesapi.h | 15 +- src/notesinterface.h | 36 +++++ src/notesmodel.cpp | 144 +++++++++++++------ src/notesmodel.h | 43 ++++-- src/notesstore.cpp | 187 +++++++++++++------------ src/notesstore.h | 23 +-- translations/harbour-nextcloudnotes.ts | 12 +- 10 files changed, 308 insertions(+), 176 deletions(-) create mode 100644 src/notesinterface.h diff --git a/harbour-nextcloudnotes.pro b/harbour-nextcloudnotes.pro index 9b6c178..c35f7a9 100644 --- a/harbour-nextcloudnotes.pro +++ b/harbour-nextcloudnotes.pro @@ -18,6 +18,7 @@ DEFINES += APP_VERSION=\\\"$$VERSION\\\" HEADERS += src/note.h \ src/notesapi.h \ + src/notesinterface.h \ src/notesmodel.h \ src/notesstore.h diff --git a/src/harbour-nextcloudnotes.cpp b/src/harbour-nextcloudnotes.cpp index 4a781f8..697441d 100644 --- a/src/harbour-nextcloudnotes.cpp +++ b/src/harbour-nextcloudnotes.cpp @@ -29,11 +29,13 @@ int main(int argc, char *argv[]) NotesStore* notesStore = new NotesStore; NotesApi* notesApi = new NotesApi; + notesModel->setNotesApi(notesApi); + notesModel->setNotesStore(notesStore); //QObject::connect(notesApi, SIGNAL(allNotesReceived(QList)), notesModel, SLOT()); - QObject::connect(notesApi, SIGNAL(noteCreated(int,QJsonObject)), notesModel, SLOT(insertNoteFromApi(int,QJsonObject))); - QObject::connect(notesApi, SIGNAL(noteUpdated(int,QJsonObject)), notesModel, SLOT(updateNoteFromApi(int,QJsonObject))); - QObject::connect(notesApi, SIGNAL(noteDeleted(int)), notesModel, SLOT(removeNoteFromApi(int))); + //QObject::connect(notesApi, SIGNAL(noteCreated(int,QJsonObject)), notesModel, SLOT(insertNoteFromApi(int,QJsonObject))); + //QObject::connect(notesApi, SIGNAL(noteUpdated(int,QJsonObject)), notesModel, SLOT(updateNoteFromApi(int,QJsonObject))); + //QObject::connect(notesApi, SIGNAL(noteDeleted(int)), notesModel, SLOT(removeNoteFromApi(int))); //QObject::connect(notesApi, SIGNAL(noteUpdated(int,QJsonObject)), notesStore, SLOT(updateNote(int,QJsonObject))); //QObject::connect(notesApi, SIGNAL(noteDeleted(int)), notesStore, SLOT(deleteNote(int))); diff --git a/src/notesapi.cpp b/src/notesapi.cpp index ba39b32..92da406 100644 --- a/src/notesapi.cpp +++ b/src/notesapi.cpp @@ -7,7 +7,7 @@ #include NotesApi::NotesApi(const QString statusEndpoint, const QString loginEndpoint, const QString ocsEndpoint, const QString notesEndpoint, QObject *parent) - : QObject(parent), m_statusEndpoint(statusEndpoint), m_loginEndpoint(loginEndpoint), m_ocsEndpoint(ocsEndpoint), m_notesEndpoint(notesEndpoint) + : m_statusEndpoint(statusEndpoint), m_loginEndpoint(loginEndpoint), m_ocsEndpoint(ocsEndpoint), m_notesEndpoint(notesEndpoint) { // TODO verify connections (also in destructor) m_loginPollTimer.setInterval(POLL_INTERVALL); @@ -42,6 +42,17 @@ NotesApi::~NotesApi() { disconnect(&m_manager, SIGNAL(sslErrors(QNetworkReply*,QList)), this, SLOT(sslError(QNetworkReply*,QList))); } +QString NotesApi::account() const { + return m_account; +} + +void NotesApi::setAccount(const QString &account) { + if (account != m_account) { + m_account = account; + emit accountChanged(account); + } +} + bool NotesApi::getAllNotes(const QStringList& exclude) { qDebug() << "Getting all notes"; QUrl url = apiEndpointUrl(m_notesEndpoint); @@ -597,7 +608,7 @@ void NotesApi::updateApiNotes(const QJsonArray &json) { } } } - emit allNotesReceived(ids); + emit allNotesChanged(ids); } void NotesApi::updateApiNote(const QJsonObject &json) { diff --git a/src/notesapi.h b/src/notesapi.h index 1f24390..97a9bc3 100644 --- a/src/notesapi.h +++ b/src/notesapi.h @@ -10,6 +10,8 @@ #include #include +#include "notesinterface.h" + #define STATUS_ENDPOINT "/status.php" #define LOGIN_ENDPOINT "/index.php/login/v2" #define NOTES_ENDPOINT "/index.php/apps/notes/api/v0.2/notes" @@ -17,7 +19,7 @@ #define EXCLUDE_QUERY "exclude=" #define POLL_INTERVALL 5000 -class NotesApi : public QObject +class NotesApi : public QObject, public NotesInterface { Q_OBJECT @@ -139,6 +141,9 @@ public: Q_ENUM(ErrorCodes) Q_INVOKABLE const QString errorMessage(int error) const; + QString account() const; + void setAccount(const QString& account); + public slots: Q_INVOKABLE bool getAllNotes(const QStringList& exclude = QStringList()); Q_INVOKABLE bool getNote(const int id, const QStringList& exclude = QStringList()); @@ -175,13 +180,12 @@ signals: void loginStatusChanged(LoginStatus status); void loginUrlChanged(QUrl url); - void allNotesReceived(const QList& ids); + void accountChanged(const QString& account); + void allNotesChanged(const QList& ids); void noteCreated(const int id, const QJsonObject& note); void noteUpdated(const int id, const QJsonObject& note); void noteDeleted(const int id); - void noteError(const ErrorCodes error); - -public slots: + void noteError(ErrorCodes error); private slots: void verifyUrl(QUrl url); @@ -193,6 +197,7 @@ private slots: private: QUrl m_url; + QString m_account; QNetworkAccessManager m_manager; QNetworkRequest m_request; QNetworkRequest m_authenticatedRequest; diff --git a/src/notesinterface.h b/src/notesinterface.h new file mode 100644 index 0000000..2e2e0b5 --- /dev/null +++ b/src/notesinterface.h @@ -0,0 +1,36 @@ +#ifndef NOTESINTERFACE_H +#define NOTESINTERFACE_H + +//#include + +class NotesInterface +{ + //Q_CLASSINFO("author", "Scharel Clemens") + //Q_CLASSINFO("url", "https://github.com/scharel/harbour-nextcloudnotes") + + Q_PROPERTY(QString account READ account WRITE setAccount NOTIFY accountChanged) + +public: + explicit NotesInterface() { + } + + virtual QString account() const = 0; + virtual void setAccount(const QString& account) = 0; + +public slots: + Q_INVOKABLE virtual bool getAllNotes(const QStringList& exclude = QStringList()) = 0; + Q_INVOKABLE virtual bool getNote(const int id, const QStringList& exclude = QStringList()) = 0; + Q_INVOKABLE virtual bool createNote(const QJsonObject& note) = 0; + Q_INVOKABLE virtual bool updateNote(const int id, const QJsonObject& note) = 0; + Q_INVOKABLE virtual bool deleteNote(const int id) = 0; + +signals: + virtual void accountChanged(const QString& account) = 0; + virtual void allNotesChanged(const QList& ids) = 0; + virtual void noteCreated(const int id, const QJsonObject& note) = 0; + virtual void noteUpdated(const int id, const QJsonObject& note) = 0; + virtual void noteDeleted(const int id) = 0; + +}; + +#endif // NOTESINTERFACE_H diff --git a/src/notesmodel.cpp b/src/notesmodel.cpp index 33b54c9..4ea33eb 100644 --- a/src/notesmodel.cpp +++ b/src/notesmodel.cpp @@ -68,49 +68,131 @@ const QHash NotesModel::m_roleNames = QHash ( {NotesModel::NoneRole, "none"} } ); NotesModel::NotesModel(QObject *parent) : QAbstractListModel(parent) { - + mp_notesApi = nullptr; + mp_notesStore = nullptr; } NotesModel::~NotesModel() { + setNotesApi(nullptr); + setNotesStore(nullptr); clear(); } -const QJsonArray NotesModel::getAllNotes(const QStringList &exclude) { - qDebug() << "Getting all Notes"; - QJsonArray array; - QMapIterator i(m_notes); - while (i.hasNext()) { - i.next(); - array << QJsonValue(i.value()); +void NotesModel::setNotesApi(NotesApi *notesApi) { + if (mp_notesApi) { + // disconnect stuff + disconnect(mp_notesApi, SIGNAL(accountChanged(QString)), this, SIGNAL(accountChanged(QString))); + disconnect(mp_notesApi, SIGNAL(noteCreated(int,QJsonObject)), this, SLOT(insert(int,QJsonObject))); + disconnect(mp_notesApi, SIGNAL(noteUpdated(int,QJsonObject)), this, SLOT(update(int,QJsonObject))); + disconnect(mp_notesApi, SIGNAL(noteDeleted(int)), this, SLOT(remove(int))); + } + mp_notesApi = notesApi; + if (mp_notesApi) { + // connect stuff + connect(mp_notesApi, SIGNAL(accountChanged(QString)), this, SIGNAL(accountChanged(QString))); + connect(mp_notesApi, SIGNAL(noteCreated(int,QJsonObject)), this, SLOT(insert(int,QJsonObject))); + connect(mp_notesApi, SIGNAL(noteUpdated(int,QJsonObject)), this, SLOT(update(int,QJsonObject))); + connect(mp_notesApi, SIGNAL(noteDeleted(int)), this, SLOT(remove(int))); } - return array; } -const QJsonObject NotesModel::getNote(const int id, const QStringList &exclude) { - qDebug() << "Getting note: " << id; - return m_notes.value(id); +void NotesModel::setNotesStore(NotesStore *notesStore) { + if (mp_notesStore) { + // disconnect stuff + disconnect(mp_notesStore, SIGNAL(accountChanged(QString)), this, SIGNAL(accountChanged(QString))); + disconnect(mp_notesStore, SIGNAL(noteCreated(int,QJsonObject)), this, SLOT(insert(int,QJsonObject))); + disconnect(mp_notesStore, SIGNAL(noteUpdated(int,QJsonObject)), this, SLOT(update(int,QJsonObject))); + disconnect(mp_notesStore, SIGNAL(noteDeleted(int)), this, SLOT(remove(int))); + } + mp_notesStore = notesStore; + if (mp_notesStore) { + // connect stuff + connect(mp_notesStore, SIGNAL(accountChanged(QString)), this, SIGNAL(accountChanged(QString))); + connect(mp_notesStore, SIGNAL(noteCreated(int,QJsonObject)), this, SLOT(insert(int,QJsonObject))); + connect(mp_notesStore, SIGNAL(noteUpdated(int,QJsonObject)), this, SLOT(update(int,QJsonObject))); + connect(mp_notesStore, SIGNAL(noteDeleted(int)), this, SLOT(remove(int))); + } } -void NotesModel::insertNote(const int id, const QJsonObject& note) { +QString NotesModel::account() const { + QString account; + if (mp_notesStore) + account = mp_notesStore->account(); + else if (mp_notesApi) + account = mp_notesApi->account(); + return account; +} + +void NotesModel::setAccount(const QString &account) { + if (mp_notesApi) + mp_notesApi->setAccount(account); + if (mp_notesStore) + mp_notesStore->setAccount(account); +} + +bool NotesModel::getAllNotes(const QStringList &exclude) { + bool success = true; + if (mp_notesApi) + success &= mp_notesApi->getAllNotes(exclude); + if (mp_notesStore) + success &= mp_notesStore->getAllNotes(exclude); + return success; +} + +bool NotesModel::getNote(const int id, const QStringList &exclude) { + bool success = true; + if (mp_notesApi) + success &= mp_notesApi->getNote(id, exclude); + if (mp_notesStore) + success &= mp_notesStore->getNote(id, exclude); + return success; +} + +bool NotesModel::createNote(const QJsonObject ¬e) { + bool success = true; + if (mp_notesApi) + success &= mp_notesApi->createNote(note); + return success; +} + +bool NotesModel::updateNote(const int id, const QJsonObject ¬e) { + bool success = true; + if (mp_notesApi) + success &= mp_notesApi->updateNote(id, note); + if (mp_notesStore) + success &= mp_notesStore->updateNote(id, note); + return success; +} + +bool NotesModel::deleteNote(const int id) { + bool success = true; + if (mp_notesApi) + success &= mp_notesApi->deleteNote(id); + if (mp_notesStore) + success &= mp_notesStore->deleteNote(id); + return success; +} + +void NotesModel::insert(const int id, const QJsonObject& note) { qDebug() << "Inserting note: " << id; if (m_notes.contains(id)) { qDebug() << "Note already present"; - updateNote(id, note); + update(id, note); } else { beginInsertRows(QModelIndex(), indexOfNoteById(id), indexOfNoteById(id)); m_notes.insert(id, note); endInsertRows(); - emit noteInserted(id, note); + //emit noteInserted(id, note); qDebug() << "Note inserted"; } } -void NotesModel::updateNote(const int id, const QJsonObject ¬e) { +void NotesModel::update(const int id, const QJsonObject ¬e) { qDebug() << "Updating note: " << id; if (!m_notes.contains(id)) { qDebug() << "Note is new"; - insertNote(id, note); + insert(id, note); } else { if (m_notes.value(id) == note) { @@ -125,7 +207,7 @@ void NotesModel::updateNote(const int id, const QJsonObject ¬e) { } } -void NotesModel::removeNote(const int id) { +void NotesModel::remove(const int id) { qDebug() << "Removing note: " << id; if (m_notes.contains(id)) { beginRemoveRows(QModelIndex(), indexOfNoteById(id), indexOfNoteById(id)); @@ -133,36 +215,12 @@ void NotesModel::removeNote(const int id) { qDebug() << "Note not found"; } else { - emit noteRemoved(id); + //emit noteRemoved(id); } endRemoveRows(); } } -void NotesModel::insertNoteFromApi(const int id, const QJsonObject ¬e) { - insertNote(id, note); -} - -void NotesModel::updateNoteFromApi(const int id, const QJsonObject ¬e) { - updateNote(id, note); -} - -void NotesModel::removeNoteFromApi(const int id) { - removeNote(id); -} - -void NotesModel::insertNoteFromStore(const int id, const QJsonObject ¬e) { - insertNote(id, note); -} - -void NotesModel::updateNoteFromStore(const int id, const QJsonObject ¬e) { - updateNote(id, note); -} - -void NotesModel::removeNoteFromStore(const int id) { - removeNote(id); -} - void NotesModel::clear() { qDebug() << "Clearing model"; beginResetModel(); diff --git a/src/notesmodel.h b/src/notesmodel.h index e30486b..c0b2045 100644 --- a/src/notesmodel.h +++ b/src/notesmodel.h @@ -6,6 +6,9 @@ #include #include #include "note.h" +#include "notesinterface.h" +#include "notesapi.h" +#include "notesstore.h" class NotesProxyModel : public QSortFilterProxyModel { Q_OBJECT @@ -34,7 +37,7 @@ private: bool m_favoritesOnTop; }; -class NotesModel : public QAbstractListModel { +class NotesModel : public QAbstractListModel, public NotesInterface { Q_OBJECT public: @@ -63,31 +66,41 @@ public: QMap itemData(const QModelIndex &index) const; virtual bool setItemData(const QModelIndex &index, const QMap &roles); + void setNotesApi(NotesApi* notesApi); + void setNotesStore(NotesStore *notesStore); + + QString account() const; + void setAccount(const QString& account); + public slots: - Q_INVOKABLE const QJsonArray getAllNotes(const QStringList& exclude = QStringList()); - Q_INVOKABLE const QJsonObject getNote(const int id, const QStringList& exclude = QStringList()); - Q_INVOKABLE void insertNote(const int id, const QJsonObject& note); - Q_INVOKABLE void updateNote(const int id, const QJsonObject& note); - Q_INVOKABLE void removeNote(const int id); - Q_INVOKABLE void insertNoteFromApi(const int id, const QJsonObject& note); - Q_INVOKABLE void updateNoteFromApi(const int id, const QJsonObject& note); - Q_INVOKABLE void removeNoteFromApi(const int id); - Q_INVOKABLE void insertNoteFromStore(const int id, const QJsonObject& note); - Q_INVOKABLE void updateNoteFromStore(const int id, const QJsonObject& note); - Q_INVOKABLE void removeNoteFromStore(const int id); + Q_INVOKABLE bool getAllNotes(const QStringList& exclude = QStringList()); + Q_INVOKABLE bool getNote(const int id, const QStringList& exclude = QStringList()); + Q_INVOKABLE bool createNote(const QJsonObject& note); + Q_INVOKABLE bool updateNote(const int id, const QJsonObject& note); + Q_INVOKABLE bool deleteNote(const int id); + + void insert(const int id, const QJsonObject& note); + void update(const int id, const QJsonObject& note); + void remove(const int id); Q_INVOKABLE void clear(); Q_INVOKABLE int indexOfNoteById(int id) const; signals: - void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles = QVector ()); - void noteInserted(const int id, const QJsonObject& note); + void accountChanged(const QString& account); + void allNotesChanged(const QList& ids); + void noteCreated(const int id, const QJsonObject& note); void noteUpdated(const int id, const QJsonObject& note); - void noteRemoved(const int id); + void noteDeleted(const int id); + + void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles = QVector ()); private: QMap m_notes; const static QHash m_roleNames; + + NotesApi* mp_notesApi; + NotesStore* mp_notesStore; }; #endif // NOTESMODEL_H diff --git a/src/notesstore.cpp b/src/notesstore.cpp index fddd8a4..f9a6653 100644 --- a/src/notesstore.cpp +++ b/src/notesstore.cpp @@ -76,98 +76,6 @@ const QString NotesStore::errorMessage(ErrorCodes error) const { return message; } -const QJsonArray NotesStore::getAllNotes(const QStringList& exclude) { - qDebug() << "Getting all notes"; - QJsonArray notes; - if (m_dir.exists()) { - QFileInfoList files = m_dir.entryInfoList(); - for (int i = 0; i < files.size(); ++i) { - bool ok; - int id = files[i].baseName().toInt(&ok); - if (ok) { - notes.append(QJsonValue(getNote(id, exclude))); - } - } - } - else { - qDebug() << errorMessage(DirNotFoundError); - emit noteError(DirCannotReadError); - } - return notes; -} - -const QJsonObject NotesStore::getNote(const int id, const QStringList& exclude) { - qDebug() << "Getting note: " << id; - QJsonObject note; - if (id >= 0) { - note = readNoteFile(id, exclude); - emit noteUpdated(id, note); - } - else { - qDebug() << "Skipping, invalid ID"; - } - return note; -} -/* -bool NotesStore::createNote(const int id, const QJsonObject& note) { - 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!"; - } - else if (!noteFileExists(id)) { - if (writeNoteFile(id, note)) { - emit noteUpdated(id, note); - return true; - } - } - else { - qDebug() << "Note already exists"; - } - return false; -} -*/ -bool NotesStore::updateNote(const int id, const QJsonObject& note) { - qDebug() << "Updating note: " << id; - if (id >= 0) { - QJsonObject tmpNote = readNoteFile(id); - if (note != tmpNote) { - if (note.value("modified").toInt() >= tmpNote.value("modified").toInt() || note.value("modified").toInt() == 0) { - QStringList fields = note.keys(); - for (int i = 0; i < fields.size(); ++i) { - tmpNote[fields[i]] = note[fields[i]]; - } - if (tmpNote.value("modified").toInt() == 0) { - tmpNote["modified"] = QJsonValue::fromVariant(QDateTime::currentDateTime().toTime_t()); - } - if (writeNoteFile(id, tmpNote)) { - emit noteUpdated(id, tmpNote); - return true; - } - } - else { - qDebug() << "Skipping, note is older" << QDateTime::fromTime_t(note.value("modified").toInt()) << QDateTime::fromTime_t(tmpNote.value("modified").toInt()); - } - } - else { - qDebug() << "Skipping, note is equal"; - } - } - else { - qDebug() << "Skipping, invalid ID"; - } - return false; -} - -bool NotesStore::deleteNote(const int id) { - qDebug() << "Deleting note: " << id; - if (removeNoteFile(id)) { - emit noteDeleted(id); - return true; - } - return false; -} - bool NotesStore::noteFileExists(const int id) const { QFileInfo fileinfo(m_dir, QString("%1.%2").arg(id).arg(m_suffix)); return fileinfo.exists(); @@ -234,3 +142,98 @@ bool NotesStore::removeNoteFile(const int id) { } return success; } + +bool NotesStore::getAllNotes(const QStringList& exclude) { + qDebug() << "Getting all notes"; + //QJsonArray notes; + if (m_dir.exists() && !account().isEmpty()) { + QFileInfoList files = m_dir.entryInfoList(); + for (int i = 0; i < files.size(); ++i) { + bool ok; + int id = files[i].baseName().toInt(&ok); + if (ok) { + getNote(id, exclude); + //notes.append(QJsonValue(getNote(id, exclude))); + } + } + return true; + } + else { + qDebug() << errorMessage(DirNotFoundError); + emit noteError(DirCannotReadError); + } + return false; +} + +bool NotesStore::getNote(const int id, const QStringList& exclude) { + qDebug() << "Getting note: " << id; + QJsonObject note; + if (id >= 0) { + note = readNoteFile(id, exclude); + emit noteUpdated(id, note); + return true; + } + else { + qDebug() << "Skipping, invalid ID"; + } + return false; +} + +bool NotesStore::createNote(const QJsonObject& note) { +/* 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!"; + } + else if (!noteFileExists(id)) { + if (writeNoteFile(id, note)) { + emit noteUpdated(id, note); + return true; + } + } + else { + qDebug() << "Note already exists"; + }*/ + return false; +} + +bool NotesStore::updateNote(const int id, const QJsonObject& note) { + qDebug() << "Updating note: " << id; + if (id >= 0) { + QJsonObject tmpNote = readNoteFile(id); + if (note != tmpNote) { + if (note.value("modified").toInt() >= tmpNote.value("modified").toInt() || note.value("modified").toInt() == 0) { + QStringList fields = note.keys(); + for (int i = 0; i < fields.size(); ++i) { + tmpNote[fields[i]] = note[fields[i]]; + } + if (tmpNote.value("modified").toInt() == 0) { + tmpNote["modified"] = QJsonValue::fromVariant(QDateTime::currentDateTime().toTime_t()); + } + if (writeNoteFile(id, tmpNote)) { + emit noteUpdated(id, tmpNote); + return true; + } + } + else { + qDebug() << "Skipping, note is older" << QDateTime::fromTime_t(note.value("modified").toInt()) << QDateTime::fromTime_t(tmpNote.value("modified").toInt()); + } + } + else { + qDebug() << "Skipping, note is equal"; + } + } + else { + qDebug() << "Skipping, invalid ID"; + } + return false; +} + +bool NotesStore::deleteNote(const int id) { + qDebug() << "Deleting note: " << id; + if (removeNoteFile(id)) { + emit noteDeleted(id); + return true; + } + return false; +} diff --git a/src/notesstore.h b/src/notesstore.h index 3443488..edc5290 100644 --- a/src/notesstore.h +++ b/src/notesstore.h @@ -7,7 +7,9 @@ #include #include -class NotesStore : public QObject +#include "notesinterface.h" + +class NotesStore : public QObject, public NotesInterface { Q_OBJECT @@ -34,16 +36,22 @@ public: Q_ENUM(ErrorCodes) Q_INVOKABLE const QString errorMessage(ErrorCodes error) const; + bool noteFileExists(const int id) const; + QJsonObject readNoteFile(const int id, const QStringList& exclude = QStringList()); + bool writeNoteFile(const int id, const QJsonObject& note); + bool removeNoteFile(const int id); + public slots: - Q_INVOKABLE const QJsonArray getAllNotes(const QStringList& exclude = QStringList()); - Q_INVOKABLE const QJsonObject getNote(const int id, const QStringList& exclude = QStringList()); - //Q_INVOKABLE bool createNote(const int id, const QJsonObject& note); + Q_INVOKABLE bool getAllNotes(const QStringList& exclude = QStringList()); + Q_INVOKABLE bool getNote(const int id, const QStringList& exclude = QStringList()); + Q_INVOKABLE bool createNote(const QJsonObject& note); Q_INVOKABLE bool updateNote(const int id, const QJsonObject& note); Q_INVOKABLE bool deleteNote(const int id); signals: void accountChanged(const QString& account); - //void noteCreated(const int id, const QJsonObject& note); + void allNotesChanged(const QList& ids); + void noteCreated(const int id, const QJsonObject& note); void noteUpdated(const int id, const QJsonObject& note); void noteDeleted(const int id); void noteError(const ErrorCodes error); @@ -51,11 +59,6 @@ signals: private: QDir m_dir; const static QString m_suffix; - - bool noteFileExists(const int id) const; - QJsonObject readNoteFile(const int id, const QStringList& exclude = QStringList()); - bool writeNoteFile(const int id, const QJsonObject& note); - bool removeNoteFile(const int id); }; #endif // NOTESSTORE_H diff --git a/translations/harbour-nextcloudnotes.ts b/translations/harbour-nextcloudnotes.ts index 9d89be7..fa4abe7 100644 --- a/translations/harbour-nextcloudnotes.ts +++ b/translations/harbour-nextcloudnotes.ts @@ -311,32 +311,32 @@ NotesApi - + No error - + No network connection available - + Failed to communicate with the Nextcloud server - + An error occured while establishing an encrypted connection - + Could not authenticate to the Nextcloud instance - + Unknown error