Continues migration with DDS, Common
This commit is contained in:
1 parent
9b15cee841
commit
fa48db111e
668 files changed
+111841
-2
No files matched your search
+215
@@ -0,0 +1,215 @@
|
||||
|
||||
|
||||
|
||||
#include "lts_app_descriptor.h"
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonParseError>
|
||||
#include <QJsonValue>
|
||||
#include <QCoreApplication>
|
||||
|
||||
|
||||
|
||||
|
||||
namespace LtsAppDescriptor
|
||||
{
|
||||
static void addOptionToPlugin(PluginInfo &pluginInfo, const PluginInfo::Flag &flag)
|
||||
{
|
||||
pluginInfo.flags |= flag;
|
||||
}
|
||||
|
||||
|
||||
static void addOptionToPlugin(QVector<PluginInfo> &pluginInfos, const PluginInfo::Flag &flag, const QString &pluginName)
|
||||
{
|
||||
for (PluginInfo &pi : pluginInfos)
|
||||
{
|
||||
if (pi.iid == pluginName)
|
||||
{
|
||||
addOptionToPlugin(pi, flag);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
PluginInfo pi;
|
||||
pi.iid = pluginName;
|
||||
pi.type = PluginInfo::PluginType::GUI;
|
||||
addOptionToPlugin(pi, flag);
|
||||
pluginInfos.append(pi);
|
||||
}
|
||||
|
||||
|
||||
static bool addOptionsToPlugin(AppDescription &appDesc, const QString &optionIdentifier, const QStringList &ignoredPlugins,
|
||||
const QJsonObject &optionsObject, const PluginInfo::Flag flag, QStringList &lastErrors,
|
||||
bool atLeastOnePluginNeeded)
|
||||
{
|
||||
bool hasPlugins = false;
|
||||
auto optionsObjectIt = optionsObject.constFind(optionIdentifier);
|
||||
if (optionsObjectIt != optionsObject.constEnd())
|
||||
{
|
||||
const QJsonArray plugins((*optionsObjectIt).toObject()[QStringLiteral("Plugins")].toArray());
|
||||
|
||||
for (const auto &pluginElem : plugins)
|
||||
{
|
||||
const QString pluginName = pluginElem.toString();
|
||||
if (!ignoredPlugins.contains(pluginName))
|
||||
{
|
||||
addOptionToPlugin(appDesc.pluginInfos, flag, pluginName);
|
||||
hasPlugins = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (atLeastOnePluginNeeded && !hasPlugins)
|
||||
{
|
||||
lastErrors.append(QCoreApplication::tr("No plugins specified for '%1' option for app '%2'").arg(optionIdentifier, appDesc.appName));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
App LtsAppDescriptor::appFromInteger(int i)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case int(App::Login):
|
||||
case int(App::Situation):
|
||||
case int(App::ResourceManager):
|
||||
case int(App::PlanEditor):
|
||||
case int(App::BuildingViewer):
|
||||
case int(App::OC):
|
||||
case int(App::OrgChart):
|
||||
case int(App::Scripts):
|
||||
|
||||
case int(App::Snapshot):
|
||||
case int(App::SystemMonitor):
|
||||
case int(App::Timeline):
|
||||
case int(App::SymbolEditor):
|
||||
case int(App::ScriptEditorEssentialsView):
|
||||
case int(App::BaseDownloader):
|
||||
case int(App::OnlineHelp):
|
||||
case int(App::ThpSituationReplay):
|
||||
case int(App::SituationTablet):
|
||||
case int(App::SilhouetteEditor):
|
||||
case int(App::Shootback):
|
||||
case int(App::SAAs):
|
||||
return static_cast<App>(i);
|
||||
}
|
||||
Q_ASSERT_X(false, "LtsAppDescriptor::appFromInteger", qPrintable(QStringLiteral("Unknown app id: %1").arg(i)));
|
||||
return App::Login;
|
||||
}
|
||||
|
||||
AppDescriptionVector LtsAppDescriptor::getAppDescriptionVector(const QByteArray &jsonDocument,
|
||||
QStringList &lastErrors,
|
||||
const QStringList &ignoredPlugins,
|
||||
QString &loginPluginIid)
|
||||
{
|
||||
|
||||
|
||||
AppDescriptionVector appDescriptions;
|
||||
|
||||
QJsonParseError parseError;
|
||||
QJsonDocument appsDoc(QJsonDocument::fromJson(jsonDocument, &parseError));
|
||||
|
||||
if (parseError.error != QJsonParseError::NoError)
|
||||
{
|
||||
|
||||
|
||||
int row = 0;
|
||||
int column = 0;
|
||||
QChar x = QLatin1Char('\n');
|
||||
|
||||
for (int i = 0; i < jsonDocument.count(); i++)
|
||||
{
|
||||
if (i == parseError.offset)
|
||||
break;
|
||||
|
||||
if (QChar::fromLatin1(jsonDocument[i]) == x)
|
||||
{
|
||||
row++;
|
||||
column = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
column++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
lastErrors.append(QCoreApplication::tr("JSON: %1<br>Row: %2, Column: %3").arg(parseError.errorString()).arg(row+1).arg(column+1));
|
||||
return appDescriptions;
|
||||
}
|
||||
|
||||
const QJsonObject root(appsDoc.object());
|
||||
|
||||
loginPluginIid = root[QStringLiteral("LoginPlugin")].toString();
|
||||
|
||||
const QJsonArray appArray(root[QStringLiteral("Apps")].toArray());
|
||||
if (appArray.isEmpty())
|
||||
{
|
||||
lastErrors.append(QCoreApplication::tr("Invalid json: Could not find 'Apps' array"));
|
||||
return appDescriptions;
|
||||
}
|
||||
|
||||
|
||||
for (const auto &appElem : appArray)
|
||||
{
|
||||
AppDescription appDesc;
|
||||
const QJsonObject appObject = appElem.toObject();
|
||||
|
||||
|
||||
|
||||
appDesc.id = appFromInteger(appObject.value(QStringLiteral("Id")).toInt(-1));
|
||||
if (appDesc.id == App::Login)
|
||||
{
|
||||
lastErrors.append(QCoreApplication::tr("App '%1': no App Id or invalid App Id given").arg(appDesc.appName));
|
||||
return appDescriptions;
|
||||
}
|
||||
|
||||
appDesc.appName = appObject.value(QStringLiteral("AppName")).toString();
|
||||
|
||||
const QJsonValue valueActive = appObject.value(QStringLiteral("Active"));
|
||||
if (!valueActive.isUndefined())
|
||||
{
|
||||
if (valueActive.type() != QJsonValue::Type::Bool)
|
||||
{
|
||||
lastErrors.append(QCoreApplication::tr("App '%1': value App.Active is not a bool (%2)").arg(appDesc.appName).arg((int)valueActive.type()));
|
||||
return appDescriptions;
|
||||
}
|
||||
}
|
||||
appDesc.active = valueActive.toBool(false);
|
||||
|
||||
const QJsonValue valueVisible = appObject.value(QStringLiteral("Visible"));
|
||||
if (!valueVisible.isUndefined() && valueVisible.type() != QJsonValue::Type::Bool)
|
||||
{
|
||||
lastErrors.append(QCoreApplication::tr("App '%1': value App.Visible is not a bool (%2)").arg(appDesc.appName).arg((int)valueVisible.type()));
|
||||
return appDescriptions;
|
||||
}
|
||||
appDesc.visible = valueVisible.toBool(true);
|
||||
|
||||
const QJsonArray array(appObject.value(QStringLiteral("ACLs")).toArray());
|
||||
for (const QJsonValue &value : array)
|
||||
appDesc.requiredAcls.append(value.toInt());
|
||||
|
||||
|
||||
|
||||
const QJsonObject optionsObject(appObject.value(QStringLiteral("Options")).toObject());
|
||||
|
||||
addOptionsToPlugin(appDesc, QStringLiteral("Payloads"), ignoredPlugins, optionsObject, PluginInfo::Flag::PAYLOAD, lastErrors, false);
|
||||
addOptionsToPlugin(appDesc, QStringLiteral("Actions"), ignoredPlugins, optionsObject, PluginInfo::Flag::ACTIONS, lastErrors, true );
|
||||
addOptionsToPlugin(appDesc, QStringLiteral("Main"), ignoredPlugins, optionsObject, PluginInfo::Flag::MAIN, lastErrors, false);
|
||||
|
||||
|
||||
appDescriptions.append(appDesc);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return appDescriptions;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user