Browse Source

FEATURE: Added Auto-Shutdown on downloads completion feature (Linux Only for now)

adaptive-webui-19844
Christophe Dumez 14 years ago
parent
commit
df677789d2
  1. 1
      Changelog
  2. 6
      src/GUI.cpp
  3. 1
      src/GUI.h
  4. 24
      src/bittorrent.cpp
  5. 1
      src/bittorrent.h
  6. 14
      src/misc.cpp
  7. 2
      src/misc.h
  8. 11
      src/preferences.h
  9. 3
      src/src.pro
  10. 12
      src/ui/mainwindow.ui

1
Changelog

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
* Unreleased - Christophe Dumez <chris@qbittorrent.org> - v2.4.0
- FEATURE: Added actions to "Move to top/bottom" of priority queue
- FEATURE: Added Auto-Shutdown on downloads completion feature
* Tue Jul 27 2010 - Christophe Dumez <chris@qbittorrent.org> - v2.3.0
- FEATURE: Simplified torrent root folder renaming/truncating (< v2.3.0 is no longer forward compatible)

6
src/GUI.cpp

@ -187,6 +187,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), for @@ -187,6 +187,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), for
actionSearch_engine->setChecked(Preferences::isSearchEnabled());
displaySearchTab(actionSearch_engine->isChecked());
displayRSSTab(actionRSS_Reader->isChecked());
actionShutdown_when_downloads_complete->setChecked(Preferences::shutdownWhenDownloadsComplete());
show();
@ -1066,6 +1067,11 @@ void GUI::on_actionTop_tool_bar_triggered() { @@ -1066,6 +1067,11 @@ void GUI::on_actionTop_tool_bar_triggered() {
Preferences::setToolbarDisplayed(is_visible);
}
void GUI::on_actionShutdown_when_downloads_complete_triggered() {
bool is_checked = static_cast<QAction*>(sender())->isChecked();
Preferences::setShutdownWhenDownloadsComplete(is_checked);
}
void GUI::on_actionSpeed_in_title_bar_triggered() {
displaySpeedInTitle = static_cast<QAction*>(sender())->isChecked();
Preferences::showSpeedInTitleBar(displaySpeedInTitle);

1
src/GUI.h

@ -170,6 +170,7 @@ private slots: @@ -170,6 +170,7 @@ private slots:
void on_actionRSS_Reader_triggered();
void on_actionSpeed_in_title_bar_triggered();
void on_actionTop_tool_bar_triggered();
void on_actionShutdown_when_downloads_complete_triggered();
};
#endif

24
src/bittorrent.cpp

@ -720,6 +720,17 @@ bool Bittorrent::hasActiveTorrents() const { @@ -720,6 +720,17 @@ bool Bittorrent::hasActiveTorrents() const {
return false;
}
bool Bittorrent::hasDownloadingTorrents() const {
std::vector<torrent_handle> torrents = getTorrents();
std::vector<torrent_handle>::iterator torrentIT;
for(torrentIT = torrents.begin(); torrentIT != torrents.end(); torrentIT++) {
const QTorrentHandle h(*torrentIT);
if(h.is_valid() && (h.state() == torrent_status::downloading || h.state() == torrent_status::downloading_metadata))
return true;
}
return false;
}
void Bittorrent::banIP(QString ip) {
FilterParserThread::processFilterList(s, QStringList(ip));
Preferences::banIP(ip);
@ -2013,6 +2024,19 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { @@ -2013,6 +2024,19 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
TorrentPersistentData::saveSeedStatus(h);
}
qDebug("Received finished alert for %s", qPrintable(h.name()));
if(!was_already_seeded) {
// Auto-Shutdown
if(Preferences::shutdownWhenDownloadsComplete() && !hasDownloadingTorrents()) {
qDebug("Preparing for auto-shutdown because all downloads are complete!");
#if LIBTORRENT_VERSION_MINOR < 15
saveDHTEntry();
#endif
saveSessionState();
saveFastResumeData();
delete s;
misc::shutdownComputer();
}
}
}
}
else if (save_resume_data_alert* p = dynamic_cast<save_resume_data_alert*>(a.get())) {

1
src/bittorrent.h

@ -108,6 +108,7 @@ public: @@ -108,6 +108,7 @@ public:
session* getSession() const;
QHash<QString, TrackerInfos> getTrackersInfo(QString hash) const;
bool hasActiveTorrents() const;
bool hasDownloadingTorrents() const;
bool isQueueingEnabled() const;
int getMaximumActiveDownloads() const;
int getMaximumActiveTorrents() const;

14
src/misc.cpp

@ -67,6 +67,11 @@ const int UNLEN = 256; @@ -67,6 +67,11 @@ const int UNLEN = 256;
#include <winbase.h>
#endif
#ifdef Q_WS_X11
#include <QDBusInterface>
#include <QDBusMessage>
#endif
QString misc::QDesktopServicesDataLocation() {
#ifdef Q_WS_WIN
LPWSTR path=new WCHAR[256];
@ -184,6 +189,15 @@ long long misc::freeDiskSpaceOnPath(QString path) { @@ -184,6 +189,15 @@ long long misc::freeDiskSpaceOnPath(QString path) {
#endif
}
void misc::shutdownComputer() {
#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());
computer.call("Shutdown");
#endif
}
QString misc::truncateRootFolder(boost::intrusive_ptr<torrent_info> t) {
if(t->num_files() == 1) {
// Single file torrent

2
src/misc.h

@ -91,6 +91,8 @@ public: @@ -91,6 +91,8 @@ public:
return x;
}
static void shutdownComputer();
static bool safeRemove(QString file_path) {
QFile MyFile(file_path);
if(!MyFile.exists()) return true;

11
src/preferences.h

@ -851,6 +851,17 @@ public: @@ -851,6 +851,17 @@ public:
}
// Advanced settings
static bool shutdownWhenDownloadsComplete() {
QIniSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Downloads/AutoShutDownOnCompletion"), false).toBool();
}
static void setShutdownWhenDownloadsComplete(bool shutdown) {
QIniSettings settings("qBittorrent", "qBittorrent");
settings.setValue(QString::fromUtf8("Preferences/Downloads/AutoShutDownOnCompletion"), shutdown);
}
static uint diskCacheSize() {
QIniSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Downloads/DiskCache"), 16).toUInt();

3
src/src.pro

@ -160,6 +160,9 @@ unix { @@ -160,6 +160,9 @@ unix {
QT += network
!contains(DEFINES, DISABLE_GUI):QT += xml
unix {
QT += dbus
}
DEFINES += QT_NO_CAST_TO_ASCII

12
src/ui/mainwindow.ui

@ -29,7 +29,7 @@ @@ -29,7 +29,7 @@
<x>0</x>
<y>0</y>
<width>914</width>
<height>25</height>
<height>23</height>
</rect>
</property>
<widget class="QMenu" name="menu_Edit">
@ -64,6 +64,8 @@ @@ -64,6 +64,8 @@
<addaction name="actionCreate_torrent"/>
<addaction name="separator"/>
<addaction name="actionOptions"/>
<addaction name="separator"/>
<addaction name="actionShutdown_when_downloads_complete"/>
</widget>
<widget class="QMenu" name="menu_File">
<property name="title">
@ -320,6 +322,14 @@ @@ -320,6 +322,14 @@
<string>Search &amp;engine</string>
</property>
</action>
<action name="actionShutdown_when_downloads_complete">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Shutdown when downloads complete</string>
</property>
</action>
</widget>
<resources>
<include location="../icons.qrc"/>

Loading…
Cancel
Save