From 9db35e515b92dc21e241d536f8a3798e609f97ba Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jonathan=20Neusch=C3=A4fer?= Date: Wed, 27 Jul 2011 20:58:18 +0200 Subject: [PATCH] screen_lyrics: optionally show the plugin used This feature is disabled by default, because I guess that most users won't want to use it. --- doc/ncmpc.1 | 3 +++ src/conf.c | 7 +++++++ src/options.c | 1 + src/options.h | 1 + src/screen_lyrics.c | 22 ++++++++++++++++------ 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/doc/ncmpc.1 b/doc/ncmpc.1 index fe97763..7ad0c61 100644 --- a/doc/ncmpc.1 +++ b/doc/ncmpc.1 @@ -127,6 +127,9 @@ When using the jump command, search for the prefix of an entry. That means typin .B lyrics\-autosave = yes|no Automatically save lyrics after receiving them. .TP +.B lyrics\-show\-plugin = yes|no +Show the name of the plugin used to receive lyrics on the lyrics screen. +.TP .B second-column = yes|no Display song length in a second column. .SS Display diff --git a/src/conf.c b/src/conf.c index a537663..6c93e1e 100644 --- a/src/conf.c +++ b/src/conf.c @@ -76,6 +76,7 @@ #define CONF_DISPLAY_TIME "display-time" #define CONF_JUMP_PREFIX_ONLY "jump-prefix-only" #define CONF_LYRICS_AUTOSAVE "lyrics-autosave" +#define CONF_LYRICS_SHOW_PLUGIN "lyrics-show-plugin" #define CONF_SECOND_COLUMN "second-column" static bool @@ -517,6 +518,12 @@ parse_line(char *line) options.lyrics_autosave = str2bool(value); #else {} +#endif + else if (!strcasecmp(CONF_LYRICS_SHOW_PLUGIN, name)) +#ifdef ENABLE_LYRICS_SCREEN + options.lyrics_show_plugin = str2bool(value); +#else + {} #endif else if (!strcasecmp(CONF_SECOND_COLUMN, name)) #ifdef NCMPC_MINI diff --git a/src/options.c b/src/options.c index 2f21dc0..398a068 100644 --- a/src/options.c +++ b/src/options.c @@ -54,6 +54,7 @@ options_t options = { #ifdef ENABLE_LYRICS_SCREEN .lyrics_timeout = DEFAULT_LYRICS_TIMEOUT, .lyrics_autosave = false, + .lyrics_show_plugin = false, #endif .find_wrap = true, .scroll_offset = 0, diff --git a/src/options.h b/src/options.h index 920605f..b9bb0ee 100644 --- a/src/options.h +++ b/src/options.h @@ -47,6 +47,7 @@ typedef struct { #ifdef ENABLE_LYRICS_SCREEN int lyrics_timeout; bool lyrics_autosave; + bool lyrics_show_plugin; #endif bool find_wrap; bool find_show_last_pattern; diff --git a/src/screen_lyrics.c b/src/screen_lyrics.c index 3dcddbf..ec723e9 100644 --- a/src/screen_lyrics.c +++ b/src/screen_lyrics.c @@ -45,7 +45,7 @@ static bool follow = false; static struct { struct mpd_song *song; - char *artist, *title; + char *artist, *title, *plugin_name; struct plugin_cycle *loader; } current; @@ -58,6 +58,11 @@ screen_lyrics_abort(void) current.loader = NULL; } + if (current.plugin_name != NULL) { + g_free(current.plugin_name); + current.plugin_name = NULL; + } + if (current.artist != NULL) { g_free(current.artist); current.artist = NULL; @@ -165,11 +170,12 @@ screen_lyrics_set(const GString *str) static void screen_lyrics_callback(const GString *result, const bool success, - G_GNUC_UNUSED const char *plugin_name, - G_GNUC_UNUSED void *data) + const char *plugin_name, G_GNUC_UNUSED void *data) { assert(current.loader != NULL); + current.plugin_name = g_strdup(plugin_name); + /* Display result, which may be lyrics or error messages */ if (result != NULL) screen_lyrics_set(result); @@ -270,9 +276,13 @@ lyrics_title(char *str, size_t size) return str; } else if (current.artist != NULL && current.title != NULL && !screen_text_is_empty(&text)) { - snprintf(str, size, "%s: %s - %s", - _("Lyrics"), - current.artist, current.title); + int n; + n = snprintf(str, size, "%s: %s - %s", + _("Lyrics"), + current.artist, current.title); + if (options.lyrics_show_plugin && current.plugin_name != NULL) + snprintf(str + n, size - n, " (%s)", + current.plugin_name); return str; } else return _("Lyrics"); -- 2.30.2