From d268360c51b02b5354c1c8dce3936d2c3f342c56 Mon Sep 17 00:00:00 2001 From: agilob Date: Sun, 19 Oct 2014 20:47:06 +0100 Subject: [PATCH 1/2] 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() From 6e5068840d35e2502a98d4fedce4df3539ed08f8 Mon Sep 17 00:00:00 2001 From: agilob Date: Mon, 20 Oct 2014 12:50:12 +0100 Subject: [PATCH 2/2] minimize to tray --- src/misc/settings.cpp | 13 +++++++++++++ src/misc/settings.h | 4 ++++ src/widget/form/settings/generalform.cpp | 19 +++++++++++++------ src/widget/form/settings/generalform.h | 1 + src/widget/form/settings/generalsettings.ui | 13 ++++++++++--- src/widget/widget.cpp | 12 ++++++++++++ src/widget/widget.h | 2 ++ 7 files changed, 55 insertions(+), 9 deletions(-) diff --git a/src/misc/settings.cpp b/src/misc/settings.cpp index 07e2522ec..16ae29f4e 100644 --- a/src/misc/settings.cpp +++ b/src/misc/settings.cpp @@ -138,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(); @@ -252,6 +253,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); @@ -402,6 +404,17 @@ 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 12a56f47b..6f75b9055 100644 --- a/src/misc/settings.h +++ b/src/misc/settings.h @@ -55,6 +55,9 @@ public: bool getCloseToTray() const; void setCloseToTray(bool newValue); + bool getMinimizeToTray() const; + void setMinimizeToTray(bool newValue); + QString getStyle() const; void setStyle(const QString& newValue); @@ -189,6 +192,7 @@ private: 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 ab87e0d56..e6b21b109 100644 --- a/src/widget/form/settings/generalform.cpp +++ b/src/widget/form/settings/generalform.cpp @@ -40,8 +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->closeToTrayCheckbox->setChecked(Settings::getInstance().getCloseToTray()); - 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()) { @@ -73,8 +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->closeToTrayCheckbox, &QCheckBox::stateChanged, this, &GeneralForm::onSetCloseToTray); - 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); @@ -113,7 +115,12 @@ void GeneralForm::onSetAutostartInTray() void GeneralForm::onSetCloseToTray() { - Settings::getInstance().setCloseToTray(bodyUI->closeToTrayCheckbox->isChecked()); + Settings::getInstance().setCloseToTray(bodyUI->closeToTray->isChecked()); +} + +void GeneralForm::onSetMinimizeToTray() +{ + Settings::getInstance().setMinimizeToTray(bodyUI->minimizeToTray->isChecked()); } void GeneralForm::onStyleSelected(QString style) @@ -132,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 593742a34..6397ccdfd 100644 --- a/src/widget/form/settings/generalform.h +++ b/src/widget/form/settings/generalform.h @@ -44,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 a6292c0a7..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,14 +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 b69764ba2..72a747ec3 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -268,6 +268,18 @@ void Widget::closeEvent(QCloseEvent *event) } } +void Widget::changeEvent(QEvent *event) +{ + if (event->type() == QEvent::WindowStateChange) + { + if(isMinimized() == true + && Settings::getInstance().getMinimizeToTray() == true) + { + this->hide(); + } + } +} + QString Widget::detectProfile() { QDir dir(Settings::getSettingsDirPath()); diff --git a/src/widget/widget.h b/src/widget/widget.h index 37af9b499..9d4dd4397 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); + signals: void friendRequestAccepted(const QString& userId);