Skip to content

Commit

Permalink
only display changed network errors during validation of connection
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
  • Loading branch information
mgallien committed Mar 13, 2024
1 parent 7a9cafd commit ce97508
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/gui/accountstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ void AccountState::setState(State state)

if (_state == SignedOut) {
_connectionStatus = ConnectionValidator::Undefined;
_connectionErrors.clear();
} else if (oldState == SignedOut && _state == Disconnected) {
// If we stop being voluntarily signed-out, try to connect and
// auth right now!
Expand Down Expand Up @@ -297,8 +296,9 @@ void AccountState::checkConnectivity()
return;
}

auto *conValidator = new ConnectionValidator(AccountStatePtr(this));
auto *conValidator = new ConnectionValidator(AccountStatePtr(this), _connectionErrors);

Check warning on line 299 in src/gui/accountstate.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/accountstate.cpp:299:11 [cppcoreguidelines-init-variables]

variable 'conValidator' is not initialized
_connectionValidator = conValidator;
_connectionErrors.clear();
connect(conValidator, &ConnectionValidator::connectionResult,
this, &AccountState::slotConnectionValidatorResult);
if (isConnected()) {
Expand Down
5 changes: 3 additions & 2 deletions src/gui/connectionvalidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ Q_LOGGING_CATEGORY(lcConnectionValidator, "nextcloud.sync.connectionvalidator",
// This makes sure we get tried often enough without "ConnectionValidator already running"
static qint64 timeoutToUseMsec = qMax(1000, ConnectionValidator::DefaultCallingIntervalMsec - 5 * 1000);

ConnectionValidator::ConnectionValidator(AccountStatePtr accountState, QObject *parent)
ConnectionValidator::ConnectionValidator(AccountStatePtr accountState, const QStringList &previousErrors, QObject *parent)

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

View workflow job for this annotation

GitHub Actions / build

src/gui/connectionvalidator.cpp:40:1 [cppcoreguidelines-pro-type-member-init]

constructor does not initialize these fields: , , , _previousErrors, _errors, _accountState, _account

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

View workflow job for this annotation

GitHub Actions / build

src/gui/connectionvalidator.cpp:40:42 [bugprone-easily-swappable-parameters]

2 adjacent parameters of 'ConnectionValidator' of similar type are easily swapped by mistake
: QObject(parent)
, _previousErrors(previousErrors)
, _accountState(accountState)
, _account(accountState->account())
{
Expand Down Expand Up @@ -331,7 +332,7 @@ void ConnectionValidator::reportResult(Status status)
emit connectionResult(status, _errors);

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

Expand Down
5 changes: 4 additions & 1 deletion src/gui/connectionvalidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ class ConnectionValidator : public QObject
{
Q_OBJECT
public:
explicit ConnectionValidator(AccountStatePtr accountState, QObject *parent = nullptr);
explicit ConnectionValidator(AccountStatePtr accountState,
const QStringList &previousErrors,
QObject *parent = nullptr);

enum Status {
Undefined,
Expand Down Expand Up @@ -142,6 +144,7 @@ protected slots:
*/
bool setAndCheckServerVersion(const QString &version);

const QStringList _previousErrors;
QStringList _errors;
AccountStatePtr _accountState;
AccountPtr _account;
Expand Down

0 comments on commit ce97508

Please sign in to comment.