2 * Copyright (C) 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 "StaticProvider.h"
22 #include "utils/XMLUtils.h"
23 #include "utils/TimeUtils.h"
27 CStaticListProvider::CStaticListProvider(const TiXmlElement *element, int parentID)
28 : IListProvider(parentID),
30 m_defaultAlways(false),
35 const TiXmlElement *item = element->FirstChildElement("item");
38 if (item->FirstChild())
40 CGUIStaticItemPtr newItem(new CGUIStaticItem(item, parentID));
41 m_items.push_back(newItem);
43 item = item->NextSiblingElement("item");
46 if (XMLUtils::GetInt(element, "default", m_defaultItem))
48 const char *always = element->FirstChildElement("default")->Attribute("always");
49 if (always && strnicmp(always, "true", 4) == 0)
50 m_defaultAlways = true;
54 CStaticListProvider::CStaticListProvider(const std::vector<CGUIStaticItemPtr> &items)
57 m_defaultAlways(false),
63 CStaticListProvider::~CStaticListProvider()
67 bool CStaticListProvider::Update(bool refresh)
69 bool changed = refresh;
71 m_updateTime = CTimeUtils::GetFrameTime();
72 else if (CTimeUtils::GetFrameTime() - m_updateTime > 1000)
74 m_updateTime = CTimeUtils::GetFrameTime();
75 for (vector<CGUIStaticItemPtr>::iterator i = m_items.begin(); i != m_items.end(); ++i)
76 (*i)->UpdateProperties(m_parentID);
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).
83 void CStaticListProvider::Fetch(vector<CGUIListItemPtr> &items) const
86 for (vector<CGUIStaticItemPtr>::const_iterator i = m_items.begin(); i != m_items.end(); ++i)
88 if ((*i)->IsVisible())
93 void CStaticListProvider::SetDefaultItem(int item, bool always)
96 m_defaultAlways = always;
99 int CStaticListProvider::GetDefaultItem() const
101 if (m_defaultItem >= 0)
103 for (vector<CGUIStaticItemPtr>::const_iterator i = m_items.begin(); i != m_items.end(); ++i)
105 if ((*i)->m_iprogramCount == m_defaultItem && (*i)->IsVisible())
106 return i - m_items.begin();
112 bool CStaticListProvider::AlwaysFocusDefaultItem() const
114 return m_defaultAlways;
117 bool CStaticListProvider::OnClick(const CGUIListItemPtr &item)
119 CGUIStaticItemPtr staticItem = boost::static_pointer_cast<CGUIStaticItem>(item);
120 return staticItem->GetClickActions().ExecuteActions(0, m_parentID);