Browse Source

FEATURE: Added auto-suspend upon downloads completion feature

adaptive-webui-19844
Christophe Dumez 14 years ago
parent
commit
1b08c087c0
  1. 1
      Changelog
  2. 44
      src/mainwindow.cpp
  3. 5
      src/mainwindow.h
  4. 63
      src/mainwindow.ui
  5. 33
      src/misc.cpp
  6. 2
      src/misc.h
  7. 8
      src/preferences/preferences.h
  8. 15
      src/qtlibtorrent/qbtsession.cpp
  9. 1
      winconf.pri

1
Changelog

@ -10,6 +10,7 @@
- FEATURE: Search engine results can now be opened in a Web browser - FEATURE: Search engine results can now be opened in a Web browser
- FEATURE: Added a search engine plugin to extratorrent.com - FEATURE: Added a search engine plugin to extratorrent.com
- FEATURE: Added a search engine plugin for kickasstorrents.com - FEATURE: Added a search engine plugin for kickasstorrents.com
- FEATURE: Added auto-suspend upon downloads completion feature
- COSMETIC: Same deletion confirmation dialog in the GUI and Web UI - COSMETIC: Same deletion confirmation dialog in the GUI and Web UI
- COSMETIC: Simplified the top toolbar - COSMETIC: Simplified the top toolbar
- COSMETIC: Display execution log as a tab instead of a modal window - COSMETIC: Display execution log as a tab instead of a modal window

44
src/mainwindow.cpp

@ -124,6 +124,7 @@ MainWindow::MainWindow(QWidget *parent, QStringList torrentCmdLine) : QMainWindo
actionStart->setIcon(misc::getIcon("media-playback-start")); actionStart->setIcon(misc::getIcon("media-playback-start"));
actionStart_All->setIcon(misc::getIcon("media-playback-start")); actionStart_All->setIcon(misc::getIcon("media-playback-start"));
action_Import_Torrent->setIcon(misc::getIcon("document-import")); action_Import_Torrent->setIcon(misc::getIcon("document-import"));
menuAuto_Shutdown_on_downloads_completion->setIcon(misc::getIcon("application-exit"));
QMenu *startAllMenu = new QMenu(this); QMenu *startAllMenu = new QMenu(this);
startAllMenu->addAction(actionStart_All); startAllMenu->addAction(actionStart_All);
@ -220,8 +221,19 @@ MainWindow::MainWindow(QWidget *parent, QStringList torrentCmdLine) : QMainWindo
displaySearchTab(actionSearch_engine->isChecked()); displaySearchTab(actionSearch_engine->isChecked());
displayRSSTab(actionRSS_Reader->isChecked()); displayRSSTab(actionRSS_Reader->isChecked());
on_actionExecution_Logs_triggered(actionExecution_Logs->isChecked()); on_actionExecution_Logs_triggered(actionExecution_Logs->isChecked());
actionShutdown_when_downloads_complete->setChecked(pref.shutdownWhenDownloadsComplete());
actionShutdown_qBittorrent_when_downloads_complete->setChecked(pref.shutdownqBTWhenDownloadsComplete()); // Auto shutdown actions
QActionGroup * autoShutdownGroup = new QActionGroup(this);
autoShutdownGroup->setExclusive(true);
autoShutdownGroup->addAction(actionAutoShutdown_Disabled);
autoShutdownGroup->addAction(actionAutoExit_qBittorrent);
autoShutdownGroup->addAction(actionAutoShutdown_system);
autoShutdownGroup->addAction(actionAutoSuspend_system);
actionAutoExit_qBittorrent->setChecked(pref.shutdownqBTWhenDownloadsComplete());
actionAutoShutdown_system->setChecked(pref.shutdownWhenDownloadsComplete());
actionAutoSuspend_system->setChecked(pref.suspendWhenDownloadsComplete());
if(!autoShutdownGroup->checkedAction())
actionAutoShutdown_Disabled->setChecked(true);
show(); show();
@ -1179,16 +1191,6 @@ void MainWindow::on_actionTop_tool_bar_triggered() {
Preferences().setToolbarDisplayed(is_visible); Preferences().setToolbarDisplayed(is_visible);
} }
void MainWindow::on_actionShutdown_when_downloads_complete_triggered() {
bool is_checked = static_cast<QAction*>(sender())->isChecked();
Preferences().setShutdownWhenDownloadsComplete(is_checked);
}
void MainWindow::on_actionShutdown_qBittorrent_when_downloads_complete_triggered() {
bool is_checked = static_cast<QAction*>(sender())->isChecked();
Preferences().setShutdownqBTWhenDownloadsComplete(is_checked);
}
void MainWindow::on_actionSpeed_in_title_bar_triggered() { void MainWindow::on_actionSpeed_in_title_bar_triggered() {
displaySpeedInTitle = static_cast<QAction*>(sender())->isChecked(); displaySpeedInTitle = static_cast<QAction*>(sender())->isChecked();
Preferences().showSpeedInTitleBar(displaySpeedInTitle); Preferences().showSpeedInTitleBar(displaySpeedInTitle);
@ -1279,3 +1281,21 @@ void MainWindow::on_actionExecution_Logs_triggered(bool checked)
} }
Preferences().setExecutionLogEnabled(checked); Preferences().setExecutionLogEnabled(checked);
} }
void MainWindow::on_actionAutoExit_qBittorrent_toggled(bool enabled)
{
qDebug() << Q_FUNC_INFO << enabled;
Preferences().setShutdownqBTWhenDownloadsComplete(enabled);
}
void MainWindow::on_actionAutoSuspend_system_toggled(bool enabled)
{
qDebug() << Q_FUNC_INFO << enabled;
Preferences().setSuspendWhenDownloadsComplete(enabled);
}
void MainWindow::on_actionAutoShutdown_system_toggled(bool enabled)
{
qDebug() << Q_FUNC_INFO << enabled;
Preferences().setShutdownWhenDownloadsComplete(enabled);
}

5
src/mainwindow.h

@ -187,11 +187,12 @@ private slots:
void on_actionRSS_Reader_triggered(); void on_actionRSS_Reader_triggered();
void on_actionSpeed_in_title_bar_triggered(); void on_actionSpeed_in_title_bar_triggered();
void on_actionTop_tool_bar_triggered(); void on_actionTop_tool_bar_triggered();
void on_actionShutdown_when_downloads_complete_triggered();
void on_actionShutdown_qBittorrent_when_downloads_complete_triggered();
void on_action_Import_Torrent_triggered(); void on_action_Import_Torrent_triggered();
void on_actionDonate_money_triggered(); void on_actionDonate_money_triggered();
void on_actionExecution_Logs_triggered(bool checked); void on_actionExecution_Logs_triggered(bool checked);
void on_actionAutoExit_qBittorrent_toggled(bool );
void on_actionAutoSuspend_system_toggled(bool );
void on_actionAutoShutdown_system_toggled(bool );
}; };
#endif #endif

63
src/mainwindow.ui

@ -59,12 +59,20 @@
<property name="title"> <property name="title">
<string>&amp;Tools</string> <string>&amp;Tools</string>
</property> </property>
<widget class="QMenu" name="menuAuto_Shutdown_on_downloads_completion">
<property name="title">
<string>Auto-Shutdown on downloads completion</string>
</property>
<addaction name="actionAutoShutdown_Disabled"/>
<addaction name="actionAutoExit_qBittorrent"/>
<addaction name="actionAutoSuspend_system"/>
<addaction name="actionAutoShutdown_system"/>
</widget>
<addaction name="actionCreate_torrent"/> <addaction name="actionCreate_torrent"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionOptions"/> <addaction name="actionOptions"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionShutdown_when_downloads_complete"/> <addaction name="menuAuto_Shutdown_on_downloads_completion"/>
<addaction name="actionShutdown_qBittorrent_when_downloads_complete"/>
</widget> </widget>
<widget class="QMenu" name="menu_File"> <widget class="QMenu" name="menu_File">
<property name="title"> <property name="title">
@ -287,17 +295,6 @@
<string>Search &amp;engine</string> <string>Search &amp;engine</string>
</property> </property>
</action> </action>
<action name="actionShutdown_when_downloads_complete">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Shutdown computer when downloads complete</string>
</property>
<property name="toolTip">
<string>Shutdown computer when downloads complete</string>
</property>
</action>
<action name="actionLock_qBittorrent"> <action name="actionLock_qBittorrent">
<property name="text"> <property name="text">
<string>Lock qBittorrent</string> <string>Lock qBittorrent</string>
@ -309,14 +306,6 @@
<string>Ctrl+L</string> <string>Ctrl+L</string>
</property> </property>
</action> </action>
<action name="actionShutdown_qBittorrent_when_downloads_complete">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Shutdown qBittorrent when downloads complete</string>
</property>
</action>
<action name="action_Import_Torrent"> <action name="action_Import_Torrent">
<property name="text"> <property name="text">
<string>Import existing torrent...</string> <string>Import existing torrent...</string>
@ -354,6 +343,38 @@
<string>Execution Log</string> <string>Execution Log</string>
</property> </property>
</action> </action>
<action name="actionAutoExit_qBittorrent">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Exit qBittorrent</string>
</property>
</action>
<action name="actionAutoSuspend_system">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Suspend system</string>
</property>
</action>
<action name="actionAutoShutdown_system">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Shutdown system</string>
</property>
</action>
<action name="actionAutoShutdown_Disabled">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Disabled</string>
</property>
</action>
</widget> </widget>
<resources> <resources>
<include location="icons.qrc"/> <include location="icons.qrc"/>

33
src/misc.cpp

@ -46,6 +46,7 @@
#ifdef Q_WS_WIN #ifdef Q_WS_WIN
#include <shlobj.h> #include <shlobj.h>
#include <windows.h> #include <windows.h>
#include <PowrProf.h>
const int UNLEN = 256; const int UNLEN = 256;
#else #else
#include <unistd.h> #include <unistd.h>
@ -194,15 +195,34 @@ long long misc::freeDiskSpaceOnPath(QString path) {
#endif #endif
} }
void misc::shutdownComputer() { void suspendComputer() {
#ifdef Q_WS_X11 #ifdef Q_WS_X11
// Use dbus to power off the system // Use dbus to power off the system
// dbus-send --print-reply --system --dest=org.freedesktop.Hal /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Shutdown // dbus-send --print-reply --system --dest=org.freedesktop.Hal /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Shutdown
QDBusInterface computer("org.freedesktop.Hal", "/org/freedesktop/Hal/devices/computer", "org.freedesktop.Hal.Device.SystemPowerManagement", QDBusConnection::systemBus()); QDBusInterface computer("org.freedesktop.Hal", "/org/freedesktop/Hal/devices/computer", "org.freedesktop.Hal.Device.SystemPowerManagement", QDBusConnection::systemBus());
computer.call("Shutdown"); computer.call("Suspend", 5);
#endif #endif
#ifdef Q_WS_MAC #ifdef Q_WS_MAC
AEEventID EventToSend = kAEShutDown;
#endif
}
void misc::shutdownComputer(bool sleep) {
#ifdef Q_WS_X11
// Use dbus to power off the system
// dbus-send --print-reply --system --dest=org.freedesktop.Hal /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Shutdown
QDBusInterface computer("org.freedesktop.Hal", "/org/freedesktop/Hal/devices/computer", "org.freedesktop.Hal.Device.SystemPowerManagement", QDBusConnection::systemBus());
if(sleep)
computer.call("Suspend", 5);
else
computer.call("Shutdown");
#endif
#ifdef Q_WS_MAC
AEEventID EventToSend;
if(sleep)
EventToSend = kAESleep;
else
EventToSend = kAEShutDown;
AEAddressDesc targetDesc; AEAddressDesc targetDesc;
static const ProcessSerialNumber kPSNOfSystemProcess = { 0, kSystemProcess }; static const ProcessSerialNumber kPSNOfSystemProcess = { 0, kSystemProcess };
AppleEvent eventReply = {typeNull, NULL}; AppleEvent eventReply = {typeNull, NULL};
@ -259,8 +279,11 @@ void misc::shutdownComputer() {
if (GetLastError() != ERROR_SUCCESS) if (GetLastError() != ERROR_SUCCESS)
return; return;
bool ret = InitiateSystemShutdownA(0, tr("qBittorrent will shutdown the computer now because all downloads are complete.").toLocal8Bit().data(), 10, true, false); bool ret;
qDebug("ret: %d", (int)ret); if(sleep)
SetSuspendState(false, false, false);
else
InitiateSystemShutdownA(0, tr("qBittorrent will shutdown the computer now because all downloads are complete.").toLocal8Bit().data(), 10, true, false);
// Disable shutdown privilege. // Disable shutdown privilege.
tkp.Privileges[0].Attributes = 0; tkp.Privileges[0].Attributes = 0;

2
src/misc.h

@ -137,7 +137,7 @@ public:
return extension; return extension;
} }
static void shutdownComputer(); static void shutdownComputer(bool sleep=false);
static bool safeRemove(QString file_path) { static bool safeRemove(QString file_path) {
QFile MyFile(file_path); QFile MyFile(file_path);

8
src/preferences/preferences.h

@ -739,6 +739,14 @@ public:
setValue(QString::fromUtf8("Preferences/Downloads/AutoShutDownOnCompletion"), shutdown); setValue(QString::fromUtf8("Preferences/Downloads/AutoShutDownOnCompletion"), shutdown);
} }
bool suspendWhenDownloadsComplete() const {
return value(QString::fromUtf8("Preferences/Downloads/AutoSuspendOnCompletion"), false).toBool();
}
void setSuspendWhenDownloadsComplete(bool suspend) {
setValue(QString::fromUtf8("Preferences/Downloads/AutoSuspendOnCompletion"), suspend);
}
bool shutdownqBTWhenDownloadsComplete() const { bool shutdownqBTWhenDownloadsComplete() const {
return value(QString::fromUtf8("Preferences/Downloads/AutoShutDownqBTOnCompletion"), false).toBool(); return value(QString::fromUtf8("Preferences/Downloads/AutoShutDownqBTOnCompletion"), false).toBool();
} }

15
src/qtlibtorrent/qbtsession.cpp

@ -1950,8 +1950,10 @@ void QBtSession::readAlerts() {
qDebug("Emitting finishedTorrent() signal"); qDebug("Emitting finishedTorrent() signal");
emit finishedTorrent(h); emit finishedTorrent(h);
qDebug("Received finished alert for %s", qPrintable(h.name())); qDebug("Received finished alert for %s", qPrintable(h.name()));
bool will_shutdown = (pref.shutdownWhenDownloadsComplete() || pref.shutdownqBTWhenDownloadsComplete()) bool will_shutdown = (pref.shutdownWhenDownloadsComplete() ||
&& !hasDownloadingTorrents(); pref.shutdownqBTWhenDownloadsComplete() ||
pref.suspendWhenDownloadsComplete())
&& !hasDownloadingTorrents();
// AutoRun program // AutoRun program
if(pref.isAutoRunEnabled()) if(pref.isAutoRunEnabled())
autoRunExternalProgram(h, will_shutdown); autoRunExternalProgram(h, will_shutdown);
@ -1960,10 +1962,13 @@ void QBtSession::readAlerts() {
sendNotificationEmail(h); sendNotificationEmail(h);
// Auto-Shutdown // Auto-Shutdown
if(will_shutdown) { if(will_shutdown) {
if(pref.shutdownWhenDownloadsComplete()) { bool suspend = pref.suspendWhenDownloadsComplete();
bool shutdown = pref.shutdownWhenDownloadsComplete();
if(suspend || shutdown) {
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);
pref.setSuspendWhenDownloadsComplete(false);
#if LIBTORRENT_VERSION_MINOR < 15 #if LIBTORRENT_VERSION_MINOR < 15
saveDHTEntry(); saveDHTEntry();
#endif #endif
@ -1971,8 +1976,8 @@ void QBtSession::readAlerts() {
saveSessionState(); saveSessionState();
qDebug("Saving fast resume data"); qDebug("Saving fast resume data");
saveFastResumeData(); saveFastResumeData();
qDebug("Sending computer shutdown signal"); qDebug("Sending computer shutdown/suspend signal");
misc::shutdownComputer(); misc::shutdownComputer(suspend);
} }
qDebug("Exiting the application"); qDebug("Exiting the application");
qApp->exit(); qApp->exit();

1
winconf.pri

@ -49,6 +49,7 @@ debug {
LIBS += advapi32.lib shell32.lib LIBS += advapi32.lib shell32.lib
LIBS += libeay32MD.lib ssleay32MD.lib LIBS += libeay32MD.lib ssleay32MD.lib
LIBS += PowrProf.lib
DEFINES += WITH_GEOIP_EMBEDDED DEFINES += WITH_GEOIP_EMBEDDED
message("On Windows, GeoIP database must be embedded.") message("On Windows, GeoIP database must be embedded.")

Loading…
Cancel
Save