Skip to content

Commit f6483e9

Browse files
author
jef
committedMay 8, 2010
network manager changes:
- add QgsNetworkAccessManager to core as singleton - add support for multiple proxy factories - remove qgisNetworkAccessManager property hack - python bindings wms provider: - use QgsNetworkAccessManager - some precision changes git-svn-id: http://svn.osgeo.org/qgis/trunk@13443 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 92e9c55 commit f6483e9

14 files changed

+300
-228
lines changed
 

‎python/core/core.sip

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,6 @@
7979
%Include qgsvectorlayer.sip
8080
%Include qgsvectoroverlay.sip
8181

82+
%Include qgsnetworkaccessmanager.sip
83+
8284
%Include symbology-ng-core.sip
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* \class QgsNetworkAccessManager
3+
* \brief network access manager for QGIS
4+
* \ingroup core
5+
* \since 1.5
6+
*
7+
* This class implements the QGIS network access manager. It's a singleton
8+
* that can be used across QGIS.
9+
*
10+
* Plugins can insert proxy factories and thereby redirect requests to
11+
* individual proxies.
12+
*
13+
* If no proxy factories are there or none returns a proxy for an URL a
14+
* fallback proxy can be set. There's also a exclude list that defines URLs
15+
* that the fallback proxy should not be used for, then no proxy will be used.
16+
*
17+
*/
18+
19+
class QgsNetworkAccessManager : QNetworkAccessManager
20+
{
21+
%TypeHeaderCode
22+
#include <qgsnetworkaccessmanager.h>
23+
%End
24+
//! returns a point to the single instance
25+
// and creates that instance on the first call.
26+
static QgsNetworkAccessManager *instance();
27+
28+
//! destructor
29+
~QgsNetworkAccessManager();
30+
31+
//! insert a factory into the proxy factories list
32+
void insertProxyFactory(QNetworkProxyFactory *factory /TransferTo/);
33+
34+
//! remove a factory from the proxy factories list
35+
void removeProxyFactory(QNetworkProxyFactory *factory /TransferBack/);
36+
37+
//! retrieve proxy factory list
38+
void setDiskCache( QString directory, qint64 size );
39+
40+
//! retrieve fall back proxy (for urls that no factory returned proxies for)
41+
const QList<QNetworkProxyFactory *> proxyFactories() const;
42+
43+
//! retrieve exclude list (urls shouldn't use the fallback proxy)
44+
const QStringList &excludeList() const;
45+
46+
//! retrieve fall back proxy (for urls that no factory returned proxies for)
47+
const QNetworkProxy &fallbackProxy() const;
48+
49+
//! set fallback proxy and URL that shouldn't use it.
50+
void setFallbackProxyAndExcludes( const QNetworkProxy &proxy, const QStringList &excludes );
51+
};

‎src/app/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ SET(QGIS_APP_SRCS
7575
qgsuniquevaluedialog.cpp
7676
qgsvectorlayerproperties.cpp
7777
qgsquerybuilder.cpp
78-
qgsnetworkproxyfactory.cpp
7978

8079
qgsmanageconnectionsdialog.cpp
8180

‎src/app/qgisapp.cpp

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@
6767
#include <QVBoxLayout>
6868
#include <QWhatsThis>
6969

70-
#include <QNetworkAccessManager>
70+
#include <qgsnetworkaccessmanager.h>
71+
7172
#include <QNetworkReply>
7273
#include <QNetworkProxy>
7374
#include <QAuthenticator>
@@ -154,7 +155,6 @@
154155
#include "qgsattributetabledialog.h"
155156
#include "qgsvectorfilewriter.h"
156157
#include "qgscredentialdialog.h"
157-
#include "qgsnetworkproxyfactory.h"
158158
#include "qgstilescalewidget.h"
159159

160160
#ifdef HAVE_QWT
@@ -360,11 +360,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
360360
: QMainWindow( parent, fl )
361361
, mSplash( splash )
362362
, mPythonUtils( NULL )
363-
, mNAM( NULL )
364363
, mpTileScaleWidget( NULL )
365-
#if QT_VERSION >= 0x40500
366-
, mProxyFactory( NULL )
367-
#endif
368364
#ifdef HAVE_QWT
369365
, mpGpsWidget( NULL )
370366
#endif
@@ -6523,26 +6519,15 @@ void QgisApp::showLayerProperties( QgsMapLayer *ml )
65236519

65246520
void QgisApp::namSetup()
65256521
{
6526-
if ( mNAM )
6527-
return;
6528-
6529-
mNAM = new QNetworkAccessManager( this );
6522+
QgsNetworkAccessManager *nam = QgsNetworkAccessManager::instance();
65306523

65316524
namUpdate();
65326525

6533-
connect( mNAM, SIGNAL( authenticationRequired( QNetworkReply *, QAuthenticator * ) ),
6526+
connect( nam, SIGNAL( authenticationRequired( QNetworkReply *, QAuthenticator * ) ),
65346527
this, SLOT( namAuthenticationRequired( QNetworkReply *, QAuthenticator * ) ) );
65356528

6536-
connect( mNAM, SIGNAL( proxyAuthenticationRequired( const QNetworkProxy &, QAuthenticator * ) ),
6529+
connect( nam, SIGNAL( proxyAuthenticationRequired( const QNetworkProxy &, QAuthenticator * ) ),
65376530
this, SLOT( namProxyAuthenticationRequired( const QNetworkProxy &, QAuthenticator * ) ) );
6538-
6539-
QCoreApplication::instance()->setProperty( "qgisNetworkAccessManager", qVariantFromValue<QObject*>( mNAM ) );
6540-
}
6541-
6542-
QNetworkAccessManager *QgisApp::nam()
6543-
{
6544-
namSetup();
6545-
return mNAM;
65466531
}
65476532

65486533
void QgisApp::namAuthenticationRequired( QNetworkReply *reply, QAuthenticator *auth )
@@ -6627,15 +6612,11 @@ void QgisApp::namUpdate()
66276612
}
66286613

66296614
#if QT_VERSION >= 0x40500
6630-
if ( !mProxyFactory )
6631-
{
6632-
mProxyFactory = new QgsNetworkProxyFactory();
6633-
mNAM->setProxyFactory( mProxyFactory );
6634-
}
6615+
QgsNetworkAccessManager *nam = QgsNetworkAccessManager::instance();
66356616

6636-
mProxyFactory->setProxyAndExcludes( proxy, excludes );
6617+
nam->setFallbackProxyAndExcludes( proxy, excludes );
66376618

6638-
QNetworkDiskCache *cache = qobject_cast<QNetworkDiskCache*>( nam()->cache() );
6619+
QNetworkDiskCache *cache = qobject_cast<QNetworkDiskCache*>( nam->cache() );
66396620
if ( !cache )
66406621
cache = new QNetworkDiskCache( this );
66416622

@@ -6648,9 +6629,9 @@ void QgisApp::namUpdate()
66486629
QgsDebugMsg( QString( "cacheDirectory: %1" ).arg( cache->cacheDirectory() ) );
66496630
QgsDebugMsg( QString( "maximumCacheSize: %1" ).arg( cache->maximumCacheSize() ) );
66506631

6651-
if ( mNAM->cache() != cache )
6652-
mNAM->setCache( cache );
6632+
if ( nam->cache() != cache )
6633+
nam->setCache( cache );
66536634
#else
6654-
mNAM->setProxy( proxy );
6635+
QgsNetworkAccessManager::instance()->setProxy( proxy );
66556636
#endif
66566637
}

‎src/app/qgisapp.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ class QgsVectorLayer;
6262
class QgsTileScaleWidget;
6363

6464
class QDomDocument;
65-
class QNetworkAccessManager;
6665
class QNetworkReply;
6766
class QNetworkProxy;
6867
class QAuthenticator;
@@ -80,10 +79,6 @@ class QgsGPSInformationWidget;
8079
#include "qgsfeature.h"
8180
#include "qgspoint.h"
8281

83-
#if QT_VERSION >= 0x40500
84-
class QgsNetworkProxyFactory;
85-
#endif
86-
8782
/*! \class QgisApp
8883
* \brief Main window for the Qgis application
8984
*/
@@ -174,9 +169,6 @@ class QgisApp : public QMainWindow
174169
//! update proxy settings
175170
void namUpdate();
176171

177-
//! retrieve network manager
178-
QNetworkAccessManager *nam();
179-
180172
//! Helper to get a theme icon. It will fall back to the
181173
//default theme if the active theme does not have the required
182174
//icon.
@@ -1095,15 +1087,9 @@ class QgisApp : public QMainWindow
10951087

10961088
QgsUndoWidget* mUndoWidget;
10971089

1098-
QNetworkAccessManager *mNAM;
1099-
11001090
//! Persistent tile scale slider
11011091
QgsTileScaleWidget * mpTileScaleWidget;
11021092

1103-
#if QT_VERSION >= 0x40500
1104-
QgsNetworkProxyFactory *mProxyFactory;
1105-
#endif
1106-
11071093
int mLastComposerId;
11081094

11091095
#ifdef HAVE_QWT

‎src/app/qgsnetworkproxyfactory.cpp

Lines changed: 0 additions & 63 deletions
This file was deleted.

‎src/app/qgsnetworkproxyfactory.h

Lines changed: 0 additions & 42 deletions
This file was deleted.

‎src/app/qgsoptions.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
#include "qgsgenericprojectionselector.h"
2424
#include "qgscoordinatereferencesystem.h"
2525
#include "qgstolerance.h"
26+
#include "qgsnetworkaccessmanager.h"
2627

2728
#include <QFileDialog>
2829
#include <QSettings>
2930
#include <QColorDialog>
3031
#include <QLocale>
31-
#include <QNetworkAccessManager>
3232

3333
#if QT_VERSION >= 0x40500
3434
#include <QNetworkDiskCache>
@@ -121,7 +121,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
121121

122122
#if QT_VERSION >= 0x40500
123123
// cache settings
124-
QNetworkDiskCache *cache = qobject_cast<QNetworkDiskCache*>( QgisApp::instance()->nam()->cache() );
124+
QNetworkDiskCache *cache = qobject_cast<QNetworkDiskCache*>( QgsNetworkAccessManager::instance()->cache() );
125125
if ( cache )
126126
{
127127
mCacheDirectory->setText( cache->cacheDirectory() );
@@ -873,6 +873,6 @@ void QgsOptions::on_mBrowseCacheDirectory_clicked()
873873
void QgsOptions::on_mClearCache_clicked()
874874
{
875875
#if QT_VERSION >= 0x40500
876-
QgisApp::instance()->nam()->cache()->clear();
876+
QgsNetworkAccessManager::instance()->cache()->clear();
877877
#endif
878878
}

‎src/app/qgswmssourceselect.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include "qgsproject.h"
3434
#include "qgsproviderregistry.h"
3535
#include "qgswmssourceselect.h"
36-
#include <qgisinterface.h>
36+
#include "qgsnetworkaccessmanager.h"
3737

3838
#include <QButtonGroup>
3939
#include <QRadioButton>
@@ -47,7 +47,6 @@
4747
#include <QSettings>
4848
#include <QUrl>
4949

50-
#include <QNetworkAccessManager>
5150
#include <QNetworkRequest>
5251
#include <QNetworkReply>
5352

@@ -1051,7 +1050,7 @@ void QgsWMSSourceSelect::on_btnSearch_clicked()
10511050
QUrl url( mySearchUrl.arg( leSearchTerm->text() ) );
10521051
QgsDebugMsg( url.toString() );
10531052

1054-
QNetworkReply *r = QgisApp::instance()->nam()->get( QNetworkRequest( url ) );
1053+
QNetworkReply *r = QgsNetworkAccessManager::instance()->get( QNetworkRequest( url ) );
10551054
connect( r, SIGNAL( finished() ), SLOT( searchFinished() ) );
10561055
}
10571056

‎src/core/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ SET(QGIS_CORE_SRCS
8888
qgsvectorlayerundocommand.cpp
8989
qgsvectoroverlay.cpp
9090

91+
qgsnetworkaccessmanager.cpp
92+
9193
composer/qgscomposerarrow.cpp
9294
composer/qgscomposeritem.cpp
9395
composer/qgscomposeritemgroup.cpp
@@ -232,6 +234,7 @@ SET(QGIS_CORE_MOC_HDRS
232234
qgsrunprocess.h
233235
qgsvectorlayer.h
234236
qgsrasterdataprovider.h
237+
qgsnetworkaccessmanager.h
235238

236239
composer/qgscomposerlegend.h
237240
composer/qgscomposermap.h

0 commit comments

Comments
 (0)
Please sign in to comment.