summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-01-02 21:35:47 +0100
committerJon Bergli Heier <snakebite@jvnv.net>2010-01-02 21:35:47 +0100
commit70cd5d5c344e9a0189880b125c744491d2c6bed4 (patch)
tree7ef37fb70ba8d4c557a37b74bc2d64fb8824cdd8
parentd8d700ec734c0d027517ab03553dc878616e13a5 (diff)
thumbnails: Check original file for modifications.
-rw-r--r--thumbnails.c33
1 files changed, 29 insertions, 4 deletions
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;
}