Merge pull request #18528 from glassez/proxy

Allow to use proxy per subsystem
This commit is contained in:
Vladimir Golovnev
2023-02-27 20:34:51 +03:00
committed by GitHub
29 changed files with 598 additions and 545 deletions

View File

@@ -32,6 +32,7 @@
#include <algorithm>
#include <QAction>
#include <QDateTime>
#include <QDebug>
#include <QDir>
#include <QFileDialog>
@@ -51,6 +52,7 @@
#include "base/bittorrent/torrentcontentlayout.h"
#include "base/global.h"
#include "base/net/downloadmanager.h"
#include "base/preferences.h"
#include "base/settingsstorage.h"
#include "base/torrentfileguard.h"
#include "base/utils/compare.h"
@@ -474,8 +476,9 @@ void AddNewTorrentDialog::show(const QString &source, const BitTorrent::AddTorre
{
// Launch downloader
Net::DownloadManager::instance()->download(
Net::DownloadRequest(source).limit(MAX_TORRENT_SIZE)
, dlg, &AddNewTorrentDialog::handleDownloadFinished);
Net::DownloadRequest(source).limit(MAX_TORRENT_SIZE)
, Preferences::instance()->useProxyForGeneralPurposes()
, dlg, &AddNewTorrentDialog::handleDownloadFinished);
return;
}

View File

@@ -1948,8 +1948,9 @@ void MainWindow::installPython()
const auto installerURL = u"https://www.python.org/ftp/python/3.8.10/python-3.8.10.exe"_qs;
#endif
Net::DownloadManager::instance()->download(
Net::DownloadRequest(installerURL).saveToFile(true)
, this, &MainWindow::pythonDownloadFinished);
Net::DownloadRequest(installerURL).saveToFile(true)
, Preferences::instance()->useProxyForGeneralPurposes()
, this, &MainWindow::pythonDownloadFinished);
}
void MainWindow::pythonDownloadFinished(const Net::DownloadResult &result)

View File

@@ -52,7 +52,6 @@
#include "base/rss/rss_session.h"
#include "base/torrentfileguard.h"
#include "base/torrentfileswatcher.h"
#include "base/utils/fs.h"
#include "base/utils/misc.h"
#include "base/utils/net.h"
#include "base/utils/password.h"
@@ -770,42 +769,25 @@ void OptionsDialog::loadConnectionTabOptions()
}
const auto *proxyConfigManager = Net::ProxyConfigurationManager::instance();
Net::ProxyConfiguration proxyConf = proxyConfigManager->proxyConfiguration();
using Net::ProxyType;
bool useProxyAuth = false;
switch (proxyConf.type)
{
case ProxyType::SOCKS4:
m_ui->comboProxyType->setCurrentIndex(1);
break;
const Net::ProxyConfiguration proxyConf = proxyConfigManager->proxyConfiguration();
case ProxyType::SOCKS5_PW:
useProxyAuth = true;
// fallthrough
case ProxyType::SOCKS5:
m_ui->comboProxyType->setCurrentIndex(2);
break;
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));
m_ui->comboProxyType->setCurrentIndex(m_ui->comboProxyType->findData(QVariant::fromValue(proxyConf.type)));
adjustProxyOptions();
case ProxyType::HTTP_PW:
useProxyAuth = true;
// fallthrough
case ProxyType::HTTP:
m_ui->comboProxyType->setCurrentIndex(3);
break;
default:
m_ui->comboProxyType->setCurrentIndex(0);
}
m_ui->textProxyIP->setText(proxyConf.ip);
m_ui->spinProxyPort->setValue(proxyConf.port);
m_ui->checkProxyAuth->setChecked(useProxyAuth);
m_ui->checkProxyAuth->setChecked(proxyConf.authEnabled);
m_ui->textProxyUsername->setText(proxyConf.username);
m_ui->textProxyPassword->setText(proxyConf.password);
m_ui->checkProxyHostnameLookup->setChecked(proxyConf.hostnameLookupEnabled);
m_ui->checkProxyBitTorrent->setChecked(Preferences::instance()->useProxyForBT());
m_ui->checkProxyPeerConnections->setChecked(session->isProxyPeerConnectionsEnabled());
m_ui->isProxyOnlyForTorrents->setChecked(proxyConfigManager->isProxyOnlyForTorrents());
m_ui->checkProxyHostnameLookup->setChecked(session->isProxyHostnameLookupEnabled());
enableProxy(m_ui->comboProxyType->currentIndex());
m_ui->checkProxyRSS->setChecked(Preferences::instance()->useProxyForRSS());
m_ui->checkProxyMisc->setChecked(Preferences::instance()->useProxyForGeneralPurposes());
m_ui->checkIPFilter->setChecked(session->isIPFilteringEnabled());
m_ui->textFilterPath->setDialogCaption(tr("Choose an IP filter file"));
@@ -830,14 +812,17 @@ void OptionsDialog::loadConnectionTabOptions()
connect(m_ui->spinMaxUploads, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
connect(m_ui->spinMaxUploadsPerTorrent, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
connect(m_ui->comboProxyType, qComboBoxCurrentIndexChanged, this, &ThisType::enableProxy);
connect(m_ui->comboProxyType, qComboBoxCurrentIndexChanged, this, &ThisType::adjustProxyOptions);
connect(m_ui->comboProxyType, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
connect(m_ui->textProxyIP, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
connect(m_ui->spinProxyPort, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
connect(m_ui->checkProxyBitTorrent, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->checkProxyBitTorrent, &QGroupBox::toggled, this, &ThisType::adjustProxyOptions);
connect(m_ui->checkProxyPeerConnections, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->isProxyOnlyForTorrents, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->checkProxyHostnameLookup, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->checkProxyRSS, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->checkProxyMisc, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->checkProxyAuth, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->textProxyUsername, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
@@ -868,13 +853,17 @@ void OptionsDialog::saveConnectionTabOptions() const
proxyConf.type = getProxyType();
proxyConf.ip = getProxyIp();
proxyConf.port = getProxyPort();
proxyConf.authEnabled = m_ui->checkProxyAuth->isChecked();
proxyConf.username = getProxyUsername();
proxyConf.password = getProxyPassword();
proxyConfigManager->setProxyOnlyForTorrents(m_ui->isProxyOnlyForTorrents->isChecked());
proxyConf.hostnameLookupEnabled = m_ui->checkProxyHostnameLookup->isChecked();
proxyConfigManager->setProxyConfiguration(proxyConf);
Preferences::instance()->setUseProxyForBT(m_ui->checkProxyBitTorrent->isChecked());
Preferences::instance()->setUseProxyForRSS(m_ui->checkProxyRSS->isChecked());
Preferences::instance()->setUseProxyForGeneralPurposes(m_ui->checkProxyMisc->isChecked());
session->setProxyPeerConnectionsEnabled(m_ui->checkProxyPeerConnections->isChecked());
session->setProxyHostnameLookupEnabled(m_ui->checkProxyHostnameLookup->isChecked());
// IPFilter
session->setIPFilteringEnabled(isIPFilteringEnabled());
@@ -1321,21 +1310,7 @@ bool OptionsDialog::isIPFilteringEnabled() const
Net::ProxyType OptionsDialog::getProxyType() const
{
switch (m_ui->comboProxyType->currentIndex())
{
case 1:
return Net::ProxyType::SOCKS4;
case 2:
if (isProxyAuthEnabled())
return Net::ProxyType::SOCKS5_PW;
return Net::ProxyType::SOCKS5;
case 3:
if (isProxyAuthEnabled())
return Net::ProxyType::HTTP_PW;
return Net::ProxyType::HTTP;
default:
return Net::ProxyType::None;
}
return m_ui->comboProxyType->currentData().value<Net::ProxyType>();
}
int OptionsDialog::getPort() const
@@ -1512,41 +1487,29 @@ void OptionsDialog::toggleComboRatioLimitAct()
m_ui->comboRatioLimitAct->setEnabled(m_ui->checkMaxRatio->isChecked() || m_ui->checkMaxSeedingMinutes->isChecked());
}
void OptionsDialog::enableProxy(const int index)
void OptionsDialog::adjustProxyOptions()
{
if (index >= 1)
{ // Any proxy type is used
//enable
m_ui->lblProxyIP->setEnabled(true);
m_ui->textProxyIP->setEnabled(true);
m_ui->lblProxyPort->setEnabled(true);
m_ui->spinProxyPort->setEnabled(true);
m_ui->checkProxyPeerConnections->setEnabled(true);
if (index >= 2)
{ // SOCKS5 or HTTP
m_ui->checkProxyAuth->setEnabled(true);
m_ui->isProxyOnlyForTorrents->setEnabled(true);
m_ui->checkProxyHostnameLookup->setEnabled(true);
}
else
{
m_ui->checkProxyAuth->setEnabled(false);
m_ui->isProxyOnlyForTorrents->setEnabled(false);
m_ui->isProxyOnlyForTorrents->setChecked(true);
m_ui->checkProxyHostnameLookup->setEnabled(false);
}
const auto currentProxyType = m_ui->comboProxyType->currentData().value<Net::ProxyType>();
const bool isAuthSupported = (currentProxyType != Net::ProxyType::SOCKS4);
m_ui->checkProxyAuth->setEnabled(isAuthSupported);
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
{ // No proxy
// disable
m_ui->lblProxyIP->setEnabled(false);
m_ui->textProxyIP->setEnabled(false);
m_ui->lblProxyPort->setEnabled(false);
m_ui->spinProxyPort->setEnabled(false);
m_ui->checkProxyPeerConnections->setEnabled(false);
m_ui->isProxyOnlyForTorrents->setEnabled(false);
m_ui->checkProxyHostnameLookup->setEnabled(false);
m_ui->checkProxyAuth->setEnabled(false);
{
// SOCKS5 or HTTP
m_ui->labelProxyTypeIncompatible->setVisible(false);
m_ui->checkProxyHostnameLookup->setEnabled(true);
m_ui->checkProxyRSS->setEnabled(true);
m_ui->checkProxyMisc->setEnabled(true);
}
}
@@ -1578,11 +1541,6 @@ bool OptionsDialog::isProxyEnabled() const
return m_ui->comboProxyType->currentIndex();
}
bool OptionsDialog::isProxyAuthEnabled() const
{
return m_ui->checkProxyAuth->isChecked();
}
QString OptionsDialog::getProxyIp() const
{
return m_ui->textProxyIP->text().trimmed();

View File

@@ -85,7 +85,7 @@ public slots:
void showConnectionTab();
private slots:
void enableProxy(int index);
void adjustProxyOptions();
void on_buttonBox_accepted();
void on_buttonBox_rejected();
void applySettings();
@@ -168,7 +168,6 @@ private:
int getMaxSeedingMinutes() const;
// Proxy options
bool isProxyEnabled() const;
bool isProxyAuthEnabled() const;
QString getProxyIp() const;
unsigned short getProxyPort() const;
QString getProxyUsername() const;

View File

@@ -1800,51 +1800,20 @@ readme[0-9].txt: filter 'readme1.txt', 'readme2.txt' but not 'readme10.txt'.</st
</widget>
</item>
<item>
<widget class="QComboBox" name="comboProxyType">
<item>
<property name="text">
<string>(None)</string>
</property>
</item>
<item>
<property name="text">
<string>SOCKS4</string>
</property>
</item>
<item>
<property name="text">
<string>SOCKS5</string>
</property>
</item>
<item>
<property name="text">
<string>HTTP</string>
</property>
</item>
</widget>
<widget class="QComboBox" name="comboProxyType" />
</item>
<item>
<widget class="QLabel" name="lblProxyIP">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Host:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="textProxyIP">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
<widget class="QLineEdit" name="textProxyIP" />
</item>
<item>
<widget class="QLabel" name="lblProxyPort">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Port:</string>
</property>
@@ -1852,9 +1821,6 @@ readme[0-9].txt: filter 'readme1.txt', 'readme2.txt' but not 'readme10.txt'.</st
</item>
<item>
<widget class="QSpinBox" name="spinProxyPort">
<property name="enabled">
<bool>false</bool>
</property>
<property name="minimum">
<number>1</number>
</property>
@@ -1869,38 +1835,21 @@ readme[0-9].txt: filter 'readme1.txt', 'readme2.txt' but not 'readme10.txt'.</st
</layout>
</item>
<item>
<widget class="QCheckBox" name="checkProxyPeerConnections">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Otherwise, the proxy server is only used for tracker connections</string>
<widget class="QLabel" name="labelProxyTypeIncompatible">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Use proxy for peer connections</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="isProxyOnlyForTorrents">
<property name="toolTip">
<string>RSS feeds, search engine, software updates or anything else other than torrent transfers and related operations (such as peer exchanges) will use a direct connection</string>
</property>
<property name="text">
<string>Use proxy only for torrents</string>
</property>
<property name="checked">
<bool>false</bool>
<string>Some options are incompatible with the chosen proxy type!</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkProxyHostnameLookup">
<property name="enabled">
<bool>true</bool>
</property>
<property name="toolTip">
<string>If checked, hostname lookups are done via the proxy.</string>
<string>If checked, hostname lookups are done via the proxy</string>
</property>
<property name="text">
<string>Use proxy for hostname lookups</string>
@@ -1960,6 +1909,57 @@ readme[0-9].txt: filter 'readme1.txt', 'readme2.txt' but not 'readme10.txt'.</st
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="checkProxyBitTorrent">
<property name="title">
<string>Use proxy for BitTorrent purposes</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayoutProxyBitTorrent">
<item>
<widget class="QCheckBox" name="checkProxyPeerConnections">
<property name="toolTip">
<string>Otherwise, the proxy server is only used for tracker connections</string>
</property>
<property name="text">
<string>Use proxy for peer connections</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkProxyRSS">
<property name="toolTip">
<string>RSS feeds will use proxy</string>
</property>
<property name="text">
<string>Use proxy for RSS purposes</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkProxyMisc">
<property name="toolTip">
<string>Search engine, software updates or anything else will use proxy</string>
</property>
<property name="text">
<string>Use proxy for general purposes</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@@ -3716,12 +3716,14 @@ Use ';' to split multiple entries. Can use wildcard '*'.</string>
<tabstop>comboProxyType</tabstop>
<tabstop>textProxyIP</tabstop>
<tabstop>spinProxyPort</tabstop>
<tabstop>checkProxyPeerConnections</tabstop>
<tabstop>isProxyOnlyForTorrents</tabstop>
<tabstop>checkProxyHostnameLookup</tabstop>
<tabstop>checkProxyAuth</tabstop>
<tabstop>textProxyUsername</tabstop>
<tabstop>textProxyPassword</tabstop>
<tabstop>checkProxyBitTorrent</tabstop>
<tabstop>checkProxyPeerConnections</tabstop>
<tabstop>checkProxyRSS</tabstop>
<tabstop>checkProxyMisc</tabstop>
<tabstop>checkIPFilter</tabstop>
<tabstop>textFilterPath</tabstop>
<tabstop>IpFilterRefreshBtn</tabstop>

View File

@@ -45,6 +45,7 @@
#include "base/global.h"
#include "base/net/downloadmanager.h"
#include "base/preferences.h"
#include "base/utils/version.h"
#include "base/version.h"
@@ -76,8 +77,8 @@ void ProgramUpdater::checkForUpdates() const
// Don't change this User-Agent. In case our updater goes haywire,
// the filehost can identify it and contact us.
Net::DownloadManager::instance()->download(
Net::DownloadRequest(RSS_URL).userAgent(QStringLiteral("qBittorrent/" QBT_VERSION_2 " ProgramUpdater (www.qbittorrent.org)"))
, this, &ProgramUpdater::rssDownloadFinished);
Net::DownloadRequest(RSS_URL).userAgent(QStringLiteral("qBittorrent/" QBT_VERSION_2 " ProgramUpdater (www.qbittorrent.org)"))
, Preferences::instance()->useProxyForGeneralPurposes(), this, &ProgramUpdater::rssDownloadFinished);
}
QString ProgramUpdater::getNewVersion() const

View File

@@ -38,6 +38,7 @@
#include "base/bittorrent/trackerentry.h"
#include "base/global.h"
#include "base/net/downloadmanager.h"
#include "base/preferences.h"
#include "gui/uithememanager.h"
#include "ui_trackersadditiondialog.h"
@@ -87,7 +88,8 @@ void TrackersAdditionDialog::onDownloadButtonClicked()
m_ui->downloadButton->setEnabled(false);
setCursor(Qt::WaitCursor);
Net::DownloadManager::instance()->download(url, this, &TrackersAdditionDialog::onTorrentListDownloadFinished);
Net::DownloadManager::instance()->download(url, Preferences::instance()->useProxyForGeneralPurposes()
, this, &TrackersAdditionDialog::onTorrentListDownloadFinished);
}
void TrackersAdditionDialog::onTorrentListDownloadFinished(const Net::DownloadResult &result)

View File

@@ -40,6 +40,7 @@
#include "base/global.h"
#include "base/net/downloadmanager.h"
#include "base/preferences.h"
#include "base/utils/fs.h"
#include "gui/autoexpandabledialog.h"
#include "gui/uithememanager.h"
@@ -311,8 +312,8 @@ void PluginSelectDialog::addNewPlugin(const QString &pluginName)
// Icon is missing, we must download it
using namespace Net;
DownloadManager::instance()->download(
DownloadRequest(plugin->url + u"/favicon.ico").saveToFile(true)
, this, &PluginSelectDialog::iconDownloadFinished);
DownloadRequest(plugin->url + u"/favicon.ico").saveToFile(true)
, Preferences::instance()->useProxyForGeneralPurposes(), this, &PluginSelectDialog::iconDownloadFinished);
}
item->setText(PLUGIN_VERSION, plugin->version.toString());
}

View File

@@ -658,8 +658,8 @@ void TrackerFiltersList::downloadFavicon(const QString &url)
{
if (!m_downloadTrackerFavicon) return;
Net::DownloadManager::instance()->download(
Net::DownloadRequest(url).saveToFile(true)
, this, &TrackerFiltersList::handleFavicoDownloadFinished);
Net::DownloadRequest(url).saveToFile(true), Preferences::instance()->useProxyForGeneralPurposes()
, this, &TrackerFiltersList::handleFavicoDownloadFinished);
}
void TrackerFiltersList::handleFavicoDownloadFinished(const Net::DownloadResult &result)