summaryrefslogtreecommitdiff
path: root/apps/gui/skin_engine/skin_tokens.c
blob: ebe9ac50b160c41940bb311495d6223f71513b5f (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
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id$
 *
 * Copyright (C) 2002-2007 Björn Stenberg
 * Copyright (C) 2007-2008 Nicolas Pennequin
 *
 * 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 software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/
#include "font.h"
#include <stdio.h>
#include "string-extra.h"
#include <stdlib.h>
#include "action.h"
#include "system.h"
#include "settings.h"
#include "settings_list.h"
#include "rbunicode.h"
#include "timefuncs.h"
#include "status.h"
#include "power.h"
#include "powermgmt.h"
#include "sound.h"
#include "debug.h"
#include "cuesheet.h"
#ifdef HAVE_LCD_CHARCELLS
#include "hwcompat.h"
#endif
#include "abrepeat.h"
#include "lang.h"
#include "misc.h"
#include "led.h"
#ifdef HAVE_LCD_BITMAP
/* Image stuff */
#include "albumart.h"
#endif
#include "dsp.h"
#include "playlist.h"
#if CONFIG_CODEC == SWCODEC
#include "playback.h"
#include "tdspeed.h"
#endif
#include "viewport.h"

#include "wps_internals.h"
#include "root_menu.h"
#ifdef HAVE_RECORDING
#include "recording.h"
#include "pcm_record.h"
#endif
#include "language.h"
#include "usb.h"
#if CONFIG_TUNER
#include "radio.h"
#include "tuner.h"
#endif

extern struct wps_state wps_state;

static const char* get_codectype(const struct mp3entry* id3)
{
    if (id3 && id3->codectype < AFMT_NUM_CODECS) {
        return audio_formats[id3->codectype].label;
    } else {
        return NULL;
    }
}

/* Extract a part from a path.
 *
 * buf      - buffer extract part to.
 * buf_size - size of buffer.
 * path     - path to extract from.
 * level    - what to extract. 0 is file name, 1 is parent of file, 2 is
 *            parent of parent, etc.
 *
 * Returns buf if the desired level was found, NULL otherwise.
 */
char* get_dir(char* buf, int buf_size, const char* path, int level)
{
    const char* sep;
    const char* last_sep;
    int len;

    sep = path + strlen(path);
    last_sep = sep;

    while (sep > path)
    {
        if ('/' == *(--sep))
        {
            if (!level)
                break;

            level--;
            last_sep = sep - 1;
        }
    }

    if (level || (last_sep <= sep))
        return NULL;

    len = MIN(last_sep - sep, buf_size - 1);
    strlcpy(buf, sep + 1, len + 1);
    return buf;
}

#if (CONFIG_CODEC != MAS3507D)
/* A helper to determine the enum value for pitch/speed.

   When there are two choices (i.e. boolean), return 1 if the value is
   different from normal value and 2 if the value is the same as the
   normal value.  E.g. "%?Sp<%Sp>" would show the pitch only when
   playing at a modified pitch.

   When there are more than two choices (i.e. enum), the left half of
   the choices are to show 0..normal range, and the right half of the
   choices are to show values over that.  The last entry is used when
   it is set to the normal setting, following the rockbox convention
   to use the last entry for special values.

   E.g.

   2 items: %?Sp<0..99 or 101..infinity|100>
   3 items: %?Sp<0..99|101..infinity|100>
   4 items: %?Sp<0..49|50..99|101..infinity|100>
   5 items: %?Sp<0..49|50..99|101..149|150..infinity|100>
   6 items: %?Sp<0..33|34..66|67..99|101..133|134..infinity|100>
   7 items: %?Sp<0..33|34..66|67..99|101..133|134..167|167..infinity|100>
*/
static int pitch_speed_enum(int range, int32_t val, int32_t normval)
{
    int center;
    int n;

    if (range < 3)
        return (val == normval) + 1;
    if (val == normval)
        return range;
    center = range / 2;
    n = (center * val) / normval + 1;
    return (range <= n) ? (range - 1) : n;
}
#endif

const char *get_cuesheetid3_token(struct wps_token *token, struct mp3entry *id3,
                                  int offset_tracks, char *buf, int buf_size)
{
    struct cuesheet *cue = id3?id3->cuesheet:NULL;
    if (!cue || !cue->curr_track)
        return NULL;
    
    struct cue_track_info *track = cue->curr_track;
    if (offset_tracks)
    {
        if (cue->curr_track_idx+offset_tracks < cue->track_count)
            track+=offset_tracks;
        else
            return NULL;
    }
    switch (token->type)
    {
        case SKIN_TOKEN_METADATA_ARTIST:
            return *track->performer ? track->performer : NULL;
        case SKIN_TOKEN_METADATA_COMPOSER:
            return *track->songwriter ? track->songwriter : NULL;
        case SKIN_TOKEN_METADATA_ALBUM:
            return *cue->title ? cue->title : NULL;
        case SKIN_TOKEN_METADATA_ALBUM_ARTIST:
            return *cue->performer ? cue->performer : NULL;
        case SKIN_TOKEN_METADATA_TRACK_TITLE:
            return *track->title ? track->title : NULL;
        case SKIN_TOKEN_METADATA_TRACK_NUMBER:
            snprintf(buf, buf_size, "%d/%d",  
                     cue->curr_track_idx+offset_tracks+1, cue->track_count);
            return buf;
        default:
            return NULL;
    }
    return NULL;
}

/* All tokens which only need the info to return a value go in here */
const char *get_id3_token(struct wps_token *token, struct mp3entry *id3,
                          char *buf, int buf_size, int limit, int *intval)
{
    struct wps_state *state = &wps_state;
    if (id3)
    {
        unsigned long length = id3->length;
        unsigned long elapsed = id3->elapsed + state->ff_rewind_count;
        switch (token->type)
        {
            case SKIN_TOKEN_METADATA_ARTIST:
                return id3->artist;
            case SKIN_TOKEN_METADATA_COMPOSER:
                return id3->composer;
            case SKIN_TOKEN_METADATA_ALBUM:
                return id3->album;
            case SKIN_TOKEN_METADATA_ALBUM_ARTIST:
                return id3->albumartist;
            case SKIN_TOKEN_METADATA_GROUPING:
                return id3->grouping;
            case SKIN_TOKEN_METADATA_GENRE:
                return id3->genre_string;
            case SKIN_TOKEN_METADATA_DISC_NUMBER:
                if (id3->disc_string)
                    return id3->disc_string;
                if (id3->discnum) {
                    snprintf(buf, buf_size, "%d", id3->discnum);
                    return buf;
                }
                return NULL;
            case SKIN_TOKEN_METADATA_TRACK_NUMBER:
                if (id3->track_string)
                    return id3->track_string;
                if (id3->tracknum) {
                    snprintf(buf, buf_size, "%d", id3->tracknum);
                    return buf;
                }
                return NULL;
            case SKIN_TOKEN_METADATA_TRACK_TITLE:
                return id3->title;
            case SKIN_TOKEN_METADATA_VERSION:
                switch (id3->id3version)
                {
                    case ID3_VER_1_0:
                        return "1";
                    case ID3_VER_1_1:
                        return "1.1";
                    case ID3_VER_2_2:
                        return "2.2";
                    case ID3_VER_2_3:
                        return "2.3";
                    case ID3_VER_2_4:
                        return "2.4";
                    default:
                        break;
                }
                return NULL;
            case SKIN_TOKEN_METADATA_YEAR:
                if( id3->year_string )
                    return id3->year_string;
                if (id3->year) {
                    snprintf(buf, buf_size, "%d", id3->year);
                    return buf;
                }
                return NULL;
            case SKIN_TOKEN_METADATA_COMMENT:
                return id3->comment;
            case SKIN_TOKEN_FILE_PATH:
                return id3->path;
            case SKIN_TOKEN_FILE_BITRATE:
                if(id3->bitrate)
                    snprintf(buf, buf_size, "%d", id3->bitrate);
                else
                    return "?";
                return buf;
            case SKIN_TOKEN_TRACK_TIME_ELAPSED:
                format_time(buf, buf_size, elapsed);
                return buf;

            case SKIN_TOKEN_TRACK_TIME_REMAINING:
                format_time(buf, buf_size, length - elapsed);
                return buf;

            case SKIN_TOKEN_TRACK_LENGTH:
                format_time(buf, buf_size, length);
                return buf;

            case SKIN_TOKEN_TRACK_ELAPSED_PERCENT:
                if (length <= 0)
                    return NULL;

                if (intval)
                {
                    *intval = limit * elapsed / length + 1;
                }
                snprintf(buf, buf_size, "%lu", 100 * elapsed / length);
                return buf;

            case SKIN_TOKEN_TRACK_STARTING:
                {
                    unsigned long time = token->value.i * (HZ/TIMEOUT_UNIT);
                    if (elapsed < time)
                        return "starting";
                }
                return NULL;
            case SKIN_TOKEN_TRACK_ENDING:
                {
                    unsigned long time = token->value.i * (HZ/TIMEOUT_UNIT);
                    if (length - elapsed < time)
                        return "ending";
                }
                return NULL;

            case SKIN_TOKEN_FILE_CODEC:
                if (intval)
                {
                    if(id3->codectype == AFMT_UNKNOWN)
                        *intval = AFMT_NUM_CODECS;
                    else
                        *intval = id3->codectype;
                }
                return get_codectype(id3);

            case SKIN_TOKEN_FILE_FREQUENCY:
                snprintf(buf, buf_size, "%ld", id3->frequency);
                return buf;
            case SKIN_TOKEN_FILE_FREQUENCY_KHZ:
                /* ignore remainders < 100, so 22050 Hz becomes just 22k */
                if ((id3->frequency % 1000) < 100)
                    snprintf(buf, buf_size, "%ld", id3->frequency / 1000);
                else
                    snprintf(buf, buf_size, "%ld.%lu",
                            id3->frequency / 1000,
                            (id3->frequency % 1000) / 100);
                return buf;
            case SKIN_TOKEN_FILE_NAME:
                if (get_dir(buf, buf_size, id3->path, 0)) {
                    /* Remove extension */
                    char* sep = strrchr(buf, '.');
                    if (NULL != sep) {
                        *sep = 0;
                    }
                    return buf;
                }
                return NULL;
            case SKIN_TOKEN_FILE_NAME_WITH_EXTENSION:
                return get_dir(buf, buf_size, id3->path, 0);
            case SKIN_TOKEN_FILE_SIZE:
                snprintf(buf, buf_size, "%ld", id3->filesize / 1024);
                return buf;
            case SKIN_TOKEN_FILE_VBR:
                return (id3->vbr) ? "(avg)" : NULL;
            case SKIN_TOKEN_FILE_DIRECTORY:
                return get_dir(buf, buf_size, id3->path, token->value.i);

#ifdef HAVE_TAGCACHE
        case SKIN_TOKEN_DATABASE_PLAYCOUNT:
            if (intval)
                *intval = id3->playcount + 1;
            snprintf(buf, buf_size, "%ld", id3->playcount);
            return buf;
        case SKIN_TOKEN_DATABASE_RATING:
            if (intval)
                *intval = id3->rating + 1;
            snprintf(buf, buf_size, "%d", id3->rating);
            return buf;
        case SKIN_TOKEN_DATABASE_AUTOSCORE:
            if (intval)
                *intval = id3->score + 1;
            snprintf(buf, buf_size, "%d", id3->score);
            return buf;
#endif

            default:
                return NULL;
        }
    }
    else /* id3 == NULL, handle the error based on the expected return type */
    {
        switch (token->type)
        {
            /* Most tokens expect NULL on error so leave that for the default case,
             * The ones that expect "0" need to be handled */
            case SKIN_TOKEN_FILE_FREQUENCY:
            case SKIN_TOKEN_FILE_FREQUENCY_KHZ:
            case SKIN_TOKEN_FILE_SIZE:
#ifdef HAVE_TAGCACHE
            case SKIN_TOKEN_DATABASE_PLAYCOUNT:
            case SKIN_TOKEN_DATABASE_RATING:
            case SKIN_TOKEN_DATABASE_AUTOSCORE:
#endif
                if (intval)
                    *intval = 0;
                return "0";
            default:
                return NULL;
        }
    }
    return buf;
}

#if CONFIG_TUNER

/* Formats the frequency (specified in Hz) in MHz,   */
/* with one or two digits after the decimal point -- */
/* depending on the frequency changing step.         */
/* Returns buf                                       */
static char *format_freq_MHz(int freq, int freq_step, char *buf, int buf_size)
{
    int scale, div;
    char *fmt;
    if (freq_step < 100000)
    {
        /* Format with two digits after decimal point */
        scale = 10000;
        fmt = "%d.%02d";
    }
    else
    {
        /* Format with one digit after decimal point */
        scale = 100000;
        fmt = "%d.%d";
    }
    div = 1000000 / scale;
    freq = freq / scale;
    snprintf(buf, buf_size, fmt, freq/div, freq%div);
    return buf;
}


/* Tokens which are really only used by the radio screen go in here */
const char *get_radio_token(struct wps_token *token, int preset_offset,
                            char *buf, int buf_size, int limit, int *intval)
{
    const struct fm_region_data *region_data =
            &(fm_region_data[global_settings.fm_region]);
    (void)limit;
    switch (token->type)
    {
        /* Radio/tuner tokens */
        case SKIN_TOKEN_TUNER_TUNED:
            if (tuner_get(RADIO_TUNED))
                return "t";
            return NULL;
        case SKIN_TOKEN_TUNER_SCANMODE:
            if (radio_scan_mode())
                return "s";
            return NULL;
        case SKIN_TOKEN_TUNER_STEREO:
            if (radio_is_stereo())
                return "s";
            return NULL;
        case SKIN_TOKEN_TUNER_MINFREQ: /* changes based on "region" */
            return format_freq_MHz(region_data->freq_min,
                            region_data->freq_step, buf, buf_size);
        case SKIN_TOKEN_TUNER_MAXFREQ: /* changes based on "region" */
            return format_freq_MHz(region_data->freq_max,
                            region_data->freq_step, buf, buf_size);
        case SKIN_TOKEN_TUNER_CURFREQ:
            return format_freq_MHz(radio_current_frequency(),
                            region_data->freq_step, buf, buf_size);
        case SKIN_TOKEN_PRESET_NAME:
        case SKIN_TOKEN_PRESET_FREQ:
        case SKIN_TOKEN_PRESET_ID:
        {
            int preset_count = radio_preset_count();
            int cur_preset = radio_current_preset();
            if (preset_count == 0 || cur_preset < 0)
                return NULL;
            int preset = cur_preset + preset_offset;
            /* make sure it's in the valid range */
            preset %= preset_count;
            if (preset < 0)
                preset += preset_count;
            if (token->type == SKIN_TOKEN_PRESET_NAME)
                snprintf(buf, buf_size, "%s", radio_get_preset(preset)->name);
            else if (token->type == SKIN_TOKEN_PRESET_FREQ)
                format_freq_MHz(radio_get_preset(preset)->frequency,
                                region_data->freq_step, buf, buf_size);
            else
                snprintf(buf, buf_size, "%d", preset + 1);
            return buf;
        }
        case SKIN_TOKEN_PRESET_COUNT:
            snprintf(buf, buf_size, "%d", radio_preset_count());        
            if (intval)
                *intval = radio_preset_count();
            return buf;
        case SKIN_TOKEN_HAVE_RDS:
#ifdef HAVE_RDS_CAP
            return "rds";
        case SKIN_TOKEN_RDS_NAME:
            return tuner_get_rds_info(RADIO_RDS_NAME);
        case SKIN_TOKEN_RDS_TEXT:
            return tuner_get_rds_info(RADIO_RDS_TEXT);
#else
            return NULL; /* end of the SKIN_TOKEN_HAVE_RDS case */
#endif /* HAVE_RDS_CAP */
        default:
            return NULL;
    }
    return NULL;
}
#endif

/* Return the tags value as text. buf should be used as temp storage if needed.

   intval is used with conditionals/enums: when this function is called,
   intval should contain the number of options in the conditional/enum.
   When this function returns, intval is -1 if the tag is non numeric or,
   if the tag is numeric, *intval is the enum case we want to go to (between 1
   and the original value of *intval, inclusive).
   When not treating a conditional/enum, intval should be NULL.
*/
const char *get_token_value(struct gui_wps *gwps,
                           struct wps_token *token,
                           char *buf, int buf_size,
                           int *intval)
{
    if (!gwps)
        return NULL;

    struct wps_data *data = gwps->data;
    struct wps_state *state = gwps->state;
    struct mp3entry *id3; /* Think very carefully about using this. 
                             maybe get_id3_token() is the better place? */
    const char *out_text = NULL;

    if (!data || !state)
        return NULL;


    if (token->next)
        id3 = state->nid3;
    else
        id3 = state->id3;
        
#if CONFIG_RTC
    struct tm* tm = NULL;

    /* if the token is an RTC one, update the time
       and do the necessary checks */
    if (token->type >= SKIN_TOKENS_RTC_BEGIN
        && token->type <= SKIN_TOKENS_RTC_END)
    {
        tm = get_time();

        if (!valid_time(tm))
            return NULL;
    }
#endif

    int limit = 1;
    if (intval)
    {
        limit = *intval;
        *intval = -1;
    }
    
    if (state->id3 && state->id3->cuesheet)
    {
        out_text = get_cuesheetid3_token(token, state->id3, token->next?1:0, buf, buf_size);
        if (out_text)
            return out_text;
    }
    out_text = get_id3_token(token, id3, buf, buf_size, limit, intval);
    if (out_text)
        return out_text;
#if CONFIG_TUNER
    out_text = get_radio_token(token, 0, buf, buf_size, limit, intval);
    if (out_text)
        return out_text;
#endif

    switch (token->type)
    {
        case SKIN_TOKEN_CHARACTER:
            if (token->value.c == '\n')
                return NULL;
            return &(token->value.c);

        case SKIN_TOKEN_STRING:
            return (char*)token->value.data;
            
        case SKIN_TOKEN_TRANSLATEDSTRING:
            return (char*)P2STR(ID2P(token->value.i));

        case SKIN_TOKEN_PLAYLIST_ENTRIES:
            snprintf(buf, buf_size, "%d", playlist_amount());
            return buf;
        
        case SKIN_TOKEN_LIST_TITLE_TEXT:
            return (char*)token->value.data;
        case SKIN_TOKEN_LIST_TITLE_ICON:
            if (intval)
                *intval = token->value.i;
            snprintf(buf, buf_size, "%d", token->value.i);
            return buf;

        case SKIN_TOKEN_PLAYLIST_NAME:
            return playlist_name(NULL, buf, buf_size);

        case SKIN_TOKEN_PLAYLIST_POSITION:
            snprintf(buf, buf_size, "%d", playlist_get_display_index());
            return buf;

        case SKIN_TOKEN_PLAYLIST_SHUFFLE:
            if ( global_settings.playlist_shuffle )
                return "s";
            else
                return NULL;
            break;

        case SKIN_TOKEN_VOLUME:
            snprintf(buf, buf_size, "%d", global_settings.volume);
            if (intval)
            {
                int minvol = sound_min(SOUND_VOLUME);
                if (global_settings.volume == minvol)
                {
                    *intval = 1;
                }
                else if (global_settings.volume == 0)
                {
                    *intval = limit - 1;
                }
                else if (global_settings.volume > 0)
                {
                    *intval = limit;
                }
                else
                {
                    *intval = (limit-3) * (global_settings.volume - minvol - 1)
                                / (-1 - minvol) + 2;
                }
            }
            return buf;
#ifdef HAVE_ALBUMART
        case SKIN_TOKEN_ALBUMART_FOUND:
            if (data->albumart)
            {
                int handle = -1;
                handle = playback_current_aa_hid(data->playback_aa_slot);
#if CONFIG_TUNER
                if (in_radio_screen() || (get_radio_status() != FMRADIO_OFF))
                {
                    struct dim dim = {data->albumart->width, data->albumart->height};
                    handle = radio_get_art_hid(&dim);
                }
#endif
                if (handle >= 0)    
                    return "C";
            }
            return NULL;
#endif

        case SKIN_TOKEN_BATTERY_PERCENT:
        {
            int l = battery_level();

            if (intval)
            {
                limit = MAX(limit, 3);
                if (l > -1) {
                    /* First enum is used for "unknown level",
                     * last enum is used for 100%.
                     */
                    *intval = (limit - 2) * l / 100 + 2;
                } else {
                    *intval = 1;
                }
            }

            if (l > -1) {
                snprintf(buf, buf_size, "%d", l);
                return buf;
            } else {
                return "?";
            }
        }

        case SKIN_TOKEN_BATTERY_VOLTS:
        {
            unsigned int v = battery_voltage();
            snprintf(buf, buf_size, "%d.%02d", v / 1000, (v % 1000) / 10);
            return buf;
        }

        case SKIN_TOKEN_BATTERY_TIME:
        {
            int t = battery_time();
            if (t >= 0)
                snprintf(buf, buf_size, "%dh %dm", t / 60, t % 60);
            else
                return "?h ?m";
            return buf;
        }

#if CONFIG_CHARGING
        case SKIN_TOKEN_BATTERY_CHARGER_CONNECTED:
        {
            if(charger_input_state==CHARGER)
                return "p";
            else
                return NULL;
        }
#endif
#if CONFIG_CHARGING >= CHARGING_MONITOR
        case SKIN_TOKEN_BATTERY_CHARGING:
        {
            if (charge_state == CHARGING || charge_state == TOPOFF) {
                return "c";
            } else {
                return NULL;
            }
        }
#endif
#ifdef HAVE_USB_POWER
        case SKIN_TOKEN_USB_POWERED:
            if (usb_powered())
                return "u";
            return NULL;
#endif
        case SKIN_TOKEN_BATTERY_SLEEPTIME:
        {
            if (get_sleep_timer() == 0)
                return NULL;
            else
            {
                format_time(buf, buf_size, get_sleep_timer() * 1000);
                return buf;
            }
        }

        case SKIN_TOKEN_PLAYBACK_STATUS:
        {
            int status = current_playmode();
            /* music */
            int mode = 1; /* stop */
            if (status == STATUS_PLAY)
                mode = 2; /* play */
            if (state->is_fading || 
               (status == STATUS_PAUSE  && !status_get_ffmode()))
                mode = 3; /* pause */
            else
            {   /* ff / rwd */
                if (status_get_ffmode() == STATUS_FASTFORWARD)
                    mode = 4;
                if (status_get_ffmode() == STATUS_FASTBACKWARD)
                    mode = 5;
            }
#ifdef HAVE_RECORDING
            /* recording */
            if (status == STATUS_RECORD)
                mode = 6;
            else if (status == STATUS_RECORD_PAUSE)
                mode = 7;
#endif
#if CONFIG_TUNER
            /* radio */
            if (status == STATUS_RADIO)
                mode = 8;
            else if (status == STATUS_RADIO_PAUSE)
                mode = 9;
#endif

            if (intval) {
                *intval = mode;
            }

            snprintf(buf, buf_size, "%d", mode-1);
            return buf;
        }

        case SKIN_TOKEN_REPEAT_MODE:
            if (intval)
                *intval = global_settings.repeat_mode + 1;
            snprintf(buf, buf_size, "%d", global_settings.repeat_mode);
            return buf;

        case SKIN_TOKEN_RTC_PRESENT:
#if CONFIG_RTC
                return "c";
#else
                return NULL;
#endif

#if CONFIG_RTC
        case SKIN_TOKEN_RTC_12HOUR_CFG:
            if (intval)
                *intval = global_settings.timeformat + 1;
            snprintf(buf, buf_size, "%d", global_settings.timeformat);
            return buf;

        case SKIN_TOKEN_RTC_DAY_OF_MONTH:
            /* d: day of month (01..31) */
            snprintf(buf, buf_size, "%02d", tm->tm_mday);
            if (intval)
                *intval = tm->tm_mday - 1;
            return buf;

        case SKIN_TOKEN_RTC_DAY_OF_MONTH_BLANK_PADDED:
            /* e: day of month, blank padded ( 1..31) */
            snprintf(buf, buf_size, "%2d", tm->tm_mday);
            if (intval)
                *intval = tm->tm_mday - 1;
            return buf;

        case SKIN_TOKEN_RTC_HOUR_24_ZERO_PADDED:
            /* H: hour (00..23) */
            snprintf(buf, buf_size, "%02d", tm->tm_hour);
            if (intval)
                *intval = tm->tm_hour;
            return buf;

        case SKIN_TOKEN_RTC_HOUR_24:
            /* k: hour ( 0..23) */
            snprintf(buf, buf_size, "%2d", tm->tm_hour);
            if (intval)
                *intval = tm->tm_hour;
            return buf;

        case SKIN_TOKEN_RTC_HOUR_12_ZERO_PADDED:
            /* I: hour (01..12) */
            snprintf(buf, buf_size, "%02d",
                     (tm->tm_hour % 12 == 0) ? 12 : tm->tm_hour % 12);
            if (intval)
                *intval = (tm->tm_hour % 12 == 0) ? 12 : tm->tm_hour % 12;
            return buf;

        case SKIN_TOKEN_RTC_HOUR_12:
            /* l: hour ( 1..12) */
            snprintf(buf, buf_size, "%2d",
                     (tm->tm_hour % 12 == 0) ? 12 : tm->tm_hour % 12);
            if (intval)
                *intval = (tm->tm_hour % 12 == 0) ? 12 : tm->tm_hour % 12;
            return buf;

        case SKIN_TOKEN_RTC_MONTH:
            /* m: month (01..12) */
            if (intval)
                *intval = tm->tm_mon + 1;
            snprintf(buf, buf_size, "%02d", tm->tm_mon + 1);
            return buf;

        case SKIN_TOKEN_RTC_MINUTE:
            /* M: minute (00..59) */
            snprintf(buf, buf_size, "%02d", tm->tm_min);
            if (intval)
                *intval = tm->tm_min;
            return buf;

        case SKIN_TOKEN_RTC_SECOND:
            /* S: second (00..59) */
            snprintf(buf, buf_size, "%02d", tm->tm_sec);
            if (intval)
                *intval = tm->tm_sec;
            return buf;

        case SKIN_TOKEN_RTC_YEAR_2_DIGITS:
            /* y: last two digits of year (00..99) */
            snprintf(buf, buf_size, "%02d", tm->tm_year % 100);
            if (intval)
                *intval = tm->tm_year % 100;
            return buf;

        case SKIN_TOKEN_RTC_YEAR_4_DIGITS:
            /* Y: year (1970...) */
            snprintf(buf, buf_size, "%04d", tm->tm_year + 1900);
            if (intval)
                *intval = tm->tm_year + 1900;
            return buf;

        case SKIN_TOKEN_RTC_AM_PM_UPPER:
            /* p: upper case AM or PM indicator */
            if (intval)
                *intval = tm->tm_hour/12 == 0 ? 0 : 1;
            return tm->tm_hour/12 == 0 ? "AM" : "PM";

        case SKIN_TOKEN_RTC_AM_PM_LOWER:
            /* P: lower case am or pm indicator */
            if (intval)
                *intval = tm->tm_hour/12 == 0 ? 0 : 1;
            return tm->tm_hour/12 == 0 ? "am" : "pm";

        case SKIN_TOKEN_RTC_WEEKDAY_NAME:
            /* a: abbreviated weekday name (Sun..Sat) */
            return str(LANG_WEEKDAY_SUNDAY + tm->tm_wday);

        case SKIN_TOKEN_RTC_MONTH_NAME:
            /* b: abbreviated month name (Jan..Dec) */
            return str(LANG_MONTH_JANUARY + tm->tm_mon);

        case SKIN_TOKEN_RTC_DAY_OF_WEEK_START_MON:
            /* u: day of week (1..7); 1 is Monday */
            if (intval)
                *intval = (tm->tm_wday == 0) ? 7 : tm->tm_wday;
            snprintf(buf, buf_size, "%1d", tm->tm_wday + 1);
            return buf;

        case SKIN_TOKEN_RTC_DAY_OF_WEEK_START_SUN:
            /* w: day of week (0..6); 0 is Sunday */
            if (intval)
                *intval = tm->tm_wday + 1;
            snprintf(buf, buf_size, "%1d", tm->tm_wday);
            return buf;
#else
        case SKIN_TOKEN_RTC_DAY_OF_MONTH:
        case SKIN_TOKEN_RTC_DAY_OF_MONTH_BLANK_PADDED:
        case SKIN_TOKEN_RTC_HOUR_24_ZERO_PADDED:
        case SKIN_TOKEN_RTC_HOUR_24:
        case SKIN_TOKEN_RTC_HOUR_12_ZERO_PADDED:
        case SKIN_TOKEN_RTC_HOUR_12:
        case SKIN_TOKEN_RTC_MONTH:
        case SKIN_TOKEN_RTC_MINUTE:
        case SKIN_TOKEN_RTC_SECOND:
        case SKIN_TOKEN_RTC_AM_PM_UPPER:
        case SKIN_TOKEN_RTC_AM_PM_LOWER:
        case SKIN_TOKEN_RTC_YEAR_2_DIGITS:
            return "--";
        case SKIN_TOKEN_RTC_YEAR_4_DIGITS:
            return "----";
        case SKIN_TOKEN_RTC_WEEKDAY_NAME:
        case SKIN_TOKEN_RTC_MONTH_NAME:
            return "---";
        case SKIN_TOKEN_RTC_DAY_OF_WEEK_START_MON:
        case SKIN_TOKEN_RTC_DAY_OF_WEEK_START_SUN:
            return "-";
#endif

#ifdef HAVE_LCD_CHARCELLS
        case SKIN_TOKEN_PROGRESSBAR:
        {
            char *end = utf8encode(data->wps_progress_pat[0], buf);
            *end = '\0';
            return buf;
        }

        case SKIN_TOKEN_PLAYER_PROGRESSBAR:
            if(is_new_player())
            {
                /* we need 11 characters (full line) for
                    progress-bar */
                strlcpy(buf, "           ", buf_size);
            }
            else
            {
                /* Tell the user if we have an OldPlayer */
                strlcpy(buf, " <Old LCD> ", buf_size);
            }
            return buf;
#endif



#if (CONFIG_CODEC == SWCODEC)
        case SKIN_TOKEN_CROSSFADE:
#ifdef HAVE_CROSSFADE
            if (intval)
                *intval = global_settings.crossfade + 1;
            snprintf(buf, buf_size, "%d", global_settings.crossfade);
#else
            snprintf(buf, buf_size, "%d", 0);
#endif
            return buf;

        case SKIN_TOKEN_REPLAYGAIN:
        {
            int val;

            if (global_settings.replaygain_type == REPLAYGAIN_OFF)
                val = 1; /* off */
            else
            {
                int type;
                if (LIKELY(id3))
                    type = get_replaygain_mode(id3->track_gain_string != NULL,
                                        id3->album_gain_string != NULL);
                else
                    type = -1;

                if (type < 0)
                    val = 6;    /* no tag */
                else
                    val = type + 2;

                if (global_settings.replaygain_type == REPLAYGAIN_SHUFFLE)
                    val += 2;
            }

            if (intval)
                *intval = val;

            switch (val)
            {
                case 1:
                case 6:
                    return "+0.00 dB";
                    break;
                /* due to above, coming here with !id3 shouldn't be possible */
                case 2:
                case 4:
                    strlcpy(buf, id3->track_gain_string, buf_size);
                    break;
                case 3:
                case 5:
                    strlcpy(buf, id3->album_gain_string, buf_size);
                    break;
            }
            return buf;
        }
#endif  /* (CONFIG_CODEC == SWCODEC) */

#if (CONFIG_CODEC != MAS3507D)
        case SKIN_TOKEN_SOUND_PITCH:
        {
            int32_t pitch = sound_get_pitch();
            snprintf(buf, buf_size, "%ld.%ld",
                     pitch / PITCH_SPEED_PRECISION,
             (pitch  % PITCH_SPEED_PRECISION) / (PITCH_SPEED_PRECISION / 10));

        if (intval)
            *intval = pitch_speed_enum(limit, pitch,
                           PITCH_SPEED_PRECISION * 100);
            return buf;
        }
#endif

#if CONFIG_CODEC == SWCODEC
    case SKIN_TOKEN_SOUND_SPEED:
    {
        int32_t pitch = sound_get_pitch();
        int32_t speed;
        if (dsp_timestretch_available())
            speed = GET_SPEED(pitch, dsp_get_timestretch());
        else
            speed = pitch;
        snprintf(buf, buf_size, "%ld.%ld",
                     speed / PITCH_SPEED_PRECISION,
             (speed  % PITCH_SPEED_PRECISION) / (PITCH_SPEED_PRECISION / 10));
        if (intval)
            *intval = pitch_speed_enum(limit, speed,
                           PITCH_SPEED_PRECISION * 100);
            return buf;
    }
#endif

        case SKIN_TOKEN_MAIN_HOLD:
#ifdef HAS_BUTTON_HOLD
            if (button_hold())
#else
            if (is_keys_locked())
#endif /*hold switch or softlock*/
                return "h";
            else
                return NULL;

#ifdef HAS_REMOTE_BUTTON_HOLD
        case SKIN_TOKEN_REMOTE_HOLD:
            if (remote_button_hold())
                return "r";
            else
                return NULL;
#endif

#if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
        case SKIN_TOKEN_VLED_HDD:
            if(led_read(HZ/2))
                return "h";
            else
                return NULL;
#endif
        case SKIN_TOKEN_BUTTON_VOLUME:
            if (global_status.last_volume_change &&
                TIME_BEFORE(current_tick, global_status.last_volume_change +
                                          token->value.i))
                return "v";
            return NULL;
            
        case SKIN_TOKEN_LASTTOUCH:
            {
#ifdef HAVE_TOUCHSCREEN
            unsigned int last_touch = touchscreen_last_touch();
            if (last_touch != 0xffff &&
                TIME_BEFORE(current_tick, token->value.i + last_touch))
                return "t";
#endif
            }
            return NULL;

        case SKIN_TOKEN_SETTING:
        {
            const struct settings_list *s = settings+token->value.i;
            if (intval)
            {
                /* Handle contionals */
                switch (s->flags&F_T_MASK)
                {
                    case F_T_INT:
                    case F_T_UINT:
                        if (s->flags&F_T_SOUND)
                        {
                            /* %?St|name|<min|min+1|...|max-1|max> */
                            int sound_setting = s->sound_setting->setting;
                            /* settings with decimals can't be used in conditionals */
                            if (sound_numdecimals(sound_setting) == 0)
                            {
                                *intval = (*(int*)s->setting-sound_min(sound_setting))
                                      /sound_steps(sound_setting) + 1;
                            }
                            else
                                *intval = -1;
                        }
                        else if (s->flags&F_RGB)
                            /* %?St|name|<#000000|#000001|...|#FFFFFF> */
                            /* shouldn't overflow since colors are stored
                             * on 16 bits ...
                             * but this is pretty useless anyway */
                            *intval = *(int*)s->setting + 1;
                        else if (s->cfg_vals == NULL)
                            /* %?St|name|<1st choice|2nd choice|...> */
                            *intval = (*(int*)s->setting-s->int_setting->min)
                                      /s->int_setting->step + 1;
                        else
                            /* %?St|name|<1st choice|2nd choice|...> */
                            /* Not sure about this one. cfg_name/vals are
                             * indexed from 0 right? */
                            *intval = *(int*)s->setting + 1;
                        break;
                    case F_T_BOOL:
                        /* %?St|name|<if true|if false> */
                        *intval = *(bool*)s->setting?1:2;
                        break;
                    case F_T_CHARPTR:
                    case F_T_UCHARPTR:
                        /* %?St|name|<if non empty string|if empty>
                         * The string's emptyness discards the setting's
                         * prefix and suffix */
                        *intval = ((char*)s->setting)[0]?1:2;
                        /* if there is a prefix we should ignore it here */
                        if (s->filename_setting->prefix)
                            return (char*)s->setting;
                        break;
                    default:
                        /* This shouldn't happen ... but you never know */
                        *intval = -1;
                        break;
                }
            }
            /* Special handlng for filenames because we dont want to show the prefix */
            if ((s->flags&F_T_MASK) == F_T_UCHARPTR ||
                (s->flags&F_T_MASK) == F_T_UCHARPTR)
            {
                if (s->filename_setting->prefix)
                    return (char*)s->setting;
            }
            cfg_to_string(token->value.i,buf,buf_size);
            return buf;
        }
        case SKIN_TOKEN_HAVE_TUNER:
#if CONFIG_TUNER
            if (radio_hardware_present())
                return "r";
#endif
            return NULL;
        /* Recording tokens */
        case SKIN_TOKEN_HAVE_RECORDING:
#ifdef HAVE_RECORDING
            return "r";
#else
            return NULL;
#endif

#ifdef HAVE_RECORDING
        case SKIN_TOKEN_IS_RECORDING:
            if (audio_status() == AUDIO_STATUS_RECORD)
                return "r";
            return NULL;
        case SKIN_TOKEN_REC_FREQ: /* order from REC_FREQ_CFG_VAL_LIST */
        {
#if CONFIG_CODEC == SWCODEC
            unsigned long samprk;
            int rec_freq = global_settings.rec_frequency;

#ifdef SIMULATOR
            samprk = 44100;
#else
#if defined(HAVE_SPDIF_REC)
            if (global_settings.rec_source == AUDIO_SRC_SPDIF)
            {
                /* Use rate in use, not current measured rate if it changed */
                samprk = pcm_rec_sample_rate();
                rec_freq = 0;
                while (rec_freq < SAMPR_NUM_FREQ &&
                       audio_master_sampr_list[rec_freq] != samprk)
                {
                    rec_freq++;
                }
            }
            else
#endif
                samprk = rec_freq_sampr[rec_freq];
#endif /* SIMULATOR */
            if (intval)
            {
                switch (rec_freq)
                {
                    REC_HAVE_96_(case REC_FREQ_96:
                        *intval = 1;
                        break;)
                    REC_HAVE_88_(case REC_FREQ_88:
                        *intval = 2;
                        break;)
                    REC_HAVE_64_(case REC_FREQ_64:
                        *intval = 3;
                        break;)
                    REC_HAVE_48_(case REC_FREQ_48:
                        *intval = 4;
                        break;)
                    REC_HAVE_44_(case REC_FREQ_44:
                        *intval = 5;
                        break;)
                    REC_HAVE_32_(case REC_FREQ_32:
                        *intval = 6;
                        break;)
                    REC_HAVE_24_(case REC_FREQ_24:
                        *intval = 7;
                        break;)
                    REC_HAVE_22_(case REC_FREQ_22:
                        *intval = 8;
                        break;)
                    REC_HAVE_16_(case REC_FREQ_16:
                        *intval = 9;
                        break;)
                    REC_HAVE_12_(case REC_FREQ_12:
                        *intval = 10;
                        break;)
                    REC_HAVE_11_(case REC_FREQ_11:
                        *intval = 11;
                        break;)
                    REC_HAVE_8_(case REC_FREQ_8:
                        *intval = 12;
                        break;)
                }
            }
            snprintf(buf, buf_size, "%lu.%1lu", samprk/1000,samprk%1000);
#else /* HWCODEC */
            
            static const char * const freq_strings[] =
                {"--", "44", "48", "32", "22", "24", "16"};
            int freq = 1 + global_settings.rec_frequency;
#ifdef HAVE_SPDIF_REC
            if (global_settings.rec_source == AUDIO_SRC_SPDIF)
            {
                /* Can't measure S/PDIF sample rate on Archos/Sim yet */
                freq = 0;
            }
#endif /* HAVE_SPDIF_IN */
            if (intval)
                *intval = freq+1; /* so the token gets a value 1<=x<=7 */
            snprintf(buf, buf_size, "%s\n",
                        freq_strings[global_settings.rec_frequency]);
#endif
            return buf;
        }
#if CONFIG_CODEC == SWCODEC
        case SKIN_TOKEN_REC_ENCODER:
        {
            int rec_format = global_settings.rec_format+1; /* WAV, AIFF, WV, MPEG */
            if (intval)
                *intval = rec_format;
            switch (rec_format)
            {
                case REC_FORMAT_PCM_WAV:
                    return "wav";
                case REC_FORMAT_AIFF:
                    return "aiff";
                case REC_FORMAT_WAVPACK:
                    return "wv";
                case REC_FORMAT_MPA_L3:
                    return "MP3";
                default:
                    return NULL;
            }
            break;
        }
#endif
        case SKIN_TOKEN_REC_BITRATE:
#if CONFIG_CODEC == SWCODEC
            if (global_settings.rec_format == REC_FORMAT_MPA_L3)
            {
                if (intval)
                {
                    #if 0 /* FIXME: I dont know if this is needed? */
                    switch (1<<global_settings.mp3_enc_config.bitrate)
                    {
                        case MP3_BITR_CAP_8:
                            *intval = 1;
                            break;
                        case MP3_BITR_CAP_16:
                            *intval = 2;
                            break;
                        case MP3_BITR_CAP_24:
                            *intval = 3;
                            break;
                        case MP3_BITR_CAP_32:
                            *intval = 4;
                            break;
                        case MP3_BITR_CAP_40:
                            *intval = 5;
                            break;
                        case MP3_BITR_CAP_48:
                            *intval = 6;
                            break;
                        case MP3_BITR_CAP_56:
                            *intval = 7;
                            break;
                        case MP3_BITR_CAP_64:
                            *intval = 8;
                            break;
                        case MP3_BITR_CAP_80:
                            *intval = 9;
                            break;
                        case MP3_BITR_CAP_96:
                            *intval = 10;
                            break;
                        case MP3_BITR_CAP_112:
                            *intval = 11;
                            break;
                        case MP3_BITR_CAP_128:
                            *intval = 12;
                            break;
                        case MP3_BITR_CAP_144:
                            *intval = 13;
                            break;
                        case MP3_BITR_CAP_160:
                            *intval = 14;
                            break;
                        case MP3_BITR_CAP_192:
                            *intval = 15;
                            break;
                    }
                    #endif
                    *intval = global_settings.mp3_enc_config.bitrate+1;
                }
                snprintf(buf, buf_size, "%lu", global_settings.mp3_enc_config.bitrate+1);
                return buf;
            }
            else
                return NULL; /* Fixme later */
#else /* CONFIG_CODEC == HWCODEC */
            if (intval)
                *intval = global_settings.rec_quality+1;
            snprintf(buf, buf_size, "%d", global_settings.rec_quality);
            return buf;
#endif
        case SKIN_TOKEN_REC_MONO:
            if (!global_settings.rec_channels)
                return "m";
            return NULL;
            
        case SKIN_TOKEN_REC_SECONDS:
        {
            int time = (audio_recorded_time() / HZ) % 60;
            if (intval)
                *intval = time;
            snprintf(buf, buf_size, "%02d", time);
            return buf;
        }
        case SKIN_TOKEN_REC_MINUTES:
        {
            int time = (audio_recorded_time() / HZ) / 60;
            if (intval)
                *intval = time;
            snprintf(buf, buf_size, "%02d", time);
            return buf;
        }
        case SKIN_TOKEN_REC_HOURS:
        {
            int time = (audio_recorded_time() / HZ) / 3600;
            if (intval)
                *intval = time;
            snprintf(buf, buf_size, "%02d", time);
            return buf;
        }

#endif /* HAVE_RECORDING */

        case SKIN_TOKEN_CURRENT_SCREEN:
        {
            int curr_screen = current_screen();

#ifdef HAVE_RECORDING
            /* override current_screen() for recording screen since it may
             * be entered from the radio screen */
            if (in_recording_screen())
                curr_screen = GO_TO_RECSCREEN;
#endif
            
            switch (curr_screen)
            {
                case GO_TO_WPS:
                    curr_screen = 2;
                    break;
#ifdef HAVE_RECORDING
                case GO_TO_RECSCREEN:
                    curr_screen = 3;
                    break;
#endif
#if CONFIG_TUNER
                case GO_TO_FM:
                    curr_screen = 4;
                    break;
#endif
                case GO_TO_PLAYLIST_VIEWER:
                    curr_screen = 5;
                    break;
                default: /* lists */
                    curr_screen = 1;
                    break;
            }
            if (intval)
            {
                *intval = curr_screen;
            }
            snprintf(buf, buf_size, "%d", curr_screen);
            return buf;
        }

        case SKIN_TOKEN_LANG_IS_RTL:
            return lang_is_rtl() ? "r" : NULL;

        default:
            return NULL;
    }
}