4
4
5
5
#include < QFile>
6
6
#include < QDir>
7
+ #include < QNetworkCacheMetaData>
8
+ #include < QSettings>
7
9
8
10
#include " qgscoordinatetransform.h"
9
11
#include " qgsdatasourceuri.h"
@@ -709,11 +711,14 @@ void QgsWmsCapabilities::parseLayer( QDomElement const & e, QgsWmsLayerProperty&
709
711
// QgsDebugMsg( "entering." );
710
712
711
713
// TODO: Delete this stanza completely, depending on success of "Inherit things into the sublayer" below.
712
- // // enforce WMS non-inheritance rules
713
- // layerProperty.name = QString::null;
714
- // layerProperty.title = QString::null;
715
- // layerProperty.abstract = QString::null;
716
- // layerProperty.keywordList.clear();
714
+ #if 0
715
+ // enforce WMS non-inheritance rules
716
+ layerProperty.name = QString::null;
717
+ layerProperty.title = QString::null;
718
+ layerProperty.abstract = QString::null;
719
+ layerProperty.keywordList.clear();
720
+ #endif
721
+
717
722
layerProperty.orderId = ++mLayerCount ;
718
723
layerProperty.queryable = e.attribute ( " queryable" ).toUInt ();
719
724
layerProperty.cascaded = e.attribute ( " cascaded" ).toUInt ();
@@ -1860,20 +1865,22 @@ int QgsWmsCapabilities::identifyCapabilities() const
1860
1865
1861
1866
// -----------------
1862
1867
1863
- QgsWmsCapabilitiesDownload::QgsWmsCapabilitiesDownload ( QObject *parent )
1868
+ QgsWmsCapabilitiesDownload::QgsWmsCapabilitiesDownload ( bool forceRefresh, QObject *parent )
1864
1869
: QObject( parent )
1865
1870
, mCapabilitiesReply( 0 )
1866
1871
, mIsAborted( false )
1872
+ , mForceRefresh( forceRefresh )
1867
1873
{
1868
1874
connectManager ();
1869
1875
}
1870
1876
1871
- QgsWmsCapabilitiesDownload::QgsWmsCapabilitiesDownload ( const QString& baseUrl, const QgsWmsAuthorization& auth, QObject *parent )
1877
+ QgsWmsCapabilitiesDownload::QgsWmsCapabilitiesDownload ( const QString& baseUrl, const QgsWmsAuthorization& auth, bool forceRefresh, QObject *parent )
1872
1878
: QObject( parent )
1873
1879
, mBaseUrl( baseUrl )
1874
1880
, mAuth( auth )
1875
1881
, mCapabilitiesReply( 0 )
1876
1882
, mIsAborted( false )
1883
+ , mForceRefresh( forceRefresh )
1877
1884
{
1878
1885
connectManager ();
1879
1886
}
@@ -1902,7 +1909,7 @@ bool QgsWmsCapabilitiesDownload::downloadCapabilities( const QString& baseUrl, c
1902
1909
1903
1910
bool QgsWmsCapabilitiesDownload::downloadCapabilities ()
1904
1911
{
1905
- QgsDebugMsg ( " entering. " );
1912
+ QgsDebugMsg ( QString ( " entering: forceRefresh=%1 " ). arg ( mForceRefresh ) );
1906
1913
abort (); // cancel previous
1907
1914
mIsAborted = false ;
1908
1915
@@ -1923,7 +1930,7 @@ bool QgsWmsCapabilitiesDownload::downloadCapabilities()
1923
1930
QgsMessageLog::logMessage ( mError , tr ( " WMS" ) );
1924
1931
return false ;
1925
1932
}
1926
- request.setAttribute ( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork );
1933
+ request.setAttribute ( QNetworkRequest::CacheLoadControlAttribute, mForceRefresh ? QNetworkRequest::PreferNetwork : QNetworkRequest::PreferCache );
1927
1934
request.setAttribute ( QNetworkRequest::CacheSaveControlAttribute, true );
1928
1935
1929
1936
connect ( QgsNetworkAccessManager::instance (), SIGNAL ( requestSent ( QNetworkReply *, QObject * ) ),
@@ -2014,13 +2021,13 @@ void QgsWmsCapabilitiesDownload::capabilitiesReplyFinished()
2014
2021
emit downloadFinished ();
2015
2022
return ;
2016
2023
}
2017
- request.setAttribute ( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork );
2024
+ request.setAttribute ( QNetworkRequest::CacheLoadControlAttribute, mForceRefresh ? QNetworkRequest::PreferNetwork : QNetworkRequest::PreferCache );
2018
2025
request.setAttribute ( QNetworkRequest::CacheSaveControlAttribute, true );
2019
2026
2020
2027
mCapabilitiesReply ->deleteLater ();
2021
2028
mCapabilitiesReply = 0 ;
2022
2029
2023
- QgsDebugMsg ( QString ( " redirected getcapabilities: %1" ).arg ( redirect.toString () ) );
2030
+ QgsDebugMsg ( QString ( " redirected getcapabilities: %1 forceRefresh=%2 " ).arg ( redirect.toString () ). arg ( mForceRefresh ) );
2024
2031
// mCapabilitiesReply = QgsNetworkAccessManager::instance()->get( request );
2025
2032
connect ( QgsNetworkAccessManager::instance (),
2026
2033
SIGNAL ( requestSent ( QNetworkReply *, QObject * ) ),
@@ -2031,6 +2038,37 @@ void QgsWmsCapabilitiesDownload::capabilitiesReplyFinished()
2031
2038
}
2032
2039
else
2033
2040
{
2041
+ const QgsNetworkAccessManager *nam = QgsNetworkAccessManager::instance ();
2042
+
2043
+ if ( nam->cache () )
2044
+ {
2045
+ QNetworkCacheMetaData cmd = nam->cache ()->metaData ( mCapabilitiesReply ->request ().url () );
2046
+
2047
+ QNetworkCacheMetaData::RawHeaderList hl;
2048
+ Q_FOREACH ( const QNetworkCacheMetaData::RawHeader &h, cmd.rawHeaders () )
2049
+ {
2050
+ if ( h.first != " Cache-Control" )
2051
+ hl.append ( h );
2052
+ }
2053
+ cmd.setRawHeaders ( hl );
2054
+
2055
+ QgsDebugMsg ( QString ( " expirationDate:%1" ).arg ( cmd.expirationDate ().toString () ) );
2056
+ if ( cmd.expirationDate ().isNull () )
2057
+ {
2058
+ QSettings s;
2059
+ cmd.setExpirationDate ( QDateTime::currentDateTime ().addSecs ( s.value ( " /qgis/defaultCapabilitiesExpiry" , " 24" ).toInt () * 60 * 60 ) );
2060
+ }
2061
+
2062
+ nam->cache ()->updateMetaData ( cmd );
2063
+ }
2064
+ else
2065
+ {
2066
+ QgsDebugMsg ( " No cache for capabilites!" );
2067
+ }
2068
+
2069
+ bool fromCache = mCapabilitiesReply ->attribute ( QNetworkRequest::SourceIsFromCacheAttribute ).toBool ();
2070
+ QgsDebugMsg ( QString ( " Capabilities reply was cached: %1" ).arg ( fromCache ) );
2071
+
2034
2072
mHttpCapabilitiesResponse = mCapabilitiesReply ->readAll ();
2035
2073
2036
2074
if ( mHttpCapabilitiesResponse .isEmpty () )
0 commit comments