/
scheduleeditor.cpp
2843 lines (2372 loc) · 82.4 KB
/
scheduleeditor.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
#include "scheduleeditor.h"
// QT
#include <QCoreApplication>
#include <QHash>
#include <QString>
#include <utility>
// Libmyth
#include "mythcorecontext.h"
#include "storagegroup.h"
#include "programtypes.h"
#include "recordingtypes.h"
// Libmythtv
#include "playgroup.h"
#include "tv_play.h"
#include "recordingprofile.h"
#include "cardutil.h"
// Libmythui
#include "mythmainwindow.h"
#include "mythuihelper.h"
#include "mythuibuttonlist.h"
#include "mythuibutton.h"
#include "mythuitext.h"
#include "mythuiimage.h"
#include "mythuistatetype.h"
#include "mythuispinbox.h"
#include "mythuicheckbox.h"
#include "mythdialogbox.h"
#include "mythprogressdialog.h"
#include "mythuifilebrowser.h"
#include "mythuimetadataresults.h"
#include "mythuiimageresults.h"
#include "videoutils.h"
#include "mythuiutils.h"
#include "mythtypes.h"
#include "metadataimagehelper.h"
// Mythfrontend
#include "proglist.h"
#include "viewschedulediff.h"
#define ENUM_TO_QVARIANT(a) QVariant::fromValue(static_cast<int>(a))
//static const QString _Location = QObject::tr("Schedule Editor");
// Define the strings inserted into the recordfilter table in the
// database. This should make them available to the translators.
static QString fs0(QT_TRANSLATE_NOOP("SchedFilterEditor", "New episode"));
static QString fs1(QT_TRANSLATE_NOOP("SchedFilterEditor", "Identifiable episode"));
static QString fs2(QT_TRANSLATE_NOOP("SchedFilterEditor", "First showing"));
static QString fs3(QT_TRANSLATE_NOOP("SchedFilterEditor", "Prime time"));
static QString fs4(QT_TRANSLATE_NOOP("SchedFilterEditor", "Commercial free"));
static QString fs5(QT_TRANSLATE_NOOP("SchedFilterEditor", "High definition"));
static QString fs6(QT_TRANSLATE_NOOP("SchedFilterEditor", "This episode"));
static QString fs7(QT_TRANSLATE_NOOP("SchedFilterEditor", "This series"));
static QString fs8(QT_TRANSLATE_NOOP("SchedFilterEditor", "This time"));
static QString fs9(QT_TRANSLATE_NOOP("SchedFilterEditor", "This day and time"));
static QString fs10(QT_TRANSLATE_NOOP("SchedFilterEditor", "This channel"));
static QString fs11(QT_TRANSLATE_NOOP("SchedFilterEditor", "No episodes"));
void *ScheduleEditor::RunScheduleEditor(ProgramInfo *proginfo, void *player)
{
auto *rule = new RecordingRule();
rule->LoadByProgram(proginfo);
MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
auto *se = new ScheduleEditor(mainStack, rule, static_cast<TV*>(player));
if (se->Create())
mainStack->AddScreen(se, (player == nullptr));
else
delete se;
return nullptr;
}
/** \class ScheduleEditor
* \brief Construct a recording schedule
*
*/
ScheduleEditor::ScheduleEditor(MythScreenStack *parent,
RecordingInfo *recInfo, TV *player)
: ScheduleCommon(parent, "ScheduleEditor"),
SchedOptMixin(*this, nullptr), FilterOptMixin(*this, nullptr),
StoreOptMixin(*this, nullptr), PostProcMixin(*this, nullptr),
m_recInfo(new RecordingInfo(*recInfo)),
m_player(player)
{
m_recordingRule = new RecordingRule();
m_recordingRule->m_recordID = m_recInfo->GetRecordingRuleID();
SchedOptMixin::SetRule(m_recordingRule);
FilterOptMixin::SetRule(m_recordingRule);
StoreOptMixin::SetRule(m_recordingRule);
PostProcMixin::SetRule(m_recordingRule);
}
ScheduleEditor::ScheduleEditor(MythScreenStack *parent,
RecordingRule *recRule, TV *player)
: ScheduleCommon(parent, "ScheduleEditor"),
SchedOptMixin(*this, recRule),
FilterOptMixin(*this, recRule),
StoreOptMixin(*this, recRule),
PostProcMixin(*this, recRule),
m_recordingRule(recRule),
m_player(player)
{
}
ScheduleEditor::~ScheduleEditor(void)
{
delete m_recordingRule;
// if we have a player, we need to tell we are done
if (m_player)
{
QString message = QString("VIEWSCHEDULED_EXITING");
qApp->postEvent(m_player, new MythEvent(message));
}
}
bool ScheduleEditor::Create()
{
if (!LoadWindowFromXML("schedule-ui.xml", "scheduleeditor", this))
return false;
bool err = false;
UIUtilE::Assign(this, m_rulesList, "rules", &err);
UIUtilW::Assign(this, m_schedOptButton, "schedoptions");
UIUtilW::Assign(this, m_storeOptButton, "storeoptions");
UIUtilW::Assign(this, m_postProcButton, "postprocessing");
UIUtilW::Assign(this, m_metadataButton, "metadata");
UIUtilW::Assign(this, m_schedInfoButton, "schedinfo");
UIUtilW::Assign(this, m_previewButton, "preview");
UIUtilW::Assign(this, m_filtersButton, "filters");
SchedOptMixin::Create(&err);
FilterOptMixin::Create(&err);
StoreOptMixin::Create(&err);
PostProcMixin::Create(&err);
UIUtilW::Assign(this, m_cancelButton, "cancel");
UIUtilE::Assign(this, m_saveButton, "save", &err);
if (err)
{
LOG(VB_GENERAL, LOG_ERR, "ScheduleEditor, theme is missing "
"required elements");
return false;
}
connect(m_rulesList, SIGNAL(itemSelected(MythUIButtonListItem *)),
SLOT(RuleChanged(MythUIButtonListItem *)));
if (m_schedOptButton)
connect(m_schedOptButton, SIGNAL(Clicked()), SLOT(ShowSchedOpt()));
if (m_filtersButton)
connect(m_filtersButton, SIGNAL(Clicked()), SLOT(ShowFilters()));
if (m_storeOptButton)
connect(m_storeOptButton, SIGNAL(Clicked()), SLOT(ShowStoreOpt()));
if (m_postProcButton)
connect(m_postProcButton, SIGNAL(Clicked()), SLOT(ShowPostProc()));
if (m_schedInfoButton)
connect(m_schedInfoButton, SIGNAL(Clicked()), SLOT(ShowSchedInfo()));
if (m_previewButton)
connect(m_previewButton, SIGNAL(Clicked()), SLOT(ShowPreview()));
if (m_metadataButton)
connect(m_metadataButton, SIGNAL(Clicked()), SLOT(ShowMetadataOptions()));
if (m_cancelButton)
connect(m_cancelButton, SIGNAL(Clicked()), SLOT(Close()));
connect(m_saveButton, SIGNAL(Clicked()), SLOT(Save()));
if (m_schedInfoButton)
m_schedInfoButton->SetEnabled(!m_recordingRule->m_isTemplate);
if (m_previewButton)
m_previewButton->SetEnabled(!m_recordingRule->m_isTemplate);
if (m_dupmethodList)
connect(m_dupmethodList, SIGNAL(itemSelected(MythUIButtonListItem *)),
SLOT(DupMethodChanged(MythUIButtonListItem *)));
if (m_filtersList)
connect(m_filtersList, SIGNAL(itemClicked(MythUIButtonListItem *)),
SLOT(FilterChanged(MythUIButtonListItem *)));
if (m_maxepSpin)
connect(m_maxepSpin, SIGNAL(itemSelected(MythUIButtonListItem *)),
SLOT(MaxEpisodesChanged(MythUIButtonListItem *)));
if (m_recgroupList)
connect(m_recgroupList, SIGNAL(LosingFocus()),
SLOT(PromptForRecGroup()));
if (m_transcodeCheck)
connect(m_transcodeCheck, SIGNAL(toggled(bool)),
SLOT(TranscodeChanged(bool)));
BuildFocusList();
if (!m_recordingRule->IsLoaded())
{
if (m_recInfo)
m_recordingRule->LoadByProgram(m_recInfo);
else if (m_recordingRule->m_recordID)
m_recordingRule->Load();
if (!m_recordingRule->IsLoaded())
{
LOG(VB_GENERAL, LOG_ERR,
"ScheduleEditor::Create() - Failed to load recording rule");
return false;
}
}
if (m_player)
m_player->StartEmbedding(QRect());
return true;
}
void ScheduleEditor::Close()
{
if (m_child)
m_child->Close();
// don't fade the screen if we are returning to the player
if (m_player)
GetScreenStack()->PopScreen(this, false);
else
GetScreenStack()->PopScreen(this, true);
}
void ScheduleEditor::Load()
{
SchedOptMixin::Load();
FilterOptMixin::Load();
StoreOptMixin::Load();
PostProcMixin::Load();
if (!m_loaded)
{
// Copy this now, it will change briefly after the first item
// is inserted into the list by design of
// MythUIButtonList::itemSelected()
RecordingType type = m_recordingRule->m_type;
// Rules List
if (m_recordingRule->m_isTemplate)
{
if (m_recordingRule->m_category
.compare("Default", Qt::CaseInsensitive) != 0)
{
new MythUIButtonListItem(m_rulesList,
tr("Delete this recording rule template"),
ENUM_TO_QVARIANT(kNotRecording));
}
new MythUIButtonListItem(m_rulesList,
toDescription(kTemplateRecord),
ENUM_TO_QVARIANT(kTemplateRecord));
}
else if (m_recordingRule->m_isOverride)
{
new MythUIButtonListItem(m_rulesList,
tr("Record this showing with normal options"),
ENUM_TO_QVARIANT(kNotRecording));
new MythUIButtonListItem(m_rulesList,
toDescription(kOverrideRecord),
ENUM_TO_QVARIANT(kOverrideRecord));
new MythUIButtonListItem(m_rulesList,
toDescription(kDontRecord),
ENUM_TO_QVARIANT(kDontRecord));
}
else
{
bool hasChannel = !m_recordingRule->m_station.isEmpty();
bool isManual = (m_recordingRule->m_searchType == kManualSearch);
new MythUIButtonListItem(m_rulesList,
toDescription(kNotRecording),
ENUM_TO_QVARIANT(kNotRecording));
if (hasChannel)
{
new MythUIButtonListItem(m_rulesList,
toDescription(kSingleRecord),
ENUM_TO_QVARIANT(kSingleRecord));
}
if (!isManual)
{
new MythUIButtonListItem(m_rulesList,
toDescription(kOneRecord),
ENUM_TO_QVARIANT(kOneRecord));
}
if (!hasChannel || isManual)
{
new MythUIButtonListItem(m_rulesList,
toDescription(kWeeklyRecord),
ENUM_TO_QVARIANT(kWeeklyRecord));
}
if (!hasChannel || isManual)
{
new MythUIButtonListItem(m_rulesList,
toDescription(kDailyRecord),
ENUM_TO_QVARIANT(kDailyRecord));
}
if (!isManual)
{
new MythUIButtonListItem(m_rulesList,
toDescription(kAllRecord),
ENUM_TO_QVARIANT(kAllRecord));
}
}
m_recordingRule->m_type = type;
}
m_rulesList->SetValueByData(ENUM_TO_QVARIANT(m_recordingRule->m_type));
InfoMap progMap;
m_recordingRule->ToMap(progMap);
if (m_recInfo)
m_recInfo->ToMap(progMap);
SetTextFromMap(progMap);
m_loaded = true;
}
void ScheduleEditor::LoadTemplate(const QString& name)
{
m_recordingRule->LoadTemplate(name);
Load();
emit templateLoaded();
}
void ScheduleEditor::RuleChanged(MythUIButtonListItem *item)
{
if (!item)
return;
m_recordingRule->m_type = static_cast<RecordingType>
(item->GetData().toInt());
bool isScheduled = (m_recordingRule->m_type != kNotRecording &&
m_recordingRule->m_type != kDontRecord);
if (m_schedOptButton)
m_schedOptButton->SetEnabled(isScheduled);
if (m_filtersButton)
m_filtersButton->SetEnabled(isScheduled);
if (m_storeOptButton)
m_storeOptButton->SetEnabled(isScheduled);
if (m_postProcButton)
m_postProcButton->SetEnabled(isScheduled);
if (m_metadataButton)
m_metadataButton->SetEnabled(isScheduled &&
!m_recordingRule->m_isTemplate);
SchedOptMixin::RuleChanged();
FilterOptMixin::RuleChanged();
StoreOptMixin::RuleChanged();
PostProcMixin::RuleChanged();
}
void ScheduleEditor::DupMethodChanged(MythUIButtonListItem *item)
{
SchedOptMixin::DupMethodChanged(item);
}
void ScheduleEditor::FilterChanged(MythUIButtonListItem *item)
{
FilterOptMixin::ToggleSelected(item);
}
void ScheduleEditor::MaxEpisodesChanged(MythUIButtonListItem *item)
{
StoreOptMixin::MaxEpisodesChanged(item);
}
void ScheduleEditor::PromptForRecGroup(void)
{
StoreOptMixin::PromptForRecGroup();
}
void ScheduleEditor::TranscodeChanged(bool enable)
{
PostProcMixin::TranscodeChanged(enable);
}
void ScheduleEditor::Save()
{
if (m_child)
m_child->Close();
if (m_recordingRule->m_type == kNotRecording)
{
int recid = m_recordingRule->m_recordID;
DeleteRule();
if (recid)
emit ruleDeleted(recid);
Close();
return;
}
SchedOptMixin::Save();
FilterOptMixin::Save();
StoreOptMixin::Save();
PostProcMixin::Save();
m_recordingRule->Save(true);
emit ruleSaved(m_recordingRule->m_recordID);
Close();
}
void ScheduleEditor::DeleteRule()
{
m_recordingRule->Delete();
}
void ScheduleEditor::ShowSchedOpt()
{
if (m_recordingRule->m_type == kNotRecording ||
m_recordingRule->m_type == kDontRecord)
return;
if (m_child)
m_child->Close();
SchedOptMixin::Save();
MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
auto *schedoptedit = new SchedOptEditor(mainStack, *this,
*m_recordingRule, m_recInfo);
if (!schedoptedit->Create())
{
delete schedoptedit;
return;
}
m_view = kSchedOptView;
m_child = schedoptedit;
mainStack->AddScreen(schedoptedit);
}
void ScheduleEditor::ShowStoreOpt()
{
if (m_recordingRule->m_type == kNotRecording ||
m_recordingRule->m_type == kDontRecord)
return;
if (m_child)
m_child->Close();
StoreOptMixin::Save();
MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
auto *storeoptedit = new StoreOptEditor(mainStack, *this,
*m_recordingRule, m_recInfo);
if (!storeoptedit->Create())
{
delete storeoptedit;
return;
}
m_view = kStoreOptView;
m_child = storeoptedit;
mainStack->AddScreen(storeoptedit);
}
void ScheduleEditor::ShowPostProc()
{
if (m_recordingRule->m_type == kNotRecording ||
m_recordingRule->m_type == kDontRecord)
return;
if (m_child)
m_child->Close();
PostProcMixin::Save();
MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
auto *ppedit = new PostProcEditor(mainStack, *this,
*m_recordingRule, m_recInfo);
if (!ppedit->Create())
{
delete ppedit;
return;
}
m_view = kPostProcView;
m_child = ppedit;
mainStack->AddScreen(ppedit);
}
void ScheduleEditor::ShowSchedInfo()
{
if (m_recordingRule->m_type == kTemplateRecord)
return;
QString label = tr("Schedule Information");
MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
auto *menuPopup = new MythDialogBox(label, popupStack, "menuPopup");
if (menuPopup->Create())
{
menuPopup->SetReturnEvent(this, "schedinfo");
if (m_recInfo)
menuPopup->AddButton(tr("Program Details"));
menuPopup->AddButton(tr("Upcoming Episodes"));
menuPopup->AddButton(tr("Upcoming Recordings"));
if (m_recordingRule->m_type != kTemplateRecord)
menuPopup->AddButton(tr("Previously Recorded"));
popupStack->AddScreen(menuPopup);
}
else
delete menuPopup;
}
bool ScheduleEditor::keyPressEvent(QKeyEvent *event)
{
if (GetFocusWidget()->keyPressEvent(event))
return true;
QStringList actions;
bool handled = GetMythMainWindow()->
TranslateKeyPress("TV Frontend", event, actions);
for (int i = 0; i < actions.size() && !handled; i++)
{
QString action = actions[i];
handled = true;
if (action == "MENU")
showMenu();
else if (action == "INFO")
ShowDetails();
else if (action == "GUIDE")
ShowGuide();
else if (action == "UPCOMING")
showUpcomingByTitle();
else if (action == "PREVVIEW")
ShowPreviousView();
else if (action == "NEXTVIEW")
ShowNextView();
else
handled = false;
}
if (!handled && MythScreenType::keyPressEvent(event))
handled = true;
return handled;
}
void ScheduleEditor::customEvent(QEvent *event)
{
if (event->type() == DialogCompletionEvent::kEventType)
{
auto *dce = (DialogCompletionEvent*)(event);
QString resultid = dce->GetId();
QString resulttext = dce->GetResultText();
if (resultid == "menu")
{
if (resulttext == tr("Main Options"))
m_child->Close();
if (resulttext == tr("Schedule Options"))
ShowSchedOpt();
else if (resulttext == tr("Filter Options"))
ShowFilters();
else if (resulttext == tr("Storage Options"))
ShowStoreOpt();
else if (resulttext == tr("Post Processing"))
ShowPostProc();
else if (resulttext == tr("Metadata Options"))
ShowMetadataOptions();
else if (resulttext == tr("Use Template"))
showTemplateMenu();
else if (resulttext == tr("Schedule Info"))
ShowSchedInfo();
else if (resulttext == tr("Preview Changes"))
ShowPreview();
}
else if (resultid == "templatemenu")
{
LoadTemplate(resulttext);
}
else if (resultid == "schedinfo")
{
if (resulttext == tr("Program Details"))
ShowDetails();
else if (resulttext == tr("Upcoming Episodes"))
showUpcomingByTitle();
else if (resulttext == tr("Upcoming Recordings"))
showUpcomingByRule();
else if (resulttext == tr("Previously Recorded"))
ShowPrevious(m_recordingRule->m_recordID,
m_recordingRule->m_title);
}
else if (resultid == "newrecgroup")
{
int groupID = CreateRecordingGroup(resulttext);
StoreOptMixin::SetRecGroup(groupID, resulttext);
}
}
}
void ScheduleEditor::showUpcomingByRule(void)
{
if (m_recordingRule->m_type == kTemplateRecord)
return;
// No rule? Search by title
if (m_recordingRule->m_recordID <= 0)
{
showUpcomingByTitle();
return;
}
MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
auto *pl = new ProgLister(mainStack, plRecordid,
QString::number(m_recordingRule->m_recordID), "");
if (pl->Create())
mainStack->AddScreen(pl);
else
delete pl;
}
void ScheduleEditor::showUpcomingByTitle(void)
{
if (m_recordingRule->m_type == kTemplateRecord)
return;
// Existing rule and search? Search by rule
if (m_recordingRule->m_recordID > 0 &&
m_recordingRule->m_searchType != kNoSearch)
showUpcomingByRule();
QString title = m_recordingRule->m_title;
if (m_recordingRule->m_searchType != kNoSearch)
title.remove(QRegExp(" \\(.*\\)$"));
ShowUpcoming(title, m_recordingRule->m_seriesid);
}
void ScheduleEditor::ShowPreview(void)
{
if (m_recordingRule->m_type == kTemplateRecord)
return;
if (m_child)
{
m_child->Save();
if (m_view == kSchedOptView)
SchedOptMixin::Load();
else if (m_view == kStoreOptView)
StoreOptMixin::Load();
else if (m_view == kPostProcView)
PostProcMixin::Load();
}
SchedOptMixin::Save();
FilterOptMixin::Save();
StoreOptMixin::Save();
PostProcMixin::Save();
QString ttable = "record_tmp";
m_recordingRule->UseTempTable(true, ttable);
MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
auto *vsd = new ViewScheduleDiff(mainStack, ttable,
m_recordingRule->m_tempID,
m_recordingRule->m_title);
if (vsd->Create())
mainStack->AddScreen(vsd);
else
delete vsd;
m_recordingRule->UseTempTable(false);
}
void ScheduleEditor::ShowMetadataOptions(void)
{
if (m_recordingRule->m_type == kNotRecording ||
m_recordingRule->m_type == kDontRecord ||
m_recordingRule->m_type == kTemplateRecord)
return;
if (m_child)
m_child->Close();
MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
auto *rad = new MetadataOptions(mainStack, *this,
*m_recordingRule, m_recInfo);
if (!rad->Create())
{
delete rad;
return;
}
m_view = kMetadataView;
m_child = rad;
mainStack->AddScreen(rad);
}
void ScheduleEditor::ShowFilters(void)
{
if (m_recordingRule->m_type == kNotRecording ||
m_recordingRule->m_type == kDontRecord)
return;
if (m_child)
m_child->Close();
FilterOptMixin::Save();
MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
auto *schedfilteredit = new SchedFilterEditor(mainStack, *this,
*m_recordingRule, m_recInfo);
if (!schedfilteredit->Create())
{
delete schedfilteredit;
return;
}
m_view = kFilterView;
m_child = schedfilteredit;
mainStack->AddScreen(schedfilteredit);
}
void ScheduleEditor::ShowPreviousView(void)
{
if (m_recordingRule->m_type == kNotRecording ||
m_recordingRule->m_type == kDontRecord)
return;
if (m_view == kMainView && !m_recordingRule->m_isTemplate)
ShowMetadataOptions();
else if ((m_view == kMainView) || (m_view == kMetadataView))
ShowPostProc();
else if (m_view == kSchedOptView)
m_child->Close();
else if (m_view == kFilterView)
ShowSchedOpt();
else if (m_view == kStoreOptView)
ShowFilters();
else if (m_view == kPostProcView)
ShowStoreOpt();
}
void ScheduleEditor::ShowNextView(void)
{
if (m_recordingRule->m_type == kNotRecording ||
m_recordingRule->m_type == kDontRecord)
return;
if (m_view == kMainView)
ShowSchedOpt();
else if (m_view == kSchedOptView)
ShowFilters();
else if (m_view == kFilterView)
ShowStoreOpt();
else if (m_view == kStoreOptView)
ShowPostProc();
else if (m_view == kPostProcView && !m_recordingRule->m_isTemplate)
ShowMetadataOptions();
else if ((m_view == kPostProcView) || (m_view == kMetadataView))
m_child->Close();
}
void ScheduleEditor::ChildClosing(void)
{
if (m_view == kSchedOptView)
SchedOptMixin::Load();
else if (m_view == kFilterView)
FilterOptMixin::Load();
else if (m_view == kStoreOptView)
StoreOptMixin::Load();
else if (m_view == kPostProcView)
PostProcMixin::Load();
m_child = nullptr;
m_view = kMainView;
}
void ScheduleEditor::showMenu(void)
{
QString label = tr("Options");
MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
auto *menuPopup = new MythDialogBox(label, popupStack, "menuPopup");
MythUIButtonListItem *item = m_rulesList->GetItemCurrent();
RecordingType type = static_cast<RecordingType>(item->GetData().toInt());
bool isScheduled = (type != kNotRecording && type != kDontRecord);
if (menuPopup->Create())
{
menuPopup->SetReturnEvent(this, "menu");
if (m_view != kMainView)
menuPopup->AddButton(tr("Main Options"));
if (isScheduled && m_view != kSchedOptView)
menuPopup->AddButton(tr("Schedule Options"));
if (isScheduled && m_view != kFilterView)
menuPopup->AddButton(tr("Filter Options"));
if (isScheduled && m_view != kStoreOptView)
menuPopup->AddButton(tr("Storage Options"));
if (isScheduled && m_view != kPostProcView)
menuPopup->AddButton(tr("Post Processing"));
if (isScheduled && !m_recordingRule->m_isTemplate &&
m_view != kMetadataView)
menuPopup->AddButton(tr("Metadata Options"));
if (!m_recordingRule->m_isTemplate)
menuPopup->AddButton(tr("Schedule Info"));
if (!m_recordingRule->m_isTemplate)
menuPopup->AddButton(tr("Preview Changes"));
menuPopup->AddButton(tr("Use Template"));
popupStack->AddScreen(menuPopup);
}
else
{
delete menuPopup;
}
}
void ScheduleEditor::showTemplateMenu(void)
{
QStringList templates = RecordingRule::GetTemplateNames();
if (templates.empty())
{
ShowOkPopup(tr("No templates available"));
return;
}
QString label = tr("Template Options");
MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
auto *menuPopup = new MythDialogBox(label, popupStack, "menuPopup");
if (menuPopup->Create())
{
menuPopup->SetReturnEvent(this, "templatemenu");
while (!templates.empty())
{
QString name = templates.front();
if (name == "Default")
menuPopup->AddButton(tr("Default"));
else
menuPopup->AddButton(name);
templates.pop_front();
}
popupStack->AddScreen(menuPopup);
}
else
{
delete menuPopup;
}
}
////////////////////////////////////////////////////////
/** \class SchedEditerChild
*
*/
SchedEditChild::SchedEditChild(MythScreenStack *parent, const QString &name,
ScheduleEditor &editor, RecordingRule &rule,
RecordingInfo *recInfo)
: MythScreenType(parent, name),
m_editor(&editor), m_recordingRule(&rule), m_recInfo(recInfo)
{
}
bool SchedEditChild::keyPressEvent(QKeyEvent *event)
{
if (GetFocusWidget()->keyPressEvent(event))
return true;
QStringList actions;
bool handled = GetMythMainWindow()->
TranslateKeyPress("TV Frontend", event, actions);
for (int i = 0; i < actions.size() && !handled; i++)
{
QString action = actions[i];
handled = true;
if (action == "MENU")
m_editor->showMenu();
else if (action == "INFO")
m_editor->ShowDetails();
else if (action == "UPCOMING")
m_editor->showUpcomingByTitle();
if (action == "ESCAPE")
Close();
else if (action == "PREVVIEW")
m_editor->ShowPreviousView();
else if (action == "NEXTVIEW")
m_editor->ShowNextView();
else
handled = false;
}
if (!handled && MythScreenType::keyPressEvent(event))
handled = true;
return handled;
}
bool SchedEditChild::CreateEditChild(
const QString &xmlfile, const QString &winname, bool isTemplate)
{
if (!LoadWindowFromXML(xmlfile, winname, this))
return false;
UIUtilW::Assign(this, m_backButton, "back");
UIUtilW::Assign(this, m_saveButton, "save");
UIUtilW::Assign(this, m_previewButton, "preview");
connect(this, SIGNAL(Closing()), m_editor, SLOT(ChildClosing()));
connect(m_editor, SIGNAL(templateLoaded()), SLOT(Load()));
if (m_backButton)
connect(m_backButton, SIGNAL(Clicked()), SLOT(Close()));
if (m_saveButton)
connect(m_saveButton, SIGNAL(Clicked()), m_editor, SLOT(Save()));
if (m_previewButton)
connect(m_previewButton, SIGNAL(Clicked()),
m_editor, SLOT(ShowPreview()));
if (m_previewButton)
m_previewButton->SetEnabled(!isTemplate);
return true;
}
void SchedEditChild::SetTextFromMaps(void)
{
InfoMap progMap;
m_recordingRule->ToMap(progMap);
if (m_recInfo)
m_recInfo->ToMap(progMap);
SetTextFromMap(progMap);
}
void SchedEditChild::Close(void)
{
Save();
emit Closing();
MythScreenType::Close();
}
////////////////////////////////////////////////////////
/** \class SchedOptEditor
* \brief Select schedule options
*
*/
SchedOptEditor::SchedOptEditor(MythScreenStack *parent,
ScheduleEditor &editor,
RecordingRule &rule,
RecordingInfo *recInfo)
: SchedEditChild(parent, "ScheduleOptionsEditor", editor, rule, recInfo),
SchedOptMixin(*this, &rule, &editor)
{
}
bool SchedOptEditor::Create()
{
if (!SchedEditChild::CreateEditChild(
"schedule-ui.xml", "scheduleoptionseditor",
m_recordingRule->m_isTemplate))
{
return false;
}
bool err = false;
SchedOptMixin::Create(&err);
UIUtilW::Assign(this, m_filtersButton, "filters");
if (err)
{
LOG(VB_GENERAL, LOG_ERR, "SchedOptEditor, theme is missing "
"required elements");
return false;
}