Skip to content

Commit

Permalink
network manager changes:
Browse files Browse the repository at this point in the history
- 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 f6483e9
Show file tree
Hide file tree
Showing 14 changed files with 300 additions and 228 deletions.
2 changes: 2 additions & 0 deletions python/core/core.sip
Expand Up @@ -79,4 +79,6 @@
%Include qgsvectorlayer.sip
%Include qgsvectoroverlay.sip

%Include qgsnetworkaccessmanager.sip

%Include symbology-ng-core.sip
51 changes: 51 additions & 0 deletions python/core/qgsnetworkaccessmanager.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 );
};
1 change: 0 additions & 1 deletion src/app/CMakeLists.txt
Expand Up @@ -75,7 +75,6 @@ SET(QGIS_APP_SRCS
qgsuniquevaluedialog.cpp
qgsvectorlayerproperties.cpp
qgsquerybuilder.cpp
qgsnetworkproxyfactory.cpp

qgsmanageconnectionsdialog.cpp

Expand Down
41 changes: 11 additions & 30 deletions src/app/qgisapp.cpp
Expand Up @@ -67,7 +67,8 @@
#include <QVBoxLayout>
#include <QWhatsThis>

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

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

#ifdef HAVE_QWT
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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 );

Expand All @@ -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
}
14 changes: 0 additions & 14 deletions src/app/qgisapp.h
Expand Up @@ -62,7 +62,6 @@ class QgsVectorLayer;
class QgsTileScaleWidget;

class QDomDocument;
class QNetworkAccessManager;
class QNetworkReply;
class QNetworkProxy;
class QAuthenticator;
Expand All @@ -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
*/
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
63 changes: 0 additions & 63 deletions src/app/qgsnetworkproxyfactory.cpp

This file was deleted.

42 changes: 0 additions & 42 deletions src/app/qgsnetworkproxyfactory.h

This file was deleted.

6 changes: 3 additions & 3 deletions src/app/qgsoptions.cpp
Expand Up @@ -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>
Expand Down Expand Up @@ -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() );
Expand Down Expand Up @@ -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
}
5 changes: 2 additions & 3 deletions src/app/qgswmssourceselect.cpp
Expand Up @@ -33,7 +33,7 @@
#include "qgsproject.h"
#include "qgsproviderregistry.h"
#include "qgswmssourceselect.h"
#include <qgisinterface.h>
#include "qgsnetworkaccessmanager.h"

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

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

Expand Down Expand Up @@ -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() ) );
}

Expand Down
3 changes: 3 additions & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -88,6 +88,8 @@ SET(QGIS_CORE_SRCS
qgsvectorlayerundocommand.cpp
qgsvectoroverlay.cpp

qgsnetworkaccessmanager.cpp

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

composer/qgscomposerlegend.h
composer/qgscomposermap.h
Expand Down

0 comments on commit f6483e9

Please sign in to comment.