Allow to globally disable the use of proxy

PR #19273.
Closes #19141.
This commit is contained in:
Vladimir Golovnev 2023-07-04 09:27:46 +03:00 committed by GitHub
parent 66e533f505
commit 7ec80263e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 105 additions and 80 deletions

View file

@ -344,7 +344,7 @@ namespace
switch (number)
{
case 0:
settingsStorage->storeValue(key, u"None"_s);
settingsStorage->storeValue(key, Net::ProxyType::None);
break;
case 1:
settingsStorage->storeValue(key, Net::ProxyType::HTTP);
@ -363,7 +363,7 @@ namespace
break;
default:
LogMsg(QCoreApplication::translate("Upgrade", "Invalid value found in configuration file, reverting it to default. Key: \"%1\". Invalid value: \"%2\".")
.arg(key, QString::number(number)), Log::WARNING);
.arg(key, QString::number(number)), Log::WARNING);
settingsStorage->removeValue(key);
break;
}
@ -377,30 +377,19 @@ namespace
const auto onlyForTorrents = settingsStorage->loadValue<bool>(u"Network/Proxy/OnlyForTorrents"_s)
|| (proxyType == u"SOCKS4");
if (proxyType == u"None")
settingsStorage->storeValue(u"Network/Proxy/Profiles/BitTorrent"_s, true);
settingsStorage->storeValue(u"Network/Proxy/Profiles/RSS"_s, !onlyForTorrents);
settingsStorage->storeValue(u"Network/Proxy/Profiles/Misc"_s, !onlyForTorrents);
if (proxyType == u"HTTP_PW"_s)
{
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);
settingsStorage->storeValue(u"Network/Proxy/AuthEnabled"_s, true);
}
else
else if (proxyType == u"SOCKS5_PW"_s)
{
settingsStorage->storeValue(u"Network/Proxy/Profiles/BitTorrent"_s, true);
settingsStorage->storeValue(u"Network/Proxy/Profiles/RSS"_s, !onlyForTorrents);
settingsStorage->storeValue(u"Network/Proxy/Profiles/Misc"_s, !onlyForTorrents);
if (proxyType == u"HTTP_PW"_s)
{
settingsStorage->storeValue(u"Network/Proxy/Type"_s, Net::ProxyType::HTTP);
settingsStorage->storeValue(u"Network/Proxy/AuthEnabled"_s, true);
}
else if (proxyType == u"SOCKS5_PW"_s)
{
settingsStorage->storeValue(u"Network/Proxy/Type"_s, Net::ProxyType::SOCKS5);
settingsStorage->storeValue(u"Network/Proxy/AuthEnabled"_s, true);
}
settingsStorage->storeValue(u"Network/Proxy/Type"_s, Net::ProxyType::SOCKS5);
settingsStorage->storeValue(u"Network/Proxy/AuthEnabled"_s, true);
}
settingsStorage->removeValue(u"Network/Proxy/OnlyForTorrents"_s);

View file

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

View file

@ -231,36 +231,36 @@ void Net::DownloadManager::applyProxySettings()
m_proxy = QNetworkProxy(QNetworkProxy::NoProxy);
if (proxyConfig.type != ProxyType::SOCKS4)
if ((proxyConfig.type == Net::ProxyType::None) || (proxyConfig.type == ProxyType::SOCKS4))
return;
// Proxy enabled
if (proxyConfig.type == ProxyType::SOCKS5)
{
// Proxy enabled
if (proxyConfig.type == ProxyType::SOCKS5)
{
qDebug() << Q_FUNC_INFO << "using SOCKS proxy";
m_proxy.setType(QNetworkProxy::Socks5Proxy);
}
else
{
qDebug() << Q_FUNC_INFO << "using HTTP proxy";
m_proxy.setType(QNetworkProxy::HttpProxy);
}
m_proxy.setHostName(proxyConfig.ip);
m_proxy.setPort(proxyConfig.port);
// Authentication?
if (proxyConfig.authEnabled)
{
qDebug("Proxy requires authentication, authenticating...");
m_proxy.setUser(proxyConfig.username);
m_proxy.setPassword(proxyConfig.password);
}
if (proxyConfig.hostnameLookupEnabled)
m_proxy.setCapabilities(m_proxy.capabilities() | QNetworkProxy::HostNameLookupCapability);
else
m_proxy.setCapabilities(m_proxy.capabilities() & ~QNetworkProxy::HostNameLookupCapability);
qDebug() << Q_FUNC_INFO << "using SOCKS proxy";
m_proxy.setType(QNetworkProxy::Socks5Proxy);
}
else
{
qDebug() << Q_FUNC_INFO << "using HTTP proxy";
m_proxy.setType(QNetworkProxy::HttpProxy);
}
m_proxy.setHostName(proxyConfig.ip);
m_proxy.setPort(proxyConfig.port);
// Authentication?
if (proxyConfig.authEnabled)
{
qDebug("Proxy requires authentication, authenticating...");
m_proxy.setUser(proxyConfig.username);
m_proxy.setPassword(proxyConfig.password);
}
if (proxyConfig.hostnameLookupEnabled)
m_proxy.setCapabilities(m_proxy.capabilities() | QNetworkProxy::HostNameLookupCapability);
else
m_proxy.setCapabilities(m_proxy.capabilities() & ~QNetworkProxy::HostNameLookupCapability);
}
void Net::DownloadManager::handleDownloadFinished(DownloadHandlerImpl *finishedHandler)

View file

@ -1,6 +1,6 @@
/*
* 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
* 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_storeProxyHostnameLookupEnabled {SETTINGS_KEY(u"HostnameLookupEnabled"_s)}
{
m_config.type = m_storeProxyType.get(ProxyType::HTTP);
if ((m_config.type < ProxyType::HTTP) || (m_config.type > ProxyType::SOCKS4))
m_config.type = ProxyType::HTTP;
m_config.ip = m_storeProxyIP.get(u"0.0.0.0"_s);
m_config.type = m_storeProxyType.get(ProxyType::None);
if ((m_config.type < ProxyType::None) || (m_config.type > ProxyType::SOCKS4))
m_config.type = ProxyType::None;
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.authEnabled = m_storeProxyAuthEnabled;
m_config.username = m_storeProxyUsername;

View file

@ -1,6 +1,6 @@
/*
* 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
* modify it under the terms of the GNU General Public License
@ -39,6 +39,7 @@ namespace Net
enum class ProxyType
{
None = 0,
HTTP = 1,
SOCKS5 = 2,
SOCKS4 = 5
@ -47,8 +48,8 @@ namespace Net
struct ProxyConfiguration
{
ProxyType type = ProxyType::HTTP;
QString ip = u"0.0.0.0"_s;
ProxyType type = ProxyType::None;
QString ip;
ushort port = 8080;
bool authEnabled = false;
QString username;

View file

@ -396,7 +396,7 @@ void SearchPluginManager::applyProxySettings()
// Define environment variables for urllib in search engine plugins
QString proxyStrHTTP, proxyStrSOCK;
if (Preferences::instance()->useProxyForGeneralPurposes())
if ((proxyConfig.type != Net::ProxyType::None) && Preferences::instance()->useProxyForGeneralPurposes())
{
switch (proxyConfig.type)
{

View file

@ -804,6 +804,7 @@ void OptionsDialog::loadConnectionTabOptions()
const auto *proxyConfigManager = Net::ProxyConfigurationManager::instance();
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("SOCKS5"), QVariant::fromValue(Net::ProxyType::SOCKS5));
m_ui->comboProxyType->addItem(tr("HTTP"), QVariant::fromValue(Net::ProxyType::HTTP));
@ -1537,26 +1538,53 @@ void OptionsDialog::toggleComboRatioLimitAct()
void OptionsDialog::adjustProxyOptions()
{
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);
if (currentProxyType == Net::ProxyType::SOCKS4)
if (currentProxyType == Net::ProxyType::None)
{
m_ui->labelProxyTypeIncompatible->setVisible(true);
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
{
// SOCKS5 or HTTP
m_ui->labelProxyTypeIncompatible->setVisible(false);
m_ui->lblProxyIP->setEnabled(true);
m_ui->textProxyIP->setEnabled(true);
m_ui->lblProxyPort->setEnabled(true);
m_ui->spinProxyPort->setEnabled(true);
m_ui->checkProxyHostnameLookup->setEnabled(true);
m_ui->checkProxyRSS->setEnabled(true);
m_ui->checkProxyMisc->setEnabled(true);
m_ui->checkProxyBitTorrent->setEnabled(true);
m_ui->checkProxyPeerConnections->setEnabled(true);
if (currentProxyType == Net::ProxyType::SOCKS4)
{
m_ui->labelProxyTypeIncompatible->setVisible(true);
m_ui->checkProxyHostnameLookup->setEnabled(false);
m_ui->checkProxyRSS->setEnabled(false);
m_ui->checkProxyMisc->setEnabled(false);
}
else
{
// SOCKS5 or HTTP
m_ui->labelProxyTypeIncompatible->setVisible(false);
m_ui->checkProxyHostnameLookup->setEnabled(true);
m_ui->checkProxyRSS->setEnabled(true);
m_ui->checkProxyMisc->setEnabled(true);
}
}
}

View file

@ -619,7 +619,7 @@ void AppController::setPreferencesAction()
auto *proxyManager = Net::ProxyConfigurationManager::instance();
Net::ProxyConfiguration proxyConf = proxyManager->proxyConfiguration();
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))
proxyConf.ip = it.value().toString();
if (hasKey(u"proxy_port"_s))

View file

@ -358,6 +358,7 @@
</td>
<td>
<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="SOCKS5">QBT_TR(SOCKS5)QBT_TR[CONTEXT=OptionsDialog]</option>
<option value="HTTP">QBT_TR(HTTP)QBT_TR[CONTEXT=OptionsDialog]</option>
@ -380,7 +381,7 @@
<div class="formRow">
<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>
<fieldset class="settings">
@ -1612,21 +1613,28 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
const updatePeerProxySettings = function() {
const proxyType = $('peer_proxy_type_select').getProperty('value');
const isProxyDisabled = (proxyType === "None");
const isProxySocks4 = (proxyType === "SOCKS4");
$('peer_proxy_auth_checkbox').setProperty('disabled', isProxySocks4);
$('use_peer_proxy_checkbox').setProperty('disabled', !$('proxy_bittorrent_checkbox').getProperty('checked'));
$('proxyHostnameLookupCheckbox').setProperty('disabled', isProxySocks4);
$('proxy_rss_checkbox').setProperty('disabled', isProxySocks4);
$('proxy_misc_checkbox').setProperty('disabled', isProxySocks4);
$('peer_proxy_host_text').setProperty('disabled', isProxyDisabled);
$('peer_proxy_port_value').setProperty('disabled', isProxyDisabled);
$('peer_proxy_auth_checkbox').setProperty('disabled', (isProxyDisabled || 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();
};
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'));
$('peer_proxy_username_text').setProperty('disabled', !isPeerProxyAuthEnabled);
$('peer_proxy_password_text').setProperty('disabled', !isPeerProxyAuthEnabled);
$('peer_proxy_username_text').setProperty('disabled', (isProxyDisabled || !isPeerProxyAuthEnabled));
$('peer_proxy_password_text').setProperty('disabled', (isProxyDisabled || !isPeerProxyAuthEnabled));
};
const updateFilterSettings = function() {