Make PluginMeta::authors a std::vector<QString>

This commit is contained in:
Mm2PL 2023-02-13 23:43:25 +01:00
parent 6a183d3f33
commit d1bcede492
3 changed files with 41 additions and 7 deletions

View file

@ -14,8 +14,11 @@
"description": "Plugin description shown to the user." "description": "Plugin description shown to the user."
}, },
"authors": { "authors": {
"type": "string", "type": "array",
"description": "A string describing authors of the Plugin. This could be a list of names, an organisation or something else, as long as it's clear who made the Plugin." "description": "An array of authors of this Plugin.",
"items": {
"type": "string"
}
}, },
"homepage": { "homepage": {
"type": "string", "type": "string",

View file

@ -22,7 +22,7 @@ struct PluginMeta {
// required fields // required fields
QString name; QString name;
QString description; QString description;
QString authors; std::vector<QString> authors;
QString license; QString license;
semver::version version; semver::version version;
@ -53,12 +53,31 @@ struct PluginMeta {
this->description = descrObj.toString(); this->description = descrObj.toString();
auto authorsObj = obj.value("authors"); auto authorsObj = obj.value("authors");
if (!authorsObj.isString()) if (authorsObj.isArray())
{ {
this->invalidWhy.emplace_back("description is not a string"); auto authorsArr = authorsObj.toArray();
for (int i = 0; i < authorsArr.size(); i++)
{
const auto &t = authorsArr.at(i);
if (!t.isString())
{
this->invalidWhy.push_back(
QString(
"authors element #%1 is not a string (it is a %2)")
.arg(i)
.arg(QString::fromStdString(
std::string(magic_enum::enum_name(t.type())))));
this->valid = false;
return;
}
this->authors.push_back(t.toString());
}
}
else
{
this->invalidWhy.emplace_back("authors is not an array");
this->valid = false; this->valid = false;
} }
this->authors = authorsObj.toString();
auto licenseObj = obj.value("license"); auto licenseObj = obj.value("license");
if (!licenseObj.isString()) if (!licenseObj.isString())

View file

@ -91,7 +91,19 @@ void PluginsPage::rebuildContent()
descrText->setWordWrap(true); descrText->setWordWrap(true);
descrText->setStyleSheet("color: #bbb"); descrText->setStyleSheet("color: #bbb");
pl->addRow(descrText); pl->addRow(descrText);
pl->addRow("Authors", new QLabel(plugin->meta.authors));
QString authorsTxt;
for (const auto &author : plugin->meta.authors)
{
if (!authorsTxt.isEmpty())
{
authorsTxt += ", ";
}
authorsTxt += author;
}
pl->addRow("Authors", new QLabel(authorsTxt));
auto *homepage = new QLabel(formatRichLink(plugin->meta.homepage)); auto *homepage = new QLabel(formatRichLink(plugin->meta.homepage));
homepage->setOpenExternalLinks(true); homepage->setOpenExternalLinks(true);