Updated signals and slots of the modules
This commit is contained in:
parent
312be40fcf
commit
433a049a14
12 changed files with 107 additions and 80 deletions
|
@ -58,7 +58,6 @@ ApplicationWindow
|
||||||
account.path = "/apps/harbour-nextcloudnotes/accounts/" + currentAccount
|
account.path = "/apps/harbour-nextcloudnotes/accounts/" + currentAccount
|
||||||
notesStore.account = currentAccount
|
notesStore.account = currentAccount
|
||||||
notesStore.getAllNotes()
|
notesStore.getAllNotes()
|
||||||
notesApi.account = currentAccount
|
|
||||||
notesApi.getAllNotes()
|
notesApi.getAllNotes()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,9 @@
|
||||||
# * date Author's Name <author's email> version-release
|
# * date Author's Name <author's email> version-release
|
||||||
# - Summary of changes
|
# - Summary of changes
|
||||||
|
|
||||||
|
* Thu Apr 13 2020 Scharel Clemens <harbour-nextcloudnotes@scharel.rocks> 0.8-1
|
||||||
|
- Updated Signals and Slots between the modules
|
||||||
|
|
||||||
* Mon Apr 13 2020 Scharel Clemens <harbour-nextcloudnotes@scharel.rocks> 0.8-0
|
* Mon Apr 13 2020 Scharel Clemens <harbour-nextcloudnotes@scharel.rocks> 0.8-0
|
||||||
- New methods for data handling improved
|
- New methods for data handling improved
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ Name: harbour-nextcloudnotes
|
||||||
%{?qtc_builddir:%define _builddir %qtc_builddir}
|
%{?qtc_builddir:%define _builddir %qtc_builddir}
|
||||||
Summary: Nextcloud Notes
|
Summary: Nextcloud Notes
|
||||||
Version: 0.8
|
Version: 0.8
|
||||||
Release: 0
|
Release: 1
|
||||||
Group: Applications/Editors
|
Group: Applications/Editors
|
||||||
License: MIT
|
License: MIT
|
||||||
URL: https://github.com/scharel/harbour-nextcloudnotes
|
URL: https://github.com/scharel/harbour-nextcloudnotes
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
Name: harbour-nextcloudnotes
|
Name: harbour-nextcloudnotes
|
||||||
Summary: Nextcloud Notes
|
Summary: Nextcloud Notes
|
||||||
Version: 0.8
|
Version: 0.8
|
||||||
Release: 0
|
Release: 1
|
||||||
# The contents of the Group field should be one of the groups listed here:
|
# The contents of the Group field should be one of the groups listed here:
|
||||||
# https://github.com/mer-tools/spectacle/blob/master/data/GROUPS
|
# https://github.com/mer-tools/spectacle/blob/master/data/GROUPS
|
||||||
Group: Applications/Editors
|
Group: Applications/Editors
|
||||||
|
|
|
@ -30,15 +30,17 @@ int main(int argc, char *argv[])
|
||||||
NotesStore* notesStore = new NotesStore;
|
NotesStore* notesStore = new NotesStore;
|
||||||
NotesApi* notesApi = new NotesApi;
|
NotesApi* notesApi = new NotesApi;
|
||||||
|
|
||||||
QObject::connect(notesApi, SIGNAL(noteUpdated(int, QJsonObject)), notesStore, SLOT(updateNote(int, QJsonObject)));
|
//QObject::connect(notesApi, SIGNAL(allNotesReceived(QList<int>)), notesModel, SLOT());
|
||||||
//QObject::connect(notesStore, SIGNAL(noteUpdated(int, QJsonObject)), notesApi, SLOT(updateNote(int, QJsonObject)));
|
QObject::connect(notesApi, SIGNAL(noteCreated(int,QJsonObject)), notesModel, SLOT(insertNote(int,QJsonObject)));
|
||||||
QObject::connect(notesApi, SIGNAL(noteDeleted(int)), notesStore, SLOT(deleteNote(int)));
|
QObject::connect(notesApi, SIGNAL(noteUpdated(int,QJsonObject)), notesModel, SLOT(updateNote(int,QJsonObject)));
|
||||||
//QObject::connect(notesStore, SIGNAL(noteDeleted(int)), notesApi, SLOT(deleteNote(int)));
|
QObject::connect(notesApi, SIGNAL(noteDeleted(int)), notesModel, SLOT(removeNote(int)));
|
||||||
|
|
||||||
QObject::connect(notesStore, SIGNAL(noteUpdated(int, QJsonObject)), notesModel, SLOT(insertNote(int, QJsonObject)));
|
QObject::connect(notesApi, SIGNAL(noteCreated(int,QJsonObject)), notesStore, SLOT(insertNote(int,QJsonObject)));
|
||||||
|
QObject::connect(notesApi, SIGNAL(noteUpdated(int,QJsonObject)), notesStore, SLOT(updateNote(int,QJsonObject)));
|
||||||
|
QObject::connect(notesApi, SIGNAL(noteDeleted(int)), notesStore, SLOT(removeNote(int)));
|
||||||
|
|
||||||
|
QObject::connect(notesStore, SIGNAL(noteUpdated(int,QJsonObject)), notesModel, SLOT(updateNote(int,QJsonObject)));
|
||||||
QObject::connect(notesStore, SIGNAL(noteDeleted(int)), notesModel, SLOT(removeNote(int)));
|
QObject::connect(notesStore, SIGNAL(noteDeleted(int)), notesModel, SLOT(removeNote(int)));
|
||||||
//QObject::connect(notesApi, SIGNAL(noteUpdated(Note)), notesModel, SLOT(insertNote(Note)));
|
|
||||||
//QObject::connect(notesApi, SIGNAL(noteDeleted(int)), notesModel, SLOT(removeNote(int)));
|
|
||||||
|
|
||||||
QQuickView* view = SailfishApp::createView();
|
QQuickView* view = SailfishApp::createView();
|
||||||
#ifdef QT_DEBUG
|
#ifdef QT_DEBUG
|
||||||
|
@ -55,15 +57,6 @@ int main(int argc, char *argv[])
|
||||||
view->show();
|
view->show();
|
||||||
|
|
||||||
int retval = app->exec();
|
int retval = app->exec();
|
||||||
//QObject::disconnect(notesApi, SIGNAL(noteDeleted(int)), notesModel, SLOT(removeNote(int)));
|
|
||||||
//QObject::disconnect(notesApi, SIGNAL(noteUpdated(Note)), notesModel, SLOT(insertNote(Note)));
|
|
||||||
QObject::disconnect(notesStore, SIGNAL(noteDeleted(int)), notesModel, SLOT(removeNote(int)));
|
|
||||||
QObject::disconnect(notesStore, SIGNAL(noteUpdated(int, QJsonObject)), notesModel, SLOT(insertNote(int, QJsonObject)));
|
|
||||||
|
|
||||||
//QObject::disconnect(notesStore, SIGNAL(noteDeleted(int)), notesApi, SLOT(deleteNote(int)));
|
|
||||||
QObject::disconnect(notesApi, SIGNAL(noteDeleted(int)), notesStore, SLOT(deleteNote(int)));
|
|
||||||
//QObject::disconnect(notesStore, SIGNAL(noteUpdated(Note)), notesApi, SLOT(updateNote(Note)));
|
|
||||||
QObject::disconnect(notesApi, SIGNAL(noteUpdated(int, QJsonObject)), notesStore, SLOT(updateNote(int, QJsonObject)));
|
|
||||||
|
|
||||||
notesApi->deleteLater();
|
notesApi->deleteLater();
|
||||||
notesStore->deleteLater();
|
notesStore->deleteLater();
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
|
||||||
NotesApi::NotesApi(const QString statusEndpoint, const QString loginEndpoint, const QString ocsEndpoint, const QString notesEndpoint, QObject *parent)
|
NotesApi::NotesApi(const QString statusEndpoint, const QString loginEndpoint, const QString ocsEndpoint, const QString notesEndpoint, QObject *parent)
|
||||||
: m_statusEndpoint(statusEndpoint), m_loginEndpoint(loginEndpoint), m_ocsEndpoint(ocsEndpoint), m_notesEndpoint(notesEndpoint)
|
: QObject(parent), m_statusEndpoint(statusEndpoint), m_loginEndpoint(loginEndpoint), m_ocsEndpoint(ocsEndpoint), m_notesEndpoint(notesEndpoint)
|
||||||
{
|
{
|
||||||
// TODO verify connections (also in destructor)
|
// TODO verify connections (also in destructor)
|
||||||
m_loginPollTimer.setInterval(POLL_INTERVALL);
|
m_loginPollTimer.setInterval(POLL_INTERVALL);
|
||||||
|
@ -42,7 +42,7 @@ NotesApi::~NotesApi() {
|
||||||
disconnect(&m_manager, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)), this, SLOT(sslError(QNetworkReply*,QList<QSslError>)));
|
disconnect(&m_manager, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)), this, SLOT(sslError(QNetworkReply*,QList<QSslError>)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotesApi::getAllNotes(const QStringList& exclude) {
|
bool NotesApi::getAllNotes(const QStringList& exclude) {
|
||||||
qDebug() << "Getting all notes";
|
qDebug() << "Getting all notes";
|
||||||
QUrl url = apiEndpointUrl(m_notesEndpoint);
|
QUrl url = apiEndpointUrl(m_notesEndpoint);
|
||||||
|
|
||||||
|
@ -54,10 +54,12 @@ void NotesApi::getAllNotes(const QStringList& exclude) {
|
||||||
m_authenticatedRequest.setUrl(url);
|
m_authenticatedRequest.setUrl(url);
|
||||||
m_getAllNotesReplies << m_manager.get(m_authenticatedRequest);
|
m_getAllNotesReplies << m_manager.get(m_authenticatedRequest);
|
||||||
emit busyChanged(true);
|
emit busyChanged(true);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotesApi::getNote(const int id, const QStringList& exclude) {
|
bool NotesApi::getNote(const int id, const QStringList& exclude) {
|
||||||
qDebug() << "Getting note: " << id;
|
qDebug() << "Getting note: " << id;
|
||||||
QUrl url = apiEndpointUrl(m_notesEndpoint + QString("/%1").arg(id));
|
QUrl url = apiEndpointUrl(m_notesEndpoint + QString("/%1").arg(id));
|
||||||
if (!exclude.isEmpty())
|
if (!exclude.isEmpty())
|
||||||
|
@ -68,10 +70,12 @@ void NotesApi::getNote(const int id, const QStringList& exclude) {
|
||||||
m_authenticatedRequest.setUrl(url);
|
m_authenticatedRequest.setUrl(url);
|
||||||
m_getNoteReplies << m_manager.get(m_authenticatedRequest);
|
m_getNoteReplies << m_manager.get(m_authenticatedRequest);
|
||||||
emit busyChanged(true);
|
emit busyChanged(true);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotesApi::createNote(const QJsonObject& note) {
|
bool NotesApi::createNote(const QJsonObject& note) {
|
||||||
qDebug() << "Creating note";
|
qDebug() << "Creating note";
|
||||||
QUrl url = apiEndpointUrl(m_notesEndpoint);
|
QUrl url = apiEndpointUrl(m_notesEndpoint);
|
||||||
if (url.isValid() && !url.scheme().isEmpty() && !url.host().isEmpty()) {
|
if (url.isValid() && !url.scheme().isEmpty() && !url.host().isEmpty()) {
|
||||||
|
@ -79,10 +83,12 @@ void NotesApi::createNote(const QJsonObject& note) {
|
||||||
m_authenticatedRequest.setUrl(url);
|
m_authenticatedRequest.setUrl(url);
|
||||||
m_createNoteReplies << m_manager.post(m_authenticatedRequest, QJsonDocument(note).toJson());
|
m_createNoteReplies << m_manager.post(m_authenticatedRequest, QJsonDocument(note).toJson());
|
||||||
emit busyChanged(true);
|
emit busyChanged(true);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotesApi::updateNote(const int id, const QJsonObject& note) {
|
bool NotesApi::updateNote(const int id, const QJsonObject& note) {
|
||||||
qDebug() << "Updating note: " << id;
|
qDebug() << "Updating note: " << id;
|
||||||
QUrl url = apiEndpointUrl(m_notesEndpoint + QString("/%1").arg(id));
|
QUrl url = apiEndpointUrl(m_notesEndpoint + QString("/%1").arg(id));
|
||||||
if (id >= 0 && url.isValid() && !url.scheme().isEmpty() && !url.host().isEmpty()) {
|
if (id >= 0 && url.isValid() && !url.scheme().isEmpty() && !url.host().isEmpty()) {
|
||||||
|
@ -90,10 +96,12 @@ void NotesApi::updateNote(const int id, const QJsonObject& note) {
|
||||||
m_authenticatedRequest.setUrl(url);
|
m_authenticatedRequest.setUrl(url);
|
||||||
m_updateNoteReplies << m_manager.put(m_authenticatedRequest, QJsonDocument(note).toJson());
|
m_updateNoteReplies << m_manager.put(m_authenticatedRequest, QJsonDocument(note).toJson());
|
||||||
emit busyChanged(true);
|
emit busyChanged(true);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotesApi::deleteNote(const int id) {
|
bool NotesApi::deleteNote(const int id) {
|
||||||
qDebug() << "Deleting note: " << id;
|
qDebug() << "Deleting note: " << id;
|
||||||
QUrl url = apiEndpointUrl(m_notesEndpoint + QString("/%1").arg(id));
|
QUrl url = apiEndpointUrl(m_notesEndpoint + QString("/%1").arg(id));
|
||||||
if (url.isValid() && !url.scheme().isEmpty() && !url.host().isEmpty()) {
|
if (url.isValid() && !url.scheme().isEmpty() && !url.host().isEmpty()) {
|
||||||
|
@ -101,7 +109,9 @@ void NotesApi::deleteNote(const int id) {
|
||||||
m_authenticatedRequest.setUrl(url);
|
m_authenticatedRequest.setUrl(url);
|
||||||
m_deleteNoteReplies << m_manager.deleteResource(m_authenticatedRequest);
|
m_deleteNoteReplies << m_manager.deleteResource(m_authenticatedRequest);
|
||||||
emit busyChanged(true);
|
emit busyChanged(true);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NotesApi::busy() const {
|
bool NotesApi::busy() const {
|
||||||
|
@ -356,8 +366,9 @@ void NotesApi::replyFinished(QNetworkReply *reply) {
|
||||||
|
|
||||||
if (m_getAllNotesReplies.contains(reply)) {
|
if (m_getAllNotesReplies.contains(reply)) {
|
||||||
qDebug() << "Get all notes reply";
|
qDebug() << "Get all notes reply";
|
||||||
if (reply->error() == QNetworkReply::NoError && json.isArray())
|
if (reply->error() == QNetworkReply::NoError && json.isArray()) {
|
||||||
updateApiNotes(json.array());
|
updateApiNotes(json.array());
|
||||||
|
}
|
||||||
m_getAllNotesReplies.removeOne(reply);
|
m_getAllNotesReplies.removeOne(reply);
|
||||||
}
|
}
|
||||||
else if (m_getNoteReplies.contains(reply)) {
|
else if (m_getNoteReplies.contains(reply)) {
|
||||||
|
@ -369,7 +380,7 @@ void NotesApi::replyFinished(QNetworkReply *reply) {
|
||||||
else if (m_createNoteReplies.contains(reply)) {
|
else if (m_createNoteReplies.contains(reply)) {
|
||||||
qDebug() << "Create note reply";
|
qDebug() << "Create note reply";
|
||||||
if (reply->error() == QNetworkReply::NoError && json.isObject())
|
if (reply->error() == QNetworkReply::NoError && json.isObject())
|
||||||
updateApiNote(json.object());
|
createApiNote(json.object());
|
||||||
m_createNoteReplies.removeOne(reply);
|
m_createNoteReplies.removeOne(reply);
|
||||||
}
|
}
|
||||||
else if (m_updateNoteReplies.contains(reply)) {
|
else if (m_updateNoteReplies.contains(reply)) {
|
||||||
|
@ -576,10 +587,17 @@ void NotesApi::setLoginStatus(LoginStatus status, bool *changed) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotesApi::updateApiNotes(const QJsonArray &json) {
|
void NotesApi::updateApiNotes(const QJsonArray &json) {
|
||||||
|
QList<int> ids;
|
||||||
for (int i = 0; i < json.size(); ++i) {
|
for (int i = 0; i < json.size(); ++i) {
|
||||||
if (json[i].isObject())
|
if (json[i].isObject()) {
|
||||||
updateApiNote(json[i].toObject());
|
QJsonObject object = json[i].toObject();
|
||||||
|
if (!object.isEmpty()) {
|
||||||
|
updateApiNote(json[i].toObject());
|
||||||
|
ids << object.value("id").toInt(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
emit allNotesReceived(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotesApi::updateApiNote(const QJsonObject &json) {
|
void NotesApi::updateApiNote(const QJsonObject &json) {
|
||||||
|
@ -587,3 +605,9 @@ void NotesApi::updateApiNote(const QJsonObject &json) {
|
||||||
if (id >= 0)
|
if (id >= 0)
|
||||||
emit noteUpdated(id, json);
|
emit noteUpdated(id, json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NotesApi::createApiNote(const QJsonObject &json) {
|
||||||
|
int id = json["id"].toInt(-1);
|
||||||
|
if (id >= 0)
|
||||||
|
emit noteCreated(id, json);
|
||||||
|
}
|
||||||
|
|
|
@ -21,9 +21,8 @@ class NotesApi : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
Q_PROPERTY(bool verifySsl READ verifySsl() WRITE setVerifySsl NOTIFY verifySslChanged)
|
Q_PROPERTY(bool verifySsl READ verifySsl WRITE setVerifySsl NOTIFY verifySslChanged)
|
||||||
Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged)
|
Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged)
|
||||||
Q_PROPERTY(bool urlValid READ urlValid NOTIFY urlValidChanged)
|
|
||||||
Q_PROPERTY(QString server READ server WRITE setServer NOTIFY serverChanged)
|
Q_PROPERTY(QString server READ server WRITE setServer NOTIFY serverChanged)
|
||||||
Q_PROPERTY(QString scheme READ scheme WRITE setScheme NOTIFY schemeChanged)
|
Q_PROPERTY(QString scheme READ scheme WRITE setScheme NOTIFY schemeChanged)
|
||||||
Q_PROPERTY(QString host READ host WRITE setHost NOTIFY hostChanged)
|
Q_PROPERTY(QString host READ host WRITE setHost NOTIFY hostChanged)
|
||||||
|
@ -31,6 +30,8 @@ class NotesApi : public QObject
|
||||||
Q_PROPERTY(QString username READ username WRITE setUsername NOTIFY usernameChanged)
|
Q_PROPERTY(QString username READ username WRITE setUsername NOTIFY usernameChanged)
|
||||||
Q_PROPERTY(QString password READ password WRITE setPassword NOTIFY passwordChanged)
|
Q_PROPERTY(QString password READ password WRITE setPassword NOTIFY passwordChanged)
|
||||||
Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged)
|
Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged)
|
||||||
|
|
||||||
|
Q_PROPERTY(bool urlValid READ urlValid NOTIFY urlValidChanged)
|
||||||
Q_PROPERTY(bool networkAccessible READ networkAccessible NOTIFY networkAccessibleChanged)
|
Q_PROPERTY(bool networkAccessible READ networkAccessible NOTIFY networkAccessibleChanged)
|
||||||
Q_PROPERTY(QDateTime lastSync READ lastSync NOTIFY lastSyncChanged)
|
Q_PROPERTY(QDateTime lastSync READ lastSync NOTIFY lastSyncChanged)
|
||||||
Q_PROPERTY(bool busy READ busy NOTIFY busyChanged)
|
Q_PROPERTY(bool busy READ busy NOTIFY busyChanged)
|
||||||
|
@ -139,15 +140,11 @@ public:
|
||||||
Q_INVOKABLE const QString errorMessage(int error) const;
|
Q_INVOKABLE const QString errorMessage(int error) const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
Q_INVOKABLE void getAllNotes(const QStringList& exclude = QStringList());
|
Q_INVOKABLE bool getAllNotes(const QStringList& exclude = QStringList());
|
||||||
//void getAllNotes(Note::NoteField exclude);
|
Q_INVOKABLE bool getNote(const int id, const QStringList& exclude = QStringList());
|
||||||
Q_INVOKABLE void getNote(const int id, const QStringList& exclude = QStringList());
|
Q_INVOKABLE bool createNote(const QJsonObject& note);
|
||||||
//void getNote(const int id, Note::NoteField exclude);
|
Q_INVOKABLE bool updateNote(const int id, const QJsonObject& note);
|
||||||
Q_INVOKABLE void createNote(const QJsonObject& note);
|
Q_INVOKABLE bool deleteNote(const int id);
|
||||||
//void createNote(const Note& note);
|
|
||||||
Q_INVOKABLE void updateNote(const int id, const QJsonObject& note);
|
|
||||||
//void updateNote(const Note& note);
|
|
||||||
Q_INVOKABLE void deleteNote(const int id);
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void verifySslChanged(bool verify);
|
void verifySslChanged(bool verify);
|
||||||
|
@ -178,10 +175,11 @@ signals:
|
||||||
void loginStatusChanged(LoginStatus status);
|
void loginStatusChanged(LoginStatus status);
|
||||||
void loginUrlChanged(QUrl url);
|
void loginUrlChanged(QUrl url);
|
||||||
|
|
||||||
|
void allNotesReceived(const QList<int>& ids);
|
||||||
void noteCreated(const int id, const QJsonObject& note);
|
void noteCreated(const int id, const QJsonObject& note);
|
||||||
void noteUpdated(const int id, const QJsonObject& note);
|
void noteUpdated(const int id, const QJsonObject& note);
|
||||||
void noteDeleted(const int id);
|
void noteDeleted(const int id);
|
||||||
void noteError(ErrorCodes error);
|
void noteError(const ErrorCodes error);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
|
@ -242,6 +240,7 @@ private:
|
||||||
QVector<QNetworkReply*> m_deleteNoteReplies;
|
QVector<QNetworkReply*> m_deleteNoteReplies;
|
||||||
void updateApiNotes(const QJsonArray& json);
|
void updateApiNotes(const QJsonArray& json);
|
||||||
void updateApiNote(const QJsonObject& json);
|
void updateApiNote(const QJsonObject& json);
|
||||||
|
void createApiNote(const QJsonObject& json);
|
||||||
QDateTime m_lastSync;
|
QDateTime m_lastSync;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -91,22 +91,28 @@ const QJsonObject NotesModel::getNote(const int id, const QStringList &exclude)
|
||||||
return m_notes.value(id);
|
return m_notes.value(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotesModel::createNote(const int id, const QJsonObject ¬e) {
|
void NotesModel::insertNote(const int id, const QJsonObject& note) {
|
||||||
qDebug() << "New note, adding it";
|
qDebug() << "Inserting note: " << id;
|
||||||
if (!m_notes.contains(id)) {
|
if (m_notes.contains(id)) {
|
||||||
beginInsertRows(QModelIndex(), indexOfNoteById(id), indexOfNoteById(id));
|
qDebug() << "Note already present";
|
||||||
m_notes.insert(id, note);
|
updateNote(id, note);
|
||||||
emit noteUpdated(id, note);
|
|
||||||
endInsertRows();
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
qDebug() << "Note already present";
|
beginInsertRows(QModelIndex(), indexOfNoteById(id), indexOfNoteById(id));
|
||||||
|
m_notes.insert(id, note);
|
||||||
|
endInsertRows();
|
||||||
|
emit noteInserted(id, note);
|
||||||
|
qDebug() << "Note inserted";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotesModel::updateNote(const int id, const QJsonObject& note) {
|
void NotesModel::updateNote(const int id, const QJsonObject ¬e) {
|
||||||
qDebug() << "Updating note: " << id;
|
qDebug() << "Updating note: " << id;
|
||||||
if (m_notes.contains(id)) {
|
if (!m_notes.contains(id)) {
|
||||||
|
qDebug() << "Note is new";
|
||||||
|
insertNote(id, note);
|
||||||
|
}
|
||||||
|
else {
|
||||||
if (m_notes.value(id) == note) {
|
if (m_notes.value(id) == note) {
|
||||||
qDebug() << "Note unchanged";
|
qDebug() << "Note unchanged";
|
||||||
}
|
}
|
||||||
|
@ -117,12 +123,9 @@ void NotesModel::updateNote(const int id, const QJsonObject& note) {
|
||||||
qDebug() << "Note changed";
|
qDebug() << "Note changed";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
qDebug() << "Note not found";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotesModel::deleteNote(const int id) {
|
void NotesModel::removeNote(const int id) {
|
||||||
qDebug() << "Removing note: " << id;
|
qDebug() << "Removing note: " << id;
|
||||||
if (m_notes.contains(id)) {
|
if (m_notes.contains(id)) {
|
||||||
beginRemoveRows(QModelIndex(), indexOfNoteById(id), indexOfNoteById(id));
|
beginRemoveRows(QModelIndex(), indexOfNoteById(id), indexOfNoteById(id));
|
||||||
|
@ -130,7 +133,7 @@ void NotesModel::deleteNote(const int id) {
|
||||||
qDebug() << "Note not found";
|
qDebug() << "Note not found";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
emit noteDeleted(id);
|
emit noteRemoved(id);
|
||||||
}
|
}
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,18 +66,18 @@ public:
|
||||||
public slots:
|
public slots:
|
||||||
Q_INVOKABLE const QJsonArray getAllNotes(const QStringList& exclude = QStringList());
|
Q_INVOKABLE const QJsonArray getAllNotes(const QStringList& exclude = QStringList());
|
||||||
Q_INVOKABLE const QJsonObject getNote(const int id, const QStringList& exclude = QStringList());
|
Q_INVOKABLE const QJsonObject getNote(const int id, const QStringList& exclude = QStringList());
|
||||||
Q_INVOKABLE void createNote(const int id, const QJsonObject& note);
|
Q_INVOKABLE void insertNote(const int id, const QJsonObject& note);
|
||||||
Q_INVOKABLE void updateNote(const int id, const QJsonObject& note);
|
Q_INVOKABLE void updateNote(const int id, const QJsonObject& note);
|
||||||
Q_INVOKABLE void deleteNote(const int id);
|
Q_INVOKABLE void removeNote(const int id);
|
||||||
|
|
||||||
Q_INVOKABLE void clear();
|
Q_INVOKABLE void clear();
|
||||||
Q_INVOKABLE int indexOfNoteById(int id) const;
|
Q_INVOKABLE int indexOfNoteById(int id) const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int> ());
|
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int> ());
|
||||||
void noteCreated(const int id, const QJsonObject& note);
|
void noteInserted(const int id, const QJsonObject& note);
|
||||||
void noteUpdated(const int id, const QJsonObject& note);
|
void noteUpdated(const int id, const QJsonObject& note);
|
||||||
void noteDeleted(const int id);
|
void noteRemoved(const int id);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QMap<int, QJsonObject> m_notes;
|
QMap<int, QJsonObject> m_notes;
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
const QString NotesStore::m_suffix = "json";
|
const QString NotesStore::m_suffix = "json";
|
||||||
|
|
||||||
NotesStore::NotesStore(QString directory, QObject *parent)
|
NotesStore::NotesStore(QString directory, QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
m_dir.setCurrent(directory);
|
m_dir.setCurrent(directory);
|
||||||
m_dir.setPath("");
|
m_dir.setPath("");
|
||||||
|
@ -101,15 +101,15 @@ const QJsonObject NotesStore::getNote(const int id, const QStringList& exclude)
|
||||||
QJsonObject note;
|
QJsonObject note;
|
||||||
if (id >= 0) {
|
if (id >= 0) {
|
||||||
note = readNoteFile(id, exclude);
|
note = readNoteFile(id, exclude);
|
||||||
|
emit noteUpdated(id, note);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
qDebug() << "Skipping, invalid ID";
|
qDebug() << "Skipping, invalid ID";
|
||||||
}
|
}
|
||||||
return note;
|
return note;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
bool NotesStore::createNote(const QJsonObject& note) {
|
bool NotesStore::createNote(const int id, const QJsonObject& note) {
|
||||||
int id = note.value("id").toInt(-1);
|
|
||||||
qDebug() << "Creating note: " << id;
|
qDebug() << "Creating note: " << id;
|
||||||
if (id < 0) {
|
if (id < 0) {
|
||||||
// TODO probably crate files with an '.json.<NUMBER>.new' extension
|
// TODO probably crate files with an '.json.<NUMBER>.new' extension
|
||||||
|
@ -126,8 +126,8 @@ bool NotesStore::createNote(const QJsonObject& note) {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
const QJsonObject NotesStore::updateNote(const int id, const QJsonObject& note) {
|
bool NotesStore::updateNote(const int id, const QJsonObject& note) {
|
||||||
qDebug() << "Updating note: " << id;
|
qDebug() << "Updating note: " << id;
|
||||||
if (id >= 0) {
|
if (id >= 0) {
|
||||||
QJsonObject tmpNote = readNoteFile(id);
|
QJsonObject tmpNote = readNoteFile(id);
|
||||||
|
@ -142,6 +142,7 @@ const QJsonObject NotesStore::updateNote(const int id, const QJsonObject& note)
|
||||||
}
|
}
|
||||||
if (writeNoteFile(id, tmpNote)) {
|
if (writeNoteFile(id, tmpNote)) {
|
||||||
emit noteUpdated(id, tmpNote);
|
emit noteUpdated(id, tmpNote);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -155,13 +156,16 @@ const QJsonObject NotesStore::updateNote(const int id, const QJsonObject& note)
|
||||||
else {
|
else {
|
||||||
qDebug() << "Skipping, invalid ID";
|
qDebug() << "Skipping, invalid ID";
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NotesStore::deleteNote(const int id) {
|
bool NotesStore::deleteNote(const int id) {
|
||||||
qDebug() << "Deleting note: " << id;
|
qDebug() << "Deleting note: " << id;
|
||||||
if (removeNoteFile(id)) {
|
if (removeNoteFile(id)) {
|
||||||
emit noteDeleted(id);
|
emit noteDeleted(id);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NotesStore::noteFileExists(const int id) const {
|
bool NotesStore::noteFileExists(const int id) const {
|
||||||
|
|
|
@ -17,6 +17,8 @@ public:
|
||||||
QObject *parent = nullptr);
|
QObject *parent = nullptr);
|
||||||
virtual ~NotesStore();
|
virtual ~NotesStore();
|
||||||
|
|
||||||
|
Q_PROPERTY(QString account READ account WRITE setAccount NOTIFY accountChanged)
|
||||||
|
|
||||||
QString account() const;
|
QString account() const;
|
||||||
void setAccount(const QString& account);
|
void setAccount(const QString& account);
|
||||||
|
|
||||||
|
@ -35,13 +37,13 @@ public:
|
||||||
public slots:
|
public slots:
|
||||||
Q_INVOKABLE const QJsonArray getAllNotes(const QStringList& exclude = QStringList());
|
Q_INVOKABLE const QJsonArray getAllNotes(const QStringList& exclude = QStringList());
|
||||||
Q_INVOKABLE const QJsonObject getNote(const int id, const QStringList& exclude = QStringList());
|
Q_INVOKABLE const QJsonObject getNote(const int id, const QStringList& exclude = QStringList());
|
||||||
Q_INVOKABLE bool createNote(const QJsonObject& note);
|
//Q_INVOKABLE bool createNote(const int id, const QJsonObject& note);
|
||||||
Q_INVOKABLE const QJsonObject updateNote(const int id, const QJsonObject& note);
|
Q_INVOKABLE bool updateNote(const int id, const QJsonObject& note);
|
||||||
Q_INVOKABLE bool deleteNote(const int id);
|
Q_INVOKABLE bool deleteNote(const int id);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void accountChanged(const QString& account);
|
void accountChanged(const QString& account);
|
||||||
void noteCreated(const int id, const QJsonObject& note);
|
//void noteCreated(const int id, const QJsonObject& note);
|
||||||
void noteUpdated(const int id, const QJsonObject& note);
|
void noteUpdated(const int id, const QJsonObject& note);
|
||||||
void noteDeleted(const int id);
|
void noteDeleted(const int id);
|
||||||
void noteError(const ErrorCodes error);
|
void noteError(const ErrorCodes error);
|
||||||
|
|
|
@ -311,32 +311,32 @@
|
||||||
<context>
|
<context>
|
||||||
<name>NotesApi</name>
|
<name>NotesApi</name>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../src/notesapi.cpp" line="303"/>
|
<location filename="../src/notesapi.cpp" line="313"/>
|
||||||
<source>No error</source>
|
<source>No error</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../src/notesapi.cpp" line="306"/>
|
<location filename="../src/notesapi.cpp" line="316"/>
|
||||||
<source>No network connection available</source>
|
<source>No network connection available</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../src/notesapi.cpp" line="309"/>
|
<location filename="../src/notesapi.cpp" line="319"/>
|
||||||
<source>Failed to communicate with the Nextcloud server</source>
|
<source>Failed to communicate with the Nextcloud server</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../src/notesapi.cpp" line="312"/>
|
<location filename="../src/notesapi.cpp" line="322"/>
|
||||||
<source>An error occured while establishing an encrypted connection</source>
|
<source>An error occured while establishing an encrypted connection</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../src/notesapi.cpp" line="315"/>
|
<location filename="../src/notesapi.cpp" line="325"/>
|
||||||
<source>Could not authenticate to the Nextcloud instance</source>
|
<source>Could not authenticate to the Nextcloud instance</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../src/notesapi.cpp" line="318"/>
|
<location filename="../src/notesapi.cpp" line="328"/>
|
||||||
<source>Unknown error</source>
|
<source>Unknown error</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
@ -878,27 +878,27 @@ You can also use other markdown syntax inside them.</source>
|
||||||
<context>
|
<context>
|
||||||
<name>harbour-nextcloudnotes</name>
|
<name>harbour-nextcloudnotes</name>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../qml/harbour-nextcloudnotes.qml" line="125"/>
|
<location filename="../qml/harbour-nextcloudnotes.qml" line="124"/>
|
||||||
<source>Notes</source>
|
<source>Notes</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../qml/harbour-nextcloudnotes.qml" line="126"/>
|
<location filename="../qml/harbour-nextcloudnotes.qml" line="125"/>
|
||||||
<source>Offline</source>
|
<source>Offline</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../qml/harbour-nextcloudnotes.qml" line="127"/>
|
<location filename="../qml/harbour-nextcloudnotes.qml" line="126"/>
|
||||||
<source>Synced</source>
|
<source>Synced</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../qml/harbour-nextcloudnotes.qml" line="141"/>
|
<location filename="../qml/harbour-nextcloudnotes.qml" line="140"/>
|
||||||
<source>API error</source>
|
<source>API error</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../qml/harbour-nextcloudnotes.qml" line="134"/>
|
<location filename="../qml/harbour-nextcloudnotes.qml" line="133"/>
|
||||||
<source>File error</source>
|
<source>File error</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
|
Loading…
Reference in a new issue