Skip to content

Commit

Permalink
A new type of list provider, MultiProvider, which allows multiple <co…
Browse files Browse the repository at this point in the history
…ntent> blocks in a single container.
  • Loading branch information
b-pass committed Oct 19, 2016
1 parent 4e49a1d commit f818b38
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 8 deletions.
6 changes: 6 additions & 0 deletions Kodi.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,7 @@
8883CEA70DD81807004E8B72 /* DVDSubtitleParserSSA.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8883CEA30DD81807004E8B72 /* DVDSubtitleParserSSA.cpp */; };
8883CEA80DD81807004E8B72 /* DVDSubtitlesLibass.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8883CEA50DD81807004E8B72 /* DVDSubtitlesLibass.cpp */; };
889B4D8E0E0EF86C00FAD25E /* RSSDirectory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 889B4D8C0E0EF86C00FAD25E /* RSSDirectory.cpp */; };
8D0E755E1DB7F5C700CF0485 /* MultiProvider.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8D0E755C1DB7F5C700CF0485 /* MultiProvider.cpp */; };
9A2FAD6A1C972BE10049652A /* ContextMenus.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A2FAD681C972BE10049652A /* ContextMenus.cpp */; };
9A2FAD6B1C972BE10049652A /* ContextMenus.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A2FAD681C972BE10049652A /* ContextMenus.cpp */; };
9A7368511C401F5F00CA169F /* DirectoryNodeInProgressTvShows.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A73684F1C401F5F00CA169F /* DirectoryNodeInProgressTvShows.cpp */; };
Expand Down Expand Up @@ -3500,6 +3501,8 @@
889B4D8C0E0EF86C00FAD25E /* RSSDirectory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RSSDirectory.cpp; sourceTree = "<group>"; };
889B4D8D0E0EF86C00FAD25E /* RSSDirectory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RSSDirectory.h; sourceTree = "<group>"; };
88ECB6580DE013C4003396A7 /* DiskArbitration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = DiskArbitration.framework; path = /System/Library/Frameworks/DiskArbitration.framework; sourceTree = "<absolute>"; };
8D0E755C1DB7F5C700CF0485 /* MultiProvider.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = MultiProvider.cpp; path = xbmc/listproviders/MultiProvider.cpp; sourceTree = SOURCE_ROOT; };
8D0E755D1DB7F5C700CF0485 /* MultiProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MultiProvider.h; path = xbmc/listproviders/MultiProvider.h; sourceTree = SOURCE_ROOT; };
8DD76F7E0486A8DE00D96B5E /* Kodi */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Kodi; sourceTree = BUILT_PRODUCTS_DIR; };
9A2FAD681C972BE10049652A /* ContextMenus.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ContextMenus.cpp; sourceTree = "<group>"; };
9A2FAD691C972BE10049652A /* ContextMenus.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContextMenus.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -6356,6 +6359,8 @@
7C8FC6ED1829A4580045153D /* DirectoryProvider.h */,
7C7BCDBF17727951004842FB /* IListProvider.cpp */,
7C7BCDC417727951004842FB /* IListProvider.h */,
8D0E755C1DB7F5C700CF0485 /* MultiProvider.cpp */,
8D0E755D1DB7F5C700CF0485 /* MultiProvider.h */,
7C7BCDC317727951004842FB /* StaticProvider.cpp */,
7C7BCDC217727951004842FB /* StaticProvider.h */,
);
Expand Down Expand Up @@ -9885,6 +9890,7 @@
DF54F7FE1B6580AD000FCBA4 /* ContextMenuItem.cpp in Sources */,
395C29C51A98A0E100EBC7AD /* ILanguageInvoker.cpp in Sources */,
E38E20580D25F9FD00618676 /* SmartPlaylistDirectory.cpp in Sources */,
8D0E755E1DB7F5C700CF0485 /* MultiProvider.cpp in Sources */,
E38E205B0D25F9FD00618676 /* StackDirectory.cpp in Sources */,
E38E205C0D25F9FD00618676 /* UPnPDirectory.cpp in Sources */,
E38E205E0D25F9FD00618676 /* DirectoryNode.cpp in Sources */,
Expand Down
2 changes: 2 additions & 0 deletions xbmc/listproviders/CMakeLists.txt
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)
24 changes: 18 additions & 6 deletions xbmc/listproviders/IListProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,30 @@
#include "utils/XBMCTinyXML.h"
#include "StaticProvider.h"
#include "DirectoryProvider.h"
#include "MultiProvider.h"

IListProvider *IListProvider::Create(const TiXmlNode *node, int parentID)
{
const TiXmlElement *root = node->FirstChildElement("content");
const TiXmlNode *root = node->FirstChild("content");
if (root)
{
const TiXmlElement *item = root->FirstChildElement("item");
if (item)
return new CStaticListProvider(root, parentID);
const TiXmlNode *next = root->NextSibling("content");
if (next)
return new CMultiProvider(root, parentID);

if (!root->NoChildren())
return new CDirectoryProvider(root, parentID);
return CreateSingle(root, parentID);
}
return NULL;
}

IListProvider *IListProvider::CreateSingle(const TiXmlNode *content, int parentID)
{
const TiXmlElement *item = content->FirstChildElement("item");
if (item)
return new CStaticListProvider(content->ToElement(), parentID);

if (!content->NoChildren())
return new CDirectoryProvider(content->ToElement(), parentID);

return NULL;
}
11 changes: 9 additions & 2 deletions xbmc/listproviders/IListProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,18 @@ class IListProvider
virtual ~IListProvider() {}

/*! \brief Factory to create list providers.
\param node a TiXmlNode to create.
\param parent a parent TiXmlNode for the container.
\param parentID id of parent window for context.
\return the list provider, NULL if none.
*/
static IListProvider *Create(const TiXmlNode *node, int parentID);
static IListProvider *Create(const TiXmlNode *parent, int parentID);

/*! \brief Factory to create list providers. Cannot create a multi-provider.
\param content the TiXmlNode for the content to create.
\param parentID id of parent window for context.
\return the list provider, NULL if none.
*/
static IListProvider *CreateSingle(const TiXmlNode *content, int parentID);

/*! \brief Update the list content
\return true if the content has changed, false otherwise.
Expand Down
1 change: 1 addition & 0 deletions xbmc/listproviders/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
SRCS = DirectoryProvider.cpp
SRCS += IListProvider.cpp
SRCS += MultiProvider.cpp
SRCS += StaticProvider.cpp

LIB=listproviders.a
Expand Down
110 changes: 110 additions & 0 deletions xbmc/listproviders/MultiProvider.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* Copyright (C) 2013 Team XBMC
* http://xbmc.org
*
* 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) const
{
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)
{
m_itemMap[item.get()] = 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(bool immediately)
{
if (immediately)
{
CSingleLock lock(m_section);
m_itemMap.clear();
}

for (auto const& provider : m_providers)
provider->Reset(immediately);
}

bool CMultiProvider::OnClick(const CGUIListItemPtr &item)
{
CSingleLock lock(m_section);
auto it = m_itemMap.find(item.get());
if (it != m_itemMap.end())
return it->second->OnClick(item);
else
return false;
}

bool CMultiProvider::OnInfo(const CGUIListItemPtr &item)
{
CSingleLock lock(m_section);
auto it = m_itemMap.find(item.get());
if (it != m_itemMap.end())
return it->second->OnInfo(item);
else
return false;
}

bool CMultiProvider::OnContextMenu(const CGUIListItemPtr &item)
{
CSingleLock lock(m_section);
auto it = m_itemMap.find(item.get());
if (it != m_itemMap.end())
return it->second->OnContextMenu(item);
else
return false;
}
51 changes: 51 additions & 0 deletions xbmc/listproviders/MultiProvider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (C) 2013 Team XBMC
* http://xbmc.org
*
* 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);
virtual void Fetch(std::vector<CGUIListItemPtr> &items) const;
virtual bool IsUpdating() const;
virtual void Reset(bool immediately = false);
virtual bool OnClick(const CGUIListItemPtr &item);
virtual bool OnInfo(const CGUIListItemPtr &item);
virtual bool OnContextMenu(const CGUIListItemPtr &item);

protected:
std::vector<IListProviderPtr> m_providers;
mutable std::map<CGUIListItem*, IListProviderPtr> m_itemMap;
CCriticalSection m_section; // protects m_itemMap
};

0 comments on commit f818b38

Please sign in to comment.