gui: Clean up setting album art

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-06-30 10:19:33 -04:00
parent dd66b10dfa
commit ecc7843ea5
1 changed files with 24 additions and 25 deletions

View File

@ -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;
}