Browse Source

Allow to globally disable the use of proxy

PR #19273.
Closes #19141.
adaptive-webui-19844
Vladimir Golovnev 1 year ago committed by GitHub
parent
commit
7ec80263e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      src/app/upgrade.cpp
  2. 5
      src/base/bittorrent/sessionimpl.cpp
  3. 6
      src/base/net/downloadmanager.cpp
  4. 10
      src/base/net/proxyconfigurationmanager.cpp
  5. 7
      src/base/net/proxyconfigurationmanager.h
  6. 2
      src/base/search/searchpluginmanager.cpp
  7. 30
      src/gui/optionsdialog.cpp
  8. 2
      src/webui/api/appcontroller.cpp
  9. 24
      src/webui/www/private/views/preferences.html

13
src/app/upgrade.cpp

@ -344,7 +344,7 @@ namespace
switch (number) switch (number)
{ {
case 0: case 0:
settingsStorage->storeValue(key, u"None"_s); settingsStorage->storeValue(key, Net::ProxyType::None);
break; break;
case 1: case 1:
settingsStorage->storeValue(key, Net::ProxyType::HTTP); settingsStorage->storeValue(key, Net::ProxyType::HTTP);
@ -377,16 +377,6 @@ namespace
const auto onlyForTorrents = settingsStorage->loadValue<bool>(u"Network/Proxy/OnlyForTorrents"_s) const auto onlyForTorrents = settingsStorage->loadValue<bool>(u"Network/Proxy/OnlyForTorrents"_s)
|| (proxyType == u"SOCKS4"); || (proxyType == u"SOCKS4");
if (proxyType == u"None")
{
settingsStorage->storeValue(u"Network/Proxy/Type"_s, Net::ProxyType::HTTP);
settingsStorage->storeValue(u"Network/Proxy/Profiles/BitTorrent"_s, false);
settingsStorage->storeValue(u"Network/Proxy/Profiles/RSS"_s, false);
settingsStorage->storeValue(u"Network/Proxy/Profiles/Misc"_s, false);
}
else
{
settingsStorage->storeValue(u"Network/Proxy/Profiles/BitTorrent"_s, true); settingsStorage->storeValue(u"Network/Proxy/Profiles/BitTorrent"_s, true);
settingsStorage->storeValue(u"Network/Proxy/Profiles/RSS"_s, !onlyForTorrents); settingsStorage->storeValue(u"Network/Proxy/Profiles/RSS"_s, !onlyForTorrents);
settingsStorage->storeValue(u"Network/Proxy/Profiles/Misc"_s, !onlyForTorrents); settingsStorage->storeValue(u"Network/Proxy/Profiles/Misc"_s, !onlyForTorrents);
@ -401,7 +391,6 @@ namespace
settingsStorage->storeValue(u"Network/Proxy/Type"_s, Net::ProxyType::SOCKS5); settingsStorage->storeValue(u"Network/Proxy/Type"_s, Net::ProxyType::SOCKS5);
settingsStorage->storeValue(u"Network/Proxy/AuthEnabled"_s, true); settingsStorage->storeValue(u"Network/Proxy/AuthEnabled"_s, true);
} }
}
settingsStorage->removeValue(u"Network/Proxy/OnlyForTorrents"_s); settingsStorage->removeValue(u"Network/Proxy/OnlyForTorrents"_s);

5
src/base/bittorrent/sessionimpl.cpp

@ -1691,11 +1691,10 @@ lt::settings_pack SessionImpl::loadLTSettings() const
// proxy // proxy
settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::none); settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::none);
if (Preferences::instance()->useProxyForBT())
{
const auto *proxyManager = Net::ProxyConfigurationManager::instance(); const auto *proxyManager = Net::ProxyConfigurationManager::instance();
const Net::ProxyConfiguration proxyConfig = proxyManager->proxyConfiguration(); const Net::ProxyConfiguration proxyConfig = proxyManager->proxyConfiguration();
if ((proxyConfig.type != Net::ProxyType::None) && Preferences::instance()->useProxyForBT())
{
switch (proxyConfig.type) switch (proxyConfig.type)
{ {
case Net::ProxyType::SOCKS4: case Net::ProxyType::SOCKS4:

6
src/base/net/downloadmanager.cpp

@ -231,8 +231,9 @@ void Net::DownloadManager::applyProxySettings()
m_proxy = QNetworkProxy(QNetworkProxy::NoProxy); m_proxy = QNetworkProxy(QNetworkProxy::NoProxy);
if (proxyConfig.type != ProxyType::SOCKS4) if ((proxyConfig.type == Net::ProxyType::None) || (proxyConfig.type == ProxyType::SOCKS4))
{ return;
// Proxy enabled // Proxy enabled
if (proxyConfig.type == ProxyType::SOCKS5) if (proxyConfig.type == ProxyType::SOCKS5)
{ {
@ -261,7 +262,6 @@ void Net::DownloadManager::applyProxySettings()
else else
m_proxy.setCapabilities(m_proxy.capabilities() & ~QNetworkProxy::HostNameLookupCapability); m_proxy.setCapabilities(m_proxy.capabilities() & ~QNetworkProxy::HostNameLookupCapability);
} }
}
void Net::DownloadManager::handleDownloadFinished(DownloadHandlerImpl *finishedHandler) void Net::DownloadManager::handleDownloadFinished(DownloadHandlerImpl *finishedHandler)
{ {

10
src/base/net/proxyconfigurationmanager.cpp

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2016 Vladimir Golovnev <glassez@yandex.ru> * Copyright (C) 2016-2023 Vladimir Golovnev <glassez@yandex.ru>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -60,10 +60,10 @@ ProxyConfigurationManager::ProxyConfigurationManager(QObject *parent)
, m_storeProxyPassword {SETTINGS_KEY(u"Password"_s)} , m_storeProxyPassword {SETTINGS_KEY(u"Password"_s)}
, m_storeProxyHostnameLookupEnabled {SETTINGS_KEY(u"HostnameLookupEnabled"_s)} , m_storeProxyHostnameLookupEnabled {SETTINGS_KEY(u"HostnameLookupEnabled"_s)}
{ {
m_config.type = m_storeProxyType.get(ProxyType::HTTP); m_config.type = m_storeProxyType.get(ProxyType::None);
if ((m_config.type < ProxyType::HTTP) || (m_config.type > ProxyType::SOCKS4)) if ((m_config.type < ProxyType::None) || (m_config.type > ProxyType::SOCKS4))
m_config.type = ProxyType::HTTP; m_config.type = ProxyType::None;
m_config.ip = m_storeProxyIP.get(u"0.0.0.0"_s); m_config.ip = m_storeProxyIP.get((m_config.type == ProxyType::None) ? u""_s : u"0.0.0.0"_s);
m_config.port = m_storeProxyPort.get(8080); m_config.port = m_storeProxyPort.get(8080);
m_config.authEnabled = m_storeProxyAuthEnabled; m_config.authEnabled = m_storeProxyAuthEnabled;
m_config.username = m_storeProxyUsername; m_config.username = m_storeProxyUsername;

7
src/base/net/proxyconfigurationmanager.h

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2016 Vladimir Golovnev <glassez@yandex.ru> * Copyright (C) 2016-2023 Vladimir Golovnev <glassez@yandex.ru>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -39,6 +39,7 @@ namespace Net
enum class ProxyType enum class ProxyType
{ {
None = 0,
HTTP = 1, HTTP = 1,
SOCKS5 = 2, SOCKS5 = 2,
SOCKS4 = 5 SOCKS4 = 5
@ -47,8 +48,8 @@ namespace Net
struct ProxyConfiguration struct ProxyConfiguration
{ {
ProxyType type = ProxyType::HTTP; ProxyType type = ProxyType::None;
QString ip = u"0.0.0.0"_s; QString ip;
ushort port = 8080; ushort port = 8080;
bool authEnabled = false; bool authEnabled = false;
QString username; QString username;

2
src/base/search/searchpluginmanager.cpp

@ -396,7 +396,7 @@ void SearchPluginManager::applyProxySettings()
// 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 (Preferences::instance()->useProxyForGeneralPurposes()) if ((proxyConfig.type != Net::ProxyType::None) && Preferences::instance()->useProxyForGeneralPurposes())
{ {
switch (proxyConfig.type) switch (proxyConfig.type)
{ {

30
src/gui/optionsdialog.cpp

@ -804,6 +804,7 @@ void OptionsDialog::loadConnectionTabOptions()
const auto *proxyConfigManager = Net::ProxyConfigurationManager::instance(); const auto *proxyConfigManager = Net::ProxyConfigurationManager::instance();
const Net::ProxyConfiguration proxyConf = proxyConfigManager->proxyConfiguration(); const Net::ProxyConfiguration proxyConf = proxyConfigManager->proxyConfiguration();
m_ui->comboProxyType->addItem(tr("(None)"), QVariant::fromValue(Net::ProxyType::None));
m_ui->comboProxyType->addItem(tr("SOCKS4"), QVariant::fromValue(Net::ProxyType::SOCKS4)); m_ui->comboProxyType->addItem(tr("SOCKS4"), QVariant::fromValue(Net::ProxyType::SOCKS4));
m_ui->comboProxyType->addItem(tr("SOCKS5"), QVariant::fromValue(Net::ProxyType::SOCKS5)); m_ui->comboProxyType->addItem(tr("SOCKS5"), QVariant::fromValue(Net::ProxyType::SOCKS5));
m_ui->comboProxyType->addItem(tr("HTTP"), QVariant::fromValue(Net::ProxyType::HTTP)); m_ui->comboProxyType->addItem(tr("HTTP"), QVariant::fromValue(Net::ProxyType::HTTP));
@ -1537,10 +1538,36 @@ void OptionsDialog::toggleComboRatioLimitAct()
void OptionsDialog::adjustProxyOptions() void OptionsDialog::adjustProxyOptions()
{ {
const auto currentProxyType = m_ui->comboProxyType->currentData().value<Net::ProxyType>(); const auto currentProxyType = m_ui->comboProxyType->currentData().value<Net::ProxyType>();
const bool isAuthSupported = (currentProxyType != Net::ProxyType::SOCKS4); const bool isAuthSupported = ((currentProxyType == Net::ProxyType::SOCKS5)
|| (currentProxyType == Net::ProxyType::HTTP));
m_ui->checkProxyAuth->setEnabled(isAuthSupported); m_ui->checkProxyAuth->setEnabled(isAuthSupported);
if (currentProxyType == Net::ProxyType::None)
{
m_ui->labelProxyTypeIncompatible->setVisible(false);
m_ui->lblProxyIP->setEnabled(false);
m_ui->textProxyIP->setEnabled(false);
m_ui->lblProxyPort->setEnabled(false);
m_ui->spinProxyPort->setEnabled(false);
m_ui->checkProxyHostnameLookup->setEnabled(false);
m_ui->checkProxyRSS->setEnabled(false);
m_ui->checkProxyMisc->setEnabled(false);
m_ui->checkProxyBitTorrent->setEnabled(false);
m_ui->checkProxyPeerConnections->setEnabled(false);
}
else
{
m_ui->lblProxyIP->setEnabled(true);
m_ui->textProxyIP->setEnabled(true);
m_ui->lblProxyPort->setEnabled(true);
m_ui->spinProxyPort->setEnabled(true);
m_ui->checkProxyBitTorrent->setEnabled(true);
m_ui->checkProxyPeerConnections->setEnabled(true);
if (currentProxyType == Net::ProxyType::SOCKS4) if (currentProxyType == Net::ProxyType::SOCKS4)
{ {
m_ui->labelProxyTypeIncompatible->setVisible(true); m_ui->labelProxyTypeIncompatible->setVisible(true);
@ -1559,6 +1586,7 @@ void OptionsDialog::adjustProxyOptions()
m_ui->checkProxyMisc->setEnabled(true); m_ui->checkProxyMisc->setEnabled(true);
} }
} }
}
bool OptionsDialog::isSplashScreenDisabled() const bool OptionsDialog::isSplashScreenDisabled() const
{ {

2
src/webui/api/appcontroller.cpp

@ -619,7 +619,7 @@ void AppController::setPreferencesAction()
auto *proxyManager = Net::ProxyConfigurationManager::instance(); auto *proxyManager = Net::ProxyConfigurationManager::instance();
Net::ProxyConfiguration proxyConf = proxyManager->proxyConfiguration(); Net::ProxyConfiguration proxyConf = proxyManager->proxyConfiguration();
if (hasKey(u"proxy_type"_s)) if (hasKey(u"proxy_type"_s))
proxyConf.type = Utils::String::toEnum(it.value().toString(), Net::ProxyType::HTTP); proxyConf.type = Utils::String::toEnum(it.value().toString(), Net::ProxyType::None);
if (hasKey(u"proxy_ip"_s)) if (hasKey(u"proxy_ip"_s))
proxyConf.ip = it.value().toString(); proxyConf.ip = it.value().toString();
if (hasKey(u"proxy_port"_s)) if (hasKey(u"proxy_port"_s))

24
src/webui/www/private/views/preferences.html

@ -358,6 +358,7 @@
</td> </td>
<td> <td>
<select id="peer_proxy_type_select" onchange="qBittorrent.Preferences.updatePeerProxySettings();"> <select id="peer_proxy_type_select" onchange="qBittorrent.Preferences.updatePeerProxySettings();">
<option value="None">QBT_TR((None))QBT_TR[CONTEXT=OptionsDialog]</option>
<option value="SOCKS4">QBT_TR(SOCKS4)QBT_TR[CONTEXT=OptionsDialog]</option> <option value="SOCKS4">QBT_TR(SOCKS4)QBT_TR[CONTEXT=OptionsDialog]</option>
<option value="SOCKS5">QBT_TR(SOCKS5)QBT_TR[CONTEXT=OptionsDialog]</option> <option value="SOCKS5">QBT_TR(SOCKS5)QBT_TR[CONTEXT=OptionsDialog]</option>
<option value="HTTP">QBT_TR(HTTP)QBT_TR[CONTEXT=OptionsDialog]</option> <option value="HTTP">QBT_TR(HTTP)QBT_TR[CONTEXT=OptionsDialog]</option>
@ -380,7 +381,7 @@
<div class="formRow"> <div class="formRow">
<input type="checkbox" id="proxyHostnameLookupCheckbox" title="QBT_TR(If checked, hostname lookups are done via the proxy.)QBT_TR[CONTEXT=OptionsDialog]" /> <input type="checkbox" id="proxyHostnameLookupCheckbox" title="QBT_TR(If checked, hostname lookups are done via the proxy.)QBT_TR[CONTEXT=OptionsDialog]" />
<label for="proxyHostnameLookupCheckbox">QBT_TR(Use proxy for hostname lookup)QBT_TR[CONTEXT=OptionsDialog]</label> <label for="proxyHostnameLookupCheckbox">QBT_TR(Perform hostname lookup via proxy)QBT_TR[CONTEXT=OptionsDialog]</label>
</div> </div>
<fieldset class="settings"> <fieldset class="settings">
@ -1612,21 +1613,28 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
const updatePeerProxySettings = function() { const updatePeerProxySettings = function() {
const proxyType = $('peer_proxy_type_select').getProperty('value'); const proxyType = $('peer_proxy_type_select').getProperty('value');
const isProxyDisabled = (proxyType === "None");
const isProxySocks4 = (proxyType === "SOCKS4"); const isProxySocks4 = (proxyType === "SOCKS4");
$('peer_proxy_auth_checkbox').setProperty('disabled', isProxySocks4); $('peer_proxy_host_text').setProperty('disabled', isProxyDisabled);
$('use_peer_proxy_checkbox').setProperty('disabled', !$('proxy_bittorrent_checkbox').getProperty('checked')); $('peer_proxy_port_value').setProperty('disabled', isProxyDisabled);
$('proxyHostnameLookupCheckbox').setProperty('disabled', isProxySocks4);
$('proxy_rss_checkbox').setProperty('disabled', isProxySocks4); $('peer_proxy_auth_checkbox').setProperty('disabled', (isProxyDisabled || isProxySocks4));
$('proxy_misc_checkbox').setProperty('disabled', isProxySocks4); $('proxy_bittorrent_checkbox').setProperty('disabled', isProxyDisabled);
$('use_peer_proxy_checkbox').setProperty('disabled', (isProxyDisabled || !$('proxy_bittorrent_checkbox').getProperty('checked')));
$('proxyHostnameLookupCheckbox').setProperty('disabled', (isProxyDisabled || isProxySocks4));
$('proxy_rss_checkbox').setProperty('disabled', (isProxyDisabled || isProxySocks4));
$('proxy_misc_checkbox').setProperty('disabled', (isProxyDisabled || isProxySocks4));
updatePeerProxyAuthSettings(); updatePeerProxyAuthSettings();
}; };
const updatePeerProxyAuthSettings = function() { const updatePeerProxyAuthSettings = function() {
const proxyType = $('peer_proxy_type_select').getProperty('value');
const isProxyDisabled = (proxyType === "None");
const isPeerProxyAuthEnabled = (!$('peer_proxy_auth_checkbox').getProperty('disabled') && $('peer_proxy_auth_checkbox').getProperty('checked')); const isPeerProxyAuthEnabled = (!$('peer_proxy_auth_checkbox').getProperty('disabled') && $('peer_proxy_auth_checkbox').getProperty('checked'));
$('peer_proxy_username_text').setProperty('disabled', !isPeerProxyAuthEnabled); $('peer_proxy_username_text').setProperty('disabled', (isProxyDisabled || !isPeerProxyAuthEnabled));
$('peer_proxy_password_text').setProperty('disabled', !isPeerProxyAuthEnabled); $('peer_proxy_password_text').setProperty('disabled', (isProxyDisabled || !isPeerProxyAuthEnabled));
}; };
const updateFilterSettings = function() { const updateFilterSettings = function() {

Loading…
Cancel
Save