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

This commit is contained in:
Christophe Dumez
2010-08-16 17:35:32 +00:00
parent 0af44eadb6
commit df677789d2
10 changed files with 74 additions and 1 deletions

View File

@@ -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())) {