[cosmetics] update date in GPL header
[vuplus_xbmc] / xbmc / interfaces / info / SkinVariable.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://www.xbmc.org
4  *
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)
8  *  any later version.
9  *
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.
14  *
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/>.
18  *
19  */
20
21 #include "SkinVariable.h"
22 #include "GUIInfoManager.h"
23 #include "utils/XBMCTinyXML.h"
24
25 using namespace std;
26 using namespace INFO;
27
28 #define DEFAULT_VALUE -1
29
30 const CSkinVariableString* CSkinVariable::CreateFromXML(const TiXmlElement& node, int context)
31 {
32   const char* name = node.Attribute("name");
33   if (name)
34   {
35     CSkinVariableString* tmp = new CSkinVariableString;
36     tmp->m_name = name;
37     tmp->m_context = context;
38     const TiXmlElement* valuenode = node.FirstChildElement("value");
39     while (valuenode)
40     {
41       if (valuenode->FirstChild())
42       {
43         CSkinVariableString::ConditionLabelPair pair;
44         if (valuenode->Attribute("condition"))
45           pair.m_condition = g_infoManager.Register(valuenode->Attribute("condition"), context);
46         else
47           pair.m_condition = DEFAULT_VALUE;
48
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
53       }
54       valuenode = valuenode->NextSiblingElement("value");
55     }
56     if (tmp->m_conditionLabelPairs.size() > 0)
57       return tmp;
58     delete tmp;
59   }
60   return NULL;
61 }
62
63 CSkinVariableString::CSkinVariableString()
64 {
65 }
66
67 int CSkinVariableString::GetContext() const
68 {
69   return m_context;
70 }
71
72 const CStdString& CSkinVariableString::GetName() const
73 {
74   return m_name;
75 }
76
77 CStdString CSkinVariableString::GetValue(bool preferImage /* = false*/, const CGUIListItem *item /* = NULL */)
78 {
79   for (VECCONDITIONLABELPAIR::const_iterator it = m_conditionLabelPairs.begin() ; it != m_conditionLabelPairs.end(); it++)
80   {
81     if (it->m_condition == DEFAULT_VALUE || g_infoManager.GetBoolValue(it->m_condition, item))
82     {
83       if (item)
84         return it->m_label.GetItemLabel(item, preferImage);
85       else
86         return it->m_label.GetLabel(m_context, preferImage);
87     }
88   }
89   return "";
90 }