Merge pull request #1447 from BrunoReX/hibernation

Add option to hibernate computer in Auto-Shutdown menu
This commit is contained in:
sledgehammer999 2014-07-06 23:11:29 +03:00
commit d6d20074be
8 changed files with 59 additions and 13 deletions

View file

@ -198,8 +198,8 @@ QBtSession::~QBtSession() {
qDebug("BTSession destructor OUT");
#ifndef DISABLE_GUI
if (m_shutdownAct != NO_SHUTDOWN) {
qDebug() << "Sending computer shutdown/suspend signal...";
misc::shutdownComputer(m_shutdownAct == SUSPEND_COMPUTER);
qDebug() << "Sending computer shutdown/suspend/hibernate signal...";
misc::shutdownComputer(m_shutdownAct);
}
#endif
}
@ -2286,7 +2286,8 @@ void QBtSession::handleTorrentFinishedAlert(libtorrent::torrent_finished_alert*
#ifndef DISABLE_GUI
bool will_shutdown = (pref.shutdownWhenDownloadsComplete() ||
pref.shutdownqBTWhenDownloadsComplete() ||
pref.suspendWhenDownloadsComplete())
pref.suspendWhenDownloadsComplete() ||
pref.hibernateWhenDownloadsComplete())
&& !hasDownloadingTorrents();
#else
bool will_shutdown = false;
@ -2304,11 +2305,14 @@ void QBtSession::handleTorrentFinishedAlert(libtorrent::torrent_finished_alert*
// Auto-Shutdown
if (will_shutdown) {
bool suspend = pref.suspendWhenDownloadsComplete();
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 {
@ -2317,14 +2321,17 @@ void QBtSession::handleTorrentFinishedAlert(libtorrent::torrent_finished_alert*
if (!ShutdownConfirmDlg::askForConfirmation(confirm_msg))
return;
// Actually shut down
if (suspend || shutdown) {
if (suspend || hibernate || shutdown) {
qDebug("Preparing for auto-shutdown because all downloads are complete!");
// Disabling it for next time
pref.setShutdownWhenDownloadsComplete(false);
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;
}