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" // PVR_CHANNEL_INVALID_UID
12 #include "settings/SettingConditions.h"
13 #include "settings/dialogs/GUIDialogSettingsManualBase.h"
14 #include "settings/lib/SettingDependency.h"
15 
16 #include <map>
17 #include <memory>
18 #include <string>
19 #include <vector>
20 
21 class CDateTime;
22 class CSetting;
23 
24 struct IntegerSettingOption;
25 
26 namespace PVR
27 {
28   class CPVRTimerInfoTag;
29   class CPVRTimerType;
30 
31   class CGUIDialogPVRTimerSettings : public CGUIDialogSettingsManualBase
32   {
33   public:
34     CGUIDialogPVRTimerSettings();
35     ~CGUIDialogPVRTimerSettings() override;
36 
37     bool CanBeActivated() const override;
38 
39     void SetTimer(const std::shared_ptr<CPVRTimerInfoTag>& timer);
40 
41   protected:
42     // implementation of ISettingCallback
43     void OnSettingChanged(const std::shared_ptr<const CSetting>& setting) override;
44     void OnSettingAction(const std::shared_ptr<const CSetting>& setting) override;
45 
46     // specialization of CGUIDialogSettingsBase
AllowResettingSettings()47     bool AllowResettingSettings() const override { return false; }
48     bool Save() override;
49     void SetupView() override;
50 
51     // specialization of CGUIDialogSettingsManualBase
52     void InitializeSettings() override;
53 
54   private:
55     bool Validate();
56     void InitializeTypesList();
57     void InitializeChannelsList();
58     void SetButtonLabels();
59 
60     static int GetDateAsIndex(const CDateTime& datetime);
61     static void SetDateFromIndex(CDateTime& datetime, int date);
62     static void SetTimeFromSystemTime(CDateTime& datetime, const KODI::TIME::SystemTime& time);
63 
64     static int GetWeekdaysFromSetting(const std::shared_ptr<const CSetting>& setting);
65 
66     static void TypesFiller(const std::shared_ptr<const CSetting>& setting,
67                             std::vector<IntegerSettingOption>& list,
68                             int& current,
69                             void* data);
70     static void ChannelsFiller(const std::shared_ptr<const CSetting>& setting,
71                                std::vector<IntegerSettingOption>& list,
72                                int& current,
73                                void* data);
74     static void DaysFiller(const std::shared_ptr<const CSetting>& setting,
75                            std::vector<IntegerSettingOption>& list,
76                            int& current,
77                            void* data);
78     static void DupEpisodesFiller(const std::shared_ptr<const CSetting>& setting,
79                                   std::vector<IntegerSettingOption>& list,
80                                   int& current,
81                                   void* data);
82     static void WeekdaysFiller(const std::shared_ptr<const CSetting>& setting,
83                                std::vector<IntegerSettingOption>& list,
84                                int& current,
85                                void* data);
86     static void PrioritiesFiller(const std::shared_ptr<const CSetting>& setting,
87                                  std::vector<IntegerSettingOption>& list,
88                                  int& current,
89                                  void* data);
90     static void LifetimesFiller(const std::shared_ptr<const CSetting>& setting,
91                                 std::vector<IntegerSettingOption>& list,
92                                 int& current,
93                                 void* data);
94     static void MaxRecordingsFiller(const std::shared_ptr<const CSetting>& setting,
95                                     std::vector<IntegerSettingOption>& list,
96                                     int& current,
97                                     void* data);
98     static void RecordingGroupFiller(const std::shared_ptr<const CSetting>& setting,
99                                      std::vector<IntegerSettingOption>& list,
100                                      int& current,
101                                      void* data);
102     static void MarginTimeFiller(const std::shared_ptr<const CSetting>& setting,
103                                  std::vector<IntegerSettingOption>& list,
104                                  int& current,
105                                  void* data);
106 
107     static std::string WeekdaysValueFormatter(const std::shared_ptr<const CSetting>& setting);
108 
109     void AddCondition(const std::shared_ptr<CSetting>& setting,
110                       const std::string& identifier,
111                       SettingConditionCheck condition,
112                       SettingDependencyType depType,
113                       const std::string& settingId);
114 
115     void AddTypeDependentEnableCondition(const std::shared_ptr<CSetting>& setting,
116                                          const std::string& identifier);
117     static bool TypeReadOnlyCondition(const std::string& condition,
118                                       const std::string& value,
119                                       const std::shared_ptr<const CSetting>& setting,
120                                       void* data);
121 
122     void AddTypeDependentVisibilityCondition(const std::shared_ptr<CSetting>& setting,
123                                              const std::string& identifier);
124     static bool TypeSupportsCondition(const std::string& condition,
125                                       const std::string& value,
126                                       const std::shared_ptr<const CSetting>& setting,
127                                       void* data);
128 
129     void AddStartAnytimeDependentVisibilityCondition(const std::shared_ptr<CSetting>& setting,
130                                                      const std::string& identifier);
131     static bool StartAnytimeSetCondition(const std::string& condition,
132                                          const std::string& value,
133                                          const std::shared_ptr<const CSetting>& setting,
134                                          void* data);
135     void AddEndAnytimeDependentVisibilityCondition(const std::shared_ptr<CSetting>& setting,
136                                                    const std::string& identifier);
137     static bool EndAnytimeSetCondition(const std::string& condition,
138                                        const std::string& value,
139                                        const std::shared_ptr<const CSetting>& setting,
140                                        void* data);
141 
142     typedef std::map<int, std::shared_ptr<CPVRTimerType>> TypeEntriesMap;
143 
144     typedef struct ChannelDescriptor
145     {
146       int channelUid;
147       int clientId;
148       std::string description;
149 
150       ChannelDescriptor(int _channelUid = PVR_CHANNEL_INVALID_UID,
151                         int _clientId = -1,
152                         const std::string& _description = "")
channelUidChannelDescriptor153       : channelUid(_channelUid),
154         clientId(_clientId),
155         description(_description)
156       {}
157 
158       inline bool operator ==(const ChannelDescriptor& right) const
159       {
160         return (channelUid == right.channelUid &&
161                 clientId == right.clientId &&
162                 description == right.description);
163       }
164 
165     } ChannelDescriptor;
166 
167     typedef std::map <int, ChannelDescriptor> ChannelEntriesMap;
168 
169     std::shared_ptr<CPVRTimerInfoTag> m_timerInfoTag;
170     TypeEntriesMap m_typeEntries;
171     ChannelEntriesMap m_channelEntries;
172     std::string m_timerStartTimeStr;
173     std::string m_timerEndTimeStr;
174 
175     std::shared_ptr<CPVRTimerType> m_timerType;
176     bool m_bIsRadio = false;
177     bool m_bIsNewTimer = true;
178     bool m_bTimerActive = false;
179     std::string m_strTitle;
180     std::string m_strEpgSearchString;
181     bool m_bFullTextEpgSearch = true;
182     ChannelDescriptor m_channel;
183     CDateTime m_startLocalTime;
184     CDateTime m_endLocalTime;
185     bool m_bStartAnyTime = false;
186     bool m_bEndAnyTime = false;
187     unsigned int m_iWeekdays;
188     CDateTime m_firstDayLocalTime;
189     unsigned int m_iPreventDupEpisodes = 0;
190     unsigned int m_iMarginStart = 0;
191     unsigned int m_iMarginEnd = 0;
192     int m_iPriority = 0;
193     int m_iLifetime = 0;
194     int m_iMaxRecordings = 0;
195     std::string m_strDirectory;
196     unsigned int m_iRecordingGroup = 0;
197   };
198 } // namespace PVR
199