-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10730 from b-pass/multi-content
Allow multiple content elements in a single container
- Loading branch information
Showing
9 changed files
with
217 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
set(SOURCES DirectoryProvider.cpp | ||
IListProvider.cpp | ||
MultiProvider.cpp | ||
StaticProvider.cpp) | ||
|
||
set(HEADERS DirectoryProvider.h | ||
IListProvider.h | ||
MultiProvider.h | ||
StaticProvider.h) | ||
|
||
core_add_library(listproviders) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
* Copyright (C) 2013-2017 Team Kodi | ||
* http://kodi.tv | ||
* | ||
* This Program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2, or (at your option) | ||
* any later version. | ||
* | ||
* This Program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with XBMC; see the file COPYING. If not, see | ||
* <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#include "MultiProvider.h" | ||
#include "utils/XBMCTinyXML.h" | ||
#include "threads/SingleLock.h" | ||
|
||
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(sub); | ||
} | ||
} | ||
|
||
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) | ||
{ | ||
CSingleLock 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; | ||
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() | ||
{ | ||
{ | ||
CSingleLock lock(m_section); | ||
m_itemMap.clear(); | ||
} | ||
|
||
for (auto const& provider : m_providers) | ||
provider->Reset(); | ||
} | ||
|
||
bool CMultiProvider::OnClick(const CGUIListItemPtr &item) | ||
{ | ||
CSingleLock 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) | ||
{ | ||
CSingleLock 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) | ||
{ | ||
CSingleLock 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()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright (C) 2013-2017 Team Kodi | ||
* http://kodi.tv | ||
* | ||
* This Program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2, or (at your option) | ||
* any later version. | ||
* | ||
* This Program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with XBMC; see the file COPYING. If not, see | ||
* <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <vector> | ||
#include <map> | ||
#include "IListProvider.h" | ||
#include "threads/CriticalSection.h" | ||
|
||
typedef std::shared_ptr<IListProvider> IListProviderPtr; | ||
|
||
/*! | ||
\ingroup listproviders | ||
\brief A listprovider that handles multiple individual providers. | ||
*/ | ||
class CMultiProvider : public IListProvider | ||
{ | ||
public: | ||
CMultiProvider(const TiXmlNode *first, int parentID); | ||
|
||
virtual bool Update(bool forceRefresh) override; | ||
virtual void Fetch(std::vector<CGUIListItemPtr> &items) override; | ||
virtual bool IsUpdating() const override; | ||
virtual void Reset() override; | ||
virtual bool OnClick(const CGUIListItemPtr &item) override; | ||
virtual bool OnInfo(const CGUIListItemPtr &item) override; | ||
virtual bool OnContextMenu(const CGUIListItemPtr &item) override; | ||
|
||
protected: | ||
typedef size_t item_key_type; | ||
static item_key_type GetItemKey(CGUIListItemPtr const &item); | ||
std::vector<IListProviderPtr> m_providers; | ||
std::map<item_key_type, IListProviderPtr> m_itemMap; | ||
CCriticalSection m_section; // protects m_itemMap | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters