Skip to content

Commit b25bf89

Browse files
author
mhugent
committed
WMS: don't apply proxy to a list of selected urls. Done in QgsHttpTransaction::applyProxySettings so WFS & co can later also use this function. Not tested yet and still needs some cleanups
git-svn-id: http://svn.osgeo.org/qgis/trunk@10009 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 556b0a2 commit b25bf89

File tree

6 files changed

+263
-54
lines changed

6 files changed

+263
-54
lines changed

src/app/qgsoptions.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,21 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
7272
QString settingProxyType = settings.value("proxy/proxyType", "DefaultProxy").toString();
7373
mProxyTypeComboBox->setCurrentIndex(mProxyTypeComboBox->findText(settingProxyType));
7474

75+
//URLs excluded not going through proxies
76+
QString proxyExcludedURLs = settings.value( "proxy/proxyExcludedUrls", "").toString();
77+
if(!proxyExcludedURLs.isEmpty())
78+
{
79+
QStringList splittedUrls = proxyExcludedURLs.split("|");
80+
QStringList::const_iterator urlIt = splittedUrls.constBegin();
81+
for(; urlIt != splittedUrls.constEnd(); ++urlIt)
82+
{
83+
QListWidgetItem* newItem = new QListWidgetItem(mExcludeUrlListWidget);
84+
newItem->setText(*urlIt);
85+
newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
86+
mExcludeUrlListWidget->addItem(newItem);
87+
}
88+
}
89+
7590
// set the current theme
7691
cmbTheme->setItemText( cmbTheme->currentIndex(), settings.value( "/Themes" ).toString() );
7792

@@ -275,6 +290,18 @@ void QgsOptions::saveOptions()
275290
settings.setValue( "proxy/proxyPassword", leProxyPassword->text() );
276291
settings.setValue( "proxy/proxyType", mProxyTypeComboBox->currentText());
277292

293+
//url to exclude from proxys
294+
QString proxyExcludeString;
295+
for(int i = 0; i < mExcludeUrlListWidget->count(); ++i)
296+
{
297+
if(i != 0)
298+
{
299+
proxyExcludeString += "|";
300+
}
301+
proxyExcludeString += mExcludeUrlListWidget->item(i)->text();
302+
}
303+
settings.setValue( "proxy/proxyExcludedUrls", proxyExcludeString);
304+
278305
//general settings
279306
settings.setValue( "/Map/identifyRadius", spinBoxIdentifyValue->value() );
280307
settings.setValue( "/qgis/showLegendClassifiers", cbxLegendClassifiers->isChecked() );
@@ -547,3 +574,19 @@ QStringList QgsOptions::i18nList()
547574
}
548575
return myList;
549576
}
577+
578+
void QgsOptions::on_mAddUrlPushButton_clicked()
579+
{
580+
QListWidgetItem* newItem = new QListWidgetItem(mExcludeUrlListWidget);
581+
newItem->setText("URL");
582+
newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
583+
mExcludeUrlListWidget->addItem(newItem);
584+
mExcludeUrlListWidget->setCurrentItem(newItem);
585+
}
586+
587+
void QgsOptions::on_mRemoveUrlPushButton_clicked()
588+
{
589+
int currentRow = mExcludeUrlListWidget->currentRow();
590+
QListWidgetItem* itemToRemove = mExcludeUrlListWidget->takeItem(currentRow);
591+
delete itemToRemove;
592+
}

src/app/qgsoptions.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ class QgsOptions : public QDialog, private Ui::QgsOptionsBase
8282
*/
8383
void on_mLineColourToolButton_clicked();
8484

85+
/**Add a new URL to exclude from Proxy*/
86+
void on_mAddUrlPushButton_clicked();
87+
88+
/**Remove an URL to exclude from Proxy*/
89+
void on_mRemoveUrlPushButton_clicked();
90+
8591
protected:
8692
//! Populates combo box with ellipsoids
8793
void getEllipsoidList();

src/core/qgshttptransaction.cpp

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#include <QApplication>
2929
#include <QUrl>
30+
#include <QSettings>
3031
#include <QTimer>
3132
#include "qgslogger.h"
3233

@@ -97,17 +98,17 @@ bool QgsHttpTransaction::getSynchronously( QByteArray &respondedContent, int red
9798
// Set the host in the QHttp object
9899
http->setHost( qurl.host(), qurl.port( HTTP_PORT_DEFAULT ) );
99100

100-
if ( httphost.isEmpty() )
101+
if(!QgsHttpTransaction::applyProxySettings(*http, httpurl))
101102
{
102-
// No proxy was specified - connect directly to host in URI
103103
httphost = qurl.host();
104104
httpport = qurl.port( HTTP_PORT_DEFAULT );
105-
106105
}
107106
else
108107
{
109-
// Insert proxy username and password authentication
110-
http->setProxy( QNetworkProxy(mProxyType, httphost, httpport, httpuser, httppass) );
108+
//proxy enabled, read httphost and httpport from settings
109+
QSettings settings;
110+
httphost = settings.value( "proxy/proxyHost", "" ).toString();
111+
httpport = settings.value( "proxy/proxyPort", "" ).toString().toInt();
111112
}
112113

113114
// int httpid1 = http->setHost( qurl.host(), qurl.port() );
@@ -470,6 +471,63 @@ QString QgsHttpTransaction::errorString()
470471
return mError;
471472
}
472473

474+
bool QgsHttpTransaction::applyProxySettings(QHttp& http, const QString& url)
475+
{
476+
QSettings settings;
477+
//check if proxy is enabled
478+
bool proxyEnabled = settings.value( "proxy/proxyEnabled", false ).toBool();
479+
if(!proxyEnabled)
480+
{
481+
return false;
482+
}
483+
484+
//check if the url should go through proxy
485+
QString proxyExcludedURLs = settings.value( "proxy/proxyExcludedUrls", "").toString();
486+
if(!proxyExcludedURLs.isEmpty())
487+
{
488+
QStringList excludedURLs = proxyExcludedURLs.split("|");
489+
QStringList::const_iterator exclIt = excludedURLs.constBegin();
490+
for(; exclIt != excludedURLs.constEnd(); ++exclIt)
491+
{
492+
if(url.startsWith(*exclIt))
493+
{
494+
return false; //url does not go through proxy
495+
}
496+
}
497+
}
498+
499+
//read type, host, port, user, passw from settings
500+
QString proxyHost = settings.value( "proxy/proxyHost", "" ).toString();
501+
int proxyPort = settings.value( "proxy/proxyPort", "" ).toString().toInt();
502+
QString proxyUser = settings.value( "proxy/proxyUser", "" ).toString();
503+
QString proxyPassword = settings.value( "proxy/proxyPassword", "" ).toString();
504+
505+
QString proxyTypeString = settings.value( "proxy/proxyType", "" ).toString();
506+
QNetworkProxy::ProxyType proxyType = QNetworkProxy::NoProxy;
507+
if(proxyTypeString == "DefaultProxy")
508+
{
509+
proxyType = QNetworkProxy::DefaultProxy;
510+
}
511+
else if(proxyTypeString == "Socks5Proxy")
512+
{
513+
proxyType = QNetworkProxy::Socks5Proxy;
514+
}
515+
else if(proxyTypeString == "HttpProxy")
516+
{
517+
proxyType = QNetworkProxy::HttpProxy;
518+
}
519+
else if(proxyTypeString == "HttpCachingProxy")
520+
{
521+
proxyType = QNetworkProxy::HttpCachingProxy;
522+
}
523+
else if(proxyTypeString == "FtpCachingProxy")
524+
{
525+
proxyType = QNetworkProxy::FtpCachingProxy;
526+
}
527+
http.setProxy( QNetworkProxy(proxyType, proxyHost, proxyPort, proxyUser, proxyPassword) );
528+
return true;
529+
}
530+
473531
void QgsHttpTransaction::abort()
474532
{
475533
if(http)

src/core/qgshttptransaction.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ class CORE_EXPORT QgsHttpTransaction : public QObject
8282
*/
8383
QString errorString();
8484

85+
/**Apply proxy settings from QSettings to a http object
86+
@param return true if proxy settings was applied, false else*/
87+
static bool applyProxySettings(QHttp& http, const QString& url);
88+
8589

8690
public slots:
8791

src/providers/wms/qgswmsprovider.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,7 @@ QByteArray QgsWmsProvider::retrieveUrl( QString url )
638638
{
639639
QgsDebugMsg( "WMS request Url: " + url );
640640

641+
#if 0 //MH: not necessary any more
641642
//read proxy settings
642643
QSettings settings;
643644
QString proxyHost, proxyUser, proxyPassword;
@@ -675,8 +676,11 @@ QByteArray QgsWmsProvider::retrieveUrl( QString url )
675676
}
676677

677678

679+
678680
QgsHttpTransaction http(url, proxyHost, proxyPort, proxyUser, proxyPassword, proxyType );
681+
#endif //0
679682

683+
QgsHttpTransaction http(url);
680684

681685
// Do a passthrough for the status bar text
682686
connect(

0 commit comments

Comments
 (0)