2 * Copyright (C) 2012-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
9 #include "GUIDialogPVRTimerSettings.h"
11 #include "ServiceBroker.h"
12 #include "dialogs/GUIDialogNumeric.h"
13 #include "guilib/GUIMessage.h"
14 #include "guilib/LocalizeStrings.h"
15 #include "messaging/helpers/DialogOKHelper.h"
16 #include "pvr/PVRManager.h"
17 #include "pvr/addons/PVRClient.h"
18 #include "pvr/addons/PVRClients.h"
19 #include "pvr/channels/PVRChannel.h"
20 #include "pvr/channels/PVRChannelGroup.h"
21 #include "pvr/channels/PVRChannelGroupMember.h"
22 #include "pvr/channels/PVRChannelGroupsContainer.h"
23 #include "pvr/epg/EpgInfoTag.h"
24 #include "pvr/timers/PVRTimerInfoTag.h"
25 #include "pvr/timers/PVRTimerType.h"
26 #include "settings/SettingUtils.h"
27 #include "settings/dialogs/GUIDialogSettingsBase.h"
28 #include "settings/lib/Setting.h"
29 #include "settings/lib/SettingsManager.h"
30 #include "settings/windows/GUIControlSettings.h"
31 #include "utils/StringUtils.h"
32 #include "utils/Variant.h"
33 #include "utils/log.h"
43 using namespace KODI::MESSAGING
;
45 #define SETTING_TMR_TYPE "timer.type"
46 #define SETTING_TMR_ACTIVE "timer.active"
47 #define SETTING_TMR_NAME "timer.name"
48 #define SETTING_TMR_EPGSEARCH "timer.epgsearch"
49 #define SETTING_TMR_FULLTEXT "timer.fulltext"
50 #define SETTING_TMR_CHANNEL "timer.channel"
51 #define SETTING_TMR_START_ANYTIME "timer.startanytime"
52 #define SETTING_TMR_END_ANYTIME "timer.endanytime"
53 #define SETTING_TMR_START_DAY "timer.startday"
54 #define SETTING_TMR_END_DAY "timer.endday"
55 #define SETTING_TMR_BEGIN "timer.begin"
56 #define SETTING_TMR_END "timer.end"
57 #define SETTING_TMR_WEEKDAYS "timer.weekdays"
58 #define SETTING_TMR_FIRST_DAY "timer.firstday"
59 #define SETTING_TMR_NEW_EPISODES "timer.newepisodes"
60 #define SETTING_TMR_BEGIN_PRE "timer.startmargin"
61 #define SETTING_TMR_END_POST "timer.endmargin"
62 #define SETTING_TMR_PRIORITY "timer.priority"
63 #define SETTING_TMR_LIFETIME "timer.lifetime"
64 #define SETTING_TMR_MAX_REC "timer.maxrecordings"
65 #define SETTING_TMR_DIR "timer.directory"
66 #define SETTING_TMR_REC_GROUP "timer.recgroup"
68 #define TYPE_DEP_VISIBI_COND_ID_POSTFIX "visibi.typedep"
69 #define TYPE_DEP_ENABLE_COND_ID_POSTFIX "enable.typedep"
70 #define CHANNEL_DEP_VISIBI_COND_ID_POSTFIX "visibi.channeldep"
71 #define START_ANYTIME_DEP_VISIBI_COND_ID_POSTFIX "visibi.startanytimedep"
72 #define END_ANYTIME_DEP_VISIBI_COND_ID_POSTFIX "visibi.endanytimedep"
74 CGUIDialogPVRTimerSettings::CGUIDialogPVRTimerSettings()
75 : CGUIDialogSettingsManualBase(WINDOW_DIALOG_PVR_TIMER_SETTING
, "DialogSettings.xml"),
76 m_iWeekdays(PVR_WEEKDAY_NONE
)
78 m_loadType
= LOAD_EVERY_TIME
;
81 CGUIDialogPVRTimerSettings::~CGUIDialogPVRTimerSettings() = default;
83 bool CGUIDialogPVRTimerSettings::CanBeActivated() const
87 CLog::LogF(LOGERROR
, "No timer info tag");
93 void CGUIDialogPVRTimerSettings::SetTimer(const std::shared_ptr
<CPVRTimerInfoTag
>& timer
)
97 CLog::LogF(LOGERROR
, "No timer given");
101 m_timerInfoTag
= timer
;
103 // Copy data we need from tag. Do not modify the tag itself until Save()!
104 m_timerType
= m_timerInfoTag
->GetTimerType();
105 m_bIsRadio
= m_timerInfoTag
->m_bIsRadio
;
106 m_bIsNewTimer
= m_timerInfoTag
->m_iClientIndex
== PVR_TIMER_NO_CLIENT_INDEX
;
107 m_bTimerActive
= m_bIsNewTimer
|| !m_timerType
->SupportsEnableDisable() ||
108 !(m_timerInfoTag
->m_state
== PVR_TIMER_STATE_DISABLED
);
110 m_bIsNewTimer
|| !m_timerType
->SupportsStartAnyTime() || m_timerInfoTag
->m_bStartAnyTime
;
112 m_bIsNewTimer
|| !m_timerType
->SupportsEndAnyTime() || m_timerInfoTag
->m_bEndAnyTime
;
113 m_strTitle
= m_timerInfoTag
->m_strTitle
;
115 m_startLocalTime
= m_timerInfoTag
->StartAsLocalTime();
116 m_endLocalTime
= m_timerInfoTag
->EndAsLocalTime();
118 m_timerStartTimeStr
= m_startLocalTime
.GetAsLocalizedTime("", false);
119 m_timerEndTimeStr
= m_endLocalTime
.GetAsLocalizedTime("", false);
120 m_firstDayLocalTime
= m_timerInfoTag
->FirstDayAsLocalTime();
122 m_strEpgSearchString
= m_timerInfoTag
->m_strEpgSearchString
;
123 if ((m_bIsNewTimer
|| !m_timerType
->SupportsEpgTitleMatch()) && m_strEpgSearchString
.empty())
124 m_strEpgSearchString
= m_strTitle
;
126 m_bFullTextEpgSearch
= m_timerInfoTag
->m_bFullTextEpgSearch
;
128 m_iWeekdays
= m_timerInfoTag
->m_iWeekdays
;
129 if ((m_bIsNewTimer
|| !m_timerType
->SupportsWeekdays()) && m_iWeekdays
== PVR_WEEKDAY_NONE
)
130 m_iWeekdays
= PVR_WEEKDAY_ALLDAYS
;
132 m_iPreventDupEpisodes
= m_timerInfoTag
->m_iPreventDupEpisodes
;
133 m_iMarginStart
= m_timerInfoTag
->m_iMarginStart
;
134 m_iMarginEnd
= m_timerInfoTag
->m_iMarginEnd
;
135 m_iPriority
= m_timerInfoTag
->m_iPriority
;
136 m_iLifetime
= m_timerInfoTag
->m_iLifetime
;
137 m_iMaxRecordings
= m_timerInfoTag
->m_iMaxRecordings
;
139 if (m_bIsNewTimer
&& m_timerInfoTag
->m_strDirectory
.empty() &&
140 m_timerType
->SupportsRecordingFolders())
141 m_strDirectory
= m_strTitle
;
143 m_strDirectory
= m_timerInfoTag
->m_strDirectory
;
145 m_iRecordingGroup
= m_timerInfoTag
->m_iRecordingGroup
;
147 InitializeChannelsList();
148 InitializeTypesList();
151 m_channel
= ChannelDescriptor();
153 if (m_timerInfoTag
->m_iClientChannelUid
== PVR_CHANNEL_INVALID_UID
)
155 if (m_timerType
->SupportsAnyChannel())
157 // Select first matching "Any channel" entry.
158 const auto it
= std::find_if(m_channelEntries
.cbegin(), m_channelEntries
.cend(),
159 [this](const auto& channel
) {
160 return channel
.second
.channelUid
== PVR_CHANNEL_INVALID_UID
&&
161 channel
.second
.clientId
== m_timerInfoTag
->m_iClientId
;
164 if (it
!= m_channelEntries
.cend())
166 m_channel
= (*it
).second
;
170 CLog::LogF(LOGERROR
, "Unable to map PVR_CHANNEL_INVALID_UID to channel entry!");
173 else if (m_bIsNewTimer
)
175 // Select first matching regular (not "Any channel") entry.
176 const auto it
= std::find_if(m_channelEntries
.cbegin(), m_channelEntries
.cend(),
177 [this](const auto& channel
) {
178 return channel
.second
.channelUid
!= PVR_CHANNEL_INVALID_UID
&&
179 channel
.second
.clientId
== m_timerInfoTag
->m_iClientId
;
182 if (it
!= m_channelEntries
.cend())
184 m_channel
= (*it
).second
;
188 CLog::LogF(LOGERROR
, "Unable to map PVR_CHANNEL_INVALID_UID to channel entry!");
194 // Find matching channel entry
195 const auto it
= std::find_if(
196 m_channelEntries
.cbegin(), m_channelEntries
.cend(), [this](const auto& channel
) {
197 return channel
.second
.channelUid
== m_timerInfoTag
->m_iClientChannelUid
&&
198 channel
.second
.clientId
== m_timerInfoTag
->m_iClientId
;
201 if (it
!= m_channelEntries
.cend())
203 m_channel
= (*it
).second
;
207 CLog::LogF(LOGERROR
, "Unable to map channel uid to channel entry!");
212 void CGUIDialogPVRTimerSettings::SetupView()
214 CGUIDialogSettingsManualBase::SetupView();
216 SET_CONTROL_HIDDEN(CONTROL_SETTINGS_CUSTOM_BUTTON
);
217 SET_CONTROL_LABEL(CONTROL_SETTINGS_OKAY_BUTTON
, 186);
218 SET_CONTROL_LABEL(CONTROL_SETTINGS_CANCEL_BUTTON
, 222);
222 void CGUIDialogPVRTimerSettings::InitializeSettings()
224 CGUIDialogSettingsManualBase::InitializeSettings();
226 const std::shared_ptr
<CSettingCategory
> category
= AddCategory("pvrtimersettings", -1);
227 if (category
== NULL
)
229 CLog::LogF(LOGERROR
, "Unable to add settings category");
233 const std::shared_ptr
<CSettingGroup
> group
= AddGroup(category
);
236 CLog::LogF(LOGERROR
, "Unable to add settings group");
240 std::shared_ptr
<CSetting
> setting
= NULL
;
243 bool useDetails
= false;
244 bool foundClientSupportingTimers
= false;
246 const CPVRClientMap clients
= CServiceBroker::GetPVRManager().Clients()->GetCreatedClients();
247 for (const auto& client
: clients
)
249 if (client
.second
->GetClientCapabilities().SupportsTimers())
251 if (foundClientSupportingTimers
)
253 // found second client supporting timers, use detailed timer type list layout
257 foundClientSupportingTimers
= true;
261 setting
= AddList(group
, SETTING_TMR_TYPE
, 803, SettingLevel::Basic
, 0, TypesFiller
, 803, true,
263 AddTypeDependentEnableCondition(setting
, SETTING_TMR_TYPE
);
265 // Timer enabled/disabled
266 setting
= AddToggle(group
, SETTING_TMR_ACTIVE
, 305, SettingLevel::Basic
, m_bTimerActive
);
267 AddTypeDependentVisibilityCondition(setting
, SETTING_TMR_ACTIVE
);
268 AddTypeDependentEnableCondition(setting
, SETTING_TMR_ACTIVE
);
272 AddEdit(group
, SETTING_TMR_NAME
, 19075, SettingLevel::Basic
, m_strTitle
, true, false, 19097);
273 AddTypeDependentEnableCondition(setting
, SETTING_TMR_NAME
);
275 // epg search string (only for epg-based timer rules)
276 setting
= AddEdit(group
, SETTING_TMR_EPGSEARCH
, 804, SettingLevel::Basic
, m_strEpgSearchString
,
278 AddTypeDependentVisibilityCondition(setting
, SETTING_TMR_EPGSEARCH
);
279 AddTypeDependentEnableCondition(setting
, SETTING_TMR_EPGSEARCH
);
281 // epg fulltext search (only for epg-based timer rules)
282 setting
= AddToggle(group
, SETTING_TMR_FULLTEXT
, 806, SettingLevel::Basic
, m_bFullTextEpgSearch
);
283 AddTypeDependentVisibilityCondition(setting
, SETTING_TMR_FULLTEXT
);
284 AddTypeDependentEnableCondition(setting
, SETTING_TMR_FULLTEXT
);
288 AddList(group
, SETTING_TMR_CHANNEL
, 19078, SettingLevel::Basic
, 0, ChannelsFiller
, 19078);
289 AddTypeDependentVisibilityCondition(setting
, SETTING_TMR_CHANNEL
);
290 AddTypeDependentEnableCondition(setting
, SETTING_TMR_CHANNEL
);
292 // Days of week (only for timer rules)
293 std::vector
<int> weekdaysPreselect
;
294 if (m_iWeekdays
& PVR_WEEKDAY_MONDAY
)
295 weekdaysPreselect
.push_back(PVR_WEEKDAY_MONDAY
);
296 if (m_iWeekdays
& PVR_WEEKDAY_TUESDAY
)
297 weekdaysPreselect
.push_back(PVR_WEEKDAY_TUESDAY
);
298 if (m_iWeekdays
& PVR_WEEKDAY_WEDNESDAY
)
299 weekdaysPreselect
.push_back(PVR_WEEKDAY_WEDNESDAY
);
300 if (m_iWeekdays
& PVR_WEEKDAY_THURSDAY
)
301 weekdaysPreselect
.push_back(PVR_WEEKDAY_THURSDAY
);
302 if (m_iWeekdays
& PVR_WEEKDAY_FRIDAY
)
303 weekdaysPreselect
.push_back(PVR_WEEKDAY_FRIDAY
);
304 if (m_iWeekdays
& PVR_WEEKDAY_SATURDAY
)
305 weekdaysPreselect
.push_back(PVR_WEEKDAY_SATURDAY
);
306 if (m_iWeekdays
& PVR_WEEKDAY_SUNDAY
)
307 weekdaysPreselect
.push_back(PVR_WEEKDAY_SUNDAY
);
309 setting
= AddList(group
, SETTING_TMR_WEEKDAYS
, 19079, SettingLevel::Basic
, weekdaysPreselect
,
310 WeekdaysFiller
, 19079, 1, -1, true, -1, WeekdaysValueFormatter
);
311 AddTypeDependentVisibilityCondition(setting
, SETTING_TMR_WEEKDAYS
);
312 AddTypeDependentEnableCondition(setting
, SETTING_TMR_WEEKDAYS
);
314 // "Start any time" (only for timer rules)
315 setting
= AddToggle(group
, SETTING_TMR_START_ANYTIME
, 810, SettingLevel::Basic
, m_bStartAnyTime
);
316 AddTypeDependentVisibilityCondition(setting
, SETTING_TMR_START_ANYTIME
);
317 AddTypeDependentEnableCondition(setting
, SETTING_TMR_START_ANYTIME
);
319 // Start day (day + month + year only, no hours, minutes)
320 setting
= AddSpinner(group
, SETTING_TMR_START_DAY
, 19128, SettingLevel::Basic
,
321 GetDateAsIndex(m_startLocalTime
), DaysFiller
);
322 AddTypeDependentVisibilityCondition(setting
, SETTING_TMR_START_DAY
);
323 AddTypeDependentEnableCondition(setting
, SETTING_TMR_START_DAY
);
324 AddStartAnytimeDependentVisibilityCondition(setting
, SETTING_TMR_START_DAY
);
326 // Start time (hours + minutes only, no day, month, year)
327 setting
= AddButton(group
, SETTING_TMR_BEGIN
, 19126, SettingLevel::Basic
);
328 AddTypeDependentVisibilityCondition(setting
, SETTING_TMR_BEGIN
);
329 AddTypeDependentEnableCondition(setting
, SETTING_TMR_BEGIN
);
330 AddStartAnytimeDependentVisibilityCondition(setting
, SETTING_TMR_BEGIN
);
332 // "End any time" (only for timer rules)
333 setting
= AddToggle(group
, SETTING_TMR_END_ANYTIME
, 817, SettingLevel::Basic
, m_bEndAnyTime
);
334 AddTypeDependentVisibilityCondition(setting
, SETTING_TMR_END_ANYTIME
);
335 AddTypeDependentEnableCondition(setting
, SETTING_TMR_END_ANYTIME
);
337 // End day (day + month + year only, no hours, minutes)
338 setting
= AddSpinner(group
, SETTING_TMR_END_DAY
, 19129, SettingLevel::Basic
,
339 GetDateAsIndex(m_endLocalTime
), DaysFiller
);
340 AddTypeDependentVisibilityCondition(setting
, SETTING_TMR_END_DAY
);
341 AddTypeDependentEnableCondition(setting
, SETTING_TMR_END_DAY
);
342 AddEndAnytimeDependentVisibilityCondition(setting
, SETTING_TMR_END_DAY
);
344 // End time (hours + minutes only, no day, month, year)
345 setting
= AddButton(group
, SETTING_TMR_END
, 19127, SettingLevel::Basic
);
346 AddTypeDependentVisibilityCondition(setting
, SETTING_TMR_END
);
347 AddTypeDependentEnableCondition(setting
, SETTING_TMR_END
);
348 AddEndAnytimeDependentVisibilityCondition(setting
, SETTING_TMR_END
);
350 // First day (only for timer rules)
351 setting
= AddSpinner(group
, SETTING_TMR_FIRST_DAY
, 19084, SettingLevel::Basic
,
352 GetDateAsIndex(m_firstDayLocalTime
), DaysFiller
);
353 AddTypeDependentVisibilityCondition(setting
, SETTING_TMR_FIRST_DAY
);
354 AddTypeDependentEnableCondition(setting
, SETTING_TMR_FIRST_DAY
);
356 // "Prevent duplicate episodes" (only for timer rules)
357 setting
= AddList(group
, SETTING_TMR_NEW_EPISODES
, 812, SettingLevel::Basic
,
358 m_iPreventDupEpisodes
, DupEpisodesFiller
, 812);
359 AddTypeDependentVisibilityCondition(setting
, SETTING_TMR_NEW_EPISODES
);
360 AddTypeDependentEnableCondition(setting
, SETTING_TMR_NEW_EPISODES
);
362 // Pre and post record time
363 setting
= AddList(group
, SETTING_TMR_BEGIN_PRE
, 813, SettingLevel::Basic
, m_iMarginStart
,
364 MarginTimeFiller
, 813);
365 AddTypeDependentVisibilityCondition(setting
, SETTING_TMR_BEGIN_PRE
);
366 AddTypeDependentEnableCondition(setting
, SETTING_TMR_BEGIN_PRE
);
368 setting
= AddList(group
, SETTING_TMR_END_POST
, 814, SettingLevel::Basic
, m_iMarginEnd
,
369 MarginTimeFiller
, 814);
370 AddTypeDependentVisibilityCondition(setting
, SETTING_TMR_END_POST
);
371 AddTypeDependentEnableCondition(setting
, SETTING_TMR_END_POST
);
374 setting
= AddList(group
, SETTING_TMR_PRIORITY
, 19082, SettingLevel::Basic
, m_iPriority
,
375 PrioritiesFiller
, 19082);
376 AddTypeDependentVisibilityCondition(setting
, SETTING_TMR_PRIORITY
);
377 AddTypeDependentEnableCondition(setting
, SETTING_TMR_PRIORITY
);
380 setting
= AddList(group
, SETTING_TMR_LIFETIME
, 19083, SettingLevel::Basic
, m_iLifetime
,
381 LifetimesFiller
, 19083);
382 AddTypeDependentVisibilityCondition(setting
, SETTING_TMR_LIFETIME
);
383 AddTypeDependentEnableCondition(setting
, SETTING_TMR_LIFETIME
);
386 setting
= AddList(group
, SETTING_TMR_MAX_REC
, 818, SettingLevel::Basic
, m_iMaxRecordings
,
387 MaxRecordingsFiller
, 818);
388 AddTypeDependentVisibilityCondition(setting
, SETTING_TMR_MAX_REC
);
389 AddTypeDependentEnableCondition(setting
, SETTING_TMR_MAX_REC
);
392 setting
= AddEdit(group
, SETTING_TMR_DIR
, 19076, SettingLevel::Basic
, m_strDirectory
, true, false,
394 AddTypeDependentVisibilityCondition(setting
, SETTING_TMR_DIR
);
395 AddTypeDependentEnableCondition(setting
, SETTING_TMR_DIR
);
398 setting
= AddList(group
, SETTING_TMR_REC_GROUP
, 811, SettingLevel::Basic
, m_iRecordingGroup
,
399 RecordingGroupFiller
, 811);
400 AddTypeDependentVisibilityCondition(setting
, SETTING_TMR_REC_GROUP
);
401 AddTypeDependentEnableCondition(setting
, SETTING_TMR_REC_GROUP
);
404 int CGUIDialogPVRTimerSettings::GetWeekdaysFromSetting(const SettingConstPtr
& setting
)
406 std::shared_ptr
<const CSettingList
> settingList
=
407 std::static_pointer_cast
<const CSettingList
>(setting
);
408 if (settingList
->GetElementType() != SettingType::Integer
)
410 CLog::LogF(LOGERROR
, "Wrong weekdays element type");
414 std::vector
<CVariant
> list
= CSettingUtils::GetList(settingList
);
415 for (const auto& value
: list
)
417 if (!value
.isInteger())
419 CLog::LogF(LOGERROR
, "Wrong weekdays value type");
422 weekdays
+= static_cast<int>(value
.asInteger());
428 void CGUIDialogPVRTimerSettings::OnSettingChanged(const std::shared_ptr
<const CSetting
>& setting
)
432 CLog::LogF(LOGERROR
, "No setting");
436 CGUIDialogSettingsManualBase::OnSettingChanged(setting
);
438 const std::string
& settingId
= setting
->GetId();
440 if (settingId
== SETTING_TMR_TYPE
)
442 int idx
= std::static_pointer_cast
<const CSettingInt
>(setting
)->GetValue();
443 const auto it
= m_typeEntries
.find(idx
);
444 if (it
!= m_typeEntries
.end())
446 m_timerType
= it
->second
;
448 if (m_timerType
->IsTimerRule() && (m_iWeekdays
== PVR_WEEKDAY_ALLDAYS
))
449 SetButtonLabels(); // update "Any day" vs. "Every day"
453 CLog::LogF(LOGERROR
, "Unable to get 'type' value");
456 else if (settingId
== SETTING_TMR_ACTIVE
)
458 m_bTimerActive
= std::static_pointer_cast
<const CSettingBool
>(setting
)->GetValue();
460 else if (settingId
== SETTING_TMR_NAME
)
462 m_strTitle
= std::static_pointer_cast
<const CSettingString
>(setting
)->GetValue();
464 else if (settingId
== SETTING_TMR_EPGSEARCH
)
466 m_strEpgSearchString
= std::static_pointer_cast
<const CSettingString
>(setting
)->GetValue();
468 else if (settingId
== SETTING_TMR_FULLTEXT
)
470 m_bFullTextEpgSearch
= std::static_pointer_cast
<const CSettingBool
>(setting
)->GetValue();
472 else if (settingId
== SETTING_TMR_CHANNEL
)
474 int idx
= std::static_pointer_cast
<const CSettingInt
>(setting
)->GetValue();
475 const auto it
= m_channelEntries
.find(idx
);
476 if (it
!= m_channelEntries
.end())
478 m_channel
= it
->second
;
482 CLog::LogF(LOGERROR
, "Unable to get 'type' value");
485 else if (settingId
== SETTING_TMR_WEEKDAYS
)
487 m_iWeekdays
= GetWeekdaysFromSetting(setting
);
489 else if (settingId
== SETTING_TMR_START_ANYTIME
)
491 m_bStartAnyTime
= std::static_pointer_cast
<const CSettingBool
>(setting
)->GetValue();
493 else if (settingId
== SETTING_TMR_END_ANYTIME
)
495 m_bEndAnyTime
= std::static_pointer_cast
<const CSettingBool
>(setting
)->GetValue();
497 else if (settingId
== SETTING_TMR_START_DAY
)
499 SetDateFromIndex(m_startLocalTime
,
500 std::static_pointer_cast
<const CSettingInt
>(setting
)->GetValue());
502 else if (settingId
== SETTING_TMR_END_DAY
)
504 SetDateFromIndex(m_endLocalTime
,
505 std::static_pointer_cast
<const CSettingInt
>(setting
)->GetValue());
507 else if (settingId
== SETTING_TMR_FIRST_DAY
)
509 SetDateFromIndex(m_firstDayLocalTime
,
510 std::static_pointer_cast
<const CSettingInt
>(setting
)->GetValue());
512 else if (settingId
== SETTING_TMR_NEW_EPISODES
)
514 m_iPreventDupEpisodes
= std::static_pointer_cast
<const CSettingInt
>(setting
)->GetValue();
516 else if (settingId
== SETTING_TMR_BEGIN_PRE
)
518 m_iMarginStart
= std::static_pointer_cast
<const CSettingInt
>(setting
)->GetValue();
520 else if (settingId
== SETTING_TMR_END_POST
)
522 m_iMarginEnd
= std::static_pointer_cast
<const CSettingInt
>(setting
)->GetValue();
524 else if (settingId
== SETTING_TMR_PRIORITY
)
526 m_iPriority
= std::static_pointer_cast
<const CSettingInt
>(setting
)->GetValue();
528 else if (settingId
== SETTING_TMR_LIFETIME
)
530 m_iLifetime
= std::static_pointer_cast
<const CSettingInt
>(setting
)->GetValue();
532 else if (settingId
== SETTING_TMR_MAX_REC
)
534 m_iMaxRecordings
= std::static_pointer_cast
<const CSettingInt
>(setting
)->GetValue();
536 else if (settingId
== SETTING_TMR_DIR
)
538 m_strDirectory
= std::static_pointer_cast
<const CSettingString
>(setting
)->GetValue();
540 else if (settingId
== SETTING_TMR_REC_GROUP
)
542 m_iRecordingGroup
= std::static_pointer_cast
<const CSettingInt
>(setting
)->GetValue();
546 void CGUIDialogPVRTimerSettings::OnSettingAction(const std::shared_ptr
<const CSetting
>& setting
)
550 CLog::LogF(LOGERROR
, "No setting");
554 CGUIDialogSettingsManualBase::OnSettingAction(setting
);
556 const std::string
& settingId
= setting
->GetId();
557 if (settingId
== SETTING_TMR_BEGIN
)
559 KODI::TIME::SystemTime timerStartTime
;
560 m_startLocalTime
.GetAsSystemTime(timerStartTime
);
561 if (CGUIDialogNumeric::ShowAndGetTime(timerStartTime
, g_localizeStrings
.Get(14066)))
563 SetTimeFromSystemTime(m_startLocalTime
, timerStartTime
);
564 m_timerStartTimeStr
= m_startLocalTime
.GetAsLocalizedTime("", false);
568 else if (settingId
== SETTING_TMR_END
)
570 KODI::TIME::SystemTime timerEndTime
;
571 m_endLocalTime
.GetAsSystemTime(timerEndTime
);
572 if (CGUIDialogNumeric::ShowAndGetTime(timerEndTime
, g_localizeStrings
.Get(14066)))
574 SetTimeFromSystemTime(m_endLocalTime
, timerEndTime
);
575 m_timerEndTimeStr
= m_endLocalTime
.GetAsLocalizedTime("", false);
581 bool CGUIDialogPVRTimerSettings::Validate()
583 bool bStartAnyTime
= m_bStartAnyTime
;
584 bool bEndAnyTime
= m_bEndAnyTime
;
586 if (!m_timerType
->SupportsStartAnyTime() ||
587 !m_timerType
->IsEpgBased()) // Start anytime toggle is not displayed
588 bStartAnyTime
= false; // Assume start time change needs checking for
590 if (!m_timerType
->SupportsEndAnyTime() ||
591 !m_timerType
->IsEpgBased()) // End anytime toggle is not displayed
592 bEndAnyTime
= false; // Assume end time change needs checking for
594 // Begin and end time
595 if (!bStartAnyTime
&& !bEndAnyTime
)
597 // Not in the set of having neither or both of start clock entry and
598 // end clock entry while also being a timer rule
599 if (!(m_timerType
->SupportsStartTime() == m_timerType
->SupportsEndTime() &&
600 m_timerType
->IsTimerRule()) &&
601 m_endLocalTime
< m_startLocalTime
)
603 HELPERS::ShowOKDialogText(CVariant
{19065}, // "Timer settings"
604 CVariant
{19072}); // In order to add/update a timer
612 bool CGUIDialogPVRTimerSettings::Save()
618 m_timerInfoTag
->SetTimerType(m_timerType
);
620 // Timer active/inactive
621 m_timerInfoTag
->m_state
= m_bTimerActive
? PVR_TIMER_STATE_SCHEDULED
: PVR_TIMER_STATE_DISABLED
;
624 m_timerInfoTag
->m_strTitle
= m_strTitle
;
626 // epg search string (only for epg-based timer rules)
627 m_timerInfoTag
->m_strEpgSearchString
= m_strEpgSearchString
;
629 // epg fulltext search, instead of just title match. (only for epg-based timer rules)
630 m_timerInfoTag
->m_bFullTextEpgSearch
= m_bFullTextEpgSearch
;
633 m_timerInfoTag
->m_iClientChannelUid
= m_channel
.channelUid
;
634 m_timerInfoTag
->m_iClientId
= m_channel
.clientId
;
635 m_timerInfoTag
->m_bIsRadio
= m_bIsRadio
;
636 m_timerInfoTag
->UpdateChannel();
638 if (!m_timerType
->SupportsStartAnyTime() ||
639 !m_timerType
->IsEpgBased()) // Start anytime toggle is not displayed
640 m_bStartAnyTime
= false; // Assume start time change needs checking for
641 m_timerInfoTag
->m_bStartAnyTime
= m_bStartAnyTime
;
643 if (!m_timerType
->SupportsEndAnyTime() ||
644 !m_timerType
->IsEpgBased()) // End anytime toggle is not displayed
645 m_bEndAnyTime
= false; // Assume end time change needs checking for
646 m_timerInfoTag
->m_bEndAnyTime
= m_bEndAnyTime
;
648 // Begin and end time
649 if (!m_bStartAnyTime
&& !m_bEndAnyTime
)
651 if (m_timerType
->SupportsStartTime() && // has start clock entry
652 m_timerType
->SupportsEndTime() && // and end clock entry
653 m_timerType
->IsTimerRule()) // but no associated start/end day spinners
655 if (m_endLocalTime
< m_startLocalTime
) // And the end clock is earlier than the start clock
657 CLog::LogFC(LOGDEBUG
, LOGPVR
, "End before start, adding a day.");
658 m_endLocalTime
+= CDateTimeSpan(1, 0, 0, 0);
659 if (m_endLocalTime
< m_startLocalTime
)
661 CLog::Log(LOGWARNING
,
662 "Timer settings dialog: End before start. Setting end time to start time.");
663 m_endLocalTime
= m_startLocalTime
;
666 else if (m_endLocalTime
>
667 (m_startLocalTime
+ CDateTimeSpan(1, 0, 0, 0))) // Or the duration is more than a day
669 CLog::LogFC(LOGDEBUG
, LOGPVR
, "End > 1 day after start, removing a day.");
670 m_endLocalTime
-= CDateTimeSpan(1, 0, 0, 0);
671 if (m_endLocalTime
> (m_startLocalTime
+ CDateTimeSpan(1, 0, 0, 0)))
675 "Timer settings dialog: End > 1 day after start. Setting end time to start time.");
676 m_endLocalTime
= m_startLocalTime
;
680 else if (m_endLocalTime
< m_startLocalTime
)
682 // this case will fail validation so this can't be reached.
684 m_timerInfoTag
->SetStartFromLocalTime(m_startLocalTime
);
685 m_timerInfoTag
->SetEndFromLocalTime(m_endLocalTime
);
687 else if (!m_bStartAnyTime
)
688 m_timerInfoTag
->SetStartFromLocalTime(m_startLocalTime
);
689 else if (!m_bEndAnyTime
)
690 m_timerInfoTag
->SetEndFromLocalTime(m_endLocalTime
);
692 // Days of week (only for timer rules)
693 if (m_timerType
->IsTimerRule())
694 m_timerInfoTag
->m_iWeekdays
= m_iWeekdays
;
696 m_timerInfoTag
->m_iWeekdays
= PVR_WEEKDAY_NONE
;
698 // First day (only for timer rules)
699 m_timerInfoTag
->SetFirstDayFromLocalTime(m_firstDayLocalTime
);
701 // "New episodes only" (only for timer rules)
702 m_timerInfoTag
->m_iPreventDupEpisodes
= m_iPreventDupEpisodes
;
704 // Pre and post record time
705 m_timerInfoTag
->m_iMarginStart
= m_iMarginStart
;
706 m_timerInfoTag
->m_iMarginEnd
= m_iMarginEnd
;
709 m_timerInfoTag
->m_iPriority
= m_iPriority
;
712 m_timerInfoTag
->m_iLifetime
= m_iLifetime
;
715 m_timerInfoTag
->m_iMaxRecordings
= m_iMaxRecordings
;
718 m_timerInfoTag
->m_strDirectory
= m_strDirectory
;
721 m_timerInfoTag
->m_iRecordingGroup
= m_iRecordingGroup
;
723 // Set the timer's title to the channel name if it's empty or 'New Timer'
724 if (m_strTitle
.empty() || m_strTitle
== g_localizeStrings
.Get(19056))
726 const std::string channelName
= m_timerInfoTag
->ChannelName();
727 if (!channelName
.empty())
728 m_timerInfoTag
->m_strTitle
= channelName
;
732 m_timerInfoTag
->UpdateSummary();
737 void CGUIDialogPVRTimerSettings::SetButtonLabels()
740 BaseSettingControlPtr settingControl
= GetSettingControl(SETTING_TMR_BEGIN
);
741 if (settingControl
!= NULL
&& settingControl
->GetControl() != NULL
)
743 SET_CONTROL_LABEL2(settingControl
->GetID(), m_timerStartTimeStr
);
747 settingControl
= GetSettingControl(SETTING_TMR_END
);
748 if (settingControl
!= NULL
&& settingControl
->GetControl() != NULL
)
750 SET_CONTROL_LABEL2(settingControl
->GetID(), m_timerEndTimeStr
);
754 void CGUIDialogPVRTimerSettings::AddCondition(const std::shared_ptr
<CSetting
>& setting
,
755 const std::string
& identifier
,
756 SettingConditionCheck condition
,
757 SettingDependencyType depType
,
758 const std::string
& settingId
)
760 GetSettingsManager()->AddDynamicCondition(identifier
, condition
, this);
761 CSettingDependency
dep(depType
, GetSettingsManager());
762 dep
.And()->Add(CSettingDependencyConditionPtr(
763 new CSettingDependencyCondition(identifier
, "true", settingId
, false, GetSettingsManager())));
764 SettingDependencies
deps(setting
->GetDependencies());
766 setting
->SetDependencies(deps
);
769 int CGUIDialogPVRTimerSettings::GetDateAsIndex(const CDateTime
& datetime
)
771 const CDateTime
date(datetime
.GetYear(), datetime
.GetMonth(), datetime
.GetDay(), 0, 0, 0);
774 return static_cast<int>(t
);
777 void CGUIDialogPVRTimerSettings::SetDateFromIndex(CDateTime
& datetime
, int date
)
779 const CDateTime
newDate(static_cast<time_t>(date
));
780 datetime
.SetDateTime(newDate
.GetYear(), newDate
.GetMonth(), newDate
.GetDay(), datetime
.GetHour(),
781 datetime
.GetMinute(), datetime
.GetSecond());
784 void CGUIDialogPVRTimerSettings::SetTimeFromSystemTime(CDateTime
& datetime
,
785 const KODI::TIME::SystemTime
& time
)
787 const CDateTime
newTime(time
);
788 datetime
.SetDateTime(datetime
.GetYear(), datetime
.GetMonth(), datetime
.GetDay(),
789 newTime
.GetHour(), newTime
.GetMinute(), newTime
.GetSecond());
792 void CGUIDialogPVRTimerSettings::InitializeTypesList()
794 m_typeEntries
.clear();
796 // If timer is read-only or was created by a timer rule, only add current type, for information. Type can't be changed.
797 if (m_timerType
->IsReadOnly() || m_timerInfoTag
->HasParent())
799 m_typeEntries
.insert(std::make_pair(0, m_timerType
));
803 bool bFoundThisType(false);
805 const std::vector
<std::shared_ptr
<CPVRTimerType
>> types(CPVRTimerType::GetAllTypes());
806 for (const auto& type
: types
)
808 // Type definition prohibits created of new instances.
809 // But the dialog can act as a viewer for these types.
810 if (type
->ForbidsNewInstances())
813 // Read-only timers cannot be created using this dialog.
814 // But the dialog can act as a viewer for read-only types.
815 if (type
->IsReadOnly())
818 // Drop TimerTypes that require EPGInfo, if none is populated
819 if (type
->RequiresEpgTagOnCreate() && !m_timerInfoTag
->GetEpgInfoTag())
822 // Drop TimerTypes without 'Series' EPG attributes if none are set
823 if (type
->RequiresEpgSeriesOnCreate())
825 const std::shared_ptr
<CPVREpgInfoTag
> epgTag(m_timerInfoTag
->GetEpgInfoTag());
826 if (epgTag
&& !epgTag
->IsSeries())
830 // Drop TimerTypes which need series link if none is set
831 if (type
->RequiresEpgSeriesLinkOnCreate())
833 const std::shared_ptr
<CPVREpgInfoTag
> epgTag(m_timerInfoTag
->GetEpgInfoTag());
834 if (!epgTag
|| epgTag
->SeriesLink().empty())
838 // Drop TimerTypes that forbid EPGInfo, if it is populated
839 if (type
->ForbidsEpgTagOnCreate() && m_timerInfoTag
->GetEpgInfoTag())
842 // Drop TimerTypes that aren't rules and cannot be recorded
843 if (!type
->IsTimerRule())
845 const std::shared_ptr
<CPVREpgInfoTag
> epgTag(m_timerInfoTag
->GetEpgInfoTag());
846 bool bCanRecord
= epgTag
? epgTag
->IsRecordable()
847 : m_timerInfoTag
->EndAsLocalTime() > CDateTime::GetCurrentDateTime();
852 if (!bFoundThisType
&& *type
== *m_timerType
)
853 bFoundThisType
= true;
855 m_typeEntries
.insert(std::make_pair(idx
++, type
));
859 m_typeEntries
.insert(std::make_pair(idx
++, m_timerType
));
862 void CGUIDialogPVRTimerSettings::InitializeChannelsList()
864 m_channelEntries
.clear();
868 // Add special "any channel" entries - one for every client (used for epg-based timer rules).
869 const CPVRClientMap clients
= CServiceBroker::GetPVRManager().Clients()->GetCreatedClients();
870 for (const auto& client
: clients
)
872 m_channelEntries
.insert(
873 {index
, ChannelDescriptor(PVR_CHANNEL_INVALID_UID
, client
.second
->GetID(),
874 g_localizeStrings
.Get(809))}); // "Any channel"
878 // Add regular channels
879 const std::shared_ptr
<CPVRChannelGroup
> allGroup
=
880 CServiceBroker::GetPVRManager().ChannelGroups()->GetGroupAll(m_bIsRadio
);
881 const std::vector
<std::shared_ptr
<CPVRChannelGroupMember
>> groupMembers
=
882 allGroup
->GetMembers(CPVRChannelGroup::Include::ONLY_VISIBLE
);
883 for (const auto& groupMember
: groupMembers
)
885 const std::shared_ptr
<CPVRChannel
> channel
= groupMember
->Channel();
886 const std::string channelDescription
= StringUtils::Format(
887 "{} {}", groupMember
->ChannelNumber().FormattedChannelNumber(), channel
->ChannelName());
888 m_channelEntries
.insert(
889 {index
, ChannelDescriptor(channel
->UniqueID(), channel
->ClientID(), channelDescription
)});
894 void CGUIDialogPVRTimerSettings::TypesFiller(const SettingConstPtr
& setting
,
895 std::vector
<IntegerSettingOption
>& list
,
899 CGUIDialogPVRTimerSettings
* pThis
= static_cast<CGUIDialogPVRTimerSettings
*>(data
);
905 static const std::vector
<std::pair
<std::string
, CVariant
>> reminderTimerProps
{
906 std::make_pair("PVR.IsRemindingTimer", CVariant
{true})};
907 static const std::vector
<std::pair
<std::string
, CVariant
>> recordingTimerProps
{
908 std::make_pair("PVR.IsRecordingTimer", CVariant
{true})};
910 const auto clients
= CServiceBroker::GetPVRManager().Clients();
912 bool foundCurrent(false);
913 for (const auto& typeEntry
: pThis
->m_typeEntries
)
915 std::string clientName
;
917 const auto client
= clients
->GetCreatedClient(typeEntry
.second
->GetClientId());
919 clientName
= client
->GetFriendlyName();
921 list
.emplace_back(typeEntry
.second
->GetDescription(), clientName
, typeEntry
.first
,
922 typeEntry
.second
->IsReminder() ? reminderTimerProps
: recordingTimerProps
);
924 if (!foundCurrent
&& (*(pThis
->m_timerType
) == *(typeEntry
.second
)))
926 current
= typeEntry
.first
;
932 CLog::LogF(LOGERROR
, "No dialog");
935 void CGUIDialogPVRTimerSettings::ChannelsFiller(const SettingConstPtr
& setting
,
936 std::vector
<IntegerSettingOption
>& list
,
940 CGUIDialogPVRTimerSettings
* pThis
= static_cast<CGUIDialogPVRTimerSettings
*>(data
);
946 bool foundCurrent(false);
947 for (const auto& channelEntry
: pThis
->m_channelEntries
)
949 // Only include channels for the currently selected timer type or all channels if type is client-independent.
950 if (pThis
->m_timerType
->GetClientId() == -1 || // client-independent
951 pThis
->m_timerType
->GetClientId() == channelEntry
.second
.clientId
)
953 // Do not add "any channel" entry if not supported by selected timer type.
954 if (channelEntry
.second
.channelUid
== PVR_CHANNEL_INVALID_UID
&&
955 !pThis
->m_timerType
->SupportsAnyChannel())
959 IntegerSettingOption(channelEntry
.second
.description
, channelEntry
.first
));
962 if (!foundCurrent
&& (pThis
->m_channel
== channelEntry
.second
))
964 current
= channelEntry
.first
;
970 CLog::LogF(LOGERROR
, "No dialog");
973 void CGUIDialogPVRTimerSettings::DaysFiller(const SettingConstPtr
& setting
,
974 std::vector
<IntegerSettingOption
>& list
,
978 CGUIDialogPVRTimerSettings
* pThis
= static_cast<CGUIDialogPVRTimerSettings
*>(data
);
984 // Data range: "today" until "yesterday next year"
985 const CDateTime
now(CDateTime::GetCurrentDateTime());
986 CDateTime
time(now
.GetYear(), now
.GetMonth(), now
.GetDay(), 0, 0, 0);
987 const CDateTime
yesterdayPlusOneYear(CDateTime(time
.GetYear() + 1, time
.GetMonth(),
988 time
.GetDay(), time
.GetHour(), time
.GetMinute(),
990 CDateTimeSpan(1, 0, 0, 0));
992 CDateTime oldCDateTime
;
993 if (setting
->GetId() == SETTING_TMR_FIRST_DAY
)
994 oldCDateTime
= pThis
->m_timerInfoTag
->FirstDayAsLocalTime();
995 else if (setting
->GetId() == SETTING_TMR_START_DAY
)
996 oldCDateTime
= pThis
->m_timerInfoTag
->StartAsLocalTime();
998 oldCDateTime
= pThis
->m_timerInfoTag
->EndAsLocalTime();
999 const CDateTime
oldCDate(oldCDateTime
.GetYear(), oldCDateTime
.GetMonth(), oldCDateTime
.GetDay(),
1002 if ((oldCDate
< time
) || (oldCDate
> yesterdayPlusOneYear
))
1003 list
.emplace_back(oldCDate
.GetAsLocalizedDate(true /*long date*/), GetDateAsIndex(oldCDate
));
1005 while (time
<= yesterdayPlusOneYear
)
1007 list
.emplace_back(time
.GetAsLocalizedDate(true /*long date*/), GetDateAsIndex(time
));
1008 time
+= CDateTimeSpan(1, 0, 0, 0);
1011 if (setting
->GetId() == SETTING_TMR_FIRST_DAY
)
1012 current
= GetDateAsIndex(pThis
->m_firstDayLocalTime
);
1013 else if (setting
->GetId() == SETTING_TMR_START_DAY
)
1014 current
= GetDateAsIndex(pThis
->m_startLocalTime
);
1016 current
= GetDateAsIndex(pThis
->m_endLocalTime
);
1019 CLog::LogF(LOGERROR
, "No dialog");
1022 void CGUIDialogPVRTimerSettings::DupEpisodesFiller(const SettingConstPtr
& setting
,
1023 std::vector
<IntegerSettingOption
>& list
,
1027 CGUIDialogPVRTimerSettings
* pThis
= static_cast<CGUIDialogPVRTimerSettings
*>(data
);
1032 std::vector
<std::pair
<std::string
, int>> values
;
1033 pThis
->m_timerType
->GetPreventDuplicateEpisodesValues(values
);
1034 std::transform(values
.cbegin(), values
.cend(), std::back_inserter(list
), [](const auto& value
) {
1035 return IntegerSettingOption(value
.first
, value
.second
);
1038 current
= pThis
->m_iPreventDupEpisodes
;
1041 CLog::LogF(LOGERROR
, "No dialog");
1044 void CGUIDialogPVRTimerSettings::WeekdaysFiller(const SettingConstPtr
& setting
,
1045 std::vector
<IntegerSettingOption
>& list
,
1049 CGUIDialogPVRTimerSettings
* pThis
= static_cast<CGUIDialogPVRTimerSettings
*>(data
);
1053 list
.emplace_back(g_localizeStrings
.Get(831), PVR_WEEKDAY_MONDAY
); // "Mondays"
1054 list
.emplace_back(g_localizeStrings
.Get(832), PVR_WEEKDAY_TUESDAY
); // "Tuesdays"
1055 list
.emplace_back(g_localizeStrings
.Get(833), PVR_WEEKDAY_WEDNESDAY
); // "Wednesdays"
1056 list
.emplace_back(g_localizeStrings
.Get(834), PVR_WEEKDAY_THURSDAY
); // "Thursdays"
1057 list
.emplace_back(g_localizeStrings
.Get(835), PVR_WEEKDAY_FRIDAY
); // "Fridays"
1058 list
.emplace_back(g_localizeStrings
.Get(836), PVR_WEEKDAY_SATURDAY
); // "Saturdays"
1059 list
.emplace_back(g_localizeStrings
.Get(837), PVR_WEEKDAY_SUNDAY
); // "Sundays"
1061 current
= pThis
->m_iWeekdays
;
1064 CLog::LogF(LOGERROR
, "No dialog");
1067 void CGUIDialogPVRTimerSettings::PrioritiesFiller(const SettingConstPtr
& setting
,
1068 std::vector
<IntegerSettingOption
>& list
,
1072 CGUIDialogPVRTimerSettings
* pThis
= static_cast<CGUIDialogPVRTimerSettings
*>(data
);
1077 std::vector
<std::pair
<std::string
, int>> values
;
1078 pThis
->m_timerType
->GetPriorityValues(values
);
1079 std::transform(values
.cbegin(), values
.cend(), std::back_inserter(list
), [](const auto& value
) {
1080 return IntegerSettingOption(value
.first
, value
.second
);
1083 current
= pThis
->m_iPriority
;
1085 auto it
= list
.begin();
1086 while (it
!= list
.end())
1088 if (it
->value
== current
)
1089 break; // value already in list
1094 if (it
== list
.end())
1096 // PVR backend supplied value is not in the list of predefined values. Insert it.
1097 list
.insert(it
, IntegerSettingOption(std::to_string(current
), current
));
1101 CLog::LogF(LOGERROR
, "No dialog");
1104 void CGUIDialogPVRTimerSettings::LifetimesFiller(const SettingConstPtr
& setting
,
1105 std::vector
<IntegerSettingOption
>& list
,
1109 CGUIDialogPVRTimerSettings
* pThis
= static_cast<CGUIDialogPVRTimerSettings
*>(data
);
1114 std::vector
<std::pair
<std::string
, int>> values
;
1115 pThis
->m_timerType
->GetLifetimeValues(values
);
1116 std::transform(values
.cbegin(), values
.cend(), std::back_inserter(list
), [](const auto& value
) {
1117 return IntegerSettingOption(value
.first
, value
.second
);
1120 current
= pThis
->m_iLifetime
;
1122 auto it
= list
.begin();
1123 while (it
!= list
.end())
1125 if (it
->value
== current
)
1126 break; // value already in list
1131 if (it
== list
.end())
1133 // PVR backend supplied value is not in the list of predefined values. Insert it.
1134 list
.insert(it
, IntegerSettingOption(
1135 StringUtils::Format(g_localizeStrings
.Get(17999), current
) /* {} days */,
1140 CLog::LogF(LOGERROR
, "No dialog");
1143 void CGUIDialogPVRTimerSettings::MaxRecordingsFiller(const SettingConstPtr
& setting
,
1144 std::vector
<IntegerSettingOption
>& list
,
1148 CGUIDialogPVRTimerSettings
* pThis
= static_cast<CGUIDialogPVRTimerSettings
*>(data
);
1153 std::vector
<std::pair
<std::string
, int>> values
;
1154 pThis
->m_timerType
->GetMaxRecordingsValues(values
);
1155 std::transform(values
.cbegin(), values
.cend(), std::back_inserter(list
), [](const auto& value
) {
1156 return IntegerSettingOption(value
.first
, value
.second
);
1159 current
= pThis
->m_iMaxRecordings
;
1161 auto it
= list
.begin();
1162 while (it
!= list
.end())
1164 if (it
->value
== current
)
1165 break; // value already in list
1170 if (it
== list
.end())
1172 // PVR backend supplied value is not in the list of predefined values. Insert it.
1173 list
.insert(it
, IntegerSettingOption(std::to_string(current
), current
));
1177 CLog::LogF(LOGERROR
, "No dialog");
1180 void CGUIDialogPVRTimerSettings::RecordingGroupFiller(const SettingConstPtr
& setting
,
1181 std::vector
<IntegerSettingOption
>& list
,
1185 CGUIDialogPVRTimerSettings
* pThis
= static_cast<CGUIDialogPVRTimerSettings
*>(data
);
1190 std::vector
<std::pair
<std::string
, int>> values
;
1191 pThis
->m_timerType
->GetRecordingGroupValues(values
);
1192 std::transform(values
.cbegin(), values
.cend(), std::back_inserter(list
), [](const auto& value
) {
1193 return IntegerSettingOption(value
.first
, value
.second
);
1196 current
= pThis
->m_iRecordingGroup
;
1199 CLog::LogF(LOGERROR
, "No dialog");
1202 void CGUIDialogPVRTimerSettings::MarginTimeFiller(const SettingConstPtr
& setting
,
1203 std::vector
<IntegerSettingOption
>& list
,
1207 CGUIDialogPVRTimerSettings
* pThis
= static_cast<CGUIDialogPVRTimerSettings
*>(data
);
1212 // Get global settings values
1213 CPVRSettings::MarginTimeFiller(setting
, list
, current
, data
);
1215 if (setting
->GetId() == SETTING_TMR_BEGIN_PRE
)
1216 current
= pThis
->m_iMarginStart
;
1218 current
= pThis
->m_iMarginEnd
;
1220 bool bInsertValue
= true;
1221 auto it
= list
.begin();
1222 while (it
!= list
.end())
1224 if (it
->value
== current
)
1226 bInsertValue
= false;
1227 break; // value already in list
1230 if (it
->value
> current
)
1238 // PVR backend supplied value is not in the list of predefined values. Insert it.
1239 list
.insert(it
, IntegerSettingOption(
1240 StringUtils::Format(g_localizeStrings
.Get(14044), current
) /* {} min */,
1245 CLog::LogF(LOGERROR
, "No dialog");
1248 std::string
CGUIDialogPVRTimerSettings::WeekdaysValueFormatter(const SettingConstPtr
& setting
)
1250 return CPVRTimerInfoTag::GetWeekdaysString(GetWeekdaysFromSetting(setting
), true, true);
1253 void CGUIDialogPVRTimerSettings::AddTypeDependentEnableCondition(
1254 const std::shared_ptr
<CSetting
>& setting
, const std::string
& identifier
)
1256 // Enable setting depending on read-only attribute of the selected timer type
1257 std::string
id(identifier
);
1258 id
.append(TYPE_DEP_ENABLE_COND_ID_POSTFIX
);
1259 AddCondition(setting
, id
, TypeReadOnlyCondition
, SettingDependencyType::Enable
, SETTING_TMR_TYPE
);
1262 bool CGUIDialogPVRTimerSettings::TypeReadOnlyCondition(const std::string
& condition
,
1263 const std::string
& value
,
1264 const SettingConstPtr
& setting
,
1267 if (setting
== NULL
)
1270 CGUIDialogPVRTimerSettings
* pThis
= static_cast<CGUIDialogPVRTimerSettings
*>(data
);
1273 CLog::LogF(LOGERROR
, "No dialog");
1277 if (!StringUtils::EqualsNoCase(value
, "true"))
1280 std::string
cond(condition
);
1281 cond
.erase(cond
.find(TYPE_DEP_ENABLE_COND_ID_POSTFIX
));
1283 // If only one type is available, disable type selector.
1284 if (pThis
->m_typeEntries
.size() == 1)
1286 if (cond
== SETTING_TMR_TYPE
)
1290 // For existing one time epg-based timers, disable editing of epg-filled data.
1291 if (!pThis
->m_bIsNewTimer
&& pThis
->m_timerType
->IsEpgBasedOnetime())
1293 if ((cond
== SETTING_TMR_NAME
) || (cond
== SETTING_TMR_CHANNEL
) ||
1294 (cond
== SETTING_TMR_START_DAY
) || (cond
== SETTING_TMR_END_DAY
) ||
1295 (cond
== SETTING_TMR_BEGIN
) || (cond
== SETTING_TMR_END
))
1299 /* Always enable enable/disable, if supported by the timer type. */
1300 if (pThis
->m_timerType
->SupportsEnableDisable() && !pThis
->m_timerInfoTag
->IsBroken())
1302 if (cond
== SETTING_TMR_ACTIVE
)
1306 // Let the PVR client decide...
1307 int idx
= std::static_pointer_cast
<const CSettingInt
>(setting
)->GetValue();
1308 const auto entry
= pThis
->m_typeEntries
.find(idx
);
1309 if (entry
!= pThis
->m_typeEntries
.end())
1310 return !entry
->second
->IsReadOnly();
1312 CLog::LogF(LOGERROR
, "No type entry");
1317 void CGUIDialogPVRTimerSettings::AddTypeDependentVisibilityCondition(
1318 const std::shared_ptr
<CSetting
>& setting
, const std::string
& identifier
)
1320 // Show or hide setting depending on attributes of the selected timer type
1321 std::string
id(identifier
);
1322 id
.append(TYPE_DEP_VISIBI_COND_ID_POSTFIX
);
1323 AddCondition(setting
, id
, TypeSupportsCondition
, SettingDependencyType::Visible
,
1327 bool CGUIDialogPVRTimerSettings::TypeSupportsCondition(const std::string
& condition
,
1328 const std::string
& value
,
1329 const SettingConstPtr
& setting
,
1332 if (setting
== NULL
)
1335 CGUIDialogPVRTimerSettings
* pThis
= static_cast<CGUIDialogPVRTimerSettings
*>(data
);
1338 CLog::LogF(LOGERROR
, "No dialog");
1342 if (!StringUtils::EqualsNoCase(value
, "true"))
1345 int idx
= std::static_pointer_cast
<const CSettingInt
>(setting
)->GetValue();
1346 const auto entry
= pThis
->m_typeEntries
.find(idx
);
1347 if (entry
!= pThis
->m_typeEntries
.end())
1349 std::string
cond(condition
);
1350 cond
.erase(cond
.find(TYPE_DEP_VISIBI_COND_ID_POSTFIX
));
1352 if (cond
== SETTING_TMR_EPGSEARCH
)
1353 return entry
->second
->SupportsEpgTitleMatch() || entry
->second
->SupportsEpgFulltextMatch();
1354 else if (cond
== SETTING_TMR_FULLTEXT
)
1355 return entry
->second
->SupportsEpgFulltextMatch();
1356 else if (cond
== SETTING_TMR_ACTIVE
)
1357 return entry
->second
->SupportsEnableDisable();
1358 else if (cond
== SETTING_TMR_CHANNEL
)
1359 return entry
->second
->SupportsChannels();
1360 else if (cond
== SETTING_TMR_START_ANYTIME
)
1361 return entry
->second
->SupportsStartAnyTime() && entry
->second
->IsEpgBased();
1362 else if (cond
== SETTING_TMR_END_ANYTIME
)
1363 return entry
->second
->SupportsEndAnyTime() && entry
->second
->IsEpgBased();
1364 else if (cond
== SETTING_TMR_START_DAY
)
1365 return entry
->second
->SupportsStartTime() && entry
->second
->IsOnetime();
1366 else if (cond
== SETTING_TMR_END_DAY
)
1367 return entry
->second
->SupportsEndTime() && entry
->second
->IsOnetime();
1368 else if (cond
== SETTING_TMR_BEGIN
)
1369 return entry
->second
->SupportsStartTime();
1370 else if (cond
== SETTING_TMR_END
)
1371 return entry
->second
->SupportsEndTime();
1372 else if (cond
== SETTING_TMR_WEEKDAYS
)
1373 return entry
->second
->SupportsWeekdays();
1374 else if (cond
== SETTING_TMR_FIRST_DAY
)
1375 return entry
->second
->SupportsFirstDay();
1376 else if (cond
== SETTING_TMR_NEW_EPISODES
)
1377 return entry
->second
->SupportsRecordOnlyNewEpisodes();
1378 else if (cond
== SETTING_TMR_BEGIN_PRE
)
1379 return entry
->second
->SupportsStartMargin();
1380 else if (cond
== SETTING_TMR_END_POST
)
1381 return entry
->second
->SupportsEndMargin();
1382 else if (cond
== SETTING_TMR_PRIORITY
)
1383 return entry
->second
->SupportsPriority();
1384 else if (cond
== SETTING_TMR_LIFETIME
)
1385 return entry
->second
->SupportsLifetime();
1386 else if (cond
== SETTING_TMR_MAX_REC
)
1387 return entry
->second
->SupportsMaxRecordings();
1388 else if (cond
== SETTING_TMR_DIR
)
1389 return entry
->second
->SupportsRecordingFolders();
1390 else if (cond
== SETTING_TMR_REC_GROUP
)
1391 return entry
->second
->SupportsRecordingGroup();
1393 CLog::LogF(LOGERROR
, "Unknown condition");
1397 CLog::LogF(LOGERROR
, "No type entry");
1402 void CGUIDialogPVRTimerSettings::AddStartAnytimeDependentVisibilityCondition(
1403 const std::shared_ptr
<CSetting
>& setting
, const std::string
& identifier
)
1405 // Show or hide setting depending on value of setting "any time"
1406 std::string
id(identifier
);
1407 id
.append(START_ANYTIME_DEP_VISIBI_COND_ID_POSTFIX
);
1408 AddCondition(setting
, id
, StartAnytimeSetCondition
, SettingDependencyType::Visible
,
1409 SETTING_TMR_START_ANYTIME
);
1412 bool CGUIDialogPVRTimerSettings::StartAnytimeSetCondition(const std::string
& condition
,
1413 const std::string
& value
,
1414 const SettingConstPtr
& setting
,
1417 if (setting
== NULL
)
1420 CGUIDialogPVRTimerSettings
* pThis
= static_cast<CGUIDialogPVRTimerSettings
*>(data
);
1423 CLog::LogF(LOGERROR
, "No dialog");
1427 if (!StringUtils::EqualsNoCase(value
, "true"))
1430 // "any time" setting is only relevant for epg-based timers.
1431 if (!pThis
->m_timerType
->IsEpgBased())
1434 // If 'Start anytime' option isn't supported, don't hide start time
1435 if (!pThis
->m_timerType
->SupportsStartAnyTime())
1438 std::string
cond(condition
);
1439 cond
.erase(cond
.find(START_ANYTIME_DEP_VISIBI_COND_ID_POSTFIX
));
1441 if ((cond
== SETTING_TMR_START_DAY
) || (cond
== SETTING_TMR_BEGIN
))
1443 bool bAnytime
= std::static_pointer_cast
<const CSettingBool
>(setting
)->GetValue();
1449 void CGUIDialogPVRTimerSettings::AddEndAnytimeDependentVisibilityCondition(
1450 const std::shared_ptr
<CSetting
>& setting
, const std::string
& identifier
)
1452 // Show or hide setting depending on value of setting "any time"
1453 std::string
id(identifier
);
1454 id
.append(END_ANYTIME_DEP_VISIBI_COND_ID_POSTFIX
);
1455 AddCondition(setting
, id
, EndAnytimeSetCondition
, SettingDependencyType::Visible
,
1456 SETTING_TMR_END_ANYTIME
);
1459 bool CGUIDialogPVRTimerSettings::EndAnytimeSetCondition(const std::string
& condition
,
1460 const std::string
& value
,
1461 const SettingConstPtr
& setting
,
1464 if (setting
== NULL
)
1467 CGUIDialogPVRTimerSettings
* pThis
= static_cast<CGUIDialogPVRTimerSettings
*>(data
);
1470 CLog::LogF(LOGERROR
, "No dialog");
1474 if (!StringUtils::EqualsNoCase(value
, "true"))
1477 // "any time" setting is only relevant for epg-based timers.
1478 if (!pThis
->m_timerType
->IsEpgBased())
1481 // If 'End anytime' option isn't supported, don't hide end time
1482 if (!pThis
->m_timerType
->SupportsEndAnyTime())
1485 std::string
cond(condition
);
1486 cond
.erase(cond
.find(END_ANYTIME_DEP_VISIBI_COND_ID_POSTFIX
));
1488 if ((cond
== SETTING_TMR_END_DAY
) || (cond
== SETTING_TMR_END
))
1490 bool bAnytime
= std::static_pointer_cast
<const CSettingBool
>(setting
)->GetValue();