Show more debug messages on the console

This commit is contained in:
Scharel Clemens 2020-04-11 19:34:28 +02:00
parent 884a464a37
commit 34484748f5
8 changed files with 44 additions and 51 deletions

View file

@ -29,9 +29,13 @@ ApplicationWindow
property bool allowUnecrypted: account.value("allowUnecrypted", false, Boolean) property bool allowUnecrypted: account.value("allowUnecrypted", false, Boolean)
property date update: value("update", "", Date) property date update: value("update", "", Date)
onServerChanged: notesApi.server = server onServerChanged: notesApi.server = server
onUsernameChanged: notesApi.username = username onUsernameChanged: {
console.log("Username: " + username)
notesApi.username = username
}
onPasswordChanged: notesApi.password = password onPasswordChanged: notesApi.password = password
onDoNotVerifySslChanged: notesApi.verifySsl = !doNotVerifySsl onDoNotVerifySslChanged: notesApi.verifySsl = !doNotVerifySsl
onNameChanged: console.log("Using account: " + name)
} }
// General settings of the app // General settings of the app
@ -50,7 +54,6 @@ ApplicationWindow
property bool useCapitalX: value("useCapitalX", false, Boolean) property bool useCapitalX: value("useCapitalX", false, Boolean)
onCurrentAccountChanged: { onCurrentAccountChanged: {
//console.log("currentAccountChanged")
notesModel.sourceModel.clear() notesModel.sourceModel.clear()
account.path = "/apps/harbour-nextcloudnotes/accounts/" + currentAccount account.path = "/apps/harbour-nextcloudnotes/accounts/" + currentAccount
notesStore.account = currentAccount notesStore.account = currentAccount
@ -154,22 +157,9 @@ ApplicationWindow
} }
} }
Connections {
target: notesStore
onAccountChanged: {
//console.log(notesStore.account)
//notesStore.getAllNotes()
}
}
Connections { Connections {
target: notesApi target: notesApi
onAccountChanged: {
//console.log(notesStore.account)
//notesApi.getAllNotes()
}
onNetworkAccessibleChanged: { onNetworkAccessibleChanged: {
console.log("Device is " + (accessible ? "online" : "offline")) console.log("Device is " + (accessible ? "online" : "offline"))
accessible ? offlineNotification.close(Notification.Closed) : offlineNotification.publish() accessible ? offlineNotification.close(Notification.Closed) : offlineNotification.publish()

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

View file

@ -1,6 +1,5 @@
import QtQuick 2.2 import QtQuick 2.2
import Sailfish.Silica 1.0 import Sailfish.Silica 1.0
//import harbour.nextcloudnotes.notesmodel 1.0
Page { Page {
id: page id: page

View file

@ -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,7 +100,7 @@ void NotesApi::getNote(const int id, Note::NoteField exclude) {
} }
void NotesApi::createNote(const Note &note) { void NotesApi::createNote(const Note &note) {
//qDebug() << "Creating note: " << note.id(); qDebug() << "Creating note";
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();
@ -111,9 +111,9 @@ void NotesApi::createNote(const Note &note) {
} }
void NotesApi::updateNote(const Note &note) { void NotesApi::updateNote(const Note &note) {
//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 (note.isValid() && url.isValid() && !url.scheme().isEmpty() && !url.host().isEmpty()) {
qDebug() << "PUT" << url.toDisplayString(); qDebug() << "PUT" << url.toDisplayString();
m_authenticatedRequest.setUrl(url); m_authenticatedRequest.setUrl(url);
m_notesReplies << m_manager.put(m_authenticatedRequest, noteApiData(note)); m_notesReplies << m_manager.put(m_authenticatedRequest, noteApiData(note));
@ -122,7 +122,7 @@ void NotesApi::updateNote(const Note &note) {
} }
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();

View file

@ -15,7 +15,7 @@ NotesProxyModel::~NotesProxyModel() {
} }
void NotesProxyModel::setFavoritesOnTop(bool favoritesOnTop) { void NotesProxyModel::setFavoritesOnTop(bool favoritesOnTop) {
//qDebug() << "Favorites on top:" << favoritesOnTop; qDebug() << "Favorites on top:" << favoritesOnTop;
if (favoritesOnTop != m_favoritesOnTop) { if (favoritesOnTop != m_favoritesOnTop) {
m_favoritesOnTop = favoritesOnTop; m_favoritesOnTop = favoritesOnTop;
emit favoritesOnTopChanged(m_favoritesOnTop); emit favoritesOnTopChanged(m_favoritesOnTop);
@ -38,7 +38,7 @@ bool NotesProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex
} }
void NotesProxyModel::sort() { void NotesProxyModel::sort() {
invalidate(); //invalidate();
QSortFilterProxyModel::sort(0); QSortFilterProxyModel::sort(0);
} }
@ -50,8 +50,8 @@ NotesModel::~NotesModel() {
clear(); clear();
} }
QVector<int> NotesModel::ids() const { QList<int> NotesModel::ids() const {
QVector<int> ids; QList<int> ids;
for (int i = 0; i < m_notes.size(); ++i) { for (int i = 0; i < m_notes.size(); ++i) {
ids.append(m_notes[i].id()); ids.append(m_notes[i].id());
} }
@ -59,22 +59,20 @@ QVector<int> NotesModel::ids() const {
} }
int NotesModel::insertNote(const Note &note) { int NotesModel::insertNote(const Note &note) {
//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)) {
//qDebug() << "-- Note already present but unchanged."; qDebug() << "Note already present unchanged.";
} }
else { else {
//qDebug() << "-- Note already present, updating it."; qDebug() << "Note already present, updating it.";
m_notes.replace(position, note); m_notes.replace(position, note);
emit dataChanged(index(position), index(position)); emit dataChanged(index(position), index(position));
} }
} }
else { else {
//if (note.id() < 0) qDebug() << "New note, adding it";
// qDebug() << "-- Local only note!";
//qDebug() << "-- New note, adding it";
position = m_notes.size(); position = m_notes.size();
beginInsertRows(QModelIndex(), position, position); beginInsertRows(QModelIndex(), position, position);
m_notes.append(note); m_notes.append(note);
@ -85,7 +83,7 @@ int NotesModel::insertNote(const Note &note) {
} }
bool NotesModel::removeNote(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); 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,12 +96,12 @@ bool NotesModel::removeNote(const Note &note) {
} }
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";
beginResetModel(); beginResetModel();
m_notes.clear(); m_notes.clear();
endResetModel(); endResetModel();

View file

@ -9,11 +9,12 @@
class NotesProxyModel : public QSortFilterProxyModel { class NotesProxyModel : public QSortFilterProxyModel {
Q_OBJECT Q_OBJECT
Q_PROPERTY(bool favoritesOnTop READ favoritesOnTop WRITE setFavoritesOnTop NOTIFY favoritesOnTopChanged)
public: public:
explicit NotesProxyModel(QObject *parent = 0); explicit NotesProxyModel(QObject *parent = 0);
virtual ~NotesProxyModel(); virtual ~NotesProxyModel();
Q_PROPERTY(bool favoritesOnTop READ favoritesOnTop WRITE setFavoritesOnTop NOTIFY favoritesOnTopChanged)
bool favoritesOnTop() const { return m_favoritesOnTop; } bool favoritesOnTop() const { return m_favoritesOnTop; }
void setFavoritesOnTop(bool favoritesOnTop); void setFavoritesOnTop(bool favoritesOnTop);
@ -34,6 +35,9 @@ private:
class NotesModel : public QAbstractListModel { class NotesModel : public QAbstractListModel {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QList<int> ids READ ids NOTIFY idsChanged)
public: public:
explicit NotesModel(QObject *parent = 0); explicit NotesModel(QObject *parent = 0);
virtual ~NotesModel(); virtual ~NotesModel();
@ -65,12 +69,11 @@ public slots:
bool removeNote(const Note &note); bool removeNote(const Note &note);
bool removeNote(int id); bool removeNote(int id);
Q_INVOKABLE void clear(); Q_INVOKABLE void clear();
Q_INVOKABLE QList<int> ids() const;
protected:
QVector<int> ids() const;
signals: signals:
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int> ()); void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int> ());
void idsChanged(QList<int> ids);
private: private:
QVector<Note> m_notes; QVector<Note> m_notes;

View file

@ -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,7 +61,7 @@ void NotesStore::getNote(const int id, Note::NoteField exclude) {
} }
void NotesStore::createNote(const Note& note) { void NotesStore::createNote(const Note& note) {
//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!";
@ -71,10 +71,13 @@ void NotesStore::createNote(const Note& note) {
emit noteUpdated(note); emit noteUpdated(note);
} }
} }
else {
qDebug() << "Note already exists";
}
} }
void NotesStore::updateNote(const Note& note) { void NotesStore::updateNote(const Note& note) {
//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) && note > file) { if (!file.equal(note) && note > file) {
@ -86,7 +89,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);
} }

View file

@ -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="122"/> <location filename="../qml/harbour-nextcloudnotes.qml" line="125"/>
<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="123"/> <location filename="../qml/harbour-nextcloudnotes.qml" line="126"/>
<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="124"/> <location filename="../qml/harbour-nextcloudnotes.qml" line="127"/>
<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="131"/> <location filename="../qml/harbour-nextcloudnotes.qml" line="134"/>
<source>Error</source> <source>Error</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>