summaryrefslogtreecommitdiffstats
path: root/xbmc/pvr/dialogs/GUIDialogPVRTimerSettings.h
blob: d3e9e3eadf34451a65620ede95743f35c9382d9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*
 *  Copyright (C) 2012-2018 Team Kodi
 *  This file is part of Kodi - https://kodi.tv
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */

#pragma once

#include "XBDateTime.h"
#include "addons/kodi-dev-kit/include/kodi/c-api/addon-instance/pvr/pvr_channels.h" // PVR_CHANNEL_INVALID_UID
#include "settings/SettingConditions.h"
#include "settings/dialogs/GUIDialogSettingsManualBase.h"
#include "settings/lib/SettingDependency.h"

#include <map>
#include <memory>
#include <string>
#include <vector>

class CSetting;

struct IntegerSettingOption;

namespace PVR
{
class CPVRTimerInfoTag;
class CPVRTimerType;

class CGUIDialogPVRTimerSettings : public CGUIDialogSettingsManualBase
{
public:
  CGUIDialogPVRTimerSettings();
  ~CGUIDialogPVRTimerSettings() override;

  bool CanBeActivated() const override;

  void SetTimer(const std::shared_ptr<CPVRTimerInfoTag>& timer);

protected:
  // implementation of ISettingCallback
  void OnSettingChanged(const std::shared_ptr<const CSetting>& setting) override;
  void OnSettingAction(const std::shared_ptr<const CSetting>& setting) override;

  // specialization of CGUIDialogSettingsBase
  bool AllowResettingSettings() const override { return false; }
  bool Save() override;
  void SetupView() override;

  // specialization of CGUIDialogSettingsManualBase
  void InitializeSettings() override;

private:
  bool Validate();
  void InitializeTypesList();
  void InitializeChannelsList();
  void SetButtonLabels();

  static int GetDateAsIndex(const CDateTime& datetime);
  static void SetDateFromIndex(CDateTime& datetime, int date);
  static void SetTimeFromSystemTime(CDateTime& datetime, const KODI::TIME::SystemTime& time);

  static int GetWeekdaysFromSetting(const std::shared_ptr<const CSetting>& setting);

  static void TypesFiller(const std::shared_ptr<const CSetting>& setting,
                          std::vector<IntegerSettingOption>& list,
                          int& current,
                          void* data);
  static void ChannelsFiller(const std::shared_ptr<const CSetting>& setting,
                             std::vector<IntegerSettingOption>& list,
                             int& current,
                             void* data);
  static void DaysFiller(const std::shared_ptr<const CSetting>& setting,
                         std::vector<IntegerSettingOption>& list,
                         int& current,
                         void* data);
  static void DupEpisodesFiller(const std::shared_ptr<const CSetting>& setting,
                                std::vector<IntegerSettingOption>& list,
                                int& current,
                                void* data);
  static void WeekdaysFiller(const std::shared_ptr<const CSetting>& setting,
                             std::vector<IntegerSettingOption>& list,
                             int& current,
                             void* data);
  static void PrioritiesFiller(const std::shared_ptr<const CSetting>& setting,
                               std::vector<IntegerSettingOption>& list,
                               int& current,
                               void* data);
  static void LifetimesFiller(const std::shared_ptr<const CSetting>& setting,
                              std::vector<IntegerSettingOption>& list,
                              int& current,
                              void* data);
  static void MaxRecordingsFiller(const std::shared_ptr<const CSetting>& setting,
                                  std::vector<IntegerSettingOption>& list,
                                  int& current,
                                  void* data);
  static void RecordingGroupFiller(const std::shared_ptr<const CSetting>& setting,
                                   std::vector<IntegerSettingOption>& list,
                                   int& current,
                                   void* data);
  static void MarginTimeFiller(const std::shared_ptr<const CSetting>& setting,
                               std::vector<IntegerSettingOption>& list,
                               int& current,
                               void* data);

  static std::string WeekdaysValueFormatter(const std::shared_ptr<const CSetting>& setting);

  void AddCondition(const std::shared_ptr<CSetting>& setting,
                    const std::string& identifier,
                    SettingConditionCheck condition,
                    SettingDependencyType depType,
                    const std::string& settingId);

  void AddTypeDependentEnableCondition(const std::shared_ptr<CSetting>& setting,
                                       const std::string& identifier);
  static bool TypeReadOnlyCondition(const std::string& condition,
                                    const std::string& value,
                                    const std::shared_ptr<const CSetting>& setting,
                                    void* data);

  void AddTypeDependentVisibilityCondition(const std::shared_ptr<CSetting>& setting,
                                           const std::string& identifier);
  static bool TypeSupportsCondition(const std::string& condition,
                                    const std::string& value,
                                    const std::shared_ptr<const CSetting>& setting,
                                    void* data);

  void AddStartAnytimeDependentVisibilityCondition(const std::shared_ptr<CSetting>& setting,
                                                   const std::string& identifier);
  static bool StartAnytimeSetCondition(const std::string& condition,
                                       const std::string& value,
                                       const std::shared_ptr<const CSetting>& setting,
                                       void* data);
  void AddEndAnytimeDependentVisibilityCondition(const std::shared_ptr<CSetting>& setting,
                                                 const std::string& identifier);
  static bool EndAnytimeSetCondition(const std::string& condition,
                                     const std::string& value,
                                     const std::shared_ptr<const CSetting>& setting,
                                     void* data);

  typedef std::map<int, std::shared_ptr<CPVRTimerType>> TypeEntriesMap;

  typedef struct ChannelDescriptor
  {
    int channelUid;
    int clientId;
    std::string description;

    ChannelDescriptor(int _channelUid = PVR_CHANNEL_INVALID_UID,
                      int _clientId = -1,
                      const std::string& _description = "")
      : channelUid(_channelUid), clientId(_clientId), description(_description)
    {
    }

    inline bool operator==(const ChannelDescriptor& right) const
    {
      return (channelUid == right.channelUid && clientId == right.clientId &&
              description == right.description);
    }

  } ChannelDescriptor;

  typedef std::map<int, ChannelDescriptor> ChannelEntriesMap;

  std::shared_ptr<CPVRTimerInfoTag> m_timerInfoTag;
  TypeEntriesMap m_typeEntries;
  ChannelEntriesMap m_channelEntries;
  std::string m_timerStartTimeStr;
  std::string m_timerEndTimeStr;

  std::shared_ptr<CPVRTimerType> m_timerType;
  bool m_bIsRadio = false;
  bool m_bIsNewTimer = true;
  bool m_bTimerActive = false;
  std::string m_strTitle;
  std::string m_strEpgSearchString;
  bool m_bFullTextEpgSearch = true;
  ChannelDescriptor m_channel;
  CDateTime m_startLocalTime;
  CDateTime m_endLocalTime;
  bool m_bStartAnyTime = false;
  bool m_bEndAnyTime = false;
  unsigned int m_iWeekdays;
  CDateTime m_firstDayLocalTime;
  unsigned int m_iPreventDupEpisodes = 0;
  unsigned int m_iMarginStart = 0;
  unsigned int m_iMarginEnd = 0;
  int m_iPriority = 0;
  int m_iLifetime = 0;
  int m_iMaxRecordings = 0;
  std::string m_strDirectory;
  unsigned int m_iRecordingGroup = 0;
};
} // namespace PVR