1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-10-06 14:53:21 +02: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()
{
_ml = new MapList(this);
QString offline;
QString dir;
if (QFile::exists(USER_MAP_DIR))
offline = USER_MAP_DIR;
dir = USER_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()));
_map = new EmptyMap(this);
@ -116,26 +116,16 @@ void GUI::loadMaps()
void GUI::loadPOIs()
{
QFileInfoList list;
QDir userDir(USER_POI_DIR);
QDir globalDir(GLOBAL_POI_DIR);
_poi = new POI(this);
QString dir;
if (userDir.exists())
list = userDir.entryInfoList(QStringList(), QDir::Files);
else
list = globalDir.entryInfoList(QStringList(), QDir::Files);
if (QFile::exists(USER_POI_DIR))
dir = USER_POI_DIR;
else if (QFile::exists(GLOBAL_POI_DIR))
dir = GLOBAL_POI_DIR;
for (int i = 0; i < list.size(); ++i) {
if (!_poi->loadFile(list.at(i).absoluteFilePath())) {
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());
}
}
if (!dir.isNull() && !_poi->loadDir(dir))
qWarning(qPrintable(_poi->errorString()));
}
void GUI::createBrowser()

View File

@ -1,4 +1,5 @@
#include <QFile>
#include <QDir>
#include "data.h"
#include "poi.h"
@ -9,20 +10,25 @@ POI::POI(QObject *parent) : QObject(parent)
_radius = 1000;
}
bool POI::loadFile(const QString &fileName)
bool POI::loadFile(const QString &path, bool dir)
{
Data data;
FileIndex index;
_errorString.clear();
_errorLine = 0;
index.enabled = true;
index.start = _data.size();
if (!data.loadFile(fileName)) {
_errorString = data.errorString();
_errorLine = data.errorLine();
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();
_errorLine = data.errorLine();
}
return false;
}
@ -38,7 +44,7 @@ bool POI::loadFile(const QString &fileName)
_tree.Insert(c, c, i);
}
_files.append(fileName);
_files.append(path);
_indexes.append(index);
emit pointsChanged();
@ -46,6 +52,39 @@ bool POI::loadFile(const QString &fileName)
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)
{
QSet<int> *set = (QSet<int>*) context;

View File

@ -18,7 +18,8 @@ class POI : public QObject
public:
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;}
int errorLine() const {return _errorLine;}
@ -43,6 +44,8 @@ private:
bool enabled;
};
bool loadFile(const QString &path, bool dir);
POITree _tree;
QVector<Waypoint> _data;
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 atlas;
_errorString.clear();
return loadFile(path, &atlas, false);
}
@ -93,6 +96,8 @@ bool MapList::loadDir(const QString &path)
QFileInfoList ml = md.entryInfoList();
bool atlas, ret = true;
_errorString.clear();
for (int i = 0; i < ml.size(); i++) {
const QFileInfo &fi = ml.at(i);
QString suffix = fi.suffix().toLower();

View File

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