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 "MultiProvider.h"
11 #include "utils/XBMCTinyXML.h"
15 CMultiProvider::CMultiProvider(const TiXmlNode
*first
, int parentID
)
16 : IListProvider(parentID
)
18 for (const TiXmlNode
*content
= first
; content
; content
= content
->NextSiblingElement("content"))
20 IListProviderPtr
sub(IListProvider::CreateSingle(content
, parentID
));
22 m_providers
.push_back(std::move(sub
));
26 CMultiProvider::CMultiProvider(const CMultiProvider
& other
) : IListProvider(other
.m_parentID
)
28 for (const auto& provider
: other
.m_providers
)
30 std::unique_ptr
<IListProvider
> newProvider
= provider
->Clone();
32 m_providers
.emplace_back(std::move(newProvider
));
36 std::unique_ptr
<IListProvider
> CMultiProvider::Clone()
38 return std::make_unique
<CMultiProvider
>(*this);
41 bool CMultiProvider::Update(bool forceRefresh
)
44 for (auto& provider
: m_providers
)
45 result
|= provider
->Update(forceRefresh
);
49 void CMultiProvider::Fetch(std::vector
<std::shared_ptr
<CGUIListItem
>>& items
)
51 std::unique_lock
<CCriticalSection
> lock(m_section
);
52 std::vector
<std::shared_ptr
<CGUIListItem
>> subItems
;
55 for (auto const& provider
: m_providers
)
57 provider
->Fetch(subItems
);
58 for (auto& item
: subItems
)
60 auto key
= GetItemKey(item
);
61 m_itemMap
[key
] = provider
.get();
62 items
.push_back(item
);
68 bool CMultiProvider::IsUpdating() const
71 for (auto const& provider
: m_providers
)
72 result
|= provider
->IsUpdating();
76 void CMultiProvider::Reset()
79 std::unique_lock
<CCriticalSection
> lock(m_section
);
83 for (auto const& provider
: m_providers
)
87 bool CMultiProvider::OnClick(const std::shared_ptr
<CGUIListItem
>& item
)
89 std::unique_lock
<CCriticalSection
> lock(m_section
);
90 auto key
= GetItemKey(item
);
91 auto it
= m_itemMap
.find(key
);
92 if (it
!= m_itemMap
.end())
93 return it
->second
->OnClick(item
);
98 bool CMultiProvider::OnInfo(const std::shared_ptr
<CGUIListItem
>& item
)
100 std::unique_lock
<CCriticalSection
> lock(m_section
);
101 auto key
= GetItemKey(item
);
102 auto it
= m_itemMap
.find(key
);
103 if (it
!= m_itemMap
.end())
104 return it
->second
->OnInfo(item
);
109 bool CMultiProvider::OnContextMenu(const std::shared_ptr
<CGUIListItem
>& item
)
111 std::unique_lock
<CCriticalSection
> lock(m_section
);
112 auto key
= GetItemKey(item
);
113 auto it
= m_itemMap
.find(key
);
114 if (it
!= m_itemMap
.end())
115 return it
->second
->OnContextMenu(item
);
120 CMultiProvider::item_key_type
CMultiProvider::GetItemKey(std::shared_ptr
<CGUIListItem
> const& item
)
122 return reinterpret_cast<item_key_type
>(item
.get());