1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-02-09 05:14:23 +00:00

Merge pull request #5127 from Chocobo1/shutdown

Fix Shutdown confirmation
This commit is contained in:
sledgehammer999 2016-04-17 12:16:03 -05:00
commit 18148a3aed
4 changed files with 41 additions and 48 deletions

View File

@ -96,9 +96,7 @@ namespace
Application::Application(const QString &id, int &argc, char **argv) Application::Application(const QString &id, int &argc, char **argv)
: BaseApplication(id, argc, argv) : BaseApplication(id, argc, argv)
, m_running(false) , m_running(false)
#ifndef DISABLE_GUI
, m_shutdownAct(ShutdownDialogAction::Exit) , m_shutdownAct(ShutdownDialogAction::Exit)
#endif
{ {
Logger::initInstance(); Logger::initInstance();
SettingsStorage::initInstance(); SettingsStorage::initInstance();
@ -283,52 +281,46 @@ void Application::torrentFinished(BitTorrent::TorrentHandle *const torrent)
void Application::allTorrentsFinished() void Application::allTorrentsFinished()
{ {
#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 ShutdownDialogAction action = ShutdownDialogAction::Exit;
if (will_shutdown) { if (isSuspend)
bool suspend = pref->suspendWhenDownloadsComplete(); action = ShutdownDialogAction::Suspend;
bool hibernate = pref->hibernateWhenDownloadsComplete(); else if (isHibernate)
bool shutdown = pref->shutdownWhenDownloadsComplete(); action = ShutdownDialogAction::Hibernate;
else if (isShutdown)
action = ShutdownDialogAction::Shutdown;
// Confirm shutdown #ifndef DISABLE_GUI
ShutdownDialogAction action = ShutdownDialogAction::Exit; // ask confirm
if (suspend) if ((action == ShutdownDialogAction::Exit) && (pref->dontConfirmAutoExit())) {
action = ShutdownDialogAction::Suspend; // do nothing & skip confirm
else if (hibernate) }
action = ShutdownDialogAction::Hibernate; else {
else if (shutdown) if (!ShutdownConfirmDlg::askForConfirmation(action)) return;
action = ShutdownDialogAction::Shutdown;
if ((action == ShutdownDialogAction::Exit) && (!pref->dontConfirmAutoExit())) {
if (!ShutdownConfirmDlg::askForConfirmation(action))
return;
}
else { //exit and shutdown
if (!ShutdownConfirmDlg::askForConfirmation(action))
return;
}
// Actually shut down
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
m_shutdownAct = action;
}
qDebug("Exiting the application");
exit();
} }
#endif // DISABLE_GUI #endif // DISABLE_GUI
// Actually shut down
if (action != ShutdownDialogAction::Exit) {
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
m_shutdownAct = action;
}
qDebug("Exiting the application");
exit();
} }
bool Application::sendParams(const QStringList &params) bool Application::sendParams(const QStringList &params)
@ -371,7 +363,7 @@ int Application::exec(const QStringList &params)
BitTorrent::Session::initInstance(); BitTorrent::Session::initInstance();
connect(BitTorrent::Session::instance(), SIGNAL(torrentFinished(BitTorrent::TorrentHandle *const)), SLOT(torrentFinished(BitTorrent::TorrentHandle *const))); connect(BitTorrent::Session::instance(), SIGNAL(torrentFinished(BitTorrent::TorrentHandle *const)), SLOT(torrentFinished(BitTorrent::TorrentHandle *const)));
connect(BitTorrent::Session::instance(), SIGNAL(allTorrentsFinished()), SLOT(allTorrentsFinished())); connect(BitTorrent::Session::instance(), SIGNAL(allTorrentsFinished()), SLOT(allTorrentsFinished()), Qt::QueuedConnection);
#ifndef DISABLE_COUNTRIES_RESOLUTION #ifndef DISABLE_COUNTRIES_RESOLUTION
Net::GeoIPManager::initInstance(); Net::GeoIPManager::initInstance();
@ -595,6 +587,7 @@ void Application::cleanup()
delete m_fileLogger; delete m_fileLogger;
Logger::freeInstance(); Logger::freeInstance();
IconProvider::freeInstance(); IconProvider::freeInstance();
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
typedef BOOL (WINAPI *PSHUTDOWNBRDESTROY)(HWND); typedef BOOL (WINAPI *PSHUTDOWNBRDESTROY)(HWND);
@ -604,9 +597,10 @@ void Application::cleanup()
shutdownBRDestroy((HWND)m_window->effectiveWinId()); shutdownBRDestroy((HWND)m_window->effectiveWinId());
#endif // Q_OS_WIN #endif // Q_OS_WIN
delete m_window; delete m_window;
#endif // DISABLE_GUI
if (m_shutdownAct != ShutdownDialogAction::Exit) { if (m_shutdownAct != ShutdownDialogAction::Exit) {
qDebug() << "Sending computer shutdown/suspend/hibernate signal..."; qDebug() << "Sending computer shutdown/suspend/hibernate signal...";
Utils::Misc::shutdownComputer(m_shutdownAct); Utils::Misc::shutdownComputer(m_shutdownAct);
} }
#endif
} }

View File

@ -111,10 +111,10 @@ private slots:
private: private:
bool m_running; bool m_running;
ShutdownDialogAction m_shutdownAct;
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
QPointer<MainWindow> m_window; QPointer<MainWindow> m_window;
ShutdownDialogAction m_shutdownAct;
#endif #endif
#ifndef DISABLE_WEBUI #ifndef DISABLE_WEBUI

View File

@ -91,7 +91,6 @@ static struct { const char *source; const char *comment; } units[] = {
QT_TRANSLATE_NOOP3("misc", "EiB", "exbibytes (1024 pebibytes)") QT_TRANSLATE_NOOP3("misc", "EiB", "exbibytes (1024 pebibytes)")
}; };
#ifndef DISABLE_GUI
void Utils::Misc::shutdownComputer(const ShutdownDialogAction &action) void Utils::Misc::shutdownComputer(const ShutdownDialogAction &action)
{ {
#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)
@ -216,7 +215,6 @@ void Utils::Misc::shutdownComputer(const ShutdownDialogAction &action)
(PTOKEN_PRIVILEGES) NULL, 0); (PTOKEN_PRIVILEGES) NULL, 0);
#endif #endif
} }
#endif // DISABLE_GUI
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
// Get screen center // Get screen center

View File

@ -67,8 +67,9 @@ namespace Utils
QString parseHtmlLinks(const QString &raw_text); QString parseHtmlLinks(const QString &raw_text);
bool isUrl(const QString &s); bool isUrl(const QString &s);
#ifndef DISABLE_GUI
void shutdownComputer(const ShutdownDialogAction &action); void shutdownComputer(const ShutdownDialogAction &action);
#ifndef DISABLE_GUI
// Get screen center // Get screen center
QPoint screenCenter(QWidget *win); QPoint screenCenter(QWidget *win);
QSize smallIconSize(); QSize smallIconSize();