From 59906152489c014846e54af95e96bed97f830d8f Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Tue, 20 Sep 2011 20:15:47 +0300 Subject: [PATCH] Add support for anonymous mode This mode was added in libtorrent v0.16 and should be used in addition to a SOCKS5 proxy. --- Changelog | 1 + src/preferences/options.ui | 37 +++++++++++++++++++++++-- src/preferences/options_imp.cpp | 33 +++++++++++++++++++++- src/preferences/options_imp.h | 1 + src/preferences/preferences.h | 10 +++++++ src/qtlibtorrent/qbtsession.cpp | 8 +++++- src/webui/eventmanager.cpp | 7 +++++ src/webui/html/preferences_content.html | 26 +++++++++++++++++ 8 files changed, 118 insertions(+), 5 deletions(-) diff --git a/Changelog b/Changelog index 4175c795b..da9c6e5a3 100644 --- a/Changelog +++ b/Changelog @@ -2,6 +2,7 @@ - FEATURE: Add file association settings to program preferences (Windows) - FEATURE: Add setting to ignore slow torrents in queueing system - FEATURE: Add advanced setting to announce to all trackers + - FEATURE: Add support for anonymous mode - BUGFIX: Add tray menu entry for toggling window visibility - COSMETIC: Display speed at the beginning of the Window title - OTHER: Display libraries versions in about dialog (sledgehammer999) diff --git a/src/preferences/options.ui b/src/preferences/options.ui index 48c9fb726..766e0538a 100644 --- a/src/preferences/options.ui +++ b/src/preferences/options.ui @@ -1825,9 +1825,9 @@ 0 - -67 + 0 530 - 471 + 500 @@ -1976,6 +1976,37 @@ + + + + + + Enable anonymous mode + + + + + + + (<a href="http://sourceforge.net/apps/mediawiki/qbittorrent/index.php?title=Anonymous_mode">More information</a>) + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + @@ -2206,7 +2237,7 @@ 0 0 - 419 + 485 535 diff --git a/src/preferences/options_imp.cpp b/src/preferences/options_imp.cpp index acdb9de5f..977bf3d63 100644 --- a/src/preferences/options_imp.cpp +++ b/src/preferences/options_imp.cpp @@ -124,10 +124,13 @@ options_imp::options_imp(QWidget *parent): #ifndef Q_WS_WIN groupFileAssociation->setVisible(false); #endif +#if LIBTORRENT_VERSION_MINOR < 16 + checkAnonymousMode->setVisible(false); +#endif // Connect signals / slots - // Proxy tab connect(comboProxyType, SIGNAL(currentIndexChanged(int)),this, SLOT(enableProxy(int))); + connect(checkAnonymousMode, SIGNAL(toggled(bool)), this, SLOT(toggleAnonymousMode(bool))); // Apply button is activated when a value is changed // General tab @@ -196,6 +199,9 @@ options_imp::options_imp(QWidget *parent): connect(spinMaxConnecPerTorrent, 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_MINOR > 15 + connect(checkAnonymousMode, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); +#endif connect(checkPeX, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); connect(checkDifferentDHTPort, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); connect(spinDHTPort, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton())); @@ -443,6 +449,9 @@ void options_imp::saveOptions(){ pref.setDHTPort(getDHTPort()); pref.setLSDEnabled(isLSDEnabled()); pref.setEncryptionSetting(getEncryptionSetting()); +#if LIBTORRENT_VERSION_MINOR > 15 + pref.enableAnonymousMode(checkAnonymousMode->isChecked()); +#endif pref.setGlobalMaxRatio(getMaxRatio()); pref.setMaxRatioAction(comboRatioLimitAct->currentIndex()); // End Bittorrent preferences @@ -700,6 +709,9 @@ void options_imp::loadOptions(){ checkPeX->setChecked(pref.isPeXEnabled()); checkLSD->setChecked(pref.isLSDEnabled()); comboEncryption->setCurrentIndex(pref.getEncryptionSetting()); +#if LIBTORRENT_VERSION_MINOR > 15 + checkAnonymousMode->setChecked(pref.isAnonymousModeEnabled()); +#endif // Ratio limit floatValue = pref.getGlobalMaxRatio(); if(floatValue >= 0.) { @@ -1301,3 +1313,22 @@ void options_imp::setSslCertificate(const QByteArray &cert, bool interactive) } #endif } + +void options_imp::toggleAnonymousMode(bool enabled) +{ + if (enabled) { + // Disable DHT, LSD, UPnP / NAT-PMP + checkDHT->setEnabled(false); + checkDifferentDHTPort->setEnabled(false); + checkDHT->setChecked(false); + checkLSD->setEnabled(false); + checkLSD->setChecked(false); + checkUPnP->setEnabled(false); + checkUPnP->setChecked(false); + } else { + checkDHT->setEnabled(true); + checkDifferentDHTPort->setEnabled(true); + checkLSD->setEnabled(true); + checkUPnP->setEnabled(true); + } +} diff --git a/src/preferences/options_imp.h b/src/preferences/options_imp.h index fa354c773..112bf1b97 100644 --- a/src/preferences/options_imp.h +++ b/src/preferences/options_imp.h @@ -84,6 +84,7 @@ private slots: void on_btnWebUiKey_clicked(); void on_registerDNSBtn_clicked(); void setLocale(const QString &locale); + void toggleAnonymousMode(bool enabled); private: // Methods diff --git a/src/preferences/preferences.h b/src/preferences/preferences.h index ff6119a08..afb85944d 100644 --- a/src/preferences/preferences.h +++ b/src/preferences/preferences.h @@ -1013,6 +1013,16 @@ public: return value(QString::fromUtf8("Preferences/Connection/InetAddress"), QString()).toString(); } +#if LIBTORRENT_VERSION_MINOR > 15 + bool isAnonymousModeEnabled() const { + return value(QString::fromUtf8("Preferences/Advanced/AnonymousMode"), false).toBool(); + } + + void enableAnonymousMode(bool enabled) { + setValue(QString::fromUtf8("Preferences/Advanced/AnonymousMode"), enabled); + } +#endif + #if LIBTORRENT_VERSION_MINOR > 14 bool isSuperSeedingEnabled() const { return value(QString::fromUtf8("Preferences/Advanced/SuperSeeding"), false).toBool(); diff --git a/src/qtlibtorrent/qbtsession.cpp b/src/qtlibtorrent/qbtsession.cpp index 6e33d5122..8e376b890 100644 --- a/src/qtlibtorrent/qbtsession.cpp +++ b/src/qtlibtorrent/qbtsession.cpp @@ -284,7 +284,7 @@ void QBtSession::configureSession() { if(old_listenPort != new_listenPort) { qDebug("Session port changes in program preferences: %d -> %d", old_listenPort, new_listenPort); setListeningPort(new_listenPort); - addConsoleMessage(tr("qBittorrent is bound to port: TCP/%1", "e.g: qBittorrent is bound to port: 6881").arg(QString::number(new_listenPort))); + addConsoleMessage(tr("qBittorrent is bound to port: TCP/%1", "e.g: qBittorrent is bound to port: 6881").arg(QString::number(getListenPort()))); } // Downloads @@ -408,6 +408,12 @@ void QBtSession::configureSession() { sessionSettings.disk_io_write_mode = session_settings::disable_os_cache_for_aligned_files; sessionSettings.disk_io_read_mode = session_settings::disable_os_cache_for_aligned_files; #endif +#endif +#if LIBTORRENT_VERSION_MINOR > 15 + sessionSettings.anonymous_mode = pref.isAnonymousModeEnabled(); + if (sessionSettings.anonymous_mode) { + addConsoleMessage(tr("Anonymous mode [ON]"), "blue"); + } #endif // Queueing System if(pref.isQueueingSystemEnabled()) { diff --git a/src/webui/eventmanager.cpp b/src/webui/eventmanager.cpp index 60c07629d..271885662 100644 --- a/src/webui/eventmanager.cpp +++ b/src/webui/eventmanager.cpp @@ -249,6 +249,10 @@ void EventManager::setGlobalPreferences(QVariantMap m) const { pref.setLSDEnabled(m["lsd"].toBool()); if(m.contains("encryption")) pref.setEncryptionSetting(m["encryption"].toInt()); +#if LIBTORRENT_VERSION_MINOR >= 16 + if(m.contains("anonymous_mode")) + pref.enableAnonymousMode(m["anonymous_mode"].toBool()); +#endif // Proxy if(m.contains("proxy_type")) pref.setProxyType(m["proxy_type"].toInt()); @@ -362,6 +366,9 @@ QVariantMap EventManager::getGlobalPreferences() const { data["pex"] = pref.isPeXEnabled(); data["lsd"] = pref.isLSDEnabled(); data["encryption"] = pref.getEncryptionSetting(); +#if LIBTORRENT_VERSION_MINOR >= 16 + data["anonymous_mode"] = pref.isAnonymousModeEnabled(); +#endif // Proxy data["proxy_type"] = pref.getProxyType(); data["proxy_ip"] = pref.getProxyIp(); diff --git a/src/webui/html/preferences_content.html b/src/webui/html/preferences_content.html index 3e3d6e036..4417eddf3 100644 --- a/src/webui/html/preferences_content.html +++ b/src/webui/html/preferences_content.html @@ -76,6 +76,7 @@
+   _(Enable anonymous mode) (More information)
@@ -312,6 +313,23 @@