xbmc
PVRChannelGroups.h
1 /*
2  * Copyright (C) 2012-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 "pvr/channels/PVRChannelGroup.h"
12 #include "pvr/settings/PVRSettings.h"
13 #include "settings/lib/ISettingCallback.h"
14 #include "threads/CriticalSection.h"
15 
16 #include <memory>
17 #include <mutex>
18 #include <string>
19 #include <vector>
20 
21 namespace PVR
22 {
23 enum class PVREvent;
24 
25 class CPVRChannel;
26 class CPVRClient;
27 
31 {
32 public:
37  explicit CPVRChannelGroups(bool bRadio);
38  virtual ~CPVRChannelGroups();
39 
40  // ISettingCallback implementation
41  void OnSettingChanged(const std::shared_ptr<const CSetting>& setting) override;
42 
46  void Unload();
47 
53  bool LoadFromDatabase(const std::vector<std::shared_ptr<CPVRClient>>& clients);
54 
61  std::shared_ptr<CPVRChannelGroup> CreateChannelGroup(int iType, const CPVRChannelsPath& path);
62 
66  size_t Size() const
67  {
68  std::unique_lock<CCriticalSection> lock(m_critSection);
69  return m_groups.size();
70  }
71 
78  bool Update(const std::shared_ptr<CPVRChannelGroup>& group, bool bUpdateFromClient = false);
79 
85  bool UpdateFromClient(const std::shared_ptr<CPVRChannelGroup>& group);
86 
92  std::shared_ptr<CPVRChannelGroupMember> GetChannelGroupMemberByPath(
93  const CPVRChannelsPath& path) const;
94 
100  std::vector<std::shared_ptr<CPVRChannelGroupMember>> GetMembersAvailableForGroup(
101  const std::shared_ptr<CPVRChannelGroup>& group);
102 
108  std::shared_ptr<CPVRChannelGroup> GetById(int iGroupId) const;
109 
115  std::shared_ptr<CPVRChannelGroup> GetGroupByPath(const std::string& strPath) const;
116 
123  std::shared_ptr<CPVRChannelGroup> GetByName(const std::string& strName, int clientID) const;
124 
129  std::shared_ptr<CPVRChannelGroup> GetGroupAll() const;
130 
134  std::shared_ptr<CPVRChannelGroup> GetFirstGroup() const { return GetGroupAll(); }
135 
139  std::shared_ptr<CPVRChannelGroup> GetLastGroup() const;
140 
144  GroupMemberPair GetLastAndPreviousToLastPlayedChannelGroupMember() const;
145 
149  std::shared_ptr<CPVRChannelGroup> GetLastOpenedGroup() const;
150 
157  std::vector<std::shared_ptr<CPVRChannelGroup>> GetMembers(bool bExcludeHidden = false) const;
158 
164  std::shared_ptr<CPVRChannelGroup> GetPreviousGroup(const CPVRChannelGroup& group) const;
165 
171  std::shared_ptr<CPVRChannelGroup> GetNextGroup(const CPVRChannelGroup& group) const;
172 
178  std::shared_ptr<CPVRChannelGroup> AddGroup(const std::string& strName);
179 
185  bool DeleteGroup(const std::shared_ptr<CPVRChannelGroup>& group);
186 
193  bool HideGroup(const std::shared_ptr<CPVRChannelGroup>& group, bool bHide);
194 
199  bool PersistAll();
200 
204  bool IsRadio() const { return m_bRadio; }
205 
212  bool UpdateFromClients(const std::vector<std::shared_ptr<CPVRClient>>& clients,
213  bool bChannelsOnly = false);
214 
220 
225  int CleanupCachedImages();
226 
230  void SortGroups();
231 
232 private:
233  void SortGroupsByBackendOrder();
234  void SortGroupsByLocalOrder();
235 
242  bool HasValidDataForClients(const std::vector<std::shared_ptr<CPVRClient>>& clients) const;
243 
244  void OnPVRManagerEvent(const PVR::PVREvent& event);
245 
246  int GetGroupTypePriority(const std::shared_ptr<CPVRChannelGroup>& group) const;
247  int GetGroupClientPriority(const std::shared_ptr<CPVRChannelGroup>& group) const;
248 
249  bool m_bRadio{false};
250  std::vector<std::shared_ptr<CPVRChannelGroup>> m_groups;
251  mutable CCriticalSection m_critSection;
252  std::vector<int> m_failedClientsForChannelGroups;
253  bool m_isSubscribed{false};
254  CPVRSettings m_settings;
255  std::shared_ptr<CPVRChannelGroup> m_allChannelsGroup;
256 };
257 } // namespace PVR
bool UpdateFromClient(const std::shared_ptr< CPVRChannelGroup > &group)
Called by the add-on callback to add a new group.
Definition: PVRChannelGroups.cpp:85
std::shared_ptr< CPVRChannelGroup > GetFirstGroup() const
Definition: PVRChannelGroups.h:134
bool IsRadio() const
Definition: PVRChannelGroups.h:204
Definition: ContextMenuManager.h:24
std::shared_ptr< CPVRChannelGroup > GetLastOpenedGroup() const
Definition: PVRChannelGroups.cpp:510
Definition: ISettingCallback.h:16
int CleanupCachedImages()
Erase stale texture db entries and image files.
Definition: PVRChannelGroups.cpp:681
std::shared_ptr< CPVRChannelGroup > CreateChannelGroup(int iType, const CPVRChannelsPath &path)
Create a channel group matching the given type.
Definition: PVRChannelGroups.cpp:377
bool LoadFromDatabase(const std::vector< std::shared_ptr< CPVRClient >> &clients)
Load all channel groups and all channels from PVR database.
Definition: PVRChannelGroups.cpp:388
void Unload()
Remove all groups from this container.
Definition: PVRChannelGroups.cpp:71
A container class for channel groups.
Definition: PVRChannelGroups.h:30
Definition: PVRChannelsPath.h:17
bool UpdateChannelNumbersFromAllChannelsGroup()
Update the channel numbers across the channel groups from the all channels group. ...
Definition: PVRChannelGroups.cpp:368
bool UpdateFromClients(const std::vector< std::shared_ptr< CPVRClient >> &clients, bool bChannelsOnly=false)
Update data with groups and channels from the given clients, sync with local data.
Definition: PVRChannelGroups.cpp:317
std::shared_ptr< CPVRChannelGroup > GetById(int iGroupId) const
Get a pointer to a channel group given its ID.
Definition: PVRChannelGroups.cpp:270
std::shared_ptr< CPVRChannelGroup > AddGroup(const std::string &strName)
Add a group to this container.
Definition: PVRChannelGroups.cpp:601
std::shared_ptr< CPVRChannelGroup > GetPreviousGroup(const CPVRChannelGroup &group) const
Get the previous group in this container.
Definition: PVRChannelGroups.cpp:535
std::shared_ptr< CPVRChannelGroup > GetLastGroup() const
Definition: PVRChannelGroups.cpp:469
std::shared_ptr< CPVRChannelGroup > GetGroupAll() const
Get the group that contains all channels.
Definition: PVRChannelGroups.cpp:463
std::vector< std::shared_ptr< CPVRChannelGroupMember > > GetMembersAvailableForGroup(const std::shared_ptr< CPVRChannelGroup > &group)
Get all channel group members that could be added to the given group.
Definition: PVRChannelGroups.cpp:250
Definition: SmartPlayList.cpp:137
std::shared_ptr< CPVRChannelGroup > GetByName(const std::string &strName, int clientID) const
Get a group given its name.
Definition: PVRChannelGroups.cpp:294
size_t Size() const
Definition: PVRChannelGroups.h:66
CPVRChannelGroups(bool bRadio)
Create a new group container.
Definition: PVRChannelGroups.cpp:43
bool Update(const std::shared_ptr< CPVRChannelGroup > &group, bool bUpdateFromClient=false)
Update a group or add it if it&#39;s not in here yet.
Definition: PVRChannelGroups.cpp:97
bool DeleteGroup(const std::shared_ptr< CPVRChannelGroup > &group)
Remove a group from this container and delete it from the database.
Definition: PVRChannelGroups.cpp:632
std::shared_ptr< CPVRChannelGroup > GetNextGroup(const CPVRChannelGroup &group) const
Get the next group in this container.
Definition: PVRChannelGroups.cpp:569
bool PersistAll()
Persist all changes in channel groups.
Definition: PVRChannelGroups.cpp:453
void SortGroups()
Sort the groups.
Definition: PVRChannelGroups.cpp:222
std::shared_ptr< CPVRChannelGroup > GetGroupByPath(const std::string &strPath) const
Get a channel group given its path.
Definition: PVRChannelGroups.cpp:279
std::shared_ptr< CPVRChannelGroupMember > GetChannelGroupMemberByPath(const CPVRChannelsPath &path) const
Get a channel group member given its path.
Definition: PVRChannelGroups.cpp:235
GroupMemberPair GetLastAndPreviousToLastPlayedChannelGroupMember() const
Definition: PVRChannelGroups.cpp:478
Definition: PVRChannelGroup.h:52
std::vector< std::shared_ptr< CPVRChannelGroup > > GetMembers(bool bExcludeHidden=false) const
Get the list of groups.
Definition: PVRChannelGroups.cpp:523
Definition: PVRSettings.h:27
bool HideGroup(const std::shared_ptr< CPVRChannelGroup > &group, bool bHide)
Hide/unhide a group in this container.
Definition: PVRChannelGroups.cpp:665
void OnSettingChanged(const std::shared_ptr< const CSetting > &setting) override
The value of the given setting has changed.
Definition: PVRChannelGroups.cpp:55