Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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@10009 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Jan 24, 2009
1 parent 556b0a2 commit b25bf89
Show file tree
Hide file tree
Showing 6 changed files with 263 additions and 54 deletions.
43 changes: 43 additions & 0 deletions src/app/qgsoptions.cpp
Expand Up @@ -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() );

Expand Down Expand Up @@ -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() );
Expand Down Expand Up @@ -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;
}
6 changes: 6 additions & 0 deletions src/app/qgsoptions.h
Expand Up @@ -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();
Expand Down
68 changes: 63 additions & 5 deletions src/core/qgshttptransaction.cpp
Expand Up @@ -27,6 +27,7 @@

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

Expand Down Expand Up @@ -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() );
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/core/qgshttptransaction.h
Expand Up @@ -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:

Expand Down
4 changes: 4 additions & 0 deletions src/providers/wms/qgswmsprovider.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit b25bf89

Please sign in to comment.