Skip to content

Commit aa3c2e7

Browse files
author
jef
committed
re-enable proxy exclusion
git-svn-id: http://svn.osgeo.org/qgis/trunk@13103 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 4f2d0f0 commit aa3c2e7

5 files changed

+116
-5
lines changed

src/app/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ SET(QGIS_APP_SRCS
7070
qgsuniquevaluedialog.cpp
7171
qgsvectorlayerproperties.cpp
7272
qgsquerybuilder.cpp
73+
qgsnetworkproxyfactory.cpp
7374

7475
qgsmanageconnectionsdialog.cpp
7576

src/app/qgisapp.cpp

+12-5
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
#include "qgsattributetabledialog.h"
150150
#include "qgsvectorfilewriter.h"
151151
#include "qgscredentialdialog.h"
152+
#include "qgsnetworkproxyfactory.h"
152153

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

62206221
void QgisApp::namUpdate()
62216222
{
6223+
QNetworkProxy proxy;
6224+
QStringList excludes;
6225+
62226226
QSettings settings;
62236227

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

62296234
//read type, host, port, user, passw from settings
62306235
QString proxyHost = settings.value( "proxy/proxyHost", "" ).toString();
@@ -6259,13 +6264,15 @@ void QgisApp::namUpdate()
62596264
.arg( proxyHost ).arg( proxyPort )
62606265
.arg( proxyUser ).arg( proxyPassword )
62616266
);
6262-
nam()->setProxy( QNetworkProxy( proxyType, proxyHost, proxyPort, proxyUser, proxyPassword ) );
6263-
}
6264-
else
6265-
{
6266-
nam()->setProxy( QNetworkProxy() );
6267+
proxy = QNetworkProxy( proxyType, proxyHost, proxyPort, proxyUser, proxyPassword );
62676268
}
62686269

6270+
#if QT_VERSION >= 0x40500
6271+
mNAM->setProxyFactory( new QgsNetworkProxyFactory( proxy, excludes ) );
6272+
#else
6273+
mNAM->setProxy( proxy );
6274+
#endif
6275+
62696276
QNetworkDiskCache *cache = qobject_cast<QNetworkDiskCache*>( nam()->cache() );
62706277
if ( !cache )
62716278
cache = new QNetworkDiskCache( this );

src/app/qgsnetworkproxyfactory.cpp

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/***************************************************************************
2+
qgsnetworkproxyfactory.cpp - description
3+
-------------------
4+
begin : Sat Mar 20 2010
5+
copyright : (C) 2010 by Juergen E. Fischer
6+
email : jef at norbit dot de
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
/* $Id$ */
18+
19+
#include <QtGlobal>
20+
21+
#if QT_VERSION >= 0x40500
22+
23+
#include <QSettings>
24+
#include <QUrl>
25+
26+
#include "qgsnetworkproxyfactory.h"
27+
#include "qgslogger.h"
28+
29+
QgsNetworkProxyFactory::QgsNetworkProxyFactory( const QNetworkProxy &proxy, const QStringList &excludes )
30+
{
31+
mProxy = proxy;
32+
mExcludedURLs = excludes;
33+
}
34+
35+
QgsNetworkProxyFactory::~QgsNetworkProxyFactory()
36+
{
37+
}
38+
39+
QList<QNetworkProxy> QgsNetworkProxyFactory::queryProxy( const QNetworkProxyQuery &query )
40+
{
41+
if( query.queryType() != QNetworkProxyQuery::UrlRequest )
42+
return QList<QNetworkProxy>() << mProxy;
43+
44+
QString url = query.url().toString();
45+
46+
foreach( QString exclude, mExcludedURLs )
47+
{
48+
if ( url.startsWith( exclude ) )
49+
{
50+
QgsDebugMsg( QString("using default proxy for %1 [exclude %2]").arg( url ).arg( exclude ) );
51+
return QList<QNetworkProxy>() << QNetworkProxy();
52+
}
53+
}
54+
55+
QgsDebugMsg( QString("using user proxy for %1").arg( url ) );
56+
return QList<QNetworkProxy>() << mProxy;
57+
}
58+
59+
#endif // QT_VERSION >= 0x40500

src/app/qgsnetworkproxyfactory.h

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/***************************************************************************
2+
qgsabout.h - description
3+
-------------------
4+
begin : Sat, 20 Mar 2010
5+
copyright : (C) 2010 by Juergen E. Fischer
6+
email : jef at norbit dot de
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
/* $Id:$ */
18+
#ifndef QGSNETWORKPROXYFACTORY_H
19+
#define QGSNETWORKPROXYFACTORY_H
20+
21+
#if QT_VERSION >= 0x40500
22+
23+
#include <QNetworkProxyFactory>
24+
#include <QStringList>
25+
26+
class QgsNetworkProxyFactory : public QNetworkProxyFactory
27+
{
28+
public:
29+
QgsNetworkProxyFactory( const QNetworkProxy &proxy, const QStringList &excludes );
30+
virtual ~QgsNetworkProxyFactory();
31+
virtual QList<QNetworkProxy> queryProxy( const QNetworkProxyQuery & query = QNetworkProxyQuery() );
32+
33+
private:
34+
QStringList mExcludedURLs;
35+
QNetworkProxy mProxy;
36+
};
37+
38+
#endif // QT_VERSION >= 0x40500
39+
40+
#endif

src/app/qgsoptions.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
116116
}
117117
}
118118

119+
#if QT_VERSION < 0x40500
120+
mExcludeUrlListWidget->setDisabled( true );
121+
#endif
122+
119123
// cache settings
120124
QNetworkDiskCache *cache = qobject_cast<QNetworkDiskCache*>( QgisApp::instance()->nam()->cache() );
121125
if ( cache )

0 commit comments

Comments
 (0)