Skip to content
Permalink
Browse files
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
  • Loading branch information
jef committed May 8, 2010
1 parent 92e9c55 commit f6483e9df5c18d772791c56697bf24949c21c67b
@@ -79,4 +79,6 @@
%Include qgsvectorlayer.sip
%Include qgsvectoroverlay.sip

%Include qgsnetworkaccessmanager.sip

%Include symbology-ng-core.sip
@@ -0,0 +1,51 @@
/*
* \class QgsNetworkAccessManager
* \brief network access manager for QGIS
* \ingroup core
* \since 1.5
*
* This class implements the QGIS network access manager. It's a singleton
* that can be used across QGIS.
*
* Plugins can insert proxy factories and thereby redirect requests to
* individual proxies.
*
* If no proxy factories are there or none returns a proxy for an URL a
* fallback proxy can be set. There's also a exclude list that defines URLs
* that the fallback proxy should not be used for, then no proxy will be used.
*
*/

class QgsNetworkAccessManager : QNetworkAccessManager
{
%TypeHeaderCode
#include <qgsnetworkaccessmanager.h>
%End
//! returns a point to the single instance
// and creates that instance on the first call.
static QgsNetworkAccessManager *instance();

//! destructor
~QgsNetworkAccessManager();

//! insert a factory into the proxy factories list
void insertProxyFactory(QNetworkProxyFactory *factory /TransferTo/);

//! remove a factory from the proxy factories list
void removeProxyFactory(QNetworkProxyFactory *factory /TransferBack/);

//! retrieve proxy factory list
void setDiskCache( QString directory, qint64 size );

//! retrieve fall back proxy (for urls that no factory returned proxies for)
const QList<QNetworkProxyFactory *> proxyFactories() const;

//! retrieve exclude list (urls shouldn't use the fallback proxy)
const QStringList &excludeList() const;

//! retrieve fall back proxy (for urls that no factory returned proxies for)
const QNetworkProxy &fallbackProxy() const;

//! set fallback proxy and URL that shouldn't use it.
void setFallbackProxyAndExcludes( const QNetworkProxy &proxy, const QStringList &excludes );
};
@@ -75,7 +75,6 @@ SET(QGIS_APP_SRCS
qgsuniquevaluedialog.cpp
qgsvectorlayerproperties.cpp
qgsquerybuilder.cpp
qgsnetworkproxyfactory.cpp

qgsmanageconnectionsdialog.cpp

@@ -67,7 +67,8 @@
#include <QVBoxLayout>
#include <QWhatsThis>

#include <QNetworkAccessManager>
#include <qgsnetworkaccessmanager.h>

#include <QNetworkReply>
#include <QNetworkProxy>
#include <QAuthenticator>
@@ -154,7 +155,6 @@
#include "qgsattributetabledialog.h"
#include "qgsvectorfilewriter.h"
#include "qgscredentialdialog.h"
#include "qgsnetworkproxyfactory.h"
#include "qgstilescalewidget.h"

#ifdef HAVE_QWT
@@ -360,11 +360,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
: QMainWindow( parent, fl )
, mSplash( splash )
, mPythonUtils( NULL )
, mNAM( NULL )
, mpTileScaleWidget( NULL )
#if QT_VERSION >= 0x40500
, mProxyFactory( NULL )
#endif
#ifdef HAVE_QWT
, mpGpsWidget( NULL )
#endif
@@ -6523,26 +6519,15 @@ void QgisApp::showLayerProperties( QgsMapLayer *ml )

void QgisApp::namSetup()
{
if ( mNAM )
return;

mNAM = new QNetworkAccessManager( this );
QgsNetworkAccessManager *nam = QgsNetworkAccessManager::instance();

namUpdate();

connect( mNAM, SIGNAL( authenticationRequired( QNetworkReply *, QAuthenticator * ) ),
connect( nam, SIGNAL( authenticationRequired( QNetworkReply *, QAuthenticator * ) ),
this, SLOT( namAuthenticationRequired( QNetworkReply *, QAuthenticator * ) ) );

connect( mNAM, SIGNAL( proxyAuthenticationRequired( const QNetworkProxy &, QAuthenticator * ) ),
connect( nam, SIGNAL( proxyAuthenticationRequired( const QNetworkProxy &, QAuthenticator * ) ),
this, SLOT( namProxyAuthenticationRequired( const QNetworkProxy &, QAuthenticator * ) ) );

QCoreApplication::instance()->setProperty( "qgisNetworkAccessManager", qVariantFromValue<QObject*>( mNAM ) );
}

QNetworkAccessManager *QgisApp::nam()
{
namSetup();
return mNAM;
}

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

#if QT_VERSION >= 0x40500
if ( !mProxyFactory )
{
mProxyFactory = new QgsNetworkProxyFactory();
mNAM->setProxyFactory( mProxyFactory );
}
QgsNetworkAccessManager *nam = QgsNetworkAccessManager::instance();

mProxyFactory->setProxyAndExcludes( proxy, excludes );
nam->setFallbackProxyAndExcludes( proxy, excludes );

QNetworkDiskCache *cache = qobject_cast<QNetworkDiskCache*>( nam()->cache() );
QNetworkDiskCache *cache = qobject_cast<QNetworkDiskCache*>( nam->cache() );
if ( !cache )
cache = new QNetworkDiskCache( this );

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

if ( mNAM->cache() != cache )
mNAM->setCache( cache );
if ( nam->cache() != cache )
nam->setCache( cache );
#else
mNAM->setProxy( proxy );
QgsNetworkAccessManager::instance()->setProxy( proxy );
#endif
}
@@ -62,7 +62,6 @@ class QgsVectorLayer;
class QgsTileScaleWidget;

class QDomDocument;
class QNetworkAccessManager;
class QNetworkReply;
class QNetworkProxy;
class QAuthenticator;
@@ -80,10 +79,6 @@ class QgsGPSInformationWidget;
#include "qgsfeature.h"
#include "qgspoint.h"

#if QT_VERSION >= 0x40500
class QgsNetworkProxyFactory;
#endif

/*! \class QgisApp
* \brief Main window for the Qgis application
*/
@@ -174,9 +169,6 @@ class QgisApp : public QMainWindow
//! update proxy settings
void namUpdate();

//! retrieve network manager
QNetworkAccessManager *nam();

//! Helper to get a theme icon. It will fall back to the
//default theme if the active theme does not have the required
//icon.
@@ -1095,15 +1087,9 @@ class QgisApp : public QMainWindow

QgsUndoWidget* mUndoWidget;

QNetworkAccessManager *mNAM;

//! Persistent tile scale slider
QgsTileScaleWidget * mpTileScaleWidget;

#if QT_VERSION >= 0x40500
QgsNetworkProxyFactory *mProxyFactory;
#endif

int mLastComposerId;

#ifdef HAVE_QWT

This file was deleted.

This file was deleted.

@@ -23,12 +23,12 @@
#include "qgsgenericprojectionselector.h"
#include "qgscoordinatereferencesystem.h"
#include "qgstolerance.h"
#include "qgsnetworkaccessmanager.h"

#include <QFileDialog>
#include <QSettings>
#include <QColorDialog>
#include <QLocale>
#include <QNetworkAccessManager>

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

#if QT_VERSION >= 0x40500
// cache settings
QNetworkDiskCache *cache = qobject_cast<QNetworkDiskCache*>( QgisApp::instance()->nam()->cache() );
QNetworkDiskCache *cache = qobject_cast<QNetworkDiskCache*>( QgsNetworkAccessManager::instance()->cache() );
if ( cache )
{
mCacheDirectory->setText( cache->cacheDirectory() );
@@ -873,6 +873,6 @@ void QgsOptions::on_mBrowseCacheDirectory_clicked()
void QgsOptions::on_mClearCache_clicked()
{
#if QT_VERSION >= 0x40500
QgisApp::instance()->nam()->cache()->clear();
QgsNetworkAccessManager::instance()->cache()->clear();
#endif
}
@@ -33,7 +33,7 @@
#include "qgsproject.h"
#include "qgsproviderregistry.h"
#include "qgswmssourceselect.h"
#include <qgisinterface.h>
#include "qgsnetworkaccessmanager.h"

#include <QButtonGroup>
#include <QRadioButton>
@@ -47,7 +47,6 @@
#include <QSettings>
#include <QUrl>

#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>

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

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

@@ -88,6 +88,8 @@ SET(QGIS_CORE_SRCS
qgsvectorlayerundocommand.cpp
qgsvectoroverlay.cpp

qgsnetworkaccessmanager.cpp

composer/qgscomposerarrow.cpp
composer/qgscomposeritem.cpp
composer/qgscomposeritemgroup.cpp
@@ -232,6 +234,7 @@ SET(QGIS_CORE_MOC_HDRS
qgsrunprocess.h
qgsvectorlayer.h
qgsrasterdataprovider.h
qgsnetworkaccessmanager.h

composer/qgscomposerlegend.h
composer/qgscomposermap.h

0 comments on commit f6483e9

Please sign in to comment.