mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-10 06:48:00 +00:00
Let Search Engine handle its proxy usage
This commit is contained in:
parent
8df80b67f9
commit
8993d87b32
@ -64,7 +64,6 @@ ProxyConfigurationManager::ProxyConfigurationManager(QObject *parent)
|
||||
m_config.port = m_storeProxyPort.get(8080);
|
||||
m_config.username = m_storeProxyUsername;
|
||||
m_config.password = m_storeProxyPassword;
|
||||
configureProxy();
|
||||
}
|
||||
|
||||
void ProxyConfigurationManager::initInstance()
|
||||
@ -99,7 +98,6 @@ void ProxyConfigurationManager::setProxyConfiguration(const ProxyConfiguration &
|
||||
m_storeProxyPort = config.port;
|
||||
m_storeProxyUsername = config.username;
|
||||
m_storeProxyPassword = config.password;
|
||||
configureProxy();
|
||||
|
||||
emit proxyConfigurationChanged();
|
||||
}
|
||||
@ -120,39 +118,3 @@ bool ProxyConfigurationManager::isAuthenticationRequired() const
|
||||
return m_config.type == ProxyType::SOCKS5_PW
|
||||
|| m_config.type == ProxyType::HTTP_PW;
|
||||
}
|
||||
|
||||
void ProxyConfigurationManager::configureProxy()
|
||||
{
|
||||
// Define environment variables for urllib in search engine plugins
|
||||
QString proxyStrHTTP, proxyStrSOCK;
|
||||
if (!isProxyOnlyForTorrents())
|
||||
{
|
||||
switch (m_config.type)
|
||||
{
|
||||
case ProxyType::HTTP_PW:
|
||||
proxyStrHTTP = u"http://%1:%2@%3:%4"_qs.arg(m_config.username
|
||||
, m_config.password, m_config.ip, QString::number(m_config.port));
|
||||
break;
|
||||
case ProxyType::HTTP:
|
||||
proxyStrHTTP = u"http://%1:%2"_qs.arg(m_config.ip, QString::number(m_config.port));
|
||||
break;
|
||||
case ProxyType::SOCKS5:
|
||||
proxyStrSOCK = u"%1:%2"_qs.arg(m_config.ip, QString::number(m_config.port));
|
||||
break;
|
||||
case ProxyType::SOCKS5_PW:
|
||||
proxyStrSOCK = u"%1:%2@%3:%4"_qs.arg(m_config.username
|
||||
, m_config.password, m_config.ip, QString::number(m_config.port));
|
||||
break;
|
||||
default:
|
||||
qDebug("Disabling HTTP communications proxy");
|
||||
}
|
||||
|
||||
qDebug("HTTP communications proxy string: %s"
|
||||
, qUtf8Printable((m_config.type == ProxyType::SOCKS5) || (m_config.type == ProxyType::SOCKS5_PW)
|
||||
? proxyStrSOCK : proxyStrHTTP));
|
||||
}
|
||||
|
||||
qputenv("http_proxy", proxyStrHTTP.toLocal8Bit());
|
||||
qputenv("https_proxy", proxyStrHTTP.toLocal8Bit());
|
||||
qputenv("sock_proxy", proxyStrSOCK.toLocal8Bit());
|
||||
}
|
||||
|
@ -83,8 +83,6 @@ namespace Net
|
||||
void proxyConfigurationChanged();
|
||||
|
||||
private:
|
||||
void configureProxy();
|
||||
|
||||
static ProxyConfigurationManager *m_instance;
|
||||
ProxyConfiguration m_config;
|
||||
SettingValue<bool> m_storeProxyOnlyForTorrents;
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include "base/global.h"
|
||||
#include "base/logger.h"
|
||||
#include "base/net/downloadmanager.h"
|
||||
#include "base/net/proxyconfigurationmanager.h"
|
||||
#include "base/preferences.h"
|
||||
#include "base/profile.h"
|
||||
#include "base/utils/bytearray.h"
|
||||
@ -90,6 +91,10 @@ SearchPluginManager::SearchPluginManager()
|
||||
Q_ASSERT(!m_instance); // only one instance is allowed
|
||||
m_instance = this;
|
||||
|
||||
connect(Net::ProxyConfigurationManager::instance(), &Net::ProxyConfigurationManager::proxyConfigurationChanged
|
||||
, this, &SearchPluginManager::applyProxySettings);
|
||||
applyProxySettings();
|
||||
|
||||
updateNova();
|
||||
update();
|
||||
}
|
||||
@ -378,6 +383,45 @@ Path SearchPluginManager::engineLocation()
|
||||
return location;
|
||||
}
|
||||
|
||||
void SearchPluginManager::applyProxySettings()
|
||||
{
|
||||
const auto *proxyManager = Net::ProxyConfigurationManager::instance();
|
||||
const Net::ProxyConfiguration proxyConfig = proxyManager->proxyConfiguration();
|
||||
|
||||
// Define environment variables for urllib in search engine plugins
|
||||
QString proxyStrHTTP, proxyStrSOCK;
|
||||
if (!proxyManager->isProxyOnlyForTorrents())
|
||||
{
|
||||
switch (proxyConfig.type)
|
||||
{
|
||||
case Net::ProxyType::HTTP_PW:
|
||||
proxyStrHTTP = u"http://%1:%2@%3:%4"_qs.arg(proxyConfig.username
|
||||
, proxyConfig.password, proxyConfig.ip, QString::number(proxyConfig.port));
|
||||
break;
|
||||
case Net::ProxyType::HTTP:
|
||||
proxyStrHTTP = u"http://%1:%2"_qs.arg(proxyConfig.ip, QString::number(proxyConfig.port));
|
||||
break;
|
||||
case Net::ProxyType::SOCKS5:
|
||||
proxyStrSOCK = u"%1:%2"_qs.arg(proxyConfig.ip, QString::number(proxyConfig.port));
|
||||
break;
|
||||
case Net::ProxyType::SOCKS5_PW:
|
||||
proxyStrSOCK = u"%1:%2@%3:%4"_qs.arg(proxyConfig.username
|
||||
, proxyConfig.password, proxyConfig.ip, QString::number(proxyConfig.port));
|
||||
break;
|
||||
default:
|
||||
qDebug("Disabling HTTP communications proxy");
|
||||
}
|
||||
|
||||
qDebug("HTTP communications proxy string: %s"
|
||||
, qUtf8Printable((proxyConfig.type == Net::ProxyType::SOCKS5) || (proxyConfig.type == Net::ProxyType::SOCKS5_PW)
|
||||
? proxyStrSOCK : proxyStrHTTP));
|
||||
}
|
||||
|
||||
qputenv("http_proxy", proxyStrHTTP.toLocal8Bit());
|
||||
qputenv("https_proxy", proxyStrHTTP.toLocal8Bit());
|
||||
qputenv("sock_proxy", proxyStrSOCK.toLocal8Bit());
|
||||
}
|
||||
|
||||
void SearchPluginManager::versionInfoDownloadFinished(const Net::DownloadResult &result)
|
||||
{
|
||||
if (result.status == Net::DownloadStatus::Success)
|
||||
|
@ -104,6 +104,7 @@ signals:
|
||||
void checkForUpdatesFailed(const QString &reason);
|
||||
|
||||
private:
|
||||
void applyProxySettings();
|
||||
void update();
|
||||
void updateNova();
|
||||
void parseVersionInfo(const QByteArray &info);
|
||||
|
Loading…
Reference in New Issue
Block a user