From 8cc3d1aac55f178af9fbc379ba029b2dd8588ad1 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Fri, 9 Sep 2022 18:03:58 +0200 Subject: [PATCH] Added some more workarounds for legacy theme sets with incorrectly defined element types. --- es-core/src/ThemeData.cpp | 34 ++++++++++++++++++++++++++-------- es-core/src/ThemeData.h | 9 ++++++++- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/es-core/src/ThemeData.cpp b/es-core/src/ThemeData.cpp index 6c1678cf5..79d21f0f1 100644 --- a/es-core/src/ThemeData.cpp +++ b/es-core/src/ThemeData.cpp @@ -1119,20 +1119,34 @@ void ThemeData::parseView(const pugi::xml_node& root, ThemeView& view) off = nameAttr.find_first_of(delim, prevOff); // Add the element type as a prefix to avoid name collisions between different - // component types. Also include a workaround for legacy theme sets if the - // md_releasedate and md_lastplayed element types are incorrectly defined as - // text instead of datetime. + // component types. Also include workarounds for legacy theme sets for when the + // fixed labels have been defined with the wrong element type. const std::string elementType {node.name()}; - bool dateTimeWorkaround {false}; + LegacyWorkaround legacyWorkaround {LegacyWorkaround::NONE}; if (mLegacyTheme && elementType == "text" && (elemKey == "md_releasedate" || elemKey == "md_lastplayed")) { LOG(LogDebug) << "ThemeData::parseView(): Element type for \"" << elemKey << "\" incorrectly set to \"text\" " "instead of \"datetime\", applying workaround"; - dateTimeWorkaround = true; + legacyWorkaround = LegacyWorkaround::DATETIME; elemKey = "datetime_" + elemKey; } + else if (mLegacyTheme && elementType == "datetime" && + (elemKey == "md_lbl_releasedate" || elemKey == "md_lbl_lastplayed")) { + LOG(LogDebug) << "ThemeData::parseView(): Element type for \"" << elemKey + << "\" incorrectly set to \"datetime\" " + "instead of \"text\", applying workaround"; + legacyWorkaround = LegacyWorkaround::TEXT; + elemKey = "text_" + elemKey; + } + else if (mLegacyTheme && elementType == "text" && elemKey == "md_rating") { + LOG(LogDebug) << "ThemeData::parseView(): Element type for \"" << elemKey + << "\" incorrectly set to \"text\" " + "instead of \"rating\", applying workaround"; + legacyWorkaround = LegacyWorkaround::RATING; + elemKey = "rating_" + elemKey; + } else { elemKey = elementType + "_" + elemKey; } @@ -1141,7 +1155,7 @@ void ThemeData::parseView(const pugi::xml_node& root, ThemeView& view) node, elemTypeIt->second, view.elements.insert(std::pair(elemKey, ThemeElement())) .first->second, - dateTimeWorkaround); + legacyWorkaround); if (mLegacyTheme && std::find(view.legacyOrderedKeys.cbegin(), view.legacyOrderedKeys.cend(), @@ -1154,14 +1168,18 @@ void ThemeData::parseView(const pugi::xml_node& root, ThemeView& view) void ThemeData::parseElement(const pugi::xml_node& root, const std::map& typeMap, ThemeElement& element, - bool dateTimeWorkaround) + const LegacyWorkaround legacyWorkaround) { ThemeException error; error << "ThemeData::parseElement(): "; error.setFiles(mPaths); - if (dateTimeWorkaround) + if (legacyWorkaround == LegacyWorkaround::DATETIME) element.type = "datetime"; + if (legacyWorkaround == LegacyWorkaround::TEXT) + element.type = "text"; + else if (legacyWorkaround == LegacyWorkaround::RATING) + element.type = "rating"; else element.type = root.name(); diff --git a/es-core/src/ThemeData.h b/es-core/src/ThemeData.h index 70af8d3b6..01931e3a0 100644 --- a/es-core/src/ThemeData.h +++ b/es-core/src/ThemeData.h @@ -239,6 +239,13 @@ public: std::map mVariables; private: + enum class LegacyWorkaround { + NONE = 0x00000000, + TEXT = 0x00000001, + DATETIME = 0x00000002, + RATING = 0x00000004 + }; + unsigned int getHexColor(const std::string& str); std::string resolvePlaceholders(const std::string& in); @@ -254,7 +261,7 @@ private: void parseElement(const pugi::xml_node& elementNode, const std::map& typeMap, ThemeElement& element, - bool dateTimeWorkaround = false); + const LegacyWorkaround legacyWorkaround); static std::vector sSupportedViews; static std::vector sLegacySupportedViews;