Commit 16b16599 authored by Nicolas Fella's avatar Nicolas Fella
Browse files

Use KFileUtils to list maps

Simplifies the code
parent a518151a
Pipeline #167816 passed with stage
in 2 minutes and 50 seconds
......@@ -13,6 +13,7 @@
#include <KLocalizedString>
#include <KMessageBox>
#include <KListWidgetSearchLine>
#include <KFileUtils>
#include <QDir>
#include <QImage>
......@@ -66,39 +67,28 @@ mapChooser::mapChooser(QWidget *parent) : QDialog(parent)
QString lastMapFile = kgeographySettings::self() -> lastMap();
QString stringToSelect;
QStringList texts;
QSet<QString> loadedMaps;
const QStringList dirs = QStandardPaths::locateAll(QStandardPaths::DataLocation, QLatin1String(""), QStandardPaths::LocateDirectory);
foreach (const QString &dir, dirs)
{
const QStringList fileNames = QDir(dir).entryList(QStringList() << QStringLiteral("*.kgm"));
foreach (const QString &file, fileNames)
{
// avoid multiple and should guarantee that first in XDG_DATA_DIRS is chosen)
if (loadedMaps.contains(file))
continue;
QString mapFilename = dir + '/' + file;
const QStringList mapFiles = KFileUtils::findAllUniqueFiles(QStandardPaths::standardLocations(QStandardPaths::AppDataLocation), {QStringLiteral("*.kgm")});
KGmap *m = p_reader.parseMap(mapFilename);
if (!m)
errorTexts << i18n("Error parsing %1: %2", mapFilename, p_reader.getError());
for (const QString &mapFilename : mapFiles) {
KGmap *m = p_reader.parseMap(mapFilename);
if (!m)
errorTexts << i18n("Error parsing %1: %2", mapFilename, p_reader.getError());
else
{
QString text = m -> getName();
KGmap* existingMap = p_maps.value(text);
if (existingMap)
{
errorTexts << i18n("The map %1 has the same name of map %2", mapFilename, existingMap -> getFile());
delete m;
}
else
{
QString text = m -> getName();
KGmap* existingMap = p_maps.value(text);
if (existingMap)
{
errorTexts << i18n("The map %1 has the same name of map %2", mapFilename, existingMap -> getFile());
delete m;
}
else
{
texts << text;
p_maps.insert(text, m);
if ( mapFilename == lastMapFile )
stringToSelect = text;
loadedMaps << file;
}
texts << text;
p_maps.insert(text, m);
if ( mapFilename == lastMapFile )
stringToSelect = text;
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment