TextComponent now only accepts valid metadata and systemdata property values.

This commit is contained in:
Leon Styhre 2022-08-18 23:44:22 +02:00
parent 8c24d0a3b7
commit d24102db0e
3 changed files with 50 additions and 6 deletions

View file

@ -172,8 +172,18 @@ void DateTimeComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
<< str << "\""; << str << "\"";
} }
if (properties & METADATA && elem->has("metadata")) if (properties & METADATA && elem->has("metadata")) {
mThemeMetadata = elem->get<std::string>("metadata"); mThemeMetadata = "";
const std::string metadata {elem->get<std::string>("metadata")};
if (metadata == "releasedate" || metadata == "lastplayed") {
mThemeMetadata = metadata;
}
else {
LOG(LogWarning) << "DateTimeComponent: Invalid theme configuration, property "
"<metadata> defined as \""
<< metadata << "\"";
}
}
if (mThemeMetadata == "lastplayed") if (mThemeMetadata == "lastplayed")
setDisplayRelative(true); setDisplayRelative(true);

View file

@ -450,11 +450,37 @@ void TextComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
if (properties & TEXT && elem->has("text")) if (properties & TEXT && elem->has("text"))
setText(elem->get<std::string>("text")); setText(elem->get<std::string>("text"));
if (properties & METADATA && elem->has("systemdata")) if (properties & METADATA && elem->has("systemdata")) {
mThemeSystemdata = elem->get<std::string>("systemdata"); mThemeSystemdata = "";
const std::string systemdata {elem->get<std::string>("systemdata")};
for (auto& type : systemdataTypes) {
if (type == systemdata) {
mThemeSystemdata = type;
break;
}
}
if (mThemeSystemdata == "") {
LOG(LogWarning)
<< "TextComponent: Invalid theme configuration, property <systemdata> defined as \""
<< systemdata << "\"";
}
}
if (properties & METADATA && elem->has("metadata")) if (properties & METADATA && elem->has("metadata")) {
mThemeMetadata = elem->get<std::string>("metadata"); mThemeMetadata = "";
const std::string metadata {elem->get<std::string>("metadata")};
for (auto& type : metadataTypes) {
if (type == metadata) {
mThemeMetadata = type;
break;
}
}
if (mThemeMetadata == "") {
LOG(LogWarning)
<< "TextComponent: Invalid theme configuration, property <metadata> defined as \""
<< metadata << "\"";
}
}
if (properties & LETTER_CASE && elem->has("letterCase")) { if (properties & LETTER_CASE && elem->has("letterCase")) {
std::string letterCase {elem->get<std::string>("letterCase")}; std::string letterCase {elem->get<std::string>("letterCase")};

View file

@ -91,6 +91,14 @@ private:
void calculateExtent(); void calculateExtent();
void onColorChanged(); void onColorChanged();
static inline std::vector<std::string> systemdataTypes {
"name", "fullname", "gamecount", "gamecount_games", "gamecount_favorites"};
static inline std::vector<std::string> metadataTypes {
"name", "description", "rating", "developer", "publisher",
"genre", "players", "favorite", "completed", "kidgame",
"broken", "playcount", "controller", "altemulator"};
Renderer* mRenderer; Renderer* mRenderer;
unsigned int mColor; unsigned int mColor;
unsigned int mBgColor; unsigned int mBgColor;