Browse Source

Unify and simplify setting to use proxy for torrents only.

adaptive-webui-19844
sledgehammer999 8 years ago
parent
commit
6053390bf5
  1. 2
      src/base/net/downloadmanager.cpp
  2. 18
      src/base/net/proxyconfigurationmanager.cpp
  3. 6
      src/base/net/proxyconfigurationmanager.h
  4. 2
      src/base/settingsstorage.cpp
  5. 10
      src/gui/optionsdlg.cpp

2
src/base/net/downloadmanager.cpp

@ -213,7 +213,7 @@ void DownloadManager::applyProxySettings()
ProxyConfiguration proxyConfig = proxyManager->proxyConfiguration(); ProxyConfiguration proxyConfig = proxyManager->proxyConfiguration();
QNetworkProxy proxy; QNetworkProxy proxy;
if (!proxyManager->isProxyDisabled() && (proxyConfig.type != ProxyType::None)) { if (!proxyManager->isProxyOnlyForTorrents() && (proxyConfig.type != ProxyType::None)) {
// Proxy enabled // Proxy enabled
proxy.setHostName(proxyConfig.ip); proxy.setHostName(proxyConfig.ip);
proxy.setPort(proxyConfig.port); proxy.setPort(proxyConfig.port);

18
src/base/net/proxyconfigurationmanager.cpp

@ -30,7 +30,7 @@
#include "base/settingsstorage.h" #include "base/settingsstorage.h"
#define SETTINGS_KEY(name) "Network/Proxy/" name #define SETTINGS_KEY(name) "Network/Proxy/" name
const QString KEY_DISABLED = SETTINGS_KEY("Disabled"); const QString KEY_ONLY_FOR_TORRENTS = SETTINGS_KEY("OnlyForTorrents");
const QString KEY_TYPE = SETTINGS_KEY("Type"); const QString KEY_TYPE = SETTINGS_KEY("Type");
const QString KEY_IP = SETTINGS_KEY("IP"); const QString KEY_IP = SETTINGS_KEY("IP");
const QString KEY_PORT = SETTINGS_KEY("Port"); const QString KEY_PORT = SETTINGS_KEY("Port");
@ -58,7 +58,7 @@ ProxyConfigurationManager *ProxyConfigurationManager::m_instance = nullptr;
ProxyConfigurationManager::ProxyConfigurationManager(QObject *parent) ProxyConfigurationManager::ProxyConfigurationManager(QObject *parent)
: QObject(parent) : QObject(parent)
{ {
m_proxyDisabled = settings()->loadValue(KEY_DISABLED, false).toBool(); m_isProxyOnlyForTorrents = settings()->loadValue(KEY_ONLY_FOR_TORRENTS, false).toBool();
m_config.type = static_cast<ProxyType>( m_config.type = static_cast<ProxyType>(
settings()->loadValue(KEY_TYPE, static_cast<int>(ProxyType::None)).toInt()); settings()->loadValue(KEY_TYPE, static_cast<int>(ProxyType::None)).toInt());
if ((m_config.type < ProxyType::None) || (m_config.type > ProxyType::SOCKS4)) if ((m_config.type < ProxyType::None) || (m_config.type > ProxyType::SOCKS4))
@ -109,16 +109,16 @@ void ProxyConfigurationManager::setProxyConfiguration(const ProxyConfiguration &
} }
} }
bool ProxyConfigurationManager::isProxyDisabled() const bool ProxyConfigurationManager::isProxyOnlyForTorrents() const
{ {
return m_proxyDisabled; return m_isProxyOnlyForTorrents || (m_config.type == ProxyType::SOCKS4);
} }
void ProxyConfigurationManager::setProxyDisabled(bool disabled) void ProxyConfigurationManager::setProxyOnlyForTorrents(bool onlyForTorrents)
{ {
if (m_proxyDisabled != disabled) { if (m_isProxyOnlyForTorrents != onlyForTorrents) {
settings()->storeValue(KEY_DISABLED, disabled); settings()->storeValue(KEY_ONLY_FOR_TORRENTS, onlyForTorrents);
m_proxyDisabled = disabled; m_isProxyOnlyForTorrents = onlyForTorrents;
} }
} }
@ -132,7 +132,7 @@ void ProxyConfigurationManager::configureProxy()
{ {
// Define environment variables for urllib in search engine plugins // Define environment variables for urllib in search engine plugins
QString proxyStrHTTP, proxyStrSOCK; QString proxyStrHTTP, proxyStrSOCK;
if (!m_proxyDisabled) { if (!m_isProxyOnlyForTorrents) {
switch (m_config.type) { switch (m_config.type) {
case ProxyType::HTTP_PW: case ProxyType::HTTP_PW:
proxyStrHTTP = QString("http://%1:%2@%3:%4").arg(m_config.username) proxyStrHTTP = QString("http://%1:%2@%3:%4").arg(m_config.username)

6
src/base/net/proxyconfigurationmanager.h

@ -67,8 +67,8 @@ namespace Net
ProxyConfiguration proxyConfiguration() const; ProxyConfiguration proxyConfiguration() const;
void setProxyConfiguration(const ProxyConfiguration &config); void setProxyConfiguration(const ProxyConfiguration &config);
bool isProxyDisabled() const; bool isProxyOnlyForTorrents() const;
void setProxyDisabled(bool disabled); void setProxyOnlyForTorrents(bool onlyForTorrents);
bool isAuthenticationRequired() const; bool isAuthenticationRequired() const;
@ -80,7 +80,7 @@ namespace Net
static ProxyConfigurationManager *m_instance; static ProxyConfigurationManager *m_instance;
ProxyConfiguration m_config; ProxyConfiguration m_config;
bool m_proxyDisabled; bool m_isProxyOnlyForTorrents;
}; };
} }

2
src/base/settingsstorage.cpp

@ -156,7 +156,7 @@ namespace
{"BitTorrent/Session/uTPEnabled", "Preferences/Bittorrent/uTP"}, {"BitTorrent/Session/uTPEnabled", "Preferences/Bittorrent/uTP"},
{"BitTorrent/Session/uTPRateLimited", "Preferences/Bittorrent/uTP_rate_limited"}, {"BitTorrent/Session/uTPRateLimited", "Preferences/Bittorrent/uTP_rate_limited"},
{"BitTorrent/TrackerEnabled", "Preferences/Advanced/trackerEnabled"}, {"BitTorrent/TrackerEnabled", "Preferences/Advanced/trackerEnabled"},
{"Network/Proxy/Disabled", "Preferences/Connection/ProxyOnlyForTorrents"}, {"Network/Proxy/OnlyForTorrents", "Preferences/Connection/ProxyOnlyForTorrents"},
{"Network/Proxy/Type", "Preferences/Connection/ProxyType"}, {"Network/Proxy/Type", "Preferences/Connection/ProxyType"},
{"Network/Proxy/Authentication", "Preferences/Connection/Proxy/Authentication"}, {"Network/Proxy/Authentication", "Preferences/Connection/Proxy/Authentication"},
{"Network/Proxy/Username", "Preferences/Connection/Proxy/Username"}, {"Network/Proxy/Username", "Preferences/Connection/Proxy/Username"},

10
src/gui/optionsdlg.cpp

@ -563,7 +563,7 @@ void OptionsDialog::saveOptions()
proxyConf.port = getProxyPort(); proxyConf.port = getProxyPort();
proxyConf.username = getProxyUsername(); proxyConf.username = getProxyUsername();
proxyConf.password = getProxyPassword(); proxyConf.password = getProxyPassword();
proxyConfigManager->setProxyDisabled(m_ui->isProxyOnlyForTorrents->isChecked()); proxyConfigManager->setProxyOnlyForTorrents(m_ui->isProxyOnlyForTorrents->isChecked());
proxyConfigManager->setProxyConfiguration(proxyConf); proxyConfigManager->setProxyConfiguration(proxyConf);
session->setProxyPeerConnectionsEnabled(m_ui->checkProxyPeerConnecs->isChecked()); session->setProxyPeerConnectionsEnabled(m_ui->checkProxyPeerConnecs->isChecked());
@ -858,7 +858,6 @@ void OptionsDialog::loadOptions()
default: default:
m_ui->comboProxyType->setCurrentIndex(0); m_ui->comboProxyType->setCurrentIndex(0);
} }
enableProxy(m_ui->comboProxyType->currentIndex() > 0);
m_ui->textProxyIP->setText(proxyConf.ip); m_ui->textProxyIP->setText(proxyConf.ip);
m_ui->spinProxyPort->setValue(proxyConf.port); m_ui->spinProxyPort->setValue(proxyConf.port);
m_ui->checkProxyAuth->setChecked(useProxyAuth); m_ui->checkProxyAuth->setChecked(useProxyAuth);
@ -867,7 +866,8 @@ void OptionsDialog::loadOptions()
m_ui->checkProxyPeerConnecs->setChecked(session->isProxyPeerConnectionsEnabled()); m_ui->checkProxyPeerConnecs->setChecked(session->isProxyPeerConnectionsEnabled());
m_ui->checkForceProxy->setChecked(session->isForceProxyEnabled()); m_ui->checkForceProxy->setChecked(session->isForceProxyEnabled());
m_ui->isProxyOnlyForTorrents->setChecked(proxyConfigManager->isProxyDisabled()); m_ui->isProxyOnlyForTorrents->setChecked(proxyConfigManager->isProxyOnlyForTorrents());
enableProxy(m_ui->comboProxyType->currentIndex() > 0);
m_ui->checkIPFilter->setChecked(session->isIPFilteringEnabled()); m_ui->checkIPFilter->setChecked(session->isIPFilteringEnabled());
m_ui->checkIpFilterTrackers->setChecked(session->isTrackerFilteringEnabled()); m_ui->checkIpFilterTrackers->setChecked(session->isTrackerFilteringEnabled());
@ -1194,13 +1194,15 @@ void OptionsDialog::enableProxy(int index)
m_ui->spinProxyPort->setEnabled(true); m_ui->spinProxyPort->setEnabled(true);
m_ui->checkProxyPeerConnecs->setEnabled(true); m_ui->checkProxyPeerConnecs->setEnabled(true);
m_ui->checkForceProxy->setEnabled(true); m_ui->checkForceProxy->setEnabled(true);
m_ui->isProxyOnlyForTorrents->setEnabled(true);
if (index > 1) { if (index > 1) {
m_ui->checkProxyAuth->setEnabled(true); m_ui->checkProxyAuth->setEnabled(true);
m_ui->isProxyOnlyForTorrents->setEnabled(true);
} }
else { else {
m_ui->checkProxyAuth->setEnabled(false); m_ui->checkProxyAuth->setEnabled(false);
m_ui->checkProxyAuth->setChecked(false); m_ui->checkProxyAuth->setChecked(false);
m_ui->isProxyOnlyForTorrents->setEnabled(false);
m_ui->isProxyOnlyForTorrents->setChecked(true);
} }
} }
else { else {

Loading…
Cancel
Save