-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmenusched.c
1228 lines (963 loc) · 34.7 KB
/
menusched.c
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
/*
* menusched.c: EPG2VDR plugin for the Video Disk Recorder
*
* See the README file for copyright information and how to reach the author.
*
*/
#include <string>
#include <vdr/menuitems.h>
#include <vdr/status.h>
#include <vdr/menu.h>
#include "lib/xml.h"
#include "plgconfig.h"
#include "menu.h"
#include "ttools.h"
class cMenuEpgScheduleItem;
//***************************************************************************
// Class cEpgCommandMenu
//***************************************************************************
class cEpgCommandMenu : public cOsdMenu
{
public:
cEpgCommandMenu(const char* title, cMenuDb* db, const cMenuEpgScheduleItem* aItem);
virtual ~cEpgCommandMenu() { };
virtual eOSState ProcessKey(eKeys key);
protected:
const cMenuEpgScheduleItem* item;
cMenuDb* menuDb;
};
cEpgCommandMenu::cEpgCommandMenu(const char* title, cMenuDb* db, const cMenuEpgScheduleItem* aItem)
: cOsdMenu(title)
{
item = aItem;
menuDb = db;
SetMenuCategory(mcMain);
SetHasHotkeys(yes);
Clear();
cOsdMenu::Add(new cOsdItem(hk(tr("Search matching Events")), osUser1));
cOsdMenu::Add(new cOsdItem(hk(tr("Search matching Recordings")), osUser2));
cOsdMenu::Add(new cOsdItem(hk(tr("Searchtimers")), osUser3));
cOsdMenu::Add(new cOsdItem(hk(tr("Switch Timer")), osUser4));
SetHelp(0, 0, 0, 0);
Display();
}
eOSState cEpgCommandMenu::ProcessKey(eKeys key)
{
eOSState state = cOsdMenu::ProcessKey(key);
switch (state)
{
case osUser1:
{
if (item)
return AddSubMenu(new cMenuEpgWhatsOn(item->event));
break;
}
case osUser2:
{
if (item)
return AddSubMenu(new cMenuEpgMatchRecordings(menuDb, item->event));
break;
}
case osUser3:
{
return AddSubMenu(new cMenuEpgSearchTimers());
}
case osUser4:
{
if (item)
menuDb->createSwitchTimer(item->event);
return osBack;
}
default: ;
}
return state;
}
//***************************************************************************
// Class cMenuEpgMatchRecordings
//***************************************************************************
cMenuEpgMatchRecordings::cMenuEpgMatchRecordings(cMenuDb* db, const cEvent* event)
: cOsdMenu(tr("Matching recordings"), 30, 30, 30, 40)
{
cMenuDb* menuDb = db;
std::map<std::string,bool> directMatches;
Add(new cOsdItem(tr("Direct Matches:")));
cList<cOsdItem>::Last()->SetSelectable(no);
tell(0, "Search recordings for '%s' '%s'", event->Title(), event->ShortText());
menuDb->recordingListDb->clear();
menuDb->recordingListDb->setValue("TITLE", event->Title());
menuDb->recordingListDb->setValue("SHORTTEXT", event->ShortText());
for (int f = menuDb->selectRecordingForEvent->find(); f; f = menuDb->selectRecordingForEvent->fetch())
{
const char* vdr = 0;
#ifdef WITH_PIN
if (!cOsd::pinValid && menuDb->recordingListDb->getIntValue("FSK"))
continue;
#endif
if (!menuDb->recordingListDb->getValue("OWNER")->isEmpty())
{
menuDb->vdrDb->clear();
menuDb->vdrDb->setValue("UUID", menuDb->recordingListDb->getStrValue("OWNER"));
if (menuDb->vdrDb->find())
vdr = menuDb->vdrDb->getStrValue("NAME");
}
directMatches[menuDb->vdrDb->getStrValue("MD5PATH")] = yes;
Add(new cEpgMenuTextItem(menuDb->recordingListDb->getStrValue("MD5PATH"),
cString::sprintf("%s%s%s\t%s\t%s/%s", vdr ? vdr : "", vdr ? "\t" : "",
menuDb->recordingListDb->getStrValue("TITLE"),
menuDb->recordingListDb->getStrValue("SHORTTEXT"),
menuDb->recordingListDb->getStrValue("FOLDER"),
menuDb->recordingListDb->getStrValue("NAME"))));
}
menuDb->selectRecordingForEvent->freeResult();
Add(new cOsdItem(tr("Similar Matches:")));
cList<cOsdItem>::Last()->SetSelectable(no);
menuDb->recordingListDb->clear();
menuDb->recordingListDb->setValue("TITLE", event->Title());
for (int f = menuDb->selectRecordingForEventByLv->find(); f; f = menuDb->selectRecordingForEventByLv->fetch())
{
const char* vdr = 0;
#ifdef WITH_PIN
if (!cOsd::pinValid && menuDb->recordingListDb->getIntValue("FSK"))
continue;
#endif
if (!menuDb->recordingListDb->getValue("OWNER")->isEmpty())
{
menuDb->vdrDb->clear();
menuDb->vdrDb->setValue("UUID", menuDb->recordingListDb->getStrValue("OWNER"));
if (menuDb->vdrDb->find())
vdr = menuDb->vdrDb->getStrValue("NAME");
}
auto it = directMatches.find(menuDb->vdrDb->getStrValue("MD5PATH"));
if (it == directMatches.end())
{
Add(new cEpgMenuTextItem(menuDb->recordingListDb->getStrValue("MD5PATH"),
cString::sprintf("%s%s%s\t%s\t%s/%s", vdr ? vdr : "", vdr ? "\t" : "",
menuDb->recordingListDb->getStrValue("TITLE"),
menuDb->recordingListDb->getStrValue("SHORTTEXT"),
menuDb->recordingListDb->getStrValue("FOLDER"),
menuDb->recordingListDb->getStrValue("NAME"))));
}
}
menuDb->selectRecordingForEventByLv->freeResult();
Display();
}
eOSState cMenuEpgMatchRecordings::ProcessKey(eKeys Key)
{
eOSState state = cOsdMenu::ProcessKey(Key);
if (state == osUnknown)
{
return osContinue;
}
return state;
}
//***************************************************************************
//***************************************************************************
// Class cMenuEpgScheduleItem
//***************************************************************************
cMenuEpgScheduleItem::eScheduleSortMode cMenuEpgScheduleItem::sortMode {ssmAllThis};
//***************************************************************************
// Object
//***************************************************************************
cMenuEpgScheduleItem::cMenuEpgScheduleItem(cMenuDb* db, const cEvent* Event,
const cChannel* Channel, bool WithDate)
{
menuDb = db;
event = Event;
channel = Channel;
withDate = WithDate;
timerMatch = tmNone;
Update(yes);
}
cMenuEpgScheduleItem::~cMenuEpgScheduleItem()
{
}
//***************************************************************************
// Compare
//***************************************************************************
int cMenuEpgScheduleItem::Compare(const cListObject &ListObject) const
{
cMenuEpgScheduleItem* p = (cMenuEpgScheduleItem*)&ListObject;
int r = -1;
if (sortMode != ssmAllThis)
r = strcoll(event->Title(), p->event->Title());
if (sortMode == ssmAllThis || r == 0)
r = event->StartTime() - p->event->StartTime();
return r;
}
//***************************************************************************
// Update
//***************************************************************************
bool cMenuEpgScheduleItem::Update(bool Force)
{
static const char* TimerMatchChars = " tT";
static const char* TimerMatchCharsRemote = " sS";
bool result = false;
int oldTimerMatch = timerMatch;
int remote = no;
char type;
if (event)
menuDb->lookupTimer(event, timerMatch, remote, type); // -> loads timerDb, vdrDb and set ther timerMatch
if (Force || timerMatch != oldTimerMatch)
{
if (timerMatch && event)
tell(0, "Timer match for '%s'", event->Title());
cString buffer;
char t = !remote ? TimerMatchChars[timerMatch] : TimerMatchCharsRemote[timerMatch];
char v = !event ? ' ' : event->Vps() && (event->Vps() - event->StartTime()) ? 'V' : ' ';
char r = !event ? ' ' : event->SeenWithin(30) && event->IsRunning() ? '*' : ' ';
const char* csn = channel ? channel->ShortName(true) : 0;
cString eds = !event ? "" : event->GetDateString();
if (channel && withDate)
buffer = cString::sprintf("%d\t%.*s\t%.*s\t%s\t%c%c%c\t%s", channel->Number(),
Utf8SymChars(csn, 999), csn, Utf8SymChars(eds, 6),
*eds,
!event ? "" : *event->GetTimeString(),
t, v, r,
!event ? "" : event->Title());
else if (channel)
buffer = cString::sprintf("%d\t%.*s\t%s\t%c%c%c\t%s", channel->Number(),
Utf8SymChars(csn, 999), csn,
!event ? "" : *event->GetTimeString(),
t, v, r,
!event ? "" : event->Title());
else
buffer = cString::sprintf("%.*s\t%s\t%c%c%c\t%s", Utf8SymChars(eds, 6), *eds,
!event ? "" : *event->GetTimeString(),
t, v, r, !event ? "" :
!event ? "" : event->Title());
SetText(buffer);
result = true;
}
return result;
}
//***************************************************************************
// Set Menu Item
//***************************************************************************
void cMenuEpgScheduleItem::SetMenuItem(cSkinDisplayMenu* DisplayMenu,
int Index, bool Current, bool Selectable)
{
if (!DisplayMenu->SetItemEvent(event, Index, Current, Selectable, channel,
withDate, (eTimerMatch)timerMatch, false))
{
DisplayMenu->SetItem(Text(), Index, Current, Selectable);
}
}
//***************************************************************************
//***************************************************************************
// cMenuEpgScheduleSepItem
//***************************************************************************
class cMenuEpgScheduleSepItem : public cOsdItem
{
public:
cMenuEpgScheduleSepItem(const cChannel* Channel, const cEvent* Event);
~cMenuEpgScheduleSepItem();
virtual bool Update(bool Force = false);
virtual void SetMenuItem(cSkinDisplayMenu *DisplayMenu, int Index, bool Current, bool Selectable);
private:
const cChannel* channel;
const cEvent* event;
cEvent* tmpEvent;
};
cMenuEpgScheduleSepItem::cMenuEpgScheduleSepItem(const cChannel* Channel, const cEvent* Event)
{
channel = Channel;
event = Event;
tmpEvent = 0;
SetSelectable(false);
Update(true);
}
cMenuEpgScheduleSepItem::~cMenuEpgScheduleSepItem()
{
delete tmpEvent;
}
bool cMenuEpgScheduleSepItem::Update(bool Force)
{
if (tmpEvent)
{
delete tmpEvent;
tmpEvent = 0;
}
if (channel)
{
tmpEvent = new cEvent(0);
tmpEvent->SetTitle(cString::sprintf("-----\t %s -----", channel->Name()));
tmpEvent->SetShortText(strncmp(channel->Name(), "->", 2) == 0 ? channel->Name()+2 : channel->Name()); // using short text to transport plain value to skin
SetText(tmpEvent->Title());
}
else if (event)
{
tmpEvent = new cEvent(0);
tmpEvent->SetTitle(cString::sprintf("-----\t %s -----", *event->GetDateString()));
tmpEvent->SetShortText(event->GetDateString()); // using short text to transport plain value to skin
SetText(tmpEvent->Title());
}
return true;
}
void cMenuEpgScheduleSepItem::SetMenuItem(cSkinDisplayMenu *DisplayMenu, int Index, bool Current, bool Selectable)
{
tell(0, "calling SetMenuItem with '%s'", tmpEvent ? tmpEvent->Title() : "<null>");
if (!DisplayMenu->SetItemEvent(tmpEvent, Index, Current, Selectable, channel, no, tmNone, false))
DisplayMenu->SetItem(Text(), Index, Current, Selectable);
}
//***************************************************************************
// cMenuEpgEvent
//***************************************************************************
cMenuEpgEvent::cMenuEpgEvent(cMenuDb* db, const cEvent* Event, const cSchedules* Schedules,
int timerMatch, bool DispSchedule, bool CanSwitch)
: cOsdMenu(tr("Event"))
{
menuDb = db;
dispSchedule = DispSchedule;
schedules = Schedules;
canSwitch = CanSwitch;
SetMenuCategory(mcEvent);
setEvent(Event, timerMatch);
}
//***************************************************************************
// Set Event
//***************************************************************************
int cMenuEpgEvent::setEvent(const cEvent* Event, int timerMatch)
{
if (Event)
{
event = Event;
#if APIVERSNUM >= 20301
LOCK_CHANNELS_READ;
const cChannels* channels = Channels;
const cChannel* channel = channels->GetByChannelID(event->ChannelID(), true);
#else
cChannels* channels = &Channels;
cChannel* channel = channels->GetByChannelID(event->ChannelID(), true);
#endif
if (channel)
{
const cChannel* prevChannel = 0;
const cChannel* nextChannel = 0;
prevTime = "";
nextTime = "";
SetTitle(channel->Name());
if (menuDb->userTimes->current()->getMode() != cUserTimes::mSearch)
{
const cEvent* e;
if ((e = getNextPrevEvent(event, -1)))
{
if (dispSchedule)
prevTime = l2pTime(e->StartTime(), "%H:%M");
else
prevChannel = channels->GetByChannelID(e->ChannelID(), true);
}
if ((e = getNextPrevEvent(event, +1)))
{
if (dispSchedule)
nextTime = l2pTime(e->StartTime(), "%H:%M");
else
nextChannel = channels->GetByChannelID(e->ChannelID(), true);
}
}
SetHelp(timerMatch == tmFull ? tr("Button$Timer") : tr("Button$Record"),
dispSchedule ? prevTime.c_str() : (prevChannel ? prevChannel->Name() : 0),
dispSchedule ? nextTime.c_str() : (nextChannel ? nextChannel->Name() : 0),
canSwitch ? tr("Button$Switch") : 0);
}
Display();
}
return success;
}
void cMenuEpgEvent::Display()
{
cOsdMenu::Display();
DisplayMenu()->SetEvent(event);
#ifdef WITH_GTFT
cStatus::MsgOsdSetEvent(event);
#endif
if (event->Description())
cStatus::MsgOsdTextItem(event->Description());
}
//***************************************************************************
// Get Next Prev Event (related to current)
//***************************************************************************
const cEvent* cMenuEpgEvent::getNextPrevEvent(const cEvent* event, int step)
{
#if APIVERSNUM >= 20301
LOCK_CHANNELS_READ;
const cChannels* channels = Channels;
const cChannel* channel = channels->GetByChannelID(event->ChannelID(), true);
#else
cChannels* channels = &Channels;
cChannel* channel = channels->GetByChannelID(event->ChannelID(), true);
#endif
const cEvent* e = 0;
if (dispSchedule)
{
const cSchedule* schedule = schedules->GetSchedule(channel);
if (schedule && step == -1)
e = schedule->Events()->Prev(event);
else if (schedule && step == +1)
e = schedule->Events()->Next(event);
}
else
{
while (!e)
{
int cn = channel->Number() + step;
if (cn < 1)
cn = channels->MaxNumber();
else if (cn > channels->MaxNumber())
cn = 1;
if (!(channel = channels->GetByNumber(cn)))
return 0;
const cSchedule* schedule = schedules->GetSchedule(channel);
if (schedule)
{
cUserTimes::UserTime* userTime = menuDb->userTimes->current();
switch (userTime->getMode())
{
case cUserTimes::mNow: e = schedule->GetPresentEvent(); break;
case cUserTimes::mNext: e = schedule->GetFollowingEvent(); break;
case cUserTimes::mTime: e = schedule->GetEventAround(userTime->getTime()); break;
}
}
}
}
return e;
}
//***************************************************************************
// Process Key
//***************************************************************************
eOSState cMenuEpgEvent::ProcessKey(eKeys Key)
{
switch (int(Key))
{
case kUp|k_Repeat:
case kUp:
case kDown|k_Repeat:
case kDown:
case kLeft|k_Repeat:
case kLeft:
case kRight|k_Repeat:
case kRight:
{
DisplayMenu()->Scroll(NORMALKEY(Key) == kUp || NORMALKEY(Key) == kLeft, NORMALKEY(Key) == kLeft || NORMALKEY(Key) == kRight);
cStatus::MsgOsdTextItem(NULL, NORMALKEY(Key) == kUp || NORMALKEY(Key) == kLeft);
return osContinue;
}
case kInfo: return osBack;
default: break;
}
if (Key == kGreen || Key == kYellow)
{
if (menuDb->userTimes->current()->getMode() == cUserTimes::mSearch)
return osContinue;
const cEvent* e = getNextPrevEvent(event, Key == kGreen ? -1 : +1);
int remote = no;
int timerMatch = tmNone;
char type;
// get remote and timerMatch info
menuDb->lookupTimer(e, timerMatch, remote, type);
setEvent(e, timerMatch);
return osContinue;
}
eOSState state = cOsdMenu::ProcessKey(Key);
if (state == osUnknown)
{
switch (Key)
{
case kOk: return osBack;
default: break;
}
}
return state;
}
//***************************************************************************
//***************************************************************************
// cMenuEpgWhatsOn
//***************************************************************************
int cMenuEpgWhatsOn::currentChannel {0};
const cEvent* cMenuEpgWhatsOn::scheduleEvent {};
//***************************************************************************
// Object
//***************************************************************************
cMenuEpgWhatsOn::cMenuEpgWhatsOn(const cEvent* aSearchEvent)
: cOsdMenu("", CHNUMWIDTH, CHNAMWIDTH, 6, 4)
{
searchEvent = aSearchEvent;
menuDb = new cMenuDb;
#if APIVERSNUM >= 20301
LOCK_CHANNELS_READ;
const cChannels* channels = Channels;
const cChannel* channel = channels->GetByNumber(cDevice::CurrentChannel());
#else
cChannels* channels = &Channels;
const cChannel* channel = channels->GetByNumber(cDevice::CurrentChannel());
#endif
if (channel)
{
currentChannel = channel->Number();
#if defined (APIVERSNUM) && (APIVERSNUM >= 20301)
schedules = cSchedules::GetSchedulesRead(schedulesKey);
#else
schedulesLock = new cSchedulesLock(false);
schedules = (cSchedules*)cSchedules::Schedules(*schedulesLock);
#endif
}
// Timers.Modified(timerState);
if (menuDb->dbConnected())
{
menuDb->userTimes->first(); // 'whats on now' should be the first
if (searchEvent)
LoadQuery(searchEvent);
else if (menuDb->startWithSched)
LoadSchedule();
else
LoadAt();
}
}
cMenuEpgWhatsOn::~cMenuEpgWhatsOn()
{
delete menuDb;
#if defined (APIVERSNUM) && (APIVERSNUM >= 20301)
if (schedules)
schedulesKey.Remove();
#else
tell(3, "LOCK free (cMenuEpgWhatsOn)");
delete schedulesLock;
#endif
}
//***************************************************************************
// Load At
//***************************************************************************
int cMenuEpgWhatsOn::LoadAt()
{
dispSchedule = no;
cUserTimes::UserTime* userTime = menuDb->userTimes->current();
cMenuEpgScheduleItem* item = (cMenuEpgScheduleItem*)Get(Current());
if (item)
{
scheduleEvent = item->event;
if (item->channel)
currentChannel = item->channel->Number();
}
if (userTime->getMode() == cUserTimes::mSearch)
return LoadSearch(userTime);
Clear();
// Timers.Modified(timerState);
SetMenuCategory(userTime->getMode() == cUserTimes::mNow ? mcScheduleNow : mcScheduleNext);
if (isEmpty(userTime->getHHMMStr()))
SetTitle(cString::sprintf(tr("Overview - %s"), userTime->getTitle()));
else
SetTitle(cString::sprintf(tr("Overview - %s (%s)"), userTime->getTitle(), userTime->getHHMMStr()));
tell(2, "DEBUG: Loading events for '%s' %s", userTime->getTitle(), !isEmpty(userTime->getHHMMStr()) ? userTime->getHHMMStr() : "");
#if APIVERSNUM >= 20301
LOCK_CHANNELS_READ;
const cChannels* channels = Channels;
#else
const cChannels* channels = &Channels;
#endif
// events
for (const cChannel* Channel = channels->First(); Channel; Channel = channels->Next(Channel))
{
if (!Channel->GroupSep())
{
const cSchedule* Schedule = schedules->GetSchedule(Channel);
const cEvent* Event = 0;
if (Schedule)
{
switch (userTime->getMode())
{
case cUserTimes::mNow: Event = Schedule->GetPresentEvent(); break;
case cUserTimes::mNext: Event = Schedule->GetFollowingEvent(); break;
case cUserTimes::mTime: Event = Schedule->GetEventAround(userTime->getTime()); break;
}
}
if (!Event && !Epg2VdrConfig.showEmptyChannels)
continue;
Add(new cMenuEpgScheduleItem(menuDb, Event, Channel), Channel->Number() == currentChannel);
}
else
{
if (strlen(Channel->Name()))
Add(new cMenuEpgScheduleSepItem(Channel, 0));
}
}
Display();
SetHelpKeys();
return done;
}
//***************************************************************************
// Load Search
//***************************************************************************
int cMenuEpgWhatsOn::LoadSearch(const cUserTimes::UserTime* userTime)
{
cDbStatement* select = 0;
Clear();
SetMenuCategory(mcSchedule);
SetTitle(cString::sprintf(tr("Overview - %s"), userTime->getTitle()));
tell(2, "DEBUG: Loading events for search '%s'", userTime->getSearch());
menuDb->searchtimerDb->clear();
menuDb->searchtimerDb->setValue("NAME", userTime->getSearch());
if (!menuDb->selectSearchTimerByName->find())
return done;
if (!(select = menuDb->search->prepareSearchStatement(menuDb->searchtimerDb->getRow(), menuDb->useeventsDb)))
return fail;
#if defined (APIVERSNUM) && (APIVERSNUM >= 20301)
LOCK_CHANNELS_READ;
const cChannels* channels = Channels;
#else
cChannels* channels = &Channels;
#endif
menuDb->useeventsDb->clear();
for (int res = select->find(); res; res = select->fetch())
{
menuDb->useeventsDb->find(); // get all fields ..
if (!menuDb->search->matchCriterias(menuDb->searchtimerDb->getRow(), menuDb->useeventsDb->getRow()))
continue;
//
const char* strChannelId = menuDb->useeventsDb->getStrValue("CHANNELID");
const cChannel* channel = channels->GetByChannelID(tChannelID::FromString(strChannelId));
const cSchedule* schedule = schedules->GetSchedule(channel);
const cEvent* event = !schedule ? 0 : schedule->GetEvent(menuDb->useeventsDb->getIntValue("USEID"));
if (event)
Add(new cMenuEpgScheduleItem(menuDb, event, channel, yes));
}
select->freeResult();
menuDb->selectSearchTimerByName->freeResult();
Display();
SetHelpKeys();
return Count();
}
//***************************************************************************
// Load Schedule
//***************************************************************************
int cMenuEpgWhatsOn::LoadSchedule()
{
Clear();
SetCols(7, 6, 4);
dispSchedule = yes;
#if APIVERSNUM >= 20301
LOCK_CHANNELS_READ;
const cChannels* channels = Channels;
const cChannel* channel = channels->GetByNumber(currentChannel);
#else
cChannels* channels = &Channels;
const cChannel* channel = channels->GetByNumber(currentChannel);
#endif
cMenuEpgScheduleItem::SetSortMode(cMenuEpgScheduleItem::ssmAllThis);
SetMenuCategory(mcSchedule);
SetTitle(cString::sprintf(tr("Schedule - %s"), channel->Name()));
if (schedules && channel)
{
const cSchedule* Schedule = schedules->GetSchedule(channel);
if (Schedule)
{
int lastDay = 0;
const cEvent* PresentEvent = scheduleEvent ? scheduleEvent : Schedule->GetPresentEvent();
time_t now = time(0) - Setup.EPGLinger * 60;
for (const cEvent* ev = Schedule->Events()->First(); ev; ev = Schedule->Events()->Next(ev))
{
time_t stime = ev->StartTime();
struct tm tmSTime;
localtime_r(&stime, &tmSTime);
if (lastDay != 0 && tmSTime.tm_mday != lastDay)
Add(new cMenuEpgScheduleSepItem(0, ev));
if (ev->EndTime() > now || ev == PresentEvent)
Add(new cMenuEpgScheduleItem(menuDb, ev), ev == PresentEvent);
lastDay = tmSTime.tm_mday;
}
}
}
Display();
SetHelpKeys();
return done;
}
//***************************************************************************
// Load Query
//***************************************************************************
int cMenuEpgWhatsOn::LoadQuery(const cEvent* searchEvent)
{
Clear();
SetMenuCategory(mcSchedule);
cMenuEpgScheduleItem::SetSortMode(cMenuEpgScheduleItem::ssmAllThis);
#if APIVERSNUM >= 20301
LOCK_CHANNELS_READ;
const cChannels* channels = Channels;
#else
const cChannels* channels = &Channels;
#endif
tell(1, "Lookup events with title '%s'", searchEvent->Title());
for (const cChannel* channel = channels->First(); channel; channel = channels->Next(channel))
{
const cSchedule* schedule = schedules->GetSchedule(channel);
if (schedule)
{
for (const cEvent* event = schedule->Events()->First(); event; event = schedule->Events()->Next(event))
{
if (strcasecmp(event->Title(), searchEvent->Title()) == 0 &&
event->StartTime() > time(0))
Add(new cMenuEpgScheduleItem(menuDb, event, channel, yes));
}
}
}
Sort();
SetTitle(cString::sprintf("%d %s - %s", Count(), tr("Search results"), searchEvent->Title()));
Display();
SetHelpKeys();
return Count();
}
//***************************************************************************
// Display
//***************************************************************************
void cMenuEpgWhatsOn::Display()
{
cOsdMenu::Display();
#ifdef WITH_GTFT
if (Count() > 0)
{
int ni = 0;
for (cOsdItem* item = First(); item; item = Next(item))
cStatus::MsgOsdEventItem(((cMenuEpgScheduleItem*)item)->event, item->Text(), ni++, Count());
}
#endif
}
//***************************************************************************
// Update
//***************************************************************************
bool cMenuEpgWhatsOn::Update()
{
bool result = false;
for (cOsdItem* item = First(); item; item = Next(item))
{
if (((cMenuEpgScheduleItem*)item)->Update())
result = true;
}
return result;
}
//***************************************************************************
// SetHelpKeys
//***************************************************************************
void cMenuEpgWhatsOn::SetHelpKeys()
{
cMenuEpgScheduleItem* item = (cMenuEpgScheduleItem *)Get(Current());
canSwitch = no;
int NewHelpKeys = 0;
if (item)
{
if (item->timerMatch == tmFull)
NewHelpKeys |= 0x02; // "Timer"
else
NewHelpKeys |= 0x01; // "Record"
if (!dispSchedule)
NewHelpKeys |= 0x04; // "Schedule"
if (item->channel)
{
if (item->channel->Number() != cDevice::CurrentChannel())
{
NewHelpKeys |= 0x10; // "Switch"
canSwitch = yes;
}
}
}
cUserTimes::UserTime* userTimeGreen = !dispSchedule ? menuDb->userTimes->getNext() : menuDb->userTimes->current();
if (NewHelpKeys != helpKeys || helpKeyTime != userTimeGreen->getTime() || helpKeyTimeMode != userTimeGreen->getMode())
{
const char* Red[] = { 0, tr("Button$Record"), tr("Button$Timer") };
if (searchEvent)
{
helpKeys = 0;
helpKeyTime = 0;
helpKeyTimeMode = na;
SetHelp(Red[NewHelpKeys & 0x03], 0, 0, 0);
}
else
{
SetHelp(Red[NewHelpKeys & 0x03], // red
userTimeGreen->getHelpKey(), // green
!dispSchedule
? tr("Button$Schedule") // yellow
: menuDb->userTimes->current() == menuDb->userTimes->getFirst()
? tr(menuDb->userTimes->getNext()->getHelpKey()) // yellow
: tr(menuDb->userTimes->getFirst()->getHelpKey()), // yellow
Epg2VdrConfig.xchgOkBlue ? tr("Button$Info") : canSwitch ? tr("Button$Switch") : 0); // blue
helpKeyTime = userTimeGreen->getTime();
helpKeyTimeMode = userTimeGreen->getMode();
helpKeys = NewHelpKeys;
}
}
}
//***************************************************************************
// Switch
//***************************************************************************
eOSState cMenuEpgWhatsOn::Switch()