From 8211acbe51487e5f3b848228492388bfa651c025 Mon Sep 17 00:00:00 2001 From: Scharel Clemens Date: Fri, 1 May 2020 12:57:43 +0200 Subject: [PATCH] Changed on the QML side to adopt the previous changes on the C++ side --- qml/pages/LoginPage.qml | 49 ++++++++++++++-------- qml/pages/NotePage.qml | 14 +++++-- qml/pages/NotesPage.qml | 2 +- src/harbour-nextcloudnotes.cpp | 11 ----- src/notesapi.cpp | 4 +- src/notesmodel.cpp | 4 ++ src/notesmodel.h | 2 + translations/harbour-nextcloudnotes-de.ts | 4 ++ translations/harbour-nextcloudnotes-sv.ts | 4 ++ translations/harbour-nextcloudnotes.ts | 51 +++++++++++++---------- 10 files changed, 87 insertions(+), 58 deletions(-) diff --git a/qml/pages/LoginPage.qml b/qml/pages/LoginPage.qml index 36c7306..4a5c1df 100644 --- a/qml/pages/LoginPage.qml +++ b/qml/pages/LoginPage.qml @@ -39,12 +39,12 @@ Page { } } - onStatusChanged: { + /*onStatusChanged: { if (status === PageStatus.Activating) notesApi.getNcStatus() if (status === PageStatus.Deactivating) notesApi.abortFlowV2Login() - } + }*/ Connections { target: notesApi @@ -85,27 +85,27 @@ Page { } onLoginStatusChanged: { switch(notesApi.loginStatus) { - case NotesApi.LoginLegacyReady: + case notesApi.LoginLegacyReady: apiProgressBar.label = qsTr("Enter your credentials") break; - //case NotesApi.LoginFlowV2Initiating: + //case notesApi.LoginFlowV2Initiating: // break; - case NotesApi.LoginFlowV2Polling: + case notesApi.LoginFlowV2Polling: apiProgressBar.label = qsTr("Follow the instructions in the browser") break; - case NotesApi.LoginFlowV2Success: + case notesApi.LoginFlowV2Success: notesApi.verifyLogin() break; - case NotesApi.LoginFlowV2Failed: + case notesApi.LoginFlowV2Failed: apiProgressBar.label = qsTr("Login failed!") break - case NotesApi.LoginSuccess: + case notesApi.LoginSuccess: apiProgressBar.label = qsTr("Login successfull!") account.username = notesApi.username account.password = notesApi.password appSettings.currentAccount = accountId break; - case NotesApi.LoginFailed: + case notesApi.LoginFailed: apiProgressBar.label = qsTr("Login failed!") break; default: @@ -155,8 +155,8 @@ Page { id: apiProgressBar anchors.horizontalCenter: parent.horizontalCenter width: parent.width - indeterminate: notesApi.loginStatus === NotesApi.LoginFlowV2Initiating || - notesApi.loginStatus === NotesApi.LoginFlowV2Polling + indeterminate: notesApi.loginStatus === notesApi.LoginFlowV2Initiating || + notesApi.loginStatus === notesApi.LoginFlowV2Polling } Row { @@ -171,15 +171,17 @@ Page { onClicked: if (text === "") text = "https://" onTextChanged: { statusBusyIndicatorTimer.restart() - if (acceptableInput) + if (acceptableInput) { notesApi.server = text + notesApi.getNcStatus() + } } //EnterKey.enabled: text.length > 0 EnterKey.iconSource: legacyLoginPossible ? "image://theme/icon-m-enter-next" : flowLoginV2Possible ? "image://theme/icon-m-enter-accept" : "image://theme/icon-m-enter-close" EnterKey.onClicked: { if (legacyLoginPossible) usernameField.focus = true - else if (flowLoginV2Possible && notesApi.loginStatus !== NotesApi.LoginFlowV2Polling) + else if (flowLoginV2Possible && notesApi.loginStatus !== notesApi.LoginFlowV2Polling) notesApi.initiateFlowV2Login() focus = false } @@ -191,7 +193,7 @@ Page { BusyIndicator { anchors.centerIn: parent size: BusyIndicatorSize.Medium - running: notesApi.ncStatusStatus === NotesApi.NextcloudBusy || (serverField.focus && statusBusyIndicatorTimer.running && !notesApi.statusInstalled) + running: notesApi.ncStatusStatus === notesApi.NextcloudBusy || (serverField.focus && statusBusyIndicatorTimer.running && !notesApi.statusInstalled) Timer { id: statusBusyIndicatorTimer interval: 200 @@ -200,17 +202,28 @@ Page { } } + TextSwitch { + id: forceLegacyButton + text: qsTr("Enforce legacy login") + onCheckedChanged: { + checked != checked + if (!checked) { + notesApi.getNcStatus() + } + } + } + Column { id: flowv2LoginColumn width: parent.width spacing: Theme.paddingLarge visible: opacity !== 0.0 - opacity: flowLoginV2Possible ? 1.0 : 0.0 + opacity: flowLoginV2Possible && !forceLegacyButton.checked ? 1.0 : 0.0 Behavior on opacity { FadeAnimator {} } Button { anchors.horizontalCenter: parent.horizontalCenter - text: notesApi.loginStatus === NotesApi.LoginFlowV2Polling ? qsTr("Abort") : notesApi.loginStatus === NotesApi.LoginSuccess ? qsTr("Re-Login") : qsTr("Login") - onClicked: notesApi.loginStatus === NotesApi.LoginFlowV2Polling ? notesApi.abortFlowV2Login() : notesApi.initiateFlowV2Login() + text: notesApi.loginStatus === notesApi.LoginFlowV2Polling ? qsTr("Abort") : notesApi.loginStatus === notesApi.LoginSuccess ? qsTr("Re-Login") : qsTr("Login") + onClicked: notesApi.loginStatus === notesApi.LoginFlowV2Polling ? notesApi.abortFlowV2Login() : notesApi.initiateFlowV2Login() } } @@ -218,7 +231,7 @@ Page { id: legacyLoginColumn width: parent.width visible: opacity !== 0.0 - opacity: legacyLoginPossible ? 1.0 : 0.0 + opacity: legacyLoginPossible || forceLegacyButton.checked ? 1.0 : 0.0 Behavior on opacity { FadeAnimator {} } TextField { id: usernameField diff --git a/qml/pages/NotePage.qml b/qml/pages/NotePage.qml index 7f190fa..e4aaa36 100644 --- a/qml/pages/NotePage.qml +++ b/qml/pages/NotePage.qml @@ -5,9 +5,17 @@ import "../js/showdown/dist/showdown.js" as ShowDown Dialog { id: noteDialog - property int index - property var note: notesProxyModel.getNote(notesProxyModel.index(index, 0)) - + property int id + //property var note: notesProxyModel.getNote(notesProxyModel.index(index, 0)) + property var note: notesModel.getNoteById(id) + Connections { + target: notesModel + onNoteUpdated: { + if (id === noteDialog.id) { + noteDialog.note = note + } + } + } property var showdown: ShowDown.showdown property var converter: new showdown.Converter( diff --git a/qml/pages/NotesPage.qml b/qml/pages/NotesPage.qml index 68265d0..6c6425d 100644 --- a/qml/pages/NotesPage.qml +++ b/qml/pages/NotesPage.qml @@ -106,7 +106,7 @@ Page { id: remorse } - onClicked: pageStack.push(Qt.resolvedUrl("../pages/NotePage.qml"), { index: index } ) + onClicked: pageStack.push(Qt.resolvedUrl("../pages/NotePage.qml"), { id: id } ) onPressAndHold: menu.open(note) Separator { diff --git a/src/harbour-nextcloudnotes.cpp b/src/harbour-nextcloudnotes.cpp index 697441d..febc5fb 100644 --- a/src/harbour-nextcloudnotes.cpp +++ b/src/harbour-nextcloudnotes.cpp @@ -32,17 +32,6 @@ int main(int argc, char *argv[]) notesModel->setNotesApi(notesApi); notesModel->setNotesStore(notesStore); - //QObject::connect(notesApi, SIGNAL(allNotesReceived(QList)), notesModel, SLOT()); - //QObject::connect(notesApi, SIGNAL(noteCreated(int,QJsonObject)), notesModel, SLOT(insertNoteFromApi(int,QJsonObject))); - //QObject::connect(notesApi, SIGNAL(noteUpdated(int,QJsonObject)), notesModel, SLOT(updateNoteFromApi(int,QJsonObject))); - //QObject::connect(notesApi, SIGNAL(noteDeleted(int)), notesModel, SLOT(removeNoteFromApi(int))); - - //QObject::connect(notesApi, SIGNAL(noteUpdated(int,QJsonObject)), notesStore, SLOT(updateNote(int,QJsonObject))); - //QObject::connect(notesApi, SIGNAL(noteDeleted(int)), notesStore, SLOT(deleteNote(int))); - - //QObject::connect(notesStore, SIGNAL(noteUpdated(int,QJsonObject)), notesModel, SLOT(updateNoteFromStore(int,QJsonObject))); - //QObject::connect(notesStore, SIGNAL(noteDeleted(int)), notesModel, SLOT(removeNoteFromStore(int))); - QQuickView* view = SailfishApp::createView(); #ifdef QT_DEBUG view->rootContext()->setContextProperty("debug", QVariant(true)); diff --git a/src/notesapi.cpp b/src/notesapi.cpp index 92da406..67ca5ca 100644 --- a/src/notesapi.cpp +++ b/src/notesapi.cpp @@ -245,11 +245,11 @@ void NotesApi::setPath(QString path) { bool NotesApi::getNcStatus() { QUrl url = apiEndpointUrl(m_statusEndpoint); - qDebug() << "POST" << url.toDisplayString(); + qDebug() << "GET" << url.toDisplayString(); if (url.isValid() && !url.scheme().isEmpty() && !url.host().isEmpty()) { setNcStatusStatus(NextcloudStatus::NextcloudBusy); m_request.setUrl(url); - m_statusReplies << m_manager.post(m_request, QByteArray()); + m_statusReplies << m_manager.get(m_request); return true; } else { diff --git a/src/notesmodel.cpp b/src/notesmodel.cpp index 4ea33eb..c9cad9f 100644 --- a/src/notesmodel.cpp +++ b/src/notesmodel.cpp @@ -130,6 +130,10 @@ void NotesModel::setAccount(const QString &account) { mp_notesStore->setAccount(account); } +const QJsonObject NotesModel::getNoteById(const int id) const { + return m_notes[id]; +} + bool NotesModel::getAllNotes(const QStringList &exclude) { bool success = true; if (mp_notesApi) diff --git a/src/notesmodel.h b/src/notesmodel.h index c0b2045..3353e38 100644 --- a/src/notesmodel.h +++ b/src/notesmodel.h @@ -72,6 +72,8 @@ public: QString account() const; void setAccount(const QString& account); + const QJsonObject getNoteById(const int id) const; + public slots: Q_INVOKABLE bool getAllNotes(const QStringList& exclude = QStringList()); Q_INVOKABLE bool getNote(const int id, const QStringList& exclude = QStringList()); diff --git a/translations/harbour-nextcloudnotes-de.ts b/translations/harbour-nextcloudnotes-de.ts index 7a624c5..df3c953 100644 --- a/translations/harbour-nextcloudnotes-de.ts +++ b/translations/harbour-nextcloudnotes-de.ts @@ -190,6 +190,10 @@ Re-Login Neu einloggen + + Enforce legacy login + + MITLicense diff --git a/translations/harbour-nextcloudnotes-sv.ts b/translations/harbour-nextcloudnotes-sv.ts index 3dd7e85..146a7e2 100644 --- a/translations/harbour-nextcloudnotes-sv.ts +++ b/translations/harbour-nextcloudnotes-sv.ts @@ -190,6 +190,10 @@ Re-Login + + Enforce legacy login + + MITLicense diff --git a/translations/harbour-nextcloudnotes.ts b/translations/harbour-nextcloudnotes.ts index fa4abe7..e743e58 100644 --- a/translations/harbour-nextcloudnotes.ts +++ b/translations/harbour-nextcloudnotes.ts @@ -143,17 +143,17 @@ - + Username - + Password - + Abort @@ -179,52 +179,57 @@ - + + Enforce legacy login + + + + Login - + Re-Login - + Test Login - + Note - + The <a href="https://apps.nextcloud.com/apps/notes">Notes</a> app needs to be installed on the Nextcloud server for this app to work. - + Security - + <strong>CAUTION: Your password will be saved without any encryption on the device!</strong><br>Please consider creating a dedicated app password! Open your Nextcloud in a browser and go to <i>Settings</i> → <i>Security</i>. - + Do not check certificates - + Enable this option to allow selfsigned certificates - + Allow unencrypted connections @@ -258,52 +263,52 @@ NotePage - + Delete - + Reload - + Updating... - + Last update - + never - + Edit - + Notes - + No category - + Category - + Modified