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. 24
      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 @@ @@ -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

24
src/bittorrent.cpp

@ -210,8 +210,8 @@ ScanFoldersModel* Bittorrent::getScanFoldersModel() const { @@ -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<torrent_handle> torrents = getTorrents();
std::vector<torrent_handle>::iterator torrentIT;
for(torrentIT = torrents.begin(); torrentIT != torrents.end(); torrentIT++) {
@ -222,7 +222,14 @@ void Bittorrent::deleteBigRatios() { @@ -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() { @@ -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) { @@ -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) { @@ -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();
}
}

5
src/bittorrent.h

@ -153,7 +153,7 @@ public slots: @@ -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: @@ -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: @@ -240,6 +240,7 @@ private:
bool preAllocateAll;
bool addInPause;
float ratio_limit;
int high_ratio_action;
bool UPnPEnabled;
bool NATPMPEnabled;
bool LSDEnabled;

26
src/options_imp.cpp

@ -168,7 +168,7 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){ @@ -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){ @@ -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){ @@ -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){ @@ -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){ @@ -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){ @@ -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){

4
src/options_imp.h

@ -96,7 +96,7 @@ protected: @@ -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: @@ -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();

18
src/preferences.h

@ -53,6 +53,7 @@ @@ -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: @@ -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");

234
src/ui/options.ui

@ -516,7 +516,7 @@ @@ -516,7 +516,7 @@
<x>0</x>
<y>0</y>
<width>506</width>
<height>630</height>
<height>504</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
@ -555,97 +555,6 @@ @@ -555,97 +555,6 @@
</layout>
</widget>
</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>
<widget class="QGroupBox" name="fileSystemBox">
<property name="sizePolicy">
@ -1650,12 +1559,12 @@ QGroupBox { @@ -1650,12 +1559,12 @@ QGroupBox {
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>524</width>
<height>406</height>
<y>-80</y>
<width>539</width>
<height>484</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_20">
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<widget class="QGroupBox" name="AddBTFeaturesBox">
<property name="title">
@ -1828,6 +1737,9 @@ QGroupBox { @@ -1828,6 +1737,9 @@ QGroupBox {
<string>Client whitelisting workaround</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_19">
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_11">
<item>
@ -1935,18 +1847,112 @@ QGroupBox { @@ -1935,18 +1847,112 @@ QGroupBox {
</layout>
</widget>
</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>
<widget class="QGroupBox" name="ratioBox">
<property name="title">
<string>Share ratio settings</string>
<string>Share ratio limiting</string>
</property>
<layout class="QVBoxLayout">
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout">
<item>
<widget class="QCheckBox" name="checkRatioRemove">
<widget class="QCheckBox" name="checkMaxRatio">
<property name="text">
<string>Remove finished torrents when their ratio reaches:</string>
<string>Seed torrents until their ratio reaches</string>
</property>
</widget>
</item>
@ -1967,10 +1973,10 @@ QGroupBox { @@ -1967,10 +1973,10 @@ QGroupBox {
<number>1</number>
</property>
<property name="minimum">
<double>1.000000000000000</double>
<double>0.100000000000000</double>
</property>
<property name="maximum">
<double>10.000000000000000</double>
<double>20.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
@ -1980,6 +1986,30 @@ QGroupBox { @@ -1980,6 +1986,30 @@ QGroupBox {
</property>
</widget>
</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>
<spacer>
<property name="orientation">
@ -2670,7 +2700,7 @@ QGroupBox { @@ -2670,7 +2700,7 @@ QGroupBox {
<tabstop>checkNATPMP</tabstop>
<tabstop>checkLSD</tabstop>
<tabstop>comboEncryption</tabstop>
<tabstop>checkRatioRemove</tabstop>
<tabstop>checkMaxRatio</tabstop>
<tabstop>spinMaxRatio</tabstop>
<tabstop>spinWebUiPort</tabstop>
<tabstop>textWebUiUsername</tabstop>

Loading…
Cancel
Save