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,17 +35,13 @@ 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,26 +71,19 @@ 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<bool>("brightColors", ui()->brightTextColorsCheckBox->isChecked());
config.writeEntry<QSize>("size", QSize(ui()->widthSpinBox->value(), ui()->heightSpinBox->value()));
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)));
ui()->widthSpinBox->setValue(size.width());
const QSize size(config.readEntry<QSize>("size", QSize(25, 25))); ui()->heightSpinBox->setValue(size.height());
ui()->widthSpinBox->setValue(size.width()); ui()->brightTextColorsCheckBox->setChecked(config.readEntry<bool>("brightColors", false));
ui()->heightSpinBox->setValue(size.height());
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,9 +132,7 @@ 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,40 +352,36 @@ 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(); notifyOn.syncComplete = ui()->notifyOnSyncCompleteCheckBox->isChecked();
notifyOn.syncComplete = ui()->notifyOnSyncCompleteCheckBox->isChecked(); notifyOn.syncthingErrors = ui()->showSyncthingNotificationsCheckBox->isChecked();
notifyOn.syncthingErrors = ui()->showSyncthingNotificationsCheckBox->isChecked();
#ifdef QT_UTILITIES_SUPPORT_DBUS_NOTIFICATIONS #ifdef QT_UTILITIES_SUPPORT_DBUS_NOTIFICATIONS
if ((values().dbusNotifications = ui()->dbusRadioButton->isChecked()) && !DBusNotification::isAvailable()) { if ((values().dbusNotifications = ui()->dbusRadioButton->isChecked()) && !DBusNotification::isAvailable()) {
errors() << QCoreApplication::translate( errors() << QCoreApplication::translate(
"QtGui::NotificationsOptionPage", "Configured to use D-Bus notifications but D-Bus notification daemon seems unavailabe."); "QtGui::NotificationsOptionPage", "Configured to use D-Bus notifications but D-Bus notification daemon seems unavailabe.");
ok = false; ok = false;
}
#endif
values().ignoreInavailabilityAfterStart = static_cast<unsigned int>(ui()->ignoreInavailabilityAfterStartSpinBox->value());
} }
#endif
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); ui()->notifyOnSyncCompleteCheckBox->setChecked(notifyOn.syncComplete);
ui()->notifyOnSyncCompleteCheckBox->setChecked(notifyOn.syncComplete); ui()->showSyncthingNotificationsCheckBox->setChecked(notifyOn.syncthingErrors);
ui()->showSyncthingNotificationsCheckBox->setChecked(notifyOn.syncthingErrors);
#ifdef QT_UTILITIES_SUPPORT_DBUS_NOTIFICATIONS #ifdef QT_UTILITIES_SUPPORT_DBUS_NOTIFICATIONS
(values().dbusNotifications ? ui()->dbusRadioButton : ui()->qtRadioButton)->setChecked(true); (values().dbusNotifications ? ui()->dbusRadioButton : ui()->qtRadioButton)->setChecked(true);
#else #else
ui()->dbusRadioButton->setEnabled(false); ui()->dbusRadioButton->setEnabled(false);
ui()->qtRadioButton->setChecked(true); ui()->qtRadioButton->setChecked(true);
#endif #endif
ui()->ignoreInavailabilityAfterStartSpinBox->setValue(static_cast<int>(values().ignoreInavailabilityAfterStart)); ui()->ignoreInavailabilityAfterStartSpinBox->setValue(static_cast<int>(values().ignoreInavailabilityAfterStart));
}
} }
// AppearanceOptionPage // AppearanceOptionPage
@ -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 (!setAutostartEnabled(ui()->autostartCheckBox->isChecked())) {
if (hasBeenShown()) { errors() << QCoreApplication::translate("QtGui::AutostartOptionPage", "unable to modify startup entry");
if (!setAutostartEnabled(ui()->autostartCheckBox->isChecked())) { return false;
errors() << QCoreApplication::translate("QtGui::AutostartOptionPage", "unable to modify startup entry");
ok = false;
}
} }
return ok; return true;
} }
void AutostartOptionPage::reset() void AutostartOptionPage::reset()
@ -665,99 +641,97 @@ 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(); settings.syncthingPath = ui()->syncthingPathSelection->lineEdit()->text();
settings.syncthingPath = ui()->syncthingPathSelection->lineEdit()->text(); settings.syncthingArgs = ui()->argumentsLineEdit->text();
settings.syncthingArgs = ui()->argumentsLineEdit->text(); } else {
} else { ToolParameter &params = settings.tools[m_tool];
ToolParameter &params = settings.tools[m_tool]; params.autostart = ui()->enabledCheckBox->isChecked();
params.autostart = ui()->enabledCheckBox->isChecked(); 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); ui()->syncthingPathSelection->lineEdit()->setText(settings.syncthingPath);
ui()->syncthingPathSelection->lineEdit()->setText(settings.syncthingPath); ui()->argumentsLineEdit->setText(settings.syncthingArgs);
ui()->argumentsLineEdit->setText(settings.syncthingArgs); } else {
} else { const ToolParameter params = settings.tools.value(m_tool);
const ToolParameter params = settings.tools.value(m_tool); ui()->enabledCheckBox->setChecked(params.autostart);
ui()->enabledCheckBox->setChecked(params.autostart); ui()->syncthingPathSelection->lineEdit()->setText(params.path);
ui()->syncthingPathSelection->lineEdit()->setText(params.path); ui()->argumentsLineEdit->setText(params.args);
ui()->argumentsLineEdit->setText(params.args);
}
} }
} }
void LauncherOptionPage::handleSyncthingReadyRead() void LauncherOptionPage::handleSyncthingReadyRead()
{ {
if (hasBeenShown()) { if (!hasBeenShown()) {
QTextCursor cursor = ui()->logTextEdit->textCursor(); return;
cursor.movePosition(QTextCursor::End); }
cursor.insertText(QString::fromLocal8Bit(m_process.readAll())); QTextCursor cursor = ui()->logTextEdit->textCursor();
if (ui()->ensureCursorVisibleCheckBox->isChecked()) { cursor.movePosition(QTextCursor::End);
ui()->logTextEdit->ensureCursorVisible(); cursor.insertText(QString::fromLocal8Bit(m_process.readAll()));
} if (ui()->ensureCursorVisibleCheckBox->isChecked()) {
ui()->logTextEdit->ensureCursorVisible();
} }
} }
void LauncherOptionPage::handleSyncthingExited(int exitCode, QProcess::ExitStatus exitStatus) void LauncherOptionPage::handleSyncthingExited(int exitCode, QProcess::ExitStatus exitStatus)
{ {
if (hasBeenShown()) { if (!hasBeenShown()) {
QTextCursor cursor = ui()->logTextEdit->textCursor(); return;
cursor.movePosition(QTextCursor::End);
switch (exitStatus) {
case QProcess::NormalExit:
cursor.insertText(QCoreApplication::translate("QtGui::LauncherOptionPage", "%1 exited with exit code %2\n")
.arg(m_tool.isEmpty() ? QStringLiteral("Syncthing") : m_tool, QString::number(exitCode)));
break;
case QProcess::CrashExit:
cursor.insertText(QCoreApplication::translate("QtGui::LauncherOptionPage", "%1 crashed with exit code %2\n")
.arg(m_tool.isEmpty() ? QStringLiteral("Syncthing") : m_tool, QString::number(exitCode)));
break;
}
ui()->stopPushButton->hide();
ui()->launchNowPushButton->show();
} }
QTextCursor cursor = ui()->logTextEdit->textCursor();
cursor.movePosition(QTextCursor::End);
switch (exitStatus) {
case QProcess::NormalExit:
cursor.insertText(QCoreApplication::translate("QtGui::LauncherOptionPage", "%1 exited with exit code %2\n")
.arg(m_tool.isEmpty() ? QStringLiteral("Syncthing") : m_tool, QString::number(exitCode)));
break;
case QProcess::CrashExit:
cursor.insertText(QCoreApplication::translate("QtGui::LauncherOptionPage", "%1 crashed with exit code %2\n")
.arg(m_tool.isEmpty() ? QStringLiteral("Syncthing") : m_tool, QString::number(exitCode)));
break;
}
ui()->stopPushButton->hide();
ui()->launchNowPushButton->show();
} }
void LauncherOptionPage::launch() void LauncherOptionPage::launch()
{ {
if (hasBeenShown()) { if (!hasBeenShown()) {
apply(); return;
if (m_process.state() == QProcess::NotRunning) { }
ui()->launchNowPushButton->hide(); apply();
ui()->stopPushButton->show(); if (m_process.state() == QProcess::NotRunning) {
m_kill = false; ui()->launchNowPushButton->hide();
if (m_tool.isEmpty()) { ui()->stopPushButton->show();
m_process.startSyncthing(values().launcher.syncthingCmd()); m_kill = false;
} else { if (m_tool.isEmpty()) {
m_process.startSyncthing(values().launcher.toolCmd(m_tool)); m_process.startSyncthing(values().launcher.syncthingCmd());
} } else {
m_process.startSyncthing(values().launcher.toolCmd(m_tool));
} }
} }
} }
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) { }
m_process.kill(); if (m_kill) {
} else { m_process.kill();
m_kill = true; } else {
m_process.terminate(); m_kill = true;
} m_process.terminate();
}
} }
} }
@ -789,26 +763,22 @@ 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); ui()->considerForReconnectCheckBox->setChecked(settings.considerForReconnect);
ui()->considerForReconnectCheckBox->setChecked(settings.considerForReconnect); handleDescriptionChanged(m_service.description());
handleDescriptionChanged(m_service.description()); 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
} }