kodi
PVRTimerInfoTag.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 "XBDateTime.h"
12 #include "pvr/timers/PVRTimerType.h"
13 #include "threads/CriticalSection.h"
14 #include "utils/ISerializable.h"
15 
16 #include <memory>
17 #include <string>
18 
19 struct PVR_TIMER;
20 
21 namespace PVR
22 {
23 class CPVRChannel;
24 class CPVREpgInfoTag;
25 
26 enum class TimerOperationResult
27 {
28  OK = 0,
29  FAILED,
30  RECORDING // The timer was not deleted because it is currently recording (see DeleteTimer).
31 };
32 
33 class CPVRTimerInfoTag final : public ISerializable
34 {
35  // allow these classes direct access to members as they act as timer tag instance factories.
36  friend class CGUIDialogPVRTimerSettings;
37  friend class CPVRDatabase;
38 
39 public:
40  explicit CPVRTimerInfoTag(bool bRadio = false);
41  CPVRTimerInfoTag(const PVR_TIMER& timer,
42  const std::shared_ptr<CPVRChannel>& channel,
43  unsigned int iClientId);
44 
45  bool operator==(const CPVRTimerInfoTag& right) const;
46  bool operator!=(const CPVRTimerInfoTag& right) const;
47 
52  void FillAddonData(PVR_TIMER& timer) const;
53 
54  // ISerializable implementation
55  void Serialize(CVariant& value) const override;
56 
57  static constexpr int DEFAULT_PVRRECORD_INSTANTRECORDTIME = -1;
58 
66  static std::shared_ptr<CPVRTimerInfoTag> CreateInstantTimerTag(
67  const std::shared_ptr<CPVRChannel>& channel,
68  int iDuration = DEFAULT_PVRRECORD_INSTANTRECORDTIME);
69 
77  static std::shared_ptr<CPVRTimerInfoTag> CreateTimerTag(
78  const std::shared_ptr<CPVRChannel>& channel, const CDateTime& start, int iDuration);
79 
89  static std::shared_ptr<CPVRTimerInfoTag> CreateFromEpg(const std::shared_ptr<CPVREpgInfoTag>& tag,
90  bool bCreateRule,
91  bool bCreateReminder,
92  bool bReadOnly = false);
93 
100  static std::shared_ptr<CPVRTimerInfoTag> CreateFromEpg(const std::shared_ptr<CPVREpgInfoTag>& tag,
101  bool bCreateRule = false);
102 
110  static std::shared_ptr<CPVRTimerInfoTag> CreateReminderFromDate(
111  const CDateTime& start,
112  int iDuration,
113  const std::shared_ptr<CPVRTimerInfoTag>& parent = std::shared_ptr<CPVRTimerInfoTag>());
114 
121  static std::shared_ptr<CPVRTimerInfoTag> CreateReminderFromEpg(
122  const std::shared_ptr<CPVREpgInfoTag>& tag,
123  const std::shared_ptr<CPVRTimerInfoTag>& parent = std::shared_ptr<CPVRTimerInfoTag>());
124 
129  void SetEpgInfoTag(const std::shared_ptr<CPVREpgInfoTag>& tag);
130 
136  std::shared_ptr<CPVREpgInfoTag> GetEpgInfoTag(bool bCreate = true) const;
137 
143  bool UpdateEntry(const std::shared_ptr<const CPVRTimerInfoTag>& tag);
144 
151  bool UpdateChildState(const std::shared_ptr<const CPVRTimerInfoTag>& childTimer, bool bAdd);
152 
156  void ResetChildState();
157 
162  bool IsActive() const
163  {
164  return m_state == PVR_TIMER_STATE_SCHEDULED || m_state == PVR_TIMER_STATE_RECORDING ||
166  m_state == PVR_TIMER_STATE_ERROR;
167  }
168 
174  bool IsBroken() const
175  {
176  return m_state == PVR_TIMER_STATE_CONFLICT_NOK || m_state == PVR_TIMER_STATE_ERROR;
177  }
178 
184  bool HasConflict() const { return m_state == PVR_TIMER_STATE_CONFLICT_NOK; }
185 
190  bool IsRecording() const { return m_state == PVR_TIMER_STATE_RECORDING; }
191 
196  bool IsDisabled() const { return m_state == PVR_TIMER_STATE_DISABLED; }
197 
202  const std::shared_ptr<CPVRTimerType> GetTimerType() const { return m_timerType; }
203 
208  void SetTimerType(const std::shared_ptr<CPVRTimerType>& type);
209 
214  bool IsTimerRule() const { return m_timerType && m_timerType->IsTimerRule(); }
215 
220  bool IsReminder() const { return m_timerType && m_timerType->IsReminder(); }
221 
226  bool IsManual() const { return m_timerType && m_timerType->IsManual(); }
227 
232  bool IsEpgBased() const { return !IsManual(); }
233 
238  int ClientID() const { return m_iClientId; }
239 
244  bool IsOwnedByClient() const;
245 
250  bool IsRadio() const { return m_bIsRadio; }
251 
256  const std::string& Path() const;
257 
263  int ClientIndex() const { return m_iClientIndex; }
264 
270  int ParentClientIndex() const { return m_iParentClientIndex; }
271 
276  bool HasParent() const { return m_iParentClientIndex != PVR_TIMER_NO_PARENT; }
277 
282  unsigned int TimerID() const { return m_iTimerId; }
283 
288  void SetTimerID(unsigned int id) { m_iTimerId = id; }
289 
294  int ClientChannelUID() const { return m_iClientChannelUid; }
295 
300  PVR_TIMER_STATE State() const { return m_state; }
301 
306  void SetState(PVR_TIMER_STATE state) { m_state = state; }
307 
312  const std::string& Title() const;
313 
318  bool HasChannel() const;
319 
324  std::shared_ptr<CPVRChannel> Channel() const;
325 
330  void UpdateChannel();
331 
336  std::string ChannelName() const;
337 
342  std::string ChannelIcon() const;
343 
348  CDateTime StartAsUTC() const;
349 
354  CDateTime StartAsLocalTime() const;
355 
360  void SetStartFromUTC(const CDateTime& start);
361 
366  void SetStartFromLocalTime(const CDateTime& start);
367 
372  CDateTime EndAsUTC() const;
373 
378  CDateTime EndAsLocalTime() const;
379 
384  void SetEndFromUTC(const CDateTime& end);
385 
390  void SetEndFromLocalTime(const CDateTime& end);
391 
396  CDateTime FirstDayAsUTC() const;
397 
402  CDateTime FirstDayAsLocalTime() const;
403 
408  void SetFirstDayFromUTC(const CDateTime& firstDay);
409 
414  void SetFirstDayFromLocalTime(const CDateTime& firstDay);
415 
421  static CDateTime ConvertUTCToLocalTime(const CDateTime& utc);
422 
428  static CDateTime ConvertLocalTimeToUTC(const CDateTime& local);
429 
434  int GetDuration() const;
435 
440  unsigned int MarginStart() const { return m_iMarginStart; }
441 
446  unsigned int MarginEnd() const { return m_iMarginEnd; }
447 
452  unsigned int WeekDays() const { return m_iWeekdays; }
453 
458  bool IsStartAnyTime() const { return m_bStartAnyTime; }
459 
464  bool IsEndAnyTime() const { return m_bEndAnyTime; }
465 
472  bool IsFullTextEpgSearch() const { return m_bFullTextEpgSearch; }
473 
479  const std::string& EpgSearchString() const { return m_strEpgSearchString; }
480 
485  const std::string& SeriesLink() const;
486 
491  unsigned int UniqueBroadcastID() const { return m_iEpgUid; }
492 
497  bool AddToClient() const;
498 
505  TimerOperationResult DeleteFromClient(bool bForce = false) const;
506 
512  bool UpdateOnClient();
513 
518  bool Persist();
519 
524  bool DeleteFromDatabase();
525 
530  std::string GetNotificationText() const;
531 
536  std::string GetDeletedNotificationText() const;
537 
543  const std::string& Summary() const;
544 
548  void UpdateSummary();
549 
555  std::string GetStatus(bool bRadio) const;
556 
561  std::string GetTypeAsString() const;
562 
570  static std::string GetWeekdaysString(unsigned int iWeekdays,
571  bool bEpgBased,
572  bool bLongMultiDaysFormat);
573 
574 private:
575  CPVRTimerInfoTag(const CPVRTimerInfoTag& tag) = delete;
576  CPVRTimerInfoTag& operator=(const CPVRTimerInfoTag& orig) = delete;
577 
578  std::string GetWeekdaysString() const;
579  void UpdateEpgInfoTag();
580 
581  static std::shared_ptr<CPVRTimerInfoTag> CreateFromDate(
582  const std::shared_ptr<CPVRChannel>& channel,
583  const CDateTime& start,
584  int iDuration,
585  bool bCreateReminder,
586  bool bReadOnly);
587 
588  mutable CCriticalSection m_critSection;
589 
590  std::string m_strTitle;
591  std::string
592  m_strEpgSearchString;
593  bool m_bFullTextEpgSearch =
594  false;
595  std::string m_strDirectory;
596  std::string m_strSummary;
598  int m_iClientId;
599  int m_iClientIndex;
600  int m_iParentClientIndex;
601  int m_iClientChannelUid;
602  bool m_bStartAnyTime =
603  false;
604  bool m_bEndAnyTime = false;
605  int m_iPriority;
606  int m_iLifetime;
607  int m_iMaxRecordings =
608  0;
609  unsigned int m_iWeekdays;
610  unsigned int
611  m_iPreventDupEpisodes;
612  unsigned int m_iRecordingGroup =
613  0;
614  std::string m_strFileNameAndPath;
615  bool m_bIsRadio;
616  unsigned int m_iTimerId = 0;
617  unsigned int
618  m_iMarginStart;
619  unsigned int
620  m_iMarginEnd;
621  mutable unsigned int
622  m_iEpgUid;
623  std::string m_strSeriesLink;
625  CDateTime m_StartTime;
626  CDateTime m_StopTime;
627  CDateTime m_FirstDay;
628  std::shared_ptr<CPVRTimerType> m_timerType;
630  unsigned int m_iTVChildTimersActive = 0;
631  unsigned int m_iTVChildTimersConflictNOK = 0;
632  unsigned int m_iTVChildTimersRecording = 0;
633  unsigned int m_iTVChildTimersErrors = 0;
634  unsigned int m_iRadioChildTimersActive = 0;
635  unsigned int m_iRadioChildTimersConflictNOK = 0;
636  unsigned int m_iRadioChildTimersRecording = 0;
637  unsigned int m_iRadioChildTimersErrors = 0;
638 
639  mutable std::shared_ptr<CPVREpgInfoTag> m_epgTag;
640  mutable std::shared_ptr<CPVRChannel> m_channel;
641 
642  mutable bool m_bProbedEpgTag = false;
643 };
644 } // namespace PVR
6 : The scheduled timer conflicts with another one, but will be recorded.
Definition: pvr_timers.h:315
bool IsManual() const
Checks whether this is a manual (vs. epg-based) timer.
Definition: PVRTimerInfoTag.h:226
Definition: GUIDialogPVRTimerSettings.h:31
int ClientChannelUID() const
The UID of the channel for this timer.
Definition: PVRTimerInfoTag.h:294
bool IsBroken() const
Whether this timer is broken.
Definition: PVRTimerInfoTag.h:174
bool IsReminder() const
Checks whether this is a reminder timer (vs. recording timer).
Definition: PVRTimerInfoTag.h:220
void SetTimerID(unsigned int id)
Set the local ID for this timer.
Definition: PVRTimerInfoTag.h:288
int ClientID() const
The ID of the client for this timer.
Definition: PVRTimerInfoTag.h:238
#define PVR_TIMER_NO_PARENT
Special kodi::addon::PVRTimer::SetParentClientIndex() value to indicate that a timer has no parent...
Definition: pvr_timers.h:55
Definition: ContextMenuManager.h:24
bool IsTimerRule() const
Checks whether this is a timer rule (vs. one time timer).
Definition: PVRTimerInfoTag.h:214
bool IsDisabled() const
Whether this timer is disabled, for example by the user.
Definition: PVRTimerInfoTag.h:196
bool IsActive() const
Whether this timer is active.
Definition: PVRTimerInfoTag.h:162
PVR_TIMER_STATE State() const
The state for this timer.
Definition: PVRTimerInfoTag.h:300
bool IsRadio() const
Whether this timer is for Radio or TV.
Definition: PVRTimerInfoTag.h:250
bool IsEpgBased() const
Checks whether this is an epg-based (vs. manual) timer.
Definition: PVRTimerInfoTag.h:232
Definition: Variant.h:31
unsigned int MarginEnd() const
Get time in minutes to end the recording after the end time of the programme.
Definition: PVRTimerInfoTag.h:446
unsigned int TimerID() const
The local ID for this timer, as given by Kodi.
Definition: PVRTimerInfoTag.h:282
bool HasConflict() const
Whether this timer has a conflict.
Definition: PVRTimerInfoTag.h:184
1 : The timer is scheduled for recording.
Definition: pvr_timers.h:299
9 : The timer was disabled by the user, can be enabled via setting the state to PVR_TIMER_STATE_SCHED...
Definition: pvr_timers.h:326
unsigned int WeekDays() const
For timer rules, the days of week this timer rule is scheduled for.
Definition: PVRTimerInfoTag.h:452
unsigned int UniqueBroadcastID() const
Get the UID of the epg event associated with this timer tag, if any.
Definition: PVRTimerInfoTag.h:491
int ClientIndex() const
The index for this timer, as given by the client.
Definition: PVRTimerInfoTag.h:263
bool IsStartAnyTime() const
For timer rules, whether start time is "any time", not a particular time.
Definition: PVRTimerInfoTag.h:458
Definition: ISerializable.h:13
void SetState(PVR_TIMER_STATE state)
Set the state for this timer.
Definition: PVRTimerInfoTag.h:306
Definition: PVRTimerInfoTag.h:33
int ParentClientIndex() const
The index for the parent of this timer, as given by the client. Timers scheduled by a timer rule will...
Definition: PVRTimerInfoTag.h:270
8 : The timer is scheduled, but can&#39;t be recorded for some reason.
Definition: pvr_timers.h:322
2 : The timer is currently recordings.
Definition: pvr_timers.h:302
DateTime class, which uses FileTime as it&#39;s base.
Definition: XBDateTime.h:63
PVR_TIMER_STATE
Definition: pvr_timers.h:291
const std::string & EpgSearchString() const
For timer rules, the epg data match string for searches. Format is backend-dependent, for example regexp.
Definition: PVRTimerInfoTag.h:479
unsigned int MarginStart() const
Get time in minutes to start the recording before the start time of the programme.
Definition: PVRTimerInfoTag.h:440
const std::shared_ptr< CPVRTimerType > GetTimerType() const
Gets the type of this timer.
Definition: PVRTimerInfoTag.h:202
"C" PVR add-on timer event.
Definition: pvr_timers.h:339
bool IsRecording() const
Whether this timer is currently recording.
Definition: PVRTimerInfoTag.h:190
Definition: PVRDatabase.h:33
bool IsEndAnyTime() const
For timer rules, whether end time is "any time", not a particular time.
Definition: PVRTimerInfoTag.h:464
bool IsFullTextEpgSearch() const
For timer rules, whether only the EPG programme title shall be searched or also other data like the p...
Definition: PVRTimerInfoTag.h:472
7 : The scheduled timer conflicts with another one and won&#39;t be recorded.
Definition: pvr_timers.h:319
bool HasParent() const
Whether this timer has a parent.
Definition: PVRTimerInfoTag.h:276