Skip to content

Commit 0bee933

Browse files
author
mhugent
committed
[FEATUE]: Add option to specify network timeout instead of using the hardcoded one in qgshttptransaction
git-svn-id: http://svn.osgeo.org/qgis/trunk@11914 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 1bf41d8 commit 0bee933

File tree

7 files changed

+105
-122
lines changed

7 files changed

+105
-122
lines changed

src/app/qgsoptions.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
7878
}
7979
}
8080

81+
//Network timeout
82+
mNetworkTimeoutSpinBox->setValue( settings.value( "/qgis/networkAndProxy/networkTimeout", "60000" ).toInt() );
83+
8184
//Web proxy settings
8285
grpProxy->setChecked( settings.value( "proxy/proxyEnabled", "0" ).toBool() );
8386
leProxyHost->setText( settings.value( "proxy/proxyHost", "" ).toString() );
@@ -274,7 +277,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
274277
{
275278
mMarkerStyleComboBox->setCurrentIndex( mMarkerStyleComboBox->findText( tr( "None" ) ) );
276279
}
277-
mMarkerSizeSpinBox->setValue( settings.value( "/qgis/digitizing/marker_size", 7 ).toInt()*2+1 );
280+
mMarkerSizeSpinBox->setValue( settings.value( "/qgis/digitizing/marker_size", 7 ).toInt()*2 + 1 );
278281

279282
chkDisableAttributeValuesDlg->setChecked( settings.value( "/qgis/digitizing/disable_enter_attribute_values_dialog", false ).toBool() );
280283

@@ -352,7 +355,7 @@ QString QgsOptions::theme()
352355
void QgsOptions::saveOptions()
353356
{
354357
QSettings settings;
355-
358+
356359
//search directories for svgs
357360
QString myPaths;
358361
for ( int i = 0; i < mListSVGPaths->count(); ++i )
@@ -365,6 +368,9 @@ void QgsOptions::saveOptions()
365368
}
366369
settings.setValue( "svg/searchPathsForSVG", myPaths );
367370

371+
//Network timeout
372+
settings.setValue( "/qgis/networkAndProxy/networkTimeout", mNetworkTimeoutSpinBox->value() );
373+
368374
//Web proxy settings
369375
settings.setValue( "proxy/proxyEnabled", grpProxy->isChecked() );
370376
settings.setValue( "proxy/proxyHost", leProxyHost->text() );
@@ -518,7 +524,7 @@ void QgsOptions::saveOptions()
518524
{
519525
settings.setValue( "/qgis/digitizing/marker_style", "None" );
520526
}
521-
settings.setValue( "/qgis/digitizing/marker_size", (mMarkerSizeSpinBox->value()-1)/2 );
527+
settings.setValue( "/qgis/digitizing/marker_size", ( mMarkerSizeSpinBox->value() - 1 ) / 2 );
522528

523529
settings.setValue( "/qgis/digitizing/disable_enter_attribute_values_dialog", chkDisableAttributeValuesDlg->isChecked() );
524530

@@ -710,11 +716,11 @@ QStringList QgsOptions::i18nList()
710716
void QgsOptions::on_mBtnAddSVGPath_clicked()
711717
{
712718
QString myDir = QFileDialog::getExistingDirectory(
713-
this,
714-
tr( "Choose a directory" ),
715-
QDir::toNativeSeparators( QDir::homePath() ),
716-
QFileDialog::ShowDirsOnly
717-
);
719+
this,
720+
tr( "Choose a directory" ),
721+
QDir::toNativeSeparators( QDir::homePath() ),
722+
QFileDialog::ShowDirsOnly
723+
);
718724

719725
if ( ! myDir.isEmpty() )
720726
{

src/core/qgshttptransaction.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include <QTimer>
3232
#include "qgslogger.h"
3333

34-
static int NETWORK_TIMEOUT_MSEC = ( 120 * 1000 ); // 120 seconds
3534
static int HTTP_PORT_DEFAULT = 80;
3635

3736
//XXX Set the connection name when creating the provider instance
@@ -51,6 +50,13 @@ QgsHttpTransaction::QgsHttpTransaction( QString uri,
5150
httphost( proxyHost ),
5251
mError( 0 )
5352
{
53+
QSettings s;
54+
mNetworkTimeoutMsec = s.value( "/qgis/networkAndProxy/networkTimeout", "20000" ).toInt();
55+
}
56+
57+
QgsHttpTransaction::QgsHttpTransaction()
58+
{
59+
5460
}
5561

5662
QgsHttpTransaction::~QgsHttpTransaction()
@@ -175,7 +181,7 @@ bool QgsHttpTransaction::getSynchronously( QByteArray &respondedContent, int red
175181
this, SLOT( networkTimedOut() ) );
176182

177183
mWatchdogTimer->setSingleShot( TRUE );
178-
mWatchdogTimer->start( NETWORK_TIMEOUT_MSEC );
184+
mWatchdogTimer->start( mNetworkTimeoutMsec );
179185

180186
QgsDebugMsg( "Starting get with id " + QString::number( httpid ) + "." );
181187
QgsDebugMsg( "Setting httpactive = TRUE" );
@@ -251,7 +257,7 @@ void QgsHttpTransaction::dataHeaderReceived( const QHttpResponseHeader& resp )
251257
resp.value( "Content-Type" ) + "'." );
252258

253259
// We saw something come back, therefore restart the watchdog timer
254-
mWatchdogTimer->start( NETWORK_TIMEOUT_MSEC );
260+
mWatchdogTimer->start( mNetworkTimeoutMsec );
255261

256262
if ( resp.statusCode() == 302 ) // Redirect
257263
{
@@ -298,7 +304,7 @@ void QgsHttpTransaction::dataProgress( int done, int total )
298304
// QgsDebugMsg("got " + QString::number(done) + " of " + QString::number(total));
299305

300306
// We saw something come back, therefore restart the watchdog timer
301-
mWatchdogTimer->start( NETWORK_TIMEOUT_MSEC );
307+
mWatchdogTimer->start( mNetworkTimeoutMsec );
302308

303309
emit dataReadProgress( done );
304310
emit totalSteps( total );
@@ -414,7 +420,7 @@ void QgsHttpTransaction::dataStateChanged( int state )
414420
QgsDebugMsg( "state " + QString::number( state ) + "." );
415421

416422
// We saw something come back, therefore restart the watchdog timer
417-
mWatchdogTimer->start( NETWORK_TIMEOUT_MSEC );
423+
mWatchdogTimer->start( mNetworkTimeoutMsec );
418424

419425
switch ( state )
420426
{
@@ -467,7 +473,7 @@ void QgsHttpTransaction::networkTimedOut()
467473
QgsDebugMsg( "entering." );
468474

469475
mError = tr( "Network timed out after %n second(s) of inactivity.\n"
470-
"This may be a problem in your network connection or at the WMS server.", "inactivity timeout", NETWORK_TIMEOUT_MSEC / 1000 );
476+
"This may be a problem in your network connection or at the WMS server.", "inactivity timeout", mNetworkTimeoutMsec / 1000 );
471477

472478
QgsDebugMsg( "Setting httpactive = FALSE" );
473479
httpactive = FALSE;

src/core/qgshttptransaction.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ class CORE_EXPORT QgsHttpTransaction : public QObject
9696

9797
void setCredentials( const QString& username, const QString &password );
9898

99+
/**Returns the network timeout in msec*/
100+
int networkTimeout() const { return mNetworkTimeoutMsec;}
101+
/**Sets the network timeout in milliseconds*/
102+
void setNetworkTimeout( int msec ) { mNetworkTimeoutMsec = msec;}
103+
99104

100105
public slots:
101106

@@ -134,6 +139,9 @@ class CORE_EXPORT QgsHttpTransaction : public QObject
134139

135140
private:
136141

142+
/**Default constructor is forbidden*/
143+
QgsHttpTransaction();
144+
137145
/**
138146
* Indicates the associated QHttp object
139147
*
@@ -207,6 +215,9 @@ class CORE_EXPORT QgsHttpTransaction : public QObject
207215
* Password
208216
*/
209217
QString mPassword;
218+
219+
/**Network timeout in milliseconds*/
220+
int mNetworkTimeoutMsec;
210221
};
211222

212223
#endif

src/plugins/wfs/qgswfssourceselect.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,10 @@ int QgsWFSSourceSelect::getCapabilitiesGET( QString uri, std::list<QString>& typ
143143

144144
QByteArray result;
145145
QgsHttpTransaction http( request );
146-
http.getSynchronously( result );
146+
if ( !http.getSynchronously( result ) )
147+
{
148+
QMessageBox::critical( 0, tr( "Error" ), tr( "The capabilities document could not be retrieved from the server" ) );
149+
}
147150

148151
QDomDocument capabilitiesDocument;
149152
if ( !capabilitiesDocument.setContent( result, true ) )

src/providers/wfs/qgswfsdata.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <QList>
2424
#include <QProgressDialog>
2525
#include <QSet>
26+
#include <QSettings>
2627

2728
//just for a test
2829
//#include <QProgressDialog>
@@ -64,8 +65,12 @@ QgsWFSData::QgsWFSData(
6465
}
6566
}
6667

68+
QSettings s;
69+
mNetworkTimeoutMsec = s.value( "/qgis/networkAndProxy/networkTimeout", "60000" ).toInt();
70+
6771
mEndian = QgsApplication::endian();
6872
QObject::connect( &mHttp, SIGNAL( done( bool ) ), this, SLOT( setFinished( bool ) ) );
73+
QObject::connect( &mNetworkTimeoutTimer, SIGNAL( timeout() ), this, SLOT( setFinished() ) );
6974
}
7075

7176
QgsWFSData::~QgsWFSData()
@@ -115,7 +120,9 @@ int QgsWFSData::getWFSData()
115120
progressDialog->show();
116121
}
117122

118-
//mHttp.get( mUri );
123+
//setup timer
124+
mNetworkTimeoutTimer.setSingleShot( true );
125+
mNetworkTimeoutTimer.start( mNetworkTimeoutMsec );
119126
mHttp.get( requestUrl.path() + "?" + QString( requestUrl.encodedQuery() ) );
120127

121128

@@ -169,6 +176,7 @@ void QgsWFSData::handleProgressEvent( int progress, int totalSteps )
169176
{
170177
emit dataReadProgress( progress );
171178
emit totalStepsUpdate( totalSteps );
179+
mNetworkTimeoutTimer.start( mNetworkTimeoutMsec );
172180
}
173181

174182
void QgsWFSData::startElement( const XML_Char* el, const XML_Char** attr )

src/providers/wfs/qgswfsdata.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define QGSWFSDATA_H
1717

1818
#include <QHttp>
19+
#include <QTimer>
1920
#include <expat.h>
2021
#include "qgis.h"
2122
#include "qgsapplication.h"
@@ -56,7 +57,7 @@ class QgsWFSData: public QObject
5657
const QHttp* http() const {return &mHttp;}
5758

5859
private slots:
59-
void setFinished( bool error );
60+
void setFinished( bool error = true );
6061

6162
/**Takes progress value and total steps and emit signals 'dataReadProgress' and 'totalStepUpdate'*/
6263
void handleProgressEvent( int progress, int totalSteps );
@@ -178,6 +179,8 @@ class QgsWFSData: public QObject
178179
QString mCoordinateSeparator;
179180
/**Tuple separator for coordinate strings. Usually " " */
180181
QString mTupleSeparator;
182+
int mNetworkTimeoutMsec;
183+
QTimer mNetworkTimeoutTimer;
181184
};
182185

183186
#endif

0 commit comments

Comments
 (0)