Ref T264, better display of other installed swift versions

* improved CApplicationInfo, added property support
* renamed functions
This commit is contained in:
Klaus Basan
2018-05-18 20:33:08 +02:00
parent bc969dcd9e
commit 7965f67455
8 changed files with 207 additions and 16 deletions

View File

@@ -9,8 +9,11 @@
//! \file
#include "blackconfig/buildconfig.h"
#include "blackmisc/applicationinfo.h"
#include "blackmisc/iconlist.h"
#include "blackmisc/comparefunctions.h"
#include "blackconfig/buildconfig.h"
#include <QStringBuilder>
using namespace BlackConfig;
@@ -33,26 +36,128 @@ namespace BlackMisc
}
}
const QString &CApplicationInfo::getApplicationAsString() const
{
static const QString unknown("unknown");
static const QString launcher("launcher");
static const QString core("core");
static const QString gui("gui");
static const QString mapping("mapping tool");
static const QString unitTest("unit test");
static const QString sample("sample");
switch (getApplication())
{
case Laucher: return launcher;
case PilotClientCore: return core;
case PilotClientGui: return gui;
case MappingTool: return mapping;
case UnitTest: return unitTest;
case Sample: return sample;
default: break;
}
return unknown;
}
bool CApplicationInfo::isSampleOrUnitTest() const
{
const Application a = this->application();
const Application a = this->getApplication();
return a == CApplicationInfo::Sample || a == CApplicationInfo::UnitTest;
}
bool CApplicationInfo::isUnitTest() const
{
const Application a = this->application();
const Application a = this->getApplication();
return a == CApplicationInfo::UnitTest;
}
bool CApplicationInfo::isNull() const
{
return this->application() == Unknown && m_exePath.isNull();
return this->getApplication() == Unknown && m_exePath.isNull();
}
QString CApplicationInfo::asOtherSwiftVersionString(const QString separator) const
{
return QStringLiteral("Version; ") % this->getVersionString() % QStringLiteral(" os: ") % this->getPlatform() % separator %
QStringLiteral("exe.path: ") % this->getExecutablePath() % separator %
QStringLiteral("app.data: ") % this->getApplicationDataDirectory();
}
QString CApplicationInfo::convertToQString(bool i18n) const
{
return QString("{ %1, %2, %3, %4 }").arg(QString::number(m_app), m_exePath, m_version, m_process.convertToQString(i18n));
return QString("{ %1, %2, %3, %4 }").arg(this->getApplicationAsString(), m_exePath, m_version, m_process.convertToQString(i18n));
}
CIcon CApplicationInfo::toIcon() const
{
switch (getApplication())
{
case Laucher: return CIconList::allIcons().findByIndex(CIcons::SwiftLauncher16);
case PilotClientCore: return CIconList::allIcons().findByIndex(CIcons::SwiftCore16);
case PilotClientGui: return CIconList::allIcons().findByIndex(CIcons::Swift16);
case MappingTool: return CIconList::allIcons().findByIndex(CIcons::SwiftDatabase16);
default: break;
}
return CIconList::allIcons().findByIndex(CIcons::StandardIconUnknown16);
}
CVariant CApplicationInfo::propertyByIndex(const CPropertyIndex &index) const
{
if (index.isMyself()) { return CVariant::from(*this); }
const ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexApplication: return CVariant::fromValue(m_app);
case IndexApplicationAsString: return CVariant::fromValue(this->getApplicationAsString());
case IndexApplicationDataPath: return CVariant::fromValue(this->getApplicationDataDirectory());
case IndexCompileInfo: return CVariant::fromValue(this->getCompileInfo());
case IndexExecutablePath: return CVariant::fromValue(this->getExecutablePath());
case IndexPlatformInfo: return CVariant::fromValue(this->getPlatform());
case IndexProcessInfo: return m_process.propertyByIndex(index.copyFrontRemoved());
case IndexVersionString: return CVariant::fromValue(this->getVersionString());
case IndexWordSize: return CVariant::fromValue(this->getWordSize());
default: break;
}
return CValueObject::propertyByIndex(index);
}
void CApplicationInfo::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
{
if (index.isMyself()) { (*this) = variant.to<CApplicationInfo>(); return; }
const ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexApplication: this->setApplication(static_cast<Application>(variant.toInt())); break;
case IndexApplicationAsString: break;
case IndexApplicationDataPath: this->setApplicationDataDirectory(variant.toQString()); break;
case IndexCompileInfo: this->setCompileInfo(variant.toQString()); break;
case IndexExecutablePath: this->setExecutablePath(variant.toQString()); break;
case IndexPlatformInfo: this->setPlatformInfo(variant.toQString()); break;
case IndexProcessInfo: m_process.setPropertyByIndex(index.copyFrontRemoved(), variant); break;
case IndexVersionString: this->setVersionString(variant.toQString()); break;
case IndexWordSize: return this->setWordSize(variant.toInt()); break;
default: CValueObject::setPropertyByIndex(index, variant); break;
}
}
int CApplicationInfo::comparePropertyByIndex(const CPropertyIndex &index, const CApplicationInfo &compareValue) const
{
if (index.isMyself()) { return this->getExecutablePath().compare(compareValue.getExecutablePath()); }
const ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexApplicationDataPath: this->getApplicationDataDirectory().compare(compareValue.getApplicationDataDirectory());
case IndexCompileInfo: this->getCompileInfo().compare(compareValue.getCompileInfo());
case IndexExecutablePath: this->getExecutablePath().compare(compareValue.getExecutablePath());
case IndexPlatformInfo: return this->getPlatform().compare(compareValue.getPlatform());
case IndexProcessInfo: return this->getProcessInfo().processName().compare(compareValue.getProcessInfo().processName());
case IndexVersionString: return this->getVersionString().compare(compareValue.getVersionString());
case IndexWordSize: return Compare::compare(this->getWordSize(), compareValue.getWordSize());
case IndexApplication:
case IndexApplicationAsString:
default:
return this->getApplicationAsString().compare(compareValue.getApplicationAsString());
}
}
const QString &CApplicationInfo::swiftPilotClientGui()
@@ -91,6 +196,12 @@ namespace BlackMisc
return fn;
}
const CApplicationInfo &CApplicationInfo::null()
{
static const CApplicationInfo n;
return n;
}
CApplicationInfo::Application CApplicationInfo::guessApplication()
{
const QString a(QCoreApplication::instance()->applicationName().toLower());
@@ -102,4 +213,4 @@ namespace BlackMisc
if (a.contains("data") || a.contains("mapping")) { return CApplicationInfo::MappingTool; }
return CApplicationInfo::Unknown;
}
}
} // ns

View File

@@ -39,6 +39,20 @@ namespace BlackMisc
Sample
};
//! Properties by index
enum ColumnIndex
{
IndexApplication = CPropertyIndex::GlobalIndexCApplicationInfo,
IndexApplicationAsString,
IndexApplicationDataPath,
IndexCompileInfo,
IndexExecutablePath,
IndexPlatformInfo,
IndexProcessInfo,
IndexVersionString,
IndexWordSize,
};
//! Default constructor.
CApplicationInfo();
@@ -49,7 +63,10 @@ namespace BlackMisc
void setApplication(Application app) { m_app = static_cast<int>(app); }
//! Get application.
Application application() const { return static_cast<Application>(m_app); }
Application getApplication() const { return static_cast<Application>(m_app); }
//! get application as string
const QString &getApplicationAsString() const;
//! Set executable path.
void setExecutablePath(const QString &exePath) { m_exePath = exePath; }
@@ -57,6 +74,14 @@ namespace BlackMisc
//! Get executable path.
const QString &getExecutablePath() const { return m_exePath; }
//! Set application data dir
//! \remark rootdir of settings, cache and logs
void setApplicationDataDirectory(const QString &appDataDir) { m_applicationDataDir = appDataDir; }
//! Set application data dir
//! \remark rootdir of settings, cache and logs
const QString &getApplicationDataDirectory() const { return m_applicationDataDir; }
//! Set version string.
void setVersionString(const QString &version) { m_version = version; }
@@ -96,9 +121,24 @@ namespace BlackMisc
//! Null object
bool isNull() const;
//! Formatted info
QString asOtherSwiftVersionString(const QString separator = " | ") const;
//! \copydoc BlackMisc::Mixin::String::toQString
QString convertToQString(bool i18n = false) const;
//! \copydoc BlackMisc::Mixin::Icon::toIcon()
CIcon toIcon() const;
//! \copydoc BlackMisc::Mixin::Index::propertyByIndex
CVariant propertyByIndex(const CPropertyIndex &index) const;
//! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex
void setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant);
//! Compare by index
int comparePropertyByIndex(const CPropertyIndex &index, const CApplicationInfo &compareValue) const;
//! Name of pilot client GUI
static const QString &swiftPilotClientGui();
@@ -117,15 +157,20 @@ namespace BlackMisc
//! File name of the application info file
static const QString &fileName();
//! NULL info
static const CApplicationInfo &null();
private:
int m_app = static_cast<int>(Unknown);
int m_wordSize;
QString m_exePath;
QString m_applicationDataDir;
QString m_version;
QString m_compileInfo;
QString m_platform;
CProcessInfo m_process;
//! Guess Application
static Application guessApplication();
BLACK_METACLASS(
@@ -133,6 +178,7 @@ namespace BlackMisc
BLACK_METAMEMBER(app),
BLACK_METAMEMBER(wordSize),
BLACK_METAMEMBER(exePath),
BLACK_METAMEMBER(applicationDataDir),
BLACK_METAMEMBER(version),
BLACK_METAMEMBER(compileInfo),
BLACK_METAMEMBER(platform),

View File

@@ -8,10 +8,14 @@
*/
#include "blackmisc/applicationinfolist.h"
#include "directoryutils.h"
#include "blackconfig/buildconfig.h"
using namespace BlackConfig;
namespace BlackMisc
{
CApplicationInfoList::CApplicationInfoList() = default;
CApplicationInfoList::CApplicationInfoList() {}
CApplicationInfoList::CApplicationInfoList(const CSequence<CApplicationInfo> &other) :
CSequence<CApplicationInfo>(other)
@@ -19,12 +23,12 @@ namespace BlackMisc
bool CApplicationInfoList::containsApplication(CApplicationInfo::Application application) const
{
return this->contains(&CApplicationInfo::application, application);
return this->contains(&CApplicationInfo::getApplication, application);
}
int CApplicationInfoList::removeApplication(CApplicationInfo::Application application)
{
return this->removeIf(&CApplicationInfo::application, application);
return this->removeIf(&CApplicationInfo::getApplication, application);
}
QStringList CApplicationInfoList::processNames() const
@@ -37,4 +41,27 @@ namespace BlackMisc
}
return names;
}
}
int CApplicationInfoList::otherSwiftVersionsFromDataDirectories()
{
this->clear();
const QMap<QString, CApplicationInfo> otherVersions = CDirectoryUtils::applicationDataDirectoryMapWithoutCurrentVersion();
for (const QString &directory : otherVersions.keys())
{
CApplicationInfo info(otherVersions.value(directory));
this->push_back(info);
}
return this->size();
}
CApplicationInfoList CApplicationInfoList::fromOtherSwiftVersionsFromDataDirectories()
{
static CApplicationInfoList info = []
{
CApplicationInfoList il;
il.otherSwiftVersionsFromDataDirectories();
return il;
}();
return info;
}
} // ns

View File

@@ -42,8 +42,14 @@ namespace BlackMisc
//! Running application names
QStringList processNames() const;
//! Fill from cache data directories
int otherSwiftVersionsFromDataDirectories();
//! Filled from cache data directories
static CApplicationInfoList fromOtherSwiftVersionsFromDataDirectories();
};
}
} // ns
Q_DECLARE_METATYPE(BlackMisc::CApplicationInfoList)
Q_DECLARE_METATYPE(BlackMisc::CSequence<BlackMisc::CApplicationInfo>)

View File

@@ -87,6 +87,7 @@ namespace BlackMisc
GlobalIndexCRgbColor = 800,
GlobalIndexCCountry = 900,
GlobalIndexCPlatform = 1000,
GlobalIndexCApplicationInfo = 1100,
GlobalIndexCCallsign = 2000,
GlobalIndexCAircraftSituation = 2100,
GlobalIndexCAircraftSituationChange = 2200,