[QGIS Commit] r13103 - trunk/qgis/src/app

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sat Mar 20 08:49:43 EDT 2010


Author: jef
Date: 2010-03-20 08:49:41 -0400 (Sat, 20 Mar 2010)
New Revision: 13103

Added:
   trunk/qgis/src/app/qgsnetworkproxyfactory.cpp
   trunk/qgis/src/app/qgsnetworkproxyfactory.h
Modified:
   trunk/qgis/src/app/CMakeLists.txt
   trunk/qgis/src/app/qgisapp.cpp
   trunk/qgis/src/app/qgsoptions.cpp
Log:
re-enable proxy exclusion

Modified: trunk/qgis/src/app/CMakeLists.txt
===================================================================
--- trunk/qgis/src/app/CMakeLists.txt	2010-03-20 11:43:28 UTC (rev 13102)
+++ trunk/qgis/src/app/CMakeLists.txt	2010-03-20 12:49:41 UTC (rev 13103)
@@ -70,6 +70,7 @@
   qgsuniquevaluedialog.cpp
   qgsvectorlayerproperties.cpp
   qgsquerybuilder.cpp
+  qgsnetworkproxyfactory.cpp
 
   qgsmanageconnectionsdialog.cpp
 

Modified: trunk/qgis/src/app/qgisapp.cpp
===================================================================
--- trunk/qgis/src/app/qgisapp.cpp	2010-03-20 11:43:28 UTC (rev 13102)
+++ trunk/qgis/src/app/qgisapp.cpp	2010-03-20 12:49:41 UTC (rev 13103)
@@ -149,6 +149,7 @@
 #include "qgsattributetabledialog.h"
 #include "qgsvectorfilewriter.h"
 #include "qgscredentialdialog.h"
+#include "qgsnetworkproxyfactory.h"
 
 #ifdef HAVE_QWT
 #include "qgsgpsinformationwidget.h"
@@ -6219,12 +6220,16 @@
 
 void QgisApp::namUpdate()
 {
+  QNetworkProxy proxy;
+  QStringList excludes;
+
   QSettings settings;
 
   //check if proxy is enabled
   bool proxyEnabled = settings.value( "proxy/proxyEnabled", false ).toBool();
   if ( proxyEnabled )
   {
+    excludes = settings.value( "proxy/proxyExcludedUrls", "" ).toString().split( "|", QString::SkipEmptyParts );
 
     //read type, host, port, user, passw from settings
     QString proxyHost = settings.value( "proxy/proxyHost", "" ).toString();
@@ -6259,13 +6264,15 @@
                  .arg( proxyHost ).arg( proxyPort )
                  .arg( proxyUser ).arg( proxyPassword )
                );
-    nam()->setProxy( QNetworkProxy( proxyType, proxyHost, proxyPort, proxyUser, proxyPassword ) );
+    proxy = QNetworkProxy( proxyType, proxyHost, proxyPort, proxyUser, proxyPassword );
   }
-  else
-  {
-    nam()->setProxy( QNetworkProxy() );
-  }
 
+#if QT_VERSION >= 0x40500
+  mNAM->setProxyFactory( new QgsNetworkProxyFactory( proxy, excludes ) );
+#else
+  mNAM->setProxy( proxy );
+#endif
+
   QNetworkDiskCache *cache = qobject_cast<QNetworkDiskCache*>( nam()->cache() );
   if ( !cache )
     cache = new QNetworkDiskCache( this );

Added: trunk/qgis/src/app/qgsnetworkproxyfactory.cpp
===================================================================
--- trunk/qgis/src/app/qgsnetworkproxyfactory.cpp	                        (rev 0)
+++ trunk/qgis/src/app/qgsnetworkproxyfactory.cpp	2010-03-20 12:49:41 UTC (rev 13103)
@@ -0,0 +1,59 @@
+/***************************************************************************
+                          qgsnetworkproxyfactory.cpp - description
+                             -------------------
+    begin                : Sat Mar 20 2010
+    copyright            : (C) 2010 by Juergen E. Fischer
+    email                : jef at norbit dot de
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+/* $Id$ */
+
+#include <QtGlobal>
+
+#if QT_VERSION >= 0x40500
+
+#include <QSettings>
+#include <QUrl>
+
+#include "qgsnetworkproxyfactory.h"
+#include "qgslogger.h"
+
+QgsNetworkProxyFactory::QgsNetworkProxyFactory( const QNetworkProxy &proxy, const QStringList &excludes )
+{
+  mProxy = proxy;
+  mExcludedURLs = excludes;
+}
+
+QgsNetworkProxyFactory::~QgsNetworkProxyFactory()
+{
+}
+
+QList<QNetworkProxy> QgsNetworkProxyFactory::queryProxy( const QNetworkProxyQuery &query )
+{
+  if( query.queryType() != QNetworkProxyQuery::UrlRequest )
+    return QList<QNetworkProxy>() << mProxy;
+
+  QString url = query.url().toString();
+
+  foreach( QString exclude, mExcludedURLs )
+  {
+    if ( url.startsWith( exclude ) )
+    {
+      QgsDebugMsg( QString("using default proxy for %1 [exclude %2]").arg( url ).arg( exclude ) );
+      return QList<QNetworkProxy>() << QNetworkProxy();
+    }
+  }
+
+  QgsDebugMsg( QString("using user proxy for %1").arg( url ) );
+  return QList<QNetworkProxy>() << mProxy; 
+}
+
+#endif // QT_VERSION >= 0x40500

Added: trunk/qgis/src/app/qgsnetworkproxyfactory.h
===================================================================
--- trunk/qgis/src/app/qgsnetworkproxyfactory.h	                        (rev 0)
+++ trunk/qgis/src/app/qgsnetworkproxyfactory.h	2010-03-20 12:49:41 UTC (rev 13103)
@@ -0,0 +1,40 @@
+/***************************************************************************
+                          qgsabout.h  -  description
+                             -------------------
+    begin                : Sat, 20 Mar 2010
+    copyright            : (C) 2010 by Juergen E. Fischer
+    email                : jef at norbit dot de
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+/* $Id:$ */
+#ifndef QGSNETWORKPROXYFACTORY_H
+#define QGSNETWORKPROXYFACTORY_H
+
+#if QT_VERSION >= 0x40500
+
+#include <QNetworkProxyFactory>
+#include <QStringList>
+
+class QgsNetworkProxyFactory : public QNetworkProxyFactory
+{
+  public:
+    QgsNetworkProxyFactory( const QNetworkProxy &proxy, const QStringList &excludes );
+    virtual ~QgsNetworkProxyFactory();
+    virtual QList<QNetworkProxy> queryProxy( const QNetworkProxyQuery & query = QNetworkProxyQuery() );
+
+  private:
+    QStringList mExcludedURLs;
+    QNetworkProxy mProxy;
+};
+
+#endif // QT_VERSION >= 0x40500
+
+#endif

Modified: trunk/qgis/src/app/qgsoptions.cpp
===================================================================
--- trunk/qgis/src/app/qgsoptions.cpp	2010-03-20 11:43:28 UTC (rev 13102)
+++ trunk/qgis/src/app/qgsoptions.cpp	2010-03-20 12:49:41 UTC (rev 13103)
@@ -116,6 +116,10 @@
     }
   }
 
+#if QT_VERSION < 0x40500
+  mExcludeUrlListWidget->setDisabled( true );
+#endif
+
   // cache settings
   QNetworkDiskCache *cache = qobject_cast<QNetworkDiskCache*>( QgisApp::instance()->nam()->cache() );
   if ( cache )



More information about the QGIS-commit mailing list