diff --git a/qml/harbour-nextcloudnotes.qml b/qml/harbour-nextcloudnotes.qml index 901ea1e..97d7129 100644 --- a/qml/harbour-nextcloudnotes.qml +++ b/qml/harbour-nextcloudnotes.qml @@ -32,11 +32,6 @@ ApplicationWindow onUsernameChanged: notesApi.username = username onPasswordChanged: notesApi.password = password onDoNotVerifySslChanged: notesApi.verifySsl = !doNotVerifySsl - onPathChanged: { - notesModel.sourceModel.clear() - notesStore.account = appSettings.currentAccount - notesApi.account = appSettings.currentAccount - } } // General settings of the app @@ -54,6 +49,16 @@ ApplicationWindow property bool useMonoFont: value("useMonoFont", false, Boolean) property bool useCapitalX: value("useCapitalX", false, Boolean) + onCurrentAccountChanged: { + //console.log("currentAccountChanged") + notesModel.sourceModel.clear() + account.path = "/apps/harbour-nextcloudnotes/accounts/" + currentAccount + notesStore.account = currentAccount + notesStore.getAllNotes() + notesApi.account = currentAccount + notesApi.getAllNotes() + } + onSortByChanged: { if (sortBy == "none") notesModel.invalidate() @@ -154,7 +159,7 @@ ApplicationWindow onAccountChanged: { //console.log(notesStore.account) - notesStore.getAllNotes() + //notesStore.getAllNotes() } } @@ -163,7 +168,7 @@ ApplicationWindow onAccountChanged: { //console.log(notesStore.account) - notesApi.getAllNotes() + //notesApi.getAllNotes() } onNetworkAccessibleChanged: { console.log("Device is " + (accessible ? "online" : "offline")) diff --git a/qml/js/showdown b/qml/js/showdown index 483e51f..8afa1ff 160000 --- a/qml/js/showdown +++ b/qml/js/showdown @@ -1 +1 @@ -Subproject commit 483e51f7a624c94c95787a14cbf577c053f8076f +Subproject commit 8afa1fff0e1de2481e0545be17a906e2a68bb4e2 diff --git a/src/harbour-nextcloudnotes.cpp b/src/harbour-nextcloudnotes.cpp index cbcf397..eef617c 100644 --- a/src/harbour-nextcloudnotes.cpp +++ b/src/harbour-nextcloudnotes.cpp @@ -30,9 +30,9 @@ int main(int argc, char *argv[]) NotesStore* notesStore = new NotesStore; NotesApi* notesApi = new NotesApi; - //QObject::connect(notesApi, SIGNAL(noteUpdated(Note)), notesStore, SLOT(updateNote(Note))); + QObject::connect(notesApi, SIGNAL(noteUpdated(Note)), notesStore, SLOT(updateNote(Note))); //QObject::connect(notesStore, SIGNAL(noteUpdated(Note)), notesApi, SLOT(updateNote(Note))); - //QObject::connect(notesApi, SIGNAL(noteDeleted(int)), notesStore, SLOT(deleteNote(int))); + QObject::connect(notesApi, SIGNAL(noteDeleted(int)), notesStore, SLOT(deleteNote(int))); //QObject::connect(notesStore, SIGNAL(noteDeleted(int)), notesApi, SLOT(deleteNote(int))); QObject::connect(notesStore, SIGNAL(noteUpdated(Note)), notesModel, SLOT(insertNote(Note))); @@ -60,9 +60,9 @@ int main(int argc, char *argv[]) QObject::disconnect(notesStore, SIGNAL(noteUpdated(Note)), notesModel, SLOT(insertNote(Note))); //QObject::disconnect(notesStore, SIGNAL(noteDeleted(int)), notesApi, SLOT(deleteNote(int))); - //QObject::disconnect(notesApi, SIGNAL(noteDeleted(int)), notesStore, 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(Note)), notesStore, SLOT(updateNote(Note))); + QObject::disconnect(notesApi, SIGNAL(noteUpdated(Note)), notesStore, SLOT(updateNote(Note))); notesApi->deleteLater(); notesStore->deleteLater(); diff --git a/src/note.cpp b/src/note.cpp index 633efc2..a0f59de 100644 --- a/src/note.cpp +++ b/src/note.cpp @@ -32,7 +32,7 @@ Note::Note(const Note& note, QObject *parent) : QObject(parent) { connectSignals(); } -Note::Note(const QJsonObject ¬e, QObject *parent) { +Note::Note(const QJsonObject ¬e, QObject *parent) : QObject(parent) { setId(id(note)); setModified(modified(note)); setTitle(title(note)); diff --git a/src/notesapi.cpp b/src/notesapi.cpp index bd7c086..be32440 100644 --- a/src/notesapi.cpp +++ b/src/notesapi.cpp @@ -45,7 +45,7 @@ NotesApi::~NotesApi() { } void NotesApi::setAccount(const QString &account) { - qDebug() << "Setting account: " << account; + //qDebug() << "Setting account: " << account; if (account != m_account) { m_account = account; // TODO reset the class @@ -54,7 +54,7 @@ void NotesApi::setAccount(const QString &account) { } void NotesApi::getAllNotes(Note::NoteField exclude) { - qDebug() << "Getting all notes"; + //qDebug() << "Getting all notes"; QUrl url = apiEndpointUrl(m_notesEndpoint); QStringList excludeFields; QList noteFields = Note::noteFields(); @@ -77,7 +77,7 @@ void NotesApi::getAllNotes(Note::NoteField exclude) { } void NotesApi::getNote(const int id, Note::NoteField exclude) { - qDebug() << "Getting note: " << id; + //qDebug() << "Getting note: " << id; QUrl url = apiEndpointUrl(m_notesEndpoint + QString("/%1").arg(id)); QStringList excludeFields; QList noteFields = Note::noteFields(); @@ -100,8 +100,7 @@ void NotesApi::getNote(const int id, Note::NoteField exclude) { } void NotesApi::createNote(const Note ¬e) { - // TODO verify modified - qDebug() << "Creating note: " << note.id(); + //qDebug() << "Creating note: " << note.id(); QUrl url = apiEndpointUrl(m_notesEndpoint); if (url.isValid() && !url.scheme().isEmpty() && !url.host().isEmpty()) { qDebug() << "POST" << url.toDisplayString(); @@ -112,8 +111,7 @@ void NotesApi::createNote(const Note ¬e) { } void NotesApi::updateNote(const Note ¬e) { - // TODO verify modified - qDebug() << "Updating note: " << note.id(); + //qDebug() << "Updating note: " << note.id(); QUrl url = apiEndpointUrl(m_notesEndpoint + QString("/%1").arg(note.id())); if (url.isValid() && !url.scheme().isEmpty() && !url.host().isEmpty()) { qDebug() << "PUT" << url.toDisplayString(); @@ -124,7 +122,7 @@ void NotesApi::updateNote(const Note ¬e) { } void NotesApi::deleteNote(const int id) { - qDebug() << "Deleting note: " << id; + //qDebug() << "Deleting note: " << id; QUrl url = apiEndpointUrl(m_notesEndpoint + QString("/%1").arg(id)); if (url.isValid() && !url.scheme().isEmpty() && !url.host().isEmpty()) { qDebug() << "DELETE" << url.toDisplayString(); diff --git a/src/notesmodel.cpp b/src/notesmodel.cpp index cfb70e8..5b52139 100644 --- a/src/notesmodel.cpp +++ b/src/notesmodel.cpp @@ -59,7 +59,7 @@ QVector NotesModel::ids() const { } int NotesModel::insertNote(const Note ¬e) { - qDebug() << "Inserting note: " << note.id(); + //qDebug() << "Inserting note: " << note.id(); int position = m_notes.indexOf(note); if (position >= 0) { if (m_notes.at(position).equal(note)) { @@ -85,7 +85,7 @@ int NotesModel::insertNote(const Note ¬e) { } bool NotesModel::removeNote(const Note ¬e) { - qDebug() << "Removing note: " << note.id(); + //qDebug() << "Removing note: " << note.id(); int position = m_notes.indexOf(note); if (position >= 0 && position < m_notes.size()) { beginRemoveRows(QModelIndex(), position, position); @@ -98,17 +98,15 @@ bool NotesModel::removeNote(const Note ¬e) { } bool NotesModel::removeNote(int id) { - qDebug() << "Removing note: " << id; + //qDebug() << "Removing note: " << id; return removeNote(Note(QJsonObject{ {"id", id} } )); } void NotesModel::clear() { - qDebug() << "Clearing model"; - int lastNoteIndex = m_notes.size() - 1; - beginRemoveRows(QModelIndex(), 0, lastNoteIndex); + //qDebug() << "Clearing model"; + beginResetModel(); m_notes.clear(); - endRemoveRows(); - emit dataChanged(index(0), index(lastNoteIndex)); + endResetModel(); } QHash NotesModel::roleNames() const { diff --git a/src/notesstore.cpp b/src/notesstore.cpp index 1e7f2fb..3210ec3 100644 --- a/src/notesstore.cpp +++ b/src/notesstore.cpp @@ -23,7 +23,7 @@ QString NotesStore::account() const { } void NotesStore::setAccount(const QString& account) { - qDebug() << "Setting account: " << account; + //qDebug() << "Setting account: " << account; if (account != m_dir.path()) { if (m_dir != QDir(QStandardPaths::writableLocation(QStandardPaths::DataLocation))) { m_dir.cdUp(); @@ -40,7 +40,7 @@ void NotesStore::setAccount(const QString& account) { } void NotesStore::getAllNotes(Note::NoteField exclude) { - qDebug() << "Getting all notes"; + //qDebug() << "Getting all notes"; QFileInfoList files = m_dir.entryInfoList(); for (int i = 0; i < files.size(); ++i) { bool ok; @@ -52,7 +52,7 @@ void NotesStore::getAllNotes(Note::NoteField exclude) { } void NotesStore::getNote(const int id, Note::NoteField exclude) { - qDebug() << "Getting note: " << id; + //qDebug() << "Getting note: " << id; if (id >= 0) { Note note = readNoteFile(id, exclude); if (note.isValid()) @@ -61,8 +61,7 @@ void NotesStore::getNote(const int id, Note::NoteField exclude) { } void NotesStore::createNote(const Note& note) { - // TODO verify modified - qDebug() << "Creating note: " << note.id(); + //qDebug() << "Creating note: " << note.id(); if (!note.isValid()) { // TODO probably crate files with an '.json..new' extension qDebug() << "Creating notes without the server API is not supported yet!"; @@ -75,11 +74,10 @@ void NotesStore::createNote(const Note& note) { } void NotesStore::updateNote(const Note& note) { - // TODO verify modified - qDebug() << "Updating note: " << note.id(); + //qDebug() << "Updating note: " << note.id(); if (note.isValid()) { Note file = readNoteFile(note.id()); - if (!file.equal(note)) { + if (!file.equal(note) && note > file) { if (writeNoteFile(note)) { emit noteUpdated(note); } @@ -88,7 +86,7 @@ void NotesStore::updateNote(const Note& note) { } void NotesStore::deleteNote(const int id) { - qDebug() << "Deleting note: " << id; + //qDebug() << "Deleting note: " << id; if (removeNoteFile(id)) { emit noteDeleted(id); } diff --git a/translations/harbour-nextcloudnotes.ts b/translations/harbour-nextcloudnotes.ts index e2b3fd4..67f5500 100644 --- a/translations/harbour-nextcloudnotes.ts +++ b/translations/harbour-nextcloudnotes.ts @@ -311,37 +311,37 @@ NotesApi - + No network connection available - + Failed to communicate with the Nextcloud server - + An error happened while reading from the local storage - + An error happened while writing to the local storage - + An error occured while establishing an encrypted connection - + Could not authenticate to the Nextcloud instance - + Unknown error @@ -840,22 +840,22 @@ You can also use other markdown syntax inside them. harbour-nextcloudnotes - + Notes - + Offline - + Synced - + Error