mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-30 22:51:16 +01:00
Compare commits
3 Commits
589c602d21
...
b156e25023
Author | SHA1 | Date | |
---|---|---|---|
b156e25023 | |||
e15deccfca | |||
9b24bccfed |
2523
lang/gpxsee_ca.ts
Normal file
2523
lang/gpxsee_ca.ts
Normal file
File diff suppressed because it is too large
Load Diff
@ -12,16 +12,26 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QDir>
|
|
||||||
#include <QTemporaryDir>
|
#include <QTemporaryDir>
|
||||||
|
#include <QCryptographicHash>
|
||||||
|
#include <QtEndian>
|
||||||
|
#include <QUrl>
|
||||||
|
#include <QRegularExpression>
|
||||||
#include <private/qzipreader_p.h>
|
#include <private/qzipreader_p.h>
|
||||||
#include "kmlparser.h"
|
#include "kmlparser.h"
|
||||||
|
|
||||||
#define ZIP_MAGIC 0x04034b50
|
static const QTemporaryDir &tempDir()
|
||||||
|
|
||||||
static inline uint readUInt(const uchar *data)
|
|
||||||
{
|
{
|
||||||
return (data[0]) + (data[1]<<8) + (data[2]<<16) + (data[3]<<24);
|
static QTemporaryDir dir;
|
||||||
|
return dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool isZIP(QFile *file)
|
||||||
|
{
|
||||||
|
quint32 magic;
|
||||||
|
|
||||||
|
return (file->read((char *)&magic, sizeof(magic)) == (qint64)sizeof(magic)
|
||||||
|
&& qFromLittleEndian(magic) == 0x04034b50);
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal KMLParser::number()
|
qreal KMLParser::number()
|
||||||
@ -512,8 +522,73 @@ void KMLParser::multiGeometry(QList<TrackData> &tracks, QList<Area> &areas,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KMLParser::placemark(QList<TrackData> &tracks, QList<Area> &areas,
|
void KMLParser::photoOverlay(const Ctx &ctx, QVector<Waypoint> &waypoints,
|
||||||
QVector<Waypoint> &waypoints, const QMap<QString, QPixmap> &icons)
|
QMap<QString, QPixmap> &icons)
|
||||||
|
{
|
||||||
|
QString name, desc, phone, address, path, link, id;
|
||||||
|
QDateTime timestamp;
|
||||||
|
|
||||||
|
while (_reader.readNextStartElement()) {
|
||||||
|
if (_reader.name() == QLatin1String("name"))
|
||||||
|
name = _reader.readElementText();
|
||||||
|
else if (_reader.name() == QLatin1String("description"))
|
||||||
|
desc = _reader.readElementText();
|
||||||
|
else if (_reader.name() == QLatin1String("phoneNumber"))
|
||||||
|
phone = _reader.readElementText();
|
||||||
|
else if (_reader.name() == QLatin1String("address"))
|
||||||
|
address = _reader.readElementText();
|
||||||
|
else if (_reader.name() == QLatin1String("TimeStamp"))
|
||||||
|
timestamp = timeStamp();
|
||||||
|
else if (_reader.name() == QLatin1String("Style"))
|
||||||
|
style(ctx.dir, icons);
|
||||||
|
else if (_reader.name() == QLatin1String("Icon")) {
|
||||||
|
QString image(icon());
|
||||||
|
|
||||||
|
QRegularExpression re("\\$\\[[^\\]]+\\]");
|
||||||
|
image.replace(re, "0");
|
||||||
|
QUrl url(image);
|
||||||
|
|
||||||
|
if (url.scheme() == "http" || url.scheme() == "https")
|
||||||
|
link = image;
|
||||||
|
else {
|
||||||
|
if (ctx.zip) {
|
||||||
|
if (tempDir().isValid()) {
|
||||||
|
QFileInfo fi(image);
|
||||||
|
QByteArray id(ctx.path.toUtf8() + image.toUtf8());
|
||||||
|
path = tempDir().path() + "/" + QString("%0.%1").arg(
|
||||||
|
QCryptographicHash::hash(id, QCryptographicHash::Sha1)
|
||||||
|
.toHex(), QString(fi.suffix()));
|
||||||
|
|
||||||
|
QFile::rename(ctx.dir.absoluteFilePath(image), path);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
path = ctx.dir.absoluteFilePath(image);
|
||||||
|
}
|
||||||
|
} else if (_reader.name() == QLatin1String("Point")) {
|
||||||
|
waypoints.append(Waypoint());
|
||||||
|
Waypoint &w = waypoints.last();
|
||||||
|
w.setName(name);
|
||||||
|
w.setDescription(desc);
|
||||||
|
w.setTimestamp(timestamp);
|
||||||
|
w.setAddress(address);
|
||||||
|
w.setPhone(phone);
|
||||||
|
w.setIcon(icons.value(id));
|
||||||
|
if (!path.isNull())
|
||||||
|
w.addImage(path);
|
||||||
|
if (!link.isNull())
|
||||||
|
w.addLink(Link(link, "Photo Overlay"));
|
||||||
|
point(w);
|
||||||
|
} else if (_reader.name() == QLatin1String("styleUrl")) {
|
||||||
|
id = _reader.readElementText();
|
||||||
|
id = (id.at(0) == '#') ? id.right(id.size() - 1) : QString();
|
||||||
|
} else
|
||||||
|
_reader.skipCurrentElement();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void KMLParser::placemark(const Ctx &ctx, QList<TrackData> &tracks,
|
||||||
|
QList<Area> &areas, QVector<Waypoint> &waypoints,
|
||||||
|
QMap<QString, QPixmap> &icons)
|
||||||
{
|
{
|
||||||
QString name, desc, phone, address, id;
|
QString name, desc, phone, address, id;
|
||||||
QDateTime timestamp;
|
QDateTime timestamp;
|
||||||
@ -529,6 +604,8 @@ void KMLParser::placemark(QList<TrackData> &tracks, QList<Area> &areas,
|
|||||||
address = _reader.readElementText();
|
address = _reader.readElementText();
|
||||||
else if (_reader.name() == QLatin1String("TimeStamp"))
|
else if (_reader.name() == QLatin1String("TimeStamp"))
|
||||||
timestamp = timeStamp();
|
timestamp = timeStamp();
|
||||||
|
else if (_reader.name() == QLatin1String("Style"))
|
||||||
|
style(ctx.dir, icons);
|
||||||
else if (_reader.name() == QLatin1String("MultiGeometry"))
|
else if (_reader.name() == QLatin1String("MultiGeometry"))
|
||||||
multiGeometry(tracks, areas, waypoints, name, desc, timestamp);
|
multiGeometry(tracks, areas, waypoints, name, desc, timestamp);
|
||||||
else if (_reader.name() == QLatin1String("Point")) {
|
else if (_reader.name() == QLatin1String("Point")) {
|
||||||
@ -539,7 +616,6 @@ void KMLParser::placemark(QList<TrackData> &tracks, QList<Area> &areas,
|
|||||||
w.setTimestamp(timestamp);
|
w.setTimestamp(timestamp);
|
||||||
w.setAddress(address);
|
w.setAddress(address);
|
||||||
w.setPhone(phone);
|
w.setPhone(phone);
|
||||||
if (!id.isNull())
|
|
||||||
w.setIcon(icons.value(id));
|
w.setIcon(icons.value(id));
|
||||||
point(w);
|
point(w);
|
||||||
} else if (_reader.name() == QLatin1String("LineString")
|
} else if (_reader.name() == QLatin1String("LineString")
|
||||||
@ -577,8 +653,7 @@ void KMLParser::placemark(QList<TrackData> &tracks, QList<Area> &areas,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KMLParser::icon(const QDir &dir, const QString &id,
|
QString KMLParser::icon()
|
||||||
QMap<QString, QPixmap> &icons)
|
|
||||||
{
|
{
|
||||||
QString path;
|
QString path;
|
||||||
|
|
||||||
@ -589,8 +664,7 @@ void KMLParser::icon(const QDir &dir, const QString &id,
|
|||||||
_reader.skipCurrentElement();
|
_reader.skipCurrentElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!path.isNull())
|
return path;
|
||||||
icons.insert(id, QPixmap(dir.absoluteFilePath(path)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void KMLParser::iconStyle(const QDir &dir, const QString &id,
|
void KMLParser::iconStyle(const QDir &dir, const QString &id,
|
||||||
@ -598,7 +672,7 @@ void KMLParser::iconStyle(const QDir &dir, const QString &id,
|
|||||||
{
|
{
|
||||||
while (_reader.readNextStartElement()) {
|
while (_reader.readNextStartElement()) {
|
||||||
if (_reader.name() == QLatin1String("Icon"))
|
if (_reader.name() == QLatin1String("Icon"))
|
||||||
icon(dir, id, icons);
|
icons.insert(id, QPixmap(dir.absoluteFilePath(icon())));
|
||||||
else
|
else
|
||||||
_reader.skipCurrentElement();
|
_reader.skipCurrentElement();
|
||||||
}
|
}
|
||||||
@ -616,51 +690,59 @@ void KMLParser::style(const QDir &dir, QMap<QString, QPixmap> &icons)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KMLParser::folder(const QDir &dir, QList<TrackData> &tracks,
|
void KMLParser::folder(const Ctx &ctx, QList<TrackData> &tracks,
|
||||||
QList<Area> &areas, QVector<Waypoint> &waypoints,
|
QList<Area> &areas, QVector<Waypoint> &waypoints,
|
||||||
const QMap<QString, QPixmap> &icons)
|
QMap<QString, QPixmap> &icons)
|
||||||
{
|
{
|
||||||
while (_reader.readNextStartElement()) {
|
while (_reader.readNextStartElement()) {
|
||||||
if (_reader.name() == QLatin1String("Document"))
|
if (_reader.name() == QLatin1String("Document"))
|
||||||
document(dir, tracks, areas, waypoints);
|
document(ctx, tracks, areas, waypoints);
|
||||||
else if (_reader.name() == QLatin1String("Placemark"))
|
|
||||||
placemark(tracks, areas, waypoints, icons);
|
|
||||||
else if (_reader.name() == QLatin1String("Folder"))
|
else if (_reader.name() == QLatin1String("Folder"))
|
||||||
folder(dir, tracks, areas, waypoints, icons);
|
folder(ctx, tracks, areas, waypoints, icons);
|
||||||
|
else if (_reader.name() == QLatin1String("Placemark"))
|
||||||
|
placemark(ctx, tracks, areas, waypoints, icons);
|
||||||
|
else if (_reader.name() == QLatin1String("PhotoOverlay"))
|
||||||
|
photoOverlay(ctx, waypoints, icons);
|
||||||
else
|
else
|
||||||
_reader.skipCurrentElement();
|
_reader.skipCurrentElement();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KMLParser::document(const QDir &dir, QList<TrackData> &tracks,
|
void KMLParser::document(const Ctx &ctx, QList<TrackData> &tracks,
|
||||||
QList<Area> &areas, QVector<Waypoint> &waypoints)
|
QList<Area> &areas, QVector<Waypoint> &waypoints)
|
||||||
{
|
{
|
||||||
QMap<QString, QPixmap> icons;
|
QMap<QString, QPixmap> icons;
|
||||||
|
|
||||||
while (_reader.readNextStartElement()) {
|
while (_reader.readNextStartElement()) {
|
||||||
if (_reader.name() == QLatin1String("Document"))
|
if (_reader.name() == QLatin1String("Document"))
|
||||||
document(dir, tracks, areas, waypoints);
|
document(ctx, tracks, areas, waypoints);
|
||||||
else if (_reader.name() == QLatin1String("Placemark"))
|
|
||||||
placemark(tracks, areas, waypoints, icons);
|
|
||||||
else if (_reader.name() == QLatin1String("Folder"))
|
else if (_reader.name() == QLatin1String("Folder"))
|
||||||
folder(dir, tracks, areas, waypoints, icons);
|
folder(ctx, tracks, areas, waypoints, icons);
|
||||||
|
else if (_reader.name() == QLatin1String("Placemark"))
|
||||||
|
placemark(ctx, tracks, areas, waypoints, icons);
|
||||||
|
else if (_reader.name() == QLatin1String("PhotoOverlay"))
|
||||||
|
photoOverlay(ctx, waypoints, icons);
|
||||||
else if (_reader.name() == QLatin1String("Style"))
|
else if (_reader.name() == QLatin1String("Style"))
|
||||||
style(dir, icons);
|
style(ctx.dir, icons);
|
||||||
else
|
else
|
||||||
_reader.skipCurrentElement();
|
_reader.skipCurrentElement();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KMLParser::kml(const QDir &dir, QList<TrackData> &tracks,
|
void KMLParser::kml(const Ctx &ctx, QList<TrackData> &tracks,
|
||||||
QList<Area> &areas, QVector<Waypoint> &waypoints)
|
QList<Area> &areas, QVector<Waypoint> &waypoints)
|
||||||
{
|
{
|
||||||
|
QMap<QString, QPixmap> icons;
|
||||||
|
|
||||||
while (_reader.readNextStartElement()) {
|
while (_reader.readNextStartElement()) {
|
||||||
if (_reader.name() == QLatin1String("Document"))
|
if (_reader.name() == QLatin1String("Document"))
|
||||||
document(dir, tracks, areas, waypoints);
|
document(ctx, tracks, areas, waypoints);
|
||||||
else if (_reader.name() == QLatin1String("Placemark"))
|
|
||||||
placemark(tracks, areas, waypoints, QMap<QString, QPixmap>());
|
|
||||||
else if (_reader.name() == QLatin1String("Folder"))
|
else if (_reader.name() == QLatin1String("Folder"))
|
||||||
folder(dir, tracks, areas, waypoints, QMap<QString, QPixmap>());
|
folder(ctx, tracks, areas, waypoints, icons);
|
||||||
|
else if (_reader.name() == QLatin1String("Placemark"))
|
||||||
|
placemark(ctx, tracks, areas, waypoints, icons);
|
||||||
|
else if (_reader.name() == QLatin1String("PhotoOverlay"))
|
||||||
|
photoOverlay(ctx, waypoints, icons);
|
||||||
else
|
else
|
||||||
_reader.skipCurrentElement();
|
_reader.skipCurrentElement();
|
||||||
}
|
}
|
||||||
@ -670,15 +752,14 @@ bool KMLParser::parse(QFile *file, QList<TrackData> &tracks,
|
|||||||
QList<RouteData> &routes, QList<Area> &areas, QVector<Waypoint> &waypoints)
|
QList<RouteData> &routes, QList<Area> &areas, QVector<Waypoint> &waypoints)
|
||||||
{
|
{
|
||||||
Q_UNUSED(routes);
|
Q_UNUSED(routes);
|
||||||
uchar magic[4];
|
|
||||||
QFileInfo fi(*file);
|
QFileInfo fi(*file);
|
||||||
|
|
||||||
_reader.clear();
|
_reader.clear();
|
||||||
|
|
||||||
if (file->read((char *)magic, 4) == 4 && readUInt(magic) == ZIP_MAGIC) {
|
if (isZIP(file)) {
|
||||||
QZipReader zip(fi.absoluteFilePath(), QIODevice::ReadOnly);
|
QZipReader zip(fi.absoluteFilePath(), QIODevice::ReadOnly);
|
||||||
QTemporaryDir tempDir;
|
QTemporaryDir tempDir;
|
||||||
if (!zip.extractAll(tempDir.path()))
|
if (!tempDir.isValid() || !zip.extractAll(tempDir.path()))
|
||||||
_reader.raiseError("Error extracting ZIP file");
|
_reader.raiseError("Error extracting ZIP file");
|
||||||
else {
|
else {
|
||||||
QDir zipDir(tempDir.path());
|
QDir zipDir(tempDir.path());
|
||||||
@ -696,7 +777,8 @@ bool KMLParser::parse(QFile *file, QList<TrackData> &tracks,
|
|||||||
|
|
||||||
if (_reader.readNextStartElement()) {
|
if (_reader.readNextStartElement()) {
|
||||||
if (_reader.name() == QLatin1String("kml"))
|
if (_reader.name() == QLatin1String("kml"))
|
||||||
kml(zipDir, tracks, areas, waypoints);
|
kml(Ctx(fi.absoluteFilePath(), zipDir, true),
|
||||||
|
tracks, areas, waypoints);
|
||||||
else
|
else
|
||||||
_reader.raiseError("Not a KML file");
|
_reader.raiseError("Not a KML file");
|
||||||
}
|
}
|
||||||
@ -709,7 +791,8 @@ bool KMLParser::parse(QFile *file, QList<TrackData> &tracks,
|
|||||||
|
|
||||||
if (_reader.readNextStartElement()) {
|
if (_reader.readNextStartElement()) {
|
||||||
if (_reader.name() == QLatin1String("kml"))
|
if (_reader.name() == QLatin1String("kml"))
|
||||||
kml(fi.absoluteDir(), tracks, areas, waypoints);
|
kml(Ctx(fi.absoluteFilePath(), fi.absoluteDir(), false), tracks,
|
||||||
|
areas, waypoints);
|
||||||
else
|
else
|
||||||
_reader.raiseError("Not a KML file");
|
_reader.raiseError("Not a KML file");
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,9 @@
|
|||||||
|
|
||||||
#include <QXmlStreamReader>
|
#include <QXmlStreamReader>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QDir>
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
|
|
||||||
class QDir;
|
|
||||||
|
|
||||||
class KMLParser : public Parser
|
class KMLParser : public Parser
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -16,17 +15,28 @@ public:
|
|||||||
int errorLine() const {return _reader.lineNumber();}
|
int errorLine() const {return _reader.lineNumber();}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void kml(const QDir &dir, QList<TrackData> &tracks, QList<Area> &areas,
|
struct Ctx {
|
||||||
|
Ctx(const QString &path, const QDir &dir, bool zip)
|
||||||
|
: path(path), dir(dir), zip(zip) {}
|
||||||
|
|
||||||
|
QString path;
|
||||||
|
QDir dir;
|
||||||
|
bool zip;
|
||||||
|
};
|
||||||
|
|
||||||
|
void kml(const Ctx &ctx, QList<TrackData> &tracks, QList<Area> &areas,
|
||||||
QVector<Waypoint> &waypoints);
|
QVector<Waypoint> &waypoints);
|
||||||
void document(const QDir &dir, QList<TrackData> &tracks, QList<Area> &areas,
|
void document(const Ctx &ctx, QList<TrackData> &tracks, QList<Area> &areas,
|
||||||
QVector<Waypoint> &waypoints);
|
QVector<Waypoint> &waypoints);
|
||||||
void folder(const QDir &dir, QList<TrackData> &tracks, QList<Area> &areas,
|
void folder(const Ctx &ctx, QList<TrackData> &tracks, QList<Area> &areas,
|
||||||
QVector<Waypoint> &waypoints, const QMap<QString, QPixmap> &icons);
|
QVector<Waypoint> &waypoints, QMap<QString, QPixmap> &icons);
|
||||||
void placemark(QList<TrackData> &tracks, QList<Area> &areas,
|
void placemark(const Ctx &ctx, QList<TrackData> &tracks, QList<Area> &areas,
|
||||||
QVector<Waypoint> &waypoints, const QMap<QString, QPixmap> &icons);
|
QVector<Waypoint> &waypoints, QMap<QString, QPixmap> &icons);
|
||||||
void multiGeometry(QList<TrackData> &tracks, QList<Area> &areas,
|
void multiGeometry(QList<TrackData> &tracks, QList<Area> &areas,
|
||||||
QVector<Waypoint> &waypoints, const QString &name, const QString &desc,
|
QVector<Waypoint> &waypoints, const QString &name, const QString &desc,
|
||||||
const QDateTime ×tamp);
|
const QDateTime ×tamp);
|
||||||
|
void photoOverlay(const Ctx &ctx, QVector<Waypoint> &waypoints,
|
||||||
|
QMap<QString, QPixmap> &icons);
|
||||||
void track(SegmentData &segment);
|
void track(SegmentData &segment);
|
||||||
void multiTrack(TrackData &t);
|
void multiTrack(TrackData &t);
|
||||||
void lineString(SegmentData &segment);
|
void lineString(SegmentData &segment);
|
||||||
@ -47,10 +57,10 @@ private:
|
|||||||
QDateTime timeStamp();
|
QDateTime timeStamp();
|
||||||
qreal number();
|
qreal number();
|
||||||
QDateTime time();
|
QDateTime time();
|
||||||
|
QString icon();
|
||||||
void style(const QDir &dir, QMap<QString, QPixmap> &icons);
|
void style(const QDir &dir, QMap<QString, QPixmap> &icons);
|
||||||
void iconStyle(const QDir &dir, const QString &id,
|
void iconStyle(const QDir &dir, const QString &id,
|
||||||
QMap<QString, QPixmap> &icons);
|
QMap<QString, QPixmap> &icons);
|
||||||
void icon(const QDir &dir, const QString &id, QMap<QString, QPixmap> &icons);
|
|
||||||
|
|
||||||
QXmlStreamReader _reader;
|
QXmlStreamReader _reader;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user