1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-02-04 10:54:35 +00:00

Fix Coverity Scan 143909.

Also, the setting "Confirmation on auto-exit when downloads finish" wasn't working before.
This commit is contained in:
Chocobo1 2016-04-16 13:01:29 +08:00
parent 2d0b9e6538
commit a1e0fa5509

View File

@ -285,38 +285,32 @@ void Application::allTorrentsFinished()
{ {
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
Preferences *const pref = Preferences::instance(); Preferences *const pref = Preferences::instance();
bool isExit = pref->shutdownqBTWhenDownloadsComplete();
bool isShutdown = pref->shutdownWhenDownloadsComplete();
bool isSuspend = pref->suspendWhenDownloadsComplete();
bool isHibernate = pref->hibernateWhenDownloadsComplete();
bool will_shutdown = (pref->shutdownWhenDownloadsComplete() bool haveAction = isExit || isShutdown || isSuspend || isHibernate;
|| pref->shutdownqBTWhenDownloadsComplete() if (!haveAction) return;
|| pref->suspendWhenDownloadsComplete()
|| pref->hibernateWhenDownloadsComplete());
// Auto-Shutdown
if (will_shutdown) {
bool suspend = pref->suspendWhenDownloadsComplete();
bool hibernate = pref->hibernateWhenDownloadsComplete();
bool shutdown = pref->shutdownWhenDownloadsComplete();
// Confirm shutdown
ShutdownDialogAction action = ShutdownDialogAction::Exit; ShutdownDialogAction action = ShutdownDialogAction::Exit;
if (suspend) if (isSuspend)
action = ShutdownDialogAction::Suspend; action = ShutdownDialogAction::Suspend;
else if (hibernate) else if (isHibernate)
action = ShutdownDialogAction::Hibernate; action = ShutdownDialogAction::Hibernate;
else if (shutdown) else if (isShutdown)
action = ShutdownDialogAction::Shutdown; action = ShutdownDialogAction::Shutdown;
if ((action == ShutdownDialogAction::Exit) && (!pref->dontConfirmAutoExit())) { // ask confirm
if (!ShutdownConfirmDlg::askForConfirmation(action)) if ((action == ShutdownDialogAction::Exit) && (pref->dontConfirmAutoExit())) {
return; // do nothing & skip confirm
} }
else { //exit and shutdown else {
if (!ShutdownConfirmDlg::askForConfirmation(action)) if (!ShutdownConfirmDlg::askForConfirmation(action)) return;
return;
} }
// Actually shut down // Actually shut down
if (suspend || hibernate || shutdown) { if (action != ShutdownDialogAction::Exit) {
qDebug("Preparing for auto-shutdown because all downloads are complete!"); qDebug("Preparing for auto-shutdown because all downloads are complete!");
// Disabling it for next time // Disabling it for next time
pref->setShutdownWhenDownloadsComplete(false); pref->setShutdownWhenDownloadsComplete(false);
@ -325,9 +319,9 @@ void Application::allTorrentsFinished()
// Make sure preferences are synced before exiting // Make sure preferences are synced before exiting
m_shutdownAct = action; m_shutdownAct = action;
} }
qDebug("Exiting the application"); qDebug("Exiting the application");
exit(); exit();
}
#endif // DISABLE_GUI #endif // DISABLE_GUI
} }