-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmenu_main.c
620 lines (577 loc) · 17.3 KB
/
menu_main.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
/* -*- c++ -*-
Copyright (C) 2004-2013 Christian Wieninger
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
The author can be reached at cwieninger@gmx.de
The project's page is at http://winni.vdr-developer.org/epgsearch
*/
#include <vector>
#include "menu_main.h"
#include "menu_whatson.h"
#include "menu_myedittimer.h"
#include "epgsearchext.h"
#include "menu_event.h"
#include "menu_searchresults.h"
#include "menu_search.h"
#include "menu_commands.h"
#include "epgsearchcfg.h"
#include "epgsearchtools.h"
#include <vdr/menu.h>
#include "menu_conflictcheck.h"
#include "menu_favorites.h"
#include "menu_deftimercheckmethod.h"
#include "timerstatus.h"
int toggleKeys=0;
int exitToMainMenu = 0;
extern int gl_InfoConflict;
int cMenuSearchMain::forceMenu = 0; // 1 = now, 2 = schedule, 3 = summary
// --- cMenuSearchMain ---------------------------------------------------------
cMenuSearchMain::cMenuSearchMain(void)
:cOsdMenu("", GetTab(1), GetTab(2), GetTab(3), GetTab(4), GetTab(5))
{
#if VDRVERSNUM >= 10734
SetMenuCategory(mcSchedule);
#endif
helpKeys = -1;
otherChannel = 0;
toggleKeys = 0;
shiftTime = 0;
InWhatsOnMenu = false;
InFavoritesMenu = false;
#if VDRVERSNUM > 20300
LOCK_CHANNELS_READ;
const cChannels *vdrchannels = Channels;
#else
cChannels *vdrchannels = &Channels;
#endif
const cChannel *channel = vdrchannels->GetByNumber(cDevice::CurrentChannel());
#if VDRVERSNUM > 20300
LOCK_SCHEDULES_READ;
schedules = Schedules;
#else
schedules = cSchedules::Schedules(schedulesLock);
#endif
if (channel) {
cMenuWhatsOnSearch::SetCurrentChannel(channel->Number());
if (EPGSearchConfig.StartMenu == 0 || forceMenu != 0)
PrepareSchedule(channel);
SetHelpKeys();
cMenuWhatsOnSearch::currentShowMode = showNow;
// timeb tnow;
//ftime(&tnow);
//isyslog("duration epgs sched: %d", tnow.millitm - gl_time.millitm + ((tnow.millitm - gl_time.millitm<0)?1000:0));
}
if ((EPGSearchConfig.StartMenu == 1 || forceMenu == 1) && forceMenu != 2)
{
InWhatsOnMenu = true;
AddSubMenu(new cMenuWhatsOnSearch(schedules, cDevice::CurrentChannel()));
}
if (forceMenu == 3)
ShowSummary();
}
#ifdef USE_GRAPHTFT
void cMenuSearchMain::Display(void)
{
cOsdMenu::Display();
if (Count() > 0)
{
int i = 0;
for (cOsdItem *item = First(); item; item = Next(item))
cStatus::MsgOsdEventItem(!item->Selectable() ? 0 :
((cMenuMyScheduleItem*)item)->event,
item->Text(), i++, Count());
}
}
#endif /* GRAPHTFT */
cMenuSearchMain::~cMenuSearchMain()
{
cMenuWhatsOnSearch::ScheduleChannel(); // makes sure any posted data is cleared
forceMenu = 0;
}
int cMenuSearchMain::GetTab(int Tab)
{
return cTemplFile::GetTemplateByName("MenuSchedule")->Tab(Tab-1);
}
void cMenuSearchMain::PrepareSchedule(const cChannel *Channel)
{
Clear();
cString buffer = cString::sprintf("%s - %s", trVDR("Schedule"), Channel->Name());
SetTitle(buffer);
cMenuTemplate* ScheduleTemplate = cTemplFile::GetTemplateByName("MenuSchedule");
eventObjects.Clear();
if (schedules) {
const cSchedule *Schedule = schedules->GetSchedule(Channel);
currentChannel = Channel->Number();
if (Schedule && Schedule->Events()->First())
{
const cEvent *PresentEvent = Schedule->GetPresentEvent();
time_t now = time(NULL);
now -= Setup.EPGLinger * 60;
if (shiftTime != 0)
PresentEvent = Schedule->GetEventAround(time(NULL) + shiftTime * 60);
time_t lastEventDate = Schedule->Events()->First()->StartTime();
// timeb tstart;
// ftime(&tstart);
for (const cEvent *Event = Schedule->Events()->First(); Event; Event = Schedule->Events()->Next(Event)) {
if (Event->EndTime() > now || (shiftTime==0 && Event == PresentEvent))
{
if (EPGSearchConfig.showDaySeparators)
{
struct tm tm_rEvent;
struct tm tm_rLastEvent;
time_t EventDate = Event->StartTime();
struct tm *t_event = localtime_r(&EventDate, &tm_rEvent);
struct tm *t_lastevent = localtime_r(&lastEventDate, &tm_rLastEvent);
if (t_event->tm_mday != t_lastevent->tm_mday)
Add(new cMenuMyScheduleSepItem(Event));
lastEventDate = EventDate;
}
Add(new cMenuMyScheduleItem(Event, NULL, showNow, ScheduleTemplate), Event == PresentEvent);
eventObjects.Add(Event);
}
}
// timeb tnow;
// ftime(&tnow);
// isyslog("duration epgs prepsched: %d (%d)", tnow.millitm - tstart.millitm + ((tnow.millitm - tstart.millitm<0)?1000:0), Count());
}
}
if (shiftTime)
{
cString buffer = cString::sprintf("%s (%s%dh %dm)", Channel->Name(), shiftTime>0?"+":"",
shiftTime/60, abs(shiftTime)%60);
SetTitle(buffer);
}
}
bool cMenuSearchMain::Update(const cTimers* vdrtimers)
{
bool result = false;
for (cOsdItem *item = First(); item; item = Next(item)) {
if (item->Selectable() && ((cMenuMyScheduleItem *)item)->Update(vdrtimers))
result = true;
}
return result;
}
eOSState cMenuSearchMain::Record(void)
{
cMenuMyScheduleItem *item = (cMenuMyScheduleItem *)Get(Current());
if (item) {
#if VDRVERSNUM > 20300
LOCK_TIMERS_WRITE;
cTimers *vdrtimers = Timers;
#else
cTimers *vdrtimers = &Timers;
#endif
if (item->timerMatch == tmFull)
{
eTimerMatch tm = tmNone;
cTimer *timer = vdrtimers->GetMatch(item->event, &tm);
if (timer)
{
if (EPGSearchConfig.useVDRTimerEditMenu)
return AddSubMenu(new cMenuEditTimer(timer));
else
return AddSubMenu(new cMenuMyEditTimer(timer, false, item->event, item->channel));
}
}
cTimer *timer = new cTimer(item->event);
PrepareTimerFile(item->event, timer);
cTimer *t = vdrtimers->GetTimer(timer);
if (EPGSearchConfig.onePressTimerCreation == 0 || t || !item->event || (!t && item->event && item->event->StartTime() - (Setup.MarginStart+2) * 60 < time(NULL)))
{
if (t)
{
delete timer;
timer = t;
}
if (EPGSearchConfig.useVDRTimerEditMenu)
return AddSubMenu(new cMenuEditTimer(timer, !t));
else
return AddSubMenu(new cMenuMyEditTimer(timer, !t, item->event));
}
else
{
string fullaux = "";
string aux = "";
if (item->event)
{
const cEvent* event = item->event;
int bstart = event->StartTime() - timer->StartTime();
int bstop = timer->StopTime() - event->EndTime();
int checkmode = DefTimerCheckModes.GetMode(timer->Channel());
aux = UpdateAuxValue(aux, "channel", NumToString(timer->Channel()->Number()) + " - " + CHANNELNAME(timer->Channel()));
aux = UpdateAuxValue(aux, "update", checkmode);
aux = UpdateAuxValue(aux, "eventid", event->EventID());
aux = UpdateAuxValue(aux, "bstart", bstart);
aux = UpdateAuxValue(aux, "bstop", bstop);
fullaux = UpdateAuxValue(fullaux, "epgsearch", aux);
}
#ifdef USE_PINPLUGIN
aux = "";
aux = UpdateAuxValue(aux, "protected", timer->FskProtection() ? "yes" : "no");
fullaux = UpdateAuxValue(fullaux, "pin-plugin", aux);
#endif
SetAux(timer, fullaux);
vdrtimers->Add(timer);
gl_timerStatusMonitor->SetConflictCheckAdvised();
timer->Matches();
#if VDRVERSNUM < 20300
vdrtimers->SetModified();
#endif
LogFile.iSysLog("timer %s added (active)", *timer->ToDescr());
if (HasSubMenu())
CloseSubMenu();
if (Update(vdrtimers))
Display();
SetHelpKeys();
}
}
return osContinue;
}
eOSState cMenuSearchMain::Switch(void)
{
cMenuMyScheduleItem *item = (cMenuMyScheduleItem *)Get(Current());
if (item) {
#if VDRVERSNUM > 20300
LOCK_CHANNELS_READ;
const cChannels *vdrchannels = Channels;
#else
cChannels *vdrchannels = &Channels;
#endif
const cChannel *channel = vdrchannels->GetByChannelID(item->event->ChannelID(), true, true);
if (channel && cDevice::PrimaryDevice()->SwitchChannel(channel, true))
return osEnd;
}
INFO(trVDR("Can't switch channel!"));
return osContinue;
}
eOSState cMenuSearchMain::ExtendedSearch(void)
{
return AddSubMenu(new cMenuEPGSearchExt());
}
eOSState cMenuSearchMain::Commands(eKeys Key)
{
if (HasSubMenu() || Count() == 0)
return osContinue;
cMenuMyScheduleItem *mi = (cMenuMyScheduleItem *)Get(Current());
if (mi && mi->event) {
cMenuSearchCommands *menu;
eOSState state = AddSubMenu(menu = new cMenuSearchCommands(tr("EPG Commands"), mi->event, true));
if (Key != kNone)
state = menu->ProcessKey(Key);
return state;
}
return osContinue;
}
eOSState cMenuSearchMain::ShowSummary()
{
if (Count())
{
cMenuMyScheduleItem *mi = (cMenuMyScheduleItem *)Get(Current());
if (mi && mi->event)
return AddSubMenu(new cMenuEventSearch(mi->event, eventObjects, SurfModeTime));
}
return osContinue;
}
void cMenuSearchMain::SetHelpKeys(bool Force)
{
cMenuMyScheduleItem *item = (cMenuMyScheduleItem *)Get(Current());
int NewHelpKeys = 0;
if (item) {
if (item->Selectable() && item->timerMatch == tmFull)
NewHelpKeys = 2;
else
NewHelpKeys = 1;
}
bool hasTimer = (NewHelpKeys == 2);
if (NewHelpKeys != helpKeys || Force)
{
if (toggleKeys==0)
SetHelp((EPGSearchConfig.redkeymode==0?(hasTimer?trVDR("Button$Timer"):trVDR("Button$Record")):tr("Button$Commands")), trVDR("Button$Now"), trVDR("Button$Next"), EPGSearchConfig.bluekeymode==0?trVDR("Button$Switch"):tr("Button$Search"));
else
{
#if VDRVERSNUM > 20300
LOCK_CHANNELS_READ;
const cChannels *vdrchannels = Channels;
#else
cChannels *vdrchannels = &Channels;
#endif
const char* szGreenToggled = CHANNELNAME(vdrchannels->GetByNumber(currentChannel-1,-1));
const char* szYellowToggled = CHANNELNAME(vdrchannels->GetByNumber(currentChannel+1,1));
SetHelp((EPGSearchConfig.redkeymode==1?(hasTimer?trVDR("Button$Timer"):trVDR("Button$Record")):tr("Button$Commands")), (EPGSearchConfig.toggleGreenYellow==0?trVDR("Button$Now"):szGreenToggled), (EPGSearchConfig.toggleGreenYellow==0?trVDR("Button$Next"):szYellowToggled), EPGSearchConfig.bluekeymode==1?trVDR("Button$Switch"):tr("Button$Search"));
}
helpKeys = NewHelpKeys;
}
}
eOSState cMenuSearchMain::Shift(int iMinutes)
{
shiftTime += iMinutes;
#if VDRVERSNUM > 20300
LOCK_CHANNELS_READ;
const cChannels *vdrchannels = Channels;
#else
cChannels *vdrchannels = &Channels;
#endif
const cChannel *channel = vdrchannels->GetByNumber(currentChannel);
PrepareSchedule(channel);
Display();
SetHelpKeys();
return osContinue;
}
void cMenuSearchMain::UpdateCurrent()
{
// navigation in summary could have changed current item, so update it
cEventObj* cureventObj = eventObjects.GetCurrent();
if (cureventObj && cureventObj->Event())
for (cMenuMyScheduleItem *item = (cMenuMyScheduleItem *)First(); item; item = (cMenuMyScheduleItem *)Next(item))
if (item->Selectable() && item->event == cureventObj->Event())
{
cureventObj->Select(false);
SetCurrent(item);
Display();
break;
}
}
eOSState cMenuSearchMain::ProcessKey(eKeys Key)
{
bool HadSubMenu = HasSubMenu();
eOSState state = cOsdMenu::ProcessKey(Key);
if (exitToMainMenu == 1)
{
exitToMainMenu = 0;
return osBack;
}
if (!HasSubMenu() && HadSubMenu)
UpdateCurrent();
if (state == osUnknown) {
switch (Key) {
case kFastRew:
if (HasSubMenu() && !InWhatsOnMenu && !InFavoritesMenu)
{
/* if (Count())
{
CursorUp();
return ShowSummary();
}
*/ }
else
return Shift(-EPGSearchConfig.timeShiftValue);
case kFastFwd:
if (HasSubMenu() && !InWhatsOnMenu && !InFavoritesMenu)
{
/* if (Count())
{
CursorDown();
return ShowSummary();
}
*/ }
else
return Shift(EPGSearchConfig.timeShiftValue);
case kRecord:
case kRed:
if(HasSubMenu()) {
UpdateCurrent();
state = Record();
break;
}
if (Count())
{
if (EPGSearchConfig.redkeymode==toggleKeys)
state = Record();
else
{
cMenuMyScheduleItem *mi = (cMenuMyScheduleItem *)Get(Current());
if (mi) {
if (mi->event) {
return AddSubMenu(new cMenuSearchCommands(tr("EPG Commands"),mi->event));
}
}
}
}
break;
case k0:
if(!HasSubMenu())
{
toggleKeys = 1 - toggleKeys;
SetHelpKeys(true);
}
state = osContinue;
break;
case k1...k9:
if (!HasSubMenu())
return Commands(Key);
else
state = osContinue;
break;
case kGreen:
if (schedules)
{
if (HasSubMenu() && !InWhatsOnMenu && !InFavoritesMenu)
{
if (Count())
{
// CursorUp();
// return ShowSummary();
}
}
else if (toggleKeys == 0 || (toggleKeys == 1 && EPGSearchConfig.toggleGreenYellow == 0))
{
int ChannelNr = cDevice::CurrentChannel();
if (Count()) {
cMenuMyScheduleItem* Item = (cMenuMyScheduleItem *)Get(Current());
if (Item && Item->event)
{
#if VDRVERSNUM > 20300
LOCK_CHANNELS_READ;
const cChannels *vdrchannels = Channels;
#else
cChannels *vdrchannels = &Channels;
#endif
const cChannel *channel = vdrchannels->GetByChannelID(Item->event->ChannelID(), true, true);
if (channel)
ChannelNr = channel->Number();
}
}
if (cMenuWhatsOnSearch::currentShowMode == showFavorites)
{
InFavoritesMenu = true;
return AddSubMenu(new cMenuFavorites());
}
else
{
InWhatsOnMenu = true;
return AddSubMenu(new cMenuWhatsOnSearch(schedules, ChannelNr));
}
}
else
{
#if VDRVERSNUM > 20300
LOCK_CHANNELS_READ;
const cChannels *vdrchannels = Channels;
#else
cChannels *vdrchannels = &Channels;
#endif
const cChannel *channel = vdrchannels->GetByNumber(currentChannel-1,-1);
if (channel) {
PrepareSchedule(channel);
if (channel->Number() != cDevice::CurrentChannel()) {
otherChannel = channel->Number();
}
Display();
}
SetHelpKeys(true);
return osContinue;
}
}
case kYellow:
if (schedules)
{
if (HasSubMenu())
{
if (Count())
{
// CursorDown();
// return ShowSummary();
}
}
else if (toggleKeys == 0 || (toggleKeys == 1 && EPGSearchConfig.toggleGreenYellow == 0))
{
cMenuWhatsOnSearch::currentShowMode = showNext;
InWhatsOnMenu = true;
return AddSubMenu(new cMenuWhatsOnSearch(schedules, cMenuWhatsOnSearch::CurrentChannel()));
}
else
{
#if VDRVERSNUM > 20300
LOCK_CHANNELS_READ;
const cChannels *vdrchannels = Channels;
#else
cChannels *vdrchannels = &Channels;
#endif
const cChannel *channel = vdrchannels->GetByNumber(currentChannel+1,1);
if (channel) {
PrepareSchedule(channel);
if (channel->Number() != cDevice::CurrentChannel()) {
otherChannel = channel->Number();
}
Display();
}
SetHelpKeys(true);
return osContinue;
}
}
break;
case kBlue:
if (HasSubMenu())
{
UpdateCurrent();
return Switch();
}
if (EPGSearchConfig.bluekeymode==toggleKeys)
return Switch();
else
return ExtendedSearch();
break;
case kInfo:
case kOk:
if (Count())
return ShowSummary();
break;
default:
break;
}
}
if (!HasSubMenu()) {
const cChannel *ch = cMenuWhatsOnSearch::ScheduleChannel();
InWhatsOnMenu = false;
InFavoritesMenu = false;
#if VDRVERSNUM > 20300
LOCK_TIMERS_READ;
const cTimers *vdrtimers = Timers;
#else
cTimers *vdrtimers = &Timers;
#endif
if (ch) {
// when switch from the other menus to the schedule, try to keep the same time
if (cMenuWhatsOnSearch::shiftTime)
{
time_t diff = cMenuWhatsOnSearch::seekTime - time(NULL);
shiftTime = (diff + (diff>0?30:-30)) / 60 ;
}
else
shiftTime = 0;
PrepareSchedule(ch);
if (ch->Number() != cDevice::CurrentChannel()) {
otherChannel = ch->Number();
}
Display();
}
else if ((HadSubMenu || gl_TimerProgged) && Update(vdrtimers))
{
if (gl_TimerProgged) // when using epgsearch's timer edit menu, update is delayed because of SVDRP
{
gl_TimerProgged = 0;
SetHelpKeys();
}
Display();
}
if (Key != kNone)
SetHelpKeys();
if (gl_InfoConflict)
{
gl_InfoConflict = 0;
if (Interface->Confirm(tr("Timer conflict! Show?")))
return AddSubMenu(new cMenuConflictCheck());
}
}
return state;
}