From db7674307dfecea3516bbf15cea6bab7fffd9947 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sivert=20Kr=C3=B8vel?= Date: Thu, 27 Oct 2022 02:12:10 +0200 Subject: [PATCH] McuSupport: Only store valid paths to settings The plugin currently requires valid packages before updating kits. Invalid packages are ignored. This change makes writing to settings consistent with this approach. If any of the given paths are invalid, changes are not applied. In order to not accidentally include changes made to packages for other targets than the one visible in the UI, the Apply-button in the Devices page now only stores the current target. This also avoids unpredictable behavior when more than one target in the repo track the same dependencies. The path shown in the UI is the one which is applied, not a hidden path currently stored in another target. Change-Id: Id0a6ec1aebd53357d0ee2fb68f14529f34ae887f Reviewed-by: Daniele Bortolotti Reviewed-by: Christian Stenger --- .../mcusupport/mcusupportoptionspage.cpp | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/plugins/mcusupport/mcusupportoptionspage.cpp b/src/plugins/mcusupport/mcusupportoptionspage.cpp index c493952f4fc..f728851774f 100644 --- a/src/plugins/mcusupport/mcusupportoptionspage.cpp +++ b/src/plugins/mcusupport/mcusupportoptionspage.cpp @@ -7,6 +7,7 @@ #include "mcusupportconstants.h" #include "mcusupportoptions.h" #include "mcusupportsdk.h" +#include "mcusupporttr.h" #include "mcutarget.h" #include "mcutargetfactory.h" #include "settingshandler.h" @@ -28,6 +29,7 @@ #include #include #include +#include #include #include @@ -288,8 +290,27 @@ void McuSupportOptionsWidget::apply() m_settingsHandler->setAutomaticKitCreation(m_options.automaticKitCreationEnabled()); McuTargetFactory::expandVariables(m_options.sdkRepository.packages); + + QMessageBox warningPopup(QMessageBox::Icon::Warning, + Tr::tr("Warning"), + Tr::tr("Unable to apply changes."), + QMessageBox::Ok, + this); + + auto target = currentMcuTarget(); + if (!target) { + warningPopup.setInformativeText(Tr::tr("No target selected.")); + warningPopup.exec(); + return; + } + if (!target->isValid()) { + warningPopup.setInformativeText(Tr::tr("Invalid path(s) present.")); + warningPopup.exec(); + return; + } + pathsChanged |= m_options.qtForMCUsSdkPackage->writeToSettings(); - for (const auto &package : std::as_const(m_options.sdkRepository.packages)) + for (const auto &package : target->packages()) pathsChanged |= package->writeToSettings(); if (pathsChanged) {