Get rid of no longer necessary hasBeenShown() checks

This commit is contained in:
Martchus 2017-09-27 00:21:53 +02:00
parent 91c589ce14
commit 60a322cb4e
4 changed files with 120 additions and 165 deletions

View File

@ -39,7 +39,7 @@ find_package(c++utilities 4.10.0 REQUIRED)
list(APPEND CMAKE_MODULE_PATH ${CPP_UTILITIES_MODULE_DIRS}) list(APPEND CMAKE_MODULE_PATH ${CPP_UTILITIES_MODULE_DIRS})
# find qtutilities # find qtutilities
find_package(qtutilities 5.0.0 REQUIRED) find_package(qtutilities 5.8.0 REQUIRED)
use_qt_utilities() use_qt_utilities()
# check whether qtutilities supports DBus notifications # check whether qtutilities supports DBus notifications

View File

@ -35,18 +35,14 @@ ShortcutOptionPage::~ShortcutOptionPage()
bool ShortcutOptionPage::apply() bool ShortcutOptionPage::apply()
{ {
if (hasBeenShown()) {
m_applet->setGlobalShortcut(m_globalShortcutEdit->keySequence()); m_applet->setGlobalShortcut(m_globalShortcutEdit->keySequence());
}
return true; return true;
} }
void ShortcutOptionPage::reset() void ShortcutOptionPage::reset()
{ {
if (hasBeenShown()) {
m_globalShortcutEdit->setKeySequence(m_applet->globalShortcut()); m_globalShortcutEdit->setKeySequence(m_applet->globalShortcut());
} }
}
QWidget *ShortcutOptionPage::setupWidget() QWidget *ShortcutOptionPage::setupWidget()
{ {
@ -75,27 +71,20 @@ AppearanceOptionPage::~AppearanceOptionPage()
bool AppearanceOptionPage::apply() bool AppearanceOptionPage::apply()
{ {
if (hasBeenShown()) {
KConfigGroup config = m_applet->config(); KConfigGroup config = m_applet->config();
config.writeEntry<QSize>("size", QSize(ui()->widthSpinBox->value(), ui()->heightSpinBox->value())); config.writeEntry<QSize>("size", QSize(ui()->widthSpinBox->value(), ui()->heightSpinBox->value()));
config.writeEntry<bool>("brightColors", ui()->brightTextColorsCheckBox->isChecked()); config.writeEntry<bool>("brightColors", ui()->brightTextColorsCheckBox->isChecked());
}
return true; return true;
} }
void AppearanceOptionPage::reset() void AppearanceOptionPage::reset()
{ {
if (hasBeenShown()) {
const KConfigGroup config = m_applet->config(); const KConfigGroup config = m_applet->config();
const QSize size(config.readEntry<QSize>("size", QSize(25, 25))); const QSize size(config.readEntry<QSize>("size", QSize(25, 25)));
ui()->widthSpinBox->setValue(size.width()); ui()->widthSpinBox->setValue(size.width());
ui()->heightSpinBox->setValue(size.height()); ui()->heightSpinBox->setValue(size.height());
ui()->brightTextColorsCheckBox->setChecked(config.readEntry<bool>("brightColors", false)); ui()->brightTextColorsCheckBox->setChecked(config.readEntry<bool>("brightColors", false));
} }
}
QtGui::SettingsDialog *setupSettingsDialog(SyncthingApplet &applet) QtGui::SettingsDialog *setupSettingsDialog(SyncthingApplet &applet)
{ {

View File

@ -73,7 +73,7 @@ find_package(c++utilities 4.6.0 REQUIRED)
use_cpp_utilities() use_cpp_utilities()
# find qtutilities # find qtutilities
find_package(qtutilities 5.6.0 REQUIRED) find_package(qtutilities 5.8.0 REQUIRED)
use_qt_utilities() use_qt_utilities()
# find backend libraries # find backend libraries

View File

@ -94,9 +94,6 @@ QWidget *ConnectionOptionPage::setupWidget()
void ConnectionOptionPage::insertFromConfigFile() void ConnectionOptionPage::insertFromConfigFile()
{ {
if (!hasBeenShown()) {
return;
}
QString configFile = SyncthingConfig::locateConfigFile(); QString configFile = SyncthingConfig::locateConfigFile();
if (configFile.isEmpty()) { if (configFile.isEmpty()) {
// allow user to select config file manually if it could not be located // allow user to select config file manually if it could not be located
@ -135,10 +132,8 @@ void ConnectionOptionPage::insertFromConfigFile()
void ConnectionOptionPage::updateConnectionStatus() void ConnectionOptionPage::updateConnectionStatus()
{ {
if (hasBeenShown()) {
ui()->statusLabel->setText(m_connection->statusText()); ui()->statusLabel->setText(m_connection->statusText());
} }
}
bool ConnectionOptionPage::showConnectionSettings(int index) bool ConnectionOptionPage::showConnectionSettings(int index)
{ {
@ -297,9 +292,6 @@ void ConnectionOptionPage::setCurrentIndex(int currentIndex)
bool ConnectionOptionPage::apply() bool ConnectionOptionPage::apply()
{ {
if (!hasBeenShown()) {
return true;
}
if (!cacheCurrentSettings(true)) { if (!cacheCurrentSettings(true)) {
return false; return false;
} }
@ -310,9 +302,6 @@ bool ConnectionOptionPage::apply()
void ConnectionOptionPage::reset() void ConnectionOptionPage::reset()
{ {
if (!hasBeenShown()) {
return;
}
m_primarySettings = values().connection.primary; m_primarySettings = values().connection.primary;
m_secondarySettings = values().connection.secondary; m_secondarySettings = values().connection.secondary;
m_currentIndex = -1; m_currentIndex = -1;
@ -363,7 +352,6 @@ QWidget *NotificationsOptionPage::setupWidget()
bool NotificationsOptionPage::apply() bool NotificationsOptionPage::apply()
{ {
bool ok = true; bool ok = true;
if (hasBeenShown()) {
auto &notifyOn = values().notifyOn; auto &notifyOn = values().notifyOn;
notifyOn.disconnect = ui()->notifyOnDisconnectCheckBox->isChecked(); notifyOn.disconnect = ui()->notifyOnDisconnectCheckBox->isChecked();
notifyOn.internalErrors = ui()->notifyOnErrorsCheckBox->isChecked(); notifyOn.internalErrors = ui()->notifyOnErrorsCheckBox->isChecked();
@ -377,13 +365,11 @@ bool NotificationsOptionPage::apply()
} }
#endif #endif
values().ignoreInavailabilityAfterStart = static_cast<unsigned int>(ui()->ignoreInavailabilityAfterStartSpinBox->value()); values().ignoreInavailabilityAfterStart = static_cast<unsigned int>(ui()->ignoreInavailabilityAfterStartSpinBox->value());
}
return ok; return ok;
} }
void NotificationsOptionPage::reset() void NotificationsOptionPage::reset()
{ {
if (hasBeenShown()) {
const auto &notifyOn = values().notifyOn; const auto &notifyOn = values().notifyOn;
ui()->notifyOnDisconnectCheckBox->setChecked(notifyOn.disconnect); ui()->notifyOnDisconnectCheckBox->setChecked(notifyOn.disconnect);
ui()->notifyOnErrorsCheckBox->setChecked(notifyOn.internalErrors); ui()->notifyOnErrorsCheckBox->setChecked(notifyOn.internalErrors);
@ -397,7 +383,6 @@ void NotificationsOptionPage::reset()
#endif #endif
ui()->ignoreInavailabilityAfterStartSpinBox->setValue(static_cast<int>(values().ignoreInavailabilityAfterStart)); ui()->ignoreInavailabilityAfterStartSpinBox->setValue(static_cast<int>(values().ignoreInavailabilityAfterStart));
} }
}
// AppearanceOptionPage // AppearanceOptionPage
AppearanceOptionPage::AppearanceOptionPage(QWidget *parentWidget) AppearanceOptionPage::AppearanceOptionPage(QWidget *parentWidget)
@ -411,9 +396,6 @@ AppearanceOptionPage::~AppearanceOptionPage()
bool AppearanceOptionPage::apply() bool AppearanceOptionPage::apply()
{ {
if (!hasBeenShown()) {
return true;
}
auto &settings = values().appearance; auto &settings = values().appearance;
settings.trayMenuSize.setWidth(ui()->widthSpinBox->value()); settings.trayMenuSize.setWidth(ui()->widthSpinBox->value());
settings.trayMenuSize.setHeight(ui()->heightSpinBox->value()); settings.trayMenuSize.setHeight(ui()->heightSpinBox->value());
@ -451,9 +433,6 @@ bool AppearanceOptionPage::apply()
void AppearanceOptionPage::reset() void AppearanceOptionPage::reset()
{ {
if (!hasBeenShown()) {
return;
}
const auto &settings = values().appearance; const auto &settings = values().appearance;
ui()->widthSpinBox->setValue(settings.trayMenuSize.width()); ui()->widthSpinBox->setValue(settings.trayMenuSize.width());
ui()->heightSpinBox->setValue(settings.trayMenuSize.height()); ui()->heightSpinBox->setValue(settings.trayMenuSize.height());
@ -597,14 +576,11 @@ bool setAutostartEnabled(bool enabled)
bool AutostartOptionPage::apply() bool AutostartOptionPage::apply()
{ {
bool ok = true;
if (hasBeenShown()) {
if (!setAutostartEnabled(ui()->autostartCheckBox->isChecked())) { if (!setAutostartEnabled(ui()->autostartCheckBox->isChecked())) {
errors() << QCoreApplication::translate("QtGui::AutostartOptionPage", "unable to modify startup entry"); errors() << QCoreApplication::translate("QtGui::AutostartOptionPage", "unable to modify startup entry");
ok = false; return false;
} }
} return true;
return ok;
} }
void AutostartOptionPage::reset() void AutostartOptionPage::reset()
@ -665,7 +641,6 @@ QWidget *LauncherOptionPage::setupWidget()
bool LauncherOptionPage::apply() bool LauncherOptionPage::apply()
{ {
if (hasBeenShown()) {
auto &settings = values().launcher; auto &settings = values().launcher;
if (m_tool.isEmpty()) { if (m_tool.isEmpty()) {
settings.enabled = ui()->enabledCheckBox->isChecked(); settings.enabled = ui()->enabledCheckBox->isChecked();
@ -677,13 +652,11 @@ bool LauncherOptionPage::apply()
params.path = ui()->syncthingPathSelection->lineEdit()->text(); params.path = ui()->syncthingPathSelection->lineEdit()->text();
params.args = ui()->argumentsLineEdit->text(); params.args = ui()->argumentsLineEdit->text();
} }
}
return true; return true;
} }
void LauncherOptionPage::reset() void LauncherOptionPage::reset()
{ {
if (hasBeenShown()) {
const auto &settings = values().launcher; const auto &settings = values().launcher;
if (m_tool.isEmpty()) { if (m_tool.isEmpty()) {
ui()->enabledCheckBox->setChecked(settings.enabled); ui()->enabledCheckBox->setChecked(settings.enabled);
@ -696,11 +669,12 @@ void LauncherOptionPage::reset()
ui()->argumentsLineEdit->setText(params.args); ui()->argumentsLineEdit->setText(params.args);
} }
} }
}
void LauncherOptionPage::handleSyncthingReadyRead() void LauncherOptionPage::handleSyncthingReadyRead()
{ {
if (hasBeenShown()) { if (!hasBeenShown()) {
return;
}
QTextCursor cursor = ui()->logTextEdit->textCursor(); QTextCursor cursor = ui()->logTextEdit->textCursor();
cursor.movePosition(QTextCursor::End); cursor.movePosition(QTextCursor::End);
cursor.insertText(QString::fromLocal8Bit(m_process.readAll())); cursor.insertText(QString::fromLocal8Bit(m_process.readAll()));
@ -708,11 +682,12 @@ void LauncherOptionPage::handleSyncthingReadyRead()
ui()->logTextEdit->ensureCursorVisible(); ui()->logTextEdit->ensureCursorVisible();
} }
} }
}
void LauncherOptionPage::handleSyncthingExited(int exitCode, QProcess::ExitStatus exitStatus) void LauncherOptionPage::handleSyncthingExited(int exitCode, QProcess::ExitStatus exitStatus)
{ {
if (hasBeenShown()) { if (!hasBeenShown()) {
return;
}
QTextCursor cursor = ui()->logTextEdit->textCursor(); QTextCursor cursor = ui()->logTextEdit->textCursor();
cursor.movePosition(QTextCursor::End); cursor.movePosition(QTextCursor::End);
switch (exitStatus) { switch (exitStatus) {
@ -728,11 +703,12 @@ void LauncherOptionPage::handleSyncthingExited(int exitCode, QProcess::ExitStatu
ui()->stopPushButton->hide(); ui()->stopPushButton->hide();
ui()->launchNowPushButton->show(); ui()->launchNowPushButton->show();
} }
}
void LauncherOptionPage::launch() void LauncherOptionPage::launch()
{ {
if (hasBeenShown()) { if (!hasBeenShown()) {
return;
}
apply(); apply();
if (m_process.state() == QProcess::NotRunning) { if (m_process.state() == QProcess::NotRunning) {
ui()->launchNowPushButton->hide(); ui()->launchNowPushButton->hide();
@ -745,12 +721,12 @@ void LauncherOptionPage::launch()
} }
} }
} }
}
void LauncherOptionPage::stop() void LauncherOptionPage::stop()
{ {
if (hasBeenShown()) { if (!hasBeenShown() || m_process.state() == QProcess::NotRunning) {
if (m_process.state() != QProcess::NotRunning) { return;
}
if (m_kill) { if (m_kill) {
m_process.kill(); m_process.kill();
} else { } else {
@ -758,8 +734,6 @@ void LauncherOptionPage::stop()
m_process.terminate(); m_process.terminate();
} }
} }
}
}
// SystemdOptionPage // SystemdOptionPage
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD #ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
@ -789,18 +763,15 @@ QWidget *SystemdOptionPage::setupWidget()
bool SystemdOptionPage::apply() bool SystemdOptionPage::apply()
{ {
if (hasBeenShown()) {
auto &settings = values().systemd; auto &settings = values().systemd;
settings.syncthingUnit = ui()->syncthingUnitLineEdit->text(); settings.syncthingUnit = ui()->syncthingUnitLineEdit->text();
settings.showButton = ui()->showButtonCheckBox->isChecked(); settings.showButton = ui()->showButtonCheckBox->isChecked();
settings.considerForReconnect = ui()->considerForReconnectCheckBox->isChecked(); settings.considerForReconnect = ui()->considerForReconnectCheckBox->isChecked();
}
return true; return true;
} }
void SystemdOptionPage::reset() void SystemdOptionPage::reset()
{ {
if (hasBeenShown()) {
const auto &settings = values().systemd; const auto &settings = values().systemd;
ui()->syncthingUnitLineEdit->setText(settings.syncthingUnit); ui()->syncthingUnitLineEdit->setText(settings.syncthingUnit);
ui()->showButtonCheckBox->setChecked(settings.showButton); ui()->showButtonCheckBox->setChecked(settings.showButton);
@ -809,7 +780,6 @@ void SystemdOptionPage::reset()
handleStatusChanged(m_service.activeState(), m_service.subState(), m_service.activeSince()); handleStatusChanged(m_service.activeState(), m_service.subState(), m_service.activeSince());
handleEnabledChanged(m_service.unitFileState()); handleEnabledChanged(m_service.unitFileState());
} }
}
void SystemdOptionPage::handleDescriptionChanged(const QString &description) void SystemdOptionPage::handleDescriptionChanged(const QString &description)
{ {
@ -887,12 +857,10 @@ QWidget *WebViewOptionPage::setupWidget()
bool WebViewOptionPage::apply() bool WebViewOptionPage::apply()
{ {
#ifndef SYNCTHINGWIDGETS_NO_WEBVIEW #ifndef SYNCTHINGWIDGETS_NO_WEBVIEW
if (hasBeenShown()) {
auto &webView = values().webView; auto &webView = values().webView;
webView.disabled = ui()->disableCheckBox->isChecked(); webView.disabled = ui()->disableCheckBox->isChecked();
webView.zoomFactor = ui()->zoomDoubleSpinBox->value(); webView.zoomFactor = ui()->zoomDoubleSpinBox->value();
webView.keepRunning = ui()->keepRunningCheckBox->isChecked(); webView.keepRunning = ui()->keepRunningCheckBox->isChecked();
}
#endif #endif
return true; return true;
} }
@ -900,12 +868,10 @@ bool WebViewOptionPage::apply()
void WebViewOptionPage::reset() void WebViewOptionPage::reset()
{ {
#ifndef SYNCTHINGWIDGETS_NO_WEBVIEW #ifndef SYNCTHINGWIDGETS_NO_WEBVIEW
if (hasBeenShown()) {
const auto &webView = values().webView; const auto &webView = values().webView;
ui()->disableCheckBox->setChecked(webView.disabled); ui()->disableCheckBox->setChecked(webView.disabled);
ui()->zoomDoubleSpinBox->setValue(webView.zoomFactor); ui()->zoomDoubleSpinBox->setValue(webView.zoomFactor);
ui()->keepRunningCheckBox->setChecked(webView.keepRunning); ui()->keepRunningCheckBox->setChecked(webView.keepRunning);
}
#endif #endif
} }