From d268360c51b02b5354c1c8dce3936d2c3f342c56 Mon Sep 17 00:00:00 2001 From: agilob Date: Sun, 19 Oct 2014 20:47:06 +0100 Subject: [PATCH] closing to tray, gui and settings --- src/misc/settings.cpp | 12 ++++++++++++ src/misc/settings.h | 4 ++++ src/widget/form/settings/generalform.cpp | 7 +++++++ src/widget/form/settings/generalform.h | 1 + src/widget/form/settings/generalsettings.ui | 7 +++++++ src/widget/widget.cpp | 16 ++++++++++++---- 6 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/misc/settings.cpp b/src/misc/settings.cpp index de84e7a3c..07e2522ec 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(); @@ -225,6 +226,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); @@ -390,6 +392,16 @@ void Settings::setAutostartInTray(bool newValue) autostartInTray = newValue; } +bool Settings::getCloseToTray() const +{ + return closeToTray; +} + +void Settings::setCloseToTray(bool newValue) +{ + closeToTray = newValue; +} + bool Settings::getStatusChangeNotificationEnabled() const { return statusChangeNotificationEnabled; diff --git a/src/misc/settings.h b/src/misc/settings.h index 5d4363f31..12a56f47b 100644 --- a/src/misc/settings.h +++ b/src/misc/settings.h @@ -52,6 +52,9 @@ public: bool getAutostartInTray() const; void setAutostartInTray(bool newValue); + bool getCloseToTray() const; + void setCloseToTray(bool newValue); + QString getStyle() const; void setStyle(const QString& newValue); @@ -185,6 +188,7 @@ private: QString translation; static bool makeToxPortable; bool autostartInTray; + bool closeToTray; bool forceTCP; diff --git a/src/widget/form/settings/generalform.cpp b/src/widget/form/settings/generalform.cpp index 78867b60e..ab87e0d56 100644 --- a/src/widget/form/settings/generalform.cpp +++ b/src/widget/form/settings/generalform.cpp @@ -40,6 +40,7 @@ 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->closeToTrayCheckbox->setChecked(Settings::getInstance().getCloseToTray()); bodyUI->statusChangesCheckbox->setChecked(Settings::getInstance().getStatusChangeNotificationEnabled()); for (auto entry : SmileyPack::listSmileyPacks()) @@ -72,6 +73,7 @@ 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->closeToTrayCheckbox, &QCheckBox::stateChanged, this, &GeneralForm::onSetCloseToTray); connect(bodyUI->statusChangesCheckbox, &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) @@ -109,6 +111,11 @@ void GeneralForm::onSetAutostartInTray() Settings::getInstance().setAutostartInTray(bodyUI->startInTray->isChecked()); } +void GeneralForm::onSetCloseToTray() +{ + Settings::getInstance().setCloseToTray(bodyUI->closeToTrayCheckbox->isChecked()); +} + void GeneralForm::onStyleSelected(QString style) { Settings::getInstance().setStyle(style); diff --git a/src/widget/form/settings/generalform.h b/src/widget/form/settings/generalform.h index bae1eb8d0..593742a34 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(); diff --git a/src/widget/form/settings/generalsettings.ui b/src/widget/form/settings/generalsettings.ui index 924bc057b..a6292c0a7 100644 --- a/src/widget/form/settings/generalsettings.ui +++ b/src/widget/form/settings/generalsettings.ui @@ -73,6 +73,13 @@ + + + + Close to tray + + + diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index fdc3465d8..b69764ba2 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -254,10 +254,18 @@ 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); + } } QString Widget::detectProfile()