mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-23 04:54:18 +00:00
Added 'Shutdown now' button in shutdown confirmation dialog. Closes #969.
This commit is contained in:
parent
634000e7a9
commit
f6156217d0
@ -2299,18 +2299,17 @@ void QBtSession::handleTorrentFinishedAlert(libtorrent::torrent_finished_alert*
|
||||
bool hibernate = pref->hibernateWhenDownloadsComplete();
|
||||
bool shutdown = pref->shutdownWhenDownloadsComplete();
|
||||
// Confirm shutdown
|
||||
QString confirm_msg;
|
||||
if (suspend) {
|
||||
confirm_msg = tr("The computer will now go to sleep mode unless you cancel within the next 15 seconds...");
|
||||
} else if (hibernate) {
|
||||
confirm_msg = tr("The computer will now go to hibernation mode unless you cancel within the next 15 seconds...");
|
||||
} else if (shutdown) {
|
||||
confirm_msg = tr("The computer will now be switched off unless you cancel within the next 15 seconds...");
|
||||
} else {
|
||||
confirm_msg = tr("qBittorrent will now exit unless you cancel within the next 15 seconds...");
|
||||
}
|
||||
if (!ShutdownConfirmDlg::askForConfirmation(confirm_msg))
|
||||
shutDownAction action = NO_SHUTDOWN;
|
||||
|
||||
if (suspend)
|
||||
action = SUSPEND_COMPUTER;
|
||||
else if (hibernate)
|
||||
action = HIBERNATE_COMPUTER;
|
||||
else if (shutdown)
|
||||
action = SHUTDOWN_COMPUTER;
|
||||
if (!ShutdownConfirmDlg::askForConfirmation(action))
|
||||
return;
|
||||
|
||||
// Actually shut down
|
||||
if (suspend || hibernate || shutdown) {
|
||||
qDebug("Preparing for auto-shutdown because all downloads are complete!");
|
||||
@ -2319,12 +2318,7 @@ void QBtSession::handleTorrentFinishedAlert(libtorrent::torrent_finished_alert*
|
||||
pref->setSuspendWhenDownloadsComplete(false);
|
||||
pref->setHibernateWhenDownloadsComplete(false);
|
||||
// Make sure preferences are synced before exiting
|
||||
if (suspend)
|
||||
m_shutdownAct = SUSPEND_COMPUTER;
|
||||
else if (hibernate)
|
||||
m_shutdownAct = HIBERNATE_COMPUTER;
|
||||
else
|
||||
m_shutdownAct = SHUTDOWN_COMPUTER;
|
||||
m_shutdownAct = action;
|
||||
}
|
||||
qDebug("Exiting the application");
|
||||
qApp->exit();
|
||||
|
@ -32,28 +32,81 @@
|
||||
|
||||
#include "shutdownconfirm.h"
|
||||
|
||||
#include <QPushButton>
|
||||
|
||||
ShutdownConfirmDlg::ShutdownConfirmDlg(const QString &message) {
|
||||
// Text
|
||||
setWindowTitle(tr("Shutdown confirmation"));
|
||||
setText(message);
|
||||
ShutdownConfirmDlg::ShutdownConfirmDlg(const shutDownAction &action): exit_now(NULL), timeout(15), action0(action) {
|
||||
// Title and button
|
||||
if (action0 == NO_SHUTDOWN) {
|
||||
setWindowTitle(tr("Exit confirmation"));
|
||||
exit_now = addButton(tr("Exit now"), QMessageBox::AcceptRole);
|
||||
}
|
||||
else {
|
||||
setWindowTitle(tr("Shutdown confirmation"));
|
||||
exit_now = addButton(tr("Shutdown now"), QMessageBox::AcceptRole);
|
||||
}
|
||||
// Cancel Button
|
||||
addButton(QMessageBox::Cancel);
|
||||
// Text
|
||||
updateText();
|
||||
// Icon
|
||||
setIcon(QMessageBox::Warning);
|
||||
// Always on top
|
||||
setWindowFlags(windowFlags()|Qt::WindowStaysOnTopHint);
|
||||
timer.setInterval(1000); // 1sec
|
||||
connect(&timer, SIGNAL(timeout()), this, SLOT(updateSeconds()));
|
||||
show();
|
||||
// Move to center
|
||||
move(misc::screenCenter(this));
|
||||
}
|
||||
|
||||
bool ShutdownConfirmDlg::askForConfirmation(const QString &message) {
|
||||
ShutdownConfirmDlg dlg(message);
|
||||
// Auto shutdown timer
|
||||
QTimer timer;
|
||||
connect(&timer, SIGNAL(timeout()), &dlg, SLOT(accept()));
|
||||
timer.start(15000); // 15sec
|
||||
dlg.exec();
|
||||
return (dlg.result() == QDialog::Accepted);
|
||||
void ShutdownConfirmDlg::showEvent(QShowEvent *event) {
|
||||
QMessageBox::showEvent(event);
|
||||
timer.start();
|
||||
}
|
||||
|
||||
bool ShutdownConfirmDlg::askForConfirmation(const shutDownAction &action) {
|
||||
ShutdownConfirmDlg dlg(action);
|
||||
dlg.exec();
|
||||
return dlg.shutdown();
|
||||
}
|
||||
|
||||
void ShutdownConfirmDlg::updateSeconds() {
|
||||
--timeout;
|
||||
updateText();
|
||||
if (timeout == 0) {
|
||||
timer.stop();
|
||||
accept();
|
||||
}
|
||||
}
|
||||
|
||||
bool ShutdownConfirmDlg::shutdown() const {
|
||||
// This is necessary because result() in the case of QMessageBox
|
||||
// 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() == exit_now);
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
void ShutdownConfirmDlg::updateText() {
|
||||
QString text;
|
||||
|
||||
switch (action0) {
|
||||
case NO_SHUTDOWN:
|
||||
text = tr("qBittorrent will now exit unless you cancel within the next %1 seconds.").arg(QString::number(timeout));
|
||||
break;
|
||||
case SHUTDOWN_COMPUTER:
|
||||
text = tr("The computer will now be switched off unless you cancel within the next %1 seconds.").arg(QString::number(timeout));
|
||||
break;
|
||||
case SUSPEND_COMPUTER:
|
||||
text = tr("The computer will now go to sleep mode unless you cancel within the next %1 seconds.").arg(QString::number(timeout));
|
||||
break;
|
||||
case HIBERNATE_COMPUTER:
|
||||
text = tr("The computer will now go to hibernation mode unless you cancel within the next %1 seconds.").arg(QString::number(timeout));
|
||||
break;
|
||||
}
|
||||
|
||||
setText(text);
|
||||
}
|
||||
|
||||
|
@ -39,9 +39,26 @@ class ShutdownConfirmDlg : public QMessageBox {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ShutdownConfirmDlg(const QString &message);
|
||||
ShutdownConfirmDlg(const shutDownAction &action);
|
||||
bool shutdown() const;
|
||||
|
||||
static bool askForConfirmation(const QString &message);
|
||||
static bool askForConfirmation(const shutDownAction &action);
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *event);
|
||||
|
||||
private slots:
|
||||
void updateSeconds();
|
||||
|
||||
private:
|
||||
// Methods
|
||||
void updateText();
|
||||
|
||||
// Vars
|
||||
QAbstractButton *exit_now;
|
||||
QTimer timer;
|
||||
int timeout;
|
||||
shutDownAction action0;
|
||||
};
|
||||
|
||||
#endif // SHUTDOWNCONFIRM_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user