@@ -1854,20 +1854,33 @@ int QgsWmsCapabilities::identifyCapabilities() const
1854
1854
1855
1855
// -----------------
1856
1856
1857
+ QgsWmsCapabilitiesDownload::QgsWmsCapabilitiesDownload ( QObject *parent )
1858
+ : QObject( parent )
1859
+ , mCapabilitiesReply( 0 )
1860
+ , mIsAborted( false )
1861
+ {
1862
+ }
1857
1863
1858
1864
QgsWmsCapabilitiesDownload::QgsWmsCapabilitiesDownload ( const QString& baseUrl, const QgsWmsAuthorization& auth, QObject *parent )
1859
1865
: QObject( parent )
1860
1866
, mBaseUrl( baseUrl )
1861
1867
, mAuth( auth )
1862
- , mCapabilitiesReply( NULL )
1868
+ , mCapabilitiesReply( 0 )
1869
+ , mIsAborted( false )
1863
1870
{
1864
1871
}
1865
1872
1873
+ bool QgsWmsCapabilitiesDownload::downloadCapabilities ( const QString& baseUrl, const QgsWmsAuthorization& auth )
1874
+ {
1875
+ mBaseUrl = baseUrl;
1876
+ mAuth = auth;
1877
+ return downloadCapabilities ();
1878
+ }
1866
1879
1867
1880
bool QgsWmsCapabilitiesDownload::downloadCapabilities ()
1868
1881
{
1869
1882
QgsDebugMsg ( " entering." );
1870
-
1883
+ mIsAborted = false ;
1871
1884
QString url = mBaseUrl ;
1872
1885
QgsDebugMsg ( " url = " + url );
1873
1886
if ( !url.contains ( " SERVICE=WMTS" ) &&
@@ -1886,6 +1899,10 @@ bool QgsWmsCapabilitiesDownload::downloadCapabilities()
1886
1899
QgsDebugMsg ( QString ( " getcapabilities: %1" ).arg ( url ) );
1887
1900
// This is causing Qt warning: "Cannot create children for a parent that is in a different thread."
1888
1901
// but it only means that the reply will have no parent
1902
+ if ( mIsAborted )
1903
+ {
1904
+ return false ;
1905
+ }
1889
1906
mCapabilitiesReply = QgsNetworkAccessManager::instance ()->get ( request );
1890
1907
1891
1908
connect ( mCapabilitiesReply , SIGNAL ( finished () ), this , SLOT ( capabilitiesReplyFinished () ), Qt::DirectConnection );
@@ -1898,7 +1915,15 @@ bool QgsWmsCapabilitiesDownload::downloadCapabilities()
1898
1915
return mError .isEmpty ();
1899
1916
}
1900
1917
1901
-
1918
+ void QgsWmsCapabilitiesDownload::abort ()
1919
+ {
1920
+ QgsDebugMsg ( " Entered" );
1921
+ mIsAborted = true ;
1922
+ if ( mCapabilitiesReply )
1923
+ {
1924
+ mCapabilitiesReply ->abort ();
1925
+ }
1926
+ }
1902
1927
1903
1928
void QgsWmsCapabilitiesDownload::capabilitiesReplyProgress ( qint64 bytesReceived, qint64 bytesTotal )
1904
1929
{
@@ -1910,54 +1935,57 @@ void QgsWmsCapabilitiesDownload::capabilitiesReplyProgress( qint64 bytesReceived
1910
1935
void QgsWmsCapabilitiesDownload::capabilitiesReplyFinished ()
1911
1936
{
1912
1937
QgsDebugMsg ( " entering." );
1913
- if ( mCapabilitiesReply -> error () == QNetworkReply::NoError )
1938
+ if ( ! mIsAborted )
1914
1939
{
1915
- QgsDebugMsg ( " reply ok" );
1916
- QVariant redirect = mCapabilitiesReply ->attribute ( QNetworkRequest::RedirectionTargetAttribute );
1917
- if ( !redirect.isNull () )
1940
+ if ( mCapabilitiesReply ->error () == QNetworkReply::NoError )
1918
1941
{
1919
- emit statusChanged ( tr ( " Capabilities request redirected." ) );
1920
-
1921
- const QUrl& toUrl = redirect.toUrl ();
1922
- mCapabilitiesReply ->request ();
1923
- if ( toUrl == mCapabilitiesReply ->url () )
1942
+ QgsDebugMsg ( " reply ok" );
1943
+ QVariant redirect = mCapabilitiesReply ->attribute ( QNetworkRequest::RedirectionTargetAttribute );
1944
+ if ( !redirect.isNull () )
1924
1945
{
1925
- mError = tr ( " Redirect loop detected: %1" ).arg ( toUrl.toString () );
1926
- QgsMessageLog::logMessage ( mError , tr ( " WMS" ) );
1927
- mHttpCapabilitiesResponse .clear ();
1946
+ emit statusChanged ( tr ( " Capabilities request redirected." ) );
1947
+
1948
+ const QUrl& toUrl = redirect.toUrl ();
1949
+ mCapabilitiesReply ->request ();
1950
+ if ( toUrl == mCapabilitiesReply ->url () )
1951
+ {
1952
+ mError = tr ( " Redirect loop detected: %1" ).arg ( toUrl.toString () );
1953
+ QgsMessageLog::logMessage ( mError , tr ( " WMS" ) );
1954
+ mHttpCapabilitiesResponse .clear ();
1955
+ }
1956
+ else
1957
+ {
1958
+ QNetworkRequest request ( toUrl );
1959
+ mAuth .setAuthorization ( request );
1960
+ request.setAttribute ( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork );
1961
+ request.setAttribute ( QNetworkRequest::CacheSaveControlAttribute, true );
1962
+
1963
+ mCapabilitiesReply ->deleteLater ();
1964
+ QgsDebugMsg ( QString ( " redirected getcapabilities: %1" ).arg ( redirect.toString () ) );
1965
+ mCapabilitiesReply = QgsNetworkAccessManager::instance ()->get ( request );
1966
+
1967
+ connect ( mCapabilitiesReply , SIGNAL ( finished () ), this , SLOT ( capabilitiesReplyFinished () ) );
1968
+ connect ( mCapabilitiesReply , SIGNAL ( downloadProgress ( qint64, qint64 ) ), this , SLOT ( capabilitiesReplyProgress ( qint64, qint64 ) ) );
1969
+ return ;
1970
+ }
1928
1971
}
1929
1972
else
1930
1973
{
1931
- QNetworkRequest request ( toUrl );
1932
- mAuth .setAuthorization ( request );
1933
- request.setAttribute ( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork );
1934
- request.setAttribute ( QNetworkRequest::CacheSaveControlAttribute, true );
1974
+ mHttpCapabilitiesResponse = mCapabilitiesReply ->readAll ();
1935
1975
1936
- mCapabilitiesReply ->deleteLater ();
1937
- QgsDebugMsg ( QString ( " redirected getcapabilities: %1" ).arg ( redirect.toString () ) );
1938
- mCapabilitiesReply = QgsNetworkAccessManager::instance ()->get ( request );
1939
-
1940
- connect ( mCapabilitiesReply , SIGNAL ( finished () ), this , SLOT ( capabilitiesReplyFinished () ) );
1941
- connect ( mCapabilitiesReply , SIGNAL ( downloadProgress ( qint64, qint64 ) ), this , SLOT ( capabilitiesReplyProgress ( qint64, qint64 ) ) );
1942
- return ;
1976
+ if ( mHttpCapabilitiesResponse .isEmpty () )
1977
+ {
1978
+ mError = tr ( " empty of capabilities: %1" ).arg ( mCapabilitiesReply ->errorString () );
1979
+ }
1943
1980
}
1944
1981
}
1945
1982
else
1946
1983
{
1947
- mHttpCapabilitiesResponse = mCapabilitiesReply ->readAll ();
1948
-
1949
- if ( mHttpCapabilitiesResponse .isEmpty () )
1950
- {
1951
- mError = tr ( " empty of capabilities: %1" ).arg ( mCapabilitiesReply ->errorString () );
1952
- }
1984
+ mError = tr ( " Download of capabilities failed: %1" ).arg ( mCapabilitiesReply ->errorString () );
1985
+ QgsMessageLog::logMessage ( mError , tr ( " WMS" ) );
1986
+ mHttpCapabilitiesResponse .clear ();
1953
1987
}
1954
1988
}
1955
- else
1956
- {
1957
- mError = tr ( " Download of capabilities failed: %1" ).arg ( mCapabilitiesReply ->errorString () );
1958
- QgsMessageLog::logMessage ( mError , tr ( " WMS" ) );
1959
- mHttpCapabilitiesResponse .clear ();
1960
- }
1961
1989
1962
1990
mCapabilitiesReply ->deleteLater ();
1963
1991
mCapabilitiesReply = 0 ;
0 commit comments