diff --git a/src/misc/settings.cpp b/src/misc/settings.cpp index 2a95fa4fe..98109a964 100644 --- a/src/misc/settings.cpp +++ b/src/misc/settings.cpp @@ -112,6 +112,7 @@ void Settings::load() translation = s.value("translation", "").toString(); makeToxPortable = s.value("makeToxPortable", false).toBool(); autostartInTray = s.value("autostartInTray", false).toBool(); + closeToTray = s.value("closeToTray", false).toBool(); forceTCP = s.value("forceTCP", false).toBool(); useProxy = s.value("useProxy", false).toBool(); proxyAddr = s.value("proxyAddr", "").toString(); @@ -137,6 +138,7 @@ void Settings::load() secondColumnHandlePosFromRight = s.value("secondColumnHandlePosFromRight", 50).toInt(); timestampFormat = s.value("timestampFormat", "hh:mm").toString(); minimizeOnClose = s.value("minimizeOnClose", false).toBool(); + minimizeToTray = s.value("minimizeToTray", false).toBool(); useNativeStyle = s.value("nativeStyle", false).toBool(); style = s.value("style", "None").toString(); statusChangeNotificationEnabled = s.value("statusChangeNotificationEnabled", false).toBool(); @@ -226,6 +228,7 @@ void Settings::save(QString path) s.setValue("translation",translation); s.setValue("makeToxPortable",makeToxPortable); s.setValue("autostartInTray",autostartInTray); + s.setValue("closeToTray", closeToTray); s.setValue("useProxy", useProxy); s.setValue("forceTCP", forceTCP); s.setValue("proxyAddr", proxyAddr); @@ -251,6 +254,7 @@ void Settings::save(QString path) s.setValue("secondColumnHandlePosFromRight", secondColumnHandlePosFromRight); s.setValue("timestampFormat", timestampFormat); s.setValue("minimizeOnClose", minimizeOnClose); + s.setValue("minimizeToTray", minimizeToTray); s.setValue("nativeStyle", useNativeStyle); s.setValue("style",style); s.setValue("statusChangeNotificationEnabled", statusChangeNotificationEnabled); @@ -392,6 +396,27 @@ void Settings::setAutostartInTray(bool newValue) autostartInTray = newValue; } +bool Settings::getCloseToTray() const +{ + return closeToTray; +} + +void Settings::setCloseToTray(bool newValue) +{ + closeToTray = newValue; +} + +bool Settings::getMinimizeToTray() const +{ + return minimizeToTray; +} + + +void Settings::setMinimizeToTray(bool newValue) +{ + minimizeToTray = newValue; +} + bool Settings::getStatusChangeNotificationEnabled() const { return statusChangeNotificationEnabled; diff --git a/src/misc/settings.h b/src/misc/settings.h index 5b131fc99..5c3e6bc17 100644 --- a/src/misc/settings.h +++ b/src/misc/settings.h @@ -52,6 +52,12 @@ public: bool getAutostartInTray() const; void setAutostartInTray(bool newValue); + bool getCloseToTray() const; + void setCloseToTray(bool newValue); + + bool getMinimizeToTray() const; + void setMinimizeToTray(bool newValue); + QString getStyle() const; void setStyle(const QString& newValue); @@ -188,6 +194,8 @@ private: QString translation; static bool makeToxPortable; bool autostartInTray; + bool closeToTray; + bool minimizeToTray; bool forceTCP; diff --git a/src/widget/form/settings/generalform.cpp b/src/widget/form/settings/generalform.cpp index 78867b60e..e6b21b109 100644 --- a/src/widget/form/settings/generalform.cpp +++ b/src/widget/form/settings/generalform.cpp @@ -40,7 +40,9 @@ GeneralForm::GeneralForm(SettingsWidget *myParent) : bodyUI->transComboBox->setCurrentIndex(locales.indexOf(Settings::getInstance().getTranslation())); bodyUI->cbMakeToxPortable->setChecked(Settings::getInstance().getMakeToxPortable()); bodyUI->startInTray->setChecked(Settings::getInstance().getAutostartInTray()); - bodyUI->statusChangesCheckbox->setChecked(Settings::getInstance().getStatusChangeNotificationEnabled()); + bodyUI->closeToTray->setChecked(Settings::getInstance().getCloseToTray()); + bodyUI->minimizeToTray->setChecked(Settings::getInstance().getMinimizeToTray()); + bodyUI->statusChanges->setChecked(Settings::getInstance().getStatusChangeNotificationEnabled()); for (auto entry : SmileyPack::listSmileyPacks()) { @@ -72,7 +74,9 @@ GeneralForm::GeneralForm(SettingsWidget *myParent) : connect(bodyUI->transComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onTranslationUpdated())); connect(bodyUI->cbMakeToxPortable, &QCheckBox::stateChanged, this, &GeneralForm::onMakeToxPortableUpdated); connect(bodyUI->startInTray, &QCheckBox::stateChanged, this, &GeneralForm::onSetAutostartInTray); - connect(bodyUI->statusChangesCheckbox, &QCheckBox::stateChanged, this, &GeneralForm::onSetStatusChange); + connect(bodyUI->closeToTray, &QCheckBox::stateChanged, this, &GeneralForm::onSetCloseToTray); + connect(bodyUI->minimizeToTray, &QCheckBox::stateChanged, this, &GeneralForm::onSetMinimizeToTray); + connect(bodyUI->statusChanges, &QCheckBox::stateChanged, this, &GeneralForm::onSetStatusChange); connect(bodyUI->smileyPackBrowser, SIGNAL(currentIndexChanged(int)), this, SLOT(onSmileyBrowserIndexChanged(int))); // new syntax can't handle overloaded signals... (at least not in a pretty way) connect(bodyUI->cbUDPDisabled, &QCheckBox::stateChanged, this, &GeneralForm::onUDPUpdated); @@ -109,6 +113,16 @@ void GeneralForm::onSetAutostartInTray() Settings::getInstance().setAutostartInTray(bodyUI->startInTray->isChecked()); } +void GeneralForm::onSetCloseToTray() +{ + Settings::getInstance().setCloseToTray(bodyUI->closeToTray->isChecked()); +} + +void GeneralForm::onSetMinimizeToTray() +{ + Settings::getInstance().setMinimizeToTray(bodyUI->minimizeToTray->isChecked()); +} + void GeneralForm::onStyleSelected(QString style) { Settings::getInstance().setStyle(style); @@ -125,7 +139,7 @@ void GeneralForm::onAutoAwayChanged() void GeneralForm::onSetStatusChange() { - Settings::getInstance().setStatusChangeNotificationEnabled(bodyUI->statusChangesCheckbox->isChecked()); + Settings::getInstance().setStatusChangeNotificationEnabled(bodyUI->statusChanges->isChecked()); } void GeneralForm::onSmileyBrowserIndexChanged(int index) diff --git a/src/widget/form/settings/generalform.h b/src/widget/form/settings/generalform.h index bae1eb8d0..6397ccdfd 100644 --- a/src/widget/form/settings/generalform.h +++ b/src/widget/form/settings/generalform.h @@ -35,6 +35,7 @@ private slots: void onTranslationUpdated(); void onMakeToxPortableUpdated(); void onSetAutostartInTray(); + void onSetCloseToTray(); void onSmileyBrowserIndexChanged(int index); void onUDPUpdated(); void onProxyAddrEdited(); @@ -43,6 +44,7 @@ private slots: void onStyleSelected(QString style); void onSetStatusChange(); void onAutoAwayChanged(); + void onSetMinimizeToTray(); private: diff --git a/src/widget/form/settings/generalsettings.ui b/src/widget/form/settings/generalsettings.ui index 924bc057b..f2976eea5 100644 --- a/src/widget/form/settings/generalsettings.ui +++ b/src/widget/form/settings/generalsettings.ui @@ -7,7 +7,7 @@ 0 0 527 - 500 + 525 @@ -74,7 +74,21 @@ - + + + Close to tray + + + + + + + Minimize to tray + + + + + Show contacts' status changes diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 2abbbf1a4..4a4dddeb2 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -253,10 +253,30 @@ QThread* Widget::getCoreThread() void Widget::closeEvent(QCloseEvent *event) { - Settings::getInstance().setWindowGeometry(saveGeometry()); - Settings::getInstance().setWindowState(saveState()); - Settings::getInstance().setSplitterState(ui->mainSplitter->saveState()); - QWidget::closeEvent(event); + if(Settings::getInstance().getCloseToTray() == true) + { + event->ignore(); + this->hide(); + } + else + { + Settings::getInstance().setWindowGeometry(saveGeometry()); + Settings::getInstance().setWindowState(saveState()); + Settings::getInstance().setSplitterState(ui->mainSplitter->saveState()); + QWidget::closeEvent(event); + } +} + +void Widget::changeEvent(QEvent *event) +{ + if (event->type() == QEvent::WindowStateChange) + { + if(isMinimized() == true + && Settings::getInstance().getMinimizeToTray() == true) + { + this->hide(); + } + } } QString Widget::detectProfile() diff --git a/src/widget/widget.h b/src/widget/widget.h index 32e856d9f..e989855d9 100644 --- a/src/widget/widget.h +++ b/src/widget/widget.h @@ -65,6 +65,8 @@ public: ~Widget(); virtual void closeEvent(QCloseEvent *event); + virtual void changeEvent(QEvent *event); + public slots: void onSettingsClicked();