Improved relations between the data sources
This commit is contained in:
parent
10b9423f35
commit
884a464a37
8 changed files with 48 additions and 49 deletions
|
@ -32,11 +32,6 @@ ApplicationWindow
|
||||||
onUsernameChanged: notesApi.username = username
|
onUsernameChanged: notesApi.username = username
|
||||||
onPasswordChanged: notesApi.password = password
|
onPasswordChanged: notesApi.password = password
|
||||||
onDoNotVerifySslChanged: notesApi.verifySsl = !doNotVerifySsl
|
onDoNotVerifySslChanged: notesApi.verifySsl = !doNotVerifySsl
|
||||||
onPathChanged: {
|
|
||||||
notesModel.sourceModel.clear()
|
|
||||||
notesStore.account = appSettings.currentAccount
|
|
||||||
notesApi.account = appSettings.currentAccount
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// General settings of the app
|
// General settings of the app
|
||||||
|
@ -54,6 +49,16 @@ ApplicationWindow
|
||||||
property bool useMonoFont: value("useMonoFont", false, Boolean)
|
property bool useMonoFont: value("useMonoFont", false, Boolean)
|
||||||
property bool useCapitalX: value("useCapitalX", 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: {
|
onSortByChanged: {
|
||||||
if (sortBy == "none")
|
if (sortBy == "none")
|
||||||
notesModel.invalidate()
|
notesModel.invalidate()
|
||||||
|
@ -154,7 +159,7 @@ ApplicationWindow
|
||||||
|
|
||||||
onAccountChanged: {
|
onAccountChanged: {
|
||||||
//console.log(notesStore.account)
|
//console.log(notesStore.account)
|
||||||
notesStore.getAllNotes()
|
//notesStore.getAllNotes()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,7 +168,7 @@ ApplicationWindow
|
||||||
|
|
||||||
onAccountChanged: {
|
onAccountChanged: {
|
||||||
//console.log(notesStore.account)
|
//console.log(notesStore.account)
|
||||||
notesApi.getAllNotes()
|
//notesApi.getAllNotes()
|
||||||
}
|
}
|
||||||
onNetworkAccessibleChanged: {
|
onNetworkAccessibleChanged: {
|
||||||
console.log("Device is " + (accessible ? "online" : "offline"))
|
console.log("Device is " + (accessible ? "online" : "offline"))
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 483e51f7a624c94c95787a14cbf577c053f8076f
|
Subproject commit 8afa1fff0e1de2481e0545be17a906e2a68bb4e2
|
|
@ -30,9 +30,9 @@ 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(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(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(noteDeleted(int)), notesApi, SLOT(deleteNote(int)));
|
||||||
|
|
||||||
QObject::connect(notesStore, SIGNAL(noteUpdated(Note)), notesModel, SLOT(insertNote(Note)));
|
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(noteUpdated(Note)), notesModel, SLOT(insertNote(Note)));
|
||||||
|
|
||||||
//QObject::disconnect(notesStore, SIGNAL(noteDeleted(int)), notesApi, SLOT(deleteNote(int)));
|
//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(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();
|
notesApi->deleteLater();
|
||||||
notesStore->deleteLater();
|
notesStore->deleteLater();
|
||||||
|
|
|
@ -32,7 +32,7 @@ Note::Note(const Note& note, QObject *parent) : QObject(parent) {
|
||||||
connectSignals();
|
connectSignals();
|
||||||
}
|
}
|
||||||
|
|
||||||
Note::Note(const QJsonObject ¬e, QObject *parent) {
|
Note::Note(const QJsonObject ¬e, QObject *parent) : QObject(parent) {
|
||||||
setId(id(note));
|
setId(id(note));
|
||||||
setModified(modified(note));
|
setModified(modified(note));
|
||||||
setTitle(title(note));
|
setTitle(title(note));
|
||||||
|
|
|
@ -45,7 +45,7 @@ NotesApi::~NotesApi() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotesApi::setAccount(const QString &account) {
|
void NotesApi::setAccount(const QString &account) {
|
||||||
qDebug() << "Setting account: " << account;
|
//qDebug() << "Setting account: " << account;
|
||||||
if (account != m_account) {
|
if (account != m_account) {
|
||||||
m_account = account;
|
m_account = account;
|
||||||
// TODO reset the class
|
// TODO reset the class
|
||||||
|
@ -54,7 +54,7 @@ void NotesApi::setAccount(const QString &account) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotesApi::getAllNotes(Note::NoteField exclude) {
|
void NotesApi::getAllNotes(Note::NoteField exclude) {
|
||||||
qDebug() << "Getting all notes";
|
//qDebug() << "Getting all notes";
|
||||||
QUrl url = apiEndpointUrl(m_notesEndpoint);
|
QUrl url = apiEndpointUrl(m_notesEndpoint);
|
||||||
QStringList excludeFields;
|
QStringList excludeFields;
|
||||||
QList<Note::NoteField> noteFields = Note::noteFields();
|
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) {
|
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));
|
QUrl url = apiEndpointUrl(m_notesEndpoint + QString("/%1").arg(id));
|
||||||
QStringList excludeFields;
|
QStringList excludeFields;
|
||||||
QList<Note::NoteField> noteFields = Note::noteFields();
|
QList<Note::NoteField> noteFields = Note::noteFields();
|
||||||
|
@ -100,8 +100,7 @@ void NotesApi::getNote(const int id, Note::NoteField exclude) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotesApi::createNote(const Note ¬e) {
|
void NotesApi::createNote(const Note ¬e) {
|
||||||
// TODO verify modified
|
//qDebug() << "Creating note: " << note.id();
|
||||||
qDebug() << "Creating note: " << note.id();
|
|
||||||
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()) {
|
||||||
qDebug() << "POST" << url.toDisplayString();
|
qDebug() << "POST" << url.toDisplayString();
|
||||||
|
@ -112,8 +111,7 @@ void NotesApi::createNote(const Note ¬e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotesApi::updateNote(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()));
|
QUrl url = apiEndpointUrl(m_notesEndpoint + QString("/%1").arg(note.id()));
|
||||||
if (url.isValid() && !url.scheme().isEmpty() && !url.host().isEmpty()) {
|
if (url.isValid() && !url.scheme().isEmpty() && !url.host().isEmpty()) {
|
||||||
qDebug() << "PUT" << url.toDisplayString();
|
qDebug() << "PUT" << url.toDisplayString();
|
||||||
|
@ -124,7 +122,7 @@ void NotesApi::updateNote(const Note ¬e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotesApi::deleteNote(const int id) {
|
void 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()) {
|
||||||
qDebug() << "DELETE" << url.toDisplayString();
|
qDebug() << "DELETE" << url.toDisplayString();
|
||||||
|
|
|
@ -59,7 +59,7 @@ QVector<int> NotesModel::ids() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
int NotesModel::insertNote(const Note ¬e) {
|
int NotesModel::insertNote(const Note ¬e) {
|
||||||
qDebug() << "Inserting note: " << note.id();
|
//qDebug() << "Inserting note: " << note.id();
|
||||||
int position = m_notes.indexOf(note);
|
int position = m_notes.indexOf(note);
|
||||||
if (position >= 0) {
|
if (position >= 0) {
|
||||||
if (m_notes.at(position).equal(note)) {
|
if (m_notes.at(position).equal(note)) {
|
||||||
|
@ -85,7 +85,7 @@ int NotesModel::insertNote(const Note ¬e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NotesModel::removeNote(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);
|
int position = m_notes.indexOf(note);
|
||||||
if (position >= 0 && position < m_notes.size()) {
|
if (position >= 0 && position < m_notes.size()) {
|
||||||
beginRemoveRows(QModelIndex(), position, position);
|
beginRemoveRows(QModelIndex(), position, position);
|
||||||
|
@ -98,17 +98,15 @@ bool NotesModel::removeNote(const Note ¬e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NotesModel::removeNote(int id) {
|
bool NotesModel::removeNote(int id) {
|
||||||
qDebug() << "Removing note: " << id;
|
//qDebug() << "Removing note: " << id;
|
||||||
return removeNote(Note(QJsonObject{ {"id", id} } ));
|
return removeNote(Note(QJsonObject{ {"id", id} } ));
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotesModel::clear() {
|
void NotesModel::clear() {
|
||||||
qDebug() << "Clearing model";
|
//qDebug() << "Clearing model";
|
||||||
int lastNoteIndex = m_notes.size() - 1;
|
beginResetModel();
|
||||||
beginRemoveRows(QModelIndex(), 0, lastNoteIndex);
|
|
||||||
m_notes.clear();
|
m_notes.clear();
|
||||||
endRemoveRows();
|
endResetModel();
|
||||||
emit dataChanged(index(0), index(lastNoteIndex));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<int, QByteArray> NotesModel::roleNames() const {
|
QHash<int, QByteArray> NotesModel::roleNames() const {
|
||||||
|
|
|
@ -23,7 +23,7 @@ QString NotesStore::account() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotesStore::setAccount(const QString& account) {
|
void NotesStore::setAccount(const QString& account) {
|
||||||
qDebug() << "Setting account: " << account;
|
//qDebug() << "Setting account: " << account;
|
||||||
if (account != m_dir.path()) {
|
if (account != m_dir.path()) {
|
||||||
if (m_dir != QDir(QStandardPaths::writableLocation(QStandardPaths::DataLocation))) {
|
if (m_dir != QDir(QStandardPaths::writableLocation(QStandardPaths::DataLocation))) {
|
||||||
m_dir.cdUp();
|
m_dir.cdUp();
|
||||||
|
@ -40,7 +40,7 @@ void NotesStore::setAccount(const QString& account) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotesStore::getAllNotes(Note::NoteField exclude) {
|
void NotesStore::getAllNotes(Note::NoteField exclude) {
|
||||||
qDebug() << "Getting all notes";
|
//qDebug() << "Getting all notes";
|
||||||
QFileInfoList files = m_dir.entryInfoList();
|
QFileInfoList files = m_dir.entryInfoList();
|
||||||
for (int i = 0; i < files.size(); ++i) {
|
for (int i = 0; i < files.size(); ++i) {
|
||||||
bool ok;
|
bool ok;
|
||||||
|
@ -52,7 +52,7 @@ void NotesStore::getAllNotes(Note::NoteField exclude) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotesStore::getNote(const int id, Note::NoteField exclude) {
|
void NotesStore::getNote(const int id, Note::NoteField exclude) {
|
||||||
qDebug() << "Getting note: " << id;
|
//qDebug() << "Getting note: " << id;
|
||||||
if (id >= 0) {
|
if (id >= 0) {
|
||||||
Note note = readNoteFile(id, exclude);
|
Note note = readNoteFile(id, exclude);
|
||||||
if (note.isValid())
|
if (note.isValid())
|
||||||
|
@ -61,8 +61,7 @@ void NotesStore::getNote(const int id, Note::NoteField exclude) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotesStore::createNote(const Note& note) {
|
void NotesStore::createNote(const Note& note) {
|
||||||
// TODO verify modified
|
//qDebug() << "Creating note: " << note.id();
|
||||||
qDebug() << "Creating note: " << note.id();
|
|
||||||
if (!note.isValid()) {
|
if (!note.isValid()) {
|
||||||
// TODO probably crate files with an '.json.<NUMBER>.new' extension
|
// TODO probably crate files with an '.json.<NUMBER>.new' extension
|
||||||
qDebug() << "Creating notes without the server API is not supported yet!";
|
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) {
|
void NotesStore::updateNote(const Note& note) {
|
||||||
// TODO verify modified
|
//qDebug() << "Updating note: " << note.id();
|
||||||
qDebug() << "Updating note: " << note.id();
|
|
||||||
if (note.isValid()) {
|
if (note.isValid()) {
|
||||||
Note file = readNoteFile(note.id());
|
Note file = readNoteFile(note.id());
|
||||||
if (!file.equal(note)) {
|
if (!file.equal(note) && note > file) {
|
||||||
if (writeNoteFile(note)) {
|
if (writeNoteFile(note)) {
|
||||||
emit noteUpdated(note);
|
emit noteUpdated(note);
|
||||||
}
|
}
|
||||||
|
@ -88,7 +86,7 @@ void NotesStore::updateNote(const Note& note) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotesStore::deleteNote(const int id) {
|
void 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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -311,37 +311,37 @@
|
||||||
<context>
|
<context>
|
||||||
<name>NotesApi</name>
|
<name>NotesApi</name>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../src/notesapi.cpp" line="343"/>
|
<location filename="../src/notesapi.cpp" line="341"/>
|
||||||
<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="346"/>
|
<location filename="../src/notesapi.cpp" line="344"/>
|
||||||
<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="349"/>
|
<location filename="../src/notesapi.cpp" line="347"/>
|
||||||
<source>An error happened while reading from the local storage</source>
|
<source>An error happened while reading from the local storage</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<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>
|
<source>An error happened while writing to the local storage</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<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>
|
<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="358"/>
|
<location filename="../src/notesapi.cpp" line="356"/>
|
||||||
<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="361"/>
|
<location filename="../src/notesapi.cpp" line="359"/>
|
||||||
<source>Unknown error</source>
|
<source>Unknown error</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
@ -840,22 +840,22 @@ 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="117"/>
|
<location filename="../qml/harbour-nextcloudnotes.qml" line="122"/>
|
||||||
<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="118"/>
|
<location filename="../qml/harbour-nextcloudnotes.qml" line="123"/>
|
||||||
<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="119"/>
|
<location filename="../qml/harbour-nextcloudnotes.qml" line="124"/>
|
||||||
<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="126"/>
|
<location filename="../qml/harbour-nextcloudnotes.qml" line="131"/>
|
||||||
<source>Error</source>
|
<source>Error</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
|
Loading…
Reference in a new issue