2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2020 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2019-08-14 11:48:13 +02:00
|
|
|
|
|
|
|
|
#include "mcusupportplugin.h"
|
2022-02-15 11:18:56 +01:00
|
|
|
#include "mcukitinformation.h"
|
2022-03-28 16:42:51 +02:00
|
|
|
#include "mcukitmanager.h"
|
2019-08-14 11:48:13 +02:00
|
|
|
#include "mcusupportconstants.h"
|
|
|
|
|
#include "mcusupportdevice.h"
|
2020-03-24 18:58:29 +01:00
|
|
|
#include "mcusupportoptions.h"
|
2019-08-14 11:48:13 +02:00
|
|
|
#include "mcusupportoptionspage.h"
|
|
|
|
|
#include "mcusupportrunconfiguration.h"
|
|
|
|
|
|
2022-02-11 13:51:42 +01:00
|
|
|
#if defined(WITH_TESTS) && defined(GOOGLE_TEST_IS_FOUND)
|
|
|
|
|
#include "test/unittest.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-08-14 11:48:13 +02:00
|
|
|
#include <coreplugin/coreconstants.h>
|
|
|
|
|
#include <coreplugin/icontext.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
2022-02-16 16:48:28 +01:00
|
|
|
#include <coreplugin/messagemanager.h>
|
2019-08-14 11:48:13 +02:00
|
|
|
|
|
|
|
|
#include <projectexplorer/devicesupport/devicemanager.h>
|
|
|
|
|
#include <projectexplorer/jsonwizard/jsonwizardfactory.h>
|
2020-05-04 16:34:38 +02:00
|
|
|
#include <projectexplorer/kitmanager.h>
|
2022-06-22 15:43:33 +02:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2019-08-14 11:48:13 +02:00
|
|
|
|
2020-06-17 12:23:44 +02:00
|
|
|
#include <utils/infobar.h>
|
|
|
|
|
|
2020-03-04 17:48:27 +01:00
|
|
|
#include <QTimer>
|
|
|
|
|
|
|
|
|
|
using namespace Core;
|
2019-08-14 11:48:13 +02:00
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
|
2022-03-28 16:42:51 +02:00
|
|
|
namespace {
|
|
|
|
|
constexpr char setupMcuSupportKits[]{"SetupMcuSupportKits"};
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-14 11:48:13 +02:00
|
|
|
namespace McuSupport {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2022-02-16 16:48:28 +01:00
|
|
|
void printMessage(const QString &message, bool important)
|
|
|
|
|
{
|
|
|
|
|
const QString displayMessage = QCoreApplication::translate("QtForMCUs", "Qt for MCUs: %1")
|
|
|
|
|
.arg(message);
|
|
|
|
|
if (important)
|
|
|
|
|
Core::MessageManager::writeFlashing(displayMessage);
|
|
|
|
|
else
|
|
|
|
|
Core::MessageManager::writeSilently(displayMessage);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-14 11:48:13 +02:00
|
|
|
class McuSupportPluginPrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
McuSupportDeviceFactory deviceFactory;
|
2019-11-22 16:48:46 +01:00
|
|
|
McuSupportRunConfigurationFactory runConfigurationFactory;
|
2023-01-06 14:39:43 +01:00
|
|
|
FlashRunWorkerFactory flashRunWorkerFactory;
|
2022-06-22 16:11:56 +02:00
|
|
|
SettingsHandler::Ptr m_settingsHandler{new SettingsHandler};
|
2022-04-22 11:41:33 +02:00
|
|
|
McuSupportOptions m_options{m_settingsHandler};
|
|
|
|
|
McuSupportOptionsPage optionsPage{m_options, m_settingsHandler};
|
2021-03-09 18:28:58 +01:00
|
|
|
McuDependenciesKitAspect environmentPathsKitAspect;
|
2022-02-11 13:51:42 +01:00
|
|
|
}; // class McuSupportPluginPrivate
|
2019-08-14 11:48:13 +02:00
|
|
|
|
2022-02-15 11:18:56 +01:00
|
|
|
static McuSupportPluginPrivate *dd{nullptr};
|
2019-08-14 11:48:13 +02:00
|
|
|
|
|
|
|
|
McuSupportPlugin::~McuSupportPlugin()
|
|
|
|
|
{
|
|
|
|
|
delete dd;
|
|
|
|
|
dd = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-20 12:28:36 +01:00
|
|
|
void McuSupportPlugin::initialize()
|
2019-08-14 11:48:13 +02:00
|
|
|
{
|
2022-02-11 13:51:42 +01:00
|
|
|
setObjectName("McuSupportPlugin");
|
2022-06-22 16:11:56 +02:00
|
|
|
dd = new McuSupportPluginPrivate;
|
2019-08-14 11:48:13 +02:00
|
|
|
|
2022-04-22 11:41:33 +02:00
|
|
|
dd->m_options.registerQchFiles();
|
|
|
|
|
dd->m_options.registerExamples();
|
2021-08-10 16:19:02 +02:00
|
|
|
ProjectExplorer::JsonWizardFactory::addWizardPath(":/mcusupport/wizards/");
|
2019-08-14 11:48:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void McuSupportPlugin::extensionsInitialized()
|
|
|
|
|
{
|
|
|
|
|
ProjectExplorer::DeviceManager::instance()->addDevice(McuSupportDevice::create());
|
2020-05-04 16:34:38 +02:00
|
|
|
|
2022-04-22 11:41:33 +02:00
|
|
|
connect(KitManager::instance(), &KitManager::kitsLoaded, [this]() {
|
2022-02-14 18:01:04 +01:00
|
|
|
McuKitManager::removeOutdatedKits();
|
2022-06-22 16:11:56 +02:00
|
|
|
McuKitManager::createAutomaticKits(dd->m_settingsHandler);
|
|
|
|
|
McuKitManager::fixExistingKits(dd->m_settingsHandler);
|
2022-04-22 11:41:33 +02:00
|
|
|
askUserAboutMcuSupportKitsSetup();
|
2020-03-04 17:48:27 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void McuSupportPlugin::askUserAboutMcuSupportKitsSetup()
|
|
|
|
|
{
|
|
|
|
|
if (!ICore::infoBar()->canInfoBeAdded(setupMcuSupportKits)
|
2022-04-22 11:41:33 +02:00
|
|
|
|| dd->m_options.qulDirFromSettings().isEmpty()
|
2022-02-14 18:01:04 +01:00
|
|
|
|| !McuKitManager::existingKits(nullptr).isEmpty())
|
2020-03-04 17:48:27 +01:00
|
|
|
return;
|
|
|
|
|
|
2020-06-17 12:23:44 +02:00
|
|
|
Utils::InfoBarEntry info(setupMcuSupportKits,
|
|
|
|
|
tr("Create Kits for Qt for MCUs? "
|
2022-06-28 10:08:45 +02:00
|
|
|
"To do it later, select Edit > Preferences > Devices > MCU."),
|
2020-06-17 12:23:44 +02:00
|
|
|
Utils::InfoBarEntry::GlobalSuppression::Enabled);
|
2022-02-22 13:36:55 +01:00
|
|
|
// clazy:excludeall=connect-3arg-lambda
|
2022-03-28 16:42:51 +02:00
|
|
|
info.addCustomButton(tr("Create Kits for Qt for MCUs"), [] {
|
2020-03-04 17:48:27 +01:00
|
|
|
ICore::infoBar()->removeInfo(setupMcuSupportKits);
|
|
|
|
|
QTimer::singleShot(0, []() { ICore::showOptionsDialog(Constants::SETTINGS_ID); });
|
2020-05-04 16:34:38 +02:00
|
|
|
});
|
2020-03-04 17:48:27 +01:00
|
|
|
ICore::infoBar()->addInfo(info);
|
2019-08-14 11:48:13 +02:00
|
|
|
}
|
|
|
|
|
|
2022-04-22 11:41:33 +02:00
|
|
|
void McuSupportPlugin::askUserAboutMcuSupportKitsUpgrade(const SettingsHandler::Ptr &settingsHandler)
|
2021-03-10 16:38:45 +01:00
|
|
|
{
|
|
|
|
|
const char upgradeMcuSupportKits[] = "UpgradeMcuSupportKits";
|
|
|
|
|
|
|
|
|
|
if (!ICore::infoBar()->canInfoBeAdded(upgradeMcuSupportKits))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Utils::InfoBarEntry info(upgradeMcuSupportKits,
|
|
|
|
|
tr("New version of Qt for MCUs detected. Upgrade existing Kits?"),
|
|
|
|
|
Utils::InfoBarEntry::GlobalSuppression::Enabled);
|
2022-03-18 11:38:35 +01:00
|
|
|
using McuKitManager::UpgradeOption;
|
|
|
|
|
static UpgradeOption selectedOption = UpgradeOption::Keep;
|
2021-03-10 16:38:45 +01:00
|
|
|
|
2022-03-18 11:38:35 +01:00
|
|
|
const QList<Utils::InfoBarEntry::ComboInfo> infos
|
|
|
|
|
= {{tr("Create new kits"), QVariant::fromValue(UpgradeOption::Keep)},
|
|
|
|
|
{tr("Replace existing kits"), QVariant::fromValue(UpgradeOption::Replace)}};
|
|
|
|
|
|
|
|
|
|
info.setComboInfo(infos, [](const Utils::InfoBarEntry::ComboInfo &selected) {
|
|
|
|
|
selectedOption = selected.data.value<UpgradeOption>();
|
2021-03-10 16:38:45 +01:00
|
|
|
});
|
|
|
|
|
|
2022-04-22 11:41:33 +02:00
|
|
|
info.addCustomButton(tr("Proceed"), [upgradeMcuSupportKits, settingsHandler] {
|
2021-03-10 16:38:45 +01:00
|
|
|
ICore::infoBar()->removeInfo(upgradeMcuSupportKits);
|
2022-04-22 11:41:33 +02:00
|
|
|
QTimer::singleShot(0, [settingsHandler]() {
|
|
|
|
|
McuKitManager::upgradeKitsByCreatingNewPackage(settingsHandler, selectedOption);
|
2022-02-14 18:01:04 +01:00
|
|
|
});
|
2021-03-10 16:38:45 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ICore::infoBar()->addInfo(info);
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-11 13:51:42 +01:00
|
|
|
QVector<QObject *> McuSupportPlugin::createTestObjects() const
|
|
|
|
|
{
|
|
|
|
|
QVector<QObject *> tests;
|
|
|
|
|
#if defined(WITH_TESTS) && defined(GOOGLE_TEST_IS_FOUND)
|
|
|
|
|
tests << new Test::McuSupportTest;
|
|
|
|
|
#endif
|
|
|
|
|
return tests;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-14 11:48:13 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace McuSupport
|