Skip to content
Permalink
Browse files

[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
  • Loading branch information
mhugent
mhugent committed Nov 4, 2009
1 parent 1bf41d8 commit 0bee9335f0802e34769855b3985c53cff68db20f
@@ -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() );
@@ -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() );

@@ -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 )
@@ -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() );
@@ -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() );

@@ -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() )
{
@@ -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
@@ -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()
@@ -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" );
@@ -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
{
@@ -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 );
@@ -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 )
{
@@ -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;
@@ -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:

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

private:

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

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

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

#endif
@@ -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 ) )
@@ -23,6 +23,7 @@
#include <QList>
#include <QProgressDialog>
#include <QSet>
#include <QSettings>

//just for a test
//#include <QProgressDialog>
@@ -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()
@@ -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() ) );


@@ -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 )
@@ -16,6 +16,7 @@
#define QGSWFSDATA_H

#include <QHttp>
#include <QTimer>
#include <expat.h>
#include "qgis.h"
#include "qgsapplication.h"
@@ -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 );
@@ -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.
You can’t perform that action at this time.