Skip to content
This repository has been archived by the owner on Jun 11, 2020. It is now read-only.

Don't ask again on close #115

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Settings/guisettingspage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions src/Settings/guisettingspage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ private slots:
EmojiFontSettingsDialog *emojiSettings;
QCheckBox* enableAnimationCheckbox;
QCheckBox* minimizeToTrayCheckbox;
QCheckBox* showConfrimationDialogOnCloseCheckbox;

QComboBox* smileypackCombobox;
QToolButton *emojiButton;
Expand Down
11 changes: 11 additions & 0 deletions src/Settings/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -286,3 +288,12 @@ void Settings::setMinimizeOnClose(bool newValue)
{
minimizeOnClose = newValue;
}

bool Settings::isShowConfrimationDialogOnCloseEnabled() const
{
return showConfrimationDialogOnClose;
}
void Settings::setShowConfrimationDialogOnClose(bool newValue)
{
showConfrimationDialogOnClose = newValue;
}
4 changes: 4 additions & 0 deletions src/Settings/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -124,6 +127,7 @@ class Settings : public QObject
QString emojiFontFamily;
int emojiFontPointSize;
bool minimizeOnClose;
bool showConfrimationDialogOnClose;

signals:
//void dataChanged();
Expand Down
17 changes: 12 additions & 5 deletions src/closeapplicationdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

#include "closeapplicationdialog.hpp"

#include "Settings/settings.hpp"
#include <QDialogButtonBox>
#include <QLabel>
#include <QPushButton>
Expand All @@ -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();
}
5 changes: 4 additions & 1 deletion src/closeapplicationdialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@
#define CLOSEAPPLICATIONDIALOG_HPP

#include <QDialog>

#include <QCheckBox>
class CloseApplicationDialog : public QDialog
{
Q_OBJECT
public:
explicit CloseApplicationDialog(QWidget *parent = 0);

private:
QCheckBox* askAgainBox;

public slots:
void accept();

Expand Down
33 changes: 27 additions & 6 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QDialog::DialogCode>(dialog.exec());
if(onCloseDialogResult == QDialog::Accepted) {
Settings::getInstance().saveGeometryState(this);
Settings::getInstance().saveGeometryState(splitterWidget);
QMainWindow::closeEvent(event);
qApp->quit();
} else {
event->ignore();
}
}
}

Expand Down Expand Up @@ -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()
Expand All @@ -297,8 +312,14 @@ void MainWindow::onTrayMenuStatusActionTriggered()
Status selectedStatus = static_cast<Status>(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);
}
Expand Down