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})
# find qtutilities
find_package(qtutilities 5.0.0 REQUIRED)
find_package(qtutilities 5.8.0 REQUIRED)
use_qt_utilities()
# check whether qtutilities supports DBus notifications

View File

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

View File

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

View File

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