[cosmetic] cleanup copyright headers
[vuplus_xbmc] / xbmc / listproviders / StaticProvider.cpp
1 /*
2  *      Copyright (C) 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 "StaticProvider.h"
22 #include "utils/XMLUtils.h"
23 #include "utils/TimeUtils.h"
24
25 using namespace std;
26
27 CStaticListProvider::CStaticListProvider(const TiXmlElement *element, int parentID)
28 : IListProvider(parentID),
29   m_defaultItem(-1),
30   m_defaultAlways(false),
31   m_updateTime(0)
32 {
33   assert(element);
34
35   const TiXmlElement *item = element->FirstChildElement("item");
36   while (item)
37   {
38     if (item->FirstChild())
39     {
40       CGUIStaticItemPtr newItem(new CGUIStaticItem(item, parentID));
41       m_items.push_back(newItem);
42     }
43     item = item->NextSiblingElement("item");
44   }
45
46   if (XMLUtils::GetInt(element, "default", m_defaultItem))
47   {
48     const char *always = element->FirstChildElement("default")->Attribute("always");
49     if (always && strnicmp(always, "true", 4) == 0)
50       m_defaultAlways = true;
51   }
52 }
53
54 CStaticListProvider::CStaticListProvider(const std::vector<CGUIStaticItemPtr> &items)
55 : IListProvider(0),
56   m_defaultItem(-1),
57   m_defaultAlways(false),
58   m_updateTime(0),
59   m_items(items)
60 {
61 }
62
63 CStaticListProvider::~CStaticListProvider()
64 {
65 }
66
67 bool CStaticListProvider::Update(bool refresh)
68 {
69   bool changed = refresh;
70   if (!m_updateTime)
71     m_updateTime = CTimeUtils::GetFrameTime();
72   else if (CTimeUtils::GetFrameTime() - m_updateTime > 1000)
73   {
74     m_updateTime = CTimeUtils::GetFrameTime();
75     for (vector<CGUIStaticItemPtr>::iterator i = m_items.begin(); i != m_items.end(); ++i)
76       (*i)->UpdateProperties(m_parentID);
77   }
78   for (vector<CGUIStaticItemPtr>::iterator i = m_items.begin(); i != m_items.end(); ++i)
79     changed |= (*i)->UpdateVisibility(m_parentID);
80   return changed; // TODO: Also returned changed if properties are changed (if so, need to update scroll to letter).
81 }
82
83 void CStaticListProvider::Fetch(vector<CGUIListItemPtr> &items) const
84 {
85   items.clear();
86   for (vector<CGUIStaticItemPtr>::const_iterator i = m_items.begin(); i != m_items.end(); ++i)
87   {
88     if ((*i)->IsVisible())
89       items.push_back(*i);
90   }
91 }
92
93 void CStaticListProvider::SetDefaultItem(int item, bool always)
94 {
95   m_defaultItem = item;
96   m_defaultAlways = always;
97 }
98
99 int CStaticListProvider::GetDefaultItem() const
100 {
101   if (m_defaultItem >= 0)
102   {
103     for (vector<CGUIStaticItemPtr>::const_iterator i = m_items.begin(); i != m_items.end(); ++i)
104     {
105       if ((*i)->m_iprogramCount == m_defaultItem && (*i)->IsVisible())
106         return i - m_items.begin();
107     }
108   }
109   return -1;
110 }
111
112 bool CStaticListProvider::AlwaysFocusDefaultItem() const
113 {
114   return m_defaultAlways;
115 }
116
117 bool CStaticListProvider::OnClick(const CGUIListItemPtr &item)
118 {
119   CGUIStaticItemPtr staticItem = boost::static_pointer_cast<CGUIStaticItem>(item);
120   return staticItem->GetClickActions().ExecuteActions(0, m_parentID);
121 }