diff options
author | Jonathan Gordon <rockbox@jdgordon.info> | 2009-07-27 07:21:05 +0000 |
---|---|---|
committer | Jonathan Gordon <rockbox@jdgordon.info> | 2009-07-27 07:21:05 +0000 |
commit | 5e5fc64cb2e74024e15cb33eab6b832610c2a60b (patch) | |
tree | 915ce63e39060b2f7223d60d730ce8f8fa2cf67f /apps/gui/wps_engine/wps_tokens.c | |
parent | 4e16015427287381e4ef826a61118408c96658f0 (diff) | |
download | rockbox-5e5fc64cb2e74024e15cb33eab6b832610c2a60b.tar.gz rockbox-5e5fc64cb2e74024e15cb33eab6b832610c2a60b.zip |
Start of some apps/ and wps cleanup work... Move everything related to the actual drawing of the wps into apps/gui/wps_engine, things related to the actual screen are in apps/gui/music_screen.c (names are temporary unless noone comes up with anything better)
No real code changes.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22062 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/gui/wps_engine/wps_tokens.c')
-rw-r--r-- | apps/gui/wps_engine/wps_tokens.c | 807 |
1 files changed, 807 insertions, 0 deletions
diff --git a/apps/gui/wps_engine/wps_tokens.c b/apps/gui/wps_engine/wps_tokens.c new file mode 100644 index 0000000000..3852251916 --- /dev/null +++ b/apps/gui/wps_engine/wps_tokens.c | |||
@@ -0,0 +1,807 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002-2007 Björn Stenberg | ||
11 | * Copyright (C) 2007-2008 Nicolas Pennequin | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or | ||
14 | * modify it under the terms of the GNU General Public License | ||
15 | * as published by the Free Software Foundation; either version 2 | ||
16 | * of the License, or (at your option) any later version. | ||
17 | * | ||
18 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
19 | * KIND, either express or implied. | ||
20 | * | ||
21 | ****************************************************************************/ | ||
22 | #include "font.h" | ||
23 | #include <stdio.h> | ||
24 | #include <string.h> | ||
25 | #include <stdlib.h> | ||
26 | #include "action.h" | ||
27 | #include "system.h" | ||
28 | #include "settings.h" | ||
29 | #include "settings_list.h" | ||
30 | #include "rbunicode.h" | ||
31 | #include "timefuncs.h" | ||
32 | #include "audio.h" | ||
33 | #include "status.h" | ||
34 | #include "power.h" | ||
35 | #include "powermgmt.h" | ||
36 | #include "sound.h" | ||
37 | #include "debug.h" | ||
38 | #ifdef HAVE_LCD_CHARCELLS | ||
39 | #include "hwcompat.h" | ||
40 | #endif | ||
41 | #include "abrepeat.h" | ||
42 | #include "mp3_playback.h" | ||
43 | #include "lang.h" | ||
44 | #include "misc.h" | ||
45 | #include "led.h" | ||
46 | #ifdef HAVE_LCD_BITMAP | ||
47 | /* Image stuff */ | ||
48 | #include "albumart.h" | ||
49 | #endif | ||
50 | #include "dsp.h" | ||
51 | #include "playlist.h" | ||
52 | #if CONFIG_CODEC == SWCODEC | ||
53 | #include "playback.h" | ||
54 | #endif | ||
55 | #include "viewport.h" | ||
56 | |||
57 | #include "wps_internals.h" | ||
58 | #include "music_screen.h" | ||
59 | |||
60 | static char* get_codectype(const struct mp3entry* id3) | ||
61 | { | ||
62 | if (id3->codectype < AFMT_NUM_CODECS) { | ||
63 | return (char*)audio_formats[id3->codectype].label; | ||
64 | } else { | ||
65 | return NULL; | ||
66 | } | ||
67 | } | ||
68 | |||
69 | /* Extract a part from a path. | ||
70 | * | ||
71 | * buf - buffer extract part to. | ||
72 | * buf_size - size of buffer. | ||
73 | * path - path to extract from. | ||
74 | * level - what to extract. 0 is file name, 1 is parent of file, 2 is | ||
75 | * parent of parent, etc. | ||
76 | * | ||
77 | * Returns buf if the desired level was found, NULL otherwise. | ||
78 | */ | ||
79 | static char* get_dir(char* buf, int buf_size, const char* path, int level) | ||
80 | { | ||
81 | const char* sep; | ||
82 | const char* last_sep; | ||
83 | int len; | ||
84 | |||
85 | sep = path + strlen(path); | ||
86 | last_sep = sep; | ||
87 | |||
88 | while (sep > path) | ||
89 | { | ||
90 | if ('/' == *(--sep)) | ||
91 | { | ||
92 | if (!level) | ||
93 | break; | ||
94 | |||
95 | level--; | ||
96 | last_sep = sep - 1; | ||
97 | } | ||
98 | } | ||
99 | |||
100 | if (level || (last_sep <= sep)) | ||
101 | return NULL; | ||
102 | |||
103 | len = MIN(last_sep - sep, buf_size - 1); | ||
104 | strlcpy(buf, sep + 1, len + 1); | ||
105 | return buf; | ||
106 | } | ||
107 | |||
108 | /* Return the tag found at index i and write its value in buf. | ||
109 | The return value is buf if the tag had a value, or NULL if not. | ||
110 | |||
111 | intval is used with conditionals/enums: when this function is called, | ||
112 | intval should contain the number of options in the conditional/enum. | ||
113 | When this function returns, intval is -1 if the tag is non numeric or, | ||
114 | if the tag is numeric, *intval is the enum case we want to go to (between 1 | ||
115 | and the original value of *intval, inclusive). | ||
116 | When not treating a conditional/enum, intval should be NULL. | ||
117 | */ | ||
118 | const char *get_token_value(struct gui_wps *gwps, | ||
119 | struct wps_token *token, | ||
120 | char *buf, int buf_size, | ||
121 | int *intval) | ||
122 | { | ||
123 | if (!gwps) | ||
124 | return NULL; | ||
125 | |||
126 | struct wps_data *data = gwps->data; | ||
127 | struct wps_state *state = gwps->state; | ||
128 | |||
129 | if (!data || !state) | ||
130 | return NULL; | ||
131 | |||
132 | struct mp3entry *id3; | ||
133 | |||
134 | if (token->next) | ||
135 | id3 = state->nid3; | ||
136 | else | ||
137 | id3 = state->id3; | ||
138 | |||
139 | if (!id3) | ||
140 | return NULL; | ||
141 | |||
142 | #if CONFIG_RTC | ||
143 | struct tm* tm = NULL; | ||
144 | |||
145 | /* if the token is an RTC one, update the time | ||
146 | and do the necessary checks */ | ||
147 | if (token->type >= WPS_TOKENS_RTC_BEGIN | ||
148 | && token->type <= WPS_TOKENS_RTC_END) | ||
149 | { | ||
150 | tm = get_time(); | ||
151 | |||
152 | if (!valid_time(tm)) | ||
153 | return NULL; | ||
154 | } | ||
155 | #endif | ||
156 | |||
157 | int limit = 1; | ||
158 | if (intval) | ||
159 | { | ||
160 | limit = *intval; | ||
161 | *intval = -1; | ||
162 | } | ||
163 | |||
164 | switch (token->type) | ||
165 | { | ||
166 | case WPS_TOKEN_CHARACTER: | ||
167 | return &(token->value.c); | ||
168 | |||
169 | case WPS_TOKEN_STRING: | ||
170 | return data->strings[token->value.i]; | ||
171 | |||
172 | case WPS_TOKEN_TRACK_TIME_ELAPSED: | ||
173 | format_time(buf, buf_size, | ||
174 | id3->elapsed + state->ff_rewind_count); | ||
175 | return buf; | ||
176 | |||
177 | case WPS_TOKEN_TRACK_TIME_REMAINING: | ||
178 | format_time(buf, buf_size, | ||
179 | id3->length - id3->elapsed - | ||
180 | state->ff_rewind_count); | ||
181 | return buf; | ||
182 | |||
183 | case WPS_TOKEN_TRACK_LENGTH: | ||
184 | format_time(buf, buf_size, id3->length); | ||
185 | return buf; | ||
186 | |||
187 | case WPS_TOKEN_PLAYLIST_ENTRIES: | ||
188 | snprintf(buf, buf_size, "%d", playlist_amount()); | ||
189 | return buf; | ||
190 | |||
191 | case WPS_TOKEN_PLAYLIST_NAME: | ||
192 | return playlist_name(NULL, buf, buf_size); | ||
193 | |||
194 | case WPS_TOKEN_PLAYLIST_POSITION: | ||
195 | snprintf(buf, buf_size, "%d", playlist_get_display_index()); | ||
196 | return buf; | ||
197 | |||
198 | case WPS_TOKEN_PLAYLIST_SHUFFLE: | ||
199 | if ( global_settings.playlist_shuffle ) | ||
200 | return "s"; | ||
201 | else | ||
202 | return NULL; | ||
203 | break; | ||
204 | |||
205 | case WPS_TOKEN_VOLUME: | ||
206 | snprintf(buf, buf_size, "%d", global_settings.volume); | ||
207 | if (intval) | ||
208 | { | ||
209 | if (global_settings.volume == sound_min(SOUND_VOLUME)) | ||
210 | { | ||
211 | *intval = 1; | ||
212 | } | ||
213 | else if (global_settings.volume == 0) | ||
214 | { | ||
215 | *intval = limit - 1; | ||
216 | } | ||
217 | else if (global_settings.volume > 0) | ||
218 | { | ||
219 | *intval = limit; | ||
220 | } | ||
221 | else | ||
222 | { | ||
223 | *intval = (limit - 3) * (global_settings.volume | ||
224 | - sound_min(SOUND_VOLUME) - 1) | ||
225 | / (-1 - sound_min(SOUND_VOLUME)) + 2; | ||
226 | } | ||
227 | } | ||
228 | return buf; | ||
229 | |||
230 | case WPS_TOKEN_TRACK_ELAPSED_PERCENT: | ||
231 | if (id3->length <= 0) | ||
232 | return NULL; | ||
233 | |||
234 | if (intval) | ||
235 | { | ||
236 | *intval = limit * (id3->elapsed + state->ff_rewind_count) | ||
237 | / id3->length + 1; | ||
238 | } | ||
239 | snprintf(buf, buf_size, "%d", | ||
240 | 100*(id3->elapsed + state->ff_rewind_count) / id3->length); | ||
241 | return buf; | ||
242 | |||
243 | case WPS_TOKEN_METADATA_ARTIST: | ||
244 | return id3->artist; | ||
245 | |||
246 | case WPS_TOKEN_METADATA_COMPOSER: | ||
247 | return id3->composer; | ||
248 | |||
249 | case WPS_TOKEN_METADATA_ALBUM: | ||
250 | return id3->album; | ||
251 | |||
252 | case WPS_TOKEN_METADATA_ALBUM_ARTIST: | ||
253 | return id3->albumartist; | ||
254 | |||
255 | case WPS_TOKEN_METADATA_GROUPING: | ||
256 | return id3->grouping; | ||
257 | |||
258 | case WPS_TOKEN_METADATA_GENRE: | ||
259 | return id3->genre_string; | ||
260 | |||
261 | case WPS_TOKEN_METADATA_DISC_NUMBER: | ||
262 | if (id3->disc_string) | ||
263 | return id3->disc_string; | ||
264 | if (id3->discnum) { | ||
265 | snprintf(buf, buf_size, "%d", id3->discnum); | ||
266 | return buf; | ||
267 | } | ||
268 | return NULL; | ||
269 | |||
270 | case WPS_TOKEN_METADATA_TRACK_NUMBER: | ||
271 | if (id3->track_string) | ||
272 | return id3->track_string; | ||
273 | |||
274 | if (id3->tracknum) { | ||
275 | snprintf(buf, buf_size, "%d", id3->tracknum); | ||
276 | return buf; | ||
277 | } | ||
278 | return NULL; | ||
279 | |||
280 | case WPS_TOKEN_METADATA_TRACK_TITLE: | ||
281 | return id3->title; | ||
282 | |||
283 | case WPS_TOKEN_METADATA_VERSION: | ||
284 | switch (id3->id3version) | ||
285 | { | ||
286 | case ID3_VER_1_0: | ||
287 | return "1"; | ||
288 | |||
289 | case ID3_VER_1_1: | ||
290 | return "1.1"; | ||
291 | |||
292 | case ID3_VER_2_2: | ||
293 | return "2.2"; | ||
294 | |||
295 | case ID3_VER_2_3: | ||
296 | return "2.3"; | ||
297 | |||
298 | case ID3_VER_2_4: | ||
299 | return "2.4"; | ||
300 | |||
301 | default: | ||
302 | return NULL; | ||
303 | } | ||
304 | |||
305 | case WPS_TOKEN_METADATA_YEAR: | ||
306 | if( id3->year_string ) | ||
307 | return id3->year_string; | ||
308 | |||
309 | if (id3->year) { | ||
310 | snprintf(buf, buf_size, "%d", id3->year); | ||
311 | return buf; | ||
312 | } | ||
313 | return NULL; | ||
314 | |||
315 | case WPS_TOKEN_METADATA_COMMENT: | ||
316 | return id3->comment; | ||
317 | |||
318 | #ifdef HAVE_ALBUMART | ||
319 | case WPS_TOKEN_ALBUMART_DISPLAY: | ||
320 | draw_album_art(gwps, audio_current_aa_hid(), false); | ||
321 | return NULL; | ||
322 | |||
323 | case WPS_TOKEN_ALBUMART_FOUND: | ||
324 | if (audio_current_aa_hid() >= 0) { | ||
325 | return "C"; | ||
326 | } | ||
327 | return NULL; | ||
328 | #endif | ||
329 | |||
330 | case WPS_TOKEN_FILE_BITRATE: | ||
331 | if(id3->bitrate) | ||
332 | snprintf(buf, buf_size, "%d", id3->bitrate); | ||
333 | else | ||
334 | return "?"; | ||
335 | return buf; | ||
336 | |||
337 | case WPS_TOKEN_FILE_CODEC: | ||
338 | if (intval) | ||
339 | { | ||
340 | if(id3->codectype == AFMT_UNKNOWN) | ||
341 | *intval = AFMT_NUM_CODECS; | ||
342 | else | ||
343 | *intval = id3->codectype; | ||
344 | } | ||
345 | return get_codectype(id3); | ||
346 | |||
347 | case WPS_TOKEN_FILE_FREQUENCY: | ||
348 | snprintf(buf, buf_size, "%ld", id3->frequency); | ||
349 | return buf; | ||
350 | |||
351 | case WPS_TOKEN_FILE_FREQUENCY_KHZ: | ||
352 | /* ignore remainders < 100, so 22050 Hz becomes just 22k */ | ||
353 | if ((id3->frequency % 1000) < 100) | ||
354 | snprintf(buf, buf_size, "%ld", id3->frequency / 1000); | ||
355 | else | ||
356 | snprintf(buf, buf_size, "%ld.%d", | ||
357 | id3->frequency / 1000, | ||
358 | (id3->frequency % 1000) / 100); | ||
359 | return buf; | ||
360 | |||
361 | case WPS_TOKEN_FILE_NAME: | ||
362 | if (get_dir(buf, buf_size, id3->path, 0)) { | ||
363 | /* Remove extension */ | ||
364 | char* sep = strrchr(buf, '.'); | ||
365 | if (NULL != sep) { | ||
366 | *sep = 0; | ||
367 | } | ||
368 | return buf; | ||
369 | } | ||
370 | else { | ||
371 | return NULL; | ||
372 | } | ||
373 | |||
374 | case WPS_TOKEN_FILE_NAME_WITH_EXTENSION: | ||
375 | return get_dir(buf, buf_size, id3->path, 0); | ||
376 | |||
377 | case WPS_TOKEN_FILE_PATH: | ||
378 | return id3->path; | ||
379 | |||
380 | case WPS_TOKEN_FILE_SIZE: | ||
381 | snprintf(buf, buf_size, "%ld", id3->filesize / 1024); | ||
382 | return buf; | ||
383 | |||
384 | case WPS_TOKEN_FILE_VBR: | ||
385 | return id3->vbr ? "(avg)" : NULL; | ||
386 | |||
387 | case WPS_TOKEN_FILE_DIRECTORY: | ||
388 | return get_dir(buf, buf_size, id3->path, token->value.i); | ||
389 | |||
390 | case WPS_TOKEN_BATTERY_PERCENT: | ||
391 | { | ||
392 | int l = battery_level(); | ||
393 | |||
394 | if (intval) | ||
395 | { | ||
396 | limit = MAX(limit, 2); | ||
397 | if (l > -1) { | ||
398 | /* First enum is used for "unknown level". */ | ||
399 | *intval = (limit - 1) * l / 100 + 2; | ||
400 | } else { | ||
401 | *intval = 1; | ||
402 | } | ||
403 | } | ||
404 | |||
405 | if (l > -1) { | ||
406 | snprintf(buf, buf_size, "%d", l); | ||
407 | return buf; | ||
408 | } else { | ||
409 | return "?"; | ||
410 | } | ||
411 | } | ||
412 | |||
413 | case WPS_TOKEN_BATTERY_VOLTS: | ||
414 | { | ||
415 | unsigned int v = battery_voltage(); | ||
416 | snprintf(buf, buf_size, "%d.%02d", v / 1000, (v % 1000) / 10); | ||
417 | return buf; | ||
418 | } | ||
419 | |||
420 | case WPS_TOKEN_BATTERY_TIME: | ||
421 | { | ||
422 | int t = battery_time(); | ||
423 | if (t >= 0) | ||
424 | snprintf(buf, buf_size, "%dh %dm", t / 60, t % 60); | ||
425 | else | ||
426 | return "?h ?m"; | ||
427 | return buf; | ||
428 | } | ||
429 | |||
430 | #if CONFIG_CHARGING | ||
431 | case WPS_TOKEN_BATTERY_CHARGER_CONNECTED: | ||
432 | { | ||
433 | if(charger_input_state==CHARGER) | ||
434 | return "p"; | ||
435 | else | ||
436 | return NULL; | ||
437 | } | ||
438 | #endif | ||
439 | #if CONFIG_CHARGING >= CHARGING_MONITOR | ||
440 | case WPS_TOKEN_BATTERY_CHARGING: | ||
441 | { | ||
442 | if (charge_state == CHARGING || charge_state == TOPOFF) { | ||
443 | return "c"; | ||
444 | } else { | ||
445 | return NULL; | ||
446 | } | ||
447 | } | ||
448 | #endif | ||
449 | case WPS_TOKEN_BATTERY_SLEEPTIME: | ||
450 | { | ||
451 | if (get_sleep_timer() == 0) | ||
452 | return NULL; | ||
453 | else | ||
454 | { | ||
455 | format_time(buf, buf_size, get_sleep_timer() * 1000); | ||
456 | return buf; | ||
457 | } | ||
458 | } | ||
459 | |||
460 | case WPS_TOKEN_PLAYBACK_STATUS: | ||
461 | { | ||
462 | int status = audio_status(); | ||
463 | int mode = 1; | ||
464 | if (status == AUDIO_STATUS_PLAY) | ||
465 | mode = 2; | ||
466 | if (is_wps_fading() || | ||
467 | (status & AUDIO_STATUS_PAUSE && !status_get_ffmode())) | ||
468 | mode = 3; | ||
469 | if (status_get_ffmode() == STATUS_FASTFORWARD) | ||
470 | mode = 4; | ||
471 | if (status_get_ffmode() == STATUS_FASTBACKWARD) | ||
472 | mode = 5; | ||
473 | |||
474 | if (intval) { | ||
475 | *intval = mode; | ||
476 | } | ||
477 | |||
478 | snprintf(buf, buf_size, "%d", mode-1); | ||
479 | return buf; | ||
480 | } | ||
481 | |||
482 | case WPS_TOKEN_REPEAT_MODE: | ||
483 | if (intval) | ||
484 | *intval = global_settings.repeat_mode + 1; | ||
485 | snprintf(buf, buf_size, "%d", global_settings.repeat_mode); | ||
486 | return buf; | ||
487 | |||
488 | case WPS_TOKEN_RTC_PRESENT: | ||
489 | #if CONFIG_RTC | ||
490 | return "c"; | ||
491 | #else | ||
492 | return NULL; | ||
493 | #endif | ||
494 | |||
495 | #if CONFIG_RTC | ||
496 | case WPS_TOKEN_RTC_12HOUR_CFG: | ||
497 | if (intval) | ||
498 | *intval = global_settings.timeformat + 1; | ||
499 | snprintf(buf, buf_size, "%d", global_settings.timeformat); | ||
500 | return buf; | ||
501 | |||
502 | case WPS_TOKEN_RTC_DAY_OF_MONTH: | ||
503 | /* d: day of month (01..31) */ | ||
504 | snprintf(buf, buf_size, "%02d", tm->tm_mday); | ||
505 | return buf; | ||
506 | |||
507 | case WPS_TOKEN_RTC_DAY_OF_MONTH_BLANK_PADDED: | ||
508 | /* e: day of month, blank padded ( 1..31) */ | ||
509 | snprintf(buf, buf_size, "%2d", tm->tm_mday); | ||
510 | return buf; | ||
511 | |||
512 | case WPS_TOKEN_RTC_HOUR_24_ZERO_PADDED: | ||
513 | /* H: hour (00..23) */ | ||
514 | snprintf(buf, buf_size, "%02d", tm->tm_hour); | ||
515 | return buf; | ||
516 | |||
517 | case WPS_TOKEN_RTC_HOUR_24: | ||
518 | /* k: hour ( 0..23) */ | ||
519 | snprintf(buf, buf_size, "%2d", tm->tm_hour); | ||
520 | return buf; | ||
521 | |||
522 | case WPS_TOKEN_RTC_HOUR_12_ZERO_PADDED: | ||
523 | /* I: hour (01..12) */ | ||
524 | snprintf(buf, buf_size, "%02d", | ||
525 | (tm->tm_hour % 12 == 0) ? 12 : tm->tm_hour % 12); | ||
526 | return buf; | ||
527 | |||
528 | case WPS_TOKEN_RTC_HOUR_12: | ||
529 | /* l: hour ( 1..12) */ | ||
530 | snprintf(buf, buf_size, "%2d", | ||
531 | (tm->tm_hour % 12 == 0) ? 12 : tm->tm_hour % 12); | ||
532 | return buf; | ||
533 | |||
534 | case WPS_TOKEN_RTC_MONTH: | ||
535 | /* m: month (01..12) */ | ||
536 | if (intval) | ||
537 | *intval = tm->tm_mon + 1; | ||
538 | snprintf(buf, buf_size, "%02d", tm->tm_mon + 1); | ||
539 | return buf; | ||
540 | |||
541 | case WPS_TOKEN_RTC_MINUTE: | ||
542 | /* M: minute (00..59) */ | ||
543 | snprintf(buf, buf_size, "%02d", tm->tm_min); | ||
544 | return buf; | ||
545 | |||
546 | case WPS_TOKEN_RTC_SECOND: | ||
547 | /* S: second (00..59) */ | ||
548 | snprintf(buf, buf_size, "%02d", tm->tm_sec); | ||
549 | return buf; | ||
550 | |||
551 | case WPS_TOKEN_RTC_YEAR_2_DIGITS: | ||
552 | /* y: last two digits of year (00..99) */ | ||
553 | snprintf(buf, buf_size, "%02d", tm->tm_year % 100); | ||
554 | return buf; | ||
555 | |||
556 | case WPS_TOKEN_RTC_YEAR_4_DIGITS: | ||
557 | /* Y: year (1970...) */ | ||
558 | snprintf(buf, buf_size, "%04d", tm->tm_year + 1900); | ||
559 | return buf; | ||
560 | |||
561 | case WPS_TOKEN_RTC_AM_PM_UPPER: | ||
562 | /* p: upper case AM or PM indicator */ | ||
563 | return tm->tm_hour/12 == 0 ? "AM" : "PM"; | ||
564 | |||
565 | case WPS_TOKEN_RTC_AM_PM_LOWER: | ||
566 | /* P: lower case am or pm indicator */ | ||
567 | return tm->tm_hour/12 == 0 ? "am" : "pm"; | ||
568 | |||
569 | case WPS_TOKEN_RTC_WEEKDAY_NAME: | ||
570 | /* a: abbreviated weekday name (Sun..Sat) */ | ||
571 | return str(LANG_WEEKDAY_SUNDAY + tm->tm_wday); | ||
572 | |||
573 | case WPS_TOKEN_RTC_MONTH_NAME: | ||
574 | /* b: abbreviated month name (Jan..Dec) */ | ||
575 | return str(LANG_MONTH_JANUARY + tm->tm_mon); | ||
576 | |||
577 | case WPS_TOKEN_RTC_DAY_OF_WEEK_START_MON: | ||
578 | /* u: day of week (1..7); 1 is Monday */ | ||
579 | if (intval) | ||
580 | *intval = (tm->tm_wday == 0) ? 7 : tm->tm_wday; | ||
581 | snprintf(buf, buf_size, "%1d", tm->tm_wday + 1); | ||
582 | return buf; | ||
583 | |||
584 | case WPS_TOKEN_RTC_DAY_OF_WEEK_START_SUN: | ||
585 | /* w: day of week (0..6); 0 is Sunday */ | ||
586 | if (intval) | ||
587 | *intval = tm->tm_wday + 1; | ||
588 | snprintf(buf, buf_size, "%1d", tm->tm_wday); | ||
589 | return buf; | ||
590 | #else | ||
591 | case WPS_TOKEN_RTC_DAY_OF_MONTH: | ||
592 | case WPS_TOKEN_RTC_DAY_OF_MONTH_BLANK_PADDED: | ||
593 | case WPS_TOKEN_RTC_HOUR_24_ZERO_PADDED: | ||
594 | case WPS_TOKEN_RTC_HOUR_24: | ||
595 | case WPS_TOKEN_RTC_HOUR_12_ZERO_PADDED: | ||
596 | case WPS_TOKEN_RTC_HOUR_12: | ||
597 | case WPS_TOKEN_RTC_MONTH: | ||
598 | case WPS_TOKEN_RTC_MINUTE: | ||
599 | case WPS_TOKEN_RTC_SECOND: | ||
600 | case WPS_TOKEN_RTC_AM_PM_UPPER: | ||
601 | case WPS_TOKEN_RTC_AM_PM_LOWER: | ||
602 | case WPS_TOKEN_RTC_YEAR_2_DIGITS: | ||
603 | return "--"; | ||
604 | case WPS_TOKEN_RTC_YEAR_4_DIGITS: | ||
605 | return "----"; | ||
606 | case WPS_TOKEN_RTC_WEEKDAY_NAME: | ||
607 | case WPS_TOKEN_RTC_MONTH_NAME: | ||
608 | return "---"; | ||
609 | case WPS_TOKEN_RTC_DAY_OF_WEEK_START_MON: | ||
610 | case WPS_TOKEN_RTC_DAY_OF_WEEK_START_SUN: | ||
611 | return "-"; | ||
612 | #endif | ||
613 | |||
614 | #ifdef HAVE_LCD_CHARCELLS | ||
615 | case WPS_TOKEN_PROGRESSBAR: | ||
616 | { | ||
617 | char *end = utf8encode(data->wps_progress_pat[0], buf); | ||
618 | *end = '\0'; | ||
619 | return buf; | ||
620 | } | ||
621 | |||
622 | case WPS_TOKEN_PLAYER_PROGRESSBAR: | ||
623 | if(is_new_player()) | ||
624 | { | ||
625 | /* we need 11 characters (full line) for | ||
626 | progress-bar */ | ||
627 | strlcpy(buf, " ", buf_size); | ||
628 | } | ||
629 | else | ||
630 | { | ||
631 | /* Tell the user if we have an OldPlayer */ | ||
632 | strlcpy(buf, " <Old LCD> ", buf_size); | ||
633 | } | ||
634 | return buf; | ||
635 | #endif | ||
636 | |||
637 | #ifdef HAVE_TAGCACHE | ||
638 | case WPS_TOKEN_DATABASE_PLAYCOUNT: | ||
639 | if (intval) { | ||
640 | *intval = id3->playcount + 1; | ||
641 | } | ||
642 | snprintf(buf, buf_size, "%ld", id3->playcount); | ||
643 | return buf; | ||
644 | |||
645 | case WPS_TOKEN_DATABASE_RATING: | ||
646 | if (intval) { | ||
647 | *intval = id3->rating + 1; | ||
648 | } | ||
649 | snprintf(buf, buf_size, "%d", id3->rating); | ||
650 | return buf; | ||
651 | |||
652 | case WPS_TOKEN_DATABASE_AUTOSCORE: | ||
653 | if (intval) | ||
654 | *intval = id3->score + 1; | ||
655 | |||
656 | snprintf(buf, buf_size, "%d", id3->score); | ||
657 | return buf; | ||
658 | #endif | ||
659 | |||
660 | #if (CONFIG_CODEC == SWCODEC) | ||
661 | case WPS_TOKEN_CROSSFADE: | ||
662 | if (intval) | ||
663 | *intval = global_settings.crossfade + 1; | ||
664 | snprintf(buf, buf_size, "%d", global_settings.crossfade); | ||
665 | return buf; | ||
666 | |||
667 | case WPS_TOKEN_REPLAYGAIN: | ||
668 | { | ||
669 | int val; | ||
670 | |||
671 | if (global_settings.replaygain_type == REPLAYGAIN_OFF) | ||
672 | val = 1; /* off */ | ||
673 | else | ||
674 | { | ||
675 | int type = | ||
676 | get_replaygain_mode(id3->track_gain_string != NULL, | ||
677 | id3->album_gain_string != NULL); | ||
678 | if (type < 0) | ||
679 | val = 6; /* no tag */ | ||
680 | else | ||
681 | val = type + 2; | ||
682 | |||
683 | if (global_settings.replaygain_type == REPLAYGAIN_SHUFFLE) | ||
684 | val += 2; | ||
685 | } | ||
686 | |||
687 | if (intval) | ||
688 | *intval = val; | ||
689 | |||
690 | switch (val) | ||
691 | { | ||
692 | case 1: | ||
693 | case 6: | ||
694 | return "+0.00 dB"; | ||
695 | break; | ||
696 | case 2: | ||
697 | case 4: | ||
698 | strlcpy(buf, id3->track_gain_string, buf_size); | ||
699 | break; | ||
700 | case 3: | ||
701 | case 5: | ||
702 | strlcpy(buf, id3->album_gain_string, buf_size); | ||
703 | break; | ||
704 | } | ||
705 | return buf; | ||
706 | } | ||
707 | #endif /* (CONFIG_CODEC == SWCODEC) */ | ||
708 | |||
709 | #if (CONFIG_CODEC != MAS3507D) | ||
710 | case WPS_TOKEN_SOUND_PITCH: | ||
711 | { | ||
712 | int val = sound_get_pitch(); | ||
713 | snprintf(buf, buf_size, "%d.%d", | ||
714 | val / 10, val % 10); | ||
715 | return buf; | ||
716 | } | ||
717 | #endif | ||
718 | |||
719 | case WPS_TOKEN_MAIN_HOLD: | ||
720 | #ifdef HAS_BUTTON_HOLD | ||
721 | if (button_hold()) | ||
722 | #else | ||
723 | if (is_keys_locked()) | ||
724 | #endif /*hold switch or softlock*/ | ||
725 | return "h"; | ||
726 | else | ||
727 | return NULL; | ||
728 | |||
729 | #ifdef HAS_REMOTE_BUTTON_HOLD | ||
730 | case WPS_TOKEN_REMOTE_HOLD: | ||
731 | if (remote_button_hold()) | ||
732 | return "r"; | ||
733 | else | ||
734 | return NULL; | ||
735 | #endif | ||
736 | |||
737 | #if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD) | ||
738 | case WPS_TOKEN_VLED_HDD: | ||
739 | if(led_read(HZ/2)) | ||
740 | return "h"; | ||
741 | else | ||
742 | return NULL; | ||
743 | #endif | ||
744 | case WPS_TOKEN_BUTTON_VOLUME: | ||
745 | if (data->button_time_volume && | ||
746 | TIME_BEFORE(current_tick, data->button_time_volume + | ||
747 | token->value.i * TIMEOUT_UNIT)) | ||
748 | return "v"; | ||
749 | return NULL; | ||
750 | case WPS_TOKEN_LASTTOUCH: | ||
751 | #ifdef HAVE_TOUCHSCREEN | ||
752 | if (TIME_BEFORE(current_tick, token->value.i * TIMEOUT_UNIT + | ||
753 | touchscreen_last_touch())) | ||
754 | return "t"; | ||
755 | #endif | ||
756 | return NULL; | ||
757 | |||
758 | case WPS_TOKEN_SETTING: | ||
759 | { | ||
760 | if (intval) | ||
761 | { | ||
762 | /* Handle contionals */ | ||
763 | const struct settings_list *s = settings+token->value.i; | ||
764 | switch (s->flags&F_T_MASK) | ||
765 | { | ||
766 | case F_T_INT: | ||
767 | case F_T_UINT: | ||
768 | if (s->flags&F_RGB) | ||
769 | /* %?St|name|<#000000|#000001|...|#FFFFFF> */ | ||
770 | /* shouldn't overflow since colors are stored | ||
771 | * on 16 bits ... | ||
772 | * but this is pretty useless anyway */ | ||
773 | *intval = *(int*)s->setting + 1; | ||
774 | else if (s->cfg_vals == NULL) | ||
775 | /* %?St|name|<1st choice|2nd choice|...> */ | ||
776 | *intval = (*(int*)s->setting-s->int_setting->min) | ||
777 | /s->int_setting->step + 1; | ||
778 | else | ||
779 | /* %?St|name|<1st choice|2nd choice|...> */ | ||
780 | /* Not sure about this one. cfg_name/vals are | ||
781 | * indexed from 0 right? */ | ||
782 | *intval = *(int*)s->setting + 1; | ||
783 | break; | ||
784 | case F_T_BOOL: | ||
785 | /* %?St|name|<if true|if false> */ | ||
786 | *intval = *(bool*)s->setting?1:2; | ||
787 | break; | ||
788 | case F_T_CHARPTR: | ||
789 | /* %?St|name|<if non empty string|if empty> | ||
790 | * The string's emptyness discards the setting's | ||
791 | * prefix and suffix */ | ||
792 | *intval = ((char*)s->setting)[0]?1:2; | ||
793 | break; | ||
794 | default: | ||
795 | /* This shouldn't happen ... but you never know */ | ||
796 | *intval = -1; | ||
797 | break; | ||
798 | } | ||
799 | } | ||
800 | cfg_to_string(token->value.i,buf,buf_size); | ||
801 | return buf; | ||
802 | } | ||
803 | |||
804 | default: | ||
805 | return NULL; | ||
806 | } | ||
807 | } | ||