From 798bd2388bd0eedcc6140538fc39d1f6b2b81df9 Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Mon, 22 Jul 2013 01:20:48 +0300 Subject: [PATCH] Allow more fine tuning of uploads. Closes #684. --- src/preferences/options.ui | 63 +++++++++++++++++++++++++++++---- src/preferences/options_imp.cpp | 22 ++++++++++++ src/preferences/options_imp.h | 1 + src/preferences/preferences.h | 9 +++++ src/qtlibtorrent/qbtsession.cpp | 4 +++ 5 files changed, 92 insertions(+), 7 deletions(-) diff --git a/src/preferences/options.ui b/src/preferences/options.ui index 386016306..a5bf61cbe 100755 --- a/src/preferences/options.ui +++ b/src/preferences/options.ui @@ -1023,7 +1023,7 @@ 0 0 458 - 472 + 498 @@ -1133,7 +1133,7 @@ - + Maximum number of connections per torrent: @@ -1143,7 +1143,7 @@ - + 2 @@ -1156,7 +1156,7 @@ - + Maximum number of upload slots per torrent: @@ -1166,7 +1166,7 @@ - + 500 @@ -1189,7 +1189,7 @@ - + Qt::Horizontal @@ -1202,7 +1202,7 @@ - + Qt::Horizontal @@ -1215,6 +1215,39 @@ + + + + Global maximum number of upload slots: + + + true + + + + + + + 2000 + + + 8 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + @@ -2870,5 +2903,21 @@ + + checkMaxUploads + toggled(bool) + spinMaxUploads + setEnabled(bool) + + + 423 + 224 + + + 571 + 224 + + + diff --git a/src/preferences/options_imp.cpp b/src/preferences/options_imp.cpp index 4e9049439..00834ae80 100755 --- a/src/preferences/options_imp.cpp +++ b/src/preferences/options_imp.cpp @@ -201,9 +201,11 @@ options_imp::options_imp(QWidget *parent): // Bittorrent tab connect(checkMaxConnecs, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); connect(checkMaxConnecsPerTorrent, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); + connect(checkMaxUploads, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); connect(checkMaxUploadsPerTorrent, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); connect(spinMaxConnec, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton())); connect(spinMaxConnecPerTorrent, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton())); + connect(spinMaxUploads, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton())); connect(spinMaxUploadsPerTorrent, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton())); connect(checkDHT, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); #if LIBTORRENT_VERSION_NUM >= 001600 @@ -449,6 +451,7 @@ void options_imp::saveOptions() { // Bittorrent preferences pref.setMaxConnecs(getMaxConnecs()); pref.setMaxConnecsPerTorrent(getMaxConnecsPerTorrent()); + pref.setMaxUploads(getMaxUploads()); pref.setMaxUploadsPerTorrent(getMaxUploadsPerTorrent()); pref.setDHTEnabled(isDHTEnabled()); pref.setPeXEnabled(checkPeX->isChecked()); @@ -713,6 +716,17 @@ void options_imp::loadOptions() { checkMaxConnecsPerTorrent->setChecked(false); spinMaxConnecPerTorrent->setEnabled(false); } + intValue = pref.getMaxUploads(); + if (intValue > 0) { + // enable + checkMaxUploads->setChecked(true); + spinMaxUploads->setEnabled(true); + spinMaxUploads->setValue(intValue); + } else { + // disable + checkMaxUploads->setChecked(false); + spinMaxUploads->setEnabled(false); + } intValue = pref.getMaxUploadsPerTorrent(); if (intValue > 0) { // enable @@ -907,6 +921,14 @@ int options_imp::getMaxConnecsPerTorrent() const { } } +int options_imp::getMaxUploads() const { + if (!checkMaxUploads->isChecked()) { + return -1; + }else{ + return spinMaxUploads->value(); + } +} + int options_imp::getMaxUploadsPerTorrent() const { if (!checkMaxUploadsPerTorrent->isChecked()) { return -1; diff --git a/src/preferences/options_imp.h b/src/preferences/options_imp.h index ff5dd3906..59be8be36 100755 --- a/src/preferences/options_imp.h +++ b/src/preferences/options_imp.h @@ -123,6 +123,7 @@ private: // Bittorrent options int getMaxConnecs() const; int getMaxConnecsPerTorrent() const; + int getMaxUploads() const; int getMaxUploadsPerTorrent() const; bool isDHTEnabled() const; bool isDHTPortSameAsBT() const; diff --git a/src/preferences/preferences.h b/src/preferences/preferences.h index a68172bd2..eb34162ea 100755 --- a/src/preferences/preferences.h +++ b/src/preferences/preferences.h @@ -588,6 +588,15 @@ public: setValue(QString::fromUtf8("Preferences/Bittorrent/MaxConnecsPerTorrent"), val); } + int getMaxUploads() const { + return value(QString::fromUtf8("Preferences/Bittorrent/MaxUploads"), 8).toInt(); + } + + void setMaxUploads(int val) { + if (val <= 0) val = -1; + setValue(QString::fromUtf8("Preferences/Bittorrent/MaxUploads"), val); + } + int getMaxUploadsPerTorrent() const { return value(QString::fromUtf8("Preferences/Bittorrent/MaxUploadsPerTorrent"), 4).toInt(); } diff --git a/src/qtlibtorrent/qbtsession.cpp b/src/qtlibtorrent/qbtsession.cpp index 12c9400ba..ae7408a9d 100755 --- a/src/qtlibtorrent/qbtsession.cpp +++ b/src/qtlibtorrent/qbtsession.cpp @@ -475,11 +475,15 @@ void QBtSession::configureSession() { sessionSettings.half_open_limit = pref.getMaxHalfOpenConnections(); // * Max connections limit sessionSettings.connections_limit = pref.getMaxConnecs(); + // * Global max upload slots + sessionSettings.unchoke_slots_limit = pref.getMaxUploads(); #else // * Max Half-open connections s->set_max_half_open_connections(pref.getMaxHalfOpenConnections()); // * Max connections limit setMaxConnections(pref.getMaxConnecs()); + // * Global max upload slots + s->set_max_uploads(pref.getMaxUploads()); #endif #if LIBTORRENT_VERSION_NUM >= 001600 // uTP