From: Max Kellermann Date: Sat, 10 Oct 2009 14:36:10 +0000 (+0200) Subject: strfsong: support multiple values for a tag X-Git-Tag: release-0.16~141 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=e768fd4c2202cb5a4ac0a400f3d27b39b4ecf9c1;p=ncmpc.git strfsong: support multiple values for a tag Concatenate them with ", " in between. --- diff --git a/NEWS b/NEWS index fc7be11..4ce914c 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,7 @@ ncmpc 0.16 - not yet released * list_window: fix narrow cursor drawing * screen_play: repaint after the "select-playing" command * screen_text: start searching at window origin, not bottom +* strfsong: support multiple values for a tag ncmpc 0.15 - 2009-09-24 diff --git a/src/strfsong.c b/src/strfsong.c index a146583..39e0c52 100644 --- a/src/strfsong.c +++ b/src/strfsong.c @@ -49,14 +49,62 @@ skip(const gchar * p) return p; } +#ifndef NCMPC_MINI + +static char * +concat_tag_values(const char *a, const char *b) +{ + return g_strconcat(a, ", ", b, NULL); +} + +static char * +song_more_tag_values(const struct mpd_song *song, enum mpd_tag_type tag, + const char *first) +{ + const char *p = mpd_song_get_tag(song, tag, 1); + char *buffer, *prev; + + if (p == NULL) + return NULL; + + buffer = concat_tag_values(first, p); + for (unsigned i = 2; (p = mpd_song_get_tag(song, tag, i)) != NULL; + ++i) { + prev = buffer; + buffer = concat_tag_values(buffer, p); + g_free(prev); + } + + return buffer; +} + +#endif /* !NCMPC_MINI */ + static char * song_tag_locale(const struct mpd_song *song, enum mpd_tag_type tag) { const char *value = mpd_song_get_tag(song, tag, 0); + char *result; +#ifndef NCMPC_MINI + char *all; +#endif /* !NCMPC_MINI */ + if (value == NULL) return NULL; - return utf8_to_locale(value); +#ifndef NCMPC_MINI + all = song_more_tag_values(song, tag, value); + if (all != NULL) + value = all; +#endif /* !NCMPC_MINI */ + + result = utf8_to_locale(value); + +#ifndef NCMPC_MINI + g_free(all); +#endif /* !NCMPC_MINI */ + + return result; } static gsize