From 0b8fad69fa297e996bd55228da98fb58c3d27768 Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Tue, 26 Aug 2014 00:32:10 +0300 Subject: [PATCH] Option to disable connections not supported by proxies. Closes #1894. --- src/misc.h | 1 - src/preferences/options.ui | 13 +++++++++++++ src/preferences/options_imp.cpp | 20 ++++++++++++++++++++ src/preferences/preferences.cpp | 10 ++++++++++ src/preferences/preferences.h | 6 ++++++ src/qtlibtorrent/qbtsession.cpp | 6 ++++++ 6 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/misc.h b/src/misc.h index 3e7eae607..45593c074 100644 --- a/src/misc.h +++ b/src/misc.h @@ -31,7 +31,6 @@ #ifndef MISC_H #define MISC_H -#include #include #include #include diff --git a/src/preferences/options.ui b/src/preferences/options.ui index 9b9dc5406..247ea7dce 100755 --- a/src/preferences/options.ui +++ b/src/preferences/options.ui @@ -1372,6 +1372,16 @@ + + + + Disable connections not supported by proxies + + + true + + + @@ -2030,6 +2040,9 @@ + + Enable when using a proxy or a VPN connection + Enable anonymous mode diff --git a/src/preferences/options_imp.cpp b/src/preferences/options_imp.cpp index 99f2f36c2..c084ffb57 100755 --- a/src/preferences/options_imp.cpp +++ b/src/preferences/options_imp.cpp @@ -215,6 +215,9 @@ options_imp::options_imp(QWidget *parent): connect(textProxyIP, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton())); connect(spinProxyPort, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton())); connect(checkProxyPeerConnecs, SIGNAL(toggled(bool)), SLOT(enableApplyButton())); +#if LIBTORRENT_VERSION_NUM >= 10000 + connect(checkForceProxy, SIGNAL(toggled(bool)), SLOT(enableApplyButton())); +#endif connect(checkProxyAuth, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); connect(textProxyUsername, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton())); connect(textProxyPassword, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton())); @@ -252,6 +255,11 @@ options_imp::options_imp(QWidget *parent): scrollArea_advanced->setLayout(adv_layout); connect(advancedSettings, SIGNAL(settingsChanged()), this, SLOT(enableApplyButton())); + //Hide incompatible options +#if LIBTORRENT_VERSION_NUM < 10000 + checkForceProxy->setVisible(false); +#endif + // Adapt size show(); loadWindowState(); @@ -418,6 +426,9 @@ void options_imp::saveOptions() { pref->setProxyIp(getProxyIp()); pref->setProxyPort(getProxyPort()); pref->setProxyPeerConnections(checkProxyPeerConnecs->isChecked()); +#if LIBTORRENT_VERSION_NUM >= 10000 + pref->setForceProxy(checkForceProxy->isChecked()); +#endif pref->setProxyAuthEnabled(isProxyAuthEnabled()); pref->setProxyUsername(getProxyUsername()); pref->setProxyPassword(getProxyPassword()); @@ -643,6 +654,9 @@ void options_imp::loadOptions() { textProxyIP->setText(pref->getProxyIp()); spinProxyPort->setValue(pref->getProxyPort()); checkProxyPeerConnecs->setChecked(pref->proxyPeerConnections()); +#if LIBTORRENT_VERSION_NUM >= 10000 + checkForceProxy->setChecked(pref->getForceProxy()); +#endif checkProxyAuth->setChecked(pref->isProxyAuthEnabled()); textProxyUsername->setText(pref->getProxyUsername()); textProxyPassword->setText(pref->getProxyPassword()); @@ -930,6 +944,9 @@ void options_imp::enableProxy(int index) { lblProxyPort->setEnabled(true); spinProxyPort->setEnabled(true); checkProxyPeerConnecs->setEnabled(true); +#if LIBTORRENT_VERSION_NUM >= 10000 + checkForceProxy->setEnabled(true); +#endif if (index > 1) { checkProxyAuth->setEnabled(true); } else { @@ -943,6 +960,9 @@ void options_imp::enableProxy(int index) { lblProxyPort->setEnabled(false); spinProxyPort->setEnabled(false); checkProxyPeerConnecs->setEnabled(false); +#if LIBTORRENT_VERSION_NUM >= 10000 + checkForceProxy->setEnabled(false); +#endif checkProxyAuth->setEnabled(false); checkProxyAuth->setChecked(false); } diff --git a/src/preferences/preferences.cpp b/src/preferences/preferences.cpp index 734c84035..c4ddd3ee8 100644 --- a/src/preferences/preferences.cpp +++ b/src/preferences/preferences.cpp @@ -698,6 +698,16 @@ void Preferences::setProxyPeerConnections(bool enabled) { setValue("Preferences/Connection/ProxyPeerConnections", enabled); } +#if LIBTORRENT_VERSION_NUM >= 10000 +bool Preferences::getForceProxy() const { + return value("Preferences/Connection/ProxyForce", true).toBool(); +} + +void Preferences::setForceProxy(bool enabled) { + setValue("Preferences/Connection/ProxyForce", enabled); +} +#endif + // Bittorrent options int Preferences::getMaxConnecs() const { return value("Preferences/Bittorrent/MaxConnecs", 500).toInt(); diff --git a/src/preferences/preferences.h b/src/preferences/preferences.h index 50c7fe0d6..efddc7afc 100755 --- a/src/preferences/preferences.h +++ b/src/preferences/preferences.h @@ -42,6 +42,8 @@ #include #include +#include + #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}; @@ -203,6 +205,10 @@ public: void setProxyType(int type); bool proxyPeerConnections() const; void setProxyPeerConnections(bool enabled); +#if LIBTORRENT_VERSION_NUM >= 10000 + bool getForceProxy() const; + void setForceProxy(bool enabled); +#endif // Bittorrent options int getMaxConnecs() const; diff --git a/src/qtlibtorrent/qbtsession.cpp b/src/qtlibtorrent/qbtsession.cpp index 3407aa4a1..86d74e1f6 100755 --- a/src/qtlibtorrent/qbtsession.cpp +++ b/src/qtlibtorrent/qbtsession.cpp @@ -482,6 +482,12 @@ void QBtSession::configureSession() { else sessionSettings.mixed_mode_algorithm = session_settings::peer_proportional; sessionSettings.connection_speed = 20; //default is 10 +#if LIBTORRENT_VERSION_NUM >= 10000 + if (pref->isProxyEnabled()) + sessionSettings.force_proxy = pref->getForceProxy(); + else + sessionSettings.force_proxy = false; +#endif qDebug() << "Settings SessionSettings"; setSessionSettings(sessionSettings); // Bittorrent