diff --git a/src/Application.cpp b/src/Application.cpp index 5939ea6a..1459a810 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -42,6 +42,7 @@ int Application::run(const std::vector& arguments) { if (this->insightConfig.insightEnabled) { this->insight.setApplicationConfig(this->applicationConfig); this->insight.setEnvironmentConfig(this->environmentConfig); + this->insight.setInsightConfig(this->insightConfig); this->insight.run(); Logger::debug("Insight closed"); this->shutdown(); diff --git a/src/ApplicationConfig.cpp b/src/ApplicationConfig.cpp index 136b2231..bc75e802 100644 --- a/src/ApplicationConfig.cpp +++ b/src/ApplicationConfig.cpp @@ -79,6 +79,11 @@ void TargetConfig::init(QJsonObject jsonObject) { } this->name = jsonObject.find("name")->toString().toLower().toStdString(); + + if (jsonObject.contains("variantName")) { + this->variantName = jsonObject.find("variantName").value().toString().toLower().toStdString(); + } + this->jsonObject = jsonObject; } diff --git a/src/ApplicationConfig.hpp b/src/ApplicationConfig.hpp index 7bf6eb6c..624c9cd9 100644 --- a/src/ApplicationConfig.hpp +++ b/src/ApplicationConfig.hpp @@ -47,6 +47,9 @@ namespace Bloom void init(QJsonObject jsonObject); std::string name; + + std::string variantName; + QJsonObject jsonObject; }; diff --git a/src/Insight/Insight.cpp b/src/Insight/Insight.cpp index ec9d44e8..ae3a3486 100644 --- a/src/Insight/Insight.cpp +++ b/src/Insight/Insight.cpp @@ -61,7 +61,7 @@ void Insight::startup() { qRegisterMetaType(); qRegisterMetaType>(); - this->mainWindow.init(*(this->application), targetDescriptor); + this->mainWindow.init(*(this->application), targetDescriptor, this->insightConfig, this->environmentConfig.targetConfig); this->mainWindow.show(); /* diff --git a/src/Insight/Insight.hpp b/src/Insight/Insight.hpp index b6161a10..8f8793c7 100644 --- a/src/Insight/Insight.hpp +++ b/src/Insight/Insight.hpp @@ -26,6 +26,7 @@ namespace Bloom private: ApplicationConfig applicationConfig; EnvironmentConfig environmentConfig; + InsightConfig insightConfig; EventManager& eventManager; EventListenerPointer eventListener = std::make_shared("InsightEventListener"); @@ -54,6 +55,10 @@ namespace Bloom this->environmentConfig = environmentConfig; } + void setInsightConfig(const InsightConfig& insightConfig) { + this->insightConfig = insightConfig; + } + /** * Entry point for Insight. */ diff --git a/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp b/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp index 53c46fea..cb64321f 100644 --- a/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp @@ -16,7 +16,12 @@ using Targets::TargetVariant; using Targets::TargetPackage; -void InsightWindow::init(QApplication& application, TargetDescriptor targetDescriptor) { +void InsightWindow::init( + QApplication& application, + TargetDescriptor targetDescriptor, + const InsightConfig& config, + const TargetConfig& targetConfig +) { this->targetDescriptor = targetDescriptor; auto mainWindowUiFile = QFile(":/compiled/Insight/UserInterfaces/InsightWindow/UiFiles/InsightWindow.ui"); @@ -106,7 +111,21 @@ void InsightWindow::init(QApplication& application, TargetDescriptor targetDescr Logger::debug("Number of target variants supported by Insight: " + std::to_string(supportedVariants.size())); if (!supportedVariants.empty()) { - this->selectVariant(&supportedVariants.front()); + auto selectedVariant = std::find_if( + supportedVariants.begin(), + supportedVariants.end(), + [&targetConfig](const TargetVariant& variant) { + auto variantName = QString::fromStdString(variant.name).toLower().toStdString(); + return !targetConfig.variantName.empty() && targetConfig.variantName == variantName; + } + ); + + /* + * If ths user specified a valid variant name in their config file, use that as the default, otherwise just + * use the first supported variant. + */ + this->selectVariant((selectedVariant != supportedVariants.end()) ? &(*selectedVariant) + : &supportedVariants.front()); } else { if (this->targetDescriptor.variants.empty()) { diff --git a/src/Insight/UserInterfaces/InsightWindow/InsightWindow.hpp b/src/Insight/UserInterfaces/InsightWindow/InsightWindow.hpp index 59fc5816..6831c0f0 100644 --- a/src/Insight/UserInterfaces/InsightWindow/InsightWindow.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/InsightWindow.hpp @@ -7,6 +7,7 @@ #include #include "AboutWindow.hpp" +#include "src/ApplicationConfig.hpp" #include "TargetWidgets/TargetPackageWidget.hpp" #include "src/Targets/TargetState.hpp" #include "src/Targets/TargetDescriptor.hpp" @@ -71,7 +72,12 @@ namespace Bloom public: InsightWindow() = default; - void init(QApplication& application, Targets::TargetDescriptor targetDescriptor); + void init( + QApplication& application, + Targets::TargetDescriptor targetDescriptor, + const InsightConfig& config, + const TargetConfig& targetConfig + ); void show();