@@ -69,20 +69,32 @@ class QgsNetworkProxyFactory : public QNetworkProxyFactory
6969 }
7070 }
7171
72- QgsDebugMsg ( QString ( " using user proxy for %1" ).arg ( url ) );
72+ if ( nam->useSystemProxy () )
73+ {
74+ QgsDebugMsg ( QString ( " requesting system proxy for query %1" ).arg ( url ) );
75+ QList<QNetworkProxy> proxies = QNetworkProxyFactory::systemProxyForQuery ( query );
76+ if ( !proxies.isEmpty () )
77+ {
78+ QgsDebugMsg ( QString ( " using system proxy %1:%2 for query" )
79+ .arg ( proxies.first ().hostName () ).arg ( proxies.first ().port () ) );
80+ return proxies;
81+ }
82+ }
83+
84+ QgsDebugMsg ( QString ( " using fallback proxy for %1" ).arg ( url ) );
7385 return QList<QNetworkProxy>() << nam->fallbackProxy ();
7486 }
7587};
7688
7789QgsNetworkAccessManager *QgsNetworkAccessManager::instance ()
7890{
7991 static QgsNetworkAccessManager sInstance ;
80-
8192 return &sInstance ;
8293}
8394
8495QgsNetworkAccessManager::QgsNetworkAccessManager ( QObject *parent )
8596 : QNetworkAccessManager( parent )
97+ , mUseSystemProxy( false )
8698{
8799 setProxyFactory ( new QgsNetworkProxyFactory () );
88100}
@@ -230,7 +242,30 @@ void QgsNetworkAccessManager::setupDefaultProxyAndCache()
230242
231243 QSettings settings;
232244
233- // check if proxy is enabled
245+ mUseSystemProxy = false ;
246+
247+ if ( this != instance () )
248+ {
249+ connect ( this , SIGNAL ( authenticationRequired ( QNetworkReply *, QAuthenticator * ) ),
250+ instance (), SIGNAL ( authenticationRequired ( QNetworkReply *, QAuthenticator * ) ),
251+ Qt::BlockingQueuedConnection );
252+
253+ connect ( this , SIGNAL ( proxyAuthenticationRequired ( const QNetworkProxy &, QAuthenticator * ) ),
254+ instance (), SIGNAL ( proxyAuthenticationRequired ( const QNetworkProxy &, QAuthenticator * ) ),
255+ Qt::BlockingQueuedConnection );
256+
257+ connect ( this , SIGNAL ( requestTimedOut ( QNetworkReply* ) ),
258+ instance (), SIGNAL ( requestTimedOut ( QNetworkReply* ) ),
259+ Qt::BlockingQueuedConnection );
260+
261+ #ifndef QT_NO_OPENSSL
262+ connect ( this , SIGNAL ( sslErrors ( QNetworkReply *, const QList<QSslError> & ) ),
263+ instance (), SIGNAL ( sslErrors ( QNetworkReply *, const QList<QSslError> & ) ),
264+ Qt::BlockingQueuedConnection );
265+ #endif
266+ }
267+
268+ // check if proxy is enabled
234269 bool proxyEnabled = settings.value ( " proxy/proxyEnabled" , false ).toBool ();
235270 if ( proxyEnabled )
236271 {
@@ -243,24 +278,21 @@ void QgsNetworkAccessManager::setupDefaultProxyAndCache()
243278 QString proxyPassword = settings.value ( " proxy/proxyPassword" , " " ).toString ();
244279
245280 QString proxyTypeString = settings.value ( " proxy/proxyType" , " " ).toString ();
246- QNetworkProxy::ProxyType proxyType = QNetworkProxy::NoProxy;
281+
247282 if ( proxyTypeString == " DefaultProxy" )
248283 {
249- proxyType = QNetworkProxy::DefaultProxy;
250-
251- #if defined(Q_OS_WIN)
284+ mUseSystemProxy = true ;
252285 QNetworkProxyFactory::setUseSystemConfiguration ( true );
253286 QList<QNetworkProxy> proxies = QNetworkProxyFactory::systemProxyForQuery ();
254287 if ( !proxies.isEmpty () )
255288 {
256289 proxy = proxies.first ();
257290 }
258- #endif
259-
260291 QgsDebugMsg ( " setting default proxy" );
261292 }
262293 else
263294 {
295+ QNetworkProxy::ProxyType proxyType = QNetworkProxy::DefaultProxy;
264296 if ( proxyTypeString == " Socks5Proxy" )
265297 {
266298 proxyType = QNetworkProxy::Socks5Proxy;
0 commit comments