summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexey Yakovenko <waker@users.sourceforge.net>2014-07-05 21:49:56 +0200
committerGravatar Alexey Yakovenko <waker@users.sourceforge.net>2014-07-05 21:49:56 +0200
commit5ebe1b869b960078cbb26c0b90a848be9800ff18 (patch)
tree1b8090a483001d33985516bb87defc6503a7d333
parent3e56c4fa4b69e20afda0c162714549ee116e06cc (diff)
fixed artwork cache resetting in multiple places (bug #1143)
-rw-r--r--plugins/artwork/artwork.c4
-rw-r--r--plugins/gtkui/coverart.c40
-rw-r--r--plugins/gtkui/coverart.h3
-rw-r--r--plugins/gtkui/gtkui.c1
-rw-r--r--plugins/gtkui/widgets.c3
5 files changed, 44 insertions, 7 deletions
diff --git a/plugins/artwork/artwork.c b/plugins/artwork/artwork.c
index e69c61e4..32cd1b96 100644
--- a/plugins/artwork/artwork.c
+++ b/plugins/artwork/artwork.c
@@ -122,7 +122,7 @@ static time_t artwork_reset_time;
static char artwork_filemask[200];
static const char *get_default_cover (void) {
-return default_cover;
+ return default_cover;
}
static int
@@ -1387,7 +1387,7 @@ find_image (const char *path) {
// invalidate cache every 2 days
if ((cache_period > 0 && (tm - stat_buf.st_mtime > cache_period * 60 * 60))
|| artwork_reset_time > stat_buf.st_mtime) {
- trace ("reloading cached file %s\n", path);
+ trace ("deleting cached file %s\n", path);
unlink (path);
return NULL;
}
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;
+}
diff --git a/plugins/gtkui/coverart.h b/plugins/gtkui/coverart.h
index bacbfd92..47627fe7 100644
--- a/plugins/gtkui/coverart.h
+++ b/plugins/gtkui/coverart.h
@@ -51,5 +51,8 @@ cover_get_default_pixbuf (void);
int
gtkui_is_default_pixbuf (GdkPixbuf *pb);
+int
+gtkui_cover_message (uint32_t id, uintptr_t ctx, uint32_t p1, uint32_t p2);
+
#endif
diff --git a/plugins/gtkui/gtkui.c b/plugins/gtkui/gtkui.c
index 5e2cbd2f..a3cca159 100644
--- a/plugins/gtkui/gtkui.c
+++ b/plugins/gtkui/gtkui.c
@@ -772,6 +772,7 @@ gtkui_message (uint32_t id, uintptr_t ctx, uint32_t p1, uint32_t p2) {
if (rootwidget) {
send_messages_to_widgets (rootwidget, id, ctx, p1, p2);
}
+ gtkui_cover_message (id, ctx, p1, p2);
switch (id) {
case DB_EV_ACTIVATED:
g_idle_add (activate_cb, NULL);
diff --git a/plugins/gtkui/widgets.c b/plugins/gtkui/widgets.c
index 1bacb50e..51b37c28 100644
--- a/plugins/gtkui/widgets.c
+++ b/plugins/gtkui/widgets.c
@@ -2349,6 +2349,9 @@ static int
coverart_message (ddb_gtkui_widget_t *w, uint32_t id, uintptr_t ctx, uint32_t p1, uint32_t p2) {
w_coverart_t *ca = (w_coverart_t *)w;
switch (id) {
+ case DB_EV_PLAYLIST_REFRESH:
+ g_idle_add (coverart_redraw_cb, w);
+ break;
case DB_EV_SONGSTARTED:
g_idle_add (coverart_redraw_cb, w);
break;