gui/artwork: Reduce time spent polling for artwork

Since MusicBrainz limits us to one request each second, it doesn't
really make sense to poll for new artwork every half second.  Instead,
let's just put this into a new timeout function that gets called every
two seconds.  This should also let us stop polling once artwork has been
found.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2016-07-20 12:30:29 -04:00
parent 83724c5f6f
commit 7dff5412bc
3 changed files with 20 additions and 5 deletions

View File

@ -1,4 +1,5 @@
6.4.16:
- Reduce time spent polling for album art
- Split album art code into a new file
- Fix PKGBUILD dependencies

View File

@ -6,6 +6,7 @@
#include <glib/gi18n.h>
static struct album *__artwork_cur_album = NULL;
static unsigned int __artwork_timeo_id = 0;
static GdkPixbuf *__artwork_get_pixbuf(struct track *track)
{
@ -24,14 +25,14 @@ static GdkPixbuf *__artwork_get_pixbuf(struct track *track)
return pix;
}
void gui_artwork_set_cover(void)
static bool __artwork_set_pixbuf(void)
{
GtkImage *cover = GTK_IMAGE(gui_builder_widget("o_cover"));
struct track *track = audio_cur_track();
GdkPixbuf *pix;
if (!track || track->tr_album == __artwork_cur_album)
return;
return true;
pix = __artwork_get_pixbuf(track);
if (pix) {
@ -42,6 +43,22 @@ void gui_artwork_set_cover(void)
gtk_widget_set_sensitive(GTK_WIDGET(cover), pix != NULL);
__artwork_cur_album = pix ? track->tr_album : NULL;
return (pix != NULL);
}
static gboolean __artwork_timeout(gpointer data)
{
if (__artwork_set_pixbuf()) {
__artwork_timeo_id = 0;
return G_SOURCE_REMOVE;
}
return G_SOURCE_CONTINUE;
}
void gui_artwork_set_cover(void)
{
if (!__artwork_set_pixbuf() && __artwork_timeo_id == 0)
__artwork_timeo_id = g_timeout_add(2000, __artwork_timeout, NULL);
}
void __artwork_select_cover(GtkButton *button)

View File

@ -95,9 +95,6 @@ static int __audio_timeout(gpointer data)
gtk_adjustment_set_upper(progress, audio_duration() / GST_SECOND);
gtk_adjustment_set_value(progress, audio_position() / GST_SECOND);
__audio_set_time_label("o_position", audio_position() / GST_SECOND);
gui_artwork_set_cover();
return G_SOURCE_CONTINUE;
}