From 9240cc12dfd298d200feb9cafdae170d6d739d5e Mon Sep 17 00:00:00 2001 From: walker0643 <> Date: Tue, 30 Jan 2018 17:32:00 -0500 Subject: [PATCH] implemented minize to tray --- src/gui/src/AppConfig.cpp | 9 ++++++- src/gui/src/AppConfig.h | 4 +++ src/gui/src/MainWindow.cpp | 47 ++++++++++------------------------ src/gui/src/MainWindow.h | 4 ++- src/gui/src/SettingsDialog.cpp | 7 ++--- 5 files changed, 33 insertions(+), 38 deletions(-) diff --git a/src/gui/src/AppConfig.cpp b/src/gui/src/AppConfig.cpp index 23374fe7..ef191376 100644 --- a/src/gui/src/AppConfig.cpp +++ b/src/gui/src/AppConfig.cpp @@ -59,7 +59,8 @@ AppConfig::AppConfig(QSettings* settings) : m_ElevateMode(defaultElevateMode), m_AutoConfigPrompted(false), m_CryptoEnabled(false), - m_AutoHide(false) + m_AutoHide(false), + m_MinimizeToTray(false) { Q_ASSERT(m_pSettings); @@ -157,6 +158,7 @@ void AppConfig::loadSettings() m_AutoConfigPrompted = settings().value("autoConfigPrompted", false).toBool(); m_CryptoEnabled = settings().value("cryptoEnabled", true).toBool(); m_AutoHide = settings().value("autoHide", false).toBool(); + m_MinimizeToTray = settings().value("minimizeToTray", false).toBool(); } void AppConfig::saveSettings() @@ -178,6 +180,7 @@ void AppConfig::saveSettings() settings().setValue("autoConfigPrompted", m_AutoConfigPrompted); settings().setValue("cryptoEnabled", m_CryptoEnabled); settings().setValue("autoHide", m_AutoHide); + settings().setValue("minimizeToTray", m_MinimizeToTray); settings().sync(); } @@ -236,3 +239,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 fd4c298a..9faab2b1 100644 --- a/src/gui/src/AppConfig.h +++ b/src/gui/src/AppConfig.h @@ -95,6 +95,9 @@ class AppConfig: public QObject void setAutoHide(bool b); bool getAutoHide(); + void setMinimizeToTray(bool b); + bool getMinimizeToTray(); + void saveSettings(); protected: @@ -128,6 +131,7 @@ protected: bool m_AutoConfigPrompted; bool m_CryptoEnabled; bool m_AutoHide; + bool m_MinimizeToTray; static const char m_BarriersName[]; static const char m_BarriercName[]; diff --git a/src/gui/src/MainWindow.cpp b/src/gui/src/MainWindow.cpp index f57f5b3c..804332e5 100644 --- a/src/gui/src/MainWindow.cpp +++ b/src/gui/src/MainWindow.cpp @@ -190,28 +190,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_pActionStartBarrier, SLOT(trigger())); - connect(m_pButtonToggleStart, SIGNAL(clicked()), m_pActionStartBarrier, SLOT(trigger())); - - if (applyService) - { - stopDesktop(); - startBarrier(); - } - } - else if ((appConfig().processMode() == Desktop) && startDesktop) - { - stopService(); - startBarrier(); - } -} - void MainWindow::setStatus(const QString &status) { m_pStatusLabel->setText(status); @@ -958,10 +936,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::updateZeroconfService() @@ -1057,15 +1040,7 @@ void MainWindow::on_m_pActionAbout_triggered() void MainWindow::on_m_pActionSettings_triggered() { - ProcessMode lastProcessMode = appConfig().processMode(); - - SettingsDialog dlg(this, appConfig()); - dlg.exec(); - - if (lastProcessMode != appConfig().processMode()) - { - onModeChanged(true, true); - } + SettingsDialog(this, appConfig()).exec(); } void MainWindow::autoAddScreen(const QString name) @@ -1334,3 +1309,9 @@ QString MainWindow::getProfileRootForArg() return QString("\"%1\"").arg(dir); } + +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 ae4cb24c..74313796 100644 --- a/src/gui/src/MainWindow.h +++ b/src/gui/src/MainWindow.h @@ -157,7 +157,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(); @@ -181,6 +180,9 @@ public slots: void showEvent (QShowEvent*); + void windowStateChanged(); + + private: QSettings& m_Settings; AppConfig* m_AppConfig; diff --git a/src/gui/src/SettingsDialog.cpp b/src/gui/src/SettingsDialog.cpp index 5fe1b255..fa178176 100644 --- a/src/gui/src/SettingsDialog.cpp +++ b/src/gui/src/SettingsDialog.cpp @@ -51,6 +51,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_pComboElevate->setCurrentIndex(static_cast(appConfig().elevateMode())); @@ -59,8 +61,6 @@ SettingsDialog::SettingsDialog(QWidget* parent, AppConfig& config) : m_pLabelElevate->hide(); m_pComboElevate->hide(); #endif - - m_pCheckBoxEnableCrypto->setChecked(m_appConfig.getCryptoEnabled()); } void SettingsDialog::accept() @@ -72,8 +72,9 @@ 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().setMinimizeToTray(m_pCheckBoxMinimizeToTray->isChecked()); appConfig().saveSettings(); QDialog::accept(); }