From 8920af8e435bb5667479940c7ebf86e8fa04cd4b Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Mon, 15 Apr 2024 16:46:46 +0200 Subject: [PATCH] Remove `PausedDueToMetered` state and use `Connecting` state Like we do for when the client is behind a captive portal. --- src/gui/accountsettings.cpp | 5 ++--- src/gui/accountstate.cpp | 13 ++++++++----- src/gui/accountstate.h | 5 ----- src/gui/folderman.cpp | 5 ++++- src/gui/folderstatusmodel.cpp | 3 ++- src/gui/networkinformation.cpp | 2 +- 6 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index bb09e7eca34..20ba88bb197 100644 --- a/src/gui/accountsettings.cpp +++ b/src/gui/accountsettings.cpp @@ -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) { @@ -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)); } diff --git a/src/gui/accountstate.cpp b/src/gui/accountstate.cpp index acbd6d67e60..9bc7efc1200 100644 --- a/src/gui/accountstate.cpp +++ b/src/gui/accountstate.cpp @@ -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); } @@ -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; + } } } @@ -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) diff --git a/src/gui/accountstate.h b/src/gui/accountstate.h index 74b29a8725d..b330d0070ca 100644 --- a/src/gui/accountstate.h +++ b/src/gui/accountstate.h @@ -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) diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp index 54ef037f61a..a0e89562001 100644 --- a/src/gui/folderman.cpp +++ b/src/gui/folderman.cpp @@ -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" @@ -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; } diff --git a/src/gui/folderstatusmodel.cpp b/src/gui/folderstatusmodel.cpp index f05b6eabb1b..8e4a5ae2c5d 100644 --- a/src/gui/folderstatusmodel.cpp +++ b/src/gui/folderstatusmodel.cpp @@ -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" @@ -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); diff --git a/src/gui/networkinformation.cpp b/src/gui/networkinformation.cpp index af548338069..46290053655 100644 --- a/src/gui/networkinformation.cpp +++ b/src/gui/networkinformation.cpp @@ -20,7 +20,7 @@ using namespace OCC; Q_LOGGING_CATEGORY(lcNetInfo, "gui.netinfo", QtInfoMsg) -NetworkInformation *NetworkInformation::_instance; +NetworkInformation *NetworkInformation::_instance = nullptr; static void loadQNetworkInformationBackend() {