diff --git a/src/gui/src/AppConfig.cpp b/src/gui/src/AppConfig.cpp index 2d6fd1b3..7613b3c6 100644 --- a/src/gui/src/AppConfig.cpp +++ b/src/gui/src/AppConfig.cpp @@ -57,7 +57,8 @@ AppConfig::AppConfig(QSettings* settings) : m_CryptoEnabled(false), m_AutoHide(false), m_LastExpiringWarningTime(0), - m_AutoConfigServer() + m_AutoConfigServer(), + m_MinimizeToTray(false) { Q_ASSERT(m_pSettings); @@ -165,6 +166,7 @@ void AppConfig::loadSettings() m_lastVersion = settings().value("lastVersion", "Unknown").toString(); m_LastExpiringWarningTime = settings().value("lastExpiringWarningTime", 0).toInt(); m_ActivationHasRun = settings().value("activationHasRun", false).toBool(); + m_MinimizeToTray = settings().value("minimizeToTray", false).toBool(); } void AppConfig::saveSettings() @@ -191,6 +193,7 @@ void AppConfig::saveSettings() settings().setValue("lastVersion", m_lastVersion); settings().setValue("lastExpiringWarningTime", m_LastExpiringWarningTime); settings().setValue("activationHasRun", m_ActivationHasRun); + settings().setValue("minimizeToTray", m_MinimizeToTray); settings().sync(); } @@ -298,3 +301,7 @@ bool AppConfig::getCryptoEnabled() const { void AppConfig::setAutoHide(bool b) { m_AutoHide = b; } bool AppConfig::getAutoHide() { return m_AutoHide; } + +void AppConfig::setMinimizeToTray(bool b) { m_MinimizeToTray = b; } + +bool AppConfig::getMinimizeToTray() { return m_MinimizeToTray; } diff --git a/src/gui/src/AppConfig.h b/src/gui/src/AppConfig.h index 654cc3dc..7e075e62 100644 --- a/src/gui/src/AppConfig.h +++ b/src/gui/src/AppConfig.h @@ -110,6 +110,9 @@ class AppConfig: public QObject QString lastVersion() const; + void setMinimizeToTray(bool b); + bool getMinimizeToTray(); + void saveSettings(); void setLastVersion(QString version); @@ -150,6 +153,7 @@ protected: QString m_lastVersion; int m_LastExpiringWarningTime; bool m_ActivationHasRun; + bool m_MinimizeToTray; static const char m_SynergysName[]; static const char m_SynergycName[]; diff --git a/src/gui/src/MainWindow.cpp b/src/gui/src/MainWindow.cpp index 951a2ff0..d8af942e 100644 --- a/src/gui/src/MainWindow.cpp +++ b/src/gui/src/MainWindow.cpp @@ -223,28 +223,6 @@ void MainWindow::open() } } -void MainWindow::onModeChanged(bool startDesktop, bool applyService) -{ - if (appConfig().processMode() == Service) - { - // ensure that the apply button actually does something, since desktop - // mode screws around with connecting/disconnecting the action. - disconnect(m_pButtonToggleStart, SIGNAL(clicked()), m_pActionStartSynergy, SLOT(trigger())); - connect(m_pButtonToggleStart, SIGNAL(clicked()), m_pActionStartSynergy, SLOT(trigger())); - - if (applyService) - { - stopDesktop(); - startSynergy(); - } - } - else if ((appConfig().processMode() == Desktop) && startDesktop) - { - stopService(); - startSynergy(); - } -} - void MainWindow::setStatus(const QString &status) { m_pStatusLabel->setText(status); @@ -1093,10 +1071,15 @@ void MainWindow::changeEvent(QEvent* event) break; } - default: - QMainWindow::changeEvent(event); + case QEvent::WindowStateChange: + { + windowStateChanged(); + break; + } } } + // all that do not return are allowing the event to propagate + QMainWindow::changeEvent(event); } void MainWindow::addZeroconfServer(const QString name) @@ -1291,21 +1274,7 @@ void MainWindow::updateAutoConfigWidgets() void MainWindow::on_m_pActionSettings_triggered() { - ProcessMode lastProcessMode = appConfig().processMode(); - bool lastAutoConfig = appConfig().autoConfig(); - - SettingsDialog dlg(this, appConfig()); - dlg.exec(); - - if (lastProcessMode != appConfig().processMode()) - { - onModeChanged(true, true); - } - - if (lastAutoConfig != appConfig().autoConfig()) { - updateAutoConfigWidgets(); - updateZeroconfService(); - } + SettingsDialog(this, appConfig()).exec(); } void MainWindow::autoAddScreen(const QString name) @@ -1439,3 +1408,9 @@ void MainWindow::on_m_pComboServerList_currentIndexChanged(const QString &server appConfig().setAutoConfigServer(server); appConfig().saveSettings(); } + +void MainWindow::windowStateChanged() +{ + if (windowState() == Qt::WindowMinimized && appConfig().getMinimizeToTray()) + hide(); +} diff --git a/src/gui/src/MainWindow.h b/src/gui/src/MainWindow.h index 812234cd..2817b192 100644 --- a/src/gui/src/MainWindow.h +++ b/src/gui/src/MainWindow.h @@ -176,7 +176,6 @@ public slots: bool serverArgs(QStringList& args, QString& app); void setStatus(const QString& status); void sendIpcMessage(qIpcMessageType type, const char* buffer, bool showErrors); - void onModeChanged(bool startDesktop, bool applyService); void updateFromLogLine(const QString& line); QString getIPAddresses(); void stopService(); @@ -203,6 +202,9 @@ public slots: void showEvent (QShowEvent*); void secureSocket(bool secureSocket); + void windowStateChanged(); + + private: #ifndef SYNERGY_ENTERPRISE LicenseManager* m_LicenseManager; diff --git a/src/gui/src/SettingsDialog.cpp b/src/gui/src/SettingsDialog.cpp index 50f3ab23..8c512a41 100644 --- a/src/gui/src/SettingsDialog.cpp +++ b/src/gui/src/SettingsDialog.cpp @@ -57,6 +57,8 @@ SettingsDialog::SettingsDialog(QWidget* parent, AppConfig& config) : m_pLineEditLogFilename->setText(appConfig().logFilename()); setIndexFromItemData(m_pComboLanguage, appConfig().language()); m_pCheckBoxAutoHide->setChecked(appConfig().getAutoHide()); + m_pCheckBoxMinimizeToTray->setChecked(appConfig().getMinimizeToTray()); + m_pCheckBoxEnableCrypto->setChecked(m_appConfig.getCryptoEnabled()); #if defined(Q_OS_WIN) m_pBonjourWindows = new BonjourWindows(this, m_pMainWindow, m_appConfig); @@ -66,7 +68,6 @@ SettingsDialog::SettingsDialog(QWidget* parent, AppConfig& config) : m_pComboElevate->setCurrentIndex(static_cast(appConfig().elevateMode())); - m_pCheckBoxAutoHide->hide(); #else // elevate checkbox is only useful on ms windows. m_pLabelElevate->hide(); @@ -106,9 +107,10 @@ void SettingsDialog::accept() appConfig().setLogToFile(m_pCheckBoxLogToFile->isChecked()); appConfig().setLogFilename(m_pLineEditLogFilename->text()); appConfig().setLanguage(m_pComboLanguage->itemData(m_pComboLanguage->currentIndex()).toString()); - appConfig().setElevateMode(static_cast(m_pComboElevate->currentIndex())); + appConfig().setElevateMode(static_cast(m_pComboElevate->currentIndex())); appConfig().setAutoHide(m_pCheckBoxAutoHide->isChecked()); appConfig().setAutoConfig(m_pCheckBoxAutoConfig->isChecked()); + appConfig().setMinimizeToTray(m_pCheckBoxMinimizeToTray->isChecked()); appConfig().saveSettings(); QDialog::accept(); } diff --git a/src/gui/src/SettingsDialogBase.ui b/src/gui/src/SettingsDialogBase.ui index b85417c2..10bcc589 100644 --- a/src/gui/src/SettingsDialogBase.ui +++ b/src/gui/src/SettingsDialogBase.ui @@ -114,13 +114,6 @@ - - - - &Hide on startup - - - @@ -153,6 +146,20 @@ + + + + &Hide on startup + + + + + + + Minimize to System &Tray + + + @@ -392,6 +399,7 @@ m_pLineEditScreenName m_pSpinBoxPort m_pLineEditInterface + m_pCheckBoxMinimizeToTray m_pComboElevate m_pCheckBoxAutoHide m_pComboLogLevel