mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-23 04:54:18 +00:00
Add 'never show again' checkbox/pref to auto-exit confirm dialog
This commit is contained in:
parent
39ad4d65e8
commit
07599b5923
@ -167,12 +167,12 @@ void Application::allTorrentsFinished()
|
|||||||
Preferences *const pref = Preferences::instance();
|
Preferences *const pref = Preferences::instance();
|
||||||
|
|
||||||
bool will_shutdown = (pref->shutdownWhenDownloadsComplete()
|
bool will_shutdown = (pref->shutdownWhenDownloadsComplete()
|
||||||
|| pref->shutdownqBTWhenDownloadsComplete()
|
|
||||||
|| pref->suspendWhenDownloadsComplete()
|
|| pref->suspendWhenDownloadsComplete()
|
||||||
|| pref->hibernateWhenDownloadsComplete());
|
|| pref->hibernateWhenDownloadsComplete());
|
||||||
|
bool will_exit_only = pref->shutdownqBTWhenDownloadsComplete();
|
||||||
|
|
||||||
// Auto-Shutdown
|
// Auto-Shutdown
|
||||||
if (will_shutdown) {
|
if (will_exit_only || will_shutdown) {
|
||||||
bool suspend = pref->suspendWhenDownloadsComplete();
|
bool suspend = pref->suspendWhenDownloadsComplete();
|
||||||
bool hibernate = pref->hibernateWhenDownloadsComplete();
|
bool hibernate = pref->hibernateWhenDownloadsComplete();
|
||||||
bool shutdown = pref->shutdownWhenDownloadsComplete();
|
bool shutdown = pref->shutdownWhenDownloadsComplete();
|
||||||
@ -186,7 +186,21 @@ void Application::allTorrentsFinished()
|
|||||||
else if (shutdown)
|
else if (shutdown)
|
||||||
action = ShutdownAction::Shutdown;
|
action = ShutdownAction::Shutdown;
|
||||||
|
|
||||||
if (!ShutdownConfirmDlg::askForConfirmation(action)) return;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else { //exit and shutdown
|
||||||
|
bool shutdownConfirmed = false;
|
||||||
|
ShutdownConfirmDlg::askForConfirmation(action, &shutdownConfirmed);
|
||||||
|
if (!shutdownConfirmed) return;
|
||||||
|
}
|
||||||
|
|
||||||
// Actually shut down
|
// Actually shut down
|
||||||
if (suspend || hibernate || shutdown) {
|
if (suspend || hibernate || shutdown) {
|
||||||
|
@ -1385,6 +1385,16 @@ void Preferences::setShutdownqBTWhenDownloadsComplete(bool shutdown)
|
|||||||
setValue("Preferences/Downloads/AutoShutDownqBTOnCompletion", shutdown);
|
setValue("Preferences/Downloads/AutoShutDownqBTOnCompletion", shutdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Preferences::dontConfirmAutoExit() const
|
||||||
|
{
|
||||||
|
return value("Preferences/Downloads/DontConfirmAutoExit", false).toBool();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Preferences::setDontConfirmAutoExit(bool dontConfirmAutoExit)
|
||||||
|
{
|
||||||
|
setValue("Preferences/Downloads/DontConfirmAutoExit", dontConfirmAutoExit);
|
||||||
|
}
|
||||||
|
|
||||||
uint Preferences::diskCacheSize() const
|
uint Preferences::diskCacheSize() const
|
||||||
{
|
{
|
||||||
uint size = value("Preferences/Downloads/DiskWriteCacheSize", 0).toUInt();
|
uint size = value("Preferences/Downloads/DiskWriteCacheSize", 0).toUInt();
|
||||||
|
@ -360,6 +360,8 @@ public:
|
|||||||
void setHibernateWhenDownloadsComplete(bool hibernate);
|
void setHibernateWhenDownloadsComplete(bool hibernate);
|
||||||
bool shutdownqBTWhenDownloadsComplete() const;
|
bool shutdownqBTWhenDownloadsComplete() const;
|
||||||
void setShutdownqBTWhenDownloadsComplete(bool shutdown);
|
void setShutdownqBTWhenDownloadsComplete(bool shutdown);
|
||||||
|
bool dontConfirmAutoExit() const;
|
||||||
|
void setDontConfirmAutoExit(bool dontConfirmAutoExit);
|
||||||
uint diskCacheSize() const;
|
uint diskCacheSize() const;
|
||||||
void setDiskCacheSize(uint size);
|
void setDiskCacheSize(uint size);
|
||||||
uint diskCacheTTL() const;
|
uint diskCacheTTL() const;
|
||||||
|
@ -379,6 +379,16 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="checkProgramAutoExitConfirm">
|
||||||
|
<property name="text">
|
||||||
|
<string>Confirmation on auto-exit when downloads finish</string>
|
||||||
|
</property>
|
||||||
|
<property name="checked">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGroupBox" name="checkShowSystray">
|
<widget class="QGroupBox" name="checkShowSystray">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
|
@ -144,6 +144,7 @@ options_imp::options_imp(QWidget *parent)
|
|||||||
#endif
|
#endif
|
||||||
connect(checkShowSplash, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
|
connect(checkShowSplash, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
|
||||||
connect(checkProgramExitConfirm, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
|
connect(checkProgramExitConfirm, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
|
||||||
|
connect(checkProgramAutoExitConfirm, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
|
||||||
connect(checkPreventFromSuspend, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
|
connect(checkPreventFromSuspend, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
|
||||||
connect(comboTrayIcon, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton()));
|
connect(comboTrayIcon, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton()));
|
||||||
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) && !defined(QT_DBUS_LIB)
|
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) && !defined(QT_DBUS_LIB)
|
||||||
@ -396,6 +397,7 @@ void options_imp::saveOptions()
|
|||||||
pref->setStartMinimized(startMinimized());
|
pref->setStartMinimized(startMinimized());
|
||||||
pref->setSplashScreenDisabled(isSlashScreenDisabled());
|
pref->setSplashScreenDisabled(isSlashScreenDisabled());
|
||||||
pref->setConfirmOnExit(checkProgramExitConfirm->isChecked());
|
pref->setConfirmOnExit(checkProgramExitConfirm->isChecked());
|
||||||
|
pref->setDontConfirmAutoExit(!checkProgramAutoExitConfirm->isChecked());
|
||||||
pref->setPreventFromSuspend(preventFromSuspend());
|
pref->setPreventFromSuspend(preventFromSuspend());
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
pref->setWinStartup(WinStartup());
|
pref->setWinStartup(WinStartup());
|
||||||
@ -559,6 +561,7 @@ void options_imp::loadOptions()
|
|||||||
checkShowSplash->setChecked(!pref->isSplashScreenDisabled());
|
checkShowSplash->setChecked(!pref->isSplashScreenDisabled());
|
||||||
checkStartMinimized->setChecked(pref->startMinimized());
|
checkStartMinimized->setChecked(pref->startMinimized());
|
||||||
checkProgramExitConfirm->setChecked(pref->confirmOnExit());
|
checkProgramExitConfirm->setChecked(pref->confirmOnExit());
|
||||||
|
checkProgramAutoExitConfirm->setChecked(!pref->dontConfirmAutoExit());
|
||||||
|
|
||||||
checkShowSystray->setChecked(pref->systrayIntegration());
|
checkShowSystray->setChecked(pref->systrayIntegration());
|
||||||
if (checkShowSystray->isChecked()) {
|
if (checkShowSystray->isChecked()) {
|
||||||
|
@ -33,50 +33,81 @@
|
|||||||
#include "base/types.h"
|
#include "base/types.h"
|
||||||
#include "shutdownconfirm.h"
|
#include "shutdownconfirm.h"
|
||||||
|
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QStyle>
|
||||||
|
#include <QIcon>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QDialogButtonBox>
|
||||||
|
#include <QCheckBox>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
|
||||||
ShutdownConfirmDlg::ShutdownConfirmDlg(const ShutdownAction &action)
|
ShutdownConfirmDlg::ShutdownConfirmDlg(const ShutdownAction &action)
|
||||||
: m_exitNow(0)
|
: m_neverShowAgain(false)
|
||||||
, m_timeout(15)
|
, m_timeout(15)
|
||||||
, m_action(action)
|
, m_action(action)
|
||||||
{
|
{
|
||||||
// Title and button
|
QVBoxLayout *myLayout = new QVBoxLayout();
|
||||||
|
//Warning Icon and Text
|
||||||
|
QHBoxLayout *messageRow = new QHBoxLayout();
|
||||||
|
QLabel *warningLabel = new QLabel();
|
||||||
|
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);
|
||||||
|
updateText();
|
||||||
|
QDialogButtonBox *buttons = new QDialogButtonBox(Qt::Horizontal);
|
||||||
|
// Never show again checkbox, Title, and button
|
||||||
if (m_action == ShutdownAction::None) {
|
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"));
|
setWindowTitle(tr("Exit confirmation"));
|
||||||
m_exitNow = addButton(tr("Exit now"), QMessageBox::AcceptRole);
|
buttons->addButton(new QPushButton(tr("Exit Now")), QDialogButtonBox::AcceptRole);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
setWindowTitle(tr("Shutdown confirmation"));
|
setWindowTitle(tr("Shutdown confirmation"));
|
||||||
m_exitNow = addButton(tr("Shutdown now"), QMessageBox::AcceptRole);
|
buttons->addButton(new QPushButton(tr("Shutdown Now")), QDialogButtonBox::AcceptRole);
|
||||||
}
|
}
|
||||||
// Cancel Button
|
// Cancel Button
|
||||||
addButton(QMessageBox::Cancel);
|
QPushButton *cancelButton = buttons->addButton(QDialogButtonBox::Cancel);
|
||||||
// Text
|
cancelButton->setDefault(true);
|
||||||
updateText();
|
myLayout->addWidget(buttons, 0, Qt::AlignHCenter);
|
||||||
// Icon
|
connect(buttons, SIGNAL(accepted()), this, SLOT(accept()));
|
||||||
setIcon(QMessageBox::Warning);
|
connect(buttons, SIGNAL(rejected()), this, SLOT(reject()));
|
||||||
// Always on top
|
// Always on top
|
||||||
setWindowFlags(windowFlags()|Qt::WindowStaysOnTopHint);
|
setWindowFlags(windowFlags()|Qt::WindowStaysOnTopHint);
|
||||||
// Set 'Cancel' as default button.
|
// Set 'Cancel' as default button.
|
||||||
setDefaultButton(QMessageBox::Cancel);
|
|
||||||
m_timer.setInterval(1000); // 1sec
|
m_timer.setInterval(1000); // 1sec
|
||||||
connect(&m_timer, SIGNAL(timeout()), this, SLOT(updateSeconds()));
|
connect(&m_timer, SIGNAL(timeout()), this, SLOT(updateSeconds()));
|
||||||
show();
|
|
||||||
// Move to center
|
// Move to center
|
||||||
move(Utils::Misc::screenCenter(this));
|
move(Utils::Misc::screenCenter(this));
|
||||||
|
setLayout(myLayout);
|
||||||
|
cancelButton->setFocus();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ShutdownConfirmDlg::neverShowAgain() const
|
||||||
|
{
|
||||||
|
return m_neverShowAgain;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShutdownConfirmDlg::showEvent(QShowEvent *event)
|
void ShutdownConfirmDlg::showEvent(QShowEvent *event)
|
||||||
{
|
{
|
||||||
QMessageBox::showEvent(event);
|
QDialog::showEvent(event);
|
||||||
m_timer.start();
|
m_timer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ShutdownConfirmDlg::askForConfirmation(const ShutdownAction &action)
|
void ShutdownConfirmDlg::askForConfirmation(const ShutdownAction &action, bool *shutdownConfirmed, bool *neverShowAgain)
|
||||||
{
|
{
|
||||||
ShutdownConfirmDlg dlg(action);
|
ShutdownConfirmDlg dlg(action);
|
||||||
dlg.exec();
|
dlg.exec();
|
||||||
return dlg.shutdown();
|
*shutdownConfirmed = dlg.shutdown();
|
||||||
|
if (neverShowAgain)
|
||||||
|
*neverShowAgain = dlg.neverShowAgain();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShutdownConfirmDlg::updateSeconds()
|
void ShutdownConfirmDlg::updateSeconds()
|
||||||
@ -89,15 +120,14 @@ void ShutdownConfirmDlg::updateSeconds()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ShutdownConfirmDlg::handleNeverShowAgainCheckboxToggled(bool checked)
|
||||||
|
{
|
||||||
|
m_neverShowAgain = checked;
|
||||||
|
}
|
||||||
|
|
||||||
bool ShutdownConfirmDlg::shutdown() const
|
bool ShutdownConfirmDlg::shutdown() const
|
||||||
{
|
{
|
||||||
// This is necessary because result() in the case of QMessageBox
|
return (result() == QDialog::Accepted);
|
||||||
// returns a type of StandardButton, but since we use a custom button
|
|
||||||
// it will return 0 instead, even though we set the 'accept' role on it.
|
|
||||||
if (result() != QDialog::Accepted)
|
|
||||||
return (clickedButton() == m_exitNow);
|
|
||||||
else
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShutdownConfirmDlg::updateText()
|
void ShutdownConfirmDlg::updateText()
|
||||||
@ -119,15 +149,5 @@ void ShutdownConfirmDlg::updateText()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
setText(text);
|
m_text->setText(text);
|
||||||
}
|
|
||||||
|
|
||||||
QAbstractButton *ShutdownConfirmDlg::getExit_now() const
|
|
||||||
{
|
|
||||||
return m_exitNow;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ShutdownConfirmDlg::setExit_now(QAbstractButton *value)
|
|
||||||
{
|
|
||||||
m_exitNow = value;
|
|
||||||
}
|
}
|
||||||
|
@ -31,35 +31,37 @@
|
|||||||
#ifndef SHUTDOWNCONFIRM_H
|
#ifndef SHUTDOWNCONFIRM_H
|
||||||
#define SHUTDOWNCONFIRM_H
|
#define SHUTDOWNCONFIRM_H
|
||||||
|
|
||||||
#include <QMessageBox>
|
#include <QDialog>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include "base/utils/misc.h"
|
#include "base/utils/misc.h"
|
||||||
|
|
||||||
class ShutdownConfirmDlg : public QMessageBox
|
class QLabel;
|
||||||
|
|
||||||
|
class ShutdownConfirmDlg : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ShutdownConfirmDlg(const ShutdownAction &action);
|
ShutdownConfirmDlg(const ShutdownAction &action);
|
||||||
|
bool neverShowAgain() const;
|
||||||
bool shutdown() const;
|
bool shutdown() const;
|
||||||
|
|
||||||
static bool askForConfirmation(const ShutdownAction &action);
|
static void askForConfirmation(const ShutdownAction &action, bool *shutdownConfirmed, bool *neverShowAgain = 0);
|
||||||
|
|
||||||
QAbstractButton *getExit_now() const;
|
|
||||||
void setExit_now(QAbstractButton *value);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void showEvent(QShowEvent *event);
|
void showEvent(QShowEvent *event);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void updateSeconds();
|
void updateSeconds();
|
||||||
|
void handleNeverShowAgainCheckboxToggled(bool checked);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Methods
|
// Methods
|
||||||
void updateText();
|
void updateText();
|
||||||
|
|
||||||
// Vars
|
// Vars
|
||||||
QAbstractButton *m_exitNow;
|
QLabel *m_text;
|
||||||
|
bool m_neverShowAgain;
|
||||||
QTimer m_timer;
|
QTimer m_timer;
|
||||||
int m_timeout;
|
int m_timeout;
|
||||||
ShutdownAction m_action;
|
ShutdownAction m_action;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user