Skip to content

Commit

Permalink
- extend support for user defined network timeout to QgsNetworkAccess…
Browse files Browse the repository at this point in the history
…Manager

- support for user defined tile expiration time for WMTS/WMS-C tiles (fixes #5104)
  • Loading branch information
jef-n committed Aug 18, 2012
1 parent 804f253 commit bb623a8
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 20 deletions.
6 changes: 6 additions & 0 deletions src/app/qgsoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
//Network timeout
mNetworkTimeoutSpinBox->setValue( settings.value( "/qgis/networkAndProxy/networkTimeout", "60000" ).toInt() );

// WMS/WMS-C tile expiry time
mDefaultTileExpirySpinBox->setValue( settings.value( "/qgis/defaultTileExpiry", "24" ).toInt() );

//Web proxy settings
grpProxy->setChecked( settings.value( "proxy/proxyEnabled", "0" ).toBool() );
leProxyHost->setText( settings.value( "proxy/proxyHost", "" ).toString() );
Expand Down Expand Up @@ -768,6 +771,9 @@ void QgsOptions::saveOptions()
//Network timeout
settings.setValue( "/qgis/networkAndProxy/networkTimeout", mNetworkTimeoutSpinBox->value() );

// WMS/WMS-C tile expiry time
settings.setValue( "/qgis/defaultTileExpiry", mDefaultTileExpirySpinBox->value() );

//Web proxy settings
settings.setValue( "proxy/proxyEnabled", grpProxy->isChecked() );
settings.setValue( "proxy/proxyHost", leProxyHost->text() );
Expand Down
10 changes: 10 additions & 0 deletions src/core/qgsnetworkaccessmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#include <qgslogger.h>

#include <QUrl>
#include <QSettings>
#include <QTimer>
#include <QNetworkReply>

#if QT_VERSION >= 0x40500
class QgsNetworkProxyFactory : public QNetworkProxyFactory
Expand Down Expand Up @@ -126,5 +129,12 @@ QNetworkReply *QgsNetworkAccessManager::createRequest( QNetworkAccessManager::Op
emit requestAboutToBeCreated( op, req, outgoingData );
QNetworkReply *reply = QNetworkAccessManager::createRequest( op, req, outgoingData );
emit requestCreated( reply );

// abort request, when network timeout happens
QTimer *timer = new QTimer( reply );

QSettings s;
timer->singleShot( s.value( "/qgis/networkAndProxy/networkTimeout", "20000" ).toInt(), reply, SLOT( abort() ) );

return reply;
}
7 changes: 7 additions & 0 deletions src/providers/wms/qgswmsprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,13 @@ void QgsWmsProvider::tileReplyFinished()
}
cmd.setRawHeaders( hl );

QgsDebugMsg( QString( "expirationDate:%1" ).arg( cmd.expirationDate().toString() ) );
if( cmd.expirationDate().isNull() )
{
QSettings s;
cmd.setExpirationDate( QDateTime::currentDateTime().addSecs( s.value( "/qgis/defaultTileExpiry", "24" ).toInt() * 60 * 60 ) );
}

QgsNetworkAccessManager::instance()->cache()->updateMetaData( cmd );

int tileReqNo = reply->request().attribute( static_cast<QNetworkRequest::Attribute>( QNetworkRequest::User + 0 ) ).toInt();
Expand Down
58 changes: 38 additions & 20 deletions src/ui/qgsoptionsbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>807</width>
<height>673</height>
<width>810</width>
<height>674</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -66,8 +66,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>773</width>
<height>938</height>
<width>784</width>
<height>1099</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
Expand Down Expand Up @@ -948,9 +948,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>-169</y>
<width>938</width>
<height>785</height>
<y>0</y>
<width>1201</width>
<height>850</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_8">
Expand Down Expand Up @@ -1464,8 +1464,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>773</width>
<height>718</height>
<width>646</width>
<height>778</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_4">
Expand Down Expand Up @@ -1834,8 +1834,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>791</width>
<height>599</height>
<width>317</width>
<height>91</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_10">
Expand Down Expand Up @@ -1915,8 +1915,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>791</width>
<height>599</height>
<width>679</width>
<height>642</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_13">
Expand Down Expand Up @@ -2291,8 +2291,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>791</width>
<height>599</height>
<width>745</width>
<height>431</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_15">
Expand Down Expand Up @@ -2478,8 +2478,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>791</width>
<height>599</height>
<width>519</width>
<height>575</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_17">
Expand Down Expand Up @@ -2575,8 +2575,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>791</width>
<height>599</height>
<width>589</width>
<height>582</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_20">
Expand Down Expand Up @@ -2768,7 +2768,7 @@
</item>
</layout>
</item>
<item row="3" column="0">
<item row="4" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="mNetworkTimeoutLabel">
Expand All @@ -2786,6 +2786,24 @@
</item>
</layout>
</item>
<item row="5" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_17">
<item>
<widget class="QLabel" name="label_32">
<property name="text">
<string>Default expiration period for WMS-C/WMTS tiles (hours)</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="mDefaultTileExpirySpinBox">
<property name="maximum">
<number>100000000</number>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
Expand Down

0 comments on commit bb623a8

Please sign in to comment.