diff --git a/src/Settings/guisettingspage.cpp b/src/Settings/guisettingspage.cpp index 9ff5c17..258fd18 100644 --- a/src/Settings/guisettingspage.cpp +++ b/src/Settings/guisettingspage.cpp @@ -99,6 +99,7 @@ void GuiSettingsPage::applyChanges() settings.setEmojiFontFamily(emojiSettings->getFontFamily()); settings.setEmojiFontPointSize(emojiSettings->getFontPointSize()); settings.setMinimizeOnClose(minimizeToTrayCheckbox->isChecked()); + settings.setShowConfrimationDialogOnClose(showConfrimationDialogOnCloseCheckbox->isChecked()); } QGroupBox *GuiSettingsPage::buildAnimationGroup() @@ -197,7 +198,9 @@ QGroupBox* GuiSettingsPage::buildOthersGroup() QGroupBox *group = new QGroupBox(tr("Others"), this); QVBoxLayout* layout = new QVBoxLayout(group); minimizeToTrayCheckbox = new QCheckBox(tr("Minimize to tray on close"), group); + showConfrimationDialogOnCloseCheckbox = new QCheckBox(tr("Show confrimation dialog on close")); layout->addWidget(minimizeToTrayCheckbox); + layout->addWidget(showConfrimationDialogOnCloseCheckbox); return group; } diff --git a/src/Settings/guisettingspage.hpp b/src/Settings/guisettingspage.hpp index 2d14d21..1540bf9 100644 --- a/src/Settings/guisettingspage.hpp +++ b/src/Settings/guisettingspage.hpp @@ -50,6 +50,7 @@ private slots: EmojiFontSettingsDialog *emojiSettings; QCheckBox* enableAnimationCheckbox; QCheckBox* minimizeToTrayCheckbox; + QCheckBox* showConfrimationDialogOnCloseCheckbox; QComboBox* smileypackCombobox; QToolButton *emojiButton; diff --git a/src/Settings/settings.cpp b/src/Settings/settings.cpp index 385bbfb..6a98425 100644 --- a/src/Settings/settings.cpp +++ b/src/Settings/settings.cpp @@ -99,6 +99,7 @@ void Settings::load() emojiFontFamily = s.value("emojiFontFamily", "DejaVu Sans").toString(); emojiFontPointSize = s.value("emojiFontPointSize", QApplication::font().pointSize()).toInt(); minimizeOnClose = s.value("minimizeOnClose", true).toBool(); + showConfrimationDialogOnClose = s.value("showConfrimationDialogOnClose",true).toBool(); s.endGroup(); loaded = true; @@ -151,6 +152,7 @@ void Settings::save() s.setValue("emojiFontFamily", emojiFontFamily); s.setValue("emojiFontPointSize", emojiFontPointSize); s.setValue("minimizeOnClose", minimizeOnClose); + s.setValue("showConfrimationDialogOnClose",showConfrimationDialogOnClose); s.endGroup(); } @@ -286,3 +288,12 @@ void Settings::setMinimizeOnClose(bool newValue) { minimizeOnClose = newValue; } + +bool Settings::isShowConfrimationDialogOnCloseEnabled() const +{ + return showConfrimationDialogOnClose; +} +void Settings::setShowConfrimationDialogOnClose(bool newValue) +{ + showConfrimationDialogOnClose = newValue; +} diff --git a/src/Settings/settings.hpp b/src/Settings/settings.hpp index 53a72f4..a54dc4d 100644 --- a/src/Settings/settings.hpp +++ b/src/Settings/settings.hpp @@ -93,6 +93,9 @@ class Settings : public QObject bool isMinimizeOnCloseEnabled() const; void setMinimizeOnClose(bool newValue); + bool isShowConfrimationDialogOnCloseEnabled() const; + void setShowConfrimationDialogOnClose(bool newValue); + private: Settings(); Settings(Settings &settings) = delete; @@ -124,6 +127,7 @@ class Settings : public QObject QString emojiFontFamily; int emojiFontPointSize; bool minimizeOnClose; + bool showConfrimationDialogOnClose; signals: //void dataChanged(); diff --git a/src/closeapplicationdialog.cpp b/src/closeapplicationdialog.cpp index d3c57e4..8b41e8b 100644 --- a/src/closeapplicationdialog.cpp +++ b/src/closeapplicationdialog.cpp @@ -15,7 +15,7 @@ */ #include "closeapplicationdialog.hpp" - +#include "Settings/settings.hpp" #include #include #include @@ -36,15 +36,22 @@ CloseApplicationDialog::CloseApplicationDialog(QWidget *parent) : connect(buttonBox, &QDialogButtonBox::accepted, this, &CloseApplicationDialog::accept); connect(buttonBox, &QDialogButtonBox::rejected, this, &CloseApplicationDialog::reject); - QVBoxLayout* layout = new QVBoxLayout(this); + askAgainBox = new QCheckBox("Don't ask again",this); + askAgainBox->setChecked(false); - layout->addWidget(closeLabel); - layout->addSpacing(16); - layout->addWidget(buttonBox); + QHBoxLayout* buttonsLayout = new QHBoxLayout(); + buttonsLayout->addWidget(askAgainBox); + buttonsLayout->addWidget(buttonBox); + + QVBoxLayout* layout = new QVBoxLayout(this); + layout->addWidget(closeLabel,0,Qt::AlignHCenter); + layout->addSpacing(8); + layout->addLayout(buttonsLayout); } void CloseApplicationDialog::accept() { + Settings::getInstance().setShowConfrimationDialogOnClose(!askAgainBox->isChecked()); qApp->quit(); QDialog::accept(); } diff --git a/src/closeapplicationdialog.hpp b/src/closeapplicationdialog.hpp index 4b1b0de..0f9119f 100644 --- a/src/closeapplicationdialog.hpp +++ b/src/closeapplicationdialog.hpp @@ -18,13 +18,16 @@ #define CLOSEAPPLICATIONDIALOG_HPP #include - +#include class CloseApplicationDialog : public QDialog { Q_OBJECT public: explicit CloseApplicationDialog(QWidget *parent = 0); +private: + QCheckBox* askAgainBox; + public slots: void accept(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 8d0223a..1816b55 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -200,12 +200,22 @@ void MainWindow::closeEvent(QCloseEvent *event) bool minimize = Settings::getInstance().isMinimizeOnCloseEnabled(); if (isVisible() && minimize) { hide(); + trayMenuShowHideAction->setText(tr("Show")); event->ignore(); } else { - Settings::getInstance().saveGeometryState(this); - Settings::getInstance().saveGeometryState(splitterWidget); - QMainWindow::closeEvent(event); - qApp->quit(); + CloseApplicationDialog dialog(this); + bool showConfrimationDialog = Settings::getInstance().isShowConfrimationDialogOnCloseEnabled(); + QDialog::DialogCode onCloseDialogResult = QDialog::Accepted; + if (showConfrimationDialog) + onCloseDialogResult = static_cast(dialog.exec()); + if(onCloseDialogResult == QDialog::Accepted) { + Settings::getInstance().saveGeometryState(this); + Settings::getInstance().saveGeometryState(splitterWidget); + QMainWindow::closeEvent(event); + qApp->quit(); + } else { + event->ignore(); + } } } @@ -276,7 +286,12 @@ void MainWindow::onAboutAppActionTriggered() void MainWindow::onTrayMenuQuitApplicationActionTriggered() { CloseApplicationDialog dialog(this); - dialog.exec(); + bool showConfrimationDialog = Settings::getInstance().isShowConfrimationDialogOnCloseEnabled(); + if(showConfrimationDialog){ + dialog.exec(); + } else { + qApp->quit(); + } } void MainWindow::onShowHideWindow() @@ -297,8 +312,14 @@ void MainWindow::onTrayMenuStatusActionTriggered() Status selectedStatus = static_cast(statusAction->data().toInt()); if (selectedStatus == Status::Offline) { + bool showConfrimationDialog = Settings::getInstance().isShowConfrimationDialogOnCloseEnabled(); CloseApplicationDialog dialog(this); - dialog.exec(); + if(showConfrimationDialog) { + dialog.exec(); + } else { + qApp->quit(); + } + } else { emit statusSet(selectedStatus); }