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

Pause sync when behind a captive portal #11551

Closed
wants to merge 1 commit into from
Closed
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
9 changes: 9 additions & 0 deletions src/gui/guiutility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ bool Utility::internetConnectionIsMetered()
return false;
}

bool OCC::Utility::internetThroughCaptivePortal()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering whether the null pointer check justifies the overhead of moving the code to utils.
In the end it hides the use of QNetworkInformation and can make reading the code in the future more complicated (also the utils class is already quire crowded)
This was also done for internetConnectionIsMetered.

{
if (auto *qNetInfo = QNetworkInformation::instance()) {
return qNetInfo->isBehindCaptivePortal();
}

return false;
}

void Utility::markDirectoryAsSyncRoot(const QString &path)
{
Q_ASSERT(getDirectorySyncRootMarking(path).isEmpty());
Expand Down
1 change: 1 addition & 0 deletions src/gui/guiutility.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ namespace Utility {
QString socketApiSocketPath();

bool internetConnectionIsMetered();
bool internetThroughCaptivePortal();

void markDirectoryAsSyncRoot(const QString &path);
QString getDirectorySyncRootMarking(const QString &path);
Expand Down
20 changes: 20 additions & 0 deletions src/gui/networksettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ NetworkSettings::NetworkSettings(QWidget *parent)
checkAccountLocalhost();

connect(_ui->pauseSyncWhenMeteredCheckbox, &QAbstractButton::clicked, this, &NetworkSettings::saveMeteredSettings);
connect(_ui->pauseSyncWhenBehindCaptivePortalCheckBox, &QAbstractButton::clicked, this, &NetworkSettings::saveCaptivePortalSettings);
}

NetworkSettings::~NetworkSettings()
Expand Down Expand Up @@ -195,6 +196,18 @@ void NetworkSettings::loadMeteredSettings()
_ui->pauseSyncWhenMeteredCheckbox->setVisible(false);
}

void NetworkSettings::loadCaptivePortalSettings()
{
if (QNetworkInformation *qNetInfo = QNetworkInformation::instance()) {
if (qNetInfo->supports(QNetworkInformation::Feature::CaptivePortal)) {
_ui->pauseSyncWhenBehindCaptivePortalCheckBox->setChecked(ConfigFile().pauseSyncWhenBehindCaptivePortal());
return;
}
}

_ui->pauseSyncWhenBehindCaptivePortalCheckBox->setVisible(false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to hide the tls dialog if enabled, I'd also say we need to pause, as util the captive portal is accepted there is no way to sync.

}

void NetworkSettings::saveProxySettings()
{
ConfigFile cfgFile;
Expand Down Expand Up @@ -256,6 +269,13 @@ void NetworkSettings::saveMeteredSettings()
FolderMan::instance()->scheduler()->setPauseSyncWhenMetered(pauseSyncWhenMetered);
}

void OCC::NetworkSettings::saveCaptivePortalSettings()
{
bool pauseWhenCaptivePortal = _ui->pauseSyncWhenBehindCaptivePortalCheckBox->isChecked();
ConfigFile().setPauseSyncWhenBehindCaptivePortal(pauseWhenCaptivePortal);
FolderMan::instance()->scheduler()->setPauseSyncWhenBehindCaptivePortal(pauseWhenCaptivePortal);
}

void NetworkSettings::checkEmptyProxyHost()
{
if (_ui->hostLineEdit->isEnabled() && _ui->hostLineEdit->text().isEmpty()) {
Expand Down
2 changes: 2 additions & 0 deletions src/gui/networksettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ private slots:
void saveProxySettings();
void saveBWLimitSettings();
void saveMeteredSettings();
void saveCaptivePortalSettings();

/// Red marking of host field if empty and enabled
void checkEmptyProxyHost();
Expand All @@ -55,6 +56,7 @@ private slots:
void loadProxySettings();
void loadBWLimitSettings();
void loadMeteredSettings();
void loadCaptivePortalSettings();
CredentialManager *_credentialManager;


Expand Down
7 changes: 7 additions & 0 deletions src/gui/networksettings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="pauseSyncWhenBehindCaptivePortalCheckBox">
<property name="text">
<string>Pause synchronization when behind a captive portal</string>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="proxyGroupBox">
<property name="enabled">
Expand Down
19 changes: 19 additions & 0 deletions src/gui/scheduling/syncscheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class FolderPriorityQueue
SyncScheduler::SyncScheduler(FolderMan *parent)
: QObject(parent)
, _pauseSyncWhenMetered(ConfigFile().pauseSyncWhenMetered())
, _pauseSyncWhenBehindCaptivePortal(ConfigFile().pauseSyncWhenBehindCaptivePortal())
, _queue(new FolderPriorityQueue)
{
new ETagWatcher(parent, this);
Expand Down Expand Up @@ -176,6 +177,16 @@ void SyncScheduler::startNext()
}
}

if (_pauseSyncWhenBehindCaptivePortal && Utility::internetThroughCaptivePortal()) {
if (syncPriority == Priority::High) {
qCInfo(lcSyncScheduler) << "Scheduler is paused due to a captive portal, BUT next sync is HIGH priority, so allow sync to start";
} else {
enqueueFolder(_currentSync, syncPriority);
qCInfo(lcSyncScheduler) << "Scheduler is paused due to a captive portal, next sync is not started";
return;
}
}

connect(
_currentSync, &Folder::syncFinished, this,
[this](const SyncResult &result) {
Expand Down Expand Up @@ -213,3 +224,11 @@ void SyncScheduler::setPauseSyncWhenMetered(bool pauseSyncWhenMetered)
startNext();
}
}

void OCC::SyncScheduler::setPauseSyncWhenBehindCaptivePortal(bool pauseSyncWhenBehindCaptivePortal)
{
_pauseSyncWhenBehindCaptivePortal = pauseSyncWhenBehindCaptivePortal;
if (!pauseSyncWhenBehindCaptivePortal) {
startNext();
}
}
3 changes: 2 additions & 1 deletion src/gui/scheduling/syncscheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ class SyncScheduler : public QObject
bool hasCurrentRunningSyncRunning() const;

void setPauseSyncWhenMetered(bool pauseSyncWhenMetered);

void setPauseSyncWhenBehindCaptivePortal(bool pauseSyncWhenBehindCaptivePortal);

private:
void startNext();

bool _running = false;
bool _pauseSyncWhenMetered;
bool _pauseSyncWhenBehindCaptivePortal;
QPointer<Folder> _currentSync;
FolderPriorityQueue *_queue;
};
Expand Down
16 changes: 16 additions & 0 deletions src/libsync/configfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ const QString pauseSyncWhenMeteredC()
{
return QStringLiteral("pauseWhenMetered");
}

const QString pauseSyncWhenBehindCaptivePortalC()
{
return QStringLiteral("pauseSyncWhenBehindCaptivePortal");
}

const QString moveToTrashC() { return QStringLiteral("moveToTrash"); }

const QString issuesWidgetFilterC()
Expand Down Expand Up @@ -708,6 +714,16 @@ void ConfigFile::setPauseSyncWhenMetered(bool isChecked)
setValue(pauseSyncWhenMeteredC(), isChecked);
}

bool ConfigFile::pauseSyncWhenBehindCaptivePortal() const
{
return getValue(pauseSyncWhenBehindCaptivePortalC(), {}, false).toBool();
}

void ConfigFile::setPauseSyncWhenBehindCaptivePortal(bool isChecked)
{
setValue(pauseSyncWhenBehindCaptivePortalC(), isChecked);
}

bool ConfigFile::moveToTrash() const
{
if (Theme::instance()->enableMoveToTrash()) {
Expand Down
3 changes: 3 additions & 0 deletions src/libsync/configfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ class OWNCLOUDSYNC_EXPORT ConfigFile
bool pauseSyncWhenMetered() const;
void setPauseSyncWhenMetered(bool isChecked);

bool pauseSyncWhenBehindCaptivePortal() const;
void setPauseSyncWhenBehindCaptivePortal(bool isChecked);

/** If we should move the files deleted on the server in the trash */
bool moveToTrash() const;
void setMoveToTrash(bool);
Expand Down
Loading