Skip to content

Commit a1e0fa5

Browse files
committed
Fix Coverity Scan 143909.
Also, the setting "Confirmation on auto-exit when downloads finish" wasn't working before.
1 parent 2d0b9e6 commit a1e0fa5

1 file changed

Lines changed: 35 additions & 41 deletions

File tree

src/app/application.cpp

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -285,49 +285,43 @@ void Application::allTorrentsFinished()
285285
{
286286
#ifndef DISABLE_GUI
287287
Preferences *const pref = Preferences::instance();
288+
bool isExit = pref->shutdownqBTWhenDownloadsComplete();
289+
bool isShutdown = pref->shutdownWhenDownloadsComplete();
290+
bool isSuspend = pref->suspendWhenDownloadsComplete();
291+
bool isHibernate = pref->hibernateWhenDownloadsComplete();
292+
293+
bool haveAction = isExit || isShutdown || isSuspend || isHibernate;
294+
if (!haveAction) return;
295+
296+
ShutdownDialogAction action = ShutdownDialogAction::Exit;
297+
if (isSuspend)
298+
action = ShutdownDialogAction::Suspend;
299+
else if (isHibernate)
300+
action = ShutdownDialogAction::Hibernate;
301+
else if (isShutdown)
302+
action = ShutdownDialogAction::Shutdown;
303+
304+
// ask confirm
305+
if ((action == ShutdownDialogAction::Exit) && (pref->dontConfirmAutoExit())) {
306+
// do nothing & skip confirm
307+
}
308+
else {
309+
if (!ShutdownConfirmDlg::askForConfirmation(action)) return;
310+
}
288311

289-
bool will_shutdown = (pref->shutdownWhenDownloadsComplete()
290-
|| pref->shutdownqBTWhenDownloadsComplete()
291-
|| pref->suspendWhenDownloadsComplete()
292-
|| pref->hibernateWhenDownloadsComplete());
293-
294-
// Auto-Shutdown
295-
if (will_shutdown) {
296-
bool suspend = pref->suspendWhenDownloadsComplete();
297-
bool hibernate = pref->hibernateWhenDownloadsComplete();
298-
bool shutdown = pref->shutdownWhenDownloadsComplete();
299-
300-
// Confirm shutdown
301-
ShutdownDialogAction action = ShutdownDialogAction::Exit;
302-
if (suspend)
303-
action = ShutdownDialogAction::Suspend;
304-
else if (hibernate)
305-
action = ShutdownDialogAction::Hibernate;
306-
else if (shutdown)
307-
action = ShutdownDialogAction::Shutdown;
308-
309-
if ((action == ShutdownDialogAction::Exit) && (!pref->dontConfirmAutoExit())) {
310-
if (!ShutdownConfirmDlg::askForConfirmation(action))
311-
return;
312-
}
313-
else { //exit and shutdown
314-
if (!ShutdownConfirmDlg::askForConfirmation(action))
315-
return;
316-
}
317-
318-
// Actually shut down
319-
if (suspend || hibernate || shutdown) {
320-
qDebug("Preparing for auto-shutdown because all downloads are complete!");
321-
// Disabling it for next time
322-
pref->setShutdownWhenDownloadsComplete(false);
323-
pref->setSuspendWhenDownloadsComplete(false);
324-
pref->setHibernateWhenDownloadsComplete(false);
325-
// Make sure preferences are synced before exiting
326-
m_shutdownAct = action;
327-
}
328-
qDebug("Exiting the application");
329-
exit();
312+
// Actually shut down
313+
if (action != ShutdownDialogAction::Exit) {
314+
qDebug("Preparing for auto-shutdown because all downloads are complete!");
315+
// Disabling it for next time
316+
pref->setShutdownWhenDownloadsComplete(false);
317+
pref->setSuspendWhenDownloadsComplete(false);
318+
pref->setHibernateWhenDownloadsComplete(false);
319+
// Make sure preferences are synced before exiting
320+
m_shutdownAct = action;
330321
}
322+
323+
qDebug("Exiting the application");
324+
exit();
331325
#endif // DISABLE_GUI
332326
}
333327

0 commit comments

Comments
 (0)