29 #include <QNetworkReply>
31 #if QT_VERSION >= 0x40500
32 class QgsNetworkProxyFactory :
public QNetworkProxyFactory
35 QgsNetworkProxyFactory() {}
36 virtual ~QgsNetworkProxyFactory() {}
38 virtual QList<QNetworkProxy> queryProxy(
const QNetworkProxyQuery & query = QNetworkProxyQuery() )
43 foreach ( QNetworkProxyFactory *f, nam->proxyFactories() )
45 QList<QNetworkProxy> systemproxies = f->systemProxyForQuery( query );
46 if ( systemproxies.size() > 0 )
49 QList<QNetworkProxy> proxies = f->queryProxy( query );
50 if ( proxies.size() > 0 )
55 if ( query.queryType() != QNetworkProxyQuery::UrlRequest )
58 QString url = query.url().toString();
62 if ( url.startsWith( exclude ) )
64 QgsDebugMsg( QString(
"using default proxy for %1 [exclude %2]" ).arg( url ).arg( exclude ) );
65 return QList<QNetworkProxy>() << QNetworkProxy();
69 QgsDebugMsg( QString(
"using user proxy for %1" ).arg( url ) );
88 : QNetworkAccessManager( parent )
90 #if QT_VERSION >= 0x40500
91 setProxyFactory(
new QgsNetworkProxyFactory() );
99 #if QT_VERSION >= 0x40500
100 void QgsNetworkAccessManager::insertProxyFactory( QNetworkProxyFactory *factory )
102 mProxyFactories.insert( 0, factory );
105 void QgsNetworkAccessManager::removeProxyFactory( QNetworkProxyFactory *factory )
107 mProxyFactories.removeAll( factory );
110 const QList<QNetworkProxyFactory *> QgsNetworkAccessManager::proxyFactories()
const
112 return mProxyFactories;
139 QTimer *timer =
new QTimer( reply );
140 connect( timer, SIGNAL( timeout() ),
this, SLOT(
abortRequest() ) );
142 timer->setSingleShot(
true );
143 timer->start( s.value(
"/qgis/networkAndProxy/networkTimeout",
"20000" ).toInt() );
150 QTimer *timer = qobject_cast<QTimer *>( sender() );
153 QNetworkReply *reply = qobject_cast<QNetworkReply *>( timer->parent() );
163 switch ( theControl )
165 case QNetworkRequest::AlwaysNetwork:
166 return "AlwaysNetwork";
168 case QNetworkRequest::PreferNetwork:
169 return "PreferNetwork";
171 case QNetworkRequest::PreferCache:
172 return "PreferCache";
174 case QNetworkRequest::AlwaysCache:
175 return "AlwaysCache";
180 return "PreferNetwork";
185 if ( theName ==
"AlwaysNetwork" )
187 return QNetworkRequest::AlwaysNetwork;
189 else if ( theName ==
"PreferNetwork" )
191 return QNetworkRequest::PreferNetwork;
193 else if ( theName ==
"PreferCache" )
195 return QNetworkRequest::PreferCache;
197 else if ( theName ==
"AlwaysCache" )
199 return QNetworkRequest::AlwaysCache;
201 return QNetworkRequest::PreferNetwork;