From fea4689e91139ed92f2acad3c3c30afcbf1c1794 Mon Sep 17 00:00:00 2001 From: Jonathan Gordon Date: Fri, 15 Jan 2010 07:20:56 +0000 Subject: Get rid of those horrible macros to protect against NULL reference when looking up the id3 info for tokens. Change the way the wps playlist viewer gets the token values. All %i tokens are now supported (and a few others, experiment :) ) git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24233 a1c6a512-1295-4272-9138-f99709370657 --- apps/gui/skin_engine/skin_display.c | 60 +++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 26 deletions(-) (limited to 'apps/gui/skin_engine/skin_display.c') diff --git a/apps/gui/skin_engine/skin_display.c b/apps/gui/skin_engine/skin_display.c index e63b078d37..e90ac4c4ce 100644 --- a/apps/gui/skin_engine/skin_display.c +++ b/apps/gui/skin_engine/skin_display.c @@ -169,17 +169,20 @@ bool audio_peek_track(struct mp3entry* id3, int offset); static void draw_playlist_viewer_list(struct gui_wps *gwps, struct playlistviewer *viewer) { + struct wps_state *state = gwps->state; int lines = viewport_get_nb_lines(viewer->vp); int line_height = font_get(viewer->vp->font)->height; int cur_playlist_pos = playlist_get_display_index(); int start_item = MAX(0, cur_playlist_pos + viewer->start_offset); int i; + struct wps_token token; struct mp3entry *pid3; #if CONFIG_CODEC == SWCODEC struct mp3entry id3; #endif char buf[MAX_PATH*2], tempbuf[MAX_PATH]; + unsigned int buf_used = 0; gwps->display->set_viewport(viewer->vp); @@ -187,11 +190,11 @@ static void draw_playlist_viewer_list(struct gui_wps *gwps, { if (i == cur_playlist_pos) { - pid3 = audio_current_track(); + pid3 = state->id3; } else if (i == cur_playlist_pos+1) { - pid3 = audio_next_track(); + pid3 = state->nid3; } #if CONFIG_CODEC == SWCODEC else if ((i>cur_playlist_pos) && audio_peek_track(&id3, i-cur_playlist_pos)) @@ -200,51 +203,56 @@ static void draw_playlist_viewer_list(struct gui_wps *gwps, } #endif else + { pid3 = NULL; + } int line = pid3 ? TRACK_HAS_INFO : TRACK_HAS_NO_INFO; - int token = 0, cur_string = 0; + int j = 0, cur_string = 0; char *filename = playlist_peek(i-cur_playlist_pos); buf[0] = '\0'; - while (token < viewer->lines[line].count) + buf_used = 0; + while (j < viewer->lines[line].count && (buf_usedlines[line].tokens[token]) + const char *out = NULL; + token.type = viewer->lines[line].tokens[j]; + token.value.i = 0; + token.next = false; + out = get_id3_token(&token, pid3, tempbuf, sizeof(tempbuf), -1, NULL); + if (out) + { + snprintf(&buf[buf_used], sizeof(buf)-buf_used, "%s", out); + buf_used += strlen(out); + j++; + continue; + } + switch (viewer->lines[line].tokens[j]) { case WPS_TOKEN_STRING: case WPS_TOKEN_CHARACTER: - strcat(buf, viewer->lines[line].strings[cur_string++]); + snprintf(tempbuf, sizeof(tempbuf), "%s", + viewer->lines[line].strings[cur_string]); + cur_string++; break; case WPS_TOKEN_PLAYLIST_POSITION: snprintf(tempbuf, sizeof(tempbuf), "%d", i); - strcat(buf, tempbuf); break; case WPS_TOKEN_FILE_NAME: get_dir(tempbuf, sizeof(tempbuf), filename, 0); - strcat(buf, tempbuf); break; case WPS_TOKEN_FILE_PATH: - strcat(buf, filename); - break; - case WPS_TOKEN_METADATA_ARTIST: - if (pid3) - strcat(buf, pid3->artist ? pid3->artist : ""); + snprintf(tempbuf, sizeof(tempbuf), "%s", filename); break; - case WPS_TOKEN_METADATA_TRACK_TITLE: - if (pid3) - strcat(buf, pid3->title ? pid3->title : ""); - break; - case WPS_TOKEN_TRACK_LENGTH: - if (pid3) - { - format_time(tempbuf, sizeof(tempbuf), pid3->length); - strcat(buf, tempbuf); - } - break; - default: + tempbuf[0] = '\0'; break; } - token++; + if (tempbuf[0]) + { + snprintf(&buf[buf_used], sizeof(buf)-buf_used, "%s", tempbuf); + buf_used += strlen(tempbuf); + } + j++; } if (viewer->lines[line].scroll) -- cgit v1.2.3