2015-11-26 19:13:59 +01:00
|
|
|
#include <QFileInfo>
|
2017-04-21 21:15:58 +02:00
|
|
|
#include <QDir>
|
2020-03-17 21:06:51 +01:00
|
|
|
#include <QApplication>
|
2017-04-21 21:15:58 +02:00
|
|
|
#include "atlas.h"
|
2018-08-21 20:01:47 +02:00
|
|
|
#include "ozimap.h"
|
2018-05-22 22:40:15 +02:00
|
|
|
#include "jnxmap.h"
|
2018-08-21 20:01:47 +02:00
|
|
|
#include "geotiffmap.h"
|
2018-01-29 00:19:57 +01:00
|
|
|
#include "mapsource.h"
|
2018-09-20 07:59:47 +02:00
|
|
|
#include "mbtilesmap.h"
|
2019-03-02 16:51:14 +01:00
|
|
|
#include "rmap.h"
|
2019-05-10 18:56:19 +02:00
|
|
|
#include "imgmap.h"
|
2020-02-09 23:24:48 +01:00
|
|
|
#include "IMG/gmap.h"
|
2020-11-27 01:11:50 +01:00
|
|
|
#include "bsbmap.h"
|
2015-11-23 23:19:57 +01:00
|
|
|
#include "maplist.h"
|
|
|
|
|
|
|
|
|
2020-03-17 21:06:51 +01:00
|
|
|
Map *MapList::loadFile(const QString &path, QString &errorString,
|
|
|
|
bool *terminate)
|
2017-07-27 19:47:46 +02:00
|
|
|
{
|
2018-01-14 23:46:39 +01:00
|
|
|
QFileInfo fi(path);
|
|
|
|
QString suffix = fi.suffix().toLower();
|
2020-02-09 23:24:48 +01:00
|
|
|
Map *map = 0;
|
2018-01-14 23:46:39 +01:00
|
|
|
|
2018-01-14 23:03:27 +01:00
|
|
|
if (Atlas::isAtlas(path)) {
|
2020-02-12 20:32:57 +01:00
|
|
|
if (terminate)
|
|
|
|
*terminate = true;
|
2020-03-17 21:06:51 +01:00
|
|
|
map = new Atlas(path);
|
2019-02-13 00:45:34 +01:00
|
|
|
} else if (suffix == "xml") {
|
2020-03-17 21:06:51 +01:00
|
|
|
if (MapSource::isMap(path)) {
|
|
|
|
if (!(map = MapSource::loadMap(path, errorString)))
|
|
|
|
return 0;
|
|
|
|
} else if (GMAP::isGMAP(path)) {
|
2020-02-12 20:32:57 +01:00
|
|
|
if (terminate)
|
|
|
|
*terminate = true;
|
2020-03-17 21:06:51 +01:00
|
|
|
map = new IMGMap(path);
|
2020-02-09 23:24:48 +01:00
|
|
|
}
|
2019-02-13 00:45:34 +01:00
|
|
|
} else if (suffix == "jnx")
|
2020-03-17 21:06:51 +01:00
|
|
|
map = new JNXMap(path);
|
2018-08-21 20:01:47 +02:00
|
|
|
else if (suffix == "tif" || suffix == "tiff")
|
2020-03-17 21:06:51 +01:00
|
|
|
map = new GeoTIFFMap(path);
|
2018-09-20 07:59:47 +02:00
|
|
|
else if (suffix == "mbtiles")
|
2020-03-17 21:06:51 +01:00
|
|
|
map = new MBTilesMap(path);
|
2019-03-07 22:58:43 +01:00
|
|
|
else if (suffix == "rmap" || suffix == "rtmap")
|
2020-03-17 21:06:51 +01:00
|
|
|
map = new RMap(path);
|
2019-05-10 18:56:19 +02:00
|
|
|
else if (suffix == "img")
|
2020-03-17 21:06:51 +01:00
|
|
|
map = new IMGMap(path);
|
2020-02-12 20:32:57 +01:00
|
|
|
else if (suffix == "map" || suffix == "tar")
|
2020-03-17 21:06:51 +01:00
|
|
|
map = new OziMap(path);
|
2020-11-28 20:34:25 +01:00
|
|
|
else if (suffix == "kap")
|
2020-11-27 01:11:50 +01:00
|
|
|
map = new BSBMap(path);
|
2019-02-13 00:45:34 +01:00
|
|
|
|
2020-03-17 21:06:51 +01:00
|
|
|
if (map && map->isValid())
|
|
|
|
return map;
|
|
|
|
else {
|
|
|
|
errorString = (map) ? map->errorString() : "Unknown file format";
|
2019-02-13 00:45:34 +01:00
|
|
|
delete map;
|
2020-03-17 21:06:51 +01:00
|
|
|
return 0;
|
2019-02-13 00:45:34 +01:00
|
|
|
}
|
2017-07-27 19:47:46 +02:00
|
|
|
}
|
|
|
|
|
2020-03-17 21:06:51 +01:00
|
|
|
QList<Map*> MapList::loadDir(const QString &path, QString &errorString)
|
2017-07-27 19:47:46 +02:00
|
|
|
{
|
2018-01-14 23:03:27 +01:00
|
|
|
QDir md(path);
|
|
|
|
md.setFilter(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
|
|
|
|
md.setSorting(QDir::DirsLast);
|
|
|
|
QFileInfoList ml = md.entryInfoList();
|
2020-03-17 21:06:51 +01:00
|
|
|
QList<Map*> list;
|
2018-01-14 23:03:27 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < ml.size(); i++) {
|
|
|
|
const QFileInfo &fi = ml.at(i);
|
|
|
|
QString suffix = fi.suffix().toLower();
|
2020-02-09 23:24:48 +01:00
|
|
|
bool terminate = false;
|
2018-01-14 23:03:27 +01:00
|
|
|
|
2020-03-17 21:06:51 +01:00
|
|
|
if (fi.isDir() && fi.fileName() != "set")
|
|
|
|
list.append(loadDir(fi.absoluteFilePath(), errorString));
|
|
|
|
else if (filter().contains("*." + suffix)) {
|
|
|
|
Map *map = loadFile(fi.absoluteFilePath(), errorString, &terminate);
|
|
|
|
if (map)
|
|
|
|
list.append(map);
|
|
|
|
else
|
2020-03-27 23:09:13 +01:00
|
|
|
qWarning("%s: %s", qPrintable(fi.absoluteFilePath()),
|
|
|
|
qPrintable(errorString));
|
2020-02-09 23:24:48 +01:00
|
|
|
if (terminate)
|
2018-01-14 23:03:27 +01:00
|
|
|
break;
|
|
|
|
}
|
2017-04-21 21:15:58 +02:00
|
|
|
}
|
2018-01-14 23:03:27 +01:00
|
|
|
|
2020-03-17 21:06:51 +01:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<Map*> MapList::loadMaps(const QString &path, QString &errorString)
|
|
|
|
{
|
|
|
|
if (QFileInfo(path).isDir())
|
|
|
|
return loadDir(path, errorString);
|
|
|
|
else {
|
|
|
|
QList<Map*> list;
|
|
|
|
Map *map = loadFile(path, errorString, 0);
|
|
|
|
if (map)
|
|
|
|
list.append(map);
|
|
|
|
return list;
|
|
|
|
}
|
2018-01-14 23:03:27 +01:00
|
|
|
}
|
|
|
|
|
2017-07-27 19:47:46 +02:00
|
|
|
QString MapList::formats()
|
|
|
|
{
|
2018-02-04 15:30:54 +01:00
|
|
|
return
|
2020-03-17 21:06:51 +01:00
|
|
|
qApp->translate("MapList", "Supported files")
|
|
|
|
+ " (" + filter().join(" ") + ");;"
|
|
|
|
+ qApp->translate("MapList", "Garmin IMG maps")
|
|
|
|
+ " (*.gmap *.gmapi *.img *.xml);;"
|
|
|
|
+ qApp->translate("MapList", "Garmin JNX maps") + " (*.jnx);;"
|
2020-11-28 20:34:25 +01:00
|
|
|
+ qApp->translate("MapList", "BSB nautical charts") + " (*.kap);;"
|
2020-03-17 21:06:51 +01:00
|
|
|
+ qApp->translate("MapList", "OziExplorer maps") + " (*.map);;"
|
|
|
|
+ qApp->translate("MapList", "MBTiles maps") + " (*.mbtiles);;"
|
|
|
|
+ qApp->translate("MapList", "TrekBuddy maps/atlases") + " (*.tar *.tba);;"
|
|
|
|
+ qApp->translate("MapList", "GeoTIFF images") + " (*.tif *.tiff);;"
|
|
|
|
+ qApp->translate("MapList", "TwoNav maps") + " (*.rmap *.rtmap);;"
|
|
|
|
+ qApp->translate("MapList", "Online map sources") + " (*.xml)";
|
2017-07-27 19:47:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QStringList MapList::filter()
|
|
|
|
{
|
|
|
|
QStringList filter;
|
2020-11-27 01:11:50 +01:00
|
|
|
filter << "*.gmap" << "*.gmapi" << "*.img" << "*.jnx" << "*.kap" << "*.map"
|
2020-11-28 20:34:25 +01:00
|
|
|
<< "*.mbtiles" << "*.rmap" << "*.rtmap" << "*.tar" << "*.tba" << "*.tif"
|
|
|
|
<< "*.tiff" << "*.xml";
|
2017-07-27 19:47:46 +02:00
|
|
|
return filter;
|
|
|
|
}
|