kodi
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<const 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 
187  int LastWatchedGroupId() const;
188 
195  bool SetIconPath(const std::string& strIconPath, bool bIsUserSetIcon = false);
196 
200  std::string ChannelName() const;
201 
208  bool SetChannelName(const std::string& strChannelName, bool bIsUserSetName = false);
209 
213  time_t LastWatched() const;
214 
221  bool SetLastWatched(time_t lastWatched, int groupId);
222 
227  bool IsChanged() const;
228 
232  void Persisted();
234 
238 
247  int UniqueID() const;
248 
252  int ClientID() const;
253 
259  bool SetClientID(int iClientId);
260 
265  const CPVRChannelNumber& ClientChannelNumber() const;
266 
270  std::string ClientChannelName() const;
271 
282  std::string MimeType() const;
283 
284  // ISortable implementation
285  void ToSortable(SortItem& sortable, Field field) const override;
286 
290  std::pair<int, int> StorageId() const { return std::make_pair(m_iClientId, m_iUniqueId); }
291 
300  bool IsEncrypted() const;
301 
310  int EncryptionSystem() const;
311 
315  std::string EncryptionName() const;
317 
321 
325  int EpgID() const;
326 
331  bool CreateEPG();
332 
337  std::shared_ptr<CPVREpg> GetEPG() const;
338 
343  std::vector<std::shared_ptr<CPVREpgInfoTag>> GetEpgTags() const;
344 
353  std::vector<std::shared_ptr<CPVREpgInfoTag>> GetEPGTimeline(const CDateTime& timelineStart,
354  const CDateTime& timelineEnd,
355  const CDateTime& minEventEnd,
356  const CDateTime& maxEventStart) const;
357 
364  std::shared_ptr<CPVREpgInfoTag> CreateEPGGapTag(const CDateTime& start,
365  const CDateTime& end) const;
366 
375  std::shared_ptr<CPVREpgInfoTag> GetEPGNow() const;
376 
385  std::shared_ptr<CPVREpgInfoTag> GetEPGPrevious() const;
386 
395  std::shared_ptr<CPVREpgInfoTag> GetEPGNext() const;
396 
400  bool EPGEnabled() const;
401 
407  bool SetEPGEnabled(bool bEPGEnabled);
408 
417  std::string EPGScraper() const;
418 
428  bool SetEPGScraper(const std::string& strScraper);
429 
430  bool CanRecord() const;
431 
432  static std::string GetEncryptionName(int iCaid);
433 
438  int ClientOrder() const { return m_iClientOrder; }
439 
444  int ClientProviderUid() const { return m_iClientProviderUid; }
445 
450  void Notify(const PVREvent& event);
451 
455  void Lock() { m_critSection.lock(); }
456 
460  void Unlock() { m_critSection.unlock(); }
461 
467  std::shared_ptr<CPVRProvider> GetDefaultProvider() const;
468 
473  bool HasClientProvider() const;
474 
481  std::shared_ptr<CPVRProvider> GetProvider() const;
482 
484 private:
485  CPVRChannel() = delete;
486  CPVRChannel(const CPVRChannel& tag) = delete;
487  CPVRChannel& operator=(const CPVRChannel& channel) = delete;
488 
492  void UpdateEncryptionName();
493 
497  void ResetEPG();
498 
504  bool SetClientProviderUid(int iClientProviderUid);
505 
509  int m_iChannelId = -1;
510  bool m_bIsRadio = false;
511  bool m_bIsHidden = false;
512  bool m_bIsUserSetName = false;
513  bool m_bIsUserSetIcon = false;
514  bool m_bIsUserSetHidden = false;
515  bool m_bIsLocked = false;
516  CPVRCachedImage m_iconPath;
517  std::string m_strChannelName;
518  time_t m_iLastWatched = 0;
519  bool m_bChanged =
520  false;
521  std::shared_ptr<CPVRRadioRDSInfoTag>
522  m_rdsTag;
523  bool m_bHasArchive = false;
525 
529  int m_iEpgId = -1;
530  bool m_bEPGEnabled = false;
531  std::string m_strEPGScraper =
532  "client";
533  std::shared_ptr<CPVREpg> m_epg;
535 
539  int m_iUniqueId = -1;
540  int m_iClientId = -1;
541  CPVRChannelNumber m_clientChannelNumber;
542  std::string m_strClientChannelName;
543  std::string
544  m_strMimeType;
545  int m_iClientEncryptionSystem =
546  -1;
547  std::string
548  m_strClientEncryptionName;
549  int m_iClientOrder = 0;
550  int m_iClientProviderUid =
551  PVR_PROVIDER_INVALID_UID;
552  int m_lastWatchedGroupId{
553  -1};
555 
556  mutable CCriticalSection m_critSection;
557 };
558 } // namespace PVR
bool IsChanged() const
Check whether this channel has unpersisted data changes.
Definition: PVRChannel.cpp:740
std::shared_ptr< CPVREpgInfoTag > GetEPGNext() const
Get the EPG tag that will be next active on this channel.
Definition: PVRChannel.cpp:588
int ClientOrder() const
Get the client order for this channel.
Definition: PVRChannel.h:438
bool SetChannelID(int iDatabaseId)
Set the identifier for this channel.
Definition: PVRChannel.cpp:258
std::vector< std::shared_ptr< CPVREpgInfoTag > > GetEpgTags() const
Get the EPG tags for this channel.
Definition: PVRChannel.cpp:536
int EncryptionSystem() const
Return the encryption system ID for this channel. 0 for FTA.
Definition: PVRChannel.cpp:787
bool IsUserSetName() const
Definition: PVRChannel.cpp:710
bool IsLocked() const
Definition: PVRChannel.cpp:686
bool IsHidden() const
Definition: PVRChannel.cpp:680
std::string MimeType() const
The stream input mime type.
Definition: PVRChannel.cpp:775
bool SetEPGScraper(const std::string &strScraper)
Set the name of the scraper to be used for this channel.
Definition: PVRChannel.cpp:633
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:276
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:837
Definition: ContextMenuManager.h:24
bool UpdateFromClient(const std::shared_ptr< const CPVRChannel > &channel)
Update this channel tag with the data of the given channel tag.
Definition: PVRChannel.cpp:208
int ClientID() const
Definition: PVRChannel.cpp:757
bool IsNew() const
Definition: PVRChannel.cpp:674
std::string IconPath() const
Definition: PVRChannel.cpp:698
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:346
"C" PVR add-on channel.
Definition: pvr_channels.h:40
std::string ChannelName() const
Definition: PVRChannel.cpp:728
bool IsEncrypted() const
Return true if this channel is encrypted.
Definition: PVRChannel.cpp:781
std::string ClientIconPath() const
Definition: PVRChannel.cpp:692
bool Persist()
Persists the changes in the database.
Definition: PVRChannel.cpp:234
std::shared_ptr< CPVREpgInfoTag > GetEPGPrevious() const
Get the EPG tag that was previously active on this channel.
Definition: PVRChannel.cpp:598
Definition: Variant.h:31
std::string ClientChannelName() const
Definition: PVRChannel.cpp:769
int ChannelID() const
Definition: PVRChannel.cpp:668
int LastWatchedGroupId() const
Definition: PVRChannel.cpp:722
std::shared_ptr< CPVREpgInfoTag > CreateEPGGapTag(const CDateTime &start, const CDateTime &end) const
Create a "gap" EPG tag.
Definition: PVRChannel.cpp:567
const CPVRChannelNumber & ClientChannelNumber() const
Definition: PVRChannel.cpp:763
void Unlock()
Unlock the instance. Other threads may get access to this channel again.
Definition: PVRChannel.h:460
std::string EncryptionName() const
Definition: PVRChannel.cpp:793
void Persisted()
reset changed flag after persist
Definition: PVRChannel.cpp:746
std::shared_ptr< CPVREpgInfoTag > GetEPGNow() const
Get the EPG tag that is now active on this channel.
Definition: PVRChannel.cpp:578
Definition: ISerializable.h:13
bool IsUserSetIcon() const
Definition: PVRChannel.cpp:704
void Notify(const PVREvent &event)
CEventStream callback for PVR events.
Definition: PVRChannel.cpp:184
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:548
std::shared_ptr< CPVRRadioRDSInfoTag > GetRadioRDSInfoTag() const
Obtain the Radio RDS data for this channel, if available.
Definition: PVRChannel.cpp:314
bool SetChannelName(const std::string &strChannelName, bool bIsUserSetName=false)
Set the name for this channel used by XBMC.
Definition: PVRChannel.cpp:369
DateTime class, which uses FileTime as it&#39;s base.
Definition: XBDateTime.h:63
bool HasArchive() const
Definition: PVRChannel.cpp:326
Definition: ISortable.h:15
int ClientProviderUid() const
Get the client provider Uid for this channel.
Definition: PVRChannel.h:444
bool SetLocked(bool bIsLocked)
Set to true to lock this channel. Set to false to unlock it.
Definition: PVRChannel.cpp:295
bool SetLastWatched(time_t lastWatched, int groupId)
Set the last time the channel has been watched and the channel group used to watch.
Definition: PVRChannel.cpp:394
std::pair< int, int > StorageId() const
Definition: PVRChannel.h:290
Definition: PVRDatabase.h:33
void Lock()
Lock the instance. No other thread gets access to this channel until Unlock was called.
Definition: PVRChannel.h:455
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:825
void SetRadioRDSInfoTag(const std::shared_ptr< CPVRRadioRDSInfoTag > &tag)
Set the Radio RDS data for the channel.
Definition: PVRChannel.cpp:320
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:716
time_t LastWatched() const
Definition: PVRChannel.cpp:734
bool EPGEnabled() const
Definition: PVRChannel.cpp:805
int EpgID() const
Definition: PVRChannel.cpp:799
int UniqueID() const
A unique identifier for this channel.
Definition: PVRChannel.cpp:752
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:811
bool HasClientProvider() const
Whether or not this channel has a provider set by the client.
Definition: PVRChannel.cpp:831
bool SetArchive(bool bHasArchive)
Set the archive support flag for this channel.
Definition: PVRChannel.cpp:332
bool SetClientID(int iClientId)
Set the identifier of the client that serves this channel.
Definition: PVRChannel.cpp:411
bool SetEPGEnabled(bool bEPGEnabled)
Set to true if an EPG should be used for this channel. Set to false otherwise.
Definition: PVRChannel.cpp:608