2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
21 #include "SkinVariable.h"
22 #include "GUIInfoManager.h"
23 #include "utils/XBMCTinyXML.h"
28 #define DEFAULT_VALUE -1
30 const CSkinVariableString* CSkinVariable::CreateFromXML(const TiXmlElement& node, int context)
32 const char* name = node.Attribute("name");
35 CSkinVariableString* tmp = new CSkinVariableString;
37 tmp->m_context = context;
38 const TiXmlElement* valuenode = node.FirstChildElement("value");
41 if (valuenode->FirstChild())
43 CSkinVariableString::ConditionLabelPair pair;
44 if (valuenode->Attribute("condition"))
45 pair.m_condition = g_infoManager.Register(valuenode->Attribute("condition"), context);
47 pair.m_condition = DEFAULT_VALUE;
49 pair.m_label = CGUIInfoLabel(valuenode->FirstChild()->Value());
50 tmp->m_conditionLabelPairs.push_back(pair);
51 if (pair.m_condition == DEFAULT_VALUE)
52 break; // once we reach default value (without condition) break iterating
54 valuenode = valuenode->NextSiblingElement("value");
56 if (tmp->m_conditionLabelPairs.size() > 0)
63 CSkinVariableString::CSkinVariableString()
67 int CSkinVariableString::GetContext() const
72 const CStdString& CSkinVariableString::GetName() const
77 CStdString CSkinVariableString::GetValue(bool preferImage /* = false*/, const CGUIListItem *item /* = NULL */)
79 for (VECCONDITIONLABELPAIR::const_iterator it = m_conditionLabelPairs.begin() ; it != m_conditionLabelPairs.end(); it++)
81 if (it->m_condition == DEFAULT_VALUE || g_infoManager.GetBoolValue(it->m_condition, item))
84 return it->m_label.GetItemLabel(item, preferImage);
86 return it->m_label.GetLabel(m_context, preferImage);