From 0ffd864832bbc973215df1c754f8976cab815ce1 Mon Sep 17 00:00:00 2001 From: Gus Grubba Date: Fri, 7 Apr 2017 10:46:15 -0400 Subject: [PATCH] Handle network availability transitions. --- src/QtLocationPlugin/QGCTileCacheWorker.cpp | 1 + src/QtLocationPlugin/QGeoMapReplyQGC.cpp | 33 +++++++++------------ src/QtLocationPlugin/QGeoMapReplyQGC.h | 1 - src/QtLocationPlugin/QGeoTileFetcherQGC.cpp | 4 +-- 4 files changed, 16 insertions(+), 23 deletions(-) diff --git a/src/QtLocationPlugin/QGCTileCacheWorker.cpp b/src/QtLocationPlugin/QGCTileCacheWorker.cpp index 0e4691497..c188025bf 100644 --- a/src/QtLocationPlugin/QGCTileCacheWorker.cpp +++ b/src/QtLocationPlugin/QGCTileCacheWorker.cpp @@ -1039,6 +1039,7 @@ QGCCacheWorker::_testInternet() QTcpSocket socket; socket.connectToHost("8.8.8.8", 53); if (socket.waitForConnected(2500)) { + qCDebug(QGCTileCacheLog) << "Yes Internet Access"; emit internetStatus(true); return; } diff --git a/src/QtLocationPlugin/QGeoMapReplyQGC.cpp b/src/QtLocationPlugin/QGeoMapReplyQGC.cpp index a4ccd09a2..0747eb4c4 100644 --- a/src/QtLocationPlugin/QGeoMapReplyQGC.cpp +++ b/src/QtLocationPlugin/QGeoMapReplyQGC.cpp @@ -62,7 +62,15 @@ QGeoTiledMapReplyQGC::QGeoTiledMapReplyQGC(QNetworkAccessManager *networkManager , _networkManager(networkManager) { if(_request.url().isEmpty()) { - _returnBadTile(); + if(!_badMapBox.size()) { + QFile b(":/res/notile.png"); + if(b.open(QFile::ReadOnly)) + _badMapBox = b.readAll(); + } + setMapImageData(_badMapBox); + setMapImageFormat("png"); + setFinished(true); + setCached(false); } else { QGCFetchTileTask* task = getQGCMapEngine()->createFetchTileTask((UrlFactory::MapType)spec.mapId(), spec.x(), spec.y(), spec.zoom()); connect(task, &QGCFetchTileTask::tileFetched, this, &QGeoTiledMapReplyQGC::cacheReply); @@ -89,21 +97,6 @@ QGeoTiledMapReplyQGC::_clearReply() } } -//----------------------------------------------------------------------------- -void -QGeoTiledMapReplyQGC::_returnBadTile() -{ - if(!_badMapBox.size()) { - QFile b(":/res/notile.png"); - if(b.open(QFile::ReadOnly)) - _badMapBox = b.readAll(); - } - setMapImageData(_badMapBox); - setMapImageFormat("png"); - setFinished(true); - setCached(false); -} - //----------------------------------------------------------------------------- void QGeoTiledMapReplyQGC::abort() @@ -145,8 +138,9 @@ QGeoTiledMapReplyQGC::networkReplyError(QNetworkReply::NetworkError error) } if (error != QNetworkReply::OperationCanceledError) { qWarning() << "Fetch tile error:" << _reply->errorString(); + setError(QGeoTiledMapReply::CommunicationError, _reply->errorString()); } - _returnBadTile(); + setFinished(true); _clearReply(); } @@ -154,8 +148,9 @@ QGeoTiledMapReplyQGC::networkReplyError(QNetworkReply::NetworkError error) void QGeoTiledMapReplyQGC::cacheError(QGCMapTask::TaskType type, QString /*errorString*/) { - if(_networkManager->networkAccessible() < QNetworkAccessManager::Accessible || !getQGCMapEngine()->isInternetActive()) { - _returnBadTile(); + if(!getQGCMapEngine()->isInternetActive()) { + setError(QGeoTiledMapReply::CommunicationError, "Network not available"); + setFinished(true); } else { if(type != QGCMapTask::taskFetchTile) { qWarning() << "QGeoTiledMapReplyQGC::cacheError() for wrong task"; diff --git a/src/QtLocationPlugin/QGeoMapReplyQGC.h b/src/QtLocationPlugin/QGeoMapReplyQGC.h index 46c38e529..132c5d28b 100644 --- a/src/QtLocationPlugin/QGeoMapReplyQGC.h +++ b/src/QtLocationPlugin/QGeoMapReplyQGC.h @@ -70,7 +70,6 @@ private slots: private: void _clearReply (); - void _returnBadTile (); private: QNetworkReply* _reply; diff --git a/src/QtLocationPlugin/QGeoTileFetcherQGC.cpp b/src/QtLocationPlugin/QGeoTileFetcherQGC.cpp index 1b38673ce..860b82096 100644 --- a/src/QtLocationPlugin/QGeoTileFetcherQGC.cpp +++ b/src/QtLocationPlugin/QGeoTileFetcherQGC.cpp @@ -82,7 +82,5 @@ QGeoTileFetcherQGC::getTileImage(const QGeoTileSpec &spec) void QGeoTileFetcherQGC::timeout() { - if(!getQGCMapEngine()->isInternetActive()) { - getQGCMapEngine()->testInternet(); - } + getQGCMapEngine()->testInternet(); } -- 2.22.0