Browse Source

Let Search Engine handle its proxy usage

adaptive-webui-19844
Vladimir Golovnev (Glassez) 2 years ago
parent
commit
8993d87b32
No known key found for this signature in database
GPG Key ID: 52A2C7DEE2DFA6F7
  1. 38
      src/base/net/proxyconfigurationmanager.cpp
  2. 2
      src/base/net/proxyconfigurationmanager.h
  3. 44
      src/base/search/searchpluginmanager.cpp
  4. 1
      src/base/search/searchpluginmanager.h

38
src/base/net/proxyconfigurationmanager.cpp

@ -64,7 +64,6 @@ ProxyConfigurationManager::ProxyConfigurationManager(QObject *parent)
m_config.port = m_storeProxyPort.get(8080); m_config.port = m_storeProxyPort.get(8080);
m_config.username = m_storeProxyUsername; m_config.username = m_storeProxyUsername;
m_config.password = m_storeProxyPassword; m_config.password = m_storeProxyPassword;
configureProxy();
} }
void ProxyConfigurationManager::initInstance() void ProxyConfigurationManager::initInstance()
@ -99,7 +98,6 @@ void ProxyConfigurationManager::setProxyConfiguration(const ProxyConfiguration &
m_storeProxyPort = config.port; m_storeProxyPort = config.port;
m_storeProxyUsername = config.username; m_storeProxyUsername = config.username;
m_storeProxyPassword = config.password; m_storeProxyPassword = config.password;
configureProxy();
emit proxyConfigurationChanged(); emit proxyConfigurationChanged();
} }
@ -120,39 +118,3 @@ bool ProxyConfigurationManager::isAuthenticationRequired() const
return m_config.type == ProxyType::SOCKS5_PW return m_config.type == ProxyType::SOCKS5_PW
|| m_config.type == ProxyType::HTTP_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());
}

2
src/base/net/proxyconfigurationmanager.h

@ -83,8 +83,6 @@ namespace Net
void proxyConfigurationChanged(); void proxyConfigurationChanged();
private: private:
void configureProxy();
static ProxyConfigurationManager *m_instance; static ProxyConfigurationManager *m_instance;
ProxyConfiguration m_config; ProxyConfiguration m_config;
SettingValue<bool> m_storeProxyOnlyForTorrents; SettingValue<bool> m_storeProxyOnlyForTorrents;

44
src/base/search/searchpluginmanager.cpp

@ -42,6 +42,7 @@
#include "base/global.h" #include "base/global.h"
#include "base/logger.h" #include "base/logger.h"
#include "base/net/downloadmanager.h" #include "base/net/downloadmanager.h"
#include "base/net/proxyconfigurationmanager.h"
#include "base/preferences.h" #include "base/preferences.h"
#include "base/profile.h" #include "base/profile.h"
#include "base/utils/bytearray.h" #include "base/utils/bytearray.h"
@ -90,6 +91,10 @@ SearchPluginManager::SearchPluginManager()
Q_ASSERT(!m_instance); // only one instance is allowed Q_ASSERT(!m_instance); // only one instance is allowed
m_instance = this; m_instance = this;
connect(Net::ProxyConfigurationManager::instance(), &Net::ProxyConfigurationManager::proxyConfigurationChanged
, this, &SearchPluginManager::applyProxySettings);
applyProxySettings();
updateNova(); updateNova();
update(); update();
} }
@ -378,6 +383,45 @@ Path SearchPluginManager::engineLocation()
return location; 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) void SearchPluginManager::versionInfoDownloadFinished(const Net::DownloadResult &result)
{ {
if (result.status == Net::DownloadStatus::Success) if (result.status == Net::DownloadStatus::Success)

1
src/base/search/searchpluginmanager.h

@ -104,6 +104,7 @@ signals:
void checkForUpdatesFailed(const QString &reason); void checkForUpdatesFailed(const QString &reason);
private: private:
void applyProxySettings();
void update(); void update();
void updateNova(); void updateNova();
void parseVersionInfo(const QByteArray &info); void parseVersionInfo(const QByteArray &info);

Loading…
Cancel
Save