diff --git a/src/downloader.cpp b/src/downloader.cpp index 5c34c0ed..ab65e660 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -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); diff --git a/src/downloader.h b/src/downloader.h index c33af8d6..ee16262c 100644 --- a/src/downloader.h +++ b/src/downloader.h @@ -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; }; diff --git a/src/map.cpp b/src/map.cpp index d8ff6b73..52883390 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -42,10 +42,11 @@ void Map::loadTilesAsync(QList &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 &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())