17 #include <QCryptographicHash>
20 #include <QImageReader>
21 #include <QStandardPaths>
51 QNetworkDiskCache* disk_cache =
new QNetworkDiskCache(
this);
52 QString
const cache_path =
53 QDir(QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation)).filePath(
"rviz_satellite");
54 disk_cache->setCacheDirectory(cache_path);
56 disk_cache->setMaximumCacheSize(std::numeric_limits<qint64>::max());
69 auto const request_url = QUrl(QString::fromStdString(
tileURL(tile_id)));
72 QNetworkRequest request(request_url);
73 char constexpr agent[] =
"rviz_satellite/" RVIZ_SATELLITE_VERSION
" (+https://github.com/gareth-cross/"
75 request.setHeader(QNetworkRequest::KnownHeaders::UserAgentHeader, agent);
77 variant.setValue(tile_id);
78 request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::CacheLoadControl::PreferCache);
79 request.setAttribute(QNetworkRequest::User, variant);
86 QVariant
const variant = reply->request().attribute(QNetworkRequest::User);
89 QUrl
const url = reply->url();
92 ROS_ERROR_STREAM(
"Got error when loading tile: " << reply->errorString().toStdString());
102 bool const from_cache = reply->attribute(QNetworkRequest::SourceIsFromCacheAttribute).toBool();
112 QImageReader reader(reply);
113 if (!reader.canRead())
115 ROS_ERROR_STREAM(
"Unable to decode image at " << reply->request().url().toString().toLatin1().data());
121 reply->deleteLater();