diff --git a/qml/harbour-nextcloudnotes.qml b/qml/harbour-nextcloudnotes.qml index 97d7129..e631f10 100644 --- a/qml/harbour-nextcloudnotes.qml +++ b/qml/harbour-nextcloudnotes.qml @@ -29,9 +29,13 @@ ApplicationWindow property bool allowUnecrypted: account.value("allowUnecrypted", false, Boolean) property date update: value("update", "", Date) onServerChanged: notesApi.server = server - onUsernameChanged: notesApi.username = username + onUsernameChanged: { + console.log("Username: " + username) + notesApi.username = username + } onPasswordChanged: notesApi.password = password onDoNotVerifySslChanged: notesApi.verifySsl = !doNotVerifySsl + onNameChanged: console.log("Using account: " + name) } // General settings of the app @@ -50,7 +54,6 @@ ApplicationWindow property bool useCapitalX: value("useCapitalX", false, Boolean) onCurrentAccountChanged: { - //console.log("currentAccountChanged") notesModel.sourceModel.clear() account.path = "/apps/harbour-nextcloudnotes/accounts/" + currentAccount notesStore.account = currentAccount @@ -154,22 +157,9 @@ ApplicationWindow } } - Connections { - target: notesStore - - onAccountChanged: { - //console.log(notesStore.account) - //notesStore.getAllNotes() - } - } - Connections { target: notesApi - onAccountChanged: { - //console.log(notesStore.account) - //notesApi.getAllNotes() - } onNetworkAccessibleChanged: { console.log("Device is " + (accessible ? "online" : "offline")) accessible ? offlineNotification.close(Notification.Closed) : offlineNotification.publish() diff --git a/qml/js/showdown b/qml/js/showdown index 8afa1ff..483e51f 160000 --- a/qml/js/showdown +++ b/qml/js/showdown @@ -1 +1 @@ -Subproject commit 8afa1fff0e1de2481e0545be17a906e2a68bb4e2 +Subproject commit 483e51f7a624c94c95787a14cbf577c053f8076f diff --git a/qml/pages/NotesPage.qml b/qml/pages/NotesPage.qml index 2efe3c9..28eb247 100644 --- a/qml/pages/NotesPage.qml +++ b/qml/pages/NotesPage.qml @@ -1,6 +1,5 @@ import QtQuick 2.2 import Sailfish.Silica 1.0 -//import harbour.nextcloudnotes.notesmodel 1.0 Page { id: page diff --git a/src/notesapi.cpp b/src/notesapi.cpp index be32440..490ee2c 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,7 +100,7 @@ void NotesApi::getNote(const int id, Note::NoteField exclude) { } void NotesApi::createNote(const Note ¬e) { - //qDebug() << "Creating note: " << note.id(); + qDebug() << "Creating note"; QUrl url = apiEndpointUrl(m_notesEndpoint); if (url.isValid() && !url.scheme().isEmpty() && !url.host().isEmpty()) { qDebug() << "POST" << url.toDisplayString(); @@ -111,9 +111,9 @@ void NotesApi::createNote(const Note ¬e) { } void NotesApi::updateNote(const Note ¬e) { - //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()) { + if (note.isValid() && url.isValid() && !url.scheme().isEmpty() && !url.host().isEmpty()) { qDebug() << "PUT" << url.toDisplayString(); m_authenticatedRequest.setUrl(url); m_notesReplies << m_manager.put(m_authenticatedRequest, noteApiData(note)); @@ -122,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 5b52139..5a60e43 100644 --- a/src/notesmodel.cpp +++ b/src/notesmodel.cpp @@ -15,7 +15,7 @@ NotesProxyModel::~NotesProxyModel() { } void NotesProxyModel::setFavoritesOnTop(bool favoritesOnTop) { - //qDebug() << "Favorites on top:" << favoritesOnTop; + qDebug() << "Favorites on top:" << favoritesOnTop; if (favoritesOnTop != m_favoritesOnTop) { m_favoritesOnTop = favoritesOnTop; emit favoritesOnTopChanged(m_favoritesOnTop); @@ -38,7 +38,7 @@ bool NotesProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex } void NotesProxyModel::sort() { - invalidate(); + //invalidate(); QSortFilterProxyModel::sort(0); } @@ -50,8 +50,8 @@ NotesModel::~NotesModel() { clear(); } -QVector NotesModel::ids() const { - QVector ids; +QList NotesModel::ids() const { + QList ids; for (int i = 0; i < m_notes.size(); ++i) { ids.append(m_notes[i].id()); } @@ -59,22 +59,20 @@ 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)) { - //qDebug() << "-- Note already present but unchanged."; + qDebug() << "Note already present unchanged."; } else { - //qDebug() << "-- Note already present, updating it."; + qDebug() << "Note already present, updating it."; m_notes.replace(position, note); emit dataChanged(index(position), index(position)); } } else { - //if (note.id() < 0) - // qDebug() << "-- Local only note!"; - //qDebug() << "-- New note, adding it"; + qDebug() << "New note, adding it"; position = m_notes.size(); beginInsertRows(QModelIndex(), position, position); m_notes.append(note); @@ -85,7 +83,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,12 +96,12 @@ 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"; + qDebug() << "Clearing model"; beginResetModel(); m_notes.clear(); endResetModel(); diff --git a/src/notesmodel.h b/src/notesmodel.h index 27d0517..1744353 100644 --- a/src/notesmodel.h +++ b/src/notesmodel.h @@ -9,11 +9,12 @@ class NotesProxyModel : public QSortFilterProxyModel { Q_OBJECT + Q_PROPERTY(bool favoritesOnTop READ favoritesOnTop WRITE setFavoritesOnTop NOTIFY favoritesOnTopChanged) + public: explicit NotesProxyModel(QObject *parent = 0); virtual ~NotesProxyModel(); - Q_PROPERTY(bool favoritesOnTop READ favoritesOnTop WRITE setFavoritesOnTop NOTIFY favoritesOnTopChanged) bool favoritesOnTop() const { return m_favoritesOnTop; } void setFavoritesOnTop(bool favoritesOnTop); @@ -34,6 +35,9 @@ private: class NotesModel : public QAbstractListModel { Q_OBJECT + + Q_PROPERTY(QList ids READ ids NOTIFY idsChanged) + public: explicit NotesModel(QObject *parent = 0); virtual ~NotesModel(); @@ -65,12 +69,11 @@ public slots: bool removeNote(const Note ¬e); bool removeNote(int id); Q_INVOKABLE void clear(); - -protected: - QVector ids() const; + Q_INVOKABLE QList ids() const; signals: void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles = QVector ()); + void idsChanged(QList ids); private: QVector m_notes; diff --git a/src/notesstore.cpp b/src/notesstore.cpp index 3210ec3..4abdfc2 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,7 +61,7 @@ void NotesStore::getNote(const int id, Note::NoteField exclude) { } void NotesStore::createNote(const Note& note) { - //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!"; @@ -71,10 +71,13 @@ void NotesStore::createNote(const Note& note) { emit noteUpdated(note); } } + else { + qDebug() << "Note already exists"; + } } void NotesStore::updateNote(const Note& note) { - //qDebug() << "Updating note: " << note.id(); + qDebug() << "Updating note: " << note.id(); if (note.isValid()) { Note file = readNoteFile(note.id()); if (!file.equal(note) && note > file) { @@ -86,7 +89,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 67f5500..e2dc511 100644 --- a/translations/harbour-nextcloudnotes.ts +++ b/translations/harbour-nextcloudnotes.ts @@ -840,22 +840,22 @@ You can also use other markdown syntax inside them. harbour-nextcloudnotes - + Notes - + Offline - + Synced - + Error