kodi
IListProvider.h
1 /*
2  * Copyright (C) 2013-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include <memory>
12 #include <vector>
13 
14 class TiXmlNode;
15 class CGUIListItem;
16 
22 {
23 public:
24  explicit IListProvider(int parentID) : m_parentID(parentID) {}
25  explicit IListProvider(const IListProvider& other) = default;
26  virtual ~IListProvider() = default;
27 
33  static std::unique_ptr<IListProvider> Create(const TiXmlNode* parent, int parentID);
34 
40  static std::unique_ptr<IListProvider> CreateSingle(const TiXmlNode* content, int parentID);
41 
44  virtual std::unique_ptr<IListProvider> Clone() = 0;
45 
49  virtual bool Update(bool forceRefresh)=0;
50 
54  virtual void Fetch(std::vector<std::shared_ptr<CGUIListItem>>& items) = 0;
55 
59  virtual bool IsUpdating() const { return false; }
60 
64  virtual void Reset() {}
65 
69  virtual void FreeResources(bool immediately) {}
70 
75  virtual bool OnClick(const std::shared_ptr<CGUIListItem>& item) = 0;
76 
81  virtual bool OnPlay(const std::shared_ptr<CGUIListItem>& item) { return false; }
82 
87  virtual bool OnInfo(const std::shared_ptr<CGUIListItem>& item) = 0;
88 
93  virtual bool OnContextMenu(const std::shared_ptr<CGUIListItem>& item) = 0;
94 
100  virtual void SetDefaultItem(int item, bool always) {}
101 
106  virtual int GetDefaultItem() const { return -1; }
107 
112  virtual bool AlwaysFocusDefaultItem() const { return false; }
113 protected:
114  int m_parentID;
115 };
An interface for providing lists to UI containers.
Definition: IListProvider.h:21
Definition: GUIListItem.h:29
virtual bool IsUpdating() const
Check whether the list provider is updating content.
Definition: IListProvider.h:59
virtual bool AlwaysFocusDefaultItem() const
Whether to always focus the default item.
Definition: IListProvider.h:112
virtual bool OnPlay(const std::shared_ptr< CGUIListItem > &item)
Play event on an item.
Definition: IListProvider.h:81
static std::unique_ptr< IListProvider > Create(const TiXmlNode *parent, int parentID)
Factory to create list providers.
Definition: IListProvider.cpp:16
virtual void Reset()
Reset the current list of items. Derived classes may choose to ignore this.
Definition: IListProvider.h:64
virtual bool OnInfo(const std::shared_ptr< CGUIListItem > &item)=0
Open the info dialog for an item provided by this IListProvider.
virtual std::unique_ptr< IListProvider > Clone()=0
Create an instance of the derived class. Allows for polymorphic copies.
virtual bool OnContextMenu(const std::shared_ptr< CGUIListItem > &item)=0
Open the context menu for an item provided by this IListProvider.
virtual int GetDefaultItem() const
The default item to focus.
Definition: IListProvider.h:106
static std::unique_ptr< IListProvider > CreateSingle(const TiXmlNode *content, int parentID)
Factory to create list providers. Cannot create a multi-provider.
Definition: IListProvider.cpp:30
virtual bool Update(bool forceRefresh)=0
Update the list content.
virtual bool OnClick(const std::shared_ptr< CGUIListItem > &item)=0
Click event on an item.
virtual void FreeResources(bool immediately)
Free all GUI resources allocated by the items.
Definition: IListProvider.h:69
virtual void Fetch(std::vector< std::shared_ptr< CGUIListItem >> &items)=0
Fetch the current list of items.
virtual void SetDefaultItem(int item, bool always)
Set the default item to focus. For backwards compatibility.
Definition: IListProvider.h:100