1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 03:35:53 +01:00

Fixed infinite download loop on broken tile images

Added support for HTTP redirects
This commit is contained in:
Martin Tůma 2016-06-16 20:32:11 +02:00
parent 40803d68c1
commit 31f6eeac26
3 changed files with 17 additions and 7 deletions

View File

@ -64,9 +64,16 @@ void Downloader::downloadFinished(QNetworkReply *reply)
fprintf(stderr, "Error downloading map tile: %s: %s\n",
url.toEncoded().constData(), qPrintable(reply->errorString()));
} else {
QUrl redirect = reply->attribute(
QNetworkRequest::RedirectionTargetAttribute).toUrl();
QString filename = reply->request().attribute(QNetworkRequest::User)
.toString();
saveToDisk(filename, reply);
if (!redirect.isEmpty()) {
Download dl(redirect, filename);
doDownload(dl);
} else
saveToDisk(filename, reply);
}
_currentDownloads.removeAll(reply);

View File

@ -12,13 +12,13 @@
class Download
{
public:
Download(const QString &url, const QString &file)
Download(const QUrl &url, const QString &file)
{_url = url; _file = file;}
const QString& url() const {return _url;}
const QUrl& url() const {return _url;}
const QString& file() const {return _file;}
private:
QString _url;
QUrl _url;
QString _file;
};

View File

@ -42,10 +42,11 @@ void Map::loadTilesAsync(QList<Tile> &list)
QString file = tileFile(t);
QFileInfo fi(file);
if (!(fi.exists() && loadTileFile(t, file))) {
if (!fi.exists()) {
fillTile(t);
dl.append(Download(tileUrl(t), file));
}
} else
loadTileFile(t, file);
}
if (!dl.empty())
@ -61,8 +62,10 @@ void Map::loadTilesSync(QList<Tile> &list)
QString file = tileFile(t);
QFileInfo fi(file);
if (!(fi.exists() && loadTileFile(t, file)))
if (!fi.exists())
dl.append(Download(tileUrl(t), file));
else
loadTileFile(t, file);
}
if (dl.empty())