From 862d24ac48486c5078d5d220f2dbd372f4889990 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sun, 9 Sep 2007 09:09:24 +0000 Subject: [PATCH] - FEATURE: Added an option to automatically delete torrents when they reach a given ratio (>= 1.0) --- Changelog | 1 + TODO | 2 ++ src/GUI.cpp | 35 ++++++++++++++++++++++++----------- src/GUI.h | 1 + src/bittorrent.cpp | 34 +++++++++++++++++++++++++++++++++- src/bittorrent.h | 5 ++++- 6 files changed, 65 insertions(+), 13 deletions(-) diff --git a/Changelog b/Changelog index 4108f857a..4b64a92ab 100644 --- a/Changelog +++ b/Changelog @@ -37,6 +37,7 @@ - FEATURE: Added an option to add torrents in paused state - FEATURE: Added an option to set the max number of connections per torrent - FEATURE: Added an option to set the max number of uploads per torrent + - FEATURE: Added an option to automatically delete torrents when they reach a given ratio (>= 1.0) - I18N: Added Hungarian translation - I18N: Added Brazilian translation - BUGFIX: Progress of paused torrents is now correct on restart diff --git a/TODO b/TODO index a77134dfc..d20c79525 100644 --- a/TODO +++ b/TODO @@ -63,6 +63,7 @@ * beta 7 - Add "Mark all as read" feature for RSS - update doc for plugins (and add screenies) + - update doc for options - Redesign options (fully) - Review torrent content selection * check the one in ktorrent @@ -102,6 +103,7 @@ beta6->beta7 changelog: - FEATURE: Allow to disable UPnP/NAT-PMP/LSD - FEATURE: Added an option to set the max number of connections per torrent - FEATURE: Added an option to set the max number of uploads per torrent +- FEATURE: Added an option to automatically delete torrents when they reach a given ratio (>= 1.0) - BUGFIX: In torrent content, it is now easier to filter all torrents using right click menu - BUGFIX: Updated man page / README / INSTALL - BUGFIX: Paused torrents could be displayed as connected for a sec after checking diff --git a/src/GUI.cpp b/src/GUI.cpp index 02efd434d..62e7c500a 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -112,6 +112,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), for connect(BTSession, SIGNAL(scanDirFoundTorrents(const QStringList&)), this, SLOT(processScannedFiles(const QStringList&))); connect(BTSession, SIGNAL(newDownloadedTorrent(QString, QString)), this, SLOT(processDownloadedFiles(QString, QString))); connect(BTSession, SIGNAL(downloadFromUrlFailure(QString, QString)), this, SLOT(handleDownloadFromUrlFailure(QString, QString))); + connect(BTSession, SIGNAL(torrent_deleted(QString, QString, bool)), this, SLOT(deleteTorrent(QString, QString, bool))); qDebug("create tabWidget"); tabs = new QTabWidget(); // Download torrents tab @@ -661,6 +662,16 @@ void GUI::on_actionDelete_Permanently_triggered() { } } +void GUI::deleteTorrent(QString hash, QString fileName, bool finished) { + if(finished) { + finishedTorrentTab->deleteTorrent(hash); + } else { + downloadingTorrentTab->deleteTorrent(hash); + } + // Update info bar + downloadingTorrentTab->setInfoBar(tr("'%1' was removed because its ratio reached the maximum value you set.", "%1 is a file name").arg(fileName)); +} + // delete selected items in the list void GUI::on_actionDelete_triggered() { QStringList hashes; @@ -778,8 +789,16 @@ void GUI::processDownloadedFiles(QString path, QString url) { void GUI::configureSession(bool deleteOptions) { qDebug("Configuring session"); // Downloads + // Save path + BTSession->setDefaultSavePath(options->getSavePath()); BTSession->preAllocateAllFiles(options->preAllocateAllFiles()); BTSession->startTorrentsInPause(options->addTorrentsInPause()); + // * Scan dir + if(options->getScanDir().isNull()) { + BTSession->disableDirectoryScanning(); + }else{ + BTSession->enableDirectoryScanning(options->getScanDir()); + } // Connection // * Ports binding unsigned short old_listenPort = BTSession->getListenPort(); @@ -906,12 +925,11 @@ void GUI::configureSession(bool deleteOptions) { downloadingTorrentTab->setInfoBar(tr("Encryption support [OFF]"), QString::fromUtf8("blue")); } BTSession->applyEncryptionSettings(encryptionSettings); - // IP Filter - // Configure session regarding options - BTSession->setDefaultSavePath(options->getSavePath()); - // Apply ratio (0 if disabled) + // * Desired ratio BTSession->setGlobalRatio(options->getDesiredRatio()); - // Apply filtering settings + // * Maximum ratio + BTSession->setDeleteRatio(options->getDeleteRatio()); + // Ip Filter if(options->isFilteringEnabled()) { BTSession->enableIPFilter(options->getFilter()); downloadingTorrentTab->setBottomTabEnabled(1, true); @@ -919,12 +937,7 @@ void GUI::configureSession(bool deleteOptions) { BTSession->disableIPFilter(); downloadingTorrentTab->setBottomTabEnabled(1, false); } - // Scan dir stuff - if(options->getScanDir().isNull()) { - BTSession->disableDirectoryScanning(); - }else{ - BTSession->enableDirectoryScanning(options->getScanDir()); - } + // Clean up if(deleteOptions) { delete options; } diff --git a/src/GUI.h b/src/GUI.h index 24548fe06..d50be13bb 100644 --- a/src/GUI.h +++ b/src/GUI.h @@ -132,6 +132,7 @@ class GUI : public QMainWindow, private Ui::MainWindow{ void processScannedFiles(const QStringList& params); void processDownloadedFiles(QString path, QString url); void downloadFromURLList(const QStringList& urls); + void deleteTorrent(QString hash, QString fileName, bool finished); void finishedTorrent(QTorrentHandle& h) const; void torrentChecked(QString hash) const; void updateLists(); diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 4a9b9359d..b95818d54 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -44,7 +44,7 @@ #define MAX_TRACKER_ERRORS 2 // Main constructor -bittorrent::bittorrent() : timerScan(0), DHTEnabled(false), preAllocateAll(false), addInPause(false), maxConnecsPerTorrent(500), maxUploadsPerTorrent(4) { +bittorrent::bittorrent() : timerScan(0), DHTEnabled(false), preAllocateAll(false), addInPause(false), maxConnecsPerTorrent(500), maxUploadsPerTorrent(4), max_ratio(-1) { // To avoid some exceptions fs::path::default_name_check(fs::no_check); // Creating bittorrent session @@ -100,6 +100,26 @@ void bittorrent::preAllocateAllFiles(bool b) { } } +void bittorrent::deleteBigRatios() { + if(max_ratio == -1) return; + std::vector handles = s->get_torrents(); + unsigned int nbHandles = handles.size(); + for(unsigned int i=0; i max_ratio) { + bool finished = finishedTorrents.contains(hash); + QString fileName = h.name(); + deleteTorrent(hash); + emit torrent_deleted(hash, fileName, finished); + } + } +} + void bittorrent::setDownloadLimit(QString hash, long val) { QTorrentHandle h = getTorrentHandle(hash); if(h.is_valid()) @@ -149,6 +169,9 @@ void bittorrent::updateETAs() { } } } + // Delete big ratios + if(max_ratio != -1) + deleteBigRatios(); } long bittorrent::getETA(QString hash) const{ @@ -929,6 +952,7 @@ void bittorrent::setUploadRateLimit(long rate) { // libtorrent allow to adjust ratio for each torrent // This function will apply to same ratio to all torrents void bittorrent::setGlobalRatio(float ratio) { + if(ratio != -1 && ratio < 1.) ratio = 1.; std::vector handles = s->get_torrents(); unsigned int nbHandles = handles.size(); for(unsigned int i=0; i