Skip to content
Permalink
Browse files

WMS: don't apply proxy to a list of selected urls. Done in QgsHttpTra…

…nsaction::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/qgis@10009 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent
mhugent committed Jan 24, 2009
1 parent 5c5d707 commit 52518cbe61f433b04d11903da49510fb18ae1593
@@ -72,6 +72,21 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
QString settingProxyType = settings.value("proxy/proxyType", "DefaultProxy").toString();
mProxyTypeComboBox->setCurrentIndex(mProxyTypeComboBox->findText(settingProxyType));

//URLs excluded not going through proxies
QString proxyExcludedURLs = settings.value( "proxy/proxyExcludedUrls", "").toString();
if(!proxyExcludedURLs.isEmpty())
{
QStringList splittedUrls = proxyExcludedURLs.split("|");
QStringList::const_iterator urlIt = splittedUrls.constBegin();
for(; urlIt != splittedUrls.constEnd(); ++urlIt)
{
QListWidgetItem* newItem = new QListWidgetItem(mExcludeUrlListWidget);
newItem->setText(*urlIt);
newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
mExcludeUrlListWidget->addItem(newItem);
}
}

// set the current theme
cmbTheme->setItemText( cmbTheme->currentIndex(), settings.value( "/Themes" ).toString() );

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

//url to exclude from proxys
QString proxyExcludeString;
for(int i = 0; i < mExcludeUrlListWidget->count(); ++i)
{
if(i != 0)
{
proxyExcludeString += "|";
}
proxyExcludeString += mExcludeUrlListWidget->item(i)->text();
}
settings.setValue( "proxy/proxyExcludedUrls", proxyExcludeString);

//general settings
settings.setValue( "/Map/identifyRadius", spinBoxIdentifyValue->value() );
settings.setValue( "/qgis/showLegendClassifiers", cbxLegendClassifiers->isChecked() );
@@ -547,3 +574,19 @@ QStringList QgsOptions::i18nList()
}
return myList;
}

void QgsOptions::on_mAddUrlPushButton_clicked()
{
QListWidgetItem* newItem = new QListWidgetItem(mExcludeUrlListWidget);
newItem->setText("URL");
newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
mExcludeUrlListWidget->addItem(newItem);
mExcludeUrlListWidget->setCurrentItem(newItem);
}

void QgsOptions::on_mRemoveUrlPushButton_clicked()
{
int currentRow = mExcludeUrlListWidget->currentRow();
QListWidgetItem* itemToRemove = mExcludeUrlListWidget->takeItem(currentRow);
delete itemToRemove;
}
@@ -82,6 +82,12 @@ class QgsOptions : public QDialog, private Ui::QgsOptionsBase
*/
void on_mLineColourToolButton_clicked();

/**Add a new URL to exclude from Proxy*/
void on_mAddUrlPushButton_clicked();

/**Remove an URL to exclude from Proxy*/
void on_mRemoveUrlPushButton_clicked();

protected:
//! Populates combo box with ellipsoids
void getEllipsoidList();
@@ -27,6 +27,7 @@

#include <QApplication>
#include <QUrl>
#include <QSettings>
#include <QTimer>
#include "qgslogger.h"

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

if ( httphost.isEmpty() )
if(!QgsHttpTransaction::applyProxySettings(*http, httpurl))
{
// No proxy was specified - connect directly to host in URI
httphost = qurl.host();
httpport = qurl.port( HTTP_PORT_DEFAULT );

}
else
{
// Insert proxy username and password authentication
http->setProxy( QNetworkProxy(mProxyType, httphost, httpport, httpuser, httppass) );
//proxy enabled, read httphost and httpport from settings
QSettings settings;
httphost = settings.value( "proxy/proxyHost", "" ).toString();
httpport = settings.value( "proxy/proxyPort", "" ).toString().toInt();
}

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

bool QgsHttpTransaction::applyProxySettings(QHttp& http, const QString& url)
{
QSettings settings;
//check if proxy is enabled
bool proxyEnabled = settings.value( "proxy/proxyEnabled", false ).toBool();
if(!proxyEnabled)
{
return false;
}

//check if the url should go through proxy
QString proxyExcludedURLs = settings.value( "proxy/proxyExcludedUrls", "").toString();
if(!proxyExcludedURLs.isEmpty())
{
QStringList excludedURLs = proxyExcludedURLs.split("|");
QStringList::const_iterator exclIt = excludedURLs.constBegin();
for(; exclIt != excludedURLs.constEnd(); ++exclIt)
{
if(url.startsWith(*exclIt))
{
return false; //url does not go through proxy
}
}
}

//read type, host, port, user, passw from settings
QString proxyHost = settings.value( "proxy/proxyHost", "" ).toString();
int proxyPort = settings.value( "proxy/proxyPort", "" ).toString().toInt();
QString proxyUser = settings.value( "proxy/proxyUser", "" ).toString();
QString proxyPassword = settings.value( "proxy/proxyPassword", "" ).toString();

QString proxyTypeString = settings.value( "proxy/proxyType", "" ).toString();
QNetworkProxy::ProxyType proxyType = QNetworkProxy::NoProxy;
if(proxyTypeString == "DefaultProxy")
{
proxyType = QNetworkProxy::DefaultProxy;
}
else if(proxyTypeString == "Socks5Proxy")
{
proxyType = QNetworkProxy::Socks5Proxy;
}
else if(proxyTypeString == "HttpProxy")
{
proxyType = QNetworkProxy::HttpProxy;
}
else if(proxyTypeString == "HttpCachingProxy")
{
proxyType = QNetworkProxy::HttpCachingProxy;
}
else if(proxyTypeString == "FtpCachingProxy")
{
proxyType = QNetworkProxy::FtpCachingProxy;
}
http.setProxy( QNetworkProxy(proxyType, proxyHost, proxyPort, proxyUser, proxyPassword) );
return true;
}

void QgsHttpTransaction::abort()
{
if(http)
@@ -82,6 +82,10 @@ class CORE_EXPORT QgsHttpTransaction : public QObject
*/
QString errorString();

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


public slots:

@@ -638,6 +638,7 @@ QByteArray QgsWmsProvider::retrieveUrl( QString url )
{
QgsDebugMsg( "WMS request Url: " + url );

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



QgsHttpTransaction http(url, proxyHost, proxyPort, proxyUser, proxyPassword, proxyType );
#endif //0

QgsHttpTransaction http(url);

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

0 comments on commit 52518cb

Please sign in to comment.
You can’t perform that action at this time.