Added some more workarounds for legacy theme sets with incorrectly defined element types.

This commit is contained in:
Leon Styhre 2022-09-09 18:03:58 +02:00
parent 34b56c490b
commit 8cc3d1aac5
2 changed files with 34 additions and 9 deletions

View file

@ -1119,20 +1119,34 @@ void ThemeData::parseView(const pugi::xml_node& root, ThemeView& view)
off = nameAttr.find_first_of(delim, prevOff); off = nameAttr.find_first_of(delim, prevOff);
// Add the element type as a prefix to avoid name collisions between different // 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 // component types. Also include workarounds for legacy theme sets for when the
// md_releasedate and md_lastplayed element types are incorrectly defined as // fixed labels have been defined with the wrong element type.
// text instead of datetime.
const std::string elementType {node.name()}; const std::string elementType {node.name()};
bool dateTimeWorkaround {false}; LegacyWorkaround legacyWorkaround {LegacyWorkaround::NONE};
if (mLegacyTheme && elementType == "text" && if (mLegacyTheme && elementType == "text" &&
(elemKey == "md_releasedate" || elemKey == "md_lastplayed")) { (elemKey == "md_releasedate" || elemKey == "md_lastplayed")) {
LOG(LogDebug) << "ThemeData::parseView(): Element type for \"" << elemKey LOG(LogDebug) << "ThemeData::parseView(): Element type for \"" << elemKey
<< "\" incorrectly set to \"text\" " << "\" incorrectly set to \"text\" "
"instead of \"datetime\", applying workaround"; "instead of \"datetime\", applying workaround";
dateTimeWorkaround = true; legacyWorkaround = LegacyWorkaround::DATETIME;
elemKey = "datetime_" + elemKey; 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 { else {
elemKey = elementType + "_" + elemKey; elemKey = elementType + "_" + elemKey;
} }
@ -1141,7 +1155,7 @@ void ThemeData::parseView(const pugi::xml_node& root, ThemeView& view)
node, elemTypeIt->second, node, elemTypeIt->second,
view.elements.insert(std::pair<std::string, ThemeElement>(elemKey, ThemeElement())) view.elements.insert(std::pair<std::string, ThemeElement>(elemKey, ThemeElement()))
.first->second, .first->second,
dateTimeWorkaround); legacyWorkaround);
if (mLegacyTheme && if (mLegacyTheme &&
std::find(view.legacyOrderedKeys.cbegin(), view.legacyOrderedKeys.cend(), 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, void ThemeData::parseElement(const pugi::xml_node& root,
const std::map<std::string, ElementPropertyType>& typeMap, const std::map<std::string, ElementPropertyType>& typeMap,
ThemeElement& element, ThemeElement& element,
bool dateTimeWorkaround) const LegacyWorkaround legacyWorkaround)
{ {
ThemeException error; ThemeException error;
error << "ThemeData::parseElement(): "; error << "ThemeData::parseElement(): ";
error.setFiles(mPaths); error.setFiles(mPaths);
if (dateTimeWorkaround) if (legacyWorkaround == LegacyWorkaround::DATETIME)
element.type = "datetime"; element.type = "datetime";
if (legacyWorkaround == LegacyWorkaround::TEXT)
element.type = "text";
else if (legacyWorkaround == LegacyWorkaround::RATING)
element.type = "rating";
else else
element.type = root.name(); element.type = root.name();

View file

@ -239,6 +239,13 @@ public:
std::map<std::string, std::string> mVariables; std::map<std::string, std::string> mVariables;
private: private:
enum class LegacyWorkaround {
NONE = 0x00000000,
TEXT = 0x00000001,
DATETIME = 0x00000002,
RATING = 0x00000004
};
unsigned int getHexColor(const std::string& str); unsigned int getHexColor(const std::string& str);
std::string resolvePlaceholders(const std::string& in); std::string resolvePlaceholders(const std::string& in);
@ -254,7 +261,7 @@ private:
void parseElement(const pugi::xml_node& elementNode, void parseElement(const pugi::xml_node& elementNode,
const std::map<std::string, ElementPropertyType>& typeMap, const std::map<std::string, ElementPropertyType>& typeMap,
ThemeElement& element, ThemeElement& element,
bool dateTimeWorkaround = false); const LegacyWorkaround legacyWorkaround);
static std::vector<std::string> sSupportedViews; static std::vector<std::string> sSupportedViews;
static std::vector<std::string> sLegacySupportedViews; static std::vector<std::string> sLegacySupportedViews;