From ecc7843ea5458c6d14b9688c0e7f302b5b3280c0 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Thu, 30 Jun 2016 10:19:33 -0400 Subject: [PATCH] gui: Clean up setting album art Signed-off-by: Anna Schumaker --- gui/audio.c | 49 ++++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/gui/audio.c b/gui/audio.c index 9f3fcbef..f2af9f23 100644 --- a/gui/audio.c +++ b/gui/audio.c @@ -28,31 +28,35 @@ static inline void __audio_set_time_label(const gchar *label, unsigned int time) g_free(str); } -static void __audio_set_cover(gchar *path) +static GdkPixbuf *__audio_get_pixbuf(struct track *track) { - GtkImage *image = GTK_IMAGE(gui_builder_widget("o_cover")); - int height = gui_builder_widget_height("o_tags") + - gui_builder_widget_height("o_position") - 1; - GdkPixbuf *pix = gdk_pixbuf_new_from_file_at_scale(path, -1, height, - true, NULL); + gchar *path = album_artwork_path(track->tr_album); + GdkPixbuf *pix; + int height; - gtk_image_set_from_pixbuf(image, pix); - gtk_widget_show(GTK_WIDGET(image)); - __audio_have_cover = true; + if (!path) + return NULL; + + height = gui_builder_widget_height("o_position") + + gui_builder_widget_height("o_tags"); + pix = gdk_pixbuf_new_from_file_at_scale(path, -1, height, true, NULL); + g_free(path); + + return pix; } static void __audio_get_cover(struct track *track) { - gchar *path = album_artwork_path(track->tr_album); + GtkImage *cover = GTK_IMAGE(gui_builder_widget("o_cover")); + GdkPixbuf *pix = __audio_get_pixbuf(track); - if (path) { - __audio_set_cover(path); - g_free(path); - } else { - gtk_widget_hide(gui_builder_widget("o_cover")); - gui_idle_enable(); - __audio_have_cover = false; - } + if (pix) { + gtk_image_set_from_pixbuf(cover, pix); + g_object_unref(G_OBJECT(pix)); + } else + gtk_image_set_from_icon_name(cover, NULL, GTK_ICON_SIZE_DIALOG); + + __audio_have_cover = (pix != NULL); } static void __audio_load(struct track *track) @@ -125,13 +129,8 @@ static int __audio_timeout(gpointer data) gtk_adjustment_set_value(progress, audio_position() / GST_SECOND); __audio_set_time_label("o_position", audio_position() / GST_SECOND); - if (track && !__audio_have_cover) { - gchar *path = album_artwork_path(track->tr_album); - if (path) { - __audio_set_cover(path); - g_free(path); - } - } + if (track && !__audio_have_cover) + __audio_get_cover(track); return G_SOURCE_CONTINUE; }