Skip to content

Commit

Permalink
Simplified proxy settings
Browse files Browse the repository at this point in the history
Fix deprecation warnings with libtorrent v0.15.4+
  • Loading branch information
Christophe Dumez committed Nov 18, 2010
1 parent 299b0f9 commit a3db479
Show file tree
Hide file tree
Showing 10 changed files with 319 additions and 884 deletions.
1 change: 1 addition & 0 deletions Changelog
Expand Up @@ -10,6 +10,7 @@
- FEATURE: Bring up the connection settings when clicking on the connection status icon
- FEATURE: Major code refactoring and optimization
- FEATURE: Added "Amount downloaded/left" columns to transfer list
- FEATURE: Simplified proxy settings
- COSMETIC: Replaced message box by on-screen notification for download errors
- COSMETIC: Improved the torrent creation tool appearance
- OTHERS: Dropped support for Qt <= 4.4
Expand Down
27 changes: 11 additions & 16 deletions src/downloadthread.cpp
Expand Up @@ -177,31 +177,26 @@ void downloadThread::checkDownloadSize(qint64 bytesReceived, qint64 bytesTotal)

void downloadThread::applyProxySettings() {
QNetworkProxy proxy;
QIniSettings settings("qBittorrent", "qBittorrent");
int intValue = settings.value(QString::fromUtf8("Preferences/Connection/HTTPProxyType"), 0).toInt();
if(intValue > 0) {
const Preferences pref;
if(pref.isProxyEnabled()) {
// Proxy enabled
QString IP = settings.value(QString::fromUtf8("Preferences/Connection/HTTPProxy/IP"), "0.0.0.0").toString();
proxy.setHostName(IP);
QString port = settings.value(QString::fromUtf8("Preferences/Connection/HTTPProxy/Port"), 8080).toString();
qDebug("Using proxy: %s", qPrintable(IP));
proxy.setPort(port.toUShort());
proxy.setHostName(pref.getProxyIp());
proxy.setPort(pref.getProxyPort());
// Default proxy type is HTTP, we must change if it is SOCKS5
if(intValue == Proxy::SOCKS5 || intValue == Proxy::SOCKS5_PW) {
qDebug("Proxy is SOCKS5, not HTTP");
const int proxy_type = pref.getProxyType();
if(proxy_type == Proxy::SOCKS5 || proxy_type == Proxy::SOCKS5_PW) {
qDebug() << Q_FUNC_INFO << "using SOCKS proxy";
proxy.setType(QNetworkProxy::Socks5Proxy);
} else {
qDebug() << Q_FUNC_INFO << "using HTTP proxy";
proxy.setType(QNetworkProxy::HttpProxy);
}
// Authentication?
if(intValue > 2) {
if(pref.isProxyAuthEnabled()) {
qDebug("Proxy requires authentication, authenticating");
QString username = settings.value(QString::fromUtf8("Preferences/Connection/HTTPProxy/Username"), QString()).toString();
proxy.setUser(username);
QString password = settings.value(QString::fromUtf8("Preferences/Connection/HTTPProxy/Password"), QString()).toString();
proxy.setPassword(password);
proxy.setUser(pref.getProxyUsername());
proxy.setPassword(pref.getProxyPassword());
}

} else {
proxy.setType(QNetworkProxy::NoProxy);
}
Expand Down
157 changes: 27 additions & 130 deletions src/options_imp.cpp
Expand Up @@ -166,10 +166,8 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){
connect(checkMaxUploadsPerTorrent, SIGNAL(toggled(bool)), this, SLOT(enableMaxUploadsLimitPerTorrent(bool)));
connect(checkMaxRatio, SIGNAL(toggled(bool)), this, SLOT(enableMaxRatio(bool)));
// Proxy tab
connect(comboProxyType_http, SIGNAL(currentIndexChanged(int)),this, SLOT(enableHTTPProxy(int)));
connect(checkProxyAuth_http, SIGNAL(toggled(bool)), this, SLOT(enableHTTPProxyAuth(bool)));
connect(comboProxyType, SIGNAL(currentIndexChanged(int)),this, SLOT(enablePeerProxy(int)));
connect(checkProxyAuth, SIGNAL(toggled(bool)), this, SLOT(enablePeerProxyAuth(bool)));
connect(comboProxyType, SIGNAL(currentIndexChanged(int)),this, SLOT(enableProxy(int)));
connect(checkProxyAuth, SIGNAL(toggled(bool)), this, SLOT(enableProxyAuth(bool)));

// Apply button is activated when a value is changed
// General tab
Expand Down Expand Up @@ -232,12 +230,6 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){
connect(spinMaxRatio, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton()));
connect(comboRatioLimitAct, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton()));
// Proxy tab
connect(comboProxyType_http, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton()));
connect(textProxyIP_http, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
connect(spinProxyPort_http, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton()));
connect(checkProxyAuth_http, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(textProxyUsername_http, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
connect(textProxyPassword_http, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
connect(comboProxyType, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton()));
connect(textProxyIP, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
connect(spinProxyPort, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton()));
Expand Down Expand Up @@ -418,18 +410,12 @@ void options_imp::saveOptions(){
pref.setSchedulerStartTime(schedule_from->time());
pref.setSchedulerEndTime(schedule_to->time());
pref.setSchedulerDays((scheduler_days)schedule_days->currentIndex());
pref.setPeerProxyType(getPeerProxyType());
pref.setPeerProxyIp(getPeerProxyIp());
pref.setPeerProxyPort(getPeerProxyPort());
pref.setPeerProxyAuthEnabled(isPeerProxyAuthEnabled());
pref.setPeerProxyUsername(getPeerProxyUsername());
pref.setPeerProxyPassword(getPeerProxyPassword());
pref.setHTTPProxyType(getHTTPProxyType());
pref.setHTTPProxyIp(getHTTPProxyIp());
pref.setHTTPProxyPort(getHTTPProxyPort());
pref.setHTTPProxyAuthEnabled(isHTTPProxyAuthEnabled());
pref.setHTTPProxyUsername(getHTTPProxyUsername());
pref.setHTTPProxyPassword(getHTTPProxyPassword());
pref.setProxyType(getProxyType());
pref.setProxyIp(getProxyIp());
pref.setProxyPort(getProxyPort());
pref.setProxyAuthEnabled(isProxyAuthEnabled());
pref.setProxyUsername(getProxyUsername());
pref.setProxyPassword(getProxyPassword());
// End Connection preferences
// Bittorrent preferences
pref.setMaxConnecs(getMaxConnecs());
Expand Down Expand Up @@ -480,18 +466,18 @@ bool options_imp::isFilteringEnabled() const{
return checkIPFilter->isChecked();
}

int options_imp::getPeerProxyType() const{
int options_imp::getProxyType() const{
switch(comboProxyType->currentIndex()) {
case 1:
return Proxy::SOCKS4;
break;
case 2:
if(isPeerProxyAuthEnabled()){
if(isProxyAuthEnabled()){
return Proxy::SOCKS5_PW;
}
return Proxy::SOCKS5;
case 3:
if(isPeerProxyAuthEnabled()){
if(isProxyAuthEnabled()){
return Proxy::HTTP_PW;
}
return Proxy::HTTP;
Expand All @@ -500,25 +486,6 @@ int options_imp::getPeerProxyType() const{
}
}

int options_imp::getHTTPProxyType() const {
switch(comboProxyType_http->currentIndex()) {
case 1: {
if(isHTTPProxyAuthEnabled()){
return Proxy::HTTP_PW;
}
return Proxy::HTTP;
}
case 2: {
if(isHTTPProxyAuthEnabled()) {
return Proxy::SOCKS5_PW;
}
return Proxy::SOCKS5;
}
default:
return -1; // Disabled
}
}

QString options_imp::getStyle() const{
return comboStyle->itemText(comboStyle->currentIndex());
}
Expand All @@ -529,10 +496,6 @@ void options_imp::setStyle(QString style) {
comboStyle->setCurrentIndex(index);
}

bool options_imp::isHTTPProxyAuthEnabled() const{
return checkProxyAuth_http->isChecked();
}

void options_imp::loadOptions(){
int intValue;
float floatValue;
Expand Down Expand Up @@ -638,7 +601,7 @@ void options_imp::loadOptions(){
schedule_to->setTime(pref.getSchedulerEndTime());
schedule_days->setCurrentIndex((int)pref.getSchedulerDays());

intValue = pref.getPeerProxyType();
intValue = pref.getProxyType();
switch(intValue) {
case Proxy::SOCKS4:
comboProxyType->setCurrentIndex(1);
Expand All @@ -654,37 +617,16 @@ void options_imp::loadOptions(){
default:
comboProxyType->setCurrentIndex(0);
}
enablePeerProxy(comboProxyType->currentIndex());
enableProxy(comboProxyType->currentIndex());
//if(isProxyEnabled()) {
// Proxy is enabled, save settings
textProxyIP->setText(pref.getPeerProxyIp());
spinProxyPort->setValue(pref.getPeerProxyPort());
checkProxyAuth->setChecked(pref.isPeerProxyAuthEnabled());
textProxyUsername->setText(pref.getPeerProxyUsername());
textProxyPassword->setText(pref.getPeerProxyPassword());
enablePeerProxyAuth(checkProxyAuth->isChecked());
textProxyIP->setText(pref.getProxyIp());
spinProxyPort->setValue(pref.getProxyPort());
checkProxyAuth->setChecked(pref.isProxyAuthEnabled());
textProxyUsername->setText(pref.getProxyUsername());
textProxyPassword->setText(pref.getProxyPassword());
enableProxyAuth(checkProxyAuth->isChecked());
//}
intValue = pref.getHTTPProxyType();
switch(intValue) {
case Proxy::HTTP:
case Proxy::HTTP_PW:
comboProxyType_http->setCurrentIndex(1);
break;
case Proxy::SOCKS5:
case Proxy::SOCKS5_PW:
comboProxyType_http->setCurrentIndex(2);
break;
default:
comboProxyType_http->setCurrentIndex(0);
}
enableHTTPProxy(comboProxyType_http->currentIndex());
textProxyUsername_http->setText(pref.getHTTPProxyUsername());
textProxyPassword_http->setText(pref.getHTTPProxyPassword());
textProxyIP_http->setText(pref.getHTTPProxyIp());
spinProxyPort_http->setValue(pref.getHTTPProxyPort());
checkProxyAuth_http->setChecked(pref.isHTTPProxyAuthEnabled());
enableHTTPProxyAuth(checkProxyAuth_http->isChecked());
// End HTTPProxy
// End Connection preferences
// Bittorrent preferences
intValue = pref.getMaxConnecs();
Expand Down Expand Up @@ -987,7 +929,7 @@ void options_imp::enableMaxRatio(bool checked){
comboRatioLimitAct->setEnabled(checked);
}

void options_imp::enablePeerProxy(int index){
void options_imp::enableProxy(int index){
if(index){
//enable
lblProxyIP->setEnabled(true);
Expand All @@ -1011,32 +953,13 @@ void options_imp::enablePeerProxy(int index){
}
}

void options_imp::enableHTTPProxy(int index){
bool enable = (index > 0);
lblProxyIP_http->setEnabled(enable);
textProxyIP_http->setEnabled(enable);
lblProxyPort_http->setEnabled(enable);
spinProxyPort_http->setEnabled(enable);
checkProxyAuth_http->setEnabled(enable);

if(!enable)
checkProxyAuth_http->setChecked(false);
}

void options_imp::enablePeerProxyAuth(bool checked){
void options_imp::enableProxyAuth(bool checked){
lblProxyUsername->setEnabled(checked);
lblProxyPassword->setEnabled(checked);
textProxyUsername->setEnabled(checked);
textProxyPassword->setEnabled(checked);
}

void options_imp::enableHTTPProxyAuth(bool checked){
lblProxyUsername_http->setEnabled(checked);
lblProxyPassword_http->setEnabled(checked);
textProxyUsername_http->setEnabled(checked);
textProxyPassword_http->setEnabled(checked);
}

bool options_imp::isSlashScreenDisabled() const {
return !checkShowSplash->isChecked();
}
Expand All @@ -1054,62 +977,36 @@ bool options_imp::isDHTPortSameAsBT() const {
}

// Proxy settings
bool options_imp::isPeerProxyEnabled() const{
bool options_imp::isProxyEnabled() const{
return comboProxyType->currentIndex();
}

bool options_imp::isHTTPProxyEnabled() const {
return comboProxyType_http->currentIndex();
}

bool options_imp::isPeerProxyAuthEnabled() const{
bool options_imp::isProxyAuthEnabled() const{
return checkProxyAuth->isChecked();
}

QString options_imp::getPeerProxyIp() const{
QString options_imp::getProxyIp() const{
QString ip = textProxyIP->text();
ip = ip.trimmed();
return ip;
}

QString options_imp::getHTTPProxyIp() const{
QString ip = textProxyIP_http->text();
ip = ip.trimmed();
return ip;
}

unsigned short options_imp::getPeerProxyPort() const{
unsigned short options_imp::getProxyPort() const{
return spinProxyPort->value();
}

unsigned short options_imp::getHTTPProxyPort() const{
return spinProxyPort_http->value();
}

QString options_imp::getPeerProxyUsername() const{
QString options_imp::getProxyUsername() const{
QString username = textProxyUsername->text();
username = username.trimmed();
return username;
}

QString options_imp::getHTTPProxyUsername() const{
QString username = textProxyUsername_http->text();
username = username.trimmed();
return username;
}

QString options_imp::getPeerProxyPassword() const{
QString options_imp::getProxyPassword() const{
QString password = textProxyPassword->text();
password = password.trimmed();
return password;
}

QString options_imp::getHTTPProxyPassword() const{
QString password = textProxyPassword_http->text();
password = password.trimmed();
return password;
}

// Locale Settings
QString options_imp::getLocale() const{
return locales.at(comboI18n->currentIndex());
Expand Down
27 changes: 9 additions & 18 deletions src/options_imp.h
Expand Up @@ -96,20 +96,13 @@ class options_imp : public QDialog, private Ui_Preferences {
int getEncryptionSetting() const;
float getMaxRatio() const;
// Proxy options
QString getHTTPProxyIp() const;
unsigned short getHTTPProxyPort() const;
QString getHTTPProxyUsername() const;
QString getHTTPProxyPassword() const;
int getHTTPProxyType() const;
bool isPeerProxyEnabled() const;
bool isHTTPProxyEnabled() const;
bool isPeerProxyAuthEnabled() const;
bool isHTTPProxyAuthEnabled() const;
QString getPeerProxyIp() const;
unsigned short getPeerProxyPort() const;
QString getPeerProxyUsername() const;
QString getPeerProxyPassword() const;
int getPeerProxyType() const;
bool isProxyEnabled() const;
bool isProxyAuthEnabled() const;
QString getProxyIp() const;
unsigned short getProxyPort() const;
QString getProxyUsername() const;
QString getProxyPassword() const;
int getProxyType() const;
// IP Filter
bool isFilteringEnabled() const;
QString getFilter() const;
Expand All @@ -126,10 +119,8 @@ class options_imp : public QDialog, private Ui_Preferences {
protected slots:
void enableUploadLimit(bool checked);
void enableDownloadLimit(bool checked);
void enablePeerProxy(int comboIndex);
void enablePeerProxyAuth(bool checked);
void enableHTTPProxy(int comboIndex);
void enableHTTPProxyAuth(bool checked);
void enableProxy(int comboIndex);
void enableProxyAuth(bool checked);
void enableMaxConnecsLimit(bool checked);
void enableMaxConnecsLimitPerTorrent(bool checked);
void enableMaxUploadsLimitPerTorrent(bool checked);
Expand Down

0 comments on commit a3db479

Please sign in to comment.