2019-10-22 14:33:31 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2020-07-02 16:04:31 +02:00
|
|
|
** Copyright (C) 2020 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2019-10-22 14:33:31 +02:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
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"
|
|
|
|
|
#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"
|
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 ProjectExplorer;
|
|
|
|
|
using namespace Utils;
|
|
|
|
|
|
2022-03-28 16:42:51 +02:00
|
|
|
namespace McuSupport::Internal {
|
2019-10-22 14:33:31 +02:00
|
|
|
|
2022-03-28 16:42:51 +02:00
|
|
|
namespace {
|
|
|
|
|
const QString automaticKitCreationSettingsKey = QLatin1String(Constants::SETTINGS_GROUP) + '/'
|
|
|
|
|
+ QLatin1String(
|
|
|
|
|
Constants::SETTINGS_KEY_AUTOMATIC_KIT_CREATION);
|
2021-09-29 17:23:11 +02:00
|
|
|
}
|
|
|
|
|
|
2019-10-22 14:33:31 +02:00
|
|
|
McuSupportOptions::McuSupportOptions(QObject *parent)
|
|
|
|
|
: QObject(parent)
|
2020-03-12 14:25:49 +01:00
|
|
|
, qtForMCUsSdkPackage(Sdk::createQtForMCUsPackage())
|
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-02-21 13:41:57 +01:00
|
|
|
m_automaticKitCreation = automaticKitCreationFromSettings();
|
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
|
|
|
}
|
|
|
|
|
|
2020-09-17 11:05:28 +02:00
|
|
|
static FilePath qulDocsDir()
|
2020-04-02 19:31:52 +02:00
|
|
|
{
|
2020-09-17 11:05:28 +02:00
|
|
|
const FilePath qulDir = McuSupportOptions::qulDirFromSettings();
|
2020-04-02 19:31:52 +02:00
|
|
|
if (qulDir.isEmpty() || !qulDir.exists())
|
|
|
|
|
return {};
|
2020-09-17 11:05:28 +02:00
|
|
|
const FilePath docsDir = qulDir.pathAppended("docs");
|
|
|
|
|
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-02-15 11:18:56 +01:00
|
|
|
const FilePath examplesDir = McuSupportOptions::qulDirFromSettings().pathAppended(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-03-09 17:29:07 +01:00
|
|
|
return legacyVersion;
|
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-03-28 16:42:51 +02:00
|
|
|
sdkRepository = Sdk::targetsAndPackages(dir);
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2020-09-17 11:05:28 +02:00
|
|
|
FilePath McuSupportOptions::qulDirFromSettings()
|
2020-03-24 18:58:29 +01:00
|
|
|
{
|
2022-02-01 14:30:35 +01:00
|
|
|
return Sdk::packagePathFromSettings(Constants::SETTINGS_KEY_PACKAGE_QT_FOR_MCUS_SDK,
|
2022-02-22 14:06:18 +01:00
|
|
|
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-02-16 16:48:28 +01:00
|
|
|
McuKitManager::upgradeKitsByCreatingNewPackage(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-02-21 13:41:57 +01:00
|
|
|
void McuSupportOptions::writeGeneralSettings() const
|
2021-02-09 17:27:02 +01:00
|
|
|
{
|
2022-02-21 13:41:57 +01:00
|
|
|
QSettings *settings = Core::ICore::settings(QSettings::UserScope);
|
2022-03-28 16:42:51 +02:00
|
|
|
settings->setValue(automaticKitCreationSettingsKey, m_automaticKitCreation);
|
2022-02-21 13:41:57 +01:00
|
|
|
}
|
2021-03-09 18:28:58 +01:00
|
|
|
|
2022-02-21 13:41:57 +01:00
|
|
|
bool McuSupportOptions::automaticKitCreationFromSettings()
|
|
|
|
|
{
|
|
|
|
|
QSettings *settings = Core::ICore::settings(QSettings::UserScope);
|
2022-03-28 16:42:51 +02:00
|
|
|
const bool automaticKitCreation = settings->value(automaticKitCreationSettingsKey, true).toBool();
|
2022-02-21 13:41:57 +01:00
|
|
|
return automaticKitCreation;
|
2021-02-09 17:27:02 +01:00
|
|
|
}
|
|
|
|
|
|
2022-03-28 16:42:51 +02:00
|
|
|
} // namespace McuSupport::Internal
|