4545#include < QMenuBar>
4646#include < QMenuItem>
4747#include < QMessageBox>
48- #include < QNetworkProxy>
4948#include < QPainter>
5049#include < QPictureIO>
5150#include < QPixmap>
6766#include < QToolButton>
6867#include < QVBoxLayout>
6968#include < QWhatsThis>
69+
70+ #include < QNetworkAccessManager>
71+ #include < QNetworkDiskCache>
72+ #include < QNetworkReply>
73+ #include < QNetworkProxy>
74+ #include < QAuthenticator>
75+
7076//
7177// Mac OS X Includes
7278// Must include before GEOS 3 due to unqualified use of 'Point'
@@ -328,12 +334,12 @@ QgisApp *QgisApp::smInstance = 0;
328334
329335// constructor starts here
330336QgisApp::QgisApp ( QSplashScreen *splash, bool restorePlugins, QWidget * parent, Qt::WFlags fl )
331- : QMainWindow( parent, fl ),
332- mSplash( splash ),
333- mPythonUtils( NULL )
337+ : QMainWindow( parent, fl )
338+ , mSplash( splash )
339+ , mPythonUtils( NULL )
340+ , mNAM( NULL )
334341#ifdef HAVE_QWT
335- ,
336- mpGpsWidget ( NULL )
342+ , mpGpsWidget( NULL )
337343#endif
338344{
339345 if ( smInstance )
@@ -347,6 +353,8 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
347353
348354 smInstance = this ;
349355
356+ namSetup ();
357+
350358// setupUi(this);
351359 resize ( 640 , 480 );
352360
@@ -1841,6 +1849,9 @@ void QgisApp::setupConnections()
18411849 connect ( mMapCanvas , SIGNAL ( layersChanged () ), this , SLOT ( markDirty () ) );
18421850 connect ( mMapLegend , SIGNAL ( zOrderChanged () ), this , SLOT ( markDirty () ) );
18431851
1852+ connect ( QgsMapLayerRegistry::instance (), SIGNAL ( layerWasAdded ( QgsMapLayer * ) ),
1853+ this , SLOT ( layerWasAdded ( QgsMapLayer * ) ) );
1854+
18441855 connect ( mRenderSuppressionCBox , SIGNAL ( toggled ( bool ) ), mMapCanvas , SLOT ( setRenderFlag ( bool ) ) );
18451856 //
18461857 // Do we really need this ??? - its already connected to the esc key...TS
@@ -4468,11 +4479,7 @@ void QgisApp::loadPythonSupport()
44684479#endif
44694480 QString version = QString ( " %1.%2.%3" ).arg ( QGis::QGIS_VERSION_INT / 10000 ).arg ( QGis::QGIS_VERSION_INT / 100 % 100 ).arg ( QGis::QGIS_VERSION_INT % 100 );
44704481 QgsDebugMsg ( QString ( " load library %1 (%2)" ).arg ( pythonlibName ).arg ( version ) );
4471- #if QT_VERSION >= 0x040400
44724482 QLibrary pythonlib ( pythonlibName, version );
4473- #else
4474- QLibrary pythonlib ( pythonlibName );
4475- #endif
44764483 // It's necessary to set these two load hints, otherwise Python library won't work correctly
44774484 // see http://lists.kde.org/?l=pykde&m=117190116820758&w=2
44784485 pythonlib.setLoadHints ( QLibrary::ResolveAllSymbolsHint | QLibrary::ExportExternalSymbolsHint );
@@ -5074,6 +5081,25 @@ void QgisApp::markDirty()
50745081 QgsProject::instance ()->dirty ( true );
50755082}
50765083
5084+ void QgisApp::layerWasAdded ( QgsMapLayer *layer )
5085+ {
5086+ QgsDataProvider *provider = 0 ;
5087+
5088+ QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
5089+ if ( vlayer )
5090+ provider = vlayer->dataProvider ();
5091+
5092+ QgsRasterLayer *rlayer = qobject_cast<QgsRasterLayer *>( layer );
5093+ if ( rlayer )
5094+ provider = rlayer->dataProvider ();
5095+
5096+ if ( provider )
5097+ {
5098+ connect ( provider, SIGNAL ( dataChanged () ), layer, SLOT ( clearCacheImage () ) );
5099+ connect ( provider, SIGNAL ( dataChanged () ), mMapCanvas , SLOT ( refresh () ) );
5100+ }
5101+ }
5102+
50775103void QgisApp::showExtents ()
50785104{
50795105 if ( !mToggleExtentsViewButton ->isChecked () )
@@ -5194,7 +5220,7 @@ void QgisApp::projectProperties()
51945220 SLOT ( updateMouseCoordinatePrecision () ) );
51955221 QApplication::restoreOverrideCursor ();
51965222
5197- // pass any refresg signals off to canvases
5223+ // pass any refresh signals off to canvases
51985224 // Line below was commented out by wonder three years ago (r4949).
51995225 // It is needed to refresh scale bar after changing display units.
52005226 connect ( pp, SIGNAL ( refresh () ), mMapCanvas , SLOT ( refresh () ) );
@@ -5345,12 +5371,14 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
53455371 mActionCapturePoint ->setEnabled ( true );
53465372 mActionCapturePoint ->setVisible ( true );
53475373 mActionDeletePart ->setEnabled ( true );
5374+ mActionAddIsland ->setEnabled ( true );
53485375 }
53495376 else
53505377 {
53515378 mActionCapturePoint ->setEnabled ( false );
53525379 mActionCapturePoint ->setVisible ( false );
53535380 mActionDeletePart ->setEnabled ( false );
5381+ mActionAddIsland ->setEnabled ( false );
53545382 }
53555383 mActionCaptureLine ->setEnabled ( false );
53565384 mActionCapturePolygon ->setEnabled ( false );
@@ -5362,6 +5390,9 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
53625390 mActionMoveVertex->setEnabled( false );
53635391#endif
53645392 mActionAddRing ->setEnabled ( false );
5393+ #if 0
5394+ mActionAddIsland->setEnabled( false );
5395+ #endif
53655396 mActionAddIsland ->setEnabled ( false );
53665397 mActionReshapeFeatures ->setEnabled ( false );
53675398 mActionSplitFeatures ->setEnabled ( false );
@@ -5608,6 +5639,7 @@ bool QgisApp::addRasterLayer( QgsRasterLayer * theRasterLayer )
56085639 SIGNAL ( drawingProgress ( int , int ) ),
56095640 this ,
56105641 SLOT ( showProgress ( int , int ) ) );
5642+
56115643 // connect up any request the raster may make to update the statusbar message
56125644 QObject::connect ( theRasterLayer,
56135645 SIGNAL ( statusChanged ( QString ) ),
@@ -5681,13 +5713,14 @@ QgsRasterLayer* QgisApp::addRasterLayer( QString const & rasterFile, QString con
56815713 \note Copied from the equivalent addVectorLayer function in this file
56825714 TODO Make it work for rasters specifically.
56835715 */
5684- QgsRasterLayer* QgisApp::addRasterLayer ( QString const & rasterLayerPath,
5685- QString const & baseName,
5686- QString const & providerKey,
5687- QStringList const & layers,
5688- QStringList const & styles,
5689- QString const & format,
5690- QString const & crs )
5716+ QgsRasterLayer* QgisApp::addRasterLayer (
5717+ QString const &rasterLayerPath,
5718+ QString const &baseName,
5719+ QString const &providerKey,
5720+ QStringList const & layers,
5721+ QStringList const & styles,
5722+ QString const &format,
5723+ QString const &crs )
56915724{
56925725 QgsDebugMsg ( " about to get library for " + providerKey );
56935726
@@ -6127,3 +6160,115 @@ void QgisApp::showLayerProperties( QgsMapLayer *ml )
61276160
61286161 }
61296162}
6163+
6164+ void QgisApp::namSetup ()
6165+ {
6166+ if ( mNAM )
6167+ return ;
6168+
6169+ mNAM = new QNetworkAccessManager ( this );
6170+
6171+ namUpdate ();
6172+
6173+ connect ( mNAM , SIGNAL ( authenticationRequired ( QNetworkReply *, QAuthenticator * ) ),
6174+ this , SLOT ( namAuthenticationRequired ( QNetworkReply *, QAuthenticator * ) ) );
6175+
6176+ connect ( mNAM , SIGNAL ( proxyAuthenticationRequired ( const QNetworkProxy &, QAuthenticator * ) ),
6177+ this , SLOT ( namProxyAuthenticationRequired ( const QNetworkProxy &, QAuthenticator * ) ) );
6178+
6179+ QCoreApplication::instance ()->setProperty ( " qgisNetworkAccessManager" , qVariantFromValue<QObject*>( mNAM ) );
6180+ }
6181+
6182+ QNetworkAccessManager *QgisApp::nam ()
6183+ {
6184+ namSetup ();
6185+ return mNAM ;
6186+ }
6187+
6188+ void QgisApp::namAuthenticationRequired ( QNetworkReply *reply, QAuthenticator *auth )
6189+ {
6190+ QString username = auth->user ();
6191+ QString password = auth->password ();
6192+
6193+ bool ok = QgsCredentials::instance ()->get (
6194+ QString ( " %1 at %2" ).arg ( auth->realm () ).arg ( reply->url ().host () ),
6195+ username, password,
6196+ tr ( " Authentication required" ) );
6197+ if ( !ok )
6198+ return ;
6199+
6200+ auth->setUser ( username );
6201+ auth->setPassword ( password );
6202+ }
6203+
6204+ void QgisApp::namProxyAuthenticationRequired ( const QNetworkProxy &proxy, QAuthenticator *auth )
6205+ {
6206+ QString username = auth->user ();
6207+ QString password = auth->password ();
6208+
6209+ bool ok = QgsCredentials::instance ()->get (
6210+ QString ( " proxy %1:%2 [%3]" ).arg ( proxy.hostName () ).arg ( proxy.port () ).arg ( auth->realm () ),
6211+ username, password,
6212+ tr ( " Proxy authentication required" ) );
6213+ if ( !ok )
6214+ return ;
6215+
6216+ auth->setUser ( username );
6217+ auth->setPassword ( password );
6218+ }
6219+
6220+ void QgisApp::namUpdate ()
6221+ {
6222+ QSettings settings;
6223+
6224+ // read type, host, port, user, passw from settings
6225+ QString proxyHost = settings.value ( " proxy/proxyHost" , " " ).toString ();
6226+ int proxyPort = settings.value ( " proxy/proxyPort" , " " ).toString ().toInt ();
6227+ QString proxyUser = settings.value ( " proxy/proxyUser" , " " ).toString ();
6228+ QString proxyPassword = settings.value ( " proxy/proxyPassword" , " " ).toString ();
6229+
6230+ QString proxyTypeString = settings.value ( " proxy/proxyType" , " " ).toString ();
6231+ QNetworkProxy::ProxyType proxyType = QNetworkProxy::NoProxy;
6232+ if ( proxyTypeString == " DefaultProxy" )
6233+ {
6234+ proxyType = QNetworkProxy::DefaultProxy;
6235+ }
6236+ else if ( proxyTypeString == " Socks5Proxy" )
6237+ {
6238+ proxyType = QNetworkProxy::Socks5Proxy;
6239+ }
6240+ else if ( proxyTypeString == " HttpProxy" )
6241+ {
6242+ proxyType = QNetworkProxy::HttpProxy;
6243+ }
6244+ else if ( proxyTypeString == " HttpCachingProxy" )
6245+ {
6246+ proxyType = QNetworkProxy::HttpCachingProxy;
6247+ }
6248+ else if ( proxyTypeString == " FtpCachingProxy" )
6249+ {
6250+ proxyType = QNetworkProxy::FtpCachingProxy;
6251+ }
6252+ QgsDebugMsg ( QString ( " setting proxy %1 %2:%3 %4/%5" )
6253+ .arg ( proxyType )
6254+ .arg ( proxyHost ).arg ( proxyPort )
6255+ .arg ( proxyUser ).arg ( proxyPassword )
6256+ );
6257+ nam ()->setProxy ( QNetworkProxy ( proxyType, proxyHost, proxyPort, proxyUser, proxyPassword ) );
6258+
6259+ QNetworkDiskCache *cache = qobject_cast<QNetworkDiskCache*>( nam ()->cache () );
6260+ if ( !cache )
6261+ cache = new QNetworkDiskCache ( this );
6262+
6263+ QString cacheDirectory = settings.value ( " cache/directory" , QgsApplication::qgisSettingsDirPath () + " cache" ).toString ();
6264+ qint64 cacheSize = settings.value ( " cache/size" , 50 * 1024 * 1024 ).toULongLong ();
6265+ QgsDebugMsg ( QString ( " setCacheDirectory: %1" ).arg ( cacheDirectory ) );
6266+ QgsDebugMsg ( QString ( " setMaximumCacheSize: %1" ).arg ( cacheSize ) );
6267+ cache->setCacheDirectory ( cacheDirectory );
6268+ cache->setMaximumCacheSize ( cacheSize );
6269+ QgsDebugMsg ( QString ( " cacheDirectory: %1" ).arg ( cache->cacheDirectory () ) );
6270+ QgsDebugMsg ( QString ( " maximumCacheSize: %1" ).arg ( cache->maximumCacheSize () ) );
6271+
6272+ if ( mNAM ->cache () != cache )
6273+ mNAM ->setCache ( cache );
6274+ }
0 commit comments