diff --git a/src/app/upgrade.cpp b/src/app/upgrade.cpp index 1887398ae..59e715c7f 100644 --- a/src/app/upgrade.cpp +++ b/src/app/upgrade.cpp @@ -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(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); diff --git a/src/base/bittorrent/sessionimpl.cpp b/src/base/bittorrent/sessionimpl.cpp index 75756181b..d3c2304a4 100644 --- a/src/base/bittorrent/sessionimpl.cpp +++ b/src/base/bittorrent/sessionimpl.cpp @@ -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: diff --git a/src/base/net/downloadmanager.cpp b/src/base/net/downloadmanager.cpp index 2b08d6761..7669af79f 100644 --- a/src/base/net/downloadmanager.cpp +++ b/src/base/net/downloadmanager.cpp @@ -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) diff --git a/src/base/net/proxyconfigurationmanager.cpp b/src/base/net/proxyconfigurationmanager.cpp index 292d63f10..00bc7cedd 100644 --- a/src/base/net/proxyconfigurationmanager.cpp +++ b/src/base/net/proxyconfigurationmanager.cpp @@ -1,6 +1,6 @@ /* * Bittorrent Client using Qt and libtorrent. - * Copyright (C) 2016 Vladimir Golovnev + * Copyright (C) 2016-2023 Vladimir Golovnev * * 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; diff --git a/src/base/net/proxyconfigurationmanager.h b/src/base/net/proxyconfigurationmanager.h index 72ac91bff..5444fb193 100644 --- a/src/base/net/proxyconfigurationmanager.h +++ b/src/base/net/proxyconfigurationmanager.h @@ -1,6 +1,6 @@ /* * Bittorrent Client using Qt and libtorrent. - * Copyright (C) 2016 Vladimir Golovnev + * Copyright (C) 2016-2023 Vladimir Golovnev * * 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; diff --git a/src/base/search/searchpluginmanager.cpp b/src/base/search/searchpluginmanager.cpp index d55d34931..d927006d2 100644 --- a/src/base/search/searchpluginmanager.cpp +++ b/src/base/search/searchpluginmanager.cpp @@ -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) { diff --git a/src/gui/optionsdialog.cpp b/src/gui/optionsdialog.cpp index a16fd0998..e3898f652 100644 --- a/src/gui/optionsdialog.cpp +++ b/src/gui/optionsdialog.cpp @@ -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(); - 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); + } } } diff --git a/src/webui/api/appcontroller.cpp b/src/webui/api/appcontroller.cpp index 39af043e3..1bb67cbe7 100644 --- a/src/webui/api/appcontroller.cpp +++ b/src/webui/api/appcontroller.cpp @@ -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)) diff --git a/src/webui/www/private/views/preferences.html b/src/webui/www/private/views/preferences.html index 5d8c06a2e..4c6d22a0c 100644 --- a/src/webui/www/private/views/preferences.html +++ b/src/webui/www/private/views/preferences.html @@ -358,6 +358,7 @@ - +
@@ -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() {