summaryrefslogtreecommitdiff
path: root/osdmenu.c
blob: 4a6ae6a2791e981c73b1d423b123890047a0975c (plain)
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
#include "osdmenu.h"
#include "osditem.h"
#include "menuevent.h"

time_t t;

int *GroupIndex;
int *CurrentGroupChannel;
int *FirstGroupChannel;
int *LastGroupChannel;

int LastMaxGroup;

int ChannelsShown;
int ChannelsBefore;
int ChannelsAfter;

myOsdMenu::myOsdMenu() : cOsdMenu("")
{
    jumpto = false;

    if( Setup.UseSmallFont == 2 )
    {
        if(showchannelnumbers)
            cOsdMenu::SetCols(1, CHNUMWIDTH + 1, ChannelNameWidth, 5);
        else
            cOsdMenu::SetCols(1, ChannelNameWidth, 5);
    }
    else
    {
        if(showchannelnumbers)
            cOsdMenu::SetCols(1, CHNUMWIDTH + 1, ChannelNameWidth, 6);
        else
            cOsdMenu::SetCols(1, ChannelNameWidth, 6);
    }

    t = time(NULL);
    next = false;

    // test how many OsdItems shown on display
    // add 50 items, make a PageDown and look what item is the current
    ChannelsShown = 0;
    char buf[20]="";
    for(int i = 0; i < 50; i++)
    {
        strcpy(buf, (const char *)itoa(i));
        if( i == 0 )
            Add(new cOsdItem(buf),  true);
        else
            Add(new cOsdItem(buf),  false);
    }
    Display();

    PageDown();
    cOsdItem *tItem = Get(Current());
    ChannelsShown = atoi((const char *)tItem->Text());
    Clear();
    //ChannelsShown = Skins.Current()->DisplayMenu()->MaxItems();

    // how many items are before and after the middle item
    if( (ChannelsShown % 2) != 0 )
    {
        ChannelsBefore = (ChannelsShown / 2);
        ChannelsAfter = (ChannelsShown / 2);
    }
    else
    {
        ChannelsBefore = (ChannelsShown / 2);
        ChannelsAfter = (ChannelsShown / 2)-1;
    }

    // Count the groups and channels
    int GroupCount = 0;
    for(cChannel *Channel = Channels.First(); Channel; Channel = Channels.Next(Channel))
    {
        if( Channel->GroupSep() )
            GroupCount++;
    }
    MaxGroup = GroupCount;

    if( !Channels.First()->GroupSep() )
        MaxGroup++;
    //syslog(LOG_ERR, "neutrinoepg: MaxGroup %d", MaxGroup);
    // Hide Groups?
    if( HideGroupsAt > MaxGroup )
        HideGroupsAt = MaxGroup;
    if( HideGroupsAt < 1 )
        HideGroupsAt = 0;
    if( HideGroupsAt > 0 )
        MaxGroup -= MaxGroup - HideGroupsAt;
    
    // test for different group count
    if( LastMaxGroup != MaxGroup )
    {
    //:(LOG_ERR, "neutrinoepg: HideGroup %d MaxGroup %d", HideGroupsAt, MaxGroup);
        
    if( GroupIndex != NULL )
        delete[] GroupIndex;
    if( CurrentGroupChannel != NULL )
        delete[] CurrentGroupChannel;
    if( FirstGroupChannel != NULL )
        delete[] FirstGroupChannel;
    if( LastGroupChannel != NULL )
        delete[] LastGroupChannel;

    // store max group count and add a little reserve
    GroupIndex = new int[MaxGroup+1];
    CurrentGroupChannel = new int[MaxGroup+1];
    FirstGroupChannel = new int[MaxGroup+1];
    LastGroupChannel = new int[MaxGroup+1];

    for( int i = 0; i < MaxGroup; i++)
    {
        CurrentGroupChannel[i] = -1;
        FirstGroupChannel[i] = -1;
        LastGroupChannel[i] = -1;
    }

    int index = 0;
    if( FirstChannelsHasGroup() == false )
    {
        GroupIndex[0] = -1;
        index = 1;
    }
    for( cChannel *Channel = Channels.First(); Channel && index < MaxGroup; Channel = Channels.Next(Channel) )
    {
        if( Channel->GroupSep() )
        {
            GroupIndex[index] = Channel->Index();
            index++;
        }
    }

    for( int Group = 0; Group < MaxGroup; Group++)
    {
        if( CurrentGroupChannel[Group] == -1 )
            CurrentGroupChannel[Group] = GetFirstChannelOfGroup(Group);
        if( FirstGroupChannel[Group] == -1 )
            FirstGroupChannel[Group] = GetFirstChannelOfGroup(Group);
        if( LastGroupChannel[Group] == -1 )
            LastGroupChannel[Group] = GetLastChannelOfGroup(Group);
    }

    LastMaxGroup = MaxGroup;
    
    }
    // what is the current watching channel?
    int CurrentChannelNr = cDevice::CurrentChannel();
    cChannel *CurrentChannel = Channels.GetByNumber(CurrentChannelNr);
    // is Current Channel is filtered?
    bool isRadio = ( (!CurrentChannel->Vpid()) && (CurrentChannel->Apid(0)) ) ? true : false;
    if( (isRadio && hideradiochannels) || (CurrentChannel->Ca() && hideencryptedchannels) )
    {
        CurrentChannel = Channels.Get( GetNextChannel( CurrentChannel->Index() ) );
    }
    // what is the current channel & group?
    CurrentGroup = GetGroupFromChannel( CurrentChannel->Index() );
    CurrentGroupChannel[CurrentGroup] = CurrentChannel->Index();

    LoadSchedules(0);
}

myOsdMenu::~myOsdMenu()
{
}

int myOsdMenu::GetGroupIndex(int Group)
{
    if( Group < 0 || Group > MaxGroup)
        return -1;

    return GroupIndex[Group];
}
int myOsdMenu::GetGroupByGroupIndex(int groupIndex)
{
    if( ChannelsHasGroup() == false || groupIndex == -1 )
        return 0;

    for(int index = 0; index < MaxGroup; index++)
    {
        if( GroupIndex[index] == groupIndex )
            return index;
    }
    return 0;
}
int myOsdMenu::GetGroupFromChannel(int ChanIndex)
{
    int GroupIndex = Channels.GetPrevGroup(ChanIndex);
    if( GroupIndex == -1 )
        return 0;
    return GetGroupByGroupIndex( GroupIndex );
}

int myOsdMenu::GetLastGroupIndex(void)
{
    cChannel *Channel = Channels.Last();
    return Channels.GetPrevGroup( Channel->Index() );
}

int myOsdMenu::GetFirstGroupIndex(void)
{
    cChannel *Channel = Channels.First();
    if( Channel->GroupSep() )
        return Channel->Index();
    return Channels.GetNextGroup( Channel->Index() );
}

int myOsdMenu::GetFirstChannelOfGroup(int Group)
{
    if( ChannelsHasGroup() == false ) // no groups -> get First Channel
    {
        cChannel *Channel;
        Channel = Channels.First();
        if( Channel == NULL )
            return -1;
        bool isRadio = ( (!Channel->Vpid()) && (Channel->Apid(0)) ) ? true : false;
        if( !(isRadio && hideradiochannels) && !(Channel->Ca() && hideencryptedchannels) )
            return Channel->Index();

        return GetNextChannelOfGroup( Channel->Index(), Group );
    }

    return GetNextChannelOfGroup( GetGroupIndex(Group), Group );
}

int myOsdMenu::GetLastChannelOfGroup(int Group)
{
    int NextGroup = Channels.GetNextGroup( GetGroupIndex(Group) );
    // next group -> get prev channel of next group
    if( NextGroup != -1 )
        return GetPrevChannelOfGroup(NextGroup, Group);
    else // no next group -> get last channel
    {
        cChannel *Channel;
        Channel = Channels.Last();
        if( Channel == NULL )
            return -1;
        if( isChannelInGroup( Channel->Index(), Group ) == false )
            return -1;

        bool isRadio = ( (!Channel->Vpid()) && (Channel->Apid(0)) ) ? true : false;
        if( !(isRadio && hideradiochannels) && !(Channel->Ca() && hideencryptedchannels) )
            return Channel->Index();
    
        return GetPrevChannelOfGroup( Channel->Index(), Group );
    }
    
}

int myOsdMenu::GetNextChannel(int ChanIndex)
{
    cChannel *Channel;
    Channel = Channels.Get( Channels.GetNextNormal(ChanIndex) );
    if( Channel == NULL )
        return -1;
    do
    {
        bool isRadio = ( (!Channel->Vpid()) && (Channel->Apid(0)) ) ? true : false;
        if( !(isRadio && hideradiochannels) && !(Channel->Ca() && hideencryptedchannels) )
            break;
    } while( (Channel = Channels.Get( Channels.GetNextNormal( Channel->Index() ))) != NULL );

    if( Channel == NULL )
        return -1;

    return Channel->Index();
}

int myOsdMenu::GetPrevChannel(int ChanIndex)
{
    cChannel *Channel;
    Channel = Channels.Get( Channels.GetPrevNormal(ChanIndex) );
    if( Channel == NULL )
        return -1;
    do
    {
        bool isRadio = ( (!Channel->Vpid()) && (Channel->Apid(0)) ) ? true : false;
        if( !(isRadio && hideradiochannels) && !(Channel->Ca() && hideencryptedchannels) )
            break;
    } while( (Channel = Channels.Get( Channels.GetPrevNormal( Channel->Index() ))) != NULL );

    if( Channel == NULL )
        return -1;

    return Channel->Index();
}

int myOsdMenu::GetNextChannelOfGroup(int ChanIndex, int Group)
{
    int NextIndex = GetNextChannel( ChanIndex );
    if( isChannelInGroup( NextIndex, Group ) == false )
        return -1;
    return NextIndex;
}
int myOsdMenu::GetPrevChannelOfGroup(int ChanIndex, int Group)
{
    int PrevIndex = GetPrevChannel( ChanIndex );
    if( isChannelInGroup( PrevIndex, Group ) == false )
        return -1;
    return PrevIndex;
}

bool myOsdMenu::isChannelInGroup(int ChanIndex, int Group)
{
    if( ChannelsHasGroup() == false )
        return true;

    int ChanGroup = GetGroupFromChannel(ChanIndex);
    return Group == ChanGroup ? true : false;
}

bool myOsdMenu::ChannelsHasGroup(void)
{
    cChannel *Channel = Channels.First();
    if( Channel->GroupSep() )
        return true;
    int Group = Channels.GetNextGroup(Channel->Index());
    return Group != -1 ? true : false;
}

bool myOsdMenu::FirstChannelsHasGroup(void)
{
    cChannel *Channel = Channels.First();
    if( Channel->GroupSep() )
        return true;
    return false;
}

void myOsdMenu::LoadSchedules(int shift)
{
    t += shift * Step * 60;

    // clar all items
    Clear();

    schedules = cSchedules::Schedules(schedulesLock);
    if( middlemenuentry )
    {
        int NumAdded = 0;
        int AddChanIndex = -1, ChanIndex = -1;
        AddChanIndex = CurrentGroupChannel[CurrentGroup];
        ChanIndex = AddChanIndex;
        
        // count if we have more channels add to the front because we are at the end
        int ExtraAdded = ChannelsAfter;
        while( ExtraAdded-- )
        {
            ChanIndex = GetNextChannelOfGroup( ChanIndex, CurrentGroup );
            if( ChanIndex == -1 )
                break;
        }

        ChanIndex = AddChanIndex;

        // count Channels
        NumAdded -= ExtraAdded;
        for( ; NumAdded <= ChannelsBefore; NumAdded++ )
        {
            AddChanIndex = GetPrevChannelOfGroup( AddChanIndex, CurrentGroup );
            if( AddChanIndex == -1 )
                break;
            ChanIndex = AddChanIndex;
        }
        for( NumAdded = 0; NumAdded < ChannelsShown && ChanIndex != -1; NumAdded++ )
        {
            cChannel *Channel = Channels.Get( ChanIndex );
            const cSchedule *Schedule = schedules->GetSchedule( Channel->GetChannelID() );
            if(Schedule)
            {
                // event from now or any other date (next)
                const cEvent *Event = next ? Schedule->GetEventAround(t) : Schedule->GetPresentEvent();
                Add(new myOsdItem(Event, Channel, next), Channel->Index() == CurrentGroupChannel[CurrentGroup] );
            }
            else
                Add(new myOsdItem(NULL, Channel, next), Channel->Index() == CurrentGroupChannel[CurrentGroup] );
            ChanIndex = GetNextChannelOfGroup( ChanIndex, CurrentGroup );
        }
        
    }
    else
    {
        for( cChannel *Channel = Channels.First(); Channel; Channel = Channels.Next(Channel) )
        {
            // is filtered by config?
            bool isRadio = ( (!Channel->Vpid()) && (Channel->Apid(0)) ) ? true : false;
            if( (isRadio && hideradiochannels) || (Channel->Ca() && hideencryptedchannels) )
                continue;

            // only channels!
            if( Channel->GroupSep() )
                continue;

            // only channels of the current Group
            if( !isChannelInGroup( Channel->Index(), CurrentGroup ) )
                continue;

            const cSchedule *Schedule = schedules->GetSchedule( Channel->GetChannelID() );
            if(Schedule)
            {
                // event from now or any other date (next)
                const cEvent *Event = next ? Schedule->GetEventAround(t) : Schedule->GetPresentEvent();
                Add(new myOsdItem(Event, Channel, next), Channel->Index() == CurrentGroupChannel[CurrentGroup] );
            }
            else
                Add(new myOsdItem(NULL, Channel, next), Channel->Index() == CurrentGroupChannel[CurrentGroup] );
        }
    }
    sprintf(tmp, "%d:%d", bookmark / 100, bookmark % 100);

    SetMyTitle();

//    if( switchwithok )
//        SetHelp(next ? trVDR("Button$Now") : NULL, "<<", ">>", trVDR("Button$Info") );
//    else
    
    if( next )
        SetHelp(trVDR("Button$Now"), "<<", ">>", switchwithok ? trVDR("Button$Info") : trVDR("Button$Switch"));
    else
        SetHelp(bookmark ? tmp : NULL, "<<", ">>", switchwithok ? trVDR("Button$Info") : trVDR("Button$Switch"));

    Display();
}

void myOsdMenu::SetMyTitle(void)
{
    char *buffer = NULL;

    if( CurrentGroup == 0 && FirstChannelsHasGroup() == false )
    {
        if( next )
            asprintf(&buffer, "%d/%d %s - %s", 
                CurrentGroup + 1, MaxGroup, tr("without group"), *DayDateTime(t));
        else
            asprintf(&buffer, "%d/%d %s - %s", 
                CurrentGroup + 1, MaxGroup, tr("without group"), trVDR("What's on now?"));
    } else
    {
        int groupindex = GetGroupIndex(CurrentGroup);
        if( next )
        {
            if( groupindex == -1 )
                asprintf(&buffer, "%d/%d %s - %s", 
                    CurrentGroup + 1, MaxGroup, "no group", *DayDateTime(t));
            else
                asprintf(&buffer, "%d/%d %s - %s", 
                    CurrentGroup + 1, MaxGroup, Channels.Get( groupindex )->Name(), *DayDateTime(t));
        }
        else
        {
            if( groupindex == -1 )
                asprintf(&buffer, "%d/%d %s - %s", 
                    CurrentGroup + 1, MaxGroup, "no group", trVDR("What's on now?"));
            else
                asprintf(&buffer, "%d/%d %s - %s", 
                    CurrentGroup + 1, MaxGroup, Channels.Get( groupindex )->Name(), trVDR("What's on now?"));
        }
    }
    SetTitle(buffer);
    free(buffer);
}
eOSState myOsdMenu::Switch()
{
    myOsdItem *item = (myOsdItem *)Get(Current());
    if(item)
    {
        const cChannel *channel = item->channel;
        if(channel && cDevice::PrimaryDevice()->SwitchChannel(channel, true) )
            return keeposd ? osContinue : osEnd;
    }
    Skins.Message(mtError, trVDR("Can't switch channel!"));
    return osContinue;
}

void myOsdMenu::GoToDay(int day)
{
    struct tm tm1, tm2;
    time_t tmp_t = time(NULL);

    localtime_r(&t, &tm1);
    localtime_r(&tmp_t, &tm2);
    tm2.tm_hour  = tm1.tm_hour;
    tm2.tm_min   = tm1.tm_min;
    tm2.tm_mday += day;

    t = mktime(&tm2);

    next = true;
    LoadSchedules(0);
}

void myOsdMenu::JumpTo(int hour, int min)
{
    struct tm tmp_tm;
    localtime_r(&t, &tmp_tm);

    if(tmp_tm.tm_hour > hour || tmp_tm.tm_min > min && tmp_tm.tm_hour >= hour)
        tmp_tm.tm_mday++;

    tmp_tm.tm_hour = hour;
    tmp_tm.tm_min  = min;

    t = mktime(&tmp_tm);

    next = true;
    LoadSchedules(0);
}

eOSState myOsdMenu::ProcessKey(eKeys Key)
{
    eOSState state;

    if(jumpto)
    {
        switch(Key)
        {
            case k0...k9:
                {
                    int number = Key-k0;
                    switch(index)
                    {
                        // first digit
                        case 0: 
                            if(number <= 2)
                            {
                                hh = number * 10;
                                sprintf(tmp,"%s: %d-:--",tr("Jump to"),number);
                                index++;
                            }
                            break;
                            // second digit
                        case 1:
                            if(hh <= 10 || hh == 20 && number <= 3)
                            {
                                hh += number;
                                sprintf(tmp,"%s: %02d:--",tr("Jump to"),hh);
                                index++;
                            }
                            break;
                            // third digit
                        case 2: 
                            if(number <= 5)
                            {
                                mm = number * 10;
                                sprintf(tmp,"%s: %02d:%d-",tr("Jump to"),hh,number);
                                index++;
                            }
                            break;
                            // fourth digit
                        case 3: 
                            mm += number;
                            sprintf(tmp,"%s: %02d:%02d",tr("Jump to"),hh,mm);
                            index++;
                            break;
                        default:
                            break;
                    }
                    if(index == 4)
                    {
                        JumpTo(hh, mm);
                        jumpto = 0;
                    }
                    else
                    {
                        SetTitle(tmp);
                        Display();
                    }
                    break;
                }
            case kOk:
                JumpTo(hh, mm);
                jumpto = 0;
                break;
            case kBack:
                jumpto = 0;
                SetMyTitle();
                Display();
                break;
            default:
                break;
        }
        state = osContinue;
    }
    else
    {
        state = cOsdMenu::ProcessKey(Key);

        if(state == osUnknown)
        {
            switch(Key)
            {
                case k1...k7:
                    GoToDay(Key-k0);
                    break;
                    // toggle asking for a time to jump to
                case k0:
                    hh = mm = index =0;
                    sprintf(tmp, "%s: --:--",tr("Jump to"));
                    SetTitle(tmp);
                    Display();
                    jumpto = 1;
                    break;
                case kRed:
                    if( next )
                    {
                        next = false;
                        t = time(NULL);
                        LoadSchedules(0);
                    } else
                    {
                        if( bookmark )
                           JumpTo(bookmark/100,bookmark%100);
                    }
                    break;
                case kGreen:
                    next = true;
                    LoadSchedules(-1);
                    break;
                case kYellow:
                    next = true;
                    LoadSchedules(1);
                    break;
                case kBlue:
                    if(switchwithok)
                    {
                        if( Count() )
                           return AddSubMenu(new myMenuEvent((myOsdItem*) Get(Current())));
                    } else
                    {
                        if( next )
                        {
                            next = false;
                            t = time(NULL);
                            LoadSchedules(0);
                        }
                        else
                            return Switch();
                    }
                    break;
                case kOk:
                    if(switchwithok)
                    {
                        return Switch();
                    } else
                    {
                        if(Count())
                            return AddSubMenu(new myMenuEvent((myOsdItem*)Get(Current())));
                    }
                case kNext:
                    if( isMenuEvent )
                        return osContinue;
                    // if we switch channel groups with next/prev key do it
                    if( switchgroupkey == 1 )
                    {
                        CurrentGroup++;
                        if( CurrentGroup >= MaxGroup )
                            CurrentGroup = 0;
                        LoadSchedules(0);
                    } else // we do a page down
                    {
                        if( CurrentGroupChannel[CurrentGroup] == LastGroupChannel[CurrentGroup] )
                        {
                            CurrentGroupChannel[CurrentGroup] = FirstGroupChannel[CurrentGroup];
                        } else
                        {
                            for(int i = 0; i < ChannelsShown; i++)
                            {
                                CurrentGroupChannel[CurrentGroup] = GetNextChannel( CurrentGroupChannel[CurrentGroup] );
                                if( CurrentGroupChannel[CurrentGroup] == -1 )
                                    break;
                            }
                            if( CurrentGroupChannel[CurrentGroup] > LastGroupChannel[CurrentGroup] || CurrentGroupChannel[CurrentGroup] == -1 )
                            {
                                CurrentGroupChannel[CurrentGroup] = LastGroupChannel[CurrentGroup];
                            }
                        }
                        
                        if( !middlemenuentry ) // if middlemenuentry hack is not set we can use vdr function for page down
                            PageDown();
                        else // otherwise we must do a page down by our own
                        {
                            LoadSchedules(0);
                        }
                    }
                    return osContinue;
                case kPrev:
                    if( isMenuEvent )
                        return osContinue;
                    // if we switch channel groups with next/prev key do it
                    if( switchgroupkey == 1 )
                    {
                        CurrentGroup--;
                        if( CurrentGroup < 0 )
                            CurrentGroup = MaxGroup-1;
                        LoadSchedules(0);
                    } else // we do a page up
                    {
                        if( CurrentGroupChannel[CurrentGroup] == FirstGroupChannel[CurrentGroup] )
                        {
                            CurrentGroupChannel[CurrentGroup] = LastGroupChannel[CurrentGroup];
                        } else
                        {
                            for(int i = 0; i < ChannelsShown; i++)
                            {
                                CurrentGroupChannel[CurrentGroup] = GetPrevChannel( CurrentGroupChannel[CurrentGroup] );
                            }
                            if( CurrentGroupChannel[CurrentGroup] < FirstGroupChannel[CurrentGroup] )
                            {
                                CurrentGroupChannel[CurrentGroup] = FirstGroupChannel[CurrentGroup];
                            }
                        }

                        if( !middlemenuentry ) // if middlemenuentry hack is not set we can use vdr function for page up
                            PageUp();
                        else // otherwise we must do a page down by our own
                        {
                            LoadSchedules(0);
                        }
                    }
                    return osContinue;
                default:
                    break;
            }
        } else
        {
            switch((int)Key)
            {
                case kUp|k_Repeat:
                case kUp:
                {
                    if( isMenuEvent )
                        return osContinue;
                   
                    CurrentGroupChannel[CurrentGroup] = GetPrevChannel( CurrentGroupChannel[CurrentGroup] );
                    if( CurrentGroupChannel[CurrentGroup] < FirstGroupChannel[CurrentGroup] )
                        CurrentGroupChannel[CurrentGroup] = LastGroupChannel[CurrentGroup];

                    if( !middlemenuentry ) // if middlemenuentry hack is not set we can let vdr kUp
                        return osContinue;

                    LoadSchedules(0);
                    return osContinue;
                }
                case kDown|k_Repeat:
                case kDown:
                {
                    if( isMenuEvent )
                        return osContinue;

                    CurrentGroupChannel[CurrentGroup] = GetNextChannel( CurrentGroupChannel[CurrentGroup] );
                    if( CurrentGroupChannel[CurrentGroup] > LastGroupChannel[CurrentGroup] || CurrentGroupChannel[CurrentGroup] == -1 )
                        CurrentGroupChannel[CurrentGroup] = FirstGroupChannel[CurrentGroup];

                    if( !middlemenuentry ) // if middlemenuentry hack is not set we can let vdr kDown
                        return osContinue;

                    LoadSchedules(0);
                    return osContinue;
                }
                case kLeft|k_Repeat:
                case kLeft:
                    if( isMenuEvent )
                        return osContinue;
                    if( switchgroupkey == 1 ) // if we not switch groups by left/right we let do vdr the rest (page up)
                    {
                        if( CurrentGroupChannel[CurrentGroup] == FirstGroupChannel[CurrentGroup] )
                        {
                            CurrentGroupChannel[CurrentGroup] = LastGroupChannel[CurrentGroup];
                        } else
                        {
                            for(int i = 0; i < ChannelsShown; i++)
                            {
                                CurrentGroupChannel[CurrentGroup] = GetPrevChannel( CurrentGroupChannel[CurrentGroup] );
                            }
                            if( CurrentGroupChannel[CurrentGroup] < FirstGroupChannel[CurrentGroup] )
                            {
                                CurrentGroupChannel[CurrentGroup] = FirstGroupChannel[CurrentGroup];
                            }
                        }
                        
                        if( middlemenuentry ) // if middlemenuentry hack is set do own page up
                        {
                            LoadSchedules(0);
                            break;
                        }
                        
                        return osContinue;
                    }
                    // otherwise we switch the group to the left
                    CurrentGroup--;
                    if( CurrentGroup < 0 )
                        CurrentGroup = MaxGroup-1;
                    LoadSchedules(0);
                    break;
                case kRight|k_Repeat:
                case kRight:
                    if( isMenuEvent )
                        return osContinue;
                    if( switchgroupkey == 1 ) // if we not switch groups by left/right we let do vdr the rest (page down)
                    {
                        if( CurrentGroupChannel[CurrentGroup] == LastGroupChannel[CurrentGroup] )
                        {
                            CurrentGroupChannel[CurrentGroup] = FirstGroupChannel[CurrentGroup];
                        } else
                        {
                            for(int i = 0; i < ChannelsShown; i++)
                            {
                                CurrentGroupChannel[CurrentGroup] = GetNextChannel( CurrentGroupChannel[CurrentGroup] );
                                if( CurrentGroupChannel[CurrentGroup] == -1 )
                                    break;
                            }
                            if( CurrentGroupChannel[CurrentGroup] > LastGroupChannel[CurrentGroup] || CurrentGroupChannel[CurrentGroup] == -1 )
                            {
                                CurrentGroupChannel[CurrentGroup] = LastGroupChannel[CurrentGroup];
                            }
                        }

                        if( middlemenuentry ) // if middlemenuentry hack is set do manuel page up
                        {
                            LoadSchedules(0);
                            break;
                        }
                        
                        return osContinue;
                    }

                    // otherwise we switch the group to the right
                    CurrentGroup++;
                    if( CurrentGroup >= MaxGroup )
                        CurrentGroup = 0;
                    LoadSchedules(0);
                    break;
                default:
                    break;
            }

        }
    }
    return state;
}