diff --git a/src/downloader.cpp b/src/downloader.cpp index 7a8372c6..a4c9318b 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -51,14 +51,29 @@ bool Downloader::saveToDisk(const QString &filename, QIODevice *data) void Downloader::downloadFinished(QNetworkReply *reply) { + QByteArray ct_key("Content-Type"); + QByteArray ct_val; QUrl url = reply->url(); if (reply->error()) { fprintf(stderr, "Error downloading map tile: %s: %s\n", url.toEncoded().constData(), qPrintable(reply->errorString())); } else { QString filename = reply->request().attribute(QNetworkRequest::User) - .toString(); - saveToDisk(filename, reply); + .toString(); + + if(reply->hasRawHeader(ct_key)){ + ct_val=reply->rawHeader(ct_key); + if(!strcmp(ct_val.data(),"image/png")){ + filename.append(".png"); + saveToDisk(filename, reply); + }else if(!strcmp(ct_val.data(),"image/jpeg")){ + filename.append(".jpg"); + saveToDisk(filename, reply); + }else{ + fprintf(stderr, "Error downloading map tile: %s: Unknown Content-Type: %s\n", + url.toEncoded().constData(),qPrintable(QString(ct_val))); + } + } } currentDownloads.removeAll(reply); diff --git a/src/map.cpp b/src/map.cpp index b443423b..d04512b0 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -28,14 +28,18 @@ void Map::loadTiles(QList &list) for (int i = 0; i < list.size(); ++i) { Tile &t = list[i]; - QString file = QString("%1/"TILES_DIR"/%2/%3-%4-%5.png") + + QString file_base = QString("%1/"TILES_DIR"/%2/%3-%4-%5") .arg(QDir::homePath()).arg(_name).arg(t.zoom()).arg(t.xy().rx()) .arg(t.xy().ry()); - QFileInfo fi(file); - if (fi.exists()) - t.pixmap().load(file); - else { + QFileInfo fi_jpg(file_base + ".jpg"); + QFileInfo fi_png(file_base + ".png"); + if (fi_jpg.exists()) { + t.pixmap().load(file_base + ".jpg"); + } else if (fi_png.exists()) { + t.pixmap().load(file_base + ".png"); + } else { t.pixmap() = QPixmap(TILE_SIZE, TILE_SIZE); t.pixmap().fill(); @@ -43,7 +47,7 @@ void Map::loadTiles(QList &list) url.replace("$z", QString::number(t.zoom())); url.replace("$x", QString::number(t.xy().x())); url.replace("$y", QString::number(t.xy().y())); - dl.append(Download(url, file)); + dl.append(Download(url, file_base)); } }