|
|
@ -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,40 +281,35 @@ 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
|
|
|
|
|
|
|
|
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())) { |
|
|
|
#ifndef DISABLE_GUI |
|
|
|
if (!ShutdownConfirmDlg::askForConfirmation(action)) |
|
|
|
// ask confirm
|
|
|
|
return; |
|
|
|
if ((action == ShutdownDialogAction::Exit) && (pref->dontConfirmAutoExit())) { |
|
|
|
|
|
|
|
// do nothing & skip confirm
|
|
|
|
} |
|
|
|
} |
|
|
|
else { //exit and shutdown
|
|
|
|
else { |
|
|
|
if (!ShutdownConfirmDlg::askForConfirmation(action)) |
|
|
|
if (!ShutdownConfirmDlg::askForConfirmation(action)) return; |
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#endif // DISABLE_GUI
|
|
|
|
|
|
|
|
|
|
|
|
// 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,10 +318,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
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool Application::sendParams(const QStringList ¶ms) |
|
|
|
bool Application::sendParams(const QStringList ¶ms) |
|
|
@ -371,7 +363,7 @@ int Application::exec(const QStringList ¶ms) |
|
|
|
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|