mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-08 03:35:35 +08:00
refs #358, extended FS specific class for cfg entries
* more details fetched * conversion to aircraft model / aircraft mode list (FS specific to generic) * detect functions to find possible trouble makers
This commit is contained in:
@@ -8,6 +8,13 @@
|
||||
*/
|
||||
|
||||
#include "aircraftcfgentrieslist.h"
|
||||
#include "blackmisc/predicates.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
#include <QFuture>
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Network;
|
||||
|
||||
namespace BlackSim
|
||||
{
|
||||
@@ -20,9 +27,10 @@ namespace BlackSim
|
||||
bool CAircraftCfgEntriesList::existsDir(const QString &directory) const
|
||||
{
|
||||
QString d = directory.isEmpty() ? this->m_rootDirectory : directory;
|
||||
if (d.isEmpty()) return false;
|
||||
if (d.isEmpty()) { return false; }
|
||||
QDir dir(d);
|
||||
return (dir.exists());
|
||||
//! \todo not available network dir can make this hang here
|
||||
return dir.exists();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -30,14 +38,62 @@ namespace BlackSim
|
||||
*/
|
||||
bool CAircraftCfgEntriesList::containsModelWithTitle(const QString &title, Qt::CaseSensitivity caseSensitivity)
|
||||
{
|
||||
return this->containsBy([ = ](const CAircraftCfgEntries & entries) -> bool
|
||||
{ return title.compare(entries.getTitle(), caseSensitivity) == 0; });
|
||||
if (title.isEmpty()) { return false; }
|
||||
return this->containsBy(
|
||||
[ = ](const CAircraftCfgEntries & entries) -> bool { return title.compare(entries.getTitle(), caseSensitivity) == 0; }
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* Double titles
|
||||
*/
|
||||
QStringList CAircraftCfgEntriesList::detectAmbiguousTitles() const
|
||||
{
|
||||
QStringList titles = this->getTitles(true);
|
||||
QStringList ambiguousTitles;
|
||||
QString last;
|
||||
foreach(QString title, titles)
|
||||
{
|
||||
if (title.isEmpty()) { continue; }
|
||||
if (title.compare(last, Qt::CaseInsensitive) == 0)
|
||||
{
|
||||
if (!ambiguousTitles.contains(title, Qt::CaseInsensitive))
|
||||
{
|
||||
ambiguousTitles.append(title);
|
||||
}
|
||||
}
|
||||
last = title;
|
||||
}
|
||||
return ambiguousTitles;
|
||||
}
|
||||
|
||||
/*
|
||||
* All titles
|
||||
*/
|
||||
QStringList CAircraftCfgEntriesList::getTitles(bool sorted) const
|
||||
{
|
||||
QStringList titles = this->transform(Predicates::MemberTransform(&CAircraftCfgEntries::getTitle));
|
||||
if (sorted) { titles.sort(Qt::CaseInsensitive); }
|
||||
return titles;
|
||||
}
|
||||
|
||||
/*
|
||||
* As model list
|
||||
*/
|
||||
CAircraftModelList CAircraftCfgEntriesList::toAircraftModelList() const
|
||||
{
|
||||
CAircraftModelList ml;
|
||||
for (auto it = this->begin() ; it != this->end(); ++it)
|
||||
{
|
||||
ml.push_back(it->toAircraftModel());
|
||||
}
|
||||
return ml;
|
||||
}
|
||||
|
||||
/*
|
||||
* Models for title
|
||||
*/
|
||||
CAircraftCfgEntriesList CAircraftCfgEntriesList::findByTitle(const QString &title, Qt::CaseSensitivity caseSensitivity)
|
||||
CAircraftCfgEntriesList CAircraftCfgEntriesList::findByTitle(const QString &title, Qt::CaseSensitivity caseSensitivity) const
|
||||
{
|
||||
return this->findBy([ = ](const CAircraftCfgEntries & entries) -> bool
|
||||
{ return title.compare(entries.getTitle(), caseSensitivity) == 0; });
|
||||
@@ -48,6 +104,8 @@ namespace BlackSim
|
||||
*/
|
||||
int CAircraftCfgEntriesList::read(const QString &directory)
|
||||
{
|
||||
if (m_cancelRead) { return -1; }
|
||||
|
||||
// set directory with name filters, get aircraft.cfg and sub directories
|
||||
QDir dir(directory, "aircraft.cfg", QDir::Name, QDir::Files | QDir::AllDirs);
|
||||
if (!dir.exists()) return 0; // can happen if there are shortcuts or linked dirs not available
|
||||
@@ -60,6 +118,7 @@ namespace BlackSim
|
||||
|
||||
foreach(QFileInfo file, files)
|
||||
{
|
||||
if (m_cancelRead) { return -1; }
|
||||
if (file.isDir())
|
||||
{
|
||||
QString nextDir = file.absoluteFilePath();
|
||||
@@ -74,28 +133,44 @@ namespace BlackSim
|
||||
|
||||
// I abuse the QSettings as ini-file reader
|
||||
QSettings aircraftCfg(path, QSettings::IniFormat);
|
||||
|
||||
// from the general section
|
||||
const QString atcType = aircraftCfg.value("atc_type").toString();
|
||||
const QString atcModel = aircraftCfg.value("atc_model").toString();
|
||||
|
||||
int index = 0;
|
||||
while (index >= 0)
|
||||
{
|
||||
if (m_cancelRead) { return -1; }
|
||||
QString group = QString("fltsim.%1").arg(index);
|
||||
aircraftCfg.beginGroup(group);
|
||||
|
||||
// does group exist?
|
||||
if (aircraftCfg.contains("title"))
|
||||
{
|
||||
CAircraftCfgEntries entry(path, index, "", atcType, atcModel, "");
|
||||
entry.setTitle(aircraftCfg.value("title").toString());
|
||||
entry.setAtcParkingCode(aircraftCfg.value("atc_parking_codes").toString());
|
||||
this->push_back(entry);
|
||||
aircraftCfg.endGroup();
|
||||
QString title = fixedStringContent(aircraftCfg, "title");
|
||||
if (!title.isEmpty())
|
||||
{
|
||||
CAircraftCfgEntries entry(path, index, title, atcType, atcModel, "", "");
|
||||
entry.setAtcParkingCode(fixedStringContent(aircraftCfg, "atc_parking_codes"));
|
||||
entry.setDescription(fixedStringContent(aircraftCfg, "description"));
|
||||
entry.setUiManufacturer(fixedStringContent(aircraftCfg, "ui_manufacturer"));
|
||||
entry.setUiType(fixedStringContent(aircraftCfg, "ui_type"));
|
||||
this->push_back(entry);
|
||||
}
|
||||
else
|
||||
{
|
||||
CLogMessage(this).info("FSX model in %1, index %2 has no title") << path << index;
|
||||
}
|
||||
++index;
|
||||
++counter;
|
||||
}
|
||||
else
|
||||
{
|
||||
// marks end of the "fltsim.x" groups
|
||||
index = -1;
|
||||
}
|
||||
aircraftCfg.endGroup();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -103,6 +178,30 @@ namespace BlackSim
|
||||
return counter;
|
||||
}
|
||||
|
||||
QString CAircraftCfgEntriesList::fixedStringContent(const QSettings &settings, const QString &key)
|
||||
{
|
||||
return fixedStringContent(settings.value(key));
|
||||
}
|
||||
|
||||
QString CAircraftCfgEntriesList::fixedStringContent(const QVariant &qv)
|
||||
{
|
||||
if (qv.isNull() || !qv.isValid())
|
||||
{
|
||||
return ""; // normal when there is no settings value
|
||||
}
|
||||
else if (qv.type() == QMetaType::QStringList)
|
||||
{
|
||||
QStringList l = qv.toStringList();
|
||||
return l.join(",").trimmed();
|
||||
}
|
||||
else if (qv.type() == QMetaType::QString)
|
||||
{
|
||||
return qv.toString().trimmed();
|
||||
}
|
||||
Q_ASSERT(false);
|
||||
return "";
|
||||
}
|
||||
|
||||
/*
|
||||
* Register metadata
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user