Skip to content

Commit a63de6d

Browse files
committedApr 9, 2014
Restart timeout timer when data is received in QgsNetworkAccessManager, show a message if timeout is reached.
1 parent 5f19830 commit a63de6d

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed
 

‎src/app/qgisapp.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9296,6 +9296,8 @@ void QgisApp::namSetup()
92969296
connect( nam, SIGNAL( proxyAuthenticationRequired( const QNetworkProxy &, QAuthenticator * ) ),
92979297
this, SLOT( namProxyAuthenticationRequired( const QNetworkProxy &, QAuthenticator * ) ) );
92989298

9299+
connect( nam, SIGNAL( requestTimedOut( QNetworkReply* ) ), this, SLOT( namRequestTimedOut( QNetworkReply* ) ) );
9300+
92999301
#ifndef QT_NO_OPENSSL
93009302
connect( nam, SIGNAL( sslErrors( QNetworkReply *, const QList<QSslError> & ) ),
93019303
this, SLOT( namSslErrors( QNetworkReply *, const QList<QSslError> & ) ) );
@@ -9381,6 +9383,11 @@ void QgisApp::namSslErrors( QNetworkReply *reply, const QList<QSslError> &errors
93819383
}
93829384
#endif
93839385

9386+
void QgisApp::namRequestTimedOut( QNetworkReply *reply )
9387+
{
9388+
QMessageBox::warning( this, tr( "Network request timed out" ), tr( "The following request timed out %1. If any data was received, it is likely incomplete." ).arg( reply->url().toString() ) );
9389+
}
9390+
93849391
void QgisApp::namUpdate()
93859392
{
93869393
QgsNetworkAccessManager::instance()->setupDefaultProxyAndCache();
@@ -9560,3 +9567,4 @@ LONG WINAPI QgisApp::qgisCrashDump( struct _EXCEPTION_POINTERS *ExceptionInfo )
95609567
return EXCEPTION_EXECUTE_HANDLER;
95619568
}
95629569
#endif
9570+

‎src/app/qgisapp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
594594
#ifndef QT_NO_OPENSSL
595595
void namSslErrors( QNetworkReply *reply, const QList<QSslError> &errors );
596596
#endif
597+
void namRequestTimedOut( QNetworkReply *reply );
597598

598599
//! update default action of toolbutton
599600
void toolButtonActionTriggered( QAction * );
@@ -1553,3 +1554,4 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
15531554
#endif
15541555

15551556
#endif
1557+

‎src/core/qgsnetworkaccessmanager.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ QNetworkReply *QgsNetworkAccessManager::createRequest( QNetworkAccessManager::Op
161161
timer->setSingleShot( true );
162162
timer->start( s.value( "/qgis/networkAndProxy/networkTimeout", "20000" ).toInt() );
163163

164+
connect( reply, SIGNAL( downloadProgress( qint64, qint64 ) ), timer, SLOT( start() ) );
165+
164166
mActiveRequests.insert( reply, timer );
165167
return reply;
166168
}
@@ -194,6 +196,8 @@ void QgsNetworkAccessManager::abortRequest()
194196

195197
if ( reply->isRunning() )
196198
reply->close();
199+
200+
emit requestTimedOut( reply );
197201
}
198202

199203
QString QgsNetworkAccessManager::cacheLoadControlName( QNetworkRequest::CacheLoadControl theControl )
@@ -324,3 +328,4 @@ void QgsNetworkAccessManager::setupDefaultProxyAndCache()
324328
setProxy( proxy );
325329
#endif
326330
}
331+

‎src/core/qgsnetworkaccessmanager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class CORE_EXPORT QgsNetworkAccessManager : public QNetworkAccessManager
8787
signals:
8888
void requestAboutToBeCreated( QNetworkAccessManager::Operation, const QNetworkRequest &, QIODevice * );
8989
void requestCreated( QNetworkReply * );
90+
void requestTimedOut( QNetworkReply * );
9091

9192
private slots:
9293
void connectionProgress();
@@ -105,3 +106,4 @@ class CORE_EXPORT QgsNetworkAccessManager : public QNetworkAccessManager
105106
};
106107

107108
#endif // QGSNETWORKACCESSMANAGER_H
109+

0 commit comments

Comments
 (0)
Please sign in to comment.