From 5a82aee76b3480c19e9d9699545f268cd3c6ee9f Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Tue, 22 Jun 2010 17:06:11 +0000 Subject: [PATCH] FEATURE: Torrents can be automatically paused once they reach a given ratio --- Changelog | 1 + src/bittorrent.cpp | 24 +++-- src/bittorrent.h | 5 +- src/options_imp.cpp | 26 +++-- src/options_imp.h | 4 +- src/preferences.h | 18 +++- src/ui/options.ui | 234 +++++++++++++++++++++++++------------------- 7 files changed, 187 insertions(+), 125 deletions(-) diff --git a/Changelog b/Changelog index 1a0d857c7..d5b4bcbc9 100644 --- a/Changelog +++ b/Changelog @@ -11,6 +11,7 @@ - FEATURE: Added filter for paused/error torrents - FEATURE: Add Check/Uncheck all feature in Web UI - FEATURE: Search engine can now be disabled + - FEATURE: Torrents can be automatically paused once they reach a given ratio - BUGFIX: Hide seeding torrents files priorities in Web UI - BUGFIX: The user can disable permanently recursive torrent download - COSMETIC: Display peers country name in tooltip diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 3c1a2dc54..6a2382faa 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -210,8 +210,8 @@ ScanFoldersModel* Bittorrent::getScanFoldersModel() const { return m_scanFolders; } -void Bittorrent::deleteBigRatios() { - if(ratio_limit == -1) return; +void Bittorrent::processBigRatios() { + if(ratio_limit <= 0) return; std::vector torrents = getTorrents(); std::vector::iterator torrentIT; for(torrentIT = torrents.begin(); torrentIT != torrents.end(); torrentIT++) { @@ -222,7 +222,14 @@ void Bittorrent::deleteBigRatios() { const float ratio = getRealRatio(hash); if(ratio <= MAX_RATIO && ratio > ratio_limit) { addConsoleMessage(tr("%1 reached the maximum ratio you set.").arg(h.name())); - deleteTorrent(hash); + if(high_ratio_action == REMOVE_ACTION) { + addConsoleMessage(tr("Removing torrent %1...").arg(h.name())); + deleteTorrent(hash); + } else { + // Pause it + addConsoleMessage(tr("Pausing torrent %1...").arg(h.name())); + pauseTorrent(hash); + } //emit torrent_ratio_deleted(fileName); } } @@ -522,7 +529,8 @@ void Bittorrent::configureSession() { } applyEncryptionSettings(encryptionSettings); // * Maximum ratio - setDeleteRatio(Preferences::getDeleteRatio()); + high_ratio_action = Preferences::getMaxRatioAction(); + setMaxRatio(Preferences::getMaxRatio()); // Ip Filter FilterParserThread::processFilterList(s, Preferences::bannedIPs()); if(Preferences::isFilteringEnabled()) { @@ -1763,12 +1771,12 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { // Torrents will a ratio superior to the given value will // be automatically deleted - void Bittorrent::setDeleteRatio(float ratio) { - if(ratio != -1 && ratio < 1.) ratio = 1.; + void Bittorrent::setMaxRatio(float ratio) { + if(ratio <= 0) ratio = -1.; if(ratio_limit == -1 && ratio != -1) { Q_ASSERT(!BigRatioTimer); BigRatioTimer = new QTimer(this); - connect(BigRatioTimer, SIGNAL(timeout()), this, SLOT(deleteBigRatios())); + connect(BigRatioTimer, SIGNAL(timeout()), this, SLOT(processBigRatios())); BigRatioTimer->start(5000); } else { if(ratio_limit != -1 && ratio == -1) { @@ -1778,7 +1786,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { if(ratio_limit != ratio) { ratio_limit = ratio; qDebug("* Set deleteRatio to %.1f", ratio_limit); - deleteBigRatios(); + processBigRatios(); } } diff --git a/src/bittorrent.h b/src/bittorrent.h index d9108dd93..190c10a85 100644 --- a/src/bittorrent.h +++ b/src/bittorrent.h @@ -153,7 +153,7 @@ public slots: void setMaxUploadsPerTorrent(int max); void setDownloadRateLimit(long rate); void setUploadRateLimit(long rate); - void setDeleteRatio(float ratio); + void setMaxRatio(float ratio); void setDHTPort(int dht_port); void setPeerProxySettings(const proxy_settings &proxySettings); void setHTTPProxySettings(const proxy_settings &proxySettings); @@ -194,7 +194,7 @@ protected: protected slots: void addTorrentsFromScanFolder(QStringList&); void readAlerts(); - void deleteBigRatios(); + void processBigRatios(); void takeETASamples(); void exportTorrentFiles(QString path); void saveTempFastResumeData(); @@ -240,6 +240,7 @@ private: bool preAllocateAll; bool addInPause; float ratio_limit; + int high_ratio_action; bool UPnPEnabled; bool NATPMPEnabled; bool LSDEnabled; diff --git a/src/options_imp.cpp b/src/options_imp.cpp index 78a1947fc..f7da11867 100644 --- a/src/options_imp.cpp +++ b/src/options_imp.cpp @@ -168,7 +168,7 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){ connect(checkMaxConnecs, SIGNAL(toggled(bool)), this, SLOT(enableMaxConnecsLimit(bool))); connect(checkMaxConnecsPerTorrent, SIGNAL(toggled(bool)), this, SLOT(enableMaxConnecsLimitPerTorrent(bool))); connect(checkMaxUploadsPerTorrent, SIGNAL(toggled(bool)), this, SLOT(enableMaxUploadsLimitPerTorrent(bool))); - connect(checkRatioRemove, SIGNAL(toggled(bool)), this, SLOT(enableDeleteRatio(bool))); + connect(checkMaxRatio, SIGNAL(toggled(bool)), this, SLOT(enableMaxRatio(bool))); connect(comboPeerID, SIGNAL(currentIndexChanged(int)), this, SLOT(enableSpoofingSettings(int))); // Proxy tab connect(comboProxyType_http, SIGNAL(currentIndexChanged(int)),this, SLOT(enableHTTPProxy(int))); @@ -230,8 +230,9 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){ connect(client_version, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton())); connect(client_build, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton())); connect(comboEncryption, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton())); - connect(checkRatioRemove, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); + connect(checkMaxRatio, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); connect(spinMaxRatio, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton())); + connect(comboRatioLimitAct, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton())); // Proxy tab connect(comboProxyType_http, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton())); connect(textProxyIP_http, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton())); @@ -465,7 +466,8 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){ Preferences::setPeerID("qB"); } settings.setValue(QString::fromUtf8("Encryption"), getEncryptionSetting()); - settings.setValue(QString::fromUtf8("MaxRatio"), getDeleteRatio()); + Preferences::setMaxRatio(getMaxRatio()); + Preferences::setMaxRatioAction(comboRatioLimitAct->currentIndex()); // End Bittorrent preferences settings.endGroup(); // Misc preferences @@ -780,17 +782,20 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){ } comboEncryption->setCurrentIndex(Preferences::getEncryptionSetting()); // Ratio limit - floatValue = Preferences::getDeleteRatio(); - if(floatValue >= 1.) { + floatValue = Preferences::getMaxRatio(); + if(floatValue > 0.) { // Enable - checkRatioRemove->setChecked(true); + checkMaxRatio->setChecked(true); spinMaxRatio->setEnabled(true); + comboRatioLimitAct->setEnabled(true); spinMaxRatio->setValue(floatValue); } else { // Disable - checkRatioRemove->setChecked(false); + checkMaxRatio->setChecked(false); spinMaxRatio->setEnabled(false); + comboRatioLimitAct->setEnabled(false); } + comboRatioLimitAct->setCurrentIndex(Preferences::getMaxRatioAction()); // End Bittorrent preferences // Misc preferences // * IP Filter @@ -957,8 +962,8 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){ } // Return Share ratio - float options_imp::getDeleteRatio() const{ - if(checkRatioRemove->isChecked()){ + float options_imp::getMaxRatio() const{ + if(checkMaxRatio->isChecked()){ return spinMaxRatio->value(); } return -1; @@ -1091,8 +1096,9 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){ applyButton->setEnabled(true); } - void options_imp::enableDeleteRatio(bool checked){ + void options_imp::enableMaxRatio(bool checked){ spinMaxRatio->setEnabled(checked); + comboRatioLimitAct->setEnabled(checked); } void options_imp::enablePeerProxy(int index){ diff --git a/src/options_imp.h b/src/options_imp.h index 62c7473cd..ee7205332 100644 --- a/src/options_imp.h +++ b/src/options_imp.h @@ -96,7 +96,7 @@ protected: int getDHTPort() const; bool isLSDEnabled() const; int getEncryptionSetting() const; - float getDeleteRatio() const; + float getMaxRatio() const; // Proxy options QString getHTTPProxyIp() const; unsigned short getHTTPProxyPort() const; @@ -135,7 +135,7 @@ protected slots: void enableMaxConnecsLimit(bool checked); void enableMaxConnecsLimitPerTorrent(bool checked); void enableMaxUploadsLimitPerTorrent(bool checked); - void enableDeleteRatio(bool checked); + void enableMaxRatio(bool checked); void enableSpoofingSettings(int index); void setStyle(QString style); void on_buttonBox_accepted(); diff --git a/src/preferences.h b/src/preferences.h index 31c94c28e..735f166f5 100644 --- a/src/preferences.h +++ b/src/preferences.h @@ -53,6 +53,7 @@ #define QBT_REALM "Web UI Access" enum scheduler_days { EVERY_DAY, WEEK_DAYS, WEEK_ENDS, MON, TUE, WED, THU, FRI, SAT, SUN }; +enum maxRatioAction {PAUSE_ACTION, REMOVE_ACTION}; class Preferences { public: @@ -693,11 +694,26 @@ public: settings.setValue(QString::fromUtf8("Preferences/Bittorrent/Encryption"), val); } - static float getDeleteRatio() { + static float getMaxRatio() { QSettings settings("qBittorrent", "qBittorrent"); return settings.value(QString::fromUtf8("Preferences/Bittorrent/MaxRatio"), -1).toDouble(); } + static void setMaxRatio(float ratio) { + QSettings settings("qBittorrent", "qBittorrent"); + settings.setValue(QString::fromUtf8("Preferences/Bittorrent/MaxRatio"), ratio); + } + + static void setMaxRatioAction(int act) { + QSettings settings("qBittorrent", "qBittorrent"); + settings.setValue(QString::fromUtf8("Preferences/Bittorrent/MaxRatioAction"), act); + } + + static int getMaxRatioAction() { + QSettings settings("qBittorrent", "qBittorrent"); + return settings.value(QString::fromUtf8("Preferences/Bittorrent/MaxRatioAction"), PAUSE_ACTION).toInt(); + } + // IP Filter static bool isFilteringEnabled() { QSettings settings("qBittorrent", "qBittorrent"); diff --git a/src/ui/options.ui b/src/ui/options.ui index 1fd98f263..b1ae577aa 100644 --- a/src/ui/options.ui +++ b/src/ui/options.ui @@ -516,7 +516,7 @@ 0 0 506 - 630 + 504 @@ -555,97 +555,6 @@ - - - - Torrent queueing - - - true - - - false - - - - 0 - - - - - Maximum active downloads: - - - - - - - -1 - - - 999 - - - 3 - - - - - - - Maximum active uploads: - - - - - - - -1 - - - 999 - - - 3 - - - - - - - Maximum active torrents: - - - - - - - -1 - - - 999 - - - 5 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - @@ -1650,12 +1559,12 @@ QGroupBox { 0 - 0 - 524 - 406 + -80 + 539 + 484 - + @@ -1828,6 +1737,9 @@ QGroupBox { Client whitelisting workaround + + 0 + @@ -1935,18 +1847,112 @@ QGroupBox { + + + + Torrent queueing + + + true + + + false + + + + 0 + + + + + Maximum active downloads: + + + + + + + -1 + + + 999 + + + 3 + + + + + + + Maximum active uploads: + + + + + + + -1 + + + 999 + + + 3 + + + + + + + Maximum active torrents: + + + + + + + -1 + + + 999 + + + 5 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + - Share ratio settings + Share ratio limiting + + 0 + - + - Remove finished torrents when their ratio reaches: + Seed torrents until their ratio reaches @@ -1967,10 +1973,10 @@ QGroupBox { 1 - 1.000000000000000 + 0.100000000000000 - 10.000000000000000 + 20.000000000000000 0.100000000000000 @@ -1980,6 +1986,30 @@ QGroupBox { + + + + then + + + + + + + false + + + + Pause them + + + + + Remove them + + + + @@ -2670,7 +2700,7 @@ QGroupBox { checkNATPMP checkLSD comboEncryption - checkRatioRemove + checkMaxRatio spinMaxRatio spinWebUiPort textWebUiUsername