From 5ebe1b869b960078cbb26c0b90a848be9800ff18 Mon Sep 17 00:00:00 2001 From: Alexey Yakovenko Date: Sat, 5 Jul 2014 21:49:56 +0200 Subject: fixed artwork cache resetting in multiple places (bug #1143) --- plugins/gtkui/coverart.c | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) (limited to 'plugins/gtkui/coverart.c') diff --git a/plugins/gtkui/coverart.c b/plugins/gtkui/coverart.c index f7d78696..0ff63ceb 100644 --- a/plugins/gtkui/coverart.c +++ b/plugins/gtkui/coverart.c @@ -43,6 +43,7 @@ GdkPixbuf *pixbuf_default; typedef struct { struct timeval tm; + time_t file_time; char *fname; int width; GdkPixbuf *pixbuf; @@ -71,6 +72,8 @@ static uintptr_t tid; load_query_t *queue; load_query_t *tail; +static int64_t artwork_reset_time; + static void queue_add (const char *fname, int width, void (*callback) (void *user_data), void *user_data) { deadbeef->mutex_lock (mutex); @@ -175,11 +178,14 @@ loading_thread (void *none) { } GdkPixbuf *pixbuf = NULL; GError *error = NULL; - pixbuf = gdk_pixbuf_new_from_file_at_scale (queue->fname, queue->width, queue->width, TRUE, &error); - if (error) { - //fprintf (stderr, "gdk_pixbuf_new_from_file_at_scale %s %d failed, error: %s\n", queue->fname, queue->width, error ? error->message : "n/a"); - g_error_free (error); - error = NULL; + struct stat stat_buf; + if (!stat (queue->fname, &stat_buf)) { + pixbuf = gdk_pixbuf_new_from_file_at_scale (queue->fname, queue->width, queue->width, TRUE, &error); + if (error) { + //fprintf (stderr, "gdk_pixbuf_new_from_file_at_scale %s %d failed, error: %s\n", queue->fname, queue->width, error ? error->message : "n/a"); + g_error_free (error); + error = NULL; + } } if (!pixbuf) { pixbuf = pixbuf_default; @@ -189,6 +195,7 @@ loading_thread (void *none) { deadbeef->mutex_lock (mutex); cache[cache_min].pixbuf = pixbuf; cache[cache_min].fname = strdup (queue->fname); + cache[cache_min].file_time = stat_buf.st_mtime; gettimeofday (&cache[cache_min].tm, NULL); cache[cache_min].width = queue->width; deadbeef->mutex_unlock (mutex); @@ -406,3 +413,26 @@ int gtkui_is_default_pixbuf (GdkPixbuf *pb) { return pb == pixbuf_default; } + +int +gtkui_cover_message (uint32_t id, uintptr_t ctx, uint32_t p1, uint32_t p2) { + switch (id) { + case DB_EV_PLAYLIST_REFRESH: + { + int64_t reset_time = deadbeef->conf_get_int64 ("artwork.cache_reset_time", 0);; + if (reset_time != artwork_reset_time) { + artwork_reset_time = reset_time; + deadbeef->mutex_lock (mutex); + for (int i = 0; i < CACHE_SIZE; i++) { + if (cache[i].pixbuf) { + g_object_unref (cache[i].pixbuf); + } + } + memset (cache, 0, sizeof (cache)); + deadbeef->mutex_unlock (mutex); + } + } + break; + } + return 0; +} -- cgit v1.2.3