Skip to content

Commit

Permalink
Remove PausedDueToMetered state and use Connecting state
Browse files Browse the repository at this point in the history
Like we do for when the client is behind a captive portal.
  • Loading branch information
erikjv committed Apr 16, 2024
1 parent aad8ec0 commit 412851f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
5 changes: 2 additions & 3 deletions src/gui/accountsettings.cpp
Expand Up @@ -466,9 +466,6 @@ void AccountSettings::slotAccountStateChanged()
.arg(Utility::escape(safeUrl.toString()));

switch (state) {
case AccountState::PausedDueToMetered:
showConnectionLabel(tr("Sync to %1 is paused due to metered internet connection.").arg(server));
break;
case AccountState::Connected: {
QStringList errors;
if (account->serverSupportLevel() != Account::ServerSupportLevel::Supported) {
Expand All @@ -493,6 +490,8 @@ void AccountSettings::slotAccountStateChanged()
case AccountState::Connecting:
if (NetworkInformation::instance()->isBehindCaptivePortal()) {
showConnectionLabel(tr("Captive portal prevents connections to %1.").arg(server));
} else if (NetworkInformation::instance()->isMetered()) {
showConnectionLabel(tr("Sync to %1 is paused due to metered internet connection.").arg(server));
} else {
showConnectionLabel(tr("Connecting to: %1.").arg(server));
}
Expand Down
13 changes: 8 additions & 5 deletions src/gui/accountstate.cpp
Expand Up @@ -138,8 +138,8 @@ AccountState::AccountState(AccountPtr account)
if (ConfigFile().pauseSyncWhenMetered()) {
if (state() == State::Connected && isMetered) {
qCInfo(lcAccountState) << "Network switched to a metered connection, setting account state to PausedDueToMetered";
setState(State::PausedDueToMetered);
} else if (state() == State::PausedDueToMetered && !isMetered) {
setState(State::Connecting);
} else if (state() == State::Connecting && !isMetered) {
qCInfo(lcAccountState) << "Network switched to a NON-metered connection, setting account state to Connected";
setState(State::Connected);
}
Expand Down Expand Up @@ -261,8 +261,11 @@ void AccountState::setState(State state)
_connectionValidator->deleteLater();
_connectionValidator.clear();
checkConnectivity();
} else if (_state == Connected && NetworkInformation::instance()->isMetered() && ConfigFile().pauseSyncWhenMetered()) {
_state = PausedDueToMetered;
} else if (_state == Connected) {
if ((NetworkInformation::instance()->isMetered() && ConfigFile().pauseSyncWhenMetered())
|| NetworkInformation::instance()->isBehindCaptivePortal()) {
_state = Connecting;
}
}
}

Expand Down Expand Up @@ -322,7 +325,7 @@ void AccountState::signIn()

bool AccountState::isConnected() const
{
return _state == Connected || _state == PausedDueToMetered;
return _state == Connected;
}

void AccountState::tagLastSuccessfullETagRequest(const QDateTime &tp)
Expand Down
5 changes: 0 additions & 5 deletions src/gui/accountstate.h
Expand Up @@ -77,11 +77,6 @@ class OWNCLOUDGUI_EXPORT AccountState : public QObject
/// We are currently asking the user for credentials
AskingCredentials,

/// We are on a metered internet connection, and the user preference
/// is to pause syncing in this case. This state is entered from and
/// left to a `Connected` state.
PausedDueToMetered,

Connecting
};
Q_ENUM(State)
Expand Down
5 changes: 4 additions & 1 deletion src/gui/folderman.cpp
Expand Up @@ -20,6 +20,7 @@
#include "common/asserts.h"
#include "configfile.h"
#include "folder.h"
#include "gui/networkinformation.h"
#include "guiutility.h"
#include "libsync/syncengine.h"
#include "lockwatcher.h"
Expand Down Expand Up @@ -73,7 +74,9 @@ void TrayOverallStatusResult::addResult(Folder *f)
lastSyncDone = time;
}

auto status = f->syncPaused() || f->accountState()->state() == AccountState::PausedDueToMetered ? SyncResult::Paused : f->syncResult().status();
auto status = f->syncPaused() || NetworkInformation::instance()->isBehindCaptivePortal() || NetworkInformation::instance()->isMetered()
? SyncResult::Paused
: f->syncResult().status();
if (status == SyncResult::Undefined) {
status = SyncResult::Problem;
}
Expand Down
3 changes: 2 additions & 1 deletion src/gui/folderstatusmodel.cpp
Expand Up @@ -17,6 +17,7 @@
#include "accountstate.h"
#include "common/asserts.h"
#include "folderman.h"
#include "gui/networkinformation.h"
#include "gui/quotainfo.h"
#include "theme.h"

Expand Down Expand Up @@ -50,7 +51,7 @@ namespace {
auto status = f->syncResult();
if (!f->accountState()->isConnected()) {
status.setStatus(SyncResult::Status::Offline);
} else if (f->syncPaused() || f->accountState()->state() == AccountState::PausedDueToMetered) {
} else if (f->syncPaused() || NetworkInformation::instance()->isBehindCaptivePortal() || NetworkInformation::instance()->isMetered()) {
status.setStatus(SyncResult::Status::Paused);
}
return Theme::instance()->syncStateIconName(status);
Expand Down

0 comments on commit 412851f

Please sign in to comment.