From 044ac46945dc6e86a88cf2fc07867b5d6999b75a Mon Sep 17 00:00:00 2001 From: Camila Ayres Date: Mon, 24 Jun 2024 19:46:05 +0200 Subject: [PATCH 1/3] WIP: Clear error list after displaying it once. Fix for #6448 and #6487. Signed-off-by: Camila Ayres --- src/gui/connectionvalidator.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/gui/connectionvalidator.cpp b/src/gui/connectionvalidator.cpp index 6bdeca0f7c3a1..04838dd44b994 100644 --- a/src/gui/connectionvalidator.cpp +++ b/src/gui/connectionvalidator.cpp @@ -228,6 +228,8 @@ void ConnectionValidator::slotAuthFailed(QNetworkReply *reply) } } + _errors << tr("Test error"); + stat = SslError; reportResult(stat); } @@ -331,9 +333,10 @@ void ConnectionValidator::reportResult(Status status) { emit connectionResult(status, _errors); - // notify user of errors + // notify user of errors - TODO: only show the new ones if (!_errors.isEmpty() && _previousErrors != _errors) { - showSystrayErrorMessage(); + showSystrayErrorMessage(); + _errors.clear(); } deleteLater(); From b4767f2fdde054155bb0ea30122daa6fe37b892f Mon Sep 17 00:00:00 2001 From: Camila Ayres Date: Sun, 4 Aug 2024 20:08:06 +0200 Subject: [PATCH 2/3] Create map with connection status and error messages. Signed-off-by: Camila Ayres --- src/gui/connectionvalidator.cpp | 44 +++++++++++++++++++++++++-------- src/gui/connectionvalidator.h | 3 ++- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/gui/connectionvalidator.cpp b/src/gui/connectionvalidator.cpp index 04838dd44b994..e20b5035aef15 100644 --- a/src/gui/connectionvalidator.cpp +++ b/src/gui/connectionvalidator.cpp @@ -48,6 +48,7 @@ ConnectionValidator::ConnectionValidator(AccountStatePtr accountState, const QSt void ConnectionValidator::checkServerAndAuth() { if (!_account) { + _statusErrorMap.insert(NotConfigured, tr("No Nextcloud account configured")); _errors << tr("No Nextcloud account configured"); reportResult(NotConfigured); return; @@ -165,9 +166,10 @@ void ConnectionValidator::slotNoStatusFound(QNetworkReply *reply) if (!_account->credentials()->stillValid(reply)) { // Note: Why would this happen on a status.php request? + _statusErrorMap.insert(StatusNotFound, tr("Authentication error: Either username or password are wrong.")); _errors.append(tr("Authentication error: Either username or password are wrong.")); } else { - //_errors.append(tr("Unable to connect to %1").arg(_account->url().toString())); + _statusErrorMap.insert(StatusNotFound, job->errorString()); _errors.append(job->errorString()); } reportResult(StatusNotFound); @@ -176,7 +178,7 @@ void ConnectionValidator::slotNoStatusFound(QNetworkReply *reply) void ConnectionValidator::slotJobTimeout(const QUrl &url) { Q_UNUSED(url); - //_errors.append(tr("Unable to connect to %1").arg(url.toString())); + _statusErrorMap.insert(Timeout, tr("Timeout")); _errors.append(tr("Timeout")); reportResult(Timeout); } @@ -208,16 +210,19 @@ void ConnectionValidator::slotAuthFailed(QNetworkReply *reply) Status stat = Timeout; if (reply->error() == QNetworkReply::SslHandshakeFailedError) { + _statusErrorMap.insert(SslError, job->errorStringParsingBody()); _errors << job->errorStringParsingBody(); stat = SslError; } else if (reply->error() == QNetworkReply::AuthenticationRequiredError || !_account->credentials()->stillValid(reply)) { qCWarning(lcConnectionValidator) << "******** Password is wrong!" << reply->error() << job->errorString(); + _statusErrorMap.insert(CredentialsWrong, tr("The provided credentials are not correct")); _errors << tr("The provided credentials are not correct"); stat = CredentialsWrong; } else if (reply->error() != QNetworkReply::NoError) { + _statusErrorMap.insert(Undefined, job->errorStringParsingBody()); _errors << job->errorStringParsingBody(); const int httpStatus = @@ -228,8 +233,6 @@ void ConnectionValidator::slotAuthFailed(QNetworkReply *reply) } } - _errors << tr("Test error"); - stat = SslError; reportResult(stat); } @@ -287,6 +290,7 @@ bool ConnectionValidator::setAndCheckServerVersion(const QString &version) // We cannot deal with servers < 7.0.0 if (_account->serverVersionInt() && _account->serverVersionInt() < Account::makeServerVersion(7, 0, 0)) { + _statusErrorMap.insert(ServerVersionMismatch, tr("The configured server for this client is too old. Please update to the latest server and restart the client.")); _errors.append(tr("The configured server for this client is too old")); _errors.append(tr("Please update to the latest server and restart the client.")); reportResult(ServerVersionMismatch); @@ -333,19 +337,39 @@ void ConnectionValidator::reportResult(Status status) { emit connectionResult(status, _errors); - // notify user of errors - TODO: only show the new ones if (!_errors.isEmpty() && _previousErrors != _errors) { - showSystrayErrorMessage(); - _errors.clear(); + showSystrayErrorMessage(status); } deleteLater(); } -void ConnectionValidator::showSystrayErrorMessage() +void ConnectionValidator::showSystrayErrorMessage(Status status) { - Systray::instance()->showMessage(tr("Connection issue"), - _errors.join("
"), + // not all Status are considered errors + constexpr auto statusString = [&](Status currentStatus) { + switch (currentStatus) { + case Status::Undefined: + return tr("Undefined issue"); + case Status::NotConfigured: + return tr("Account not configured"); + case Status::ServerVersionMismatch: + return tr("Server version mismatch"); + case Status::CredentialsWrong: + return tr("Credentials issue"); + case Status::StatusNotFound: + case Status::Timeout: + return tr("Connection issue"); + case Status::ServiceUnavailable: + return tr("Service unavailable"); + case Status::MaintenanceMode: + return tr("Mantainance mode"); + default: + return QString(); + } + }; + Systray::instance()->showMessage(statusString(status), + _statusErrorMap.value(status), QSystemTrayIcon::Warning); } diff --git a/src/gui/connectionvalidator.h b/src/gui/connectionvalidator.h index 4b7193b0c8004..9df087fc91d93 100644 --- a/src/gui/connectionvalidator.h +++ b/src/gui/connectionvalidator.h @@ -146,11 +146,12 @@ protected slots: const QStringList _previousErrors; QStringList _errors; + QMap _statusErrorMap; AccountStatePtr _accountState; AccountPtr _account; bool _isCheckingServerAndAuth = false; - void showSystrayErrorMessage(); + void showSystrayErrorMessage(Status status); }; } From e57556138b75a1e579ea0a79db6cd89ef9286632 Mon Sep 17 00:00:00 2001 From: Camila Ayres Date: Sun, 4 Aug 2024 20:38:11 +0200 Subject: [PATCH 3/3] Clean list of connection errors when account state changes. Signed-off-by: Camila Ayres --- src/gui/accountstate.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gui/accountstate.cpp b/src/gui/accountstate.cpp index d1a0957791936..88604350debc5 100644 --- a/src/gui/accountstate.cpp +++ b/src/gui/accountstate.cpp @@ -130,8 +130,9 @@ void AccountState::setState(State state) emit isConnectedChanged(); } if (_state == Connected) { + _connectionErrors.clear(); resetRetryCount(); - } + } } // might not have changed but the underlying _connectionErrors might have @@ -487,6 +488,7 @@ void AccountState::slotCredentialsAsked(AbstractCredentials *credentials) // connection validation, even if it's currently running. _connectionValidator->deleteLater(); _connectionValidator = nullptr; + _connectionErrors.clear(); } checkConnectivity();