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

Image type of map tiles is recognized according to Content-Type.

- works for png and jpg only
This commit is contained in:
Jiri Luznicky 2015-12-02 23:41:58 +01:00
parent db4dc37848
commit f9ec908ea5
2 changed files with 27 additions and 8 deletions

View File

@ -51,6 +51,8 @@ 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",
@ -58,7 +60,20 @@ void Downloader::downloadFinished(QNetworkReply *reply)
} else {
QString filename = reply->request().attribute(QNetworkRequest::User)
.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);

View File

@ -28,14 +28,18 @@ void Map::loadTiles(QList<Tile> &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<Tile> &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));
}
}