2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2020 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2019-10-22 14:33:31 +02:00
|
|
|
|
2022-02-15 11:18:56 +01:00
|
|
|
#include "mcusupportoptions.h"
|
2022-02-15 11:18:56 +01:00
|
|
|
|
2022-02-16 16:48:28 +01:00
|
|
|
#include "mcukitinformation.h"
|
2022-03-09 17:29:07 +01:00
|
|
|
#include "mcukitmanager.h"
|
2022-06-17 17:15:17 +02:00
|
|
|
#include "mculegacyconstants.h"
|
2022-03-09 17:29:07 +01:00
|
|
|
#include "mcupackage.h"
|
2019-10-22 14:33:31 +02:00
|
|
|
#include "mcusupportconstants.h"
|
2022-02-16 16:48:28 +01:00
|
|
|
#include "mcusupportplugin.h"
|
2022-03-09 17:29:07 +01:00
|
|
|
#include "mcusupportsdk.h"
|
|
|
|
|
#include "mcutarget.h"
|
2022-04-22 11:41:33 +02:00
|
|
|
#include "settingshandler.h"
|
2019-10-22 14:33:31 +02:00
|
|
|
|
2021-02-26 14:22:42 +01:00
|
|
|
#include <cmakeprojectmanager/cmakekitinformation.h>
|
2022-02-15 11:18:56 +01:00
|
|
|
#include <cmakeprojectmanager/cmaketoolmanager.h>
|
2020-03-24 18:58:29 +01:00
|
|
|
#include <coreplugin/helpmanager.h>
|
2022-02-15 11:18:56 +01:00
|
|
|
#include <coreplugin/icore.h>
|
2019-10-22 14:33:31 +02:00
|
|
|
#include <debugger/debuggerkitinformation.h>
|
|
|
|
|
#include <utils/algorithm.h>
|
2022-02-15 11:18:56 +01:00
|
|
|
#include <qtsupport/qtkitinformation.h>
|
|
|
|
|
#include <qtsupport/qtversionmanager.h>
|
2019-10-22 14:33:31 +02:00
|
|
|
|
2021-03-10 16:38:45 +01:00
|
|
|
#include <QMessageBox>
|
|
|
|
|
#include <QPushButton>
|
2019-10-22 14:33:31 +02:00
|
|
|
|
2020-09-17 11:05:28 +02:00
|
|
|
using namespace Utils;
|
|
|
|
|
|
2022-03-28 16:42:51 +02:00
|
|
|
namespace McuSupport::Internal {
|
2019-10-22 14:33:31 +02:00
|
|
|
|
2022-04-22 11:41:33 +02:00
|
|
|
McuSupportOptions::McuSupportOptions(const SettingsHandler::Ptr &settingsHandler, QObject *parent)
|
2019-10-22 14:33:31 +02:00
|
|
|
: QObject(parent)
|
2022-06-17 17:15:17 +02:00
|
|
|
, qtForMCUsSdkPackage(createQtForMCUsPackage(settingsHandler))
|
2022-04-22 11:41:33 +02:00
|
|
|
, settingsHandler(settingsHandler)
|
2019-10-22 14:33:31 +02:00
|
|
|
{
|
2022-03-28 16:42:51 +02:00
|
|
|
connect(qtForMCUsSdkPackage.get(),
|
2022-02-16 10:44:23 +01:00
|
|
|
&McuAbstractPackage::changed,
|
2022-02-15 11:18:56 +01:00
|
|
|
this,
|
|
|
|
|
&McuSupportOptions::populatePackagesAndTargets);
|
2022-05-03 15:01:42 +02:00
|
|
|
m_automaticKitCreation = settingsHandler->isAutomaticKitCreationEnabled();
|
2019-10-22 14:33:31 +02:00
|
|
|
}
|
|
|
|
|
|
2020-03-18 03:17:35 +01:00
|
|
|
void McuSupportOptions::populatePackagesAndTargets()
|
|
|
|
|
{
|
2021-09-30 18:30:02 +02:00
|
|
|
setQulDir(qtForMCUsSdkPackage->path());
|
2020-03-18 03:17:35 +01:00
|
|
|
}
|
|
|
|
|
|
2022-04-22 11:41:33 +02:00
|
|
|
FilePath McuSupportOptions::qulDocsDir() const
|
2020-04-02 19:31:52 +02:00
|
|
|
{
|
2022-04-22 11:41:33 +02:00
|
|
|
const FilePath qulDir = qulDirFromSettings();
|
2020-04-02 19:31:52 +02:00
|
|
|
if (qulDir.isEmpty() || !qulDir.exists())
|
|
|
|
|
return {};
|
2022-04-21 12:27:51 +02:00
|
|
|
const FilePath docsDir = qulDir / "docs";
|
2020-09-17 11:05:28 +02:00
|
|
|
return docsDir.exists() ? docsDir : FilePath();
|
2020-04-02 19:31:52 +02:00
|
|
|
}
|
|
|
|
|
|
2020-03-24 18:58:29 +01:00
|
|
|
void McuSupportOptions::registerQchFiles()
|
|
|
|
|
{
|
2020-04-02 19:31:52 +02:00
|
|
|
const QString docsDir = qulDocsDir().toString();
|
|
|
|
|
if (docsDir.isEmpty())
|
2020-03-24 18:58:29 +01:00
|
|
|
return;
|
|
|
|
|
|
2020-12-04 08:47:55 +01:00
|
|
|
const QFileInfoList qchFiles = QDir(docsDir, "*.qch").entryInfoList();
|
2020-09-17 13:47:30 +02:00
|
|
|
Core::HelpManager::registerDocumentation(
|
2022-02-15 11:18:56 +01:00
|
|
|
Utils::transform<QStringList>(qchFiles,
|
|
|
|
|
[](const QFileInfo &fi) { return fi.absoluteFilePath(); }));
|
2020-03-24 18:58:29 +01:00
|
|
|
}
|
|
|
|
|
|
2020-04-02 19:31:52 +02:00
|
|
|
void McuSupportOptions::registerExamples()
|
|
|
|
|
{
|
2020-09-17 11:05:28 +02:00
|
|
|
const FilePath docsDir = qulDocsDir();
|
2020-04-02 19:31:52 +02:00
|
|
|
if (docsDir.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
2022-02-15 11:18:56 +01:00
|
|
|
auto examples = {std::make_pair(QStringLiteral("demos"), tr("Qt for MCUs Demos")),
|
|
|
|
|
std::make_pair(QStringLiteral("examples"), tr("Qt for MCUs Examples"))};
|
2021-02-09 17:06:24 +01:00
|
|
|
for (const auto &dir : examples) {
|
2022-04-22 11:41:33 +02:00
|
|
|
const FilePath examplesDir = qulDirFromSettings() / dir.first;
|
2021-02-09 17:06:24 +01:00
|
|
|
if (!examplesDir.exists())
|
|
|
|
|
continue;
|
|
|
|
|
|
2022-02-15 11:18:56 +01:00
|
|
|
QtSupport::QtVersionManager::registerExampleSet(dir.second,
|
|
|
|
|
docsDir.toString(),
|
2021-02-09 17:06:24 +01:00
|
|
|
examplesDir.toString());
|
|
|
|
|
}
|
2020-04-02 19:31:52 +02:00
|
|
|
}
|
|
|
|
|
|
2020-06-30 17:09:03 +02:00
|
|
|
const QVersionNumber &McuSupportOptions::minimalQulVersion()
|
2020-03-25 15:09:02 +01:00
|
|
|
{
|
2022-04-01 13:28:09 +02:00
|
|
|
return minimalVersion;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool McuSupportOptions::isLegacyVersion(const QVersionNumber &version)
|
|
|
|
|
{
|
|
|
|
|
return version < newVersion;
|
2020-03-25 15:09:02 +01:00
|
|
|
}
|
|
|
|
|
|
2020-09-17 11:05:28 +02:00
|
|
|
void McuSupportOptions::setQulDir(const FilePath &dir)
|
2020-03-18 03:17:35 +01:00
|
|
|
{
|
2020-12-04 16:32:34 +01:00
|
|
|
qtForMCUsSdkPackage->updateStatus();
|
2022-02-21 15:24:46 +01:00
|
|
|
if (qtForMCUsSdkPackage->isValidStatus())
|
2022-06-17 17:15:17 +02:00
|
|
|
sdkRepository = targetsAndPackages(dir, settingsHandler);
|
2022-03-28 16:42:51 +02:00
|
|
|
else
|
|
|
|
|
sdkRepository = McuSdkRepository{};
|
2021-09-29 17:23:11 +02:00
|
|
|
for (const auto &package : qAsConst(sdkRepository.packages))
|
2022-03-28 16:42:51 +02:00
|
|
|
connect(package.get(),
|
|
|
|
|
&McuAbstractPackage::changed,
|
|
|
|
|
this,
|
|
|
|
|
&McuSupportOptions::packagesChanged);
|
2020-09-17 11:05:28 +02:00
|
|
|
|
2022-02-14 18:01:04 +01:00
|
|
|
emit packagesChanged();
|
2020-03-18 03:17:35 +01:00
|
|
|
}
|
|
|
|
|
|
2022-04-22 11:41:33 +02:00
|
|
|
FilePath McuSupportOptions::qulDirFromSettings() const
|
2020-03-24 18:58:29 +01:00
|
|
|
{
|
2022-04-22 11:41:33 +02:00
|
|
|
return settingsHandler->getPath(Constants::SETTINGS_KEY_PACKAGE_QT_FOR_MCUS_SDK,
|
|
|
|
|
QSettings::UserScope,
|
|
|
|
|
{});
|
2019-10-22 14:33:31 +02:00
|
|
|
}
|
|
|
|
|
|
2022-02-16 16:48:28 +01:00
|
|
|
McuKitManager::UpgradeOption McuSupportOptions::askForKitUpgrades()
|
2021-03-10 16:38:45 +01:00
|
|
|
{
|
|
|
|
|
QMessageBox upgradePopup(Core::ICore::dialogParent());
|
|
|
|
|
upgradePopup.setStandardButtons(QMessageBox::Cancel);
|
2022-02-15 11:18:56 +01:00
|
|
|
QPushButton *replaceButton = upgradePopup.addButton(tr("Replace Existing Kits"),
|
|
|
|
|
QMessageBox::NoRole);
|
|
|
|
|
QPushButton *keepButton = upgradePopup.addButton(tr("Create New Kits"), QMessageBox::NoRole);
|
2021-03-10 16:38:45 +01:00
|
|
|
upgradePopup.setWindowTitle(tr("Qt for MCUs"));
|
2021-07-02 15:00:36 +02:00
|
|
|
upgradePopup.setText(tr("New version of Qt for MCUs detected. Upgrade existing kits?"));
|
2021-03-10 16:38:45 +01:00
|
|
|
|
|
|
|
|
upgradePopup.exec();
|
|
|
|
|
|
|
|
|
|
if (upgradePopup.clickedButton() == keepButton)
|
2022-02-16 16:48:28 +01:00
|
|
|
return McuKitManager::UpgradeOption::Keep;
|
2021-03-10 16:38:45 +01:00
|
|
|
|
|
|
|
|
if (upgradePopup.clickedButton() == replaceButton)
|
2022-02-16 16:48:28 +01:00
|
|
|
return McuKitManager::UpgradeOption::Replace;
|
2021-03-10 16:38:45 +01:00
|
|
|
|
2022-02-16 16:48:28 +01:00
|
|
|
return McuKitManager::UpgradeOption::Ignore;
|
2021-03-10 16:38:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void McuSupportOptions::checkUpgradeableKits()
|
|
|
|
|
{
|
2022-03-28 16:42:51 +02:00
|
|
|
if (!qtForMCUsSdkPackage->isValidStatus() || sdkRepository.mcuTargets.isEmpty())
|
2021-03-10 16:38:45 +01:00
|
|
|
return;
|
|
|
|
|
|
2022-03-28 16:42:51 +02:00
|
|
|
if (Utils::anyOf(sdkRepository.mcuTargets, [this](const McuTargetPtr &target) {
|
|
|
|
|
return !McuKitManager::upgradeableKits(target.get(), this->qtForMCUsSdkPackage).empty()
|
|
|
|
|
&& McuKitManager::matchingKits(target.get(), this->qtForMCUsSdkPackage).empty();
|
2021-03-10 16:38:45 +01:00
|
|
|
}))
|
2022-04-22 11:41:33 +02:00
|
|
|
McuKitManager::upgradeKitsByCreatingNewPackage(settingsHandler, askForKitUpgrades());
|
2021-03-10 16:38:45 +01:00
|
|
|
}
|
|
|
|
|
|
2022-02-16 16:48:28 +01:00
|
|
|
bool McuSupportOptions::kitsNeedQtVersion()
|
2021-03-10 16:38:45 +01:00
|
|
|
{
|
2022-02-16 16:48:28 +01:00
|
|
|
// Only on Windows, Qt is linked into the distributed qul Desktop libs. Also, the host tools
|
|
|
|
|
// are missing the Qt runtime libraries on non-Windows.
|
|
|
|
|
return !HostOsInfo::isWindowsHost();
|
2021-03-10 16:38:45 +01:00
|
|
|
}
|
|
|
|
|
|
2022-02-21 13:41:57 +01:00
|
|
|
bool McuSupportOptions::automaticKitCreationEnabled() const
|
2021-03-31 16:47:22 +02:00
|
|
|
{
|
2022-02-21 13:41:57 +01:00
|
|
|
return m_automaticKitCreation;
|
2021-03-31 16:47:22 +02:00
|
|
|
}
|
|
|
|
|
|
2022-02-21 13:41:57 +01:00
|
|
|
void McuSupportOptions::setAutomaticKitCreationEnabled(const bool enabled)
|
2021-04-08 17:14:55 +02:00
|
|
|
{
|
2022-02-21 13:41:57 +01:00
|
|
|
m_automaticKitCreation = enabled;
|
2021-04-08 17:14:55 +02:00
|
|
|
}
|
|
|
|
|
|
2022-03-28 16:42:51 +02:00
|
|
|
} // namespace McuSupport::Internal
|