xbmc
PVRChannel.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 "addons/kodi-dev-kit/include/kodi/c-api/addon-instance/pvr/pvr_channels.h"
12 #include "addons/kodi-dev-kit/include/kodi/c-api/addon-instance/pvr/pvr_providers.h"
13 #include "pvr/PVRCachedImage.h"
14 #include "pvr/channels/PVRChannelNumber.h"
15 #include "threads/CriticalSection.h"
16 #include "utils/ISerializable.h"
17 #include "utils/ISortable.h"
18 
19 #include <memory>
20 #include <string>
21 #include <utility>
22 #include <vector>
23 
24 class CDateTime;
25 
26 namespace PVR
27 {
28 enum class PVREvent;
29 
30 class CPVRProvider;
31 class CPVREpg;
32 class CPVREpgInfoTag;
33 class CPVRRadioRDSInfoTag;
34 
35 class CPVRChannel : public ISerializable, public ISortable
36 {
37  friend class CPVRDatabase;
38 
39 public:
40  static const std::string IMAGE_OWNER_PATTERN;
41 
42  explicit CPVRChannel(bool bRadio);
43  CPVRChannel(bool bRadio, const std::string& iconPath);
44  CPVRChannel(const PVR_CHANNEL& channel, unsigned int iClientId);
45 
46  virtual ~CPVRChannel();
47 
48  bool operator==(const CPVRChannel& right) const;
49  bool operator!=(const CPVRChannel& right) const;
50 
55  void FillAddonData(PVR_CHANNEL& channel) const;
56 
57  void Serialize(CVariant& value) const override;
58 
62 
67  bool QueueDelete();
68 
74  bool UpdateFromClient(const std::shared_ptr<CPVRChannel>& channel);
75 
80  bool Persist();
81 
85  int ChannelID() const;
86 
90  bool IsNew() const;
91 
97  bool SetChannelID(int iDatabaseId);
98 
102  bool IsRadio() const { return m_bIsRadio; }
103 
107  bool IsHidden() const;
108 
118  bool SetHidden(bool bIsHidden, bool bIsUserSetHidden = false);
119 
123  bool IsLocked() const;
124 
133  bool SetLocked(bool bIsLocked);
134 
139  std::shared_ptr<CPVRRadioRDSInfoTag> GetRadioRDSInfoTag() const;
140 
145  void SetRadioRDSInfoTag(const std::shared_ptr<CPVRRadioRDSInfoTag>& tag);
146 
150  bool HasArchive() const;
151 
157  bool SetArchive(bool bHasArchive);
158 
162  std::string ClientIconPath() const;
163 
167  std::string IconPath() const;
168 
172  bool IsUserSetIcon() const;
173 
177  bool IsUserSetName() const;
178 
182  bool IsUserSetHidden() const;
183 
190  bool SetIconPath(const std::string& strIconPath, bool bIsUserSetIcon = false);
191 
195  std::string ChannelName() const;
196 
203  bool SetChannelName(const std::string& strChannelName, bool bIsUserSetName = false);
204 
208  time_t LastWatched() const;
209 
215  bool SetLastWatched(time_t iLastWatched);
216 
221  bool IsChanged() const;
222 
226  void Persisted();
228 
232 
241  int UniqueID() const;
242 
246  int ClientID() const;
247 
253  bool SetClientID(int iClientId);
254 
259  const CPVRChannelNumber& ClientChannelNumber() const;
260 
264  std::string ClientChannelName() const;
265 
276  std::string MimeType() const;
277 
278  // ISortable implementation
279  void ToSortable(SortItem& sortable, Field field) const override;
280 
284  std::pair<int, int> StorageId() const { return std::make_pair(m_iClientId, m_iUniqueId); }
285 
294  bool IsEncrypted() const;
295 
304  int EncryptionSystem() const;
305 
309  std::string EncryptionName() const;
311 
315 
319  int EpgID() const;
320 
325  bool CreateEPG();
326 
331  std::shared_ptr<CPVREpg> GetEPG() const;
332 
337  std::vector<std::shared_ptr<CPVREpgInfoTag>> GetEpgTags() const;
338 
347  std::vector<std::shared_ptr<CPVREpgInfoTag>> GetEPGTimeline(const CDateTime& timelineStart,
348  const CDateTime& timelineEnd,
349  const CDateTime& minEventEnd,
350  const CDateTime& maxEventStart) const;
351 
358  std::shared_ptr<CPVREpgInfoTag> CreateEPGGapTag(const CDateTime& start,
359  const CDateTime& end) const;
360 
369  std::shared_ptr<CPVREpgInfoTag> GetEPGNow() const;
370 
379  std::shared_ptr<CPVREpgInfoTag> GetEPGPrevious() const;
380 
389  std::shared_ptr<CPVREpgInfoTag> GetEPGNext() const;
390 
394  bool EPGEnabled() const;
395 
401  bool SetEPGEnabled(bool bEPGEnabled);
402 
411  std::string EPGScraper() const;
412 
422  bool SetEPGScraper(const std::string& strScraper);
423 
424  bool CanRecord() const;
425 
426  static std::string GetEncryptionName(int iCaid);
427 
432  int ClientOrder() const { return m_iClientOrder; }
433 
438  int ClientProviderUid() const { return m_iClientProviderUid; }
439 
444  void Notify(const PVREvent& event);
445 
449  void Lock() { m_critSection.lock(); }
450 
454  void Unlock() { m_critSection.unlock(); }
455 
461  std::shared_ptr<CPVRProvider> GetDefaultProvider() const;
462 
467  bool HasClientProvider() const;
468 
475  std::shared_ptr<CPVRProvider> GetProvider() const;
476 
478 private:
479  CPVRChannel() = delete;
480  CPVRChannel(const CPVRChannel& tag) = delete;
481  CPVRChannel& operator=(const CPVRChannel& channel) = delete;
482 
486  void UpdateEncryptionName();
487 
491  void ResetEPG();
492 
498  bool SetClientProviderUid(int iClientProviderUid);
499 
503  int m_iChannelId = -1;
504  bool m_bIsRadio = false;
505  bool m_bIsHidden = false;
506  bool m_bIsUserSetName = false;
507  bool m_bIsUserSetIcon = false;
508  bool m_bIsUserSetHidden = false;
509  bool m_bIsLocked = false;
510  CPVRCachedImage m_iconPath;
511  std::string m_strChannelName;
512  time_t m_iLastWatched = 0;
513  bool m_bChanged =
514  false;
515  std::shared_ptr<CPVRRadioRDSInfoTag>
516  m_rdsTag;
517  bool m_bHasArchive = false;
519 
523  int m_iEpgId = -1;
524  bool m_bEPGEnabled = false;
525  std::string m_strEPGScraper =
526  "client";
527  std::shared_ptr<CPVREpg> m_epg;
529 
533  int m_iUniqueId = -1;
534  int m_iClientId = -1;
535  CPVRChannelNumber m_clientChannelNumber;
536  std::string m_strClientChannelName;
537  std::string
538  m_strMimeType;
539  int m_iClientEncryptionSystem =
540  -1;
541  std::string
542  m_strClientEncryptionName;
543  int m_iClientOrder = 0;
544  int m_iClientProviderUid =
545  PVR_PROVIDER_INVALID_UID;
547 
548  mutable CCriticalSection m_critSection;
549 };
550 } // namespace PVR
bool IsChanged() const
Check whether this channel has unpersisted data changes.
Definition: PVRChannel.cpp:738
std::shared_ptr< CPVREpgInfoTag > GetEPGNext() const
Get the EPG tag that will be next active on this channel.
Definition: PVRChannel.cpp:592
int ClientOrder() const
Get the client order for this channel.
Definition: PVRChannel.h:432
bool SetChannelID(int iDatabaseId)
Set the identifier for this channel.
Definition: PVRChannel.cpp:255
std::vector< std::shared_ptr< CPVREpgInfoTag > > GetEpgTags() const
Get the EPG tags for this channel.
Definition: PVRChannel.cpp:540
int EncryptionSystem() const
Return the encryption system ID for this channel. 0 for FTA.
Definition: PVRChannel.cpp:785
bool IsUserSetName() const
Definition: PVRChannel.cpp:714
bool IsLocked() const
Definition: PVRChannel.cpp:690
bool IsHidden() const
Definition: PVRChannel.cpp:684
std::string MimeType() const
The stream input mime type.
Definition: PVRChannel.cpp:773
bool SetEPGScraper(const std::string &strScraper)
Set the name of the scraper to be used for this channel.
Definition: PVRChannel.cpp:637
Definition: PVRChannel.h:35
Definition: PVRCachedImage.h:16
bool IsRadio() const
Definition: PVRChannel.h:102
bool SetHidden(bool bIsHidden, bool bIsUserSetHidden=false)
Set to true to hide this channel. Set to false to unhide it.
Definition: PVRChannel.cpp:273
std::shared_ptr< CPVRProvider > GetProvider() const
Get the provider of this channel. This may be the default provider or a custom provider set by the cl...
Definition: PVRChannel.cpp:834
Definition: ContextMenuManager.h:24
int ClientID() const
Definition: PVRChannel.cpp:755
bool IsNew() const
Definition: PVRChannel.cpp:678
std::string IconPath() const
Definition: PVRChannel.cpp:702
bool CreateEPG()
Create the EPG for this channel, if it does not yet exist.
Definition: PVRChannel.cpp:158
bool SetIconPath(const std::string &strIconPath, bool bIsUserSetIcon=false)
Set the path to the icon for this channel.
Definition: PVRChannel.cpp:343
"C" PVR add-on channel.
Definition: pvr_channels.h:40
std::string ChannelName() const
Definition: PVRChannel.cpp:726
bool IsEncrypted() const
Return true if this channel is encrypted.
Definition: PVRChannel.cpp:779
std::string ClientIconPath() const
Definition: PVRChannel.cpp:696
bool Persist()
Persists the changes in the database.
Definition: PVRChannel.cpp:231
std::shared_ptr< CPVREpgInfoTag > GetEPGPrevious() const
Get the EPG tag that was previously active on this channel.
Definition: PVRChannel.cpp:602
Definition: Variant.h:29
std::string ClientChannelName() const
Definition: PVRChannel.cpp:767
int ChannelID() const
Definition: PVRChannel.cpp:672
std::shared_ptr< CPVREpgInfoTag > CreateEPGGapTag(const CDateTime &start, const CDateTime &end) const
Create a "gap" EPG tag.
Definition: PVRChannel.cpp:571
const CPVRChannelNumber & ClientChannelNumber() const
Definition: PVRChannel.cpp:761
void Unlock()
Unlock the instance. Other threads may get access to this channel again.
Definition: PVRChannel.h:454
std::string EncryptionName() const
Definition: PVRChannel.cpp:791
void Persisted()
reset changed flag after persist
Definition: PVRChannel.cpp:744
std::shared_ptr< CPVREpgInfoTag > GetEPGNow() const
Get the EPG tag that is now active on this channel.
Definition: PVRChannel.cpp:582
Definition: ISerializable.h:13
bool IsUserSetIcon() const
Definition: PVRChannel.cpp:708
void Notify(const PVREvent &event)
CEventStream callback for PVR events.
Definition: PVRChannel.cpp:181
std::vector< std::shared_ptr< CPVREpgInfoTag > > GetEPGTimeline(const CDateTime &timelineStart, const CDateTime &timelineEnd, const CDateTime &minEventEnd, const CDateTime &maxEventStart) const
Get all EPG tags for the given time frame, including "gap" tags.
Definition: PVRChannel.cpp:552
std::shared_ptr< CPVRRadioRDSInfoTag > GetRadioRDSInfoTag() const
Obtain the Radio RDS data for this channel, if available.
Definition: PVRChannel.cpp:311
bool SetChannelName(const std::string &strChannelName, bool bIsUserSetName=false)
Set the name for this channel used by XBMC.
Definition: PVRChannel.cpp:366
DateTime class, which uses FileTime as it&#39;s base.
Definition: XBDateTime.h:63
bool UpdateFromClient(const std::shared_ptr< CPVRChannel > &channel)
Update this channel tag with the data of the given channel tag.
Definition: PVRChannel.cpp:205
bool HasArchive() const
Definition: PVRChannel.cpp:323
Definition: ISortable.h:15
int ClientProviderUid() const
Get the client provider Uid for this channel.
Definition: PVRChannel.h:438
bool SetLocked(bool bIsLocked)
Set to true to lock this channel. Set to false to unlock it.
Definition: PVRChannel.cpp:292
std::pair< int, int > StorageId() const
Definition: PVRChannel.h:284
Definition: PVRDatabase.h:33
void Lock()
Lock the instance. No other thread gets access to this channel until Unlock was called.
Definition: PVRChannel.h:449
std::shared_ptr< CPVRProvider > GetDefaultProvider() const
Get the default provider of this channel. The default provider represents the PVR add-on itself...
Definition: PVRChannel.cpp:822
void SetRadioRDSInfoTag(const std::shared_ptr< CPVRRadioRDSInfoTag > &tag)
Set the Radio RDS data for the channel.
Definition: PVRChannel.cpp:317
std::shared_ptr< CPVREpg > GetEPG() const
Get the EPG table for this channel.
Definition: PVRChannel.cpp:147
Definition: PVRChannelNumber.h:15
void FillAddonData(PVR_CHANNEL &channel) const
Copy over data to the given PVR_CHANNEL instance.
Definition: PVRChannel.cpp:87
bool IsUserSetHidden() const
Definition: PVRChannel.cpp:720
time_t LastWatched() const
Definition: PVRChannel.cpp:732
bool EPGEnabled() const
Definition: PVRChannel.cpp:803
bool SetLastWatched(time_t iLastWatched)
Last time channel has been watched.
Definition: PVRChannel.cpp:399
int EpgID() const
Definition: PVRChannel.cpp:797
int UniqueID() const
A unique identifier for this channel.
Definition: PVRChannel.cpp:750
bool QueueDelete()
Delete this channel from the database.
Definition: PVRChannel.cpp:132
std::string EPGScraper() const
Get the name of the scraper to be used for this channel.
Definition: PVRChannel.cpp:809
bool HasClientProvider() const
Whether or not this channel has a provider set by the client.
Definition: PVRChannel.cpp:828
bool SetArchive(bool bHasArchive)
Set the archive support flag for this channel.
Definition: PVRChannel.cpp:329
bool SetClientID(int iClientId)
Set the identifier of the client that serves this channel.
Definition: PVRChannel.cpp:415
bool SetEPGEnabled(bool bEPGEnabled)
Set to true if an EPG should be used for this channel. Set to false otherwise.
Definition: PVRChannel.cpp:612