summaryrefslogtreecommitdiff
path: root/skinconfig.c
blob: f5ada81f28488f39373e62099f658b96a12274c0 (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
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
/*
 * GraphLCD plugin for the Video Disk Recorder
 *
 * skinconfig.c - skin config class that implements all the callbacks
 *
 * This file is released under the GNU General Public License. Refer
 * to the COPYING file distributed with this package.
 *
 * (c) 2004-2010 Andreas Regel <andreas.regel AT powarman.de>
 * (c) 2010-2011 Wolfgang Astleitner <mrwastl AT users sourceforge net>
 */

#include <glcdskin/config.h>
#include <glcdskin/type.h>
#include <glcdskin/string.h>

#include "common.h"
#include "display.h"
#include "state.h"
#include "skinconfig.h"
#include "service.h"
#include "extdata.h"

typedef enum _eTokenId
{
    // current channel
    tokPrivateChannelStart,
    tokChannelNumber,
    tokChannelName,
    tokChannelShortName,
    tokChannelProvider,
    tokChannelPortal,
    tokChannelSource,
    tokChannelID,
    tokHasTeletext,
    tokChannelHasTeletext,
    tokHasMultilang,
    tokChannelHasMultilang,
    tokHasDolby,
    tokChannelHasDolby,
    tokIsEncrypted,
    tokChannelIsEncrypted,
    tokIsRadio,
    tokChannelIsRadio,
    tokChannelAlias,
    tokPrivateChannelEnd,

    // current device
    tokPrivateDeviceStart,
    tokActualDevice,
    tokSignalStrength,
    tokSignalQuality,
    tokSupportsSignalInfo,
    tokPrivateDeviceEnd,

    tokPrivateRecordingStart,
    tokIsRecording,
    tokIsRecording1,
    tokIsRecording2,
    tokIsRecording3,
    tokRecordings,
    tokRecording1,
    tokRecording2,
    tokRecording3,
    tokPrivateRecordingEnd,

    // present event
    tokPrivatePresentStart,
    tokPresentValid,
    tokPresentStartDateTime,
    tokPresentVpsDateTime,
    tokPresentEndDateTime,
    tokPresentDuration,
    tokPresentProgress,
    tokPresentRemaining,
    tokPresentTitle,
    tokPresentShortText,
    tokPresentDescription,
    tokPrivatePresentEnd,

    // following event
    tokPrivateFollowingStart,
    tokFollowingValid,
    tokFollowingStartDateTime,
    tokFollowingVpsDateTime,
    tokFollowingEndDateTime,
    tokFollowingDuration,
    tokFollowingTitle,
    tokFollowingShortText,
    tokFollowingDescription,
    tokPrivateFollowingEnd,

    // volume display
    tokPrivateVolumeStart,
    tokVolumeCurrent,
    tokVolumeTotal,
    tokIsMute,
    tokVolumeIsMute,
    tokPrivateVolumeEnd,

    // audio display
    tokPrivateAudioStart,
    tokAudioTrackItem,
    tokAudioTrackCurrent,
    tokIsAudioTrackCurrent,
    tokAudioChannel,
    tokPrivateAudioEnd,

    tokPrivateReplayStart,
    tokReplayTitle,
    tokReplayPositionIndex,
    tokReplayDurationIndex,
    tokIsPlaying,
    tokReplayIsPlaying,
    tokIsFastForward,
    tokReplayIsFastForward,
    tokIsFastRewind,
    tokReplayIsFastRewind,
    tokIsSlowForward,
    tokReplayIsSlowForward,
    tokIsSlowRewind,
    tokReplayIsSlowRewind,
    tokIsPausing,
    tokReplayIsPausing,
    tokReplayPosition,
    tokReplayDuration,
    tokReplayRemaining,
    tokReplayMode,
    tokReplayIsShuffle,
    tokReplayIsLoop,
    tokPrivateReplayEnd,

    tokPrivateOsdStart,
    tokMessage,
    tokMenuTitle,
    tokMenuItem,
    tokMenuCurrent,
    tokIsMenuCurrent,
    tokIsMenuList,
    tokMenuText,
    tokMenuTextScroll,
    tokButtonRed,
    tokButtonGreen,
    tokButtonYellow,
    tokButtonBlue,
    tokPrivateOsdEnd,

    tokDateTime,
    tokConfigPath,
    tokSkinPath,
    tokScreenWidth,
    tokScreenHeight,
    tokDefaultForegroundColor,
    tokDefaultBackgroundColor,
    tokForegroundColor,
    tokBackgroundColor,
    tokIsUTF8,

    tokPrivateSettingStart,
    tokSettingShowChannelLogo,
    tokSettingShowReplayLogo,
    tokSettingShowSymbols,
    tokSettingShowTimebar,

    tokScrollMode,
    tokScrollSpeed,
    tokScrollTime,
    tokBrightnessActive,
    tokBrightnessIdle,
    tokBrightnessDelay,
    tokDisplayMode,
    tokPrivateSettingEnd,

    // external services and data
    tokPrivateServiceStart,
    tokServiceIsAvailable,
    tokServiceItem,
    tokExtDataIsAvailable,
    tokExtDataItem,
    tokPrivateServiceEnd,

    tokCountToken
} eTokenId;

static const std::string Tokens[tokCountToken] =
{
    "privateChannelStart",
    "ChannelNumber",
    "ChannelName",
    "ChannelShortName",
    "ChannelProvider",
    "ChannelPortal",
    "ChannelSource",
    "ChannelID",
    "HasTeletext",
    "ChannelHasTeletext",
    "HasMultilang",
    "ChannelHasMultilang",
    "HasDolby",
    "ChannelHasDolby",
    "IsEncrypted",
    "ChannelIsEncrypted",
    "IsRadio",
    "ChannelIsRadio",
    "ChannelAlias",
    "privateChannelEnd",

    "privatePrivateDeviceStart",
    "ActualDevice",
    "SignalStrength",
    "SignalQuality",
    "SupportsSignalInfo",
    "privateDeviceEnd",

    "privateRecordingStart",
    "IsRecording",
    "IsRecording1",
    "IsRecording2",
    "IsRecording3",
    "Recordings",
    "Recording1",
    "Recording2",
    "Recording3",
    "privateRecordingEnd",

    "privatePresentStart",
    "PresentValid",
    "PresentStartDateTime",
    "PresentVpsDateTime",
    "PresentEndDateTime",
    "PresentDuration",
    "PresentProgress",
    "PresentRemaining",
    "PresentTitle",
    "PresentShortText",
    "PresentDescription",
    "privatePresentEnd",

    "privateFollowingStart",
    "FollowingValid",
    "FollowingStartDateTime",
    "FollowingVpsDateTime",
    "FollowingEndDateTime",
    "FollowingDuration",
    "FollowingTitle",
    "FollowingShortText",
    "FollowingDescription",
    "privateFollowingEnd",

    "privateVolumeStart",
    "VolumeCurrent",
    "VolumeTotal",
    "IsMute",
    "VolumeIsMute",
    "privateVolumeEnd",

    "privateAudioStart",
    "AudioTrackItem",
    "AudioTrackCurrent",
    "IsAudioTrackCurrent",
    "AudioChannel",
    "privateAudioEnd",

    "privateReplayStart",
    "ReplayTitle",
    "ReplayPositionIndex",
    "ReplayDurationIndex",
    "IsPlaying",
    "ReplayIsPlaying",
    "IsFastForward",
    "ReplayIsFastForward",
    "IsFastRewind",
    "ReplayIsFastRewind",
    "IsSlowForward",
    "ReplayIsSlowForward",
    "IsSlowRewind",
    "ReplayIsSlowRewind",
    "IsPausing",
    "ReplayIsPausing",
    "ReplayPosition",
    "ReplayDuration",
    "ReplayRemaining",
    "ReplayMode",
    "ReplayIsShuffle",
    "ReplayIsLoop",
    "privateReplayEnd",

    "privateOsdStart",
    "Message",
    "MenuTitle",
    "MenuItem",
    "MenuCurrent",
    "IsMenuCurrent",
    "IsMenuList",
    "MenuText",
    "MenuTextScroll",
    "ButtonRed",
    "ButtonGreen",
    "ButtonYellow",
    "ButtonBlue",
    "privateOsdEnd",

    "DateTime",
    "ConfigPath",
    "SkinPath",
    "ScreenWidth",
    "ScreenHeight",
    "DefaultForegroundColor",
    "DefaultBackgroundColor",
    "ForegroundColor",
    "BackgroundColor",
    "IsUTF8",

    "privateSettingStart",
    "SettingShowChannelLogo",
    "SettingShowReplayLogo",
    "SettingShowSymbols",
    "SettingShowTimebar",

    "ScrollMode",
    "ScrollSpeed",
    "ScrollTime",
    "BrightnessActive",
    "BrightnessIdle",
    "BrightnessDelay",
    "DisplayMode",
    "privateSettingEnd",

    // external services
    "privateServiceStart",
    "ServiceIsAvailable",
    "ServiceItem",
    "ExtDataIsAvailable",
    "ExtDataItem",
    "privateServiceEnd"
};

cGraphLCDSkinConfig::cGraphLCDSkinConfig(const cGraphLCDDisplay * Display, const std::string & CfgPath, const std::string & SkinsPath, const std::string & SkinName, cGraphLCDState * State)
{
    mDisplay = Display;
    mConfigPath = CfgPath;
    mSkinPath = SkinsPath + "/" + SkinName;
    mSkinName = SkinName;
    mState = State;
    mAliasList.Load(CfgPath);
}

cGraphLCDSkinConfig::~cGraphLCDSkinConfig()
{
}

std::string cGraphLCDSkinConfig::SkinPath(void)
{
    return mSkinPath;
}

std::string cGraphLCDSkinConfig::FontPath(void)
{
    return mConfigPath + "/fonts";
}

std::string cGraphLCDSkinConfig::CharSet(void)
{
#if APIVERSNUM >= 10503
    if (cCharSetConv::SystemCharacterTable()) {
      return cCharSetConv::SystemCharacterTable();
    } else {
      return "UTF-8";
    }
#else
    if (I18nCharSets()[Setup.OSDLanguage]) {
      return I18nCharSets()[Setup.OSDLanguage];
    } else {
      return "iso-8859-15";
    }
#endif
}

std::string cGraphLCDSkinConfig::Translate(const std::string & Text)
{
    return I18nTranslate(Text.c_str());
}

GLCD::cType cGraphLCDSkinConfig::GetToken(const GLCD::tSkinToken & Token)
{
    if (Token.Id > tokPrivateChannelStart && Token.Id < tokPrivateChannelEnd)
    {
        tChannel channel = mState->GetChannelInfo();
        switch (Token.Id)
        {
            case tokChannelNumber:
                return channel.number;
            case tokChannelName:
                return channel.name;
            case tokChannelShortName:
                return channel.shortName;
            case tokChannelProvider:
                return channel.provider;
            case tokChannelPortal:
                return channel.portal;
            case tokChannelSource:
                return channel.source;
            case tokChannelID:
                return (GLCD::cType) (const char *) channel.id.ToString();
            case tokHasTeletext:
            case tokChannelHasTeletext:
                return channel.hasTeletext;
            case tokHasMultilang:
            case tokChannelHasMultilang:
                return channel.hasMultiLanguage;
            case tokHasDolby:
            case tokChannelHasDolby:
                return channel.hasDolby;
            case tokIsEncrypted:
            case tokChannelIsEncrypted:
                return channel.isEncrypted;
            case tokIsRadio:
            case tokChannelIsRadio:
                return channel.isRadio;
            case tokChannelAlias:
            {
                char tmp[64];
                std::string alias;

                sprintf(tmp, "%d-%d-%d", channel.id.Nid(), channel.id.Tid(), channel.id.Sid());
                alias = mAliasList.GetAlias(tmp);
                return alias;
            }
            default:
                break;
        }
    }
    else if (Token.Id > tokPrivateDeviceStart && Token.Id < tokPrivateDeviceEnd)
    {
        cDevice * currDev = cDevice::ActualDevice();
        if (currDev)
        {
            switch (Token.Id)
            {
                case tokActualDevice:
                {
                    return currDev->DeviceNumber()+1;  // DeviceNumber() starts with 0 but let output start w/ 1
                }
                case tokSignalStrength:
                {
#if VDRVERSNUM >= 10719
                    return currDev->SignalStrength();
#else
                    return false;
#endif
                }
                case tokSignalQuality:
                {
#if VDRVERSNUM >= 10719
                    return currDev->SignalQuality();
#else
                    return false;
#endif
                }
                case tokSupportsSignalInfo:
                {
#if VDRVERSNUM >= 10719
                    return true;
#else
                    return false;
#endif
                }
                default:
                    break;
            }
        }
        return false;
    }
    else if (Token.Id > tokPrivateRecordingStart && Token.Id < tokPrivateRecordingEnd)
    {
        switch (Token.Id)
        {
            case tokIsRecording:
            {
                if (Token.Attrib.Type == GLCD::aNumber)
                    return mState->IsRecording(Token.Attrib.Number, 0);
                return mState->IsRecording(-1, 0);
            }
            case tokIsRecording1:
            {
                if (Token.Attrib.Type == GLCD::aNumber)
                    return mState->IsRecording(Token.Attrib.Number, 1);
                return mState->IsRecording(-1, 1);
            }
            case tokIsRecording2:
            {
                if (Token.Attrib.Type == GLCD::aNumber)
                    return mState->IsRecording(Token.Attrib.Number, 2);
                return mState->IsRecording(-1, 2);
            }
            case tokIsRecording3:
            {
                if (Token.Attrib.Type == GLCD::aNumber)
                    return mState->IsRecording(Token.Attrib.Number, 3);
                return mState->IsRecording(-1, 3);
            }
            case tokRecordings:
            {
                if (Token.Attrib.Type == GLCD::aNumber)
                    return mState->Recordings(Token.Attrib.Number, 0);
                return mState->Recordings(-1, 0);
            }
            case tokRecording1:
            {
                if (Token.Attrib.Type == GLCD::aNumber)
                    return mState->Recordings(Token.Attrib.Number, 1);
                return mState->Recordings(-1, 1);
            }
            case tokRecording2:
            {
                if (Token.Attrib.Type == GLCD::aNumber)
                    return mState->Recordings(Token.Attrib.Number, 2);
                return mState->Recordings(-1, 2);
            }
            case tokRecording3:
            {
                if (Token.Attrib.Type == GLCD::aNumber)
                    return mState->Recordings(Token.Attrib.Number, 3);
                return mState->Recordings(-1, 3);
            }
            default:
                break;
        }
    }
    else if (Token.Id > tokPrivatePresentStart && Token.Id < tokPrivatePresentEnd)
    {
        tEvent event = mState->GetPresentEvent();
        switch (Token.Id)
        {
            case tokPresentValid:
                return event.valid;
            case tokPresentStartDateTime:
                return TimeType(event.startTime, Token.Attrib.Text);
            case tokPresentVpsDateTime:
                return TimeType(event.vpsTime, Token.Attrib.Text);
            case tokPresentEndDateTime:
                return TimeType(event.startTime + event.duration, Token.Attrib.Text);
            case tokPresentDuration:
                return DurationType(event.duration, Token.Attrib.Text);
            case tokPresentProgress:
                return DurationType(time(NULL) - event.startTime, Token.Attrib.Text);
            case tokPresentRemaining:
                if ((time(NULL) - event.startTime) < event.duration)
                {
                    return DurationType(event.duration - (time(NULL) - event.startTime), Token.Attrib.Text);
                }
                return false;
            case tokPresentTitle:
                return event.title;
            case tokPresentShortText:
                return event.shortText;
            case tokPresentDescription:
                return event.description;
            default:
                break;
        }
    }
    else if (Token.Id > tokPrivateFollowingStart && Token.Id < tokPrivateFollowingEnd)
    {
        tEvent event = mState->GetFollowingEvent();
        switch (Token.Id)
        {
            case tokFollowingValid:
                return event.valid;
            case tokFollowingStartDateTime:
                return TimeType(event.startTime, Token.Attrib.Text);
            case tokFollowingVpsDateTime:
                return TimeType(event.vpsTime, Token.Attrib.Text);
            case tokFollowingEndDateTime:
                return TimeType(event.startTime + event.duration, Token.Attrib.Text);
            case tokFollowingDuration:
                return DurationType(event.duration, Token.Attrib.Text);
            case tokFollowingTitle:
                return event.title;
            case tokFollowingShortText:
                return event.shortText;
            case tokFollowingDescription:
                return event.description;
            default:
                break;
        }
    }
    else if (Token.Id > tokPrivateVolumeStart && Token.Id < tokPrivateVolumeEnd)
    {
        tVolumeState volume = mState->GetVolumeState();
        switch (Token.Id)
        {
            case tokVolumeCurrent:
                return volume.value;
            case tokVolumeTotal:
                return 255;
            case tokIsMute:
            case tokVolumeIsMute:
                return volume.value == 0;
            default:
                break;
        }
    }
    else if (Token.Id > tokPrivateAudioStart && Token.Id < tokPrivateAudioEnd)
    {
        tAudioState audio = mState->GetAudioState();
        switch (Token.Id)
        {
            case tokAudioTrackItem:
            case tokAudioTrackCurrent:
            case tokIsAudioTrackCurrent:
            {
                if (audio.tracks.size() == 0
                  || audio.currentTrack == -1)
                {
                    return false;
                }
                int maxItems = Token.MaxItems;
                if (maxItems > (int) audio.tracks.size())
                    maxItems = audio.tracks.size();
                int currentIndex = maxItems / 2;
                if (audio.currentTrack < currentIndex)
                    currentIndex = audio.currentTrack;
                int topIndex = audio.currentTrack - currentIndex;
                if ((topIndex + maxItems) > (int) audio.tracks.size())
                {
                    currentIndex += (topIndex + maxItems) - audio.tracks.size();
                    topIndex = audio.currentTrack - currentIndex;
                }
                if (Token.Id == tokAudioTrackItem)
                {
                    if (Token.Index < maxItems && Token.Index != currentIndex)
                        return audio.tracks[topIndex + Token.Index];
                }
                else if (Token.Id == tokAudioTrackCurrent)
                {
                    if (Token.Index < maxItems && Token.Index == currentIndex)
                        return audio.tracks[topIndex + Token.Index];
                    else if (Token.Index < 0) // outside of <list/>: return last MenuCurrent
                        return audio.tracks[topIndex];
                }
                else if (Token.Id == tokIsAudioTrackCurrent)
                {
                    if (Token.Index < maxItems && Token.Index == currentIndex)
                        return true;
                }
                return false;
            }
            case tokAudioChannel:
                return audio.currentChannel;
            default:
                break;
        }
    }
    else if (Token.Id > tokPrivateReplayStart && Token.Id < tokPrivateReplayEnd)
    {
        tReplayState replay = mState->GetReplayState();
        double framesPerSec = 
#if VDRVERSNUM >= 10701
          (replay.control) ? replay.control->FramesPerSecond() : (double)DEFAULTFRAMESPERSECOND
#else
          (double)FRAMESPERSEC
#endif
        ;

        switch (Token.Id)
        {
            case tokReplayTitle:
                return replay.name;
            case tokReplayPositionIndex:
                return DurationType(replay.current, Token.Attrib.Text, framesPerSec);
            case tokReplayDurationIndex:
                return DurationType(replay.total, Token.Attrib.Text, framesPerSec);
            case tokReplayPosition:
                return replay.current;
            case tokReplayDuration:
                return replay.total;
            case tokReplayRemaining:
                return DurationType(replay.total - replay.current, Token.Attrib.Text, framesPerSec);
            case tokIsPlaying:
            case tokReplayIsPlaying:
                return replay.play && replay.speed == -1;
            case tokIsPausing:
            case tokReplayIsPausing:
                return !replay.play && replay.speed == -1;
            case tokIsFastForward:
            case tokReplayIsFastForward:
                if (replay.play && replay.forward && replay.speed != -1)
                {
                    return Token.Attrib.Type == GLCD::aNumber
                        ? (GLCD::cType) (replay.speed == Token.Attrib.Number)
                        : (GLCD::cType) true;
                }
                return false;
            case tokIsFastRewind:
            case tokReplayIsFastRewind:
                if (replay.play && !replay.forward && replay.speed != -1)
                {
                    return Token.Attrib.Type == GLCD::aNumber
                        ? (GLCD::cType) (replay.speed == Token.Attrib.Number)
                        : (GLCD::cType) true;
                }
                return false;
            case tokIsSlowForward:
            case tokReplayIsSlowForward:
                if (!replay.play && replay.forward && replay.speed != -1)
                {
                    return Token.Attrib.Type == GLCD::aNumber
                        ? (GLCD::cType) (replay.speed == Token.Attrib.Number)
                        : (GLCD::cType) true;
                }
                return false;
            case tokIsSlowRewind:
            case tokReplayIsSlowRewind:
                if (!replay.play && !replay.forward && replay.speed != -1)
                {
                    return Token.Attrib.Type == GLCD::aNumber
                        ? (GLCD::cType) (replay.speed == Token.Attrib.Number)
                        : (GLCD::cType) true;
                }
                return false;
            case tokReplayMode:
                switch (replay.mode)
                {
                    case eReplayAudioCD:
                        return "cd";
                    case eReplayDVD:
                        return "dvd";
                    case eReplayFile:
                        return "file";
                    case eReplayImage:
                        return "image";
                    case eReplayMusic:
                        return "music";
                    default:
                        return "vdr";
                }
            case tokReplayIsShuffle:
            case tokReplayIsLoop:
            default:
                break;
        }
    }
    else if (Token.Id > tokPrivateOsdStart && Token.Id < tokPrivateOsdEnd)
    {
        tOsdState osd = mState->GetOsdState();
        switch (Token.Id)
        {
            case tokMessage:
                return osd.message;
            case tokMenuTitle:
                return SplitToken(osd.title, Token.Attrib);
            case tokMenuItem:
            case tokMenuCurrent:
            case tokIsMenuCurrent:
            {
                if (osd.items.size() == 0
                  || osd.currentItemIndex == -1)
                {
                    return false;
                }
                int maxItems = Token.MaxItems;
                if (maxItems > (int) osd.items.size())
                    maxItems = osd.items.size();
                int currentIndex = maxItems / 2;
                if (osd.currentItemIndex < currentIndex)
                    currentIndex = osd.currentItemIndex;
                int topIndex = osd.currentItemIndex - currentIndex;
                if ((topIndex + maxItems) > (int) osd.items.size())
                {
                    currentIndex += (topIndex + maxItems) - osd.items.size();
                    topIndex = osd.currentItemIndex - currentIndex;
                }
                if (Token.Id == tokMenuItem)
                {
                    if (Token.Index < maxItems && Token.Index != currentIndex)
                        return osd.items[topIndex + Token.Index];
                }
                else if (Token.Id == tokMenuCurrent)
                {
                    if (Token.Index < maxItems && Token.Index == currentIndex)
                        return SplitToken(osd.items[topIndex + Token.Index], Token.Attrib);
                    else if (Token.Index < 0) // outside of <list/>: return last MenuCurrent
                        return SplitToken(osd.items[topIndex], Token.Attrib, true);
                }
                else if (Token.Id == tokIsMenuCurrent)
                {
                    if (Token.Index < maxItems && Token.Index == currentIndex)
                        return true;
                }
                return false;
            }
            case tokIsMenuList:
                return (osd.items.size() == 0) ? false : true;
            case tokMenuText:
                return SplitToken(osd.textItem, Token.Attrib);
            case tokMenuTextScroll: {
                int curr_scroll = osd.currentTextItemScroll;
                mState->ResetOsdStateScroll();
                return curr_scroll;
            }
            case tokButtonRed:
                return osd.redButton;
            case tokButtonGreen:
                return osd.greenButton;
            case tokButtonYellow:
                return osd.yellowButton;
            case tokButtonBlue:
                return osd.blueButton;
            default:
                break;
        }
    }
    else if (Token.Id > tokPrivateSettingStart && Token.Id < tokPrivateSettingEnd)
    {
        switch (Token.Id)
        {
            case tokSettingShowChannelLogo:
                if (GraphLCDSetup.ShowChannelLogo)
                    return true;
                return false;
            case tokSettingShowReplayLogo:
                if (GraphLCDSetup.ShowReplayLogo)
                    return true;
                return false;
            case tokSettingShowSymbols:
                if (GraphLCDSetup.ShowSymbols)
                    return true;
                return false;
            case tokSettingShowTimebar:
                if (GraphLCDSetup.ShowTimebar)
                    return true;
                return false;

            case tokScrollMode:
                return GraphLCDSetup.ScrollMode;
            case tokScrollSpeed:
                return GraphLCDSetup.ScrollSpeed;
            case tokScrollTime:
                return GraphLCDSetup.ScrollTime;
            case tokBrightnessActive:
                return GraphLCDSetup.BrightnessActive;
            case tokBrightnessIdle:
                return GraphLCDSetup.BrightnessIdle;
            case tokBrightnessDelay:
                return GraphLCDSetup.BrightnessDelay;
            case tokDisplayMode:
                switch (mDisplay->GetDisplayMode())
                {
                    case DisplayModeNormal:
                        return "Normal";
                    case DisplayModeInteractive:
                        return "Interactive";
                    default:
                        return "Normal";
                }

            default:
                break;
        }
    }
    else if (Token.Id > tokPrivateServiceStart && Token.Id < tokPrivateServiceEnd)
    {
        cGraphLCDService * s = (cGraphLCDService*)mDisplay->GetServiceObject();
        switch (Token.Id)
        {
            case tokServiceIsAvailable: {
                if (Token.Attrib.Text == "")
                    return false;

                size_t found = Token.Attrib.Text.find(",");
                std::string ServiceName = "";
                std::string Options = "";

                if (found != std::string::npos) {
                    ServiceName = Token.Attrib.Text.substr(0, found);
                    Options = Token.Attrib.Text.substr(found+1);
                } else {
                    ServiceName = Token.Attrib.Text;
                }
                return s->ServiceIsAvailable(ServiceName, Options);
            }
            break;
            case tokServiceItem: {
                size_t found = Token.Attrib.Text.find(",");
                std::string ServiceName = "";
                std::string ItemName = "";

                if (found != std::string::npos) {
                    ServiceName = Token.Attrib.Text.substr(0, found);
                    ItemName = Token.Attrib.Text.substr(found+1);
                } else {
                    ServiceName = Token.Attrib.Text;
                }
                return s->GetItem(ServiceName, ItemName);
            }
            break;
            case tokExtDataIsAvailable: {
                if (Token.Attrib.Text == "")
                    return false;

                cExtData * extData = cExtData::GetExtData();
                if (extData)
                    return extData->IsSet( Token.Attrib.Text, mDisplay->GetDriver()->ConfigName() );
                return false;
            }
            break;
            case tokExtDataItem: {
                if (Token.Attrib.Text == "")
                    return false;

                cExtData * extData = cExtData::GetExtData();
                if (extData)
                    return extData->Get( Token.Attrib.Text, mDisplay->GetDriver()->ConfigName() );
                return false;
            }
            break;
            default:
                break;
        }
    }
    else
    {
        switch (Token.Id)
        {
            case tokDateTime:
                return TimeType(time(NULL), Token.Attrib.Text);
            case tokConfigPath:
                return mConfigPath;
            case tokSkinPath:
                return mSkinPath;
            case tokScreenWidth:
            {
                const GLCD::cBitmap * bitmap = mDisplay->GetScreen();
                return bitmap->Width();
            }
            case tokScreenHeight:
            {
                const GLCD::cBitmap * bitmap = mDisplay->GetScreen();
                return bitmap->Height();
            }
            case tokDefaultForegroundColor:
            {
                char buffer[12];
                snprintf(buffer, 11, "0x%08x", (uint32_t)((mDisplay)->GetDriver()->GetForegroundColor(true)));
                return buffer;
            }
            case tokDefaultBackgroundColor:
            {
                char buffer[12];
                snprintf(buffer, 11, "0x%08x", (uint32_t)((mDisplay)->GetDriver()->GetBackgroundColor(true)));
                return buffer;
            }
            case tokForegroundColor:
            {
                char buffer[12];
                snprintf(buffer, 11, "0x%08x", (uint32_t)((mDisplay)->GetDriver()->GetForegroundColor(false)));
                return buffer;
            }
            case tokBackgroundColor:
            {
                char buffer[12];
                snprintf(buffer, 11, "0x%08x", (uint32_t)((mDisplay)->GetDriver()->GetBackgroundColor(false)));
                return buffer;
            }
            case tokIsUTF8:
            {
                return (CharSet() == "UTF-8");
            }
            default:
                break;
        }
    }
    return "";
}

int cGraphLCDSkinConfig::GetTokenId(const std::string & Name)
{
    int i;

    for (i = 0; i < tokCountToken; i++)
    {
        if (Name == Tokens[i])
            return i;
    }
    esyslog("graphlcd plugin: ERROR: Unknown token %s", Name.c_str());
    return tokCountToken;
}

int cGraphLCDSkinConfig::GetTabPosition(int Index, int MaxWidth, const GLCD::cFont & Font)
{
    if (mTabs.size() == 0)
    {
        int i;
        tOsdState osd = mState->GetOsdState();

        for (i = 0; i < (int) osd.items.size(); i++)
        {
            int iTab, t;
            std::string str;
            std::string::size_type pos1, pos2;

            str = osd.items[i];
            pos1 = 0;
            pos2 = str.find('\t');
            iTab = 0;
            while (pos1 < str.length() && pos2 != std::string::npos)
            {
                t = Font.Width(str.substr(pos1), pos2 - pos1);
                if (iTab == 0 && t > (MaxWidth * 66) / 100)
                    t = (MaxWidth * 66) / 100;
                if (iTab < (int) mTabs.size())
                {
                    if (mTabs[iTab] < t)
                        mTabs[iTab] = t;
                }
                else
                {
                    mTabs.push_back(t);
                }
                pos1 = pos2 + 1;
                pos2 = str.find('\t', pos1);
                iTab++;
            }
        }
    }

    if (Index < (int) mTabs.size())
        return mTabs[Index];
    return 0;
}

void cGraphLCDSkinConfig::SetMenuClear()
{
    mTabs.clear();
}


uint64_t cGraphLCDSkinConfig::Now(void)
{
    return cTimeMs::Now();
}

GLCD::cDriver * cGraphLCDSkinConfig::GetDriver(void) const
{
    return (mDisplay) ? (mDisplay)->GetDriver() : NULL;
}