2 * Copyright (C) 2013-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
9 #include "StaticProvider.h"
11 #include "utils/StringUtils.h"
12 #include "utils/TimeUtils.h"
13 #include "utils/XMLUtils.h"
15 CStaticListProvider::CStaticListProvider(const TiXmlElement
*element
, int parentID
)
16 : IListProvider(parentID
),
18 m_defaultAlways(false),
23 const TiXmlElement
*item
= element
->FirstChildElement("item");
26 if (item
->FirstChild())
28 CGUIStaticItemPtr
newItem(new CGUIStaticItem(item
, parentID
));
29 m_items
.push_back(newItem
);
31 item
= item
->NextSiblingElement("item");
34 if (XMLUtils::GetInt(element
, "default", m_defaultItem
))
36 const char *always
= element
->FirstChildElement("default")->Attribute("always");
37 if (always
&& StringUtils::CompareNoCase(always
, "true", 4) == 0)
38 m_defaultAlways
= true;
42 CStaticListProvider::CStaticListProvider(const std::vector
<CGUIStaticItemPtr
> &items
)
45 m_defaultAlways(false),
51 CStaticListProvider::CStaticListProvider(const CStaticListProvider
& other
)
52 : IListProvider(other
.m_parentID
),
53 m_defaultItem(other
.m_defaultItem
),
54 m_defaultAlways(other
.m_defaultAlways
),
55 m_updateTime(other
.m_updateTime
)
57 for (const auto& item
: other
.m_items
)
59 std::shared_ptr
<CGUIListItem
> control(item
->Clone());
63 std::shared_ptr
<CGUIStaticItem
> newItem
= std::dynamic_pointer_cast
<CGUIStaticItem
>(control
);
67 m_items
.emplace_back(std::move(newItem
));
71 CStaticListProvider::~CStaticListProvider() = default;
73 std::unique_ptr
<IListProvider
> CStaticListProvider::Clone()
75 return std::make_unique
<CStaticListProvider
>(*this);
78 bool CStaticListProvider::Update(bool forceRefresh
)
80 bool changed
= forceRefresh
;
82 m_updateTime
= CTimeUtils::GetFrameTime();
83 else if (CTimeUtils::GetFrameTime() - m_updateTime
> 1000)
85 m_updateTime
= CTimeUtils::GetFrameTime();
86 for (auto& i
: m_items
)
87 i
->UpdateProperties(m_parentID
);
89 for (auto& i
: m_items
)
90 changed
|= i
->UpdateVisibility(m_parentID
);
91 return changed
; //! @todo Also returned changed if properties are changed (if so, need to update scroll to letter).
94 void CStaticListProvider::Fetch(std::vector
<std::shared_ptr
<CGUIListItem
>>& items
)
97 for (const auto& i
: m_items
)
104 void CStaticListProvider::SetDefaultItem(int item
, bool always
)
106 m_defaultItem
= item
;
107 m_defaultAlways
= always
;
110 int CStaticListProvider::GetDefaultItem() const
112 if (m_defaultItem
>= 0)
114 unsigned int offset
= 0;
115 for (const auto& i
: m_items
)
119 if (i
->m_iprogramCount
== m_defaultItem
)
128 bool CStaticListProvider::AlwaysFocusDefaultItem() const
130 return m_defaultAlways
;
133 bool CStaticListProvider::OnClick(const std::shared_ptr
<CGUIListItem
>& item
)
135 CGUIStaticItem
*staticItem
= static_cast<CGUIStaticItem
*>(item
.get());
136 return staticItem
->GetClickActions().ExecuteActions(0, m_parentID
);