mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-29 13:58:51 +03:00
Merge pull request #3561 from pmzqla/proxy-torrent
Add an option to allow the use of proxies only for torrents
This commit is contained in:
commit
25c6d8bf6b
6 changed files with 66 additions and 27 deletions
|
@ -1828,35 +1828,44 @@ void Session::setProxySettings(libt::proxy_settings proxySettings)
|
||||||
proxySettings.proxy_peer_connections = Preferences::instance()->proxyPeerConnections();
|
proxySettings.proxy_peer_connections = Preferences::instance()->proxyPeerConnections();
|
||||||
m_nativeSession->set_proxy(proxySettings);
|
m_nativeSession->set_proxy(proxySettings);
|
||||||
|
|
||||||
// Define environment variable
|
// Define environment variables for urllib in search engine plugins
|
||||||
QString proxy_str;
|
if (Preferences::instance()->isProxyOnlyForTorrents()) {
|
||||||
switch(proxySettings.type) {
|
|
||||||
case libt::proxy_settings::http_pw:
|
|
||||||
proxy_str = QString("http://%1:%2@%3:%4").arg(Utils::String::fromStdString(proxySettings.username)).arg(Utils::String::fromStdString(proxySettings.password))
|
|
||||||
.arg(Utils::String::fromStdString(proxySettings.hostname)).arg(proxySettings.port);
|
|
||||||
break;
|
|
||||||
case libt::proxy_settings::http:
|
|
||||||
proxy_str = QString("http://%1:%2").arg(Utils::String::fromStdString(proxySettings.hostname)).arg(proxySettings.port);
|
|
||||||
break;
|
|
||||||
case libt::proxy_settings::socks5:
|
|
||||||
proxy_str = QString("%1:%2").arg(Utils::String::fromStdString(proxySettings.hostname)).arg(proxySettings.port);
|
|
||||||
break;
|
|
||||||
case libt::proxy_settings::socks5_pw:
|
|
||||||
proxy_str = QString("%1:%2@%3:%4").arg(Utils::String::fromStdString(proxySettings.username)).arg(Utils::String::fromStdString(proxySettings.password))
|
|
||||||
.arg(Utils::String::fromStdString(proxySettings.hostname)).arg(proxySettings.port);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
qDebug("Disabling HTTP communications proxy");
|
|
||||||
qputenv("http_proxy", QByteArray());
|
qputenv("http_proxy", QByteArray());
|
||||||
|
qputenv("https_proxy", QByteArray());
|
||||||
qputenv("sock_proxy", QByteArray());
|
qputenv("sock_proxy", QByteArray());
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
// We need this for urllib in search engine plugins
|
else {
|
||||||
qDebug("HTTP communications proxy string: %s", qPrintable(proxy_str));
|
QString proxy_str;
|
||||||
if ((proxySettings.type == libt::proxy_settings::socks5) || (proxySettings.type == libt::proxy_settings::socks5_pw))
|
switch(proxySettings.type) {
|
||||||
qputenv("sock_proxy", proxy_str.toLocal8Bit());
|
case libt::proxy_settings::http_pw:
|
||||||
else
|
proxy_str = QString("http://%1:%2@%3:%4").arg(Utils::String::fromStdString(proxySettings.username)).arg(Utils::String::fromStdString(proxySettings.password))
|
||||||
qputenv("http_proxy", proxy_str.toLocal8Bit());
|
.arg(Utils::String::fromStdString(proxySettings.hostname)).arg(proxySettings.port);
|
||||||
|
break;
|
||||||
|
case libt::proxy_settings::http:
|
||||||
|
proxy_str = QString("http://%1:%2").arg(Utils::String::fromStdString(proxySettings.hostname)).arg(proxySettings.port);
|
||||||
|
break;
|
||||||
|
case libt::proxy_settings::socks5:
|
||||||
|
proxy_str = QString("%1:%2").arg(Utils::String::fromStdString(proxySettings.hostname)).arg(proxySettings.port);
|
||||||
|
break;
|
||||||
|
case libt::proxy_settings::socks5_pw:
|
||||||
|
proxy_str = QString("%1:%2@%3:%4").arg(Utils::String::fromStdString(proxySettings.username)).arg(Utils::String::fromStdString(proxySettings.password))
|
||||||
|
.arg(Utils::String::fromStdString(proxySettings.hostname)).arg(proxySettings.port);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
qDebug("Disabling HTTP communications proxy");
|
||||||
|
qputenv("http_proxy", QByteArray());
|
||||||
|
qputenv("https_proxy", QByteArray());
|
||||||
|
qputenv("sock_proxy", QByteArray());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
qDebug("HTTP communications proxy string: %s", qPrintable(proxy_str));
|
||||||
|
if ((proxySettings.type == libt::proxy_settings::socks5) || (proxySettings.type == libt::proxy_settings::socks5_pw))
|
||||||
|
qputenv("sock_proxy", proxy_str.toLocal8Bit());
|
||||||
|
else {
|
||||||
|
qputenv("http_proxy", proxy_str.toLocal8Bit());
|
||||||
|
qputenv("https_proxy", proxy_str.toLocal8Bit());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Will resume torrents in backup directory
|
// Will resume torrents in backup directory
|
||||||
|
|
|
@ -110,7 +110,7 @@ void DownloadManager::applyProxySettings()
|
||||||
QNetworkProxy proxy;
|
QNetworkProxy proxy;
|
||||||
const Preferences* const pref = Preferences::instance();
|
const Preferences* const pref = Preferences::instance();
|
||||||
|
|
||||||
if (pref->isProxyEnabled()) {
|
if (pref->isProxyEnabled() && !pref->isProxyOnlyForTorrents()) {
|
||||||
// Proxy enabled
|
// Proxy enabled
|
||||||
proxy.setHostName(pref->getProxyIp());
|
proxy.setHostName(pref->getProxyIp());
|
||||||
proxy.setPort(pref->getProxyPort());
|
proxy.setPort(pref->getProxyPort());
|
||||||
|
|
|
@ -832,6 +832,16 @@ void Preferences::setForceProxy(bool enabled)
|
||||||
setValue("Preferences/Connection/ProxyForce", enabled);
|
setValue("Preferences/Connection/ProxyForce", enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Preferences::setProxyOnlyForTorrents(bool enabled)
|
||||||
|
{
|
||||||
|
setValue("Preferences/Connection/ProxyOnlyForTorrents", enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Preferences::isProxyOnlyForTorrents() const
|
||||||
|
{
|
||||||
|
return value("Preferences/Connection/ProxyOnlyForTorrents", false).toBool();
|
||||||
|
}
|
||||||
|
|
||||||
// Bittorrent options
|
// Bittorrent options
|
||||||
int Preferences::getMaxConnecs() const
|
int Preferences::getMaxConnecs() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -246,6 +246,8 @@ public:
|
||||||
void setProxyPeerConnections(bool enabled);
|
void setProxyPeerConnections(bool enabled);
|
||||||
bool getForceProxy() const;
|
bool getForceProxy() const;
|
||||||
void setForceProxy(bool enabled);
|
void setForceProxy(bool enabled);
|
||||||
|
void setProxyOnlyForTorrents(bool enabled);
|
||||||
|
bool isProxyOnlyForTorrents() const;
|
||||||
|
|
||||||
// Bittorrent options
|
// Bittorrent options
|
||||||
int getMaxConnecs() const;
|
int getMaxConnecs() const;
|
||||||
|
|
|
@ -1384,6 +1384,19 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="isProxyOnlyForTorrents">
|
||||||
|
<property name="text">
|
||||||
|
<string>Use proxy only for torrents</string>
|
||||||
|
</property>
|
||||||
|
<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="checked">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGroupBox" name="checkProxyAuth">
|
<widget class="QGroupBox" name="checkProxyAuth">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
|
|
|
@ -235,6 +235,7 @@ options_imp::options_imp(QWidget *parent):
|
||||||
connect(spinProxyPort, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton()));
|
connect(spinProxyPort, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton()));
|
||||||
connect(checkProxyPeerConnecs, SIGNAL(toggled(bool)), SLOT(enableApplyButton()));
|
connect(checkProxyPeerConnecs, SIGNAL(toggled(bool)), SLOT(enableApplyButton()));
|
||||||
connect(checkForceProxy, SIGNAL(toggled(bool)), SLOT(enableApplyButton()));
|
connect(checkForceProxy, SIGNAL(toggled(bool)), SLOT(enableApplyButton()));
|
||||||
|
connect(isProxyOnlyForTorrents, SIGNAL(toggled(bool)), SLOT(enableApplyButton()));
|
||||||
connect(checkProxyAuth, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
|
connect(checkProxyAuth, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
|
||||||
connect(textProxyUsername, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
|
connect(textProxyUsername, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
|
||||||
connect(textProxyPassword, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
|
connect(textProxyPassword, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
|
||||||
|
@ -445,6 +446,7 @@ void options_imp::saveOptions() {
|
||||||
pref->setProxyPort(getProxyPort());
|
pref->setProxyPort(getProxyPort());
|
||||||
pref->setProxyPeerConnections(checkProxyPeerConnecs->isChecked());
|
pref->setProxyPeerConnections(checkProxyPeerConnecs->isChecked());
|
||||||
pref->setForceProxy(checkForceProxy->isChecked());
|
pref->setForceProxy(checkForceProxy->isChecked());
|
||||||
|
pref->setProxyOnlyForTorrents(isProxyOnlyForTorrents->isChecked());
|
||||||
pref->setProxyAuthEnabled(isProxyAuthEnabled());
|
pref->setProxyAuthEnabled(isProxyAuthEnabled());
|
||||||
pref->setProxyUsername(getProxyUsername());
|
pref->setProxyUsername(getProxyUsername());
|
||||||
pref->setProxyPassword(getProxyPassword());
|
pref->setProxyPassword(getProxyPassword());
|
||||||
|
@ -700,6 +702,7 @@ void options_imp::loadOptions() {
|
||||||
spinProxyPort->setValue(pref->getProxyPort());
|
spinProxyPort->setValue(pref->getProxyPort());
|
||||||
checkProxyPeerConnecs->setChecked(pref->proxyPeerConnections());
|
checkProxyPeerConnecs->setChecked(pref->proxyPeerConnections());
|
||||||
checkForceProxy->setChecked(pref->getForceProxy());
|
checkForceProxy->setChecked(pref->getForceProxy());
|
||||||
|
isProxyOnlyForTorrents->setChecked(pref->isProxyOnlyForTorrents());
|
||||||
checkProxyAuth->setChecked(pref->isProxyAuthEnabled());
|
checkProxyAuth->setChecked(pref->isProxyAuthEnabled());
|
||||||
textProxyUsername->setText(pref->getProxyUsername());
|
textProxyUsername->setText(pref->getProxyUsername());
|
||||||
textProxyPassword->setText(pref->getProxyPassword());
|
textProxyPassword->setText(pref->getProxyPassword());
|
||||||
|
@ -1002,6 +1005,7 @@ void options_imp::enableProxy(int index) {
|
||||||
spinProxyPort->setEnabled(true);
|
spinProxyPort->setEnabled(true);
|
||||||
checkProxyPeerConnecs->setEnabled(true);
|
checkProxyPeerConnecs->setEnabled(true);
|
||||||
checkForceProxy->setEnabled(true);
|
checkForceProxy->setEnabled(true);
|
||||||
|
isProxyOnlyForTorrents->setEnabled(true);
|
||||||
if (index > 1) {
|
if (index > 1) {
|
||||||
checkProxyAuth->setEnabled(true);
|
checkProxyAuth->setEnabled(true);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1016,6 +1020,7 @@ void options_imp::enableProxy(int index) {
|
||||||
spinProxyPort->setEnabled(false);
|
spinProxyPort->setEnabled(false);
|
||||||
checkProxyPeerConnecs->setEnabled(false);
|
checkProxyPeerConnecs->setEnabled(false);
|
||||||
checkForceProxy->setEnabled(false);
|
checkForceProxy->setEnabled(false);
|
||||||
|
isProxyOnlyForTorrents->setEnabled(false);
|
||||||
checkProxyAuth->setEnabled(false);
|
checkProxyAuth->setEnabled(false);
|
||||||
checkProxyAuth->setChecked(false);
|
checkProxyAuth->setChecked(false);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue