Prepare sync of offline changed notes

This commit is contained in:
Scharel Clemens 2020-05-03 13:00:36 +02:00
parent 8211acbe51
commit 842ea9f699
5 changed files with 37 additions and 16 deletions

View file

@ -204,6 +204,7 @@ Page {
TextSwitch {
id: forceLegacyButton
visible: debug
text: qsTr("Enforce legacy login")
onCheckedChanged: {
checked != checked

View file

@ -177,6 +177,13 @@ bool NotesModel::deleteNote(const int id) {
return success;
}
bool NotesModel::syncNotes() {
if (mp_notesApi && mp_notesStore) {
// TODO
}
return false;
}
void NotesModel::insert(const int id, const QJsonObject& note) {
qDebug() << "Inserting note: " << id;
if (m_notes.contains(id)) {
@ -215,11 +222,11 @@ void NotesModel::remove(const int id) {
qDebug() << "Removing note: " << id;
if (m_notes.contains(id)) {
beginRemoveRows(QModelIndex(), indexOfNoteById(id), indexOfNoteById(id));
if (m_notes.remove(id) == 0) {
qDebug() << "Note not found";
if (m_notes.remove(id) > 0) {
emit noteDeleted(id);
}
else {
//emit noteRemoved(id);
qDebug() << "Note not found";
}
endRemoveRows();
}

View file

@ -80,6 +80,7 @@ public slots:
Q_INVOKABLE bool createNote(const QJsonObject& note);
Q_INVOKABLE bool updateNote(const int id, const QJsonObject& note);
Q_INVOKABLE bool deleteNote(const int id);
Q_INVOKABLE bool syncNotes();
void insert(const int id, const QJsonObject& note);
void update(const int id, const QJsonObject& note);

View file

@ -76,6 +76,25 @@ const QString NotesStore::errorMessage(ErrorCodes error) const {
return message;
}
const QList<int> NotesStore::noteFileIdList() {
QList<int> ids;
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) {
ids << id;
}
}
}
else {
qDebug() << errorMessage(DirNotFoundError);
emit noteError(DirCannotReadError);
}
return ids;
}
bool NotesStore::noteFileExists(const int id) const {
QFileInfo fileinfo(m_dir, QString("%1.%2").arg(id).arg(m_suffix));
return fileinfo.exists();
@ -145,25 +164,17 @@ bool NotesStore::removeNoteFile(const int id) {
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)));
}
const QList<int> ids = noteFileIdList();
if (!ids.empty()) {
for (int i = 0; i < ids.size(); ++i) {
getNote(ids.at(i), 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;

View file

@ -36,6 +36,7 @@ public:
Q_ENUM(ErrorCodes)
Q_INVOKABLE const QString errorMessage(ErrorCodes error) const;
const QList<int> noteFileIdList();
bool noteFileExists(const int id) const;
QJsonObject readNoteFile(const int id, const QStringList& exclude = QStringList());
bool writeNoteFile(const int id, const QJsonObject& note);