Merge pull request #3146 from FernetMenta/aefixes
[vuplus_xbmc] / xbmc / guilib / GUIStaticItem.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://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 "GUIStaticItem.h"
22 #include "utils/XMLUtils.h"
23 #include "GUIControlFactory.h"
24 #include "GUIInfoManager.h"
25 #include "utils/Variant.h"
26
27 using namespace std;
28
29 CGUIStaticItem::CGUIStaticItem(const TiXmlElement *item, int parentID) : CFileItem()
30 {
31   m_visCondition = 0;
32   m_visState = false;
33
34   assert(item);
35
36   // check whether we're using the more verbose method...
37   const TiXmlNode *click = item->FirstChild("onclick");
38   if (click && click->FirstChild())
39   {
40     CGUIInfoLabel label, label2, thumb, icon;
41     CGUIControlFactory::GetInfoLabel(item, "label", label, parentID);
42     CGUIControlFactory::GetInfoLabel(item, "label2", label2, parentID);
43     CGUIControlFactory::GetInfoLabel(item, "thumb", thumb, parentID);
44     CGUIControlFactory::GetInfoLabel(item, "icon", icon, parentID);
45     const char *id = item->Attribute("id");
46     CStdString condition;
47     CGUIControlFactory::GetConditionalVisibility(item, condition);
48     m_visCondition = g_infoManager.Register(condition, parentID);
49     CGUIControlFactory::GetActions(item, "onclick", m_clickActions);
50     SetLabel(label.GetLabel(parentID));
51     SetLabel2(label2.GetLabel(parentID));
52     SetArt("thumb", thumb.GetLabel(parentID, true));
53     SetIconImage(icon.GetLabel(parentID, true));
54     if (!label.IsConstant())  m_info.push_back(make_pair(label, "label"));
55     if (!label2.IsConstant()) m_info.push_back(make_pair(label2, "label2"));
56     if (!thumb.IsConstant())  m_info.push_back(make_pair(thumb, "thumb"));
57     if (!icon.IsConstant())   m_info.push_back(make_pair(icon, "icon"));
58     m_iprogramCount = id ? atoi(id) : 0;
59     // add any properties
60     const TiXmlElement *property = item->FirstChildElement("property");
61     while (property)
62     {
63       CStdString name = property->Attribute("name");
64       CGUIInfoLabel prop;
65       if (!name.IsEmpty() && CGUIControlFactory::GetInfoLabelFromElement(property, prop, parentID))
66       {
67         SetProperty(name, prop.GetLabel(parentID, true).c_str());
68         if (!prop.IsConstant())
69           m_info.push_back(make_pair(prop, name));
70       }
71       property = property->NextSiblingElement("property");
72     }
73   }
74   else
75   {
76     CStdString label, label2, thumb, icon;
77     label  = item->Attribute("label");  label  = CGUIControlFactory::FilterLabel(label);
78     label2 = item->Attribute("label2"); label2 = CGUIControlFactory::FilterLabel(label2);
79     thumb  = item->Attribute("thumb");  thumb  = CGUIControlFactory::FilterLabel(thumb);
80     icon   = item->Attribute("icon");   icon   = CGUIControlFactory::FilterLabel(icon);
81     const char *id = item->Attribute("id");
82     SetLabel(CGUIInfoLabel::GetLabel(label, parentID));
83     SetPath(item->FirstChild()->Value());
84     SetLabel2(CGUIInfoLabel::GetLabel(label2, parentID));
85     SetArt("thumb", CGUIInfoLabel::GetLabel(thumb, parentID, true));
86     SetIconImage(CGUIInfoLabel::GetLabel(icon, parentID, true));
87     m_iprogramCount = id ? atoi(id) : 0;
88   }
89 }
90     
91 void CGUIStaticItem::UpdateProperties(int contextWindow)
92 {
93   for (InfoVector::const_iterator i = m_info.begin(); i != m_info.end(); i++)
94   {
95     const CGUIInfoLabel &info = i->first;
96     const CStdString &name = i->second;
97     bool preferTexture = strnicmp("label", name.c_str(), 5) != 0;
98     CStdString value(info.GetLabel(contextWindow, preferTexture));
99     if (name.Equals("label"))
100       SetLabel(value);
101     else if (name.Equals("label2"))
102       SetLabel2(value);
103     else if (name.Equals("thumb"))
104       SetArt("thumb", value);
105     else if (name.Equals("icon"))
106       SetIconImage(value);
107     else
108       SetProperty(name, value.c_str());
109   }
110 }
111
112 bool CGUIStaticItem::UpdateVisibility(int contextWindow)
113 {
114   if (!m_visCondition)
115     return false;
116   bool state = g_infoManager.GetBoolValue(m_visCondition);
117   if (state != m_visState)
118   {
119     m_visState = state;
120     return true;
121   }
122   return false;
123 }
124
125 bool CGUIStaticItem::IsVisible() const
126 {
127   if (m_visCondition)
128     return m_visState;
129   return true;
130 }