Code

screen_lyrics: optionally show the plugin used
authorJonathan Neuschäfer <j.neuschaefer@gmx.net>
Wed, 27 Jul 2011 18:58:18 +0000 (20:58 +0200)
committerJonathan Neuschäfer <j.neuschaefer@gmx.net>
Tue, 9 Aug 2011 20:24:05 +0000 (22:24 +0200)
This feature is disabled by default, because I guess that most users
won't want to use it.

doc/ncmpc.1
src/conf.c
src/options.c
src/options.h
src/screen_lyrics.c

index fe977638f8469db2cb4601245dfa4e790b85e5f6..7ad0c61dc8735d09c2485221db5ab62fdc7e4617 100644 (file)
@@ -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
index a537663d161c7d72e7c7d822a4e34b7a9f885440..6c93e1e3a8692c53b0e17c7d13d4f7a5d816d81b 100644 (file)
@@ -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
index 2f21dc0837a31085a25b00c9a68cee5403dd44e2..398a0688f11a0feca4135507be7f23b107dacb05 100644 (file)
@@ -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,
index 920605f5ededac606f42cda6077e122fbcd00a29..b9bb0eed3d0a768348371ea493fdb3998241b675 100644 (file)
@@ -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;
index 3dcddbfe5691a5cc07d0cac11d4cfbacee615445..ec723e9e2ee98e5820c9c6adaf3ccf907e5261d3 100644 (file)
@@ -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");