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

Added recursive POI dir searching to be consistent with map dir searching

This commit is contained in:
Martin Tůma 2018-01-30 00:30:26 +01:00
parent e10f8e9c1b
commit 84d860e2a2
5 changed files with 68 additions and 31 deletions

View File

@ -101,14 +101,14 @@ GUI::~GUI()
void GUI::loadMaps() void GUI::loadMaps()
{ {
_ml = new MapList(this); _ml = new MapList(this);
QString offline; QString dir;
if (QFile::exists(USER_MAP_DIR)) if (QFile::exists(USER_MAP_DIR))
offline = USER_MAP_DIR; dir = USER_MAP_DIR;
else if (QFile::exists(GLOBAL_MAP_DIR)) else if (QFile::exists(GLOBAL_MAP_DIR))
offline = GLOBAL_MAP_DIR; dir = GLOBAL_MAP_DIR;
if (!offline.isNull() && !_ml->loadDir(offline)) if (!dir.isNull() && !_ml->loadDir(dir))
qWarning(qPrintable(_ml->errorString())); qWarning(qPrintable(_ml->errorString()));
_map = new EmptyMap(this); _map = new EmptyMap(this);
@ -116,26 +116,16 @@ void GUI::loadMaps()
void GUI::loadPOIs() void GUI::loadPOIs()
{ {
QFileInfoList list;
QDir userDir(USER_POI_DIR);
QDir globalDir(GLOBAL_POI_DIR);
_poi = new POI(this); _poi = new POI(this);
QString dir;
if (userDir.exists()) if (QFile::exists(USER_POI_DIR))
list = userDir.entryInfoList(QStringList(), QDir::Files); dir = USER_POI_DIR;
else else if (QFile::exists(GLOBAL_POI_DIR))
list = globalDir.entryInfoList(QStringList(), QDir::Files); dir = GLOBAL_POI_DIR;
for (int i = 0; i < list.size(); ++i) { if (!dir.isNull() && !_poi->loadDir(dir))
if (!_poi->loadFile(list.at(i).absoluteFilePath())) { qWarning(qPrintable(_poi->errorString()));
qWarning("Error loading POI file: %s: %s\n",
qPrintable(list.at(i).fileName()),
qPrintable(_poi->errorString()));
if (_poi->errorLine())
qWarning("Line: %d\n", _poi->errorLine());
}
}
} }
void GUI::createBrowser() void GUI::createBrowser()

View File

@ -1,4 +1,5 @@
#include <QFile> #include <QFile>
#include <QDir>
#include "data.h" #include "data.h"
#include "poi.h" #include "poi.h"
@ -9,20 +10,25 @@ POI::POI(QObject *parent) : QObject(parent)
_radius = 1000; _radius = 1000;
} }
bool POI::loadFile(const QString &fileName) bool POI::loadFile(const QString &path, bool dir)
{ {
Data data; Data data;
FileIndex index; FileIndex index;
_errorString.clear();
_errorLine = 0;
index.enabled = true; index.enabled = true;
index.start = _data.size(); index.start = _data.size();
if (!data.loadFile(fileName)) { if (!data.loadFile(path)) {
if (dir) {
if (data.errorLine())
_errorString += QString("%1:%2: %3\n").arg(path)
.arg(data.errorLine()).arg(data.errorString());
else
_errorString += path + ": " + data.errorString() + "\n";
} else {
_errorString = data.errorString(); _errorString = data.errorString();
_errorLine = data.errorLine(); _errorLine = data.errorLine();
}
return false; return false;
} }
@ -38,7 +44,7 @@ bool POI::loadFile(const QString &fileName)
_tree.Insert(c, c, i); _tree.Insert(c, c, i);
} }
_files.append(fileName); _files.append(path);
_indexes.append(index); _indexes.append(index);
emit pointsChanged(); emit pointsChanged();
@ -46,6 +52,39 @@ bool POI::loadFile(const QString &fileName)
return true; return true;
} }
bool POI::loadFile(const QString &path)
{
_errorString.clear();
_errorLine = 0;
return loadFile(path, false);
}
bool POI::loadDir(const QString &path)
{
QDir md(path);
md.setFilter(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
QFileInfoList fl = md.entryInfoList();
bool ret = true;
_errorString.clear();
_errorLine = 0;
for (int i = 0; i < fl.size(); i++) {
const QFileInfo &fi = fl.at(i);
if (fi.isDir()) {
if (!loadDir(fi.absoluteFilePath()))
ret = false;
} else {
if (!loadFile(fi.absoluteFilePath(), true))
ret = false;
}
}
return ret;
}
static bool cb(size_t data, void* context) static bool cb(size_t data, void* context)
{ {
QSet<int> *set = (QSet<int>*) context; QSet<int> *set = (QSet<int>*) context;

View File

@ -18,7 +18,8 @@ class POI : public QObject
public: public:
POI(QObject *parent = 0); POI(QObject *parent = 0);
bool loadFile(const QString &fileName); bool loadFile(const QString &path);
bool loadDir(const QString &path);
const QString &errorString() const {return _errorString;} const QString &errorString() const {return _errorString;}
int errorLine() const {return _errorLine;} int errorLine() const {return _errorLine;}
@ -43,6 +44,8 @@ private:
bool enabled; bool enabled;
}; };
bool loadFile(const QString &path, bool dir);
POITree _tree; POITree _tree;
QVector<Waypoint> _data; QVector<Waypoint> _data;
QStringList _files; QStringList _files;

View File

@ -82,6 +82,9 @@ bool MapList::loadFile(const QString &path, bool *atlas, bool dir)
bool MapList::loadFile(const QString &path) bool MapList::loadFile(const QString &path)
{ {
bool atlas; bool atlas;
_errorString.clear();
return loadFile(path, &atlas, false); return loadFile(path, &atlas, false);
} }
@ -93,6 +96,8 @@ bool MapList::loadDir(const QString &path)
QFileInfoList ml = md.entryInfoList(); QFileInfoList ml = md.entryInfoList();
bool atlas, ret = true; bool atlas, ret = true;
_errorString.clear();
for (int i = 0; i < ml.size(); i++) { for (int i = 0; i < ml.size(); i++) {
const QFileInfo &fi = ml.at(i); const QFileInfo &fi = ml.at(i);
QString suffix = fi.suffix().toLower(); QString suffix = fi.suffix().toLower();

View File

@ -25,7 +25,7 @@ private:
void map(QXmlStreamReader &reader); void map(QXmlStreamReader &reader);
QString _errorString; QString _errorString;
Map* _map; Map *_map;
}; };
#endif // MAPSOURCE_H #endif // MAPSOURCE_H