From 70cd5d5c344e9a0189880b125c744491d2c6bed4 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Sat, 2 Jan 2010 21:35:47 +0100 Subject: thumbnails: Check original file for modifications. --- thumbnails.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'thumbnails.c') diff --git a/thumbnails.c b/thumbnails.c index 19cc817..83e6ec4 100644 --- a/thumbnails.c +++ b/thumbnails.c @@ -31,6 +31,26 @@ inline static time_t get_mtime(const gchar *filepath) { } } +inline static gboolean is_thumb_modified(GdkPixbuf *pb, const gchar *filename, const gchar *thumbname) { + time_t mtime, pb_mtime, thumb_mtime; + const gchar *mtime_s; + + mtime = get_mtime(filename); + mtime_s = gdk_pixbuf_get_option(pb, "tEXt::Thumb::MTime"); + pb_mtime = g_ascii_strtoll(mtime_s, NULL, 10); + + /* Original file modified since thumbnail creation. */ + if(mtime != pb_mtime) + return TRUE; + + thumb_mtime = get_mtime(thumbname); + /* Original file newer than thumbnail. */ + if(mtime > thumb_mtime) + return TRUE; + + return FALSE; +} + GdkPixbuf *get_thumbnail(const gchar *filepath) { GdkPixbuf *pb, *pb2; gint win_width, win_height, img_width, img_height, width, height; @@ -42,15 +62,20 @@ GdkPixbuf *get_thumbnail(const gchar *filepath) { if(g_access(thumbname, F_OK) == 0) { pb = gdk_pixbuf_new_from_file(thumbname, &error); - g_free(thumbname); - return pb; - } else { - pb = gdk_pixbuf_new_from_file(filepath, &error); + if(pb && !is_thumb_modified(pb, filepath, thumbname)) { + g_free(thumbname); + return pb; + } else if(pb) { + g_object_unref(pb); + } } + pb = gdk_pixbuf_new_from_file(filepath, &error); + if(!pb) { g_warning("%s", error->message); g_free(error); + g_free(thumbname); return NULL; } -- cgit v1.2.3