Browse Source

FEATURE: Torrents can be automatically paused once they reach a given ratio

adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
5a82aee76b
  1. 1
      Changelog
  2. 22
      src/bittorrent.cpp
  3. 5
      src/bittorrent.h
  4. 26
      src/options_imp.cpp
  5. 4
      src/options_imp.h
  6. 18
      src/preferences.h
  7. 234
      src/ui/options.ui

1
Changelog

@ -11,6 +11,7 @@
- FEATURE: Added filter for paused/error torrents - FEATURE: Added filter for paused/error torrents
- FEATURE: Add Check/Uncheck all feature in Web UI - FEATURE: Add Check/Uncheck all feature in Web UI
- FEATURE: Search engine can now be disabled - 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: Hide seeding torrents files priorities in Web UI
- BUGFIX: The user can disable permanently recursive torrent download - BUGFIX: The user can disable permanently recursive torrent download
- COSMETIC: Display peers country name in tooltip - COSMETIC: Display peers country name in tooltip

22
src/bittorrent.cpp

@ -210,8 +210,8 @@ ScanFoldersModel* Bittorrent::getScanFoldersModel() const {
return m_scanFolders; return m_scanFolders;
} }
void Bittorrent::deleteBigRatios() { void Bittorrent::processBigRatios() {
if(ratio_limit == -1) return; if(ratio_limit <= 0) return;
std::vector<torrent_handle> torrents = getTorrents(); std::vector<torrent_handle> torrents = getTorrents();
std::vector<torrent_handle>::iterator torrentIT; std::vector<torrent_handle>::iterator torrentIT;
for(torrentIT = torrents.begin(); torrentIT != torrents.end(); torrentIT++) { for(torrentIT = torrents.begin(); torrentIT != torrents.end(); torrentIT++) {
@ -222,7 +222,14 @@ void Bittorrent::deleteBigRatios() {
const float ratio = getRealRatio(hash); const float ratio = getRealRatio(hash);
if(ratio <= MAX_RATIO && ratio > ratio_limit) { if(ratio <= MAX_RATIO && ratio > ratio_limit) {
addConsoleMessage(tr("%1 reached the maximum ratio you set.").arg(h.name())); addConsoleMessage(tr("%1 reached the maximum ratio you set.").arg(h.name()));
if(high_ratio_action == REMOVE_ACTION) {
addConsoleMessage(tr("Removing torrent %1...").arg(h.name()));
deleteTorrent(hash); deleteTorrent(hash);
} else {
// Pause it
addConsoleMessage(tr("Pausing torrent %1...").arg(h.name()));
pauseTorrent(hash);
}
//emit torrent_ratio_deleted(fileName); //emit torrent_ratio_deleted(fileName);
} }
} }
@ -522,7 +529,8 @@ void Bittorrent::configureSession() {
} }
applyEncryptionSettings(encryptionSettings); applyEncryptionSettings(encryptionSettings);
// * Maximum ratio // * Maximum ratio
setDeleteRatio(Preferences::getDeleteRatio()); high_ratio_action = Preferences::getMaxRatioAction();
setMaxRatio(Preferences::getMaxRatio());
// Ip Filter // Ip Filter
FilterParserThread::processFilterList(s, Preferences::bannedIPs()); FilterParserThread::processFilterList(s, Preferences::bannedIPs());
if(Preferences::isFilteringEnabled()) { if(Preferences::isFilteringEnabled()) {
@ -1763,12 +1771,12 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
// Torrents will a ratio superior to the given value will // Torrents will a ratio superior to the given value will
// be automatically deleted // be automatically deleted
void Bittorrent::setDeleteRatio(float ratio) { void Bittorrent::setMaxRatio(float ratio) {
if(ratio != -1 && ratio < 1.) ratio = 1.; if(ratio <= 0) ratio = -1.;
if(ratio_limit == -1 && ratio != -1) { if(ratio_limit == -1 && ratio != -1) {
Q_ASSERT(!BigRatioTimer); Q_ASSERT(!BigRatioTimer);
BigRatioTimer = new QTimer(this); BigRatioTimer = new QTimer(this);
connect(BigRatioTimer, SIGNAL(timeout()), this, SLOT(deleteBigRatios())); connect(BigRatioTimer, SIGNAL(timeout()), this, SLOT(processBigRatios()));
BigRatioTimer->start(5000); BigRatioTimer->start(5000);
} else { } else {
if(ratio_limit != -1 && ratio == -1) { if(ratio_limit != -1 && ratio == -1) {
@ -1778,7 +1786,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
if(ratio_limit != ratio) { if(ratio_limit != ratio) {
ratio_limit = ratio; ratio_limit = ratio;
qDebug("* Set deleteRatio to %.1f", ratio_limit); qDebug("* Set deleteRatio to %.1f", ratio_limit);
deleteBigRatios(); processBigRatios();
} }
} }

5
src/bittorrent.h

@ -153,7 +153,7 @@ public slots:
void setMaxUploadsPerTorrent(int max); void setMaxUploadsPerTorrent(int max);
void setDownloadRateLimit(long rate); void setDownloadRateLimit(long rate);
void setUploadRateLimit(long rate); void setUploadRateLimit(long rate);
void setDeleteRatio(float ratio); void setMaxRatio(float ratio);
void setDHTPort(int dht_port); void setDHTPort(int dht_port);
void setPeerProxySettings(const proxy_settings &proxySettings); void setPeerProxySettings(const proxy_settings &proxySettings);
void setHTTPProxySettings(const proxy_settings &proxySettings); void setHTTPProxySettings(const proxy_settings &proxySettings);
@ -194,7 +194,7 @@ protected:
protected slots: protected slots:
void addTorrentsFromScanFolder(QStringList&); void addTorrentsFromScanFolder(QStringList&);
void readAlerts(); void readAlerts();
void deleteBigRatios(); void processBigRatios();
void takeETASamples(); void takeETASamples();
void exportTorrentFiles(QString path); void exportTorrentFiles(QString path);
void saveTempFastResumeData(); void saveTempFastResumeData();
@ -240,6 +240,7 @@ private:
bool preAllocateAll; bool preAllocateAll;
bool addInPause; bool addInPause;
float ratio_limit; float ratio_limit;
int high_ratio_action;
bool UPnPEnabled; bool UPnPEnabled;
bool NATPMPEnabled; bool NATPMPEnabled;
bool LSDEnabled; bool LSDEnabled;

26
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(checkMaxConnecs, SIGNAL(toggled(bool)), this, SLOT(enableMaxConnecsLimit(bool)));
connect(checkMaxConnecsPerTorrent, SIGNAL(toggled(bool)), this, SLOT(enableMaxConnecsLimitPerTorrent(bool))); connect(checkMaxConnecsPerTorrent, SIGNAL(toggled(bool)), this, SLOT(enableMaxConnecsLimitPerTorrent(bool)));
connect(checkMaxUploadsPerTorrent, SIGNAL(toggled(bool)), this, SLOT(enableMaxUploadsLimitPerTorrent(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))); connect(comboPeerID, SIGNAL(currentIndexChanged(int)), this, SLOT(enableSpoofingSettings(int)));
// Proxy tab // Proxy tab
connect(comboProxyType_http, SIGNAL(currentIndexChanged(int)),this, SLOT(enableHTTPProxy(int))); 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_version, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
connect(client_build, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton())); connect(client_build, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
connect(comboEncryption, SIGNAL(currentIndexChanged(int)), 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(spinMaxRatio, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton()));
connect(comboRatioLimitAct, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton()));
// Proxy tab // Proxy tab
connect(comboProxyType_http, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton())); connect(comboProxyType_http, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton()));
connect(textProxyIP_http, SIGNAL(textChanged(QString)), 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"); Preferences::setPeerID("qB");
} }
settings.setValue(QString::fromUtf8("Encryption"), getEncryptionSetting()); settings.setValue(QString::fromUtf8("Encryption"), getEncryptionSetting());
settings.setValue(QString::fromUtf8("MaxRatio"), getDeleteRatio()); Preferences::setMaxRatio(getMaxRatio());
Preferences::setMaxRatioAction(comboRatioLimitAct->currentIndex());
// End Bittorrent preferences // End Bittorrent preferences
settings.endGroup(); settings.endGroup();
// Misc preferences // Misc preferences
@ -780,17 +782,20 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){
} }
comboEncryption->setCurrentIndex(Preferences::getEncryptionSetting()); comboEncryption->setCurrentIndex(Preferences::getEncryptionSetting());
// Ratio limit // Ratio limit
floatValue = Preferences::getDeleteRatio(); floatValue = Preferences::getMaxRatio();
if(floatValue >= 1.) { if(floatValue > 0.) {
// Enable // Enable
checkRatioRemove->setChecked(true); checkMaxRatio->setChecked(true);
spinMaxRatio->setEnabled(true); spinMaxRatio->setEnabled(true);
comboRatioLimitAct->setEnabled(true);
spinMaxRatio->setValue(floatValue); spinMaxRatio->setValue(floatValue);
} else { } else {
// Disable // Disable
checkRatioRemove->setChecked(false); checkMaxRatio->setChecked(false);
spinMaxRatio->setEnabled(false); spinMaxRatio->setEnabled(false);
comboRatioLimitAct->setEnabled(false);
} }
comboRatioLimitAct->setCurrentIndex(Preferences::getMaxRatioAction());
// End Bittorrent preferences // End Bittorrent preferences
// Misc preferences // Misc preferences
// * IP Filter // * IP Filter
@ -957,8 +962,8 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){
} }
// Return Share ratio // Return Share ratio
float options_imp::getDeleteRatio() const{ float options_imp::getMaxRatio() const{
if(checkRatioRemove->isChecked()){ if(checkMaxRatio->isChecked()){
return spinMaxRatio->value(); return spinMaxRatio->value();
} }
return -1; return -1;
@ -1091,8 +1096,9 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){
applyButton->setEnabled(true); applyButton->setEnabled(true);
} }
void options_imp::enableDeleteRatio(bool checked){ void options_imp::enableMaxRatio(bool checked){
spinMaxRatio->setEnabled(checked); spinMaxRatio->setEnabled(checked);
comboRatioLimitAct->setEnabled(checked);
} }
void options_imp::enablePeerProxy(int index){ void options_imp::enablePeerProxy(int index){

4
src/options_imp.h

@ -96,7 +96,7 @@ protected:
int getDHTPort() const; int getDHTPort() const;
bool isLSDEnabled() const; bool isLSDEnabled() const;
int getEncryptionSetting() const; int getEncryptionSetting() const;
float getDeleteRatio() const; float getMaxRatio() const;
// Proxy options // Proxy options
QString getHTTPProxyIp() const; QString getHTTPProxyIp() const;
unsigned short getHTTPProxyPort() const; unsigned short getHTTPProxyPort() const;
@ -135,7 +135,7 @@ protected slots:
void enableMaxConnecsLimit(bool checked); void enableMaxConnecsLimit(bool checked);
void enableMaxConnecsLimitPerTorrent(bool checked); void enableMaxConnecsLimitPerTorrent(bool checked);
void enableMaxUploadsLimitPerTorrent(bool checked); void enableMaxUploadsLimitPerTorrent(bool checked);
void enableDeleteRatio(bool checked); void enableMaxRatio(bool checked);
void enableSpoofingSettings(int index); void enableSpoofingSettings(int index);
void setStyle(QString style); void setStyle(QString style);
void on_buttonBox_accepted(); void on_buttonBox_accepted();

18
src/preferences.h

@ -53,6 +53,7 @@
#define QBT_REALM "Web UI Access" #define QBT_REALM "Web UI Access"
enum scheduler_days { EVERY_DAY, WEEK_DAYS, WEEK_ENDS, MON, TUE, WED, THU, FRI, SAT, SUN }; enum scheduler_days { EVERY_DAY, WEEK_DAYS, WEEK_ENDS, MON, TUE, WED, THU, FRI, SAT, SUN };
enum maxRatioAction {PAUSE_ACTION, REMOVE_ACTION};
class Preferences { class Preferences {
public: public:
@ -693,11 +694,26 @@ public:
settings.setValue(QString::fromUtf8("Preferences/Bittorrent/Encryption"), val); settings.setValue(QString::fromUtf8("Preferences/Bittorrent/Encryption"), val);
} }
static float getDeleteRatio() { static float getMaxRatio() {
QSettings settings("qBittorrent", "qBittorrent"); QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Bittorrent/MaxRatio"), -1).toDouble(); 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 // IP Filter
static bool isFilteringEnabled() { static bool isFilteringEnabled() {
QSettings settings("qBittorrent", "qBittorrent"); QSettings settings("qBittorrent", "qBittorrent");

234
src/ui/options.ui

@ -516,7 +516,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>506</width> <width>506</width>
<height>630</height> <height>504</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
@ -555,97 +555,6 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item>
<widget class="QGroupBox" name="checkEnableQueueing">
<property name="title">
<string>Torrent queueing</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_max_active_dl">
<property name="text">
<string>Maximum active downloads:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="spinMaxActiveDownloads">
<property name="minimum">
<number>-1</number>
</property>
<property name="maximum">
<number>999</number>
</property>
<property name="value">
<number>3</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_max_active_up">
<property name="text">
<string>Maximum active uploads:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="spinMaxActiveUploads">
<property name="minimum">
<number>-1</number>
</property>
<property name="maximum">
<number>999</number>
</property>
<property name="value">
<number>3</number>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="maxActiveTorrents_lbl">
<property name="text">
<string>Maximum active torrents:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="spinMaxActiveTorrents">
<property name="minimum">
<number>-1</number>
</property>
<property name="maximum">
<number>999</number>
</property>
<property name="value">
<number>5</number>
</property>
</widget>
</item>
<item row="1" column="2">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item> <item>
<widget class="QGroupBox" name="fileSystemBox"> <widget class="QGroupBox" name="fileSystemBox">
<property name="sizePolicy"> <property name="sizePolicy">
@ -1650,12 +1559,12 @@ QGroupBox {
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>-80</y>
<width>524</width> <width>539</width>
<height>406</height> <height>484</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_20"> <layout class="QVBoxLayout" name="verticalLayout_7">
<item> <item>
<widget class="QGroupBox" name="AddBTFeaturesBox"> <widget class="QGroupBox" name="AddBTFeaturesBox">
<property name="title"> <property name="title">
@ -1828,6 +1737,9 @@ QGroupBox {
<string>Client whitelisting workaround</string> <string>Client whitelisting workaround</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_19"> <layout class="QVBoxLayout" name="verticalLayout_19">
<property name="bottomMargin">
<number>0</number>
</property>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_11"> <layout class="QHBoxLayout" name="horizontalLayout_11">
<item> <item>
@ -1935,18 +1847,112 @@ QGroupBox {
</layout> </layout>
</widget> </widget>
</item> </item>
<item>
<widget class="QGroupBox" name="checkEnableQueueing">
<property name="title">
<string>Torrent queueing</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_max_active_dl">
<property name="text">
<string>Maximum active downloads:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="spinMaxActiveDownloads">
<property name="minimum">
<number>-1</number>
</property>
<property name="maximum">
<number>999</number>
</property>
<property name="value">
<number>3</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_max_active_up">
<property name="text">
<string>Maximum active uploads:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="spinMaxActiveUploads">
<property name="minimum">
<number>-1</number>
</property>
<property name="maximum">
<number>999</number>
</property>
<property name="value">
<number>3</number>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="maxActiveTorrents_lbl">
<property name="text">
<string>Maximum active torrents:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="spinMaxActiveTorrents">
<property name="minimum">
<number>-1</number>
</property>
<property name="maximum">
<number>999</number>
</property>
<property name="value">
<number>5</number>
</property>
</widget>
</item>
<item row="1" column="2">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item> <item>
<widget class="QGroupBox" name="ratioBox"> <widget class="QGroupBox" name="ratioBox">
<property name="title"> <property name="title">
<string>Share ratio settings</string> <string>Share ratio limiting</string>
</property> </property>
<layout class="QVBoxLayout"> <layout class="QVBoxLayout">
<property name="bottomMargin">
<number>0</number>
</property>
<item> <item>
<layout class="QHBoxLayout"> <layout class="QHBoxLayout">
<item> <item>
<widget class="QCheckBox" name="checkRatioRemove"> <widget class="QCheckBox" name="checkMaxRatio">
<property name="text"> <property name="text">
<string>Remove finished torrents when their ratio reaches:</string> <string>Seed torrents until their ratio reaches</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -1967,10 +1973,10 @@ QGroupBox {
<number>1</number> <number>1</number>
</property> </property>
<property name="minimum"> <property name="minimum">
<double>1.000000000000000</double> <double>0.100000000000000</double>
</property> </property>
<property name="maximum"> <property name="maximum">
<double>10.000000000000000</double> <double>20.000000000000000</double>
</property> </property>
<property name="singleStep"> <property name="singleStep">
<double>0.100000000000000</double> <double>0.100000000000000</double>
@ -1980,6 +1986,30 @@ QGroupBox {
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>then</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboRatioLimitAct">
<property name="enabled">
<bool>false</bool>
</property>
<item>
<property name="text">
<string>Pause them</string>
</property>
</item>
<item>
<property name="text">
<string>Remove them</string>
</property>
</item>
</widget>
</item>
<item> <item>
<spacer> <spacer>
<property name="orientation"> <property name="orientation">
@ -2670,7 +2700,7 @@ QGroupBox {
<tabstop>checkNATPMP</tabstop> <tabstop>checkNATPMP</tabstop>
<tabstop>checkLSD</tabstop> <tabstop>checkLSD</tabstop>
<tabstop>comboEncryption</tabstop> <tabstop>comboEncryption</tabstop>
<tabstop>checkRatioRemove</tabstop> <tabstop>checkMaxRatio</tabstop>
<tabstop>spinMaxRatio</tabstop> <tabstop>spinMaxRatio</tabstop>
<tabstop>spinWebUiPort</tabstop> <tabstop>spinWebUiPort</tabstop>
<tabstop>textWebUiUsername</tabstop> <tabstop>textWebUiUsername</tabstop>

Loading…
Cancel
Save