diff options
Diffstat (limited to 'apps/gui/skin_engine/skin_tokens.c')
-rw-r--r-- | apps/gui/skin_engine/skin_tokens.c | 114 |
1 files changed, 82 insertions, 32 deletions
diff --git a/apps/gui/skin_engine/skin_tokens.c b/apps/gui/skin_engine/skin_tokens.c index ebe9ac50b1..8218358769 100644 --- a/apps/gui/skin_engine/skin_tokens.c +++ b/apps/gui/skin_engine/skin_tokens.c | |||
@@ -53,6 +53,7 @@ | |||
53 | #include "tdspeed.h" | 53 | #include "tdspeed.h" |
54 | #endif | 54 | #endif |
55 | #include "viewport.h" | 55 | #include "viewport.h" |
56 | #include "tagcache.h" | ||
56 | 57 | ||
57 | #include "wps_internals.h" | 58 | #include "wps_internals.h" |
58 | #include "root_menu.h" | 59 | #include "root_menu.h" |
@@ -192,9 +193,39 @@ const char *get_cuesheetid3_token(struct wps_token *token, struct mp3entry *id3, | |||
192 | return NULL; | 193 | return NULL; |
193 | } | 194 | } |
194 | 195 | ||
196 | const char* get_filename_token(struct wps_token *token, char* filename, | ||
197 | char *buf, int buf_size) | ||
198 | { | ||
199 | if (filename) | ||
200 | { | ||
201 | switch (token->type) | ||
202 | { | ||
203 | case SKIN_TOKEN_FILE_PATH: | ||
204 | return filename; | ||
205 | case SKIN_TOKEN_FILE_NAME: | ||
206 | if (get_dir(buf, buf_size, filename, 0)) { | ||
207 | /* Remove extension */ | ||
208 | char* sep = strrchr(buf, '.'); | ||
209 | if (NULL != sep) { | ||
210 | *sep = 0; | ||
211 | } | ||
212 | return buf; | ||
213 | } | ||
214 | return NULL; | ||
215 | case SKIN_TOKEN_FILE_NAME_WITH_EXTENSION: | ||
216 | return get_dir(buf, buf_size, filename, 0); | ||
217 | case SKIN_TOKEN_FILE_DIRECTORY: | ||
218 | return get_dir(buf, buf_size, filename, token->value.i); | ||
219 | default: | ||
220 | return NULL; | ||
221 | } | ||
222 | } | ||
223 | return NULL; | ||
224 | } | ||
225 | |||
195 | /* All tokens which only need the info to return a value go in here */ | 226 | /* All tokens which only need the info to return a value go in here */ |
196 | const char *get_id3_token(struct wps_token *token, struct mp3entry *id3, | 227 | const char *get_id3_token(struct wps_token *token, struct mp3entry *id3, |
197 | char *buf, int buf_size, int limit, int *intval) | 228 | char *filename, char *buf, int buf_size, int limit, int *intval) |
198 | { | 229 | { |
199 | struct wps_state *state = &wps_state; | 230 | struct wps_state *state = &wps_state; |
200 | if (id3) | 231 | if (id3) |
@@ -260,8 +291,6 @@ const char *get_id3_token(struct wps_token *token, struct mp3entry *id3, | |||
260 | return NULL; | 291 | return NULL; |
261 | case SKIN_TOKEN_METADATA_COMMENT: | 292 | case SKIN_TOKEN_METADATA_COMMENT: |
262 | return id3->comment; | 293 | return id3->comment; |
263 | case SKIN_TOKEN_FILE_PATH: | ||
264 | return id3->path; | ||
265 | case SKIN_TOKEN_FILE_BITRATE: | 294 | case SKIN_TOKEN_FILE_BITRATE: |
266 | if(id3->bitrate) | 295 | if(id3->bitrate) |
267 | snprintf(buf, buf_size, "%d", id3->bitrate); | 296 | snprintf(buf, buf_size, "%d", id3->bitrate); |
@@ -328,25 +357,11 @@ const char *get_id3_token(struct wps_token *token, struct mp3entry *id3, | |||
328 | id3->frequency / 1000, | 357 | id3->frequency / 1000, |
329 | (id3->frequency % 1000) / 100); | 358 | (id3->frequency % 1000) / 100); |
330 | return buf; | 359 | return buf; |
331 | case SKIN_TOKEN_FILE_NAME: | 360 | case SKIN_TOKEN_FILE_VBR: |
332 | if (get_dir(buf, buf_size, id3->path, 0)) { | 361 | return (id3->vbr) ? "(avg)" : NULL; |
333 | /* Remove extension */ | ||
334 | char* sep = strrchr(buf, '.'); | ||
335 | if (NULL != sep) { | ||
336 | *sep = 0; | ||
337 | } | ||
338 | return buf; | ||
339 | } | ||
340 | return NULL; | ||
341 | case SKIN_TOKEN_FILE_NAME_WITH_EXTENSION: | ||
342 | return get_dir(buf, buf_size, id3->path, 0); | ||
343 | case SKIN_TOKEN_FILE_SIZE: | 362 | case SKIN_TOKEN_FILE_SIZE: |
344 | snprintf(buf, buf_size, "%ld", id3->filesize / 1024); | 363 | snprintf(buf, buf_size, "%ld", id3->filesize / 1024); |
345 | return buf; | 364 | return buf; |
346 | case SKIN_TOKEN_FILE_VBR: | ||
347 | return (id3->vbr) ? "(avg)" : NULL; | ||
348 | case SKIN_TOKEN_FILE_DIRECTORY: | ||
349 | return get_dir(buf, buf_size, id3->path, token->value.i); | ||
350 | 365 | ||
351 | #ifdef HAVE_TAGCACHE | 366 | #ifdef HAVE_TAGCACHE |
352 | case SKIN_TOKEN_DATABASE_PLAYCOUNT: | 367 | case SKIN_TOKEN_DATABASE_PLAYCOUNT: |
@@ -367,7 +382,7 @@ const char *get_id3_token(struct wps_token *token, struct mp3entry *id3, | |||
367 | #endif | 382 | #endif |
368 | 383 | ||
369 | default: | 384 | default: |
370 | return NULL; | 385 | return get_filename_token(token, id3->path, buf, buf_size); |
371 | } | 386 | } |
372 | } | 387 | } |
373 | else /* id3 == NULL, handle the error based on the expected return type */ | 388 | else /* id3 == NULL, handle the error based on the expected return type */ |
@@ -388,7 +403,7 @@ const char *get_id3_token(struct wps_token *token, struct mp3entry *id3, | |||
388 | *intval = 0; | 403 | *intval = 0; |
389 | return "0"; | 404 | return "0"; |
390 | default: | 405 | default: |
391 | return NULL; | 406 | return get_filename_token(token, filename, buf, buf_size); |
392 | } | 407 | } |
393 | } | 408 | } |
394 | return buf; | 409 | return buf; |
@@ -498,6 +513,41 @@ const char *get_radio_token(struct wps_token *token, int preset_offset, | |||
498 | } | 513 | } |
499 | #endif | 514 | #endif |
500 | 515 | ||
516 | static struct mp3entry* get_mp3entry_from_offset(struct gui_wps *gwps, | ||
517 | int offset, char **filename) | ||
518 | { | ||
519 | struct mp3entry* pid3 = NULL; | ||
520 | struct cuesheet *cue = gwps->state->id3 ? gwps->state->id3->cuesheet:NULL; | ||
521 | const char *fname = NULL; | ||
522 | if (cue && cue->curr_track_idx + offset < cue->track_count) | ||
523 | pid3 = gwps->state->id3; | ||
524 | else if (offset == 0) | ||
525 | pid3 = gwps->state->id3; | ||
526 | else if (offset == 1) | ||
527 | pid3 = gwps->state->nid3; | ||
528 | else | ||
529 | { | ||
530 | static struct mp3entry tempid3; | ||
531 | static char filename_buf[MAX_PATH + 1]; | ||
532 | fname = playlist_peek(offset, filename_buf, sizeof(filename_buf)); | ||
533 | *filename = (char*)fname; | ||
534 | #if CONFIG_CODEC == SWCODEC | ||
535 | #ifdef HAVE_TC_RAMCACHE | ||
536 | if (tagcache_fill_tags(&tempid3, fname)) | ||
537 | { | ||
538 | pid3 = &tempid3; | ||
539 | } | ||
540 | else | ||
541 | #endif | ||
542 | { | ||
543 | if (!audio_peek_track(&pid3, offset)) | ||
544 | pid3 = NULL; | ||
545 | } | ||
546 | #endif | ||
547 | } | ||
548 | return pid3; | ||
549 | } | ||
550 | |||
501 | /* Return the tags value as text. buf should be used as temp storage if needed. | 551 | /* Return the tags value as text. buf should be used as temp storage if needed. |
502 | 552 | ||
503 | intval is used with conditionals/enums: when this function is called, | 553 | intval is used with conditionals/enums: when this function is called, |
@@ -508,7 +558,7 @@ const char *get_radio_token(struct wps_token *token, int preset_offset, | |||
508 | When not treating a conditional/enum, intval should be NULL. | 558 | When not treating a conditional/enum, intval should be NULL. |
509 | */ | 559 | */ |
510 | const char *get_token_value(struct gui_wps *gwps, | 560 | const char *get_token_value(struct gui_wps *gwps, |
511 | struct wps_token *token, | 561 | struct wps_token *token, int offset, |
512 | char *buf, int buf_size, | 562 | char *buf, int buf_size, |
513 | int *intval) | 563 | int *intval) |
514 | { | 564 | { |
@@ -520,15 +570,14 @@ const char *get_token_value(struct gui_wps *gwps, | |||
520 | struct mp3entry *id3; /* Think very carefully about using this. | 570 | struct mp3entry *id3; /* Think very carefully about using this. |
521 | maybe get_id3_token() is the better place? */ | 571 | maybe get_id3_token() is the better place? */ |
522 | const char *out_text = NULL; | 572 | const char *out_text = NULL; |
573 | char *filename = NULL; | ||
523 | 574 | ||
524 | if (!data || !state) | 575 | if (!data || !state) |
525 | return NULL; | 576 | return NULL; |
526 | 577 | ||
527 | 578 | id3 = get_mp3entry_from_offset(gwps, token->next? 1: offset, &filename); | |
528 | if (token->next) | 579 | if (id3) |
529 | id3 = state->nid3; | 580 | filename = id3->path; |
530 | else | ||
531 | id3 = state->id3; | ||
532 | 581 | ||
533 | #if CONFIG_RTC | 582 | #if CONFIG_RTC |
534 | struct tm* tm = NULL; | 583 | struct tm* tm = NULL; |
@@ -552,17 +601,18 @@ const char *get_token_value(struct gui_wps *gwps, | |||
552 | *intval = -1; | 601 | *intval = -1; |
553 | } | 602 | } |
554 | 603 | ||
555 | if (state->id3 && state->id3->cuesheet) | 604 | if (id3 && id3 == state->id3 && id3->cuesheet ) |
556 | { | 605 | { |
557 | out_text = get_cuesheetid3_token(token, state->id3, token->next?1:0, buf, buf_size); | 606 | out_text = get_cuesheetid3_token(token, id3, |
607 | token->next?1:offset, buf, buf_size); | ||
558 | if (out_text) | 608 | if (out_text) |
559 | return out_text; | 609 | return out_text; |
560 | } | 610 | } |
561 | out_text = get_id3_token(token, id3, buf, buf_size, limit, intval); | 611 | out_text = get_id3_token(token, id3, filename, buf, buf_size, limit, intval); |
562 | if (out_text) | 612 | if (out_text) |
563 | return out_text; | 613 | return out_text; |
564 | #if CONFIG_TUNER | 614 | #if CONFIG_TUNER |
565 | out_text = get_radio_token(token, 0, buf, buf_size, limit, intval); | 615 | out_text = get_radio_token(token, offset, buf, buf_size, limit, intval); |
566 | if (out_text) | 616 | if (out_text) |
567 | return out_text; | 617 | return out_text; |
568 | #endif | 618 | #endif |
@@ -596,7 +646,7 @@ const char *get_token_value(struct gui_wps *gwps, | |||
596 | return playlist_name(NULL, buf, buf_size); | 646 | return playlist_name(NULL, buf, buf_size); |
597 | 647 | ||
598 | case SKIN_TOKEN_PLAYLIST_POSITION: | 648 | case SKIN_TOKEN_PLAYLIST_POSITION: |
599 | snprintf(buf, buf_size, "%d", playlist_get_display_index()); | 649 | snprintf(buf, buf_size, "%d", playlist_get_display_index()+offset); |
600 | return buf; | 650 | return buf; |
601 | 651 | ||
602 | case SKIN_TOKEN_PLAYLIST_SHUFFLE: | 652 | case SKIN_TOKEN_PLAYLIST_SHUFFLE: |