/
proglist.cpp
1698 lines (1474 loc) · 51.5 KB
/
proglist.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 "proglist.h"
// C/C++
#include <algorithm>
#include <functional>
#include <deque> // for _Deque_iterator, operator-, etc
#include <iterator> // for reverse_iterator
// Qt
#include <QCoreApplication>
#include <QLocale>
#include <QRegExp>
#include <utility>
// MythTV
#include "mythmiscutil.h"
#include "scheduledrecording.h"
#include "mythuibuttonlist.h"
#include "mythuistatetype.h"
#include "mythcorecontext.h"
#include "mythdialogbox.h"
#include "recordinginfo.h"
#include "recordingrule.h"
#include "channelinfo.h"
#include "channelutil.h"
#include "mythuitext.h"
#include "tv_actions.h" // for ACTION_CHANNELSEARCH
#include "mythdb.h"
#include "mythdate.h"
#define LOC QString("ProgLister: ")
#define LOC_WARN QString("ProgLister, Warning: ")
#define LOC_ERR QString("ProgLister, Error: ")
ProgLister::ProgLister(MythScreenStack *parent, ProgListType pltype,
QString view, QString extraArg,
QDateTime selectedTime) :
ScheduleCommon(parent, "ProgLister"),
m_type(pltype),
m_extraArg(std::move(extraArg)),
m_startTime(MythDate::current()),
m_searchTime(m_startTime),
m_selectedTime(std::move(selectedTime)),
m_channelOrdering(gCoreContext->GetSetting("ChannelOrdering", "channum")),
m_view(std::move(view))
{
if (pltype == plMovies)
{
MSqlQuery query(MSqlQuery::InitCon());
query.prepare("SELECT COUNT(*) FROM program WHERE stars > 0");
if (query.exec() && query.next())
{
if (query.value(0).toInt() == 0) // No ratings in database
{
m_curView = 0; // Show All
m_allowViewDialog = false;
}
}
}
switch (pltype)
{
case plTitleSearch: m_searchType = kTitleSearch; break;
case plKeywordSearch: m_searchType = kKeywordSearch; break;
case plPeopleSearch: m_searchType = kPeopleSearch; break;
case plPowerSearch:
case plSQLSearch:
case plStoredSearch: m_searchType = kPowerSearch; break;
default: m_searchType = kNoSearch; break;
}
}
// previously recorded ctor
ProgLister::ProgLister(
MythScreenStack *parent, uint recid, QString title) :
ScheduleCommon(parent, "PreviousList"),
m_type(plPreviouslyRecorded),
m_recid(recid),
m_title(std::move(title)),
m_startTime(MythDate::current()),
m_searchTime(m_startTime),
m_channelOrdering(gCoreContext->GetSetting("ChannelOrdering", "channum")),
m_view("reverse time"),
m_reverseSort(true)
{
}
ProgLister::~ProgLister()
{
m_itemList.clear();
m_itemListSave.clear();
gCoreContext->removeListener(this);
}
bool ProgLister::Create()
{
if (!LoadWindowFromXML("schedule-ui.xml", "programlist", this))
return false;
bool err = false;
UIUtilW::Assign(this, m_curviewText, "curview", &err);
UIUtilE::Assign(this, m_progList, "proglist", &err);
UIUtilW::Assign(this, m_schedText, "sched", &err);
UIUtilW::Assign(this, m_messageText, "msg", &err);
UIUtilW::Assign(this, m_positionText, "position", &err);
if (err)
{
LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'programlist'");
return false;
}
connect(m_progList, SIGNAL(itemSelected(MythUIButtonListItem*)),
this, SLOT( HandleSelected( MythUIButtonListItem*)));
connect(m_progList, SIGNAL(itemVisible(MythUIButtonListItem*)),
this, SLOT( HandleVisible( MythUIButtonListItem*)));
connect(m_progList, SIGNAL(itemLoaded(MythUIButtonListItem*)),
this, SLOT( HandleVisible( MythUIButtonListItem*)));
if (m_type == plPreviouslyRecorded)
{
connect(m_progList, SIGNAL(itemClicked(MythUIButtonListItem*)),
this, SLOT( ShowOldRecordedMenu()));
}
else
{
connect(m_progList, SIGNAL(itemClicked(MythUIButtonListItem*)),
this, SLOT( EditRecording()));
}
m_progList->SetLCDTitles(tr("Program List"), "title|channel|shortstarttimedate");
m_progList->SetSearchFields("titlesubtitle");
BuildFocusList();
QString value;
switch (m_type)
{
case plTitle: value = tr("Program Listings"); break;
case plNewListings: value = tr("New Title Search"); break;
case plTitleSearch: value = tr("Title Search"); break;
case plKeywordSearch: value = tr("Keyword Search"); break;
case plPeopleSearch: value = tr("People Search"); break;
case plStoredSearch: value = tr("Stored Search"); break;
case plPowerSearch:
case plSQLSearch: value = tr("Power Search"); break;
case plRecordid: value = tr("Rule Search"); break;
case plCategory: value = tr("Category Search"); break;
case plChannel: value = tr("Channel Search"); break;
case plMovies: value = tr("Movie Search"); break;
case plTime: value = tr("Time Search"); break;
case plPreviouslyRecorded: value = tr("Previously Recorded"); break;
default: value = tr("Unknown Search"); break;
}
if (m_schedText)
m_schedText->SetText(value);
gCoreContext->addListener(this);
LoadInBackground();
return true;
}
void ProgLister::Load(void)
{
if (m_viewList.isEmpty() || m_curView < 0)
FillViewList(m_view);
FillItemList(false, false);
auto *slce = new ScreenLoadCompletionEvent(objectName());
QCoreApplication::postEvent(this, slce);
}
bool ProgLister::keyPressEvent(QKeyEvent *e)
{
if (!m_allowEvents)
return true;
if (GetFocusWidget() && GetFocusWidget()->keyPressEvent(e))
{
m_allowEvents = true;
return true;
}
m_allowEvents = false;
QStringList actions;
bool handled = GetMythMainWindow()->TranslateKeyPress(
"TV Frontend", e, actions);
bool needUpdate = false;
for (uint i = 0; i < uint(actions.size()) && !handled; ++i)
{
QString action = actions[i];
handled = true;
if (action == "PREVVIEW")
SwitchToPreviousView();
else if (action == "NEXTVIEW")
SwitchToNextView();
else if (action == "CUSTOMEDIT")
EditCustom();
else if (action == "EDIT")
EditScheduled();
else if (action == "DELETE")
ShowDeleteItemMenu();
else if (action == "UPCOMING" && m_type != plTitle)
ShowUpcoming();
else if (action == "PREVRECORDED" && m_type != plPreviouslyRecorded)
ShowPrevious();
else if (action == "DETAILS" || action == "INFO")
ShowDetails();
else if (action == "GUIDE")
ShowGuide();
else if (action == ACTION_CHANNELSEARCH && m_type != plChannel)
ShowChannelSearch();
else if (action == "TOGGLERECORD")
QuickRecord();
else if (action == "1")
{
if (m_titleSort)
{
m_titleSort = false;
m_reverseSort = (m_type == plPreviouslyRecorded);
}
else
{
m_reverseSort = !m_reverseSort;
}
needUpdate = true;
}
else if (action == "2")
{
if (!m_titleSort)
{
m_titleSort = true;
m_reverseSort = false;
}
else
{
m_reverseSort = !m_reverseSort;
}
needUpdate = true;
}
else
{
handled = false;
}
}
if (!handled && MythScreenType::keyPressEvent(e))
handled = true;
if (needUpdate)
LoadInBackground();
m_allowEvents = true;
return handled;
}
void ProgLister::ShowMenu(void)
{
auto *sortMenu = new MythMenu(tr("Sort Options"), this, "sortmenu");
sortMenu->AddItem(tr("Reverse Sort Order"));
sortMenu->AddItem(tr("Sort By Title"));
sortMenu->AddItem(tr("Sort By Time"));
auto *menu = new MythMenu(tr("Options"), this, "menu");
if (m_allowViewDialog && m_type != plPreviouslyRecorded)
{
menu->AddItem(tr("Choose Search Phrase..."), SLOT(ShowChooseViewMenu()));
}
menu->AddItem(tr("Sort"), nullptr, sortMenu);
if (m_type != plPreviouslyRecorded)
menu->AddItem(tr("Record"), SLOT(QuickRecord()));
menu->AddItem(tr("Edit Schedule"), SLOT(EditScheduled()));
menu->AddItem(tr("Program Details"), SLOT(ShowDetails()));
menu->AddItem(tr("Program Guide"), SLOT(ShowGuide()));
if (m_type != plChannel)
menu->AddItem(tr("Channel Search"), SLOT(ShowChannelSearch()));
if (m_type != plTitle)
menu->AddItem(tr("Upcoming"), SLOT(ShowUpcoming()));
if (m_type != plPreviouslyRecorded)
menu->AddItem(tr("Previously Recorded"),SLOT(ShowPrevious()));
menu->AddItem(tr("Custom Edit"), SLOT(EditCustom()));
ProgramInfo *pi = m_itemList[m_progList->GetCurrentPos()];
if (m_type != plPreviouslyRecorded)
{
if (pi && pi->GetRecordingRuleID())
menu->AddItem(tr("Delete Rule"), SLOT(ShowDeleteRuleMenu()));
}
else
{
menu->AddItem(
tr("Delete Episode"), SLOT(ShowDeleteOldEpisodeMenu()));
}
MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
auto *menuPopup = new MythDialogBox(menu, popupStack, "menuPopup");
if (!menuPopup->Create())
{
delete menuPopup;
return;
}
popupStack->AddScreen(menuPopup);
}
void ProgLister::SwitchToPreviousView(void)
{
if (m_type == plTime && !m_viewList.empty() && !m_viewTextList.empty())
{
m_searchTime = m_searchTime.addSecs(-3600);
m_curView = 0;
m_viewList[m_curView] = MythDate::toString(m_searchTime,
MythDate::kDateTimeFull | MythDate::kSimplify);
m_viewTextList[m_curView] = m_viewList[m_curView];
LoadInBackground();
return;
}
if (m_viewList.size() <= 1)
return;
m_curView--;
if (m_curView < 0)
m_curView = m_viewList.size() - 1;
LoadInBackground();
}
void ProgLister:: SwitchToNextView(void)
{
if (m_type == plTime && !m_viewList.empty() && !m_viewTextList.empty())
{
m_searchTime = m_searchTime.addSecs(3600);
m_curView = 0;
m_viewList[m_curView] = MythDate::toString(m_searchTime,
MythDate::kDateTimeFull | MythDate::kSimplify);
m_viewTextList[m_curView] = m_viewList[m_curView];
LoadInBackground();
return;
}
if (m_viewList.size() <= 1)
return;
m_curView++;
if (m_curView >= m_viewList.size())
m_curView = 0;
LoadInBackground();
}
void ProgLister::UpdateKeywordInDB(const QString &text, const QString &oldValue)
{
int oldview = m_viewList.indexOf(oldValue);
int newview = m_viewList.indexOf(text);
if (newview >= 0 && newview == oldview)
return;
if (oldview >= 0)
{
QString qphrase = m_viewList[oldview];
MSqlQuery query(MSqlQuery::InitCon());
query.prepare("DELETE FROM keyword "
"WHERE phrase = :PHRASE AND searchtype = :TYPE;");
query.bindValue(":PHRASE", qphrase);
query.bindValue(":TYPE", m_searchType);
if (!query.exec())
{
MythDB::DBError(
"ProgLister::updateKeywordInDB -- delete", query);
}
m_viewList.removeAll(qphrase);
m_viewTextList.removeAll(qphrase);
}
if (newview < 0)
{
const QString& qphrase = text;
MSqlQuery query(MSqlQuery::InitCon());
query.prepare("REPLACE INTO keyword (phrase, searchtype)"
"VALUES(:PHRASE, :TYPE );");
query.bindValue(":PHRASE", qphrase);
query.bindValue(":TYPE", m_searchType);
if (!query.exec())
{
MythDB::DBError(
"ProgLister::updateKeywordInDB -- replace", query);
}
m_viewList.push_back(qphrase);
m_viewTextList.push_back(qphrase);
}
}
void ProgLister::ShowChooseViewMenu(void)
{
MythScreenStack *popupStack =
GetMythMainWindow()->GetStack("popup stack");
MythScreenType *screen = nullptr;
bool connect_string = true;
switch (m_type)
{
case plChannel:
case plCategory:
case plMovies:
case plNewListings:
case plStoredSearch:
{
if (m_viewList.empty())
return;
QString msg;
switch (m_type)
{
case plMovies: msg = tr("Select Rating"); break;
case plChannel: msg = tr("Select Channel"); break;
case plCategory: msg = tr("Select Category"); break;
case plNewListings: msg = tr("Select List"); break;
case plStoredSearch: msg = QString("%1\n%2")
.arg(tr("Select a search stored from"))
.arg(tr("Custom Record")); break;
default: // silence warning
break;
}
screen = new MythUISearchDialog(
popupStack, msg, m_viewTextList, true, "");
break;
}
case plTitleSearch:
case plKeywordSearch:
case plPeopleSearch:
screen = new PhrasePopup(
popupStack, this, m_searchType, m_viewTextList,
(m_curView >= 0) ? m_viewList[m_curView] : QString());
break;
case plPowerSearch:
screen = new PowerSearchPopup(
popupStack, this, m_searchType, m_viewTextList,
(m_curView >= 0) ? m_viewList[m_curView] : QString());
break;
case plTime:
{
QString message = tr("Start search from date and time");
int flags = (MythTimeInputDialog::kDay |
MythTimeInputDialog::kHours |
MythTimeInputDialog::kFutureDates);
screen = new MythTimeInputDialog(popupStack, message, flags);
connect_string = false;
break;
}
case plRecordid:
case plPreviouslyRecorded:
case plUnknown:
case plTitle:
case plSQLSearch:
break;
}
if (!screen)
return;
if (!screen->Create())
{
delete screen;
return;
}
if (connect_string)
{
connect(screen, SIGNAL(haveResult( QString)),
this, SLOT( SetViewFromList(QString)));
}
else
{
connect(screen, SIGNAL(haveResult( QDateTime)),
this, SLOT( SetViewFromTime(QDateTime)));
}
popupStack->AddScreen(screen);
}
void ProgLister::SetViewFromTime(QDateTime searchTime)
{
if (m_viewList.empty() || m_viewTextList.empty())
return;
m_searchTime = std::move(searchTime);
m_curView = 0;
m_viewList[m_curView] = MythDate::toString(m_searchTime,
MythDate::kDateTimeFull | MythDate::kSimplify);
m_viewTextList[m_curView] = m_viewList[m_curView];
LoadInBackground();
}
void ProgLister::SetViewFromList(const QString& item)
{
m_curView = m_viewTextList.indexOf(item);
if (m_curView >= 0)
LoadInBackground();
}
bool ProgLister::PowerStringToSQL(
const QString &qphrase, QString &output, MSqlBindings &bindings)
{
output.clear();
QStringList field = qphrase.split(':');
if (field.size() != 6)
{
LOG(VB_GENERAL, LOG_ERR, LOC + "Power search should have 6 fields," +
QString("\n\t\t\tnot %1 (%2)") .arg(field.size()).arg(qphrase));
return false;
};
static const std::array<QString,6> kBindingList
{
":POWERTITLE",
":POWERSUB",
":POWERDESC",
":POWERCATTYPE",
":POWERGENRE",
":POWERCALLSIGN",
};
static const std::array<QString,6> kOutputList
{
"program.title LIKE :POWERTITLE ",
"program.subtitle LIKE :POWERSUB ",
"program.description LIKE :POWERDESC ",
"program.category_type = :POWERCATTYPE ",
"programgenres.genre = :POWERGENRE ",
"channel.callsign = :POWERCALLSIGN ",
};
for (uint i = 0; i < (uint) field.size(); i++)
{
if (field[i].isEmpty())
continue;
if (!output.isEmpty())
output += "\nAND ";
output += kOutputList[i];
bindings[kBindingList[i]] =
(!kOutputList[i].contains("=")) ?
QString('%') + field[i] + QString('%') : field[i];
}
return output.contains("programgenres");
}
ProgramInfo *ProgLister::GetCurrentProgram(void) const
{
int pos = m_progList->GetCurrentPos();
if (pos >= 0 && pos < (int) m_itemList.size())
return m_itemList[pos];
return nullptr;
}
void ProgLister::ShowDeleteItemMenu(void)
{
if (m_type == plPreviouslyRecorded)
ShowDeleteOldEpisodeMenu();
else
ShowDeleteRuleMenu();
}
void ProgLister::ShowDeleteRuleMenu(void)
{
ProgramInfo *pi = GetCurrentProgram();
if (!pi || !pi->GetRecordingRuleID())
return;
auto *record = new RecordingRule();
if (!record->LoadByProgram(pi))
{
delete record;
return;
}
QString message = tr("Delete '%1' %2 rule?").arg(record->m_title)
.arg(toString(pi->GetRecordingRuleType()));
MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
auto *okPopup = new MythConfirmationDialog(
popupStack, message, true);
okPopup->SetReturnEvent(this, "deleterule");
okPopup->SetData(QVariant::fromValue(record));
if (okPopup->Create())
popupStack->AddScreen(okPopup);
else
delete okPopup;
}
void ProgLister::ShowDeleteOldEpisodeMenu(void)
{
ProgramInfo *pi = GetCurrentProgram();
if (!pi)
return;
QString message = tr("Delete this episode of '%1'?").arg(pi->GetTitle());
ShowOkPopup(message, this, SLOT(DeleteOldEpisode(bool)), true);
}
void ProgLister::DeleteOldEpisode(bool ok)
{
ProgramInfo *pi = GetCurrentProgram();
if (!ok || !pi)
return;
MSqlQuery query(MSqlQuery::InitCon());
query.prepare(
"DELETE FROM oldrecorded "
"WHERE chanid = :CHANID AND "
" starttime = :STARTTIME");
query.bindValue(":CHANID", pi->GetChanID());
query.bindValue(":STARTTIME", pi->GetScheduledStartTime());
if (!query.exec())
MythDB::DBError("ProgLister::DeleteOldEpisode", query);
ScheduledRecording::RescheduleCheck(*pi, "DeleteOldEpisode");
FillItemList(true);
}
void ProgLister::ShowDeleteOldSeriesMenu(void)
{
ProgramInfo *pi = GetCurrentProgram();
if (!pi)
return;
QString message = tr("Delete all episodes of '%1'?").arg(pi->GetTitle());
ShowOkPopup(message, this, SLOT(DeleteOldSeries(bool)), true);
}
void ProgLister::DeleteOldSeries(bool ok)
{
ProgramInfo *pi = GetCurrentProgram();
if (!ok || !pi)
return;
MSqlQuery query(MSqlQuery::InitCon());
query.prepare("DELETE FROM oldrecorded "
"WHERE title = :TITLE AND future = 0");
query.bindValue(":TITLE", pi->GetTitle());
if (!query.exec())
MythDB::DBError("ProgLister::DeleteOldSeries -- delete", query);
// Set the programid to the special value of "**any**" which the
// scheduler recognizes to mean the entire series was deleted.
RecordingInfo tempri(*pi);
tempri.SetProgramID("**any**");
ScheduledRecording::RescheduleCheck(tempri, "DeleteOldSeries");
FillItemList(true);
}
void ProgLister::ShowOldRecordedMenu(void)
{
ProgramInfo *pi = GetCurrentProgram();
if (!pi)
return;
QString message = pi->toString(ProgramInfo::kTitleSubtitle, " - ");
if (!pi->GetDescription().isEmpty())
message += "\n\n" + pi->GetDescription();
message += "\n\n\n" + tr("NOTE: removing items from this list will not "
"delete any recordings.");
QString title = tr("Previously Recorded");
auto *menu = new MythMenu(title, message, this, "deletemenu");
if (pi->IsDuplicate())
menu->AddItem(tr("Allow this episode to re-record"));
else
menu->AddItem(tr("Never record this episode"));
menu->AddItem(tr("Remove this episode from the list"));
menu->AddItem(tr("Remove all episodes for this title"));
menu->AddItem(tr("Cancel"));
MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
auto *menuPopup = new MythDialogBox(menu, mainStack, "deletepopup", true);
if (menuPopup->Create())
mainStack->AddScreen(menuPopup);
else
delete menuPopup;
}
void ProgLister::FillViewList(const QString &view)
{
m_viewList.clear();
m_viewTextList.clear();
if (m_type == plChannel) // list by channel
{
ChannelInfoList channels = ChannelUtil::GetChannels(
0, true, "channum, chanid");
ChannelUtil::SortChannels(channels, m_channelOrdering, true);
for (auto & channel : channels)
{
QString chantext = channel.GetFormatted(ChannelInfo::kChannelShort);
m_viewList.push_back(QString::number(channel.m_chanId));
m_viewTextList.push_back(chantext);
}
if (!view.isEmpty())
m_curView = m_viewList.indexOf(view);
}
else if (m_type == plCategory) // list by category
{
QDateTime query_starttime = m_startTime.addSecs(50 -
m_startTime.time().second());
MSqlQuery query(MSqlQuery::InitCon());
query.prepare("SELECT g1.genre, g2.genre "
"FROM program "
"JOIN programgenres g1 ON "
" program.chanid = g1.chanid AND "
" program.starttime = g1.starttime "
"LEFT JOIN programgenres g2 ON "
" g1.chanid = g2.chanid AND "
" g1.starttime = g2.starttime "
"WHERE program.endtime > :PGILSTART "
"GROUP BY g1.genre, g2.genre;");
query.bindValue(":PGILSTART", query_starttime);
m_useGenres = false;
if (query.exec())
{
QString lastGenre1;
while (query.next())
{
m_useGenres = true;
QString genre1 = query.value(0).toString();
if (genre1.isEmpty())
continue;
if (genre1 != lastGenre1)
{
m_viewList.push_back(genre1);
m_viewTextList.push_back(genre1);
lastGenre1 = genre1;
}
QString genre2 = query.value(1).toString();
if (genre2.isEmpty() || genre2 == genre1)
continue;
m_viewList.push_back(genre1 + ":/:" + genre2);
m_viewTextList.push_back(" " + genre1 + " / " + genre2);
}
}
if (!m_useGenres)
{
query.prepare("SELECT category "
"FROM program "
"WHERE program.endtime > :PGILSTART "
"GROUP BY category");
query.bindValue(":PGILSTART", query_starttime);
if (query.exec())
{
while (query.next())
{
QString category = query.value(0).toString();
if (category.isEmpty())
continue;
category = query.value(0).toString();
m_viewList.push_back(category);
m_viewTextList.push_back(category);
}
}
}
if (!view.isEmpty())
m_curView = m_viewList.indexOf(view);
}
else if (m_type == plTitleSearch || m_type == plKeywordSearch ||
m_type == plPeopleSearch || m_type == plPowerSearch)
{
MSqlQuery query(MSqlQuery::InitCon());
query.prepare("SELECT phrase FROM keyword "
"WHERE searchtype = :SEARCHTYPE;");
query.bindValue(":SEARCHTYPE", m_searchType);
if (query.exec())
{
while (query.next())
{
/* The keyword.phrase column uses utf8_bin collation, so
* Qt uses QString::fromAscii() for toString(). Explicitly
* convert the value using QString::fromUtf8() to prevent
* corruption. */
QString phrase = QString::fromUtf8(query.value(0)
.toByteArray().constData());
if (phrase.isEmpty())
continue;
m_viewList.push_back(phrase);
m_viewTextList.push_back(phrase);
}
}
if (!view.isEmpty())
{
m_curView = m_viewList.indexOf(view);
if (m_curView < 0)
{
const QString& qphrase = view;
MSqlQuery query2(MSqlQuery::InitCon());
query2.prepare("REPLACE INTO keyword (phrase, searchtype)"
"VALUES(:VIEW, :SEARCHTYPE );");
query2.bindValue(":VIEW", qphrase);
query2.bindValue(":SEARCHTYPE", m_searchType);
if (!query2.exec())
MythDB::DBError("ProgLister::FillViewList -- "
"replace keyword", query2);
m_viewList.push_back(qphrase);
m_viewTextList.push_back(qphrase);
m_curView = m_viewList.size() - 1;
}
}
else
{
m_curView = -1;
}
}
else if (m_type == plTitle)
{
if (!view.isEmpty())
{
m_viewList.push_back(view);
m_viewTextList.push_back(view);
m_curView = 0;
}
else
{
m_curView = -1;
}
}
else if (m_type == plNewListings)
{
m_viewList.push_back("all");
m_viewTextList.push_back(tr("All"));
m_viewList.push_back("premieres");
m_viewTextList.push_back(tr("Premieres"));
m_viewList.push_back("movies");
m_viewTextList.push_back(tr("Movies"));
m_viewList.push_back("series");
m_viewTextList.push_back(tr("Series"));
m_viewList.push_back("specials");
m_viewTextList.push_back(tr("Specials"));
if (!view.isEmpty())
m_curView = m_viewList.indexOf(view);
}
else if (m_type == plMovies)
{
m_viewList.push_back(">= 0.0");
m_viewTextList.push_back(tr("All"));
m_viewList.push_back("= 0.0");
m_viewTextList.push_back(tr("Unrated"));
m_viewList.push_back(QString(">= %1").arg((10 - 0.5) / 10.0 - 0.001));
m_viewTextList.push_back(tr("%n star(s)", "", 10));
for (int i = 9; i > 0; i--)
{
float stars = (i - 0.5 ) / 10.0 - 0.001;
m_viewList.push_back(QString(">= %1").arg(stars));
m_viewTextList.push_back(tr("%n star(s) and above", "", i));
}
if (!view.isEmpty())
m_curView = m_viewList.indexOf(view);
}
else if (m_type == plTime)
{
m_curView = 0;
m_viewList.push_back(MythDate::toString(m_searchTime,
MythDate::kDateTimeFull | MythDate::kSimplify));
m_viewTextList.push_back(m_viewList[m_curView]);
}
else if (m_type == plSQLSearch)
{
m_curView = 0;
m_viewList.push_back(view);
m_viewTextList.push_back(tr("Power Recording Rule"));
}
else if (m_type == plRecordid)
{
m_curView = 0;
MSqlQuery query(MSqlQuery::InitCon());
query.prepare("SELECT title FROM record "
"WHERE recordid = :RECORDID");
query.bindValue(":RECORDID", view);
if (query.exec() && query.next())
{
QString title = query.value(0).toString();
m_viewList.push_back(view);
m_viewTextList.push_back(title);
}
}
else if (m_type == plStoredSearch) // stored searches
{
MSqlQuery query(MSqlQuery::InitCon());
query.prepare("SELECT rulename FROM customexample "
"WHERE search > 0 ORDER BY rulename;");
if (query.exec())
{
while (query.next())
{
QString rulename = query.value(0).toString();
if (rulename.isEmpty() || rulename.trimmed().isEmpty())
continue;
rulename = query.value(0).toString();
m_viewList.push_back(rulename);
m_viewTextList.push_back(rulename);
}
}
if (!view.isEmpty())
m_curView = m_viewList.indexOf(view);
}
else if (m_type == plPreviouslyRecorded) // previously recorded
{
m_viewList.push_back("sort by time");
m_viewTextList.push_back(tr("Time"));
m_viewList.push_back("reverse time");
m_viewTextList.push_back(tr("Reverse Time"));
m_viewList.push_back("sort by title");
m_viewTextList.push_back(tr("Title"));
m_viewList.push_back("reverse title");
m_viewTextList.push_back(tr("Reverse Title"));
if (!view.isEmpty())
m_curView = m_viewList.indexOf(view);
}
if (m_curView >= m_viewList.size())
m_curView = m_viewList.size() - 1;
}
class plCompare : std::binary_function<const ProgramInfo*, const ProgramInfo*, bool>
{
public:
virtual bool operator()(const ProgramInfo*, const ProgramInfo*) = 0;
virtual ~plCompare() = default;
};