mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-30 16:34:16 +00:00
FEATURE: Added Auto-Shutdown on downloads completion feature (Linux Only for now)
This commit is contained in:
parent
0af44eadb6
commit
df677789d2
@ -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)
|
||||
|
@ -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() {
|
||||
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);
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
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())) {
|
||||
|
@ -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
14
src/misc.cpp
@ -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) {
|
||||
#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
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
@ -160,6 +160,9 @@ unix {
|
||||
|
||||
QT += network
|
||||
!contains(DEFINES, DISABLE_GUI):QT += xml
|
||||
unix {
|
||||
QT += dbus
|
||||
}
|
||||
|
||||
DEFINES += QT_NO_CAST_TO_ASCII
|
||||
|
||||
|
@ -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 @@
|
||||
<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 @@
|
||||
<string>Search &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…
x
Reference in New Issue
Block a user