diff --git a/src/app/application.cpp b/src/app/application.cpp
index a414ae7cb..9c0d10bc5 100644
--- a/src/app/application.cpp
+++ b/src/app/application.cpp
@@ -287,12 +287,12 @@ void Application::allTorrentsFinished()
Preferences *const pref = Preferences::instance();
bool will_shutdown = (pref->shutdownWhenDownloadsComplete()
+ || pref->shutdownqBTWhenDownloadsComplete()
|| pref->suspendWhenDownloadsComplete()
|| pref->hibernateWhenDownloadsComplete());
- bool will_exit_only = pref->shutdownqBTWhenDownloadsComplete();
// Auto-Shutdown
- if (will_exit_only || will_shutdown) {
+ if (will_shutdown) {
bool suspend = pref->suspendWhenDownloadsComplete();
bool hibernate = pref->hibernateWhenDownloadsComplete();
bool shutdown = pref->shutdownWhenDownloadsComplete();
@@ -306,20 +306,13 @@ void Application::allTorrentsFinished()
else if (shutdown)
action = ShutdownAction::Shutdown;
- if (will_exit_only) {
- if (!pref->dontConfirmAutoExit()) {
- bool exitConfirmed = false;
- bool neverAskForExitConfirmationAgain = false;
- ShutdownConfirmDlg::askForConfirmation(action, &exitConfirmed, &neverAskForExitConfirmationAgain);
- if (neverAskForExitConfirmationAgain && exitConfirmed/*discard the request to never show again if dialog not accepted*/)
- pref->setDontConfirmAutoExit(true);
- if (!exitConfirmed) return;
- }
+ if ((action == ShutdownAction::None) && (!pref->dontConfirmAutoExit())) {
+ if (!ShutdownConfirmDlg::askForConfirmation(action))
+ return;
}
else { //exit and shutdown
- bool shutdownConfirmed = false;
- ShutdownConfirmDlg::askForConfirmation(action, &shutdownConfirmed);
- if (!shutdownConfirmed) return;
+ if (!ShutdownConfirmDlg::askForConfirmation(action))
+ return;
}
// Actually shut down
diff --git a/src/base/preferences.cpp b/src/base/preferences.cpp
index 8f3e8df9e..2fbda9c15 100644
--- a/src/base/preferences.cpp
+++ b/src/base/preferences.cpp
@@ -1166,12 +1166,12 @@ void Preferences::setShutdownqBTWhenDownloadsComplete(bool shutdown)
bool Preferences::dontConfirmAutoExit() const
{
- return value("Preferences/Downloads/DontConfirmAutoExit", false).toBool();
+ return value("ShutdownConfirmDlg/DontConfirmAutoExit", false).toBool();
}
void Preferences::setDontConfirmAutoExit(bool dontConfirmAutoExit)
{
- setValue("Preferences/Downloads/DontConfirmAutoExit", dontConfirmAutoExit);
+ setValue("ShutdownConfirmDlg/DontConfirmAutoExit", dontConfirmAutoExit);
}
uint Preferences::diskCacheSize() const
diff --git a/src/gui/confirmshutdowndlg.ui b/src/gui/confirmshutdowndlg.ui
new file mode 100644
index 000000000..8c1562ac1
--- /dev/null
+++ b/src/gui/confirmshutdowndlg.ui
@@ -0,0 +1,146 @@
+
+
+ confirmShutdownDlg
+
+
+
+ 0
+ 0
+ 463
+ 128
+
+
+
+
+ 0
+ 0
+
+
+
+ -
+
+
+ 20
+
+
-
+
+
+ 6
+
+
-
+
+
+
+ 0
+ 0
+
+
+
+ warning icon goes here
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+
+ 20
+ 40
+
+
+
+
+
+
+ -
+
+
+ 6
+
+
-
+
+
+
+ 0
+ 0
+
+
+
+ shutdown message goes here
+
+
+ Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter
+
+
+ true
+
+
+
+ -
+
+
+ Don't show again
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+
+ 20
+ 40
+
+
+
+
+
+
+
+
+ -
+
+
+
+
+
+
+
+ buttonBox
+ accepted()
+ confirmShutdownDlg
+ accept()
+
+
+ 248
+ 254
+
+
+ 157
+ 274
+
+
+
+
+ buttonBox
+ rejected()
+ confirmShutdownDlg
+ reject()
+
+
+ 316
+ 260
+
+
+ 286
+ 274
+
+
+
+
+
diff --git a/src/gui/gui.pri b/src/gui/gui.pri
index f2a5e89ca..c92e27571 100644
--- a/src/gui/gui.pri
+++ b/src/gui/gui.pri
@@ -103,6 +103,7 @@ FORMS += \
$$PWD/bandwidth_limit.ui \
$$PWD/updownratiodlg.ui \
$$PWD/confirmdeletiondlg.ui \
+ $$PWD/confirmshutdowndlg.ui \
$$PWD/torrentimportdlg.ui \
$$PWD/executionlog.ui \
$$PWD/addnewtorrentdialog.ui \
diff --git a/src/gui/shutdownconfirm.cpp b/src/gui/shutdownconfirm.cpp
index d1579f7c8..cc5b58e7a 100644
--- a/src/gui/shutdownconfirm.cpp
+++ b/src/gui/shutdownconfirm.cpp
@@ -30,9 +30,6 @@
* Contact : hammered999@gmail.com
*/
-#include "base/types.h"
-#include "shutdownconfirm.h"
-
#include
#include
#include
@@ -42,43 +39,35 @@
#include
#include
+#include "base/preferences.h"
+#include "base/types.h"
+
+#include "shutdownconfirm.h"
+#include "ui_confirmshutdowndlg.h"
+
ShutdownConfirmDlg::ShutdownConfirmDlg(const ShutdownAction &action)
- : m_neverShowAgain(false)
+ : ui(new Ui::confirmShutdownDlg)
, m_timeout(15)
, m_action(action)
{
- QVBoxLayout *myLayout = new QVBoxLayout();
- //Warning Icon and Text
- QHBoxLayout *messageRow = new QHBoxLayout();
- QLabel *warningLabel = new QLabel();
+ ui->setupUi(this);
+
QIcon warningIcon(style()->standardIcon(QStyle::SP_MessageBoxWarning, 0, this));
- warningLabel->setPixmap(warningIcon.pixmap(warningIcon.actualSize(QSize(32, 32))));
- messageRow->addWidget(warningLabel);
- m_text = new QLabel();
- messageRow->addWidget(m_text);
- myLayout->addLayout(messageRow);
+ ui->warningLabel->setPixmap(warningIcon.pixmap(warningIcon.actualSize(QSize(32, 32))));
updateText();
- QDialogButtonBox *buttons = new QDialogButtonBox(Qt::Horizontal);
// Never show again checkbox, Title, and button
if (m_action == ShutdownAction::None) {
- //Never show again checkbox (shown only when exitting without shutdown)
- QCheckBox *neverShowAgainCheckbox = new QCheckBox(tr("Never show again"));
- myLayout->addWidget(neverShowAgainCheckbox, 0, Qt::AlignHCenter);
- //Title and button
- connect(neverShowAgainCheckbox, SIGNAL(clicked(bool)), this, SLOT(handleNeverShowAgainCheckboxToggled(bool)));
setWindowTitle(tr("Exit confirmation"));
- buttons->addButton(new QPushButton(tr("Exit Now")), QDialogButtonBox::AcceptRole);
+ ui->buttonBox->addButton(new QPushButton(tr("Exit Now"), this), QDialogButtonBox::AcceptRole);
}
else {
setWindowTitle(tr("Shutdown confirmation"));
- buttons->addButton(new QPushButton(tr("Shutdown Now")), QDialogButtonBox::AcceptRole);
+ ui->buttonBox->addButton(new QPushButton(tr("Shutdown Now"), this), QDialogButtonBox::AcceptRole);
+ ui->neverShowAgainCheckbox->setVisible(false);
}
// Cancel Button
- QPushButton *cancelButton = buttons->addButton(QDialogButtonBox::Cancel);
+ QPushButton *cancelButton = ui->buttonBox->addButton(QDialogButtonBox::Cancel);
cancelButton->setDefault(true);
- myLayout->addWidget(buttons, 0, Qt::AlignHCenter);
- connect(buttons, SIGNAL(accepted()), this, SLOT(accept()));
- connect(buttons, SIGNAL(rejected()), this, SLOT(reject()));
// Always on top
setWindowFlags(windowFlags()|Qt::WindowStaysOnTopHint);
// Set 'Cancel' as default button.
@@ -86,28 +75,20 @@ ShutdownConfirmDlg::ShutdownConfirmDlg(const ShutdownAction &action)
connect(&m_timer, SIGNAL(timeout()), this, SLOT(updateSeconds()));
// Move to center
move(Utils::Misc::screenCenter(this));
- setLayout(myLayout);
cancelButton->setFocus();
}
-bool ShutdownConfirmDlg::neverShowAgain() const
-{
- return m_neverShowAgain;
-}
-
void ShutdownConfirmDlg::showEvent(QShowEvent *event)
{
QDialog::showEvent(event);
m_timer.start();
}
-void ShutdownConfirmDlg::askForConfirmation(const ShutdownAction &action, bool *shutdownConfirmed, bool *neverShowAgain)
+bool ShutdownConfirmDlg::askForConfirmation(const ShutdownAction &action)
{
ShutdownConfirmDlg dlg(action);
dlg.exec();
- *shutdownConfirmed = dlg.shutdown();
- if (neverShowAgain)
- *neverShowAgain = dlg.neverShowAgain();
+ return dlg.shutdown();
}
void ShutdownConfirmDlg::updateSeconds()
@@ -120,9 +101,10 @@ void ShutdownConfirmDlg::updateSeconds()
}
}
-void ShutdownConfirmDlg::handleNeverShowAgainCheckboxToggled(bool checked)
+void ShutdownConfirmDlg::accept()
{
- m_neverShowAgain = checked;
+ Preferences::instance()->setDontConfirmAutoExit(ui->neverShowAgainCheckbox->isChecked());
+ QDialog::accept();
}
bool ShutdownConfirmDlg::shutdown() const
@@ -149,5 +131,5 @@ void ShutdownConfirmDlg::updateText()
break;
}
- m_text->setText(text);
+ ui->shutdownText->setText(text);
}
diff --git a/src/gui/shutdownconfirm.h b/src/gui/shutdownconfirm.h
index a365fd27e..7304fa9d7 100644
--- a/src/gui/shutdownconfirm.h
+++ b/src/gui/shutdownconfirm.h
@@ -36,6 +36,12 @@
#include "base/utils/misc.h"
class QLabel;
+class QCheckBox;
+
+namespace Ui
+{
+ class confirmShutdownDlg;
+}
class ShutdownConfirmDlg : public QDialog
{
@@ -43,25 +49,23 @@ class ShutdownConfirmDlg : public QDialog
public:
ShutdownConfirmDlg(const ShutdownAction &action);
- bool neverShowAgain() const;
bool shutdown() const;
- static void askForConfirmation(const ShutdownAction &action, bool *shutdownConfirmed, bool *neverShowAgain = 0);
+ static bool askForConfirmation(const ShutdownAction &action);
protected:
void showEvent(QShowEvent *event);
private slots:
void updateSeconds();
- void handleNeverShowAgainCheckboxToggled(bool checked);
+ void accept() override;
private:
// Methods
void updateText();
// Vars
- QLabel *m_text;
- bool m_neverShowAgain;
+ Ui::confirmShutdownDlg *ui;
QTimer m_timer;
int m_timeout;
ShutdownAction m_action;