From: Jonathan Neuschäfer Date: Sat, 20 Aug 2011 20:40:50 +0000 (+0200) Subject: implement the "lyrics-timeout" config option X-Git-Tag: release-0.20~101 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=3e9f42e1cc6f8158b66d111b9e2bdbd96c1b9321;p=ncmpc.git implement the "lyrics-timeout" config option --- diff --git a/doc/ncmpc.1 b/doc/ncmpc.1 index 7ad0c61..24c0007 100644 --- a/doc/ncmpc.1 +++ b/doc/ncmpc.1 @@ -119,7 +119,7 @@ Default crossfade time in seconds Seek forward/backward by NUM seconds. .TP .B lyrics\-timeout = NUM -Quits downloading lyrics of a song after the timeout of NUM seconds is reached. +Quits downloading lyrics of a song after the timeout of NUM seconds is reached, if NUM is greater than zero. .TP .B jump\-prefix\-only = yes|no When using the jump command, search for the prefix of an entry. That means typing "m" will start to the first entry which begins with "m". diff --git a/src/screen_lyrics.c b/src/screen_lyrics.c index ec723e9..0819f91 100644 --- a/src/screen_lyrics.c +++ b/src/screen_lyrics.c @@ -48,6 +48,8 @@ static struct { char *artist, *title, *plugin_name; struct plugin_cycle *loader; + + guint loader_timeout; } current; static void @@ -58,6 +60,11 @@ screen_lyrics_abort(void) current.loader = NULL; } + if (current.loader_timeout != 0) { + g_source_remove(current.loader_timeout); + current.loader_timeout = 0; + } + if (current.plugin_name != NULL) { g_free(current.plugin_name); current.plugin_name = NULL; @@ -189,8 +196,26 @@ screen_lyrics_callback(const GString *result, const bool success, screen_status_message (_("No lyrics")); } + if (current.loader_timeout != 0) { + g_source_remove(current.loader_timeout); + current.loader_timeout = 0; + } + + plugin_stop(current.loader); + current.loader = NULL; +} + +static gboolean +screen_lyrics_timeout_callback(gpointer G_GNUC_UNUSED data) +{ plugin_stop(current.loader); current.loader = NULL; + + screen_status_printf(_("Lyrics timeout occurred after %d seconds"), + options.lyrics_timeout); + + current.loader_timeout = 0; + return FALSE; } static void @@ -212,6 +237,13 @@ screen_lyrics_load(const struct mpd_song *song) current.loader = lyrics_load(current.artist, current.title, screen_lyrics_callback, NULL); + + if (options.lyrics_timeout != 0) { + current.loader_timeout = + g_timeout_add_seconds(options.lyrics_timeout, + screen_lyrics_timeout_callback, + NULL); + } } static void