Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
re-enable proxy exclusion
git-svn-id: http://svn.osgeo.org/qgis/trunk@13103 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Mar 20, 2010
1 parent 4f2d0f0 commit aa3c2e7
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -70,6 +70,7 @@ SET(QGIS_APP_SRCS
qgsuniquevaluedialog.cpp
qgsvectorlayerproperties.cpp
qgsquerybuilder.cpp
qgsnetworkproxyfactory.cpp

qgsmanageconnectionsdialog.cpp

Expand Down
17 changes: 12 additions & 5 deletions src/app/qgisapp.cpp
Expand Up @@ -149,6 +149,7 @@
#include "qgsattributetabledialog.h"
#include "qgsvectorfilewriter.h"
#include "qgscredentialdialog.h"
#include "qgsnetworkproxyfactory.h"

#ifdef HAVE_QWT
#include "qgsgpsinformationwidget.h"
Expand Down Expand Up @@ -6219,12 +6220,16 @@ void QgisApp::namProxyAuthenticationRequired( const QNetworkProxy &proxy, QAuthe

void QgisApp::namUpdate()
{
QNetworkProxy proxy;
QStringList excludes;

QSettings settings;

//check if proxy is enabled
bool proxyEnabled = settings.value( "proxy/proxyEnabled", false ).toBool();
if ( proxyEnabled )
{
excludes = settings.value( "proxy/proxyExcludedUrls", "" ).toString().split( "|", QString::SkipEmptyParts );

//read type, host, port, user, passw from settings
QString proxyHost = settings.value( "proxy/proxyHost", "" ).toString();
Expand Down Expand Up @@ -6259,13 +6264,15 @@ void QgisApp::namUpdate()
.arg( proxyHost ).arg( proxyPort )
.arg( proxyUser ).arg( proxyPassword )
);
nam()->setProxy( QNetworkProxy( proxyType, proxyHost, proxyPort, proxyUser, proxyPassword ) );
}
else
{
nam()->setProxy( QNetworkProxy() );
proxy = QNetworkProxy( proxyType, proxyHost, proxyPort, proxyUser, proxyPassword );
}

#if QT_VERSION >= 0x40500
mNAM->setProxyFactory( new QgsNetworkProxyFactory( proxy, excludes ) );
#else
mNAM->setProxy( proxy );
#endif

QNetworkDiskCache *cache = qobject_cast<QNetworkDiskCache*>( nam()->cache() );
if ( !cache )
cache = new QNetworkDiskCache( this );
Expand Down
59 changes: 59 additions & 0 deletions src/app/qgsnetworkproxyfactory.cpp
@@ -0,0 +1,59 @@
/***************************************************************************
qgsnetworkproxyfactory.cpp - description
-------------------
begin : Sat Mar 20 2010
copyright : (C) 2010 by Juergen E. Fischer
email : jef at norbit dot de
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/* $Id$ */

#include <QtGlobal>

#if QT_VERSION >= 0x40500

#include <QSettings>
#include <QUrl>

#include "qgsnetworkproxyfactory.h"
#include "qgslogger.h"

QgsNetworkProxyFactory::QgsNetworkProxyFactory( const QNetworkProxy &proxy, const QStringList &excludes )
{
mProxy = proxy;
mExcludedURLs = excludes;
}

QgsNetworkProxyFactory::~QgsNetworkProxyFactory()
{
}

QList<QNetworkProxy> QgsNetworkProxyFactory::queryProxy( const QNetworkProxyQuery &query )
{
if( query.queryType() != QNetworkProxyQuery::UrlRequest )
return QList<QNetworkProxy>() << mProxy;

QString url = query.url().toString();

foreach( QString exclude, mExcludedURLs )
{
if ( url.startsWith( exclude ) )
{
QgsDebugMsg( QString("using default proxy for %1 [exclude %2]").arg( url ).arg( exclude ) );
return QList<QNetworkProxy>() << QNetworkProxy();
}
}

QgsDebugMsg( QString("using user proxy for %1").arg( url ) );
return QList<QNetworkProxy>() << mProxy;
}

#endif // QT_VERSION >= 0x40500
40 changes: 40 additions & 0 deletions src/app/qgsnetworkproxyfactory.h
@@ -0,0 +1,40 @@
/***************************************************************************
qgsabout.h - description
-------------------
begin : Sat, 20 Mar 2010
copyright : (C) 2010 by Juergen E. Fischer
email : jef at norbit dot de
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/* $Id:$ */
#ifndef QGSNETWORKPROXYFACTORY_H
#define QGSNETWORKPROXYFACTORY_H

#if QT_VERSION >= 0x40500

#include <QNetworkProxyFactory>
#include <QStringList>

class QgsNetworkProxyFactory : public QNetworkProxyFactory
{
public:
QgsNetworkProxyFactory( const QNetworkProxy &proxy, const QStringList &excludes );
virtual ~QgsNetworkProxyFactory();
virtual QList<QNetworkProxy> queryProxy( const QNetworkProxyQuery & query = QNetworkProxyQuery() );

private:
QStringList mExcludedURLs;
QNetworkProxy mProxy;
};

#endif // QT_VERSION >= 0x40500

#endif
4 changes: 4 additions & 0 deletions src/app/qgsoptions.cpp
Expand Up @@ -116,6 +116,10 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
}
}

#if QT_VERSION < 0x40500
mExcludeUrlListWidget->setDisabled( true );
#endif

// cache settings
QNetworkDiskCache *cache = qobject_cast<QNetworkDiskCache*>( QgisApp::instance()->nam()->cache() );
if ( cache )
Expand Down

0 comments on commit aa3c2e7

Please sign in to comment.