summaryrefslogtreecommitdiffstats
path: root/xbmc/listproviders/MultiProvider.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 18:07:22 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 18:07:22 +0000
commitc04dcc2e7d834218ef2d4194331e383402495ae1 (patch)
tree7333e38d10d75386e60f336b80c2443c1166031d /xbmc/listproviders/MultiProvider.cpp
parentInitial commit. (diff)
downloadkodi-c04dcc2e7d834218ef2d4194331e383402495ae1.tar.xz
kodi-c04dcc2e7d834218ef2d4194331e383402495ae1.zip
Adding upstream version 2:20.4+dfsg.upstream/2%20.4+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'xbmc/listproviders/MultiProvider.cpp')
-rw-r--r--xbmc/listproviders/MultiProvider.cpp123
1 files changed, 123 insertions, 0 deletions
diff --git a/xbmc/listproviders/MultiProvider.cpp b/xbmc/listproviders/MultiProvider.cpp
new file mode 100644
index 0000000..e05a037
--- /dev/null
+++ b/xbmc/listproviders/MultiProvider.cpp
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2013-2018 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#include "MultiProvider.h"
+
+#include "utils/XBMCTinyXML.h"
+
+#include <mutex>
+
+CMultiProvider::CMultiProvider(const TiXmlNode *first, int parentID)
+ : IListProvider(parentID)
+{
+ for (const TiXmlNode *content = first; content; content = content->NextSiblingElement("content"))
+ {
+ IListProviderPtr sub(IListProvider::CreateSingle(content, parentID));
+ if (sub)
+ m_providers.push_back(std::move(sub));
+ }
+}
+
+CMultiProvider::CMultiProvider(const CMultiProvider& other) : IListProvider(other.m_parentID)
+{
+ for (const auto& provider : other.m_providers)
+ {
+ std::unique_ptr<IListProvider> newProvider = provider->Clone();
+ if (newProvider)
+ m_providers.emplace_back(std::move(newProvider));
+ }
+}
+
+std::unique_ptr<IListProvider> CMultiProvider::Clone()
+{
+ return std::make_unique<CMultiProvider>(*this);
+}
+
+bool CMultiProvider::Update(bool forceRefresh)
+{
+ bool result = false;
+ for (auto& provider : m_providers)
+ result |= provider->Update(forceRefresh);
+ return result;
+}
+
+void CMultiProvider::Fetch(std::vector<CGUIListItemPtr> &items)
+{
+ std::unique_lock<CCriticalSection> lock(m_section);
+ std::vector<CGUIListItemPtr> subItems;
+ items.clear();
+ m_itemMap.clear();
+ for (auto const& provider : m_providers)
+ {
+ provider->Fetch(subItems);
+ for (auto& item : subItems)
+ {
+ auto key = GetItemKey(item);
+ m_itemMap[key] = provider.get();
+ items.push_back(item);
+ }
+ subItems.clear();
+ }
+}
+
+bool CMultiProvider::IsUpdating() const
+{
+ bool result = false;
+ for (auto const& provider : m_providers)
+ result |= provider->IsUpdating();
+ return result;
+}
+
+void CMultiProvider::Reset()
+{
+ {
+ std::unique_lock<CCriticalSection> lock(m_section);
+ m_itemMap.clear();
+ }
+
+ for (auto const& provider : m_providers)
+ provider->Reset();
+}
+
+bool CMultiProvider::OnClick(const CGUIListItemPtr &item)
+{
+ std::unique_lock<CCriticalSection> lock(m_section);
+ auto key = GetItemKey(item);
+ auto it = m_itemMap.find(key);
+ if (it != m_itemMap.end())
+ return it->second->OnClick(item);
+ else
+ return false;
+}
+
+bool CMultiProvider::OnInfo(const CGUIListItemPtr &item)
+{
+ std::unique_lock<CCriticalSection> lock(m_section);
+ auto key = GetItemKey(item);
+ auto it = m_itemMap.find(key);
+ if (it != m_itemMap.end())
+ return it->second->OnInfo(item);
+ else
+ return false;
+}
+
+bool CMultiProvider::OnContextMenu(const CGUIListItemPtr &item)
+{
+ std::unique_lock<CCriticalSection> lock(m_section);
+ auto key = GetItemKey(item);
+ auto it = m_itemMap.find(key);
+ if (it != m_itemMap.end())
+ return it->second->OnContextMenu(item);
+ else
+ return false;
+}
+
+CMultiProvider::item_key_type CMultiProvider::GetItemKey(CGUIListItemPtr const &item)
+{
+ return reinterpret_cast<item_key_type>(item.get());
+}