/
GUIDialogPVRTimerSettings.cpp
1308 lines (1134 loc) · 46 KB
/
GUIDialogPVRTimerSettings.cpp
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* 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.
*/
#include "GUIDialogPVRTimerSettings.h"
#include "FileItem.h"
#include "ServiceBroker.h"
#include "addons/PVRClient.h"
#include "dialogs/GUIDialogNumeric.h"
#include "guilib/GUIWindowManager.h"
#include "guilib/LocalizeStrings.h"
#include "settings/SettingUtils.h"
#include "settings/lib/Setting.h"
#include "settings/lib/SettingsManager.h"
#include "settings/windows/GUIControlSettings.h"
#include "utils/StringUtils.h"
#include "utils/Variant.h"
#include "utils/log.h"
#include "pvr/PVRManager.h"
#include "pvr/PVRSettings.h"
#include "pvr/channels/PVRChannelGroupsContainer.h"
#include "pvr/epg/EpgInfoTag.h"
#include "pvr/timers/PVRTimerInfoTag.h"
#include "pvr/timers/PVRTimerType.h"
using namespace PVR;
#define SETTING_TMR_TYPE "timer.type"
#define SETTING_TMR_ACTIVE "timer.active"
#define SETTING_TMR_NAME "timer.name"
#define SETTING_TMR_EPGSEARCH "timer.epgsearch"
#define SETTING_TMR_FULLTEXT "timer.fulltext"
#define SETTING_TMR_CHANNEL "timer.channel"
#define SETTING_TMR_START_ANYTIME "timer.startanytime"
#define SETTING_TMR_END_ANYTIME "timer.endanytime"
#define SETTING_TMR_START_DAY "timer.startday"
#define SETTING_TMR_END_DAY "timer.endday"
#define SETTING_TMR_BEGIN "timer.begin"
#define SETTING_TMR_END "timer.end"
#define SETTING_TMR_WEEKDAYS "timer.weekdays"
#define SETTING_TMR_FIRST_DAY "timer.firstday"
#define SETTING_TMR_NEW_EPISODES "timer.newepisodes"
#define SETTING_TMR_BEGIN_PRE "timer.startmargin"
#define SETTING_TMR_END_POST "timer.endmargin"
#define SETTING_TMR_PRIORITY "timer.priority"
#define SETTING_TMR_LIFETIME "timer.lifetime"
#define SETTING_TMR_MAX_REC "timer.maxrecordings"
#define SETTING_TMR_DIR "timer.directory"
#define SETTING_TMR_REC_GROUP "timer.recgroup"
#define TYPE_DEP_VISIBI_COND_ID_POSTFIX "visibi.typedep"
#define TYPE_DEP_ENABLE_COND_ID_POSTFIX "enable.typedep"
#define CHANNEL_DEP_VISIBI_COND_ID_POSTFIX "visibi.channeldep"
#define START_ANYTIME_DEP_VISIBI_COND_ID_POSTFIX "visibi.startanytimedep"
#define END_ANYTIME_DEP_VISIBI_COND_ID_POSTFIX "visibi.endanytimedep"
#define ENTRY_ANY_CHANNEL (-1)
CGUIDialogPVRTimerSettings::CGUIDialogPVRTimerSettings() :
CGUIDialogSettingsManualBase(WINDOW_DIALOG_PVR_TIMER_SETTING, "DialogSettings.xml"),
m_iWeekdays(PVR_WEEKDAY_NONE)
{
m_loadType = LOAD_EVERY_TIME;
}
CGUIDialogPVRTimerSettings::~CGUIDialogPVRTimerSettings() = default;
bool CGUIDialogPVRTimerSettings::CanBeActivated() const
{
if (!m_timerInfoTag)
{
CLog::LogF(LOGERROR, "No timer info tag");
return false;
}
return true;
}
void CGUIDialogPVRTimerSettings::SetTimer(const CPVRTimerInfoTagPtr &timer)
{
if (!timer)
{
CLog::LogF(LOGERROR, "No timer given");
return;
}
m_timerInfoTag = timer;
// Copy data we need from tag. Do not modify the tag itself until Save()!
m_timerType = m_timerInfoTag->GetTimerType();
m_bIsRadio = m_timerInfoTag->m_bIsRadio;
m_bIsNewTimer = m_timerInfoTag->m_iClientIndex == PVR_TIMER_NO_CLIENT_INDEX;
m_bTimerActive = m_bIsNewTimer || !m_timerType->SupportsEnableDisable() || !(m_timerInfoTag->m_state == PVR_TIMER_STATE_DISABLED);
m_bStartAnyTime = m_bIsNewTimer || !m_timerType->SupportsStartAnyTime() || m_timerInfoTag->m_bStartAnyTime;
m_bEndAnyTime = m_bIsNewTimer || !m_timerType->SupportsEndAnyTime() || m_timerInfoTag->m_bEndAnyTime;
m_strTitle = m_timerInfoTag->m_strTitle;
m_startLocalTime = m_timerInfoTag->StartAsLocalTime();
m_endLocalTime = m_timerInfoTag->EndAsLocalTime();
if (m_bIsNewTimer && (m_startLocalTime == m_endLocalTime))
m_endLocalTime += CDateTimeSpan(0, 2, 0, 0);
m_timerStartTimeStr = m_startLocalTime.GetAsLocalizedTime("", false);
m_timerEndTimeStr = m_endLocalTime.GetAsLocalizedTime("", false);
m_firstDayLocalTime = m_timerInfoTag->FirstDayAsLocalTime();
m_strEpgSearchString = m_timerInfoTag->m_strEpgSearchString;
if ((m_bIsNewTimer || !m_timerType->SupportsEpgTitleMatch()) && m_strEpgSearchString.empty())
m_strEpgSearchString = m_strTitle;
m_bFullTextEpgSearch = m_timerInfoTag->m_bFullTextEpgSearch;
m_iWeekdays = m_timerInfoTag->m_iWeekdays;
if ((m_bIsNewTimer || !m_timerType->SupportsWeekdays()) && m_iWeekdays == PVR_WEEKDAY_NONE)
m_iWeekdays = PVR_WEEKDAY_ALLDAYS;
m_iPreventDupEpisodes = m_timerInfoTag->m_iPreventDupEpisodes;
m_iMarginStart = m_timerInfoTag->m_iMarginStart;
m_iMarginEnd = m_timerInfoTag->m_iMarginEnd;
m_iPriority = m_timerInfoTag->m_iPriority;
m_iLifetime = m_timerInfoTag->m_iLifetime;
m_iMaxRecordings = m_timerInfoTag->m_iMaxRecordings;
if (m_bIsNewTimer && m_timerInfoTag->m_strDirectory.empty() && m_timerType->SupportsRecordingFolders())
m_strDirectory = m_strTitle;
else
m_strDirectory = m_timerInfoTag->m_strDirectory;
m_iRecordingGroup = m_timerInfoTag->m_iRecordingGroup;
InitializeChannelsList();
InitializeTypesList();
// Channel
m_channel = ChannelDescriptor();
if (m_timerInfoTag->m_iClientChannelUid == PVR_CHANNEL_INVALID_UID)
{
bool bChannelSet(false);
if (m_timerType->SupportsAnyChannel())
{
// Select "Any channel"
const auto it = m_channelEntries.find(ENTRY_ANY_CHANNEL);
if (it != m_channelEntries.end())
{
m_channel = it->second;
bChannelSet = true;
}
}
else if (m_bIsNewTimer)
{
// Select first real (not "Any channel") entry.
for (const auto &channel : m_channelEntries)
{
if (channel.second.channelUid != PVR_CHANNEL_INVALID_UID)
{
m_channel = channel.second;
bChannelSet = true;
break;
}
}
}
if (!bChannelSet)
CLog::LogF(LOGERROR, "Unable to map PVR_CHANNEL_INVALID_UID to channel entry!");
}
else
{
// Find matching channel entry
bool bChannelSet(false);
for (const auto &channel : m_channelEntries)
{
if ((channel.second.channelUid == m_timerInfoTag->m_iClientChannelUid) &&
(channel.second.clientId == m_timerInfoTag->m_iClientId))
{
m_channel = channel.second;
bChannelSet = true;
break;
}
}
if (!bChannelSet)
CLog::LogF(LOGERROR, "Unable to map channel uid to channel entry!");
}
}
void CGUIDialogPVRTimerSettings::SetupView()
{
CGUIDialogSettingsManualBase::SetupView();
SetHeading(19065);
SET_CONTROL_HIDDEN(CONTROL_SETTINGS_CUSTOM_BUTTON);
SET_CONTROL_LABEL(CONTROL_SETTINGS_OKAY_BUTTON, 186);
SET_CONTROL_LABEL(CONTROL_SETTINGS_CANCEL_BUTTON, 222);
SetButtonLabels();
}
void CGUIDialogPVRTimerSettings::InitializeSettings()
{
CGUIDialogSettingsManualBase::InitializeSettings();
const std::shared_ptr<CSettingCategory> category = AddCategory("pvrtimersettings", -1);
if (category == NULL)
{
CLog::LogF(LOGERROR, "Unable to add settings category");
return;
}
const std::shared_ptr<CSettingGroup> group = AddGroup(category);
if (group == NULL)
{
CLog::LogF(LOGERROR, "Unable to add settings group");
return;
}
std::shared_ptr<CSetting> setting = NULL;
// Timer type
setting = AddList(group, SETTING_TMR_TYPE, 803, SettingLevel::Basic, 0, TypesFiller, 803);
AddTypeDependentEnableCondition(setting, SETTING_TMR_TYPE);
// Timer enabled/disabled
setting = AddToggle(group, SETTING_TMR_ACTIVE, 305, SettingLevel::Basic, m_bTimerActive);
AddTypeDependentVisibilityCondition(setting, SETTING_TMR_ACTIVE);
AddTypeDependentEnableCondition(setting, SETTING_TMR_ACTIVE);
// Name
setting = AddEdit(group, SETTING_TMR_NAME, 19075, SettingLevel::Basic, m_strTitle, true, false, 19097);
AddTypeDependentEnableCondition(setting, SETTING_TMR_NAME);
// epg search string (only for epg-based timer rules)
setting = AddEdit(group, SETTING_TMR_EPGSEARCH, 804, SettingLevel::Basic, m_strEpgSearchString, true, false, 805);
AddTypeDependentVisibilityCondition(setting, SETTING_TMR_EPGSEARCH);
AddTypeDependentEnableCondition(setting, SETTING_TMR_EPGSEARCH);
// epg fulltext search (only for epg-based timer rules)
setting = AddToggle(group, SETTING_TMR_FULLTEXT, 806, SettingLevel::Basic, m_bFullTextEpgSearch);
AddTypeDependentVisibilityCondition(setting, SETTING_TMR_FULLTEXT);
AddTypeDependentEnableCondition(setting, SETTING_TMR_FULLTEXT);
// Channel
setting = AddList(group, SETTING_TMR_CHANNEL, 19078, SettingLevel::Basic, 0, ChannelsFiller, 19078);
AddTypeDependentVisibilityCondition(setting, SETTING_TMR_CHANNEL);
AddTypeDependentEnableCondition(setting, SETTING_TMR_CHANNEL);
// Days of week (only for timer rules)
std::vector<int> weekdaysPreselect;
if (m_iWeekdays & PVR_WEEKDAY_MONDAY)
weekdaysPreselect.push_back(PVR_WEEKDAY_MONDAY);
if (m_iWeekdays & PVR_WEEKDAY_TUESDAY)
weekdaysPreselect.push_back(PVR_WEEKDAY_TUESDAY);
if (m_iWeekdays & PVR_WEEKDAY_WEDNESDAY)
weekdaysPreselect.push_back(PVR_WEEKDAY_WEDNESDAY);
if (m_iWeekdays & PVR_WEEKDAY_THURSDAY)
weekdaysPreselect.push_back(PVR_WEEKDAY_THURSDAY);
if (m_iWeekdays & PVR_WEEKDAY_FRIDAY)
weekdaysPreselect.push_back(PVR_WEEKDAY_FRIDAY);
if (m_iWeekdays & PVR_WEEKDAY_SATURDAY)
weekdaysPreselect.push_back(PVR_WEEKDAY_SATURDAY);
if (m_iWeekdays & PVR_WEEKDAY_SUNDAY)
weekdaysPreselect.push_back(PVR_WEEKDAY_SUNDAY);
setting = AddList(group, SETTING_TMR_WEEKDAYS, 19079, SettingLevel::Basic, weekdaysPreselect, WeekdaysFiller, 19079, 1, -1, true, -1, WeekdaysValueFormatter);
AddTypeDependentVisibilityCondition(setting, SETTING_TMR_WEEKDAYS);
AddTypeDependentEnableCondition(setting, SETTING_TMR_WEEKDAYS);
// "Start any time" (only for timer rules)
setting = AddToggle(group, SETTING_TMR_START_ANYTIME, 810, SettingLevel::Basic, m_bStartAnyTime);
AddTypeDependentVisibilityCondition(setting, SETTING_TMR_START_ANYTIME);
AddTypeDependentEnableCondition(setting, SETTING_TMR_START_ANYTIME);
// Start day (day + month + year only, no hours, minutes)
setting = AddSpinner(group, SETTING_TMR_START_DAY, 19128, SettingLevel::Basic, GetDateAsIndex(m_startLocalTime), DaysFiller);
AddTypeDependentVisibilityCondition(setting, SETTING_TMR_START_DAY);
AddTypeDependentEnableCondition(setting, SETTING_TMR_START_DAY);
AddStartAnytimeDependentVisibilityCondition(setting, SETTING_TMR_START_DAY);
// Start time (hours + minutes only, no day, month, year)
setting = AddButton(group, SETTING_TMR_BEGIN, 19126, SettingLevel::Basic);
AddTypeDependentVisibilityCondition(setting, SETTING_TMR_BEGIN);
AddTypeDependentEnableCondition(setting, SETTING_TMR_BEGIN);
AddStartAnytimeDependentVisibilityCondition(setting, SETTING_TMR_BEGIN);
// "End any time" (only for timer rules)
setting = AddToggle(group, SETTING_TMR_END_ANYTIME, 817, SettingLevel::Basic, m_bEndAnyTime);
AddTypeDependentVisibilityCondition(setting, SETTING_TMR_END_ANYTIME);
AddTypeDependentEnableCondition(setting, SETTING_TMR_END_ANYTIME);
// End day (day + month + year only, no hours, minutes)
setting = AddSpinner(group, SETTING_TMR_END_DAY, 19129, SettingLevel::Basic, GetDateAsIndex(m_endLocalTime), DaysFiller);
AddTypeDependentVisibilityCondition(setting, SETTING_TMR_END_DAY);
AddTypeDependentEnableCondition(setting, SETTING_TMR_END_DAY);
AddEndAnytimeDependentVisibilityCondition(setting, SETTING_TMR_END_DAY);
// End time (hours + minutes only, no day, month, year)
setting = AddButton(group, SETTING_TMR_END, 19127, SettingLevel::Basic);
AddTypeDependentVisibilityCondition(setting, SETTING_TMR_END);
AddTypeDependentEnableCondition(setting, SETTING_TMR_END);
AddEndAnytimeDependentVisibilityCondition(setting, SETTING_TMR_END);
// First day (only for timer rules)
setting = AddSpinner(group, SETTING_TMR_FIRST_DAY, 19084, SettingLevel::Basic, GetDateAsIndex(m_firstDayLocalTime), DaysFiller);
AddTypeDependentVisibilityCondition(setting, SETTING_TMR_FIRST_DAY);
AddTypeDependentEnableCondition(setting, SETTING_TMR_FIRST_DAY);
// "Prevent duplicate episodes" (only for timer rules)
setting = AddList(group, SETTING_TMR_NEW_EPISODES, 812, SettingLevel::Basic, m_iPreventDupEpisodes, DupEpisodesFiller, 812);
AddTypeDependentVisibilityCondition(setting, SETTING_TMR_NEW_EPISODES);
AddTypeDependentEnableCondition(setting, SETTING_TMR_NEW_EPISODES);
// Pre and post record time
setting = AddList(group, SETTING_TMR_BEGIN_PRE, 813, SettingLevel::Basic, m_iMarginStart, MarginTimeFiller, 813);
AddTypeDependentVisibilityCondition(setting, SETTING_TMR_BEGIN_PRE);
AddTypeDependentEnableCondition(setting, SETTING_TMR_BEGIN_PRE);
setting = AddList(group, SETTING_TMR_END_POST, 814, SettingLevel::Basic, m_iMarginEnd, MarginTimeFiller, 814);
AddTypeDependentVisibilityCondition(setting, SETTING_TMR_END_POST);
AddTypeDependentEnableCondition(setting, SETTING_TMR_END_POST);
// Priority
setting = AddList(group, SETTING_TMR_PRIORITY, 19082, SettingLevel::Basic, m_iPriority, PrioritiesFiller, 19082);
AddTypeDependentVisibilityCondition(setting, SETTING_TMR_PRIORITY);
AddTypeDependentEnableCondition(setting, SETTING_TMR_PRIORITY);
// Lifetime
setting = AddList(group, SETTING_TMR_LIFETIME, 19083, SettingLevel::Basic, m_iLifetime, LifetimesFiller, 19083);
AddTypeDependentVisibilityCondition(setting, SETTING_TMR_LIFETIME);
AddTypeDependentEnableCondition(setting, SETTING_TMR_LIFETIME);
// MaxRecordings
setting = AddList(group, SETTING_TMR_MAX_REC, 818, SettingLevel::Basic, m_iMaxRecordings, MaxRecordingsFiller, 818);
AddTypeDependentVisibilityCondition(setting, SETTING_TMR_MAX_REC);
AddTypeDependentEnableCondition(setting, SETTING_TMR_MAX_REC);
// Recording folder
setting = AddEdit(group, SETTING_TMR_DIR, 19076, SettingLevel::Basic, m_strDirectory, true, false, 19104);
AddTypeDependentVisibilityCondition(setting, SETTING_TMR_DIR);
AddTypeDependentEnableCondition(setting, SETTING_TMR_DIR);
// Recording group
setting = AddList(group, SETTING_TMR_REC_GROUP, 811, SettingLevel::Basic, m_iRecordingGroup, RecordingGroupFiller, 811);
AddTypeDependentVisibilityCondition(setting, SETTING_TMR_REC_GROUP);
AddTypeDependentEnableCondition(setting, SETTING_TMR_REC_GROUP);
}
int CGUIDialogPVRTimerSettings::GetWeekdaysFromSetting(SettingConstPtr setting)
{
std::shared_ptr<const CSettingList> settingList = std::static_pointer_cast<const CSettingList>(setting);
if (settingList->GetElementType() != SettingType::Integer)
{
CLog::LogF(LOGERROR, "Wrong weekdays element type");
return 0;
}
int weekdays = 0;
std::vector<CVariant> list = CSettingUtils::GetList(settingList);
for (const auto &value : list)
{
if (!value.isInteger())
{
CLog::LogF(LOGERROR, "Wrong weekdays value type");
return 0;
}
weekdays += static_cast<int>(value.asInteger());
}
return weekdays;
}
void CGUIDialogPVRTimerSettings::OnSettingChanged(std::shared_ptr<const CSetting> setting)
{
if (setting == NULL)
{
CLog::LogF(LOGERROR, "No setting");
return;
}
CGUIDialogSettingsManualBase::OnSettingChanged(setting);
const std::string &settingId = setting->GetId();
if (settingId == SETTING_TMR_TYPE)
{
int idx = std::static_pointer_cast<const CSettingInt>(setting)->GetValue();
const auto it = m_typeEntries.find(idx);
if (it != m_typeEntries.end())
{
m_timerType = it->second;
if (m_timerType->IsTimerRule() && (m_iWeekdays == PVR_WEEKDAY_ALLDAYS))
SetButtonLabels(); // update "Any day" vs. "Every day"
}
else
{
CLog::LogF(LOGERROR, "Unable to get 'type' value");
}
}
else if (settingId == SETTING_TMR_ACTIVE)
{
m_bTimerActive = std::static_pointer_cast<const CSettingBool>(setting)->GetValue();
}
else if (settingId == SETTING_TMR_NAME)
{
m_strTitle = std::static_pointer_cast<const CSettingString>(setting)->GetValue();
}
else if (settingId == SETTING_TMR_EPGSEARCH)
{
m_strEpgSearchString = std::static_pointer_cast<const CSettingString>(setting)->GetValue();
}
else if (settingId == SETTING_TMR_FULLTEXT)
{
m_bFullTextEpgSearch = std::static_pointer_cast<const CSettingBool>(setting)->GetValue();
}
else if (settingId == SETTING_TMR_CHANNEL)
{
int idx = std::static_pointer_cast<const CSettingInt>(setting)->GetValue();
const auto it = m_channelEntries.find(idx);
if (it != m_channelEntries.end())
{
m_channel = it->second;
}
else
{
CLog::LogF(LOGERROR, "Unable to get 'type' value");
}
}
else if (settingId == SETTING_TMR_WEEKDAYS)
{
m_iWeekdays = GetWeekdaysFromSetting(setting);
}
else if (settingId == SETTING_TMR_START_ANYTIME)
{
m_bStartAnyTime = std::static_pointer_cast<const CSettingBool>(setting)->GetValue();
}
else if (settingId == SETTING_TMR_END_ANYTIME)
{
m_bEndAnyTime = std::static_pointer_cast<const CSettingBool>(setting)->GetValue();
}
else if (settingId == SETTING_TMR_START_DAY)
{
SetDateFromIndex(m_startLocalTime, std::static_pointer_cast<const CSettingInt>(setting)->GetValue());
}
else if (settingId == SETTING_TMR_END_DAY)
{
SetDateFromIndex(m_endLocalTime, std::static_pointer_cast<const CSettingInt>(setting)->GetValue());
}
else if (settingId == SETTING_TMR_FIRST_DAY)
{
SetDateFromIndex(m_firstDayLocalTime, std::static_pointer_cast<const CSettingInt>(setting)->GetValue());
}
else if (settingId == SETTING_TMR_NEW_EPISODES)
{
m_iPreventDupEpisodes = std::static_pointer_cast<const CSettingInt>(setting)->GetValue();
}
else if (settingId == SETTING_TMR_BEGIN_PRE)
{
m_iMarginStart = std::static_pointer_cast<const CSettingInt>(setting)->GetValue();
}
else if (settingId == SETTING_TMR_END_POST)
{
m_iMarginEnd = std::static_pointer_cast<const CSettingInt>(setting)->GetValue();
}
else if (settingId == SETTING_TMR_PRIORITY)
{
m_iPriority = std::static_pointer_cast<const CSettingInt>(setting)->GetValue();
}
else if (settingId == SETTING_TMR_LIFETIME)
{
m_iLifetime = std::static_pointer_cast<const CSettingInt>(setting)->GetValue();
}
else if (settingId == SETTING_TMR_MAX_REC)
{
m_iMaxRecordings = std::static_pointer_cast<const CSettingInt>(setting)->GetValue();
}
else if (settingId == SETTING_TMR_DIR)
{
m_strDirectory = std::static_pointer_cast<const CSettingString>(setting)->GetValue();
}
else if (settingId == SETTING_TMR_REC_GROUP)
{
m_iRecordingGroup = std::static_pointer_cast<const CSettingInt>(setting)->GetValue();
}
}
void CGUIDialogPVRTimerSettings::OnSettingAction(std::shared_ptr<const CSetting> setting)
{
if (setting == NULL)
{
CLog::LogF(LOGERROR, "No setting");
return;
}
CGUIDialogSettingsManualBase::OnSettingAction(setting);
const std::string &settingId = setting->GetId();
if (settingId == SETTING_TMR_BEGIN)
{
SYSTEMTIME timerStartTime;
m_startLocalTime.GetAsSystemTime(timerStartTime);
if (CGUIDialogNumeric::ShowAndGetTime(timerStartTime, g_localizeStrings.Get(14066)))
{
SetTimeFromSystemTime(m_startLocalTime, timerStartTime);
m_timerStartTimeStr = m_startLocalTime.GetAsLocalizedTime("", false);
SetButtonLabels();
}
}
else if (settingId == SETTING_TMR_END)
{
SYSTEMTIME timerEndTime;
m_endLocalTime.GetAsSystemTime(timerEndTime);
if (CGUIDialogNumeric::ShowAndGetTime(timerEndTime, g_localizeStrings.Get(14066)))
{
SetTimeFromSystemTime(m_endLocalTime, timerEndTime);
m_timerEndTimeStr = m_endLocalTime.GetAsLocalizedTime("", false);
SetButtonLabels();
}
}
}
void CGUIDialogPVRTimerSettings::Save()
{
// Timer type
m_timerInfoTag->SetTimerType(m_timerType);
// Timer active/inactive
m_timerInfoTag->m_state = m_bTimerActive ? PVR_TIMER_STATE_SCHEDULED : PVR_TIMER_STATE_DISABLED;
// Name
m_timerInfoTag->m_strTitle = m_strTitle;
// epg search string (only for epg-based timer rules)
m_timerInfoTag->m_strEpgSearchString = m_strEpgSearchString;
// epg fulltext search, instead of just title match. (only for epg-based timer rules)
m_timerInfoTag->m_bFullTextEpgSearch = m_bFullTextEpgSearch;
// Channel
CPVRChannelPtr channel(CServiceBroker::GetPVRManager().ChannelGroups()->GetByUniqueID(m_channel.channelUid, m_channel.clientId));
if (channel)
{
m_timerInfoTag->m_iClientChannelUid = channel->UniqueID();
m_timerInfoTag->m_iClientId = channel->ClientID();
m_timerInfoTag->m_bIsRadio = channel->IsRadio();
m_timerInfoTag->UpdateChannel();
}
else
{
if (m_timerType->IsOnetime() || m_timerType->IsManual())
CLog::LogF(LOGERROR, "No channel");
m_timerInfoTag->m_iClientChannelUid = m_channel.channelUid;
m_timerInfoTag->m_iClientId = m_timerType->GetClientId();
}
if (m_timerType->SupportsStartAnyTime() && m_timerType->IsEpgBased()) // Start anytime toggle is displayed
m_timerInfoTag->m_bStartAnyTime = m_bStartAnyTime;
else
m_bStartAnyTime = false; // Assume start time change needs checking for
if (m_timerType->SupportsEndAnyTime() && m_timerType->IsEpgBased()) // End anytime toggle is displayed
m_timerInfoTag->m_bEndAnyTime = m_bEndAnyTime;
else
m_bEndAnyTime = false; // Assume end time change needs checking for
// Begin and end time
if (!m_bStartAnyTime && !m_bEndAnyTime)
{
if (m_timerType->SupportsStartTime() && // has start clock entry
m_timerType->SupportsEndTime() && // and end clock entry
m_timerType->IsTimerRule()) // but no associated start/end day spinners
{
if (m_endLocalTime < m_startLocalTime) // And the end clock is earlier than the start clock
{
CLog::LogFC(LOGDEBUG, LOGPVR, "End before start, adding a day.");
m_endLocalTime += CDateTimeSpan(1, 0, 0, 0);
if (m_endLocalTime < m_startLocalTime)
{
CLog::Log(LOGWARNING, "Timer settings dialog: End before start. Setting end time to start time.");
m_endLocalTime = m_startLocalTime;
}
}
else if (m_endLocalTime > (m_startLocalTime + CDateTimeSpan(1, 0, 0, 0))) // Or the duration is more than a day
{
CLog::LogFC(LOGDEBUG, LOGPVR, "End > 1 day after start, removing a day.");
m_endLocalTime -= CDateTimeSpan(1, 0, 0, 0);
if (m_endLocalTime > (m_startLocalTime + CDateTimeSpan(1, 0, 0, 0)))
{
CLog::Log(LOGWARNING, "Timer settings dialog: End > 1 day after start. Setting end time to start time.");
m_endLocalTime = m_startLocalTime;
}
}
}
else if (m_endLocalTime < m_startLocalTime) // Assume the user knows what they are doing, but log a warning just in case
{
CLog::Log(LOGWARNING, "Timer settings dialog: Specified recording end time < start time: expect errors!");
}
m_timerInfoTag->SetStartFromLocalTime(m_startLocalTime);
m_timerInfoTag->SetEndFromLocalTime(m_endLocalTime);
}
else if (!m_bStartAnyTime)
m_timerInfoTag->SetStartFromLocalTime(m_startLocalTime);
else if (!m_bEndAnyTime)
m_timerInfoTag->SetEndFromLocalTime(m_endLocalTime);
// Days of week (only for timer rules)
if (m_timerType->IsTimerRule())
m_timerInfoTag->m_iWeekdays = m_iWeekdays;
else
m_timerInfoTag->m_iWeekdays = PVR_WEEKDAY_NONE;
// First day (only for timer rules)
m_timerInfoTag->SetFirstDayFromLocalTime(m_firstDayLocalTime);
// "New episodes only" (only for timer rules)
m_timerInfoTag->m_iPreventDupEpisodes = m_iPreventDupEpisodes;
// Pre and post record time
m_timerInfoTag->m_iMarginStart = m_iMarginStart;
m_timerInfoTag->m_iMarginEnd = m_iMarginEnd;
// Priority
m_timerInfoTag->m_iPriority = m_iPriority;
// Lifetime
m_timerInfoTag->m_iLifetime = m_iLifetime;
// MaxRecordings
m_timerInfoTag->m_iMaxRecordings = m_iMaxRecordings;
// Recording folder
m_timerInfoTag->m_strDirectory = m_strDirectory;
// Recording group
m_timerInfoTag->m_iRecordingGroup = m_iRecordingGroup;
// Set the timer's title to the channel name if it's empty or 'New Timer'
if (channel && (m_strTitle.empty() || m_strTitle == g_localizeStrings.Get(19056)))
m_timerInfoTag->m_strTitle = channel->ChannelName();
// Update summary
m_timerInfoTag->UpdateSummary();
}
void CGUIDialogPVRTimerSettings::SetButtonLabels()
{
// timer start time
BaseSettingControlPtr settingControl = GetSettingControl(SETTING_TMR_BEGIN);
if (settingControl != NULL && settingControl->GetControl() != NULL)
{
SET_CONTROL_LABEL2(settingControl->GetID(), m_timerStartTimeStr);
}
// timer end time
settingControl = GetSettingControl(SETTING_TMR_END);
if (settingControl != NULL && settingControl->GetControl() != NULL)
{
SET_CONTROL_LABEL2(settingControl->GetID(), m_timerEndTimeStr);
}
}
void CGUIDialogPVRTimerSettings::AddCondition(
std::shared_ptr<CSetting> setting, const std::string &identifier, SettingConditionCheck condition,
SettingDependencyType depType, const std::string &settingId)
{
GetSettingsManager()->AddDynamicCondition(identifier, condition, this);
CSettingDependency dep(depType, GetSettingsManager());
dep.And()->Add(
CSettingDependencyConditionPtr(
new CSettingDependencyCondition(identifier, "true", settingId, false, GetSettingsManager())));
SettingDependencies deps(setting->GetDependencies());
deps.push_back(dep);
setting->SetDependencies(deps);
}
int CGUIDialogPVRTimerSettings::GetDateAsIndex(const CDateTime &datetime)
{
const CDateTime date(datetime.GetYear(), datetime.GetMonth(), datetime.GetDay(), 0, 0, 0);
time_t t(0);
date.GetAsTime(t);
return static_cast<int>(t);
}
void CGUIDialogPVRTimerSettings::SetDateFromIndex(CDateTime &datetime, int date)
{
const CDateTime newDate(static_cast<time_t>(date));
datetime.SetDateTime(
newDate.GetYear(), newDate.GetMonth(), newDate.GetDay(),
datetime.GetHour(), datetime.GetMinute(), datetime.GetSecond());
}
void CGUIDialogPVRTimerSettings::SetTimeFromSystemTime(CDateTime &datetime, const SYSTEMTIME &time)
{
const CDateTime newTime(time);
datetime.SetDateTime(
datetime.GetYear(), datetime.GetMonth(), datetime.GetDay(),
newTime.GetHour(), newTime.GetMinute(), newTime.GetSecond());
}
void CGUIDialogPVRTimerSettings::InitializeTypesList()
{
m_typeEntries.clear();
// If timer is read-only or was created by a timer rule, only add current type, for information. Type can't be changed.
if (m_timerType->IsReadOnly() || m_timerInfoTag->GetTimerRuleId() != PVR_TIMER_NO_PARENT)
{
m_typeEntries.insert(std::make_pair(0, m_timerType));
return;
}
bool bFoundThisType(false);
int idx(0);
const std::vector<CPVRTimerTypePtr> types(CPVRTimerType::GetAllTypes());
for (const auto &type : types)
{
// Type definition prohibits created of new instances.
// But the dialog can act as a viewer for these types.
if (type->ForbidsNewInstances())
continue;
// Read-only timers cannot be created using this dialog.
// But the dialog can act as a viewer for read-only types.
if (type->IsReadOnly())
continue;
// Drop TimerTypes that require EPGInfo, if none is populated
if (type->RequiresEpgTagOnCreate() && !m_timerInfoTag->GetEpgInfoTag())
continue;
// Drop TimerTypes without 'Series' EPG attributes if none are set
if (type->RequiresEpgSeriesOnCreate())
{
const CPVREpgInfoTagPtr epgTag(m_timerInfoTag->GetEpgInfoTag());
if (epgTag && !epgTag->IsSeries())
continue;
}
// Drop TimerTypes which need series link if none is set
if (type->RequiresEpgSeriesLinkOnCreate())
{
const CPVREpgInfoTagPtr epgTag(m_timerInfoTag->GetEpgInfoTag());
if (!epgTag || epgTag->SeriesLink().empty())
continue;
}
// Drop TimerTypes that forbid EPGInfo, if it is populated
if (type->ForbidsEpgTagOnCreate() && m_timerInfoTag->GetEpgInfoTag())
continue;
// Drop TimerTypes that aren't rules and cannot be recorded
if (!type->IsTimerRule())
{
const CPVREpgInfoTagPtr epgTag(m_timerInfoTag->GetEpgInfoTag());
bool bCanRecord = epgTag ? epgTag->IsRecordable() : m_timerInfoTag->EndAsLocalTime() > CDateTime::GetCurrentDateTime();
if (!bCanRecord)
continue;
}
if (!bFoundThisType && *type == *m_timerType)
bFoundThisType = true;
m_typeEntries.insert(std::make_pair(idx++, type));
}
if (!bFoundThisType)
m_typeEntries.insert(std::make_pair(idx++, m_timerType));
}
void CGUIDialogPVRTimerSettings::InitializeChannelsList()
{
m_channelEntries.clear();
CFileItemList channelsList;
CServiceBroker::GetPVRManager().ChannelGroups()->GetGroupAll(m_bIsRadio)->GetMembers(channelsList);
for (int i = 0; i < channelsList.Size(); ++i)
{
const CPVRChannelPtr channel(channelsList[i]->GetPVRChannelInfoTag());
std::string channelDescription(
StringUtils::Format("%s %s", channel->ChannelNumber().FormattedChannelNumber().c_str(), channel->ChannelName().c_str()));
m_channelEntries.insert(
std::make_pair(i, ChannelDescriptor(channel->UniqueID(), channel->ClientID(), channelDescription)));
}
// Add special "any channel" entry (used for epg-based timer rules).
m_channelEntries.insert(
std::make_pair(
ENTRY_ANY_CHANNEL, ChannelDescriptor(PVR_CHANNEL_INVALID_UID, 0, g_localizeStrings.Get(809))));
}
void CGUIDialogPVRTimerSettings::TypesFiller(
SettingConstPtr setting, std::vector< std::pair<std::string, int> > &list, int ¤t, void *data)
{
CGUIDialogPVRTimerSettings *pThis = static_cast<CGUIDialogPVRTimerSettings*>(data);
if (pThis)
{
list.clear();
current = 0;
bool foundCurrent(false);
for (const auto &typeEntry : pThis->m_typeEntries)
{
list.push_back(std::make_pair(typeEntry.second->GetDescription(), typeEntry.first));
if (!foundCurrent && (*(pThis->m_timerType) == *(typeEntry.second)))
{
current = typeEntry.first;
foundCurrent = true;
}
}
}
else
CLog::LogF(LOGERROR, "No dialog");
}
void CGUIDialogPVRTimerSettings::ChannelsFiller(
SettingConstPtr setting, std::vector< std::pair<std::string, int> > &list, int ¤t, void *data)
{
CGUIDialogPVRTimerSettings *pThis = static_cast<CGUIDialogPVRTimerSettings*>(data);
if (pThis)
{
list.clear();
current = 0;
bool foundCurrent(false);
for (const auto &channelEntry : pThis->m_channelEntries)
{
if (channelEntry.first == ENTRY_ANY_CHANNEL)
{
// add an "any channel" entry, if supported by this type.
if (pThis->m_timerType->SupportsAnyChannel())
list.push_back(std::make_pair(channelEntry.second.description, channelEntry.first));
else
continue;
}
else
{
// Only include channels supplied by the currently active PVR client.
if (channelEntry.second.clientId == pThis->m_timerType->GetClientId())
list.push_back(std::make_pair(channelEntry.second.description, channelEntry.first));
}
if (!foundCurrent && (pThis->m_channel == channelEntry.second))
{
current = channelEntry.first;
foundCurrent = true;
}
}
}
else
CLog::LogF(LOGERROR, "No dialog");
}
void CGUIDialogPVRTimerSettings::DaysFiller(
SettingConstPtr setting, std::vector< std::pair<std::string, int> > &list, int ¤t, void *data)
{
CGUIDialogPVRTimerSettings *pThis = static_cast<CGUIDialogPVRTimerSettings*>(data);
if (pThis)
{
list.clear();
current = 0;
// Data range: "today" until "yesterday next year"
const CDateTime now(CDateTime::GetCurrentDateTime());
CDateTime time(now.GetYear(), now.GetMonth(), now.GetDay(), 0, 0, 0);
const CDateTime yesterdayPlusOneYear(CDateTime(time.GetYear() + 1, time.GetMonth(), time.GetDay(), time.GetHour(), time.GetMinute(), time.GetSecond())
- CDateTimeSpan(1, 0, 0, 0));
CDateTime oldCDateTime;
if (setting->GetId() == SETTING_TMR_FIRST_DAY)
oldCDateTime = pThis->m_timerInfoTag->FirstDayAsLocalTime();
else if (setting->GetId() == SETTING_TMR_START_DAY)
oldCDateTime = pThis->m_timerInfoTag->StartAsLocalTime();
else
oldCDateTime = pThis->m_timerInfoTag->EndAsLocalTime();
const CDateTime oldCDate(oldCDateTime.GetYear(), oldCDateTime.GetMonth(), oldCDateTime.GetDay(), 0, 0, 0);
if ((oldCDate < time) || (oldCDate > yesterdayPlusOneYear))
list.push_back(std::make_pair(oldCDate.GetAsLocalizedDate(true /*long date*/), GetDateAsIndex(oldCDate)));
while (time <= yesterdayPlusOneYear)
{
list.push_back(std::make_pair(time.GetAsLocalizedDate(true /*long date*/), GetDateAsIndex(time)));
time += CDateTimeSpan(1, 0, 0, 0);
}
if (setting->GetId() == SETTING_TMR_FIRST_DAY)
current = GetDateAsIndex(pThis->m_firstDayLocalTime);
else if (setting->GetId() == SETTING_TMR_START_DAY)
current = GetDateAsIndex(pThis->m_startLocalTime);
else
current = GetDateAsIndex(pThis->m_endLocalTime);
}
else
CLog::LogF(LOGERROR, "No dialog");
}
void CGUIDialogPVRTimerSettings::DupEpisodesFiller(
SettingConstPtr setting, std::vector< std::pair<std::string, int> > &list, int ¤t, void *data)
{
CGUIDialogPVRTimerSettings *pThis = static_cast<CGUIDialogPVRTimerSettings*>(data);
if (pThis)
{
list.clear();
pThis->m_timerType->GetPreventDuplicateEpisodesValues(list);
current = pThis->m_iPreventDupEpisodes;
}
else
CLog::LogF(LOGERROR, "No dialog");
}
void CGUIDialogPVRTimerSettings::WeekdaysFiller(
SettingConstPtr setting, std::vector< std::pair<std::string, int> > &list, int ¤t, void *data)
{
CGUIDialogPVRTimerSettings *pThis = static_cast<CGUIDialogPVRTimerSettings*>(data);
if (pThis)
{
list.clear();
list.push_back(std::make_pair(g_localizeStrings.Get(831), PVR_WEEKDAY_MONDAY)); // "Mondays"
list.push_back(std::make_pair(g_localizeStrings.Get(832), PVR_WEEKDAY_TUESDAY)); // "Tuesdays"
list.push_back(std::make_pair(g_localizeStrings.Get(833), PVR_WEEKDAY_WEDNESDAY)); // "Wednesdays"
list.push_back(std::make_pair(g_localizeStrings.Get(834), PVR_WEEKDAY_THURSDAY)); // "Thursdays"
list.push_back(std::make_pair(g_localizeStrings.Get(835), PVR_WEEKDAY_FRIDAY)); // "Fridays"
list.push_back(std::make_pair(g_localizeStrings.Get(836), PVR_WEEKDAY_SATURDAY)); // "Saturdays"
list.push_back(std::make_pair(g_localizeStrings.Get(837), PVR_WEEKDAY_SUNDAY)); // "Sundays"
current = pThis->m_iWeekdays;
}
else
CLog::LogF(LOGERROR, "No dialog");
}
void CGUIDialogPVRTimerSettings::PrioritiesFiller(
SettingConstPtr setting, std::vector< std::pair<std::string, int> > &list, int ¤t, void *data)
{
CGUIDialogPVRTimerSettings *pThis = static_cast<CGUIDialogPVRTimerSettings*>(data);
if (pThis)
{
list.clear();
pThis->m_timerType->GetPriorityValues(list);
current = pThis->m_iPriority;
auto it = list.begin();
while (it != list.end())
{
if (it->second == current)
break; // value already in list
++it;
}
if (it == list.end())
{
// PVR backend supplied value is not in the list of predefined values. Insert it.
list.insert(it, std::make_pair(StringUtils::Format("%d", current), current));
}
}
else
CLog::LogF(LOGERROR, "No dialog");
}
void CGUIDialogPVRTimerSettings::LifetimesFiller(
SettingConstPtr setting, std::vector< std::pair<std::string, int> > &list, int ¤t, void *data)
{
CGUIDialogPVRTimerSettings *pThis = static_cast<CGUIDialogPVRTimerSettings*>(data);
if (pThis)
{
list.clear();
pThis->m_timerType->GetLifetimeValues(list);
current = pThis->m_iLifetime;
auto it = list.begin();
while (it != list.end())
{
if (it->second == current)
break; // value already in list
++it;
}
if (it == list.end())
{
// PVR backend supplied value is not in the list of predefined values. Insert it.
list.insert(it, std::make_pair(StringUtils::Format(g_localizeStrings.Get(17999).c_str(), current) /* %i days */, current));
}
}
else
CLog::LogF(LOGERROR, "No dialog");
}
void CGUIDialogPVRTimerSettings::MaxRecordingsFiller(
SettingConstPtr setting, std::vector< std::pair<std::string, int> > &list, int ¤t, void *data)
{
CGUIDialogPVRTimerSettings *pThis = static_cast<CGUIDialogPVRTimerSettings*>(data);
if (pThis)
{
list.clear();
pThis->m_timerType->GetMaxRecordingsValues(list);
current = pThis->m_iMaxRecordings;