From 0521ff2c4dbce2ea64d6ff9963d5a1140b23a1e7 Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Sat, 2 Dec 2023 21:04:23 +0100 Subject: [PATCH] Move PasswordStatus out of Controller --- src/controller.h | 11 ----------- src/neochatconnection.cpp | 9 ++++----- src/neochatconnection.h | 11 +++++++++++ src/qml/AccountEditorPage.qml | 13 +++++++++++++ src/qml/AccountsPage.qml | 9 --------- 5 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/controller.h b/src/controller.h index 7afe0c614..f72438147 100644 --- a/src/controller.h +++ b/src/controller.h @@ -65,16 +65,6 @@ class Controller : public QObject Q_PROPERTY(QStringList accountsLoading MEMBER m_accountsLoading NOTIFY accountsLoadingChanged) public: - /** - * @brief Defines the status after an attempt to change the password on an account. - */ - enum PasswordStatus { - Success, /**< The password was successfully changed. */ - Wrong, /**< The current password entered was wrong. */ - Other, /**< An unknown problem occurred. */ - }; - Q_ENUM(PasswordStatus) - static Controller &instance(); static Controller *create(QQmlEngine *engine, QJSEngine *) { @@ -162,7 +152,6 @@ Q_SIGNALS: void quitOnLastWindowClosedChanged(); void unreadCountChanged(); void activeConnectionChanged(); - void passwordStatus(Controller::PasswordStatus status); void userConsentRequired(QUrl url); void accountsLoadingChanged(); diff --git a/src/neochatconnection.cpp b/src/neochatconnection.cpp index 905a1d9d3..7b47ebc5a 100644 --- a/src/neochatconnection.cpp +++ b/src/neochatconnection.cpp @@ -124,12 +124,11 @@ void NeoChatConnection::changePassword(const QString ¤tPassword, const QSt QJsonObject identifier = {{"type"_ls, "m.id.user"_ls}, {"user"_ls, user()->id()}}; authData["identifier"_ls] = identifier; NeochatChangePasswordJob *innerJob = callApi(newPassword, false, authData); - connect(innerJob, &BaseJob::success, this, []() { - Q_EMIT Controller::instance().passwordStatus(Controller::PasswordStatus::Success); + connect(innerJob, &BaseJob::success, this, [this]() { + Q_EMIT passwordStatus(PasswordStatus::Success); }); - connect(innerJob, &BaseJob::failure, this, [innerJob]() { - Q_EMIT Controller::instance().passwordStatus(innerJob->jsonData()["errcode"_ls] == "M_FORBIDDEN"_ls ? Controller::PasswordStatus::Wrong - : Controller::PasswordStatus::Other); + connect(innerJob, &BaseJob::failure, this, [innerJob, this]() { + Q_EMIT passwordStatus(innerJob->jsonData()["errcode"_ls] == "M_FORBIDDEN"_ls ? PasswordStatus::Wrong : PasswordStatus::Other); }); } }); diff --git a/src/neochatconnection.h b/src/neochatconnection.h index 6f82832e7..20c714f1f 100644 --- a/src/neochatconnection.h +++ b/src/neochatconnection.h @@ -33,6 +33,16 @@ class NeoChatConnection : public Quotient::Connection Q_PROPERTY(bool isOnline READ isOnline WRITE setIsOnline NOTIFY isOnlineChanged) public: + /** + * @brief Defines the status after an attempt to change the password on an account. + */ + enum PasswordStatus { + Success, /**< The password was successfully changed. */ + Wrong, /**< The current password entered was wrong. */ + Other, /**< An unknown problem occurred. */ + }; + Q_ENUM(PasswordStatus) + NeoChatConnection(QObject *parent = nullptr); NeoChatConnection(const QUrl &server, QObject *parent = nullptr); @@ -88,6 +98,7 @@ public: Q_SIGNALS: void labelChanged(); void isOnlineChanged(); + void passwordStatus(NeoChatConnection::PasswordStatus status); private: bool m_isOnline = true; diff --git a/src/qml/AccountEditorPage.qml b/src/qml/AccountEditorPage.qml index 634969308..a3056c457 100644 --- a/src/qml/AccountEditorPage.qml +++ b/src/qml/AccountEditorPage.qml @@ -215,4 +215,17 @@ FormCard.FormCardPage { onClicked: pageStack.pushDialogLayer("qrc:/org/kde/neochat/qml/ConfirmDeactivateAccountDialog.qml", {connection: root.connection}, {title: i18nc("@title", "Confirm Deactivating Account")}) } } + + data: Connections { + target: root.connection + function onPasswordStatus(status) { + if (status === NeoChatConnection.Success) { + showPassiveNotification(i18n("Password changed successfully")); + } else if (status === NeoChatConnection.Wrong) { + showPassiveNotification(i18n("Wrong password entered")); + } else { + showPassiveNotification(i18n("Unknown problem while trying to change password")); + } + } + } } diff --git a/src/qml/AccountsPage.qml b/src/qml/AccountsPage.qml index 1e341a136..d070f5582 100644 --- a/src/qml/AccountsPage.qml +++ b/src/qml/AccountsPage.qml @@ -110,14 +110,5 @@ FormCard.FormCardPage { pageStack.layers.pop() } } - function onPasswordStatus(status) { - if (status === Controller.Success) { - showPassiveNotification(i18n("Password changed successfully")); - } else if (status === Controller.Wrong) { - showPassiveNotification(i18n("Wrong password entered")); - } else { - showPassiveNotification(i18n("Unknown problem while trying to change password")); - } - } } }