From e768fd4c2202cb5a4ac0a400f3d27b39b4ecf9c1 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 10 Oct 2009 16:36:10 +0200 Subject: [PATCH] strfsong: support multiple values for a tag Concatenate them with ", " in between. --- NEWS | 1 + src/strfsong.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) 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 -- 2.30.2