Skip to content

Commit

Permalink
Merge pull request #9327 from xhaggi/guilib-expression-definitions
Browse files Browse the repository at this point in the history
[guilib] introduce reusable expression definitions
  • Loading branch information
xhaggi committed Mar 13, 2016
2 parents 2ecc21c + bd9cedc commit 8d55ebe
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
35 changes: 35 additions & 0 deletions xbmc/guilib/GUIIncludes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ CGUIIncludes::CGUIIncludes()
m_constantNodes.insert("fadetime");
m_constantNodes.insert("pauseatend");
m_constantNodes.insert("depth");

m_expressionAttributes.insert("condition");

m_expressionNodes.insert("visible");
m_expressionNodes.insert("enable");
m_expressionNodes.insert("usealttexture");
m_expressionNodes.insert("selected");
}

CGUIIncludes::~CGUIIncludes()
Expand Down Expand Up @@ -197,6 +204,17 @@ bool CGUIIncludes::LoadIncludesFromXML(const TiXmlElement *root)
node = node->NextSiblingElement("variable");
}

node = root->FirstChildElement("expression");
while (node)
{
if (node->Attribute("name") && node->FirstChild())
{
std::string tagName = node->Attribute("name");
m_expressions.insert(make_pair(tagName, node->FirstChild()->ValueStr()));
}
node = node->NextSiblingElement("expression");
}

return true;
}

Expand Down Expand Up @@ -341,11 +359,15 @@ void CGUIIncludes::ResolveIncludesForNode(TiXmlElement *node, std::map<INFO::Inf
{ // check the attribute against our set
if (m_constantAttributes.count(attribute->Name()))
attribute->SetValue(ResolveConstant(attribute->ValueStr()));
if (m_expressionAttributes.count(attribute->Name()))
attribute->SetValue(ResolveExpressions(attribute->ValueStr()));
attribute = attribute->Next();
}
// also do the value
if (node->FirstChild() && node->FirstChild()->Type() == TiXmlNode::TINYXML_TEXT && m_constantNodes.count(node->ValueStr()))
node->FirstChild()->SetValue(ResolveConstant(node->FirstChild()->ValueStr()));
if (node->FirstChild() && node->FirstChild()->Type() == TiXmlNode::TINYXML_TEXT && m_expressionNodes.count(node->ValueStr()))
node->FirstChild()->SetValue(ResolveExpressions(node->FirstChild()->ValueStr()));
}

bool CGUIIncludes::GetParameters(const TiXmlElement *include, const char *valueAttribute, Params& params)
Expand Down Expand Up @@ -490,6 +512,19 @@ std::string CGUIIncludes::ResolveConstant(const std::string &constant) const
return StringUtils::Join(values, ",");
}

std::string CGUIIncludes::ResolveExpressions(const std::string &expression) const
{
std::string work(expression);
CGUIInfoLabel::ReplaceSpecialKeywordReferences(work, "EXP", [&](const std::string &str) -> std::string {
std::map<std::string, std::string>::const_iterator it = m_expressions.find(str);
if (it != m_expressions.end())
return it->second;
return "";
});

return work;
}

const INFO::CSkinVariableString* CGUIIncludes::CreateSkinVariable(const std::string& name, int context)
{
std::map<std::string, TiXmlElement>::const_iterator it = m_skinvariables.find(name);
Expand Down
5 changes: 5 additions & 0 deletions xbmc/guilib/GUIIncludes.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,19 @@ class CGUIIncludes
static void ResolveParametersForNode(TiXmlElement *node, const Params& params);
static ResolveParamsResult ResolveParameters(const std::string& strInput, std::string& strOutput, const Params& params);
std::string ResolveConstant(const std::string &constant) const;
std::string ResolveExpressions(const std::string &expression) const;
bool HasIncludeFile(const std::string &includeFile) const;
std::map<std::string, std::pair<TiXmlElement, Params>> m_includes;
std::map<std::string, TiXmlElement> m_defaults;
std::map<std::string, TiXmlElement> m_skinvariables;
std::map<std::string, std::string> m_constants;
std::map<std::string, std::string> m_expressions;
std::vector<std::string> m_files;
typedef std::vector<std::string>::const_iterator iFiles;

std::set<std::string> m_constantAttributes;
std::set<std::string> m_constantNodes;

std::set<std::string> m_expressionAttributes;
std::set<std::string> m_expressionNodes;
};

0 comments on commit 8d55ebe

Please sign in to comment.