Change notes locally befor committing it to the server
This commit is contained in:
parent
20635dfd6e
commit
da29b4b0ff
5 changed files with 46 additions and 22 deletions
28
src/note.cpp
28
src/note.cpp
|
@ -1,17 +1,7 @@
|
|||
#include "note.h"
|
||||
|
||||
Note::Note(QObject *parent) : QObject(parent) {
|
||||
connect(this, SIGNAL(idChanged(double)), this, SIGNAL(noteChanged()));
|
||||
connect(this, SIGNAL(modifiedChanged(double)), this, SIGNAL(noteChanged()));
|
||||
connect(this, SIGNAL(titleChanged(QString)), this, SIGNAL(noteChanged()));
|
||||
connect(this, SIGNAL(categoryChanged(QString)), this, SIGNAL(noteChanged()));
|
||||
connect(this, SIGNAL(contentChanged(QString)), this, SIGNAL(noteChanged()));
|
||||
connect(this, SIGNAL(favoriteChanged(bool)), this, SIGNAL(noteChanged()));
|
||||
connect(this, SIGNAL(etagChanged(QString)), this, SIGNAL(noteChanged()));
|
||||
connect(this, SIGNAL(errorChanged(bool)), this, SIGNAL(noteChanged()));
|
||||
connect(this, SIGNAL(errorMessageChanged(QString)), this, SIGNAL(noteChanged()));
|
||||
connect(this, SIGNAL(prettyDateChanged(QString)), this, SIGNAL(noteChanged()));
|
||||
connect(this, SIGNAL(dateTimeChanged(QDateTime)), this, SIGNAL(noteChanged()));
|
||||
connectSignals();
|
||||
}
|
||||
|
||||
Note::Note(const Note& note, QObject *parent) : QObject(parent) {
|
||||
|
@ -24,6 +14,7 @@ Note::Note(const Note& note, QObject *parent) : QObject(parent) {
|
|||
setEtag(note.etag());
|
||||
setError(note.error());
|
||||
setErrorMessage(note.errorMessage());
|
||||
connectSignals();
|
||||
}
|
||||
|
||||
Note::Note(const QJsonObject ¬e, QObject *parent) {
|
||||
|
@ -36,6 +27,7 @@ Note::Note(const QJsonObject ¬e, QObject *parent) {
|
|||
setEtag(etag(note));
|
||||
setError(error(note));
|
||||
setErrorMessage(errorMessage(note));
|
||||
connectSignals();
|
||||
}
|
||||
|
||||
Note& Note::operator =(const Note& note) {
|
||||
|
@ -266,3 +258,17 @@ QDateTime Note::modifiedDateTime(const QJsonObject &jobj) {
|
|||
date.setTime_t(modified(jobj));
|
||||
return date;
|
||||
}
|
||||
|
||||
void Note::connectSignals() {
|
||||
connect(this, SIGNAL(idChanged(double)), this, SIGNAL(noteChanged()));
|
||||
connect(this, SIGNAL(modifiedChanged(double)), this, SIGNAL(noteChanged()));
|
||||
connect(this, SIGNAL(titleChanged(QString)), this, SIGNAL(noteChanged()));
|
||||
connect(this, SIGNAL(categoryChanged(QString)), this, SIGNAL(noteChanged()));
|
||||
connect(this, SIGNAL(contentChanged(QString)), this, SIGNAL(noteChanged()));
|
||||
connect(this, SIGNAL(favoriteChanged(bool)), this, SIGNAL(noteChanged()));
|
||||
connect(this, SIGNAL(etagChanged(QString)), this, SIGNAL(noteChanged()));
|
||||
connect(this, SIGNAL(errorChanged(bool)), this, SIGNAL(noteChanged()));
|
||||
connect(this, SIGNAL(errorMessageChanged(QString)), this, SIGNAL(noteChanged()));
|
||||
connect(this, SIGNAL(modifiedStringChanged(QString)), this, SIGNAL(noteChanged()));
|
||||
connect(this, SIGNAL(modifiedDateTimeChanged(QDateTime)), this, SIGNAL(noteChanged()));
|
||||
}
|
||||
|
|
|
@ -109,6 +109,8 @@ signals:
|
|||
|
||||
private:
|
||||
QJsonObject m_json;
|
||||
|
||||
void connectSignals();
|
||||
};
|
||||
|
||||
#endif // NOTE_H
|
||||
|
|
|
@ -181,28 +181,42 @@ void NotesApi::getNote(double noteId, QStringList excludeFields) {
|
|||
}
|
||||
|
||||
void NotesApi::createNote(QVariantMap fields) {
|
||||
// Update note in the model
|
||||
Note note(QJsonObject::fromVariantMap(fields));
|
||||
mp_model->insertNote(note);
|
||||
|
||||
// Create note via the API
|
||||
QUrl url = m_url;
|
||||
url.setPath(url.path() + "/notes");
|
||||
if (url.isValid()) {
|
||||
qDebug() << "POST" << url.toDisplayString();
|
||||
m_request.setUrl(url);
|
||||
m_replies << m_manager.post(m_request, QJsonDocument(QJsonObject::fromVariantMap(fields)).toJson());
|
||||
m_replies << m_manager.post(m_request, note.toJsonDocument().toJson());
|
||||
emit busyChanged(busy());
|
||||
}
|
||||
}
|
||||
|
||||
void NotesApi::updateNote(double noteId, QVariantMap fields) {
|
||||
// Update note in the model
|
||||
Note note(QJsonObject::fromVariantMap(fields));
|
||||
mp_model->insertNote(note);
|
||||
|
||||
// Update note on the server
|
||||
QUrl url = m_url;
|
||||
url.setPath(url.path() + QString("/notes/%1").arg(noteId));
|
||||
if (url.isValid()) {
|
||||
qDebug() << "PUT" << url.toDisplayString();
|
||||
m_request.setUrl(url);
|
||||
m_replies << m_manager.put(m_request, QJsonDocument(QJsonObject::fromVariantMap(fields)).toJson());
|
||||
m_replies << m_manager.put(m_request, note.toJsonDocument().toJson());
|
||||
emit busyChanged(busy());
|
||||
}
|
||||
}
|
||||
|
||||
void NotesApi::deleteNote(double noteId) {
|
||||
// Remove note from the model
|
||||
mp_model->removeNote(noteId);
|
||||
|
||||
// Remove note from the server
|
||||
QUrl url = m_url;
|
||||
url.setPath(url.path() + QString("/notes/%1").arg(noteId));
|
||||
if (url.isValid()) {
|
||||
|
|
|
@ -125,6 +125,8 @@ int NotesModel::insertNote(const Note ¬e) {
|
|||
}
|
||||
}
|
||||
else {
|
||||
if (note.id() < 0)
|
||||
qDebug() << "-- Local only note!";
|
||||
qDebug() << "-- New note, adding it";
|
||||
position = m_notes.size();
|
||||
beginInsertRows(QModelIndex(), position, position);
|
||||
|
|
|
@ -196,12 +196,12 @@
|
|||
<context>
|
||||
<name>Note</name>
|
||||
<message>
|
||||
<location filename="../src/note.cpp" line="249"/>
|
||||
<location filename="../src/note.cpp" line="241"/>
|
||||
<source>Today</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/note.cpp" line="251"/>
|
||||
<location filename="../src/note.cpp" line="243"/>
|
||||
<source>Yesterday</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
|
@ -262,37 +262,37 @@
|
|||
<context>
|
||||
<name>NotesApi</name>
|
||||
<message>
|
||||
<location filename="../src/notesapi.cpp" line="283"/>
|
||||
<location filename="../src/notesapi.cpp" line="299"/>
|
||||
<source>No network connection available</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/notesapi.cpp" line="286"/>
|
||||
<location filename="../src/notesapi.cpp" line="302"/>
|
||||
<source>Failed to communicate with the Nextcloud server</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/notesapi.cpp" line="289"/>
|
||||
<location filename="../src/notesapi.cpp" line="305"/>
|
||||
<source>An error happened while reading from the local storage</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/notesapi.cpp" line="292"/>
|
||||
<location filename="../src/notesapi.cpp" line="308"/>
|
||||
<source>An error happened while writing to the local storage</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/notesapi.cpp" line="295"/>
|
||||
<location filename="../src/notesapi.cpp" line="311"/>
|
||||
<source>An error occured while establishing an encrypted connection</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/notesapi.cpp" line="298"/>
|
||||
<location filename="../src/notesapi.cpp" line="314"/>
|
||||
<source>Could not authenticate to the Nextcloud instance</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/notesapi.cpp" line="301"/>
|
||||
<location filename="../src/notesapi.cpp" line="317"/>
|
||||
<source>Unknown error</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
|
|
Loading…
Reference in a new issue