From d2dc15fdde3475f5a59c810ce4eb4dcdbd2df605 Mon Sep 17 00:00:00 2001 From: Martchus Date: Sat, 17 Feb 2024 18:07:46 +0100 Subject: [PATCH] Make it more clear when the options regarding metered connections are not available Since this feature will likely not be available in mingw-w64-based builds of the next release (due to missing cppwinrt) it is important to make it clear when those options don't actually work. With this change the checkboxes are completely disabled in case the feature is not available (instead of just providing the information via the tooltip). --- syncthingwidgets/settings/settingsdialog.cpp | 27 +++++++++----------- syncthingwidgets/settings/settingsdialog.h | 2 -- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/syncthingwidgets/settings/settingsdialog.cpp b/syncthingwidgets/settings/settingsdialog.cpp index 3da8ab2..88b5596 100644 --- a/syncthingwidgets/settings/settingsdialog.cpp +++ b/syncthingwidgets/settings/settingsdialog.cpp @@ -91,6 +91,13 @@ static QString meteredToolTip(std::optional isMetered) : QCoreApplication::translate("QtGui", "Unable to determine whether the network connection is metered; assuming an unmetered connection."); } +/// \brief Configures the specified \a checkBox for the specified \a isMetered value. +static void configureMeteredCheckbox(QCheckBox *checkBox, std::optional isMetered) +{ + checkBox->setEnabled(isMetered.has_value()); + checkBox->setToolTip(meteredToolTip(isMetered)); +} + // ConnectionOptionPage ConnectionOptionPage::ConnectionOptionPage(Data::SyncthingConnection *connection, QWidget *parentWidget) : ConnectionOptionPageBase(parentWidget) @@ -143,9 +150,9 @@ QWidget *ConnectionOptionPage::setupWidget() QObject::connect(ui()->removePushButton, &QPushButton::clicked, bind(&ConnectionOptionPage::removeSelectedConfig, this)); QObject::connect(ui()->advancedCheckBox, &QCheckBox::toggled, bind(&ConnectionOptionPage::toggleAdvancedSettings, this, std::placeholders::_1)); if (const auto *const launcher = SyncthingLauncher::mainInstance()) { - handleNetworkConnectionMeteredChanged(launcher->isNetworkConnectionMetered()); + configureMeteredCheckbox(ui()->pauseOnMeteredConnectionCheckBox, launcher->isNetworkConnectionMetered()); QObject::connect(launcher, &SyncthingLauncher::networkConnectionMeteredChanged, - bind(&ConnectionOptionPage::handleNetworkConnectionMeteredChanged, this, std::placeholders::_1)); + bind(&configureMeteredCheckbox, ui()->pauseOnMeteredConnectionCheckBox, std::placeholders::_1)); } #if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0)) ui()->timeoutSpinBox->setEnabled(false); @@ -397,11 +404,6 @@ void ConnectionOptionPage::toggleAdvancedSettings(bool show) #endif } -void ConnectionOptionPage::handleNetworkConnectionMeteredChanged(std::optional isMetered) -{ - ui()->pauseOnMeteredConnectionCheckBox->setToolTip(meteredToolTip(isMetered)); -} - bool ConnectionOptionPage::apply() { if (!cacheCurrentSettings(true)) { @@ -1164,9 +1166,9 @@ QWidget *LauncherOptionPage::setupWidget() connect(ui()->logLevelComboBox, static_cast(&QComboBox::currentIndexChanged), this, &LauncherOptionPage::updateLibSyncthingLogLevel); #endif - - handleNetworkConnectionMeteredChanged(m_launcher->isNetworkConnectionMetered()); - connect(m_launcher, &SyncthingLauncher::networkConnectionMeteredChanged, this, &LauncherOptionPage::handleNetworkConnectionMeteredChanged); + configureMeteredCheckbox(ui()->stopOnMeteredCheckBox, m_launcher->isNetworkConnectionMetered()); + connect(m_launcher, &SyncthingLauncher::networkConnectionMeteredChanged, this, + std::bind(&configureMeteredCheckbox, ui()->stopOnMeteredCheckBox, std::placeholders::_1)); m_launcher->setEmittingOutput(true); } @@ -1333,11 +1335,6 @@ void LauncherOptionPage::handleSyncthingError(QProcess::ProcessError error) } } -void LauncherOptionPage::handleNetworkConnectionMeteredChanged(std::optional isMetered) -{ - ui()->stopOnMeteredCheckBox->setToolTip(meteredToolTip(isMetered)); -} - bool LauncherOptionPage::isRunning() const { return (m_process && m_process->isRunning()) || (m_launcher && m_launcher->isRunning()); diff --git a/syncthingwidgets/settings/settingsdialog.h b/syncthingwidgets/settings/settingsdialog.h index d57b7c5..89a3196 100644 --- a/syncthingwidgets/settings/settingsdialog.h +++ b/syncthingwidgets/settings/settingsdialog.h @@ -69,7 +69,6 @@ void moveSelectedConfigDown(); void moveSelectedConfigUp(); void setCurrentIndex(int currentIndex); void toggleAdvancedSettings(bool show); -void handleNetworkConnectionMeteredChanged(std::optional isMetered); Data::SyncthingConnection *m_connection; Data::SyncthingConnectionSettings m_primarySettings; std::vector m_secondarySettings; @@ -138,7 +137,6 @@ private Q_SLOTS: void handleSyncthingOutputAvailable(const QByteArray &output); void handleSyncthingExited(int exitCode, QProcess::ExitStatus exitStatus); void handleSyncthingError(QProcess::ProcessError error); - void handleNetworkConnectionMeteredChanged(std::optional isMetered); void launch(); #ifdef SYNCTHINGWIDGETS_USE_LIBSYNCTHING void updateLibSyncthingLogLevel();