mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-02-17 16:20:48 +01:00
Image type of map tiles is recognized according to Content-Type.
- works for png and jpg only
This commit is contained in:
parent
db4dc37848
commit
f9ec908ea5
@ -51,6 +51,8 @@ bool Downloader::saveToDisk(const QString &filename, QIODevice *data)
|
|||||||
|
|
||||||
void Downloader::downloadFinished(QNetworkReply *reply)
|
void Downloader::downloadFinished(QNetworkReply *reply)
|
||||||
{
|
{
|
||||||
|
QByteArray ct_key("Content-Type");
|
||||||
|
QByteArray ct_val;
|
||||||
QUrl url = reply->url();
|
QUrl url = reply->url();
|
||||||
if (reply->error()) {
|
if (reply->error()) {
|
||||||
fprintf(stderr, "Error downloading map tile: %s: %s\n",
|
fprintf(stderr, "Error downloading map tile: %s: %s\n",
|
||||||
@ -58,7 +60,20 @@ void Downloader::downloadFinished(QNetworkReply *reply)
|
|||||||
} else {
|
} else {
|
||||||
QString filename = reply->request().attribute(QNetworkRequest::User)
|
QString filename = reply->request().attribute(QNetworkRequest::User)
|
||||||
.toString();
|
.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);
|
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);
|
currentDownloads.removeAll(reply);
|
||||||
|
16
src/map.cpp
16
src/map.cpp
@ -28,14 +28,18 @@ void Map::loadTiles(QList<Tile> &list)
|
|||||||
|
|
||||||
for (int i = 0; i < list.size(); ++i) {
|
for (int i = 0; i < list.size(); ++i) {
|
||||||
Tile &t = list[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(QDir::homePath()).arg(_name).arg(t.zoom()).arg(t.xy().rx())
|
||||||
.arg(t.xy().ry());
|
.arg(t.xy().ry());
|
||||||
QFileInfo fi(file);
|
|
||||||
|
|
||||||
if (fi.exists())
|
QFileInfo fi_jpg(file_base + ".jpg");
|
||||||
t.pixmap().load(file);
|
QFileInfo fi_png(file_base + ".png");
|
||||||
else {
|
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() = QPixmap(TILE_SIZE, TILE_SIZE);
|
||||||
t.pixmap().fill();
|
t.pixmap().fill();
|
||||||
|
|
||||||
@ -43,7 +47,7 @@ void Map::loadTiles(QList<Tile> &list)
|
|||||||
url.replace("$z", QString::number(t.zoom()));
|
url.replace("$z", QString::number(t.zoom()));
|
||||||
url.replace("$x", QString::number(t.xy().x()));
|
url.replace("$x", QString::number(t.xy().x()));
|
||||||
url.replace("$y", QString::number(t.xy().y()));
|
url.replace("$y", QString::number(t.xy().y()));
|
||||||
dl.append(Download(url, file));
|
dl.append(Download(url, file_base));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user