30 #include <QNetworkReply>
38 virtual QList<QNetworkProxy>
queryProxy(
const QNetworkProxyQuery & query = QNetworkProxyQuery() )
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 ) );
82 : QNetworkAccessManager( parent )
118 QgsDebugMsg( QString(
"proxy settings: (type:%1 host: %2:%3, user:%4, password:%5" )
119 .arg( proxy.type() == QNetworkProxy::DefaultProxy ?
"DefaultProxy" :
120 proxy.type() == QNetworkProxy::Socks5Proxy ?
"Socks5Proxy" :
121 proxy.type() == QNetworkProxy::NoProxy ?
"NoProxy" :
122 proxy.type() == QNetworkProxy::HttpProxy ?
"HttpProxy" :
123 proxy.type() == QNetworkProxy::HttpCachingProxy ?
"HttpCachingProxy" :
124 proxy.type() == QNetworkProxy::FtpCachingProxy ?
"FtpCachingProxy" :
126 .arg( proxy.hostName() )
129 .arg( proxy.password().isEmpty() ?
"not set" :
"set" ) );
139 QNetworkRequest *pReq(( QNetworkRequest * ) &req );
141 QString userAgent = s.value(
"/qgis/networkAndProxy/userAgent",
"Mozilla/5.0" ).toString();
142 if ( !userAgent.isEmpty() )
145 pReq->setRawHeader(
"User-Agent", userAgent.toUtf8() );
150 connect( reply, SIGNAL( downloadProgress( qint64, qint64 ) ),
this, SLOT(
connectionProgress() ) );
151 connect( reply, SIGNAL( uploadProgress( qint64, qint64 ) ),
this, SLOT(
connectionProgress() ) );
152 connect( reply, SIGNAL( destroyed( QObject* ) ),
this, SLOT(
connectionDestroyed( QObject* ) ) );
156 QTimer *timer =
new QTimer( reply );
157 connect( timer, SIGNAL( timeout() ),
this, SLOT(
abortRequest() ) );
158 timer->setSingleShot(
true );
159 timer->start( s.value(
"/qgis/networkAndProxy/networkTimeout",
"20000" ).toInt() );
167 QNetworkReply *reply = qobject_cast<QNetworkReply *>( sender() );
174 timer->start( s.value(
"/qgis/networkAndProxy/networkTimeout",
"20000" ).toInt() );
184 QTimer *timer = qobject_cast<QTimer *>( sender() );
187 QNetworkReply *reply = qobject_cast<QNetworkReply *>( timer->parent() );
192 if ( reply->isRunning() )
198 switch ( theControl )
200 case QNetworkRequest::AlwaysNetwork:
201 return "AlwaysNetwork";
203 case QNetworkRequest::PreferNetwork:
204 return "PreferNetwork";
206 case QNetworkRequest::PreferCache:
207 return "PreferCache";
209 case QNetworkRequest::AlwaysCache:
210 return "AlwaysCache";
215 return "PreferNetwork";
220 if ( theName ==
"AlwaysNetwork" )
222 return QNetworkRequest::AlwaysNetwork;
224 else if ( theName ==
"PreferNetwork" )
226 return QNetworkRequest::PreferNetwork;
228 else if ( theName ==
"PreferCache" )
230 return QNetworkRequest::PreferCache;
232 else if ( theName ==
"AlwaysCache" )
234 return QNetworkRequest::AlwaysCache;
236 return QNetworkRequest::PreferNetwork;