Debian Codegraph @

xbmc/pvr/channels/PVRChannelGroups.h

raw
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
28 /** A container class for channel groups */
29
30 class CPVRChannelGroups : public ISettingCallback
31 {
32 public:
33 /*!
34 * @brief Create a new group container.
35 * @param bRadio True if this is a container for radio channels, false if it is for tv channels.
36 */
37 explicit CPVRChannelGroups(bool bRadio);
38 virtual ~CPVRChannelGroups();
39
40 // ISettingCallback implementation
41 void OnSettingChanged(const std::shared_ptr<const CSetting>& setting) override;
42
43 /*!
44 * @brief Remove all groups from this container.
45 */
46 void Unload();
47
48 /*!
49 * @brief Load all channel groups and all channels from PVR database.
50 * @param clients The PVR clients data should be loaded for. Leave empty for all clients.
51 * @return True on success, false otherwise.
52 */
53 bool LoadFromDatabase(const std::vector<std::shared_ptr<CPVRClient>>& clients);
54
55 /*!
56 * @brief Create a channel group matching the given type.
57 * @param iType The type for the group.
58 * @param path The path of the group.
59 * @return The new group.
60 */
61 std::shared_ptr<CPVRChannelGroup> CreateChannelGroup(int iType, const CPVRChannelsPath& path);
62
63 /*!
64 * @return Amount of groups in this container
65 */
66 size_t Size() const
67 {
68 std::unique_lock<CCriticalSection> lock(m_critSection);
69 return m_groups.size();
70 }
71
72 /*!
73 * @brief Update a group or add it if it's not in here yet.
74 * @param group The group to update.
75 * @param bUpdateFromClient True to save the changes in the db.
76 * @return True if the group was added or update successfully, false otherwise.
77 */
78 bool Update(const std::shared_ptr<CPVRChannelGroup>& group, bool bUpdateFromClient = false);
79
80 /*!
81 * @brief Called by the add-on callback to add a new group
82 * @param group The group to add
83 * @return True when updated, false otherwise
84 */
85 bool UpdateFromClient(const std::shared_ptr<CPVRChannelGroup>& group);
86
87 /*!
88 * @brief Get a channel group member given its path
89 * @param strPath The path to the channel group member
90 * @return The channel group member, or nullptr if not found
91 */
92 std::shared_ptr<CPVRChannelGroupMember> GetChannelGroupMemberByPath(
93 const CPVRChannelsPath& path) const;
94
95 /*!
96 * @brief Get all channel group members that could be added to the given group
97 * @param group The group
98 * @return The channel group members that could be added to the group
99 */
100 std::vector<std::shared_ptr<CPVRChannelGroupMember>> GetMembersAvailableForGroup(
101 const std::shared_ptr<const CPVRChannelGroup>& group);
102
103 /*!
104 * @brief Get a pointer to a channel group given its ID.
105 * @param iGroupId The ID of the group.
106 * @return The group or NULL if it wasn't found.
107 */
108 std::shared_ptr<CPVRChannelGroup> GetById(int iGroupId) const;
109
110 /*!
111 * @brief Get a channel group given its path
112 * @param strPath The path to the channel group
113 * @return The channel group, or nullptr if not found
114 */
115 std::shared_ptr<CPVRChannelGroup> GetGroupByPath(const std::string& strPath) const;
116
117 /*!
118 * @brief Get a group given its name.
119 * @param strName The name.
120 * @param clientID The id of the client of the group to obtain or PVR_GROUP_CLIENT_ID_LOCAL for local groups.
121 * @return The group or NULL if it wasn't found.
122 */
123 std::shared_ptr<CPVRChannelGroup> GetByName(const std::string& strName, int clientID) const;
124
125 /*!
126 * @brief Get the group that contains all channels.
127 * @return The group that contains all channels.
128 */
129 std::shared_ptr<CPVRChannelGroup> GetGroupAll() const;
130
131 /*!
132 * @return The first group in this container, which always is the group with all channels.
133 */
134 std::shared_ptr<CPVRChannelGroup> GetFirstGroup() const { return GetGroupAll(); }
135
136 /*!
137 * @return The last group in this container.
138 */
139 std::shared_ptr<CPVRChannelGroup> GetLastGroup() const;
140
141 /*!
142 * @return The last and previous to last played channel group members. pair.first contains the last, pair.second the previous to last member.
143 */
144 GroupMemberPair GetLastAndPreviousToLastPlayedChannelGroupMember() const;
145
146 /*!
147 * @return The last opened group.
148 */
149 std::shared_ptr<CPVRChannelGroup> GetLastOpenedGroup() const;
150
151 /*!
152 * @brief Get the list of groups.
153 * @param groups The list to store the results in.
154 * @param bExcludeHidden Whenever to exclude hidden channel groups.
155 * @return The amount of items that were added.
156 */
157 std::vector<std::shared_ptr<CPVRChannelGroup>> GetMembers(bool bExcludeHidden = false) const;
158
159 /*!
160 * @brief Get the previous group in this container.
161 * @param group The current group.
162 * @return The previous group or the group containing all channels if it wasn't found.
163 */
164 std::shared_ptr<CPVRChannelGroup> GetPreviousGroup(const CPVRChannelGroup& group) const;
165
166 /*!
167 * @brief Get the next group in this container.
168 * @param group The current group.
169 * @return The next group or the group containing all channels if it wasn't found.
170 */
171 std::shared_ptr<CPVRChannelGroup> GetNextGroup(const CPVRChannelGroup& group) const;
172
173 /*!
174 * @brief Add a group to this container.
175 * @param strName The name of the group.
176 * @return The new group on success, nullptr otherwise.
177 */
178 std::shared_ptr<CPVRChannelGroup> AddGroup(const std::string& strName);
179
180 /*!
181 * @brief Remove a group from this container and delete it from the database.
182 * @param group The group to delete.
183 * @return True if it was deleted successfully, false if not.
184 */
185 bool DeleteGroup(const std::shared_ptr<CPVRChannelGroup>& group);
186
187 /*!
188 * @brief Hide/unhide a group in this container.
189 * @param group The group to hide/unhide.
190 * @param bHide True to hide the group, false to unhide it.
191 * @return True on success, false otherwise.
192 */
193 bool HideGroup(const std::shared_ptr<CPVRChannelGroup>& group, bool bHide);
194
195 /*!
196 * @brief Persist all changes in channel groups.
197 * @return True if everything was persisted, false otherwise.
198 */
199 bool PersistAll();
200
201 /*!
202 * @return True when this container contains radio groups, false otherwise
203 */
204 bool IsRadio() const { return m_bRadio; }
205
206 /*!
207 * @brief Update data with groups and channels from the given clients, sync with local data.
208 * @param clients The clients to fetch data from. Leave empty to fetch data from all created clients.
209 * @param bChannelsOnly Set to true to only update channels, not the groups themselves.
210 * @return True on success, false otherwise.
211 */
212 bool UpdateFromClients(const std::vector<std::shared_ptr<CPVRClient>>& clients,
213 bool bChannelsOnly = false);
214
215 /*!
216 * @brief Update the channel numbers across the channel groups from the all channels group
217 * @return True if any channel number was changed, false otherwise.
218 */
219 bool UpdateChannelNumbersFromAllChannelsGroup();
220
221 /*!
222 * @brief Erase stale texture db entries and image files.
223 * @return number of cleaned up images.
224 */
225 int CleanupCachedImages();
226
227 /*!
228 * @brief Sort the groups.
229 */
230 void SortGroups();
231
232 private:
233 void SortGroupsByBackendOrder();
234 void SortGroupsByLocalOrder();
235
236 /*!
237 * @brief Check, whether data for given pvr clients are currently valid. For instance, data
238 * can be invalid because the client's backend was offline when data was last queried.
239 * @param clients The clients to check. Check all active clients if vector is empty.
240 * @return True, if data is currently valid, false otherwise.
241 */
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<const CPVRChannelGroup>& group) const;
247 int GetGroupClientPriority(const std::shared_ptr<const 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