diff --git a/src/controller.cpp b/src/controller.cpp index 916b33c35..a591f098e 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -224,7 +224,7 @@ void Controller::invokeLogin() } }); connect(connection, &NeoChatConnection::networkError, this, [this](const QString &error, const QString &, int, int) { - Q_EMIT errorOccured(i18n("Network Error: %1", error), {}); + Q_EMIT errorOccured(i18n("Network Error: %1", error)); }); #if Quotient_VERSION_MINOR > 8 connection->assumeIdentity(account.userId(), account.deviceId(), accessToken); @@ -250,17 +250,17 @@ QKeychain::ReadPasswordJob *Controller::loadAccessTokenFromKeyChain(const QStrin switch (job->error()) { case QKeychain::EntryNotFound: - Q_EMIT errorOccured(i18n("Access token wasn't found"), i18n("Maybe it was deleted?")); + Q_EMIT errorOccured(i18n("Access token wasn't found: Maybe it was deleted?")); break; case QKeychain::AccessDeniedByUser: case QKeychain::AccessDenied: - Q_EMIT errorOccured(i18n("Access to keychain was denied."), i18n("Please allow NeoChat to read the access token")); + Q_EMIT errorOccured(i18n("Access to keychain was denied: Please allow NeoChat to read the access token")); break; case QKeychain::NoBackendAvailable: - Q_EMIT errorOccured(i18n("No keychain available."), i18n("Please install a keychain, e.g. KWallet or GNOME keyring on Linux")); + Q_EMIT errorOccured(i18n("No keychain available: Please install a keychain, e.g. KWallet or GNOME keyring on Linux")); break; case QKeychain::OtherError: - Q_EMIT errorOccured(i18n("Unable to read access token"), job->errorString()); + Q_EMIT errorOccured(i18n("Unable to read access token: %1", job->errorString())); break; default: break; @@ -325,11 +325,17 @@ void Controller::setActiveConnection(NeoChatConnection *connection) return; } + if (m_connection != nullptr) { + m_connection->disconnect(this); + } + m_connection = connection; if (m_connection != nullptr) { m_connection->refreshBadgeNotificationCount(); updateBadgeNotificationCount(m_connection, m_connection->badgeNotificationCount()); + + connect(m_connection, &NeoChatConnection::errorOccured, this, &Controller::errorOccured); } Q_EMIT activeConnectionChanged(m_connection); diff --git a/src/controller.h b/src/controller.h index e5e41afc8..78cfab15f 100644 --- a/src/controller.h +++ b/src/controller.h @@ -129,7 +129,10 @@ private Q_SLOTS: void updateBadgeNotificationCount(NeoChatConnection *connection, int count); Q_SIGNALS: - void errorOccured(const QString &error, const QString &detail); + /** + * @brief Request a error message be shown to the user. + */ + void errorOccured(const QString &error); void connectionAdded(NeoChatConnection *connection); void connectionDropped(NeoChatConnection *connection); void activeConnectionChanged(NeoChatConnection *connection); diff --git a/src/login.cpp b/src/login.cpp index afe7ee5fa..b5726b68f 100644 --- a/src/login.cpp +++ b/src/login.cpp @@ -85,7 +85,7 @@ void LoginHelper::init() m_connection = nullptr; }); connect(m_connection, &Connection::networkError, this, [this](QString error, const QString &, int, int) { - Q_EMIT Controller::instance().errorOccured(i18n("Network Error"), std::move(error)); + Q_EMIT m_connection->errorOccured(i18n("Network Error: %1", std::move(error))); m_isLoggingIn = false; Q_EMIT isLoggingInChanged(); }); @@ -93,14 +93,14 @@ void LoginHelper::init() if (error == QStringLiteral("Invalid username or password")) { setInvalidPassword(true); } else { - Q_EMIT errorOccured(i18n("Login Failed: %1", error)); + Q_EMIT loginErrorOccured(i18n("Login Failed: %1", error)); } m_isLoggingIn = false; Q_EMIT isLoggingInChanged(); }); - connect(m_connection, &Connection::resolveError, this, [](QString error) { - Q_EMIT Controller::instance().errorOccured(i18n("Network Error"), std::move(error)); + connect(m_connection, &Connection::resolveError, this, [this](QString error) { + Q_EMIT m_connection->errorOccured(i18n("Network Error: %1", std::move(error))); }); connect( diff --git a/src/login.h b/src/login.h index 917df9e5d..f374867a3 100644 --- a/src/login.h +++ b/src/login.h @@ -130,7 +130,7 @@ Q_SIGNALS: void loginFlowsChanged(); void ssoUrlChanged(); void connected(); - void errorOccured(const QString &message); + void loginErrorOccured(const QString &message); void testingChanged(); void isLoggingInChanged(); void isLoggedInChanged(); diff --git a/src/login/WelcomePage.qml b/src/login/WelcomePage.qml index ab3266b7f..161924e77 100644 --- a/src/login/WelcomePage.qml +++ b/src/login/WelcomePage.qml @@ -214,7 +214,7 @@ Kirigami.Page { Connections { target: LoginHelper - function onErrorOccured(message) { + function onLoginErrorOccured(message) { headerMessage.text = message; headerMessage.visible = message.length > 0; headerMessage.type = Kirigami.MessageType.Error; diff --git a/src/neochatconnection.cpp b/src/neochatconnection.cpp index 8b2cf9a83..8f9fceacd 100644 --- a/src/neochatconnection.cpp +++ b/src/neochatconnection.cpp @@ -6,7 +6,6 @@ #include #include -#include "controller.h" #include "jobs/neochatchangepasswordjob.h" #include "jobs/neochatdeactivateaccountjob.h" #include "neochatconfig.h" @@ -345,8 +344,8 @@ void NeoChatConnection::createRoom(const QString &name, const QString &topic, co } }); } - connect(job, &CreateRoomJob::failure, this, [job] { - Q_EMIT Controller::instance().errorOccured(i18n("Room creation failed: %1", job->errorString()), {}); + connect(job, &CreateRoomJob::failure, this, [this, job] { + Q_EMIT errorOccured(i18n("Room creation failed: %1", job->errorString())); }); connect( this, @@ -382,8 +381,8 @@ void NeoChatConnection::createSpace(const QString &name, const QString &topic, c } }); } - connect(job, &CreateRoomJob::failure, this, [job] { - Q_EMIT Controller::instance().errorOccured(i18n("Space creation failed: %1", job->errorString()), {}); + connect(job, &CreateRoomJob::failure, this, [this, job] { + Q_EMIT errorOccured(i18n("Space creation failed: %1", job->errorString())); }); connect( this, diff --git a/src/neochatconnection.h b/src/neochatconnection.h index d31d285d9..28306c4fb 100644 --- a/src/neochatconnection.h +++ b/src/neochatconnection.h @@ -212,6 +212,11 @@ Q_SIGNALS: void badgeNotificationCountChanged(NeoChatConnection *connection, int count); void canCheckMutualRoomsChanged(); + /** + * @brief Request a error message be shown to the user. + */ + void errorOccured(const QString &error); + private: bool m_isOnline = true; void setIsOnline(bool isOnline); diff --git a/src/qml/Main.qml b/src/qml/Main.qml index 6992d80ba..356fc27c1 100644 --- a/src/qml/Main.qml +++ b/src/qml/Main.qml @@ -247,8 +247,8 @@ Kirigami.ApplicationWindow { Connections { target: Controller - function onErrorOccured(error, detail) { - showPassiveNotification(detail.length > 0 ? i18n("%1: %2", error, detail) : error, "short"); + function onErrorOccured(error) { + showPassiveNotification(error, "short"); } }