Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear error list after displaying it once. #6831

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/gui/accountstate.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check notice on line 1 in src/gui/accountstate.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on src/gui/accountstate.cpp

File src/gui/accountstate.cpp does not conform to Custom style guidelines. (lines 135)
* Copyright (C) by Daniel Molkentin <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -130,8 +130,9 @@
emit isConnectedChanged();
}
if (_state == Connected) {
_connectionErrors.clear();
resetRetryCount();
}
}
}

// might not have changed but the underlying _connectionErrors might have
Expand Down Expand Up @@ -487,6 +488,7 @@
// connection validation, even if it's currently running.
_connectionValidator->deleteLater();
_connectionValidator = nullptr;
_connectionErrors.clear();
}

checkConnectivity();
Expand Down
41 changes: 34 additions & 7 deletions src/gui/connectionvalidator.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check notice on line 1 in src/gui/connectionvalidator.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on src/gui/connectionvalidator.cpp

File src/gui/connectionvalidator.cpp does not conform to Custom style guidelines. (lines 293, 371, 372)
* Copyright (C) by Klaas Freitag <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
Expand All @@ -12,7 +12,7 @@
* for more details.
*/

#include <QJsonDocument>

Check failure on line 15 in src/gui/connectionvalidator.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/connectionvalidator.cpp:15:10 [clang-diagnostic-error]

'QJsonDocument' file not found
#include <QJsonObject>
#include <QJsonArray>
#include <QLoggingCategory>
Expand Down Expand Up @@ -48,6 +48,7 @@
void ConnectionValidator::checkServerAndAuth()
{
if (!_account) {
_statusErrorMap.insert(NotConfigured, tr("No Nextcloud account configured"));
_errors << tr("No Nextcloud account configured");
reportResult(NotConfigured);
return;
Expand Down Expand Up @@ -165,9 +166,10 @@

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);
Expand All @@ -176,7 +178,7 @@
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);
}
Expand Down Expand Up @@ -208,16 +210,19 @@
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 =
Expand Down Expand Up @@ -285,6 +290,7 @@
// 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);
Expand Down Expand Up @@ -331,18 +337,39 @@
{
emit connectionResult(status, _errors);

// notify user of errors
if (!_errors.isEmpty() && _previousErrors != _errors) {
showSystrayErrorMessage();
showSystrayErrorMessage(status);
}

deleteLater();
}

void ConnectionValidator::showSystrayErrorMessage()
void ConnectionValidator::showSystrayErrorMessage(Status status)

Check warning on line 347 in src/gui/connectionvalidator.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/connectionvalidator.cpp:347:27 [readability-convert-member-functions-to-static]

method 'showSystrayErrorMessage' can be made static
{
Systray::instance()->showMessage(tr("Connection issue"),
_errors.join("<br>"),
// 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);
}

Expand Down
3 changes: 2 additions & 1 deletion src/gui/connectionvalidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#ifndef CONNECTIONVALIDATOR_H
#define CONNECTIONVALIDATOR_H

#include "owncloudlib.h"

Check failure on line 18 in src/gui/connectionvalidator.h

View workflow job for this annotation

GitHub Actions / build

src/gui/connectionvalidator.h:18:10 [clang-diagnostic-error]

'owncloudlib.h' file not found
#include <QObject>
#include <QStringList>
#include <QVariantMap>
Expand Down Expand Up @@ -146,11 +146,12 @@

const QStringList _previousErrors;
QStringList _errors;
QMap<Status, QString> _statusErrorMap;
AccountStatePtr _accountState;
AccountPtr _account;
bool _isCheckingServerAndAuth = false;

void showSystrayErrorMessage();
void showSystrayErrorMessage(Status status);
};
}

Expand Down
Loading