Skip to content

Commit

Permalink
[FEATUE]: Add option to specify network timeout instead of using the …
Browse files Browse the repository at this point in the history
…hardcoded one in qgshttptransaction

git-svn-id: http://svn.osgeo.org/qgis/trunk@11914 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Nov 4, 2009
1 parent 1bf41d8 commit 0bee933
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 122 deletions.
22 changes: 14 additions & 8 deletions src/app/qgsoptions.cpp
Expand Up @@ -78,6 +78,9 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
}
}

//Network timeout
mNetworkTimeoutSpinBox->setValue( settings.value( "/qgis/networkAndProxy/networkTimeout", "60000" ).toInt() );

//Web proxy settings
grpProxy->setChecked( settings.value( "proxy/proxyEnabled", "0" ).toBool() );
leProxyHost->setText( settings.value( "proxy/proxyHost", "" ).toString() );
Expand Down Expand Up @@ -274,7 +277,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
{
mMarkerStyleComboBox->setCurrentIndex( mMarkerStyleComboBox->findText( tr( "None" ) ) );
}
mMarkerSizeSpinBox->setValue( settings.value( "/qgis/digitizing/marker_size", 7 ).toInt()*2+1 );
mMarkerSizeSpinBox->setValue( settings.value( "/qgis/digitizing/marker_size", 7 ).toInt()*2 + 1 );

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

Expand Down Expand Up @@ -352,7 +355,7 @@ QString QgsOptions::theme()
void QgsOptions::saveOptions()
{
QSettings settings;

//search directories for svgs
QString myPaths;
for ( int i = 0; i < mListSVGPaths->count(); ++i )
Expand All @@ -365,6 +368,9 @@ void QgsOptions::saveOptions()
}
settings.setValue( "svg/searchPathsForSVG", myPaths );

//Network timeout
settings.setValue( "/qgis/networkAndProxy/networkTimeout", mNetworkTimeoutSpinBox->value() );

//Web proxy settings
settings.setValue( "proxy/proxyEnabled", grpProxy->isChecked() );
settings.setValue( "proxy/proxyHost", leProxyHost->text() );
Expand Down Expand Up @@ -518,7 +524,7 @@ void QgsOptions::saveOptions()
{
settings.setValue( "/qgis/digitizing/marker_style", "None" );
}
settings.setValue( "/qgis/digitizing/marker_size", (mMarkerSizeSpinBox->value()-1)/2 );
settings.setValue( "/qgis/digitizing/marker_size", ( mMarkerSizeSpinBox->value() - 1 ) / 2 );

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

Expand Down Expand Up @@ -710,11 +716,11 @@ QStringList QgsOptions::i18nList()
void QgsOptions::on_mBtnAddSVGPath_clicked()
{
QString myDir = QFileDialog::getExistingDirectory(
this,
tr( "Choose a directory" ),
QDir::toNativeSeparators( QDir::homePath() ),
QFileDialog::ShowDirsOnly
);
this,
tr( "Choose a directory" ),
QDir::toNativeSeparators( QDir::homePath() ),
QFileDialog::ShowDirsOnly
);

if ( ! myDir.isEmpty() )
{
Expand Down
18 changes: 12 additions & 6 deletions src/core/qgshttptransaction.cpp
Expand Up @@ -31,7 +31,6 @@
#include <QTimer>
#include "qgslogger.h"

static int NETWORK_TIMEOUT_MSEC = ( 120 * 1000 ); // 120 seconds
static int HTTP_PORT_DEFAULT = 80;

//XXX Set the connection name when creating the provider instance
Expand All @@ -51,6 +50,13 @@ QgsHttpTransaction::QgsHttpTransaction( QString uri,
httphost( proxyHost ),
mError( 0 )
{
QSettings s;
mNetworkTimeoutMsec = s.value( "/qgis/networkAndProxy/networkTimeout", "20000" ).toInt();
}

QgsHttpTransaction::QgsHttpTransaction()
{

}

QgsHttpTransaction::~QgsHttpTransaction()
Expand Down Expand Up @@ -175,7 +181,7 @@ bool QgsHttpTransaction::getSynchronously( QByteArray &respondedContent, int red
this, SLOT( networkTimedOut() ) );

mWatchdogTimer->setSingleShot( TRUE );
mWatchdogTimer->start( NETWORK_TIMEOUT_MSEC );
mWatchdogTimer->start( mNetworkTimeoutMsec );

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

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

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

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

emit dataReadProgress( done );
emit totalSteps( total );
Expand Down Expand Up @@ -414,7 +420,7 @@ void QgsHttpTransaction::dataStateChanged( int state )
QgsDebugMsg( "state " + QString::number( state ) + "." );

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

switch ( state )
{
Expand Down Expand Up @@ -467,7 +473,7 @@ void QgsHttpTransaction::networkTimedOut()
QgsDebugMsg( "entering." );

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

QgsDebugMsg( "Setting httpactive = FALSE" );
httpactive = FALSE;
Expand Down
11 changes: 11 additions & 0 deletions src/core/qgshttptransaction.h
Expand Up @@ -96,6 +96,11 @@ class CORE_EXPORT QgsHttpTransaction : public QObject

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

/**Returns the network timeout in msec*/
int networkTimeout() const { return mNetworkTimeoutMsec;}
/**Sets the network timeout in milliseconds*/
void setNetworkTimeout( int msec ) { mNetworkTimeoutMsec = msec;}


public slots:

Expand Down Expand Up @@ -134,6 +139,9 @@ class CORE_EXPORT QgsHttpTransaction : public QObject

private:

/**Default constructor is forbidden*/
QgsHttpTransaction();

/**
* Indicates the associated QHttp object
*
Expand Down Expand Up @@ -207,6 +215,9 @@ class CORE_EXPORT QgsHttpTransaction : public QObject
* Password
*/
QString mPassword;

/**Network timeout in milliseconds*/
int mNetworkTimeoutMsec;
};

#endif
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/wfs/qgswfssourceselect.cpp
Expand Up @@ -143,7 +143,10 @@ int QgsWFSSourceSelect::getCapabilitiesGET( QString uri, std::list<QString>& typ

QByteArray result;
QgsHttpTransaction http( request );
http.getSynchronously( result );
if ( !http.getSynchronously( result ) )
{
QMessageBox::critical( 0, tr( "Error" ), tr( "The capabilities document could not be retrieved from the server" ) );
}

QDomDocument capabilitiesDocument;
if ( !capabilitiesDocument.setContent( result, true ) )
Expand Down
10 changes: 9 additions & 1 deletion src/providers/wfs/qgswfsdata.cpp
Expand Up @@ -23,6 +23,7 @@
#include <QList>
#include <QProgressDialog>
#include <QSet>
#include <QSettings>

//just for a test
//#include <QProgressDialog>
Expand Down Expand Up @@ -64,8 +65,12 @@ QgsWFSData::QgsWFSData(
}
}

QSettings s;
mNetworkTimeoutMsec = s.value( "/qgis/networkAndProxy/networkTimeout", "60000" ).toInt();

mEndian = QgsApplication::endian();
QObject::connect( &mHttp, SIGNAL( done( bool ) ), this, SLOT( setFinished( bool ) ) );
QObject::connect( &mNetworkTimeoutTimer, SIGNAL( timeout() ), this, SLOT( setFinished() ) );
}

QgsWFSData::~QgsWFSData()
Expand Down Expand Up @@ -115,7 +120,9 @@ int QgsWFSData::getWFSData()
progressDialog->show();
}

//mHttp.get( mUri );
//setup timer
mNetworkTimeoutTimer.setSingleShot( true );
mNetworkTimeoutTimer.start( mNetworkTimeoutMsec );
mHttp.get( requestUrl.path() + "?" + QString( requestUrl.encodedQuery() ) );


Expand Down Expand Up @@ -169,6 +176,7 @@ void QgsWFSData::handleProgressEvent( int progress, int totalSteps )
{
emit dataReadProgress( progress );
emit totalStepsUpdate( totalSteps );
mNetworkTimeoutTimer.start( mNetworkTimeoutMsec );
}

void QgsWFSData::startElement( const XML_Char* el, const XML_Char** attr )
Expand Down
5 changes: 4 additions & 1 deletion src/providers/wfs/qgswfsdata.h
Expand Up @@ -16,6 +16,7 @@
#define QGSWFSDATA_H

#include <QHttp>
#include <QTimer>
#include <expat.h>
#include "qgis.h"
#include "qgsapplication.h"
Expand Down Expand Up @@ -56,7 +57,7 @@ class QgsWFSData: public QObject
const QHttp* http() const {return &mHttp;}

private slots:
void setFinished( bool error );
void setFinished( bool error = true );

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

#endif

0 comments on commit 0bee933

Please sign in to comment.