McuSupport: Implement support for parsing path type from json

The json kit files have an entry named "type" which is intended to
specify whether a specific path points to a file or a directory (or
something else). Until now, this entry has not been handled and all
lineEdits expect a path, thus appearing red in the UI if supplied with
a file. With this patch, support for the type "file" is added, with the
possibility to support further types in parseLineEditType.

Currently, only File and ExistingDirectory are supported, with the
latter being used by default whenever no "type" entry is specified.

Task-number: UL-6610
Change-Id: I252d4eff76d4a11b92ce55a0c0964446072e48c1
Reviewed-by: Daniele Bortolotti <daniele.bortolotti@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Sivert Krøvel
2022-10-31 21:09:19 +01:00
parent 2c04c644d0
commit 8fa0c2c390
7 changed files with 85 additions and 22 deletions

View File

@@ -9,6 +9,7 @@
#include "mcusupportconstants.h"
#include "mcusupportoptions.h"
#include "mcusupportplugin.h"
#include "mcusupporttr.h"
#include "mcusupportversiondetection.h"
#include "mcutarget.h"
#include "mcutargetdescription.h"
@@ -630,6 +631,39 @@ static VersionDetection parseVersionDetection(const QJsonObject &packageEntry)
};
}
static Utils::PathChooser::Kind parseLineEditType(const QJsonValue &type)
{
//Utility function to handle the different kinds of PathChooser
//Default is ExistingDirectory, see pathchooser.h for more options
const auto defaultValue = Utils::PathChooser::Kind::ExistingDirectory;
if (type.isUndefined()) {
//No "type" entry in the json file, this is not an error
return defaultValue;
}
const QString typeString = type.toString();
if (typeString.isNull()) {
printMessage(Tr::tr("Parsing error: the type entry in JSON kit files must be a string, "
"defaulting to \"path\"")
.arg(typeString),
true);
return defaultValue;
} else if (typeString.compare("file", Qt::CaseInsensitive) == 0) {
return Utils::PathChooser::File;
} else if (typeString.compare("path", Qt::CaseInsensitive) == 0) {
return Utils::PathChooser::ExistingDirectory;
} else {
printMessage(Tr::tr(
"Parsing error: the type entry \"%2\" in JSON kit files is not supported, "
"defaulting to \"path\"")
.arg(typeString),
true);
return defaultValue;
}
}
static PackageDescription parsePackage(const QJsonObject &cmakeEntry)
{
@@ -652,7 +686,8 @@ static PackageDescription parsePackage(const QJsonObject &cmakeEntry)
FilePath::fromUserInput(detectionPathString),
versions,
parseVersionDetection(cmakeEntry),
cmakeEntry["addToSystemPath"].toBool()};
cmakeEntry["addToSystemPath"].toBool(),
parseLineEditType(cmakeEntry["type"])};
}
static QList<PackageDescription> parsePackages(const QJsonArray &cmakeEntries)