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 "threads/CriticalSection.h"
13 
14 #include <memory>
15 #include <mutex>
16 #include <string>
17 #include <vector>
18 
19 namespace PVR
20 {
21  class CPVRChannel;
22  class CPVRClient;
23 
27  {
28  public:
33  explicit CPVRChannelGroups(bool bRadio);
34  virtual ~CPVRChannelGroups();
35 
39  void Unload();
40 
46  bool LoadFromDatabase(const std::vector<std::shared_ptr<CPVRClient>>& clients);
47 
54  std::shared_ptr<CPVRChannelGroup> CreateChannelGroup(int iType, const CPVRChannelsPath& path);
55 
59  size_t Size() const
60  {
61  std::unique_lock<CCriticalSection> lock(m_critSection);
62  return m_groups.size();
63  }
64 
71  bool Update(const std::shared_ptr<CPVRChannelGroup>& group, bool bUpdateFromClient = false);
72 
78  bool UpdateFromClient(const std::shared_ptr<CPVRChannelGroup>& group)
79  {
80  return Update(group, true);
81  }
82 
88  std::shared_ptr<CPVRChannelGroupMember> GetChannelGroupMemberByPath(
89  const CPVRChannelsPath& path) const;
90 
96  std::shared_ptr<CPVRChannelGroup> GetById(int iGroupId) const;
97 
104  std::vector<std::shared_ptr<CPVRChannelGroup>> GetGroupsByChannel(const std::shared_ptr<CPVRChannel>& channel, bool bExcludeHidden = false) const;
105 
111  std::shared_ptr<CPVRChannelGroup> GetGroupByPath(const std::string& strPath) const;
112 
118  std::shared_ptr<CPVRChannelGroup> GetByName(const std::string& strName) const;
119 
124  std::shared_ptr<CPVRChannelGroup> GetGroupAll() const;
125 
129  std::shared_ptr<CPVRChannelGroup> GetFirstGroup() const { return GetGroupAll(); }
130 
134  std::shared_ptr<CPVRChannelGroup> GetLastGroup() const;
135 
139  GroupMemberPair GetLastAndPreviousToLastPlayedChannelGroupMember() const;
140 
144  std::shared_ptr<CPVRChannelGroup> GetLastOpenedGroup() const;
145 
152  std::vector<std::shared_ptr<CPVRChannelGroup>> GetMembers(bool bExcludeHidden = false) const;
153 
159  std::shared_ptr<CPVRChannelGroup> GetPreviousGroup(const CPVRChannelGroup& group) const;
160 
166  std::shared_ptr<CPVRChannelGroup> GetNextGroup(const CPVRChannelGroup& group) const;
167 
173  bool AddGroup(const std::string& strName);
174 
180  bool DeleteGroup(const std::shared_ptr<CPVRChannelGroup>& group);
181 
188  bool HideGroup(const std::shared_ptr<CPVRChannelGroup>& group, bool bHide);
189 
194  bool CreateChannelEpgs();
195 
200  bool PersistAll();
201 
205  bool IsRadio() const { return m_bRadio; }
206 
213  bool UpdateFromClients(const std::vector<std::shared_ptr<CPVRClient>>& clients,
214  bool bChannelsOnly = false);
215 
221 
226  int CleanupCachedImages();
227 
228  private:
229  void SortGroups();
230 
237  bool HasValidDataForClients(const std::vector<std::shared_ptr<CPVRClient>>& clients) const;
238 
239  bool m_bRadio;
240  std::vector<std::shared_ptr<CPVRChannelGroup>> m_groups;
241  mutable CCriticalSection m_critSection;
242  std::vector<int> m_failedClientsForChannelGroups;
243  };
244 }
std::shared_ptr< CPVRChannelGroup > GetFirstGroup() const
Definition: PVRChannelGroups.h:129
bool IsRadio() const
Definition: PVRChannelGroups.h:205
Definition: ContextMenuManager.h:24
bool AddGroup(const std::string &strName)
Add a group to this container.
Definition: PVRChannelGroups.cpp:511
std::shared_ptr< CPVRChannelGroup > GetLastOpenedGroup() const
Definition: PVRChannelGroups.cpp:428
int CleanupCachedImages()
Erase stale texture db entries and image files.
Definition: PVRChannelGroups.cpp:601
std::shared_ptr< CPVRChannelGroup > CreateChannelGroup(int iType, const CPVRChannelsPath &path)
Create a channel group matching the given type.
Definition: PVRChannelGroups.cpp:305
bool LoadFromDatabase(const std::vector< std::shared_ptr< CPVRClient >> &clients)
Load all channel groups and all channels from PVR database.
Definition: PVRChannelGroups.cpp:314
void Unload()
Remove all groups from this container.
Definition: PVRChannelGroups.cpp:50
A container class for channel groups.
Definition: PVRChannelGroups.h:26
Definition: PVRChannelsPath.h:17
bool UpdateChannelNumbersFromAllChannelsGroup()
Update the channel numbers across the channel groups from the all channels group. ...
Definition: PVRChannelGroups.cpp:296
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:201
std::shared_ptr< CPVRChannelGroup > GetById(int iGroupId) const
Get a pointer to a channel group given its ID.
Definition: PVRChannelGroups.cpp:145
std::shared_ptr< CPVRChannelGroup > GetPreviousGroup(const CPVRChannelGroup &group) const
Get the previous group in this container.
Definition: PVRChannelGroups.cpp:453
std::shared_ptr< CPVRChannelGroup > GetLastGroup() const
Definition: PVRChannelGroups.cpp:387
std::shared_ptr< CPVRChannelGroup > GetGroupAll() const
Get the group that contains all channels.
Definition: PVRChannelGroups.cpp:378
Definition: SmartPlayList.cpp:137
size_t Size() const
Definition: PVRChannelGroups.h:59
CPVRChannelGroups(bool bRadio)
Create a new group container.
Definition: PVRChannelGroups.cpp:40
std::vector< std::shared_ptr< CPVRChannelGroup > > GetGroupsByChannel(const std::shared_ptr< CPVRChannel > &channel, bool bExcludeHidden=false) const
Get all groups the given channel is a member.
Definition: PVRChannelGroups.cpp:154
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:60
bool CreateChannelEpgs()
Create EPG tags for all channels of the internal group.
Definition: PVRChannelGroups.cpp:587
bool DeleteGroup(const std::shared_ptr< CPVRChannelGroup > &group)
Remove a group from this container and delete it from the database.
Definition: PVRChannelGroups.cpp:537
std::shared_ptr< CPVRChannelGroup > GetNextGroup(const CPVRChannelGroup &group) const
Get the next group in this container.
Definition: PVRChannelGroups.cpp:482
bool PersistAll()
Persist all changes in channel groups.
Definition: PVRChannelGroups.cpp:368
std::shared_ptr< CPVRChannelGroup > GetGroupByPath(const std::string &strPath) const
Get a channel group given its path.
Definition: PVRChannelGroups.cpp:166
std::shared_ptr< CPVRChannelGroupMember > GetChannelGroupMemberByPath(const CPVRChannelsPath &path) const
Get a channel group member given its path.
Definition: PVRChannelGroups.cpp:131
bool UpdateFromClient(const std::shared_ptr< CPVRChannelGroup > &group)
Called by the add-on callback to add a new group.
Definition: PVRChannelGroups.h:78
GroupMemberPair GetLastAndPreviousToLastPlayedChannelGroupMember() const
Definition: PVRChannelGroups.cpp:396
Definition: PVRChannelGroup.h:46
std::vector< std::shared_ptr< CPVRChannelGroup > > GetMembers(bool bExcludeHidden=false) const
Get the list of groups.
Definition: PVRChannelGroups.cpp:442
std::shared_ptr< CPVRChannelGroup > GetByName(const std::string &strName) const
Get a group given its name.
Definition: PVRChannelGroups.cpp:180
bool HideGroup(const std::shared_ptr< CPVRChannelGroup > &group, bool bHide)
Hide/unhide a group in this container.
Definition: PVRChannelGroups.cpp:571