Improved relations between the data sources

This commit is contained in:
Scharel Clemens 2020-04-11 16:39:30 +02:00
parent 10b9423f35
commit 884a464a37
8 changed files with 48 additions and 49 deletions

View file

@ -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"))

@ -1 +1 @@
Subproject commit 483e51f7a624c94c95787a14cbf577c053f8076f
Subproject commit 8afa1fff0e1de2481e0545be17a906e2a68bb4e2

View file

@ -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();

View file

@ -32,7 +32,7 @@ Note::Note(const Note& note, QObject *parent) : QObject(parent) {
connectSignals();
}
Note::Note(const QJsonObject &note, QObject *parent) {
Note::Note(const QJsonObject &note, QObject *parent) : QObject(parent) {
setId(id(note));
setModified(modified(note));
setTitle(title(note));

View file

@ -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<Note::NoteField> 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<Note::NoteField> noteFields = Note::noteFields();
@ -100,8 +100,7 @@ void NotesApi::getNote(const int id, Note::NoteField exclude) {
}
void NotesApi::createNote(const Note &note) {
// 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 &note) {
}
void NotesApi::updateNote(const Note &note) {
// 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 &note) {
}
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();

View file

@ -59,7 +59,7 @@ QVector<int> NotesModel::ids() const {
}
int NotesModel::insertNote(const Note &note) {
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 &note) {
}
bool NotesModel::removeNote(const Note &note) {
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 &note) {
}
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<int, QByteArray> NotesModel::roleNames() const {

View file

@ -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.<NUMBER>.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);
}

View file

@ -311,37 +311,37 @@
<context>
<name>NotesApi</name>
<message>
<location filename="../src/notesapi.cpp" line="343"/>
<location filename="../src/notesapi.cpp" line="341"/>
<source>No network connection available</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/notesapi.cpp" line="346"/>
<location filename="../src/notesapi.cpp" line="344"/>
<source>Failed to communicate with the Nextcloud server</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/notesapi.cpp" line="349"/>
<location filename="../src/notesapi.cpp" line="347"/>
<source>An error happened while reading from the local storage</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/notesapi.cpp" line="352"/>
<location filename="../src/notesapi.cpp" line="350"/>
<source>An error happened while writing to the local storage</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/notesapi.cpp" line="355"/>
<location filename="../src/notesapi.cpp" line="353"/>
<source>An error occured while establishing an encrypted connection</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/notesapi.cpp" line="358"/>
<location filename="../src/notesapi.cpp" line="356"/>
<source>Could not authenticate to the Nextcloud instance</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/notesapi.cpp" line="361"/>
<location filename="../src/notesapi.cpp" line="359"/>
<source>Unknown error</source>
<translation type="unfinished"></translation>
</message>
@ -840,22 +840,22 @@ You can also use other markdown syntax inside them.</source>
<context>
<name>harbour-nextcloudnotes</name>
<message>
<location filename="../qml/harbour-nextcloudnotes.qml" line="117"/>
<location filename="../qml/harbour-nextcloudnotes.qml" line="122"/>
<source>Notes</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/harbour-nextcloudnotes.qml" line="118"/>
<location filename="../qml/harbour-nextcloudnotes.qml" line="123"/>
<source>Offline</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/harbour-nextcloudnotes.qml" line="119"/>
<location filename="../qml/harbour-nextcloudnotes.qml" line="124"/>
<source>Synced</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/harbour-nextcloudnotes.qml" line="126"/>
<location filename="../qml/harbour-nextcloudnotes.qml" line="131"/>
<source>Error</source>
<translation type="unfinished"></translation>
</message>