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 18, 2024
1 parent d65d66a commit e6a9593
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 16 deletions.
5 changes: 2 additions & 3 deletions src/gui/accountsettings.cpp
Original file line number Diff line number Diff line change
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
15 changes: 10 additions & 5 deletions src/gui/accountstate.cpp
Original file line number Diff line number Diff line change
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 All @@ -149,6 +149,8 @@ AccountState::AccountState(AccountPtr account)
connect(NetworkInformation::instance(), &NetworkInformation::isBehindCaptivePortalChanged, this, [this](bool) {
// A direct connect is not possible, because then the state parameter of `isBehindCaptivePortalChanged`
// would become the `verifyServerState` argument to `checkConnectivity`.
// The call is also made for when we "go behind" a captive portal. That ensures that not
// only the statis is set to `Connecting`, but also makes the UI show that syncing is paused.
QTimer::singleShot(0, this, [this] { checkConnectivity(false); });
});

Expand Down Expand Up @@ -261,8 +263,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 +327,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion src/gui/networkinformation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ using namespace OCC;

Q_LOGGING_CATEGORY(lcNetInfo, "gui.netinfo", QtInfoMsg)

NetworkInformation *NetworkInformation::_instance;
NetworkInformation *NetworkInformation::_instance = nullptr;

static void loadQNetworkInformationBackend()
{
Expand Down

0 comments on commit e6a9593

Please sign in to comment.