4 * Copyright (C) 2008 The Geeqie Team
8 * This software is released under the GNU General Public License (GNU GPL).
9 * Please read the included file COPYING for more information.
10 * This software comes with no warranty of any kind, use at your own risk!
15 #include "thumb_standard.h"
17 #include "cache.h" /* for cache_ensure_dir_exists */
18 #include "image-load.h"
20 #include "pixbuf_util.h"
21 #include "ui_fileops.h"
25 * This thumbnail caching implementation attempts to conform
26 * to the Thumbnail Managing Standard proposed on freedesktop.org
27 * The standard is documented here:
28 * http://triq.net/~jens/thumbnail-spec/index.html
29 * (why isn't it actually hosted on freedesktop.org?)
31 * This code attempts to conform to version 0.7.0 of the standard.
34 * > Validation of the thumb's embedded uri is a simple strcmp between our
35 * version of the escaped uri and the thumb's escaped uri. But not all uri
36 * escape functions escape the same set of chars, comparing the unescaped
37 * versions may be more accurate.
38 * > Only Thumb::URI and Thumb::MTime are stored in a thumb at this time.
39 * Storing the Size, Width, Height should probably be implemented.
43 #define THUMB_SIZE_NORMAL 128
44 #define THUMB_SIZE_LARGE 256
46 #define THUMB_MARKER_URI "tEXt::Thumb::URI"
47 #define THUMB_MARKER_MTIME "tEXt::Thumb::MTime"
48 #define THUMB_MARKER_SIZE "tEXt::Thumb::Size"
49 #define THUMB_MARKER_WIDTH "tEXt::Thumb::Image::Width"
50 #define THUMB_MARKER_HEIGHT "tEXt::Thumb::Image::Height"
51 #define THUMB_MARKER_APP "tEXt::Software"
53 #define THUMB_PERMS_FOLDER 0700
54 #define THUMB_PERMS_THUMB 0600
59 *-----------------------------------------------------------------------------
61 *-----------------------------------------------------------------------------
65 static void thumb_loader_std_error_cb(ImageLoader *il, gpointer data);
66 static gint thumb_loader_std_setup(ThumbLoaderStd *tl, const gchar *path);
69 ThumbLoaderStd *thumb_loader_std_new(gint width, gint height)
73 tl = g_new0(ThumbLoaderStd, 1);
75 tl->standard_loader = TRUE;
77 tl->requested_width = width;
78 tl->requested_height = height;
82 tl->source_path = NULL;
84 tl->cache_enable = options->thumbnails.enable_caching;
85 tl->cache_local = FALSE;
86 tl->cache_retry = FALSE;
91 void thumb_loader_std_set_callbacks(ThumbLoaderStd *tl,
92 ThumbLoaderStdFunc func_done,
93 ThumbLoaderStdFunc func_error,
94 ThumbLoaderStdFunc func_progress,
99 tl->func_done = func_done;
100 tl->func_error = func_error;
101 tl->func_progress = func_progress;
105 static void thumb_loader_std_reset(ThumbLoaderStd *tl)
107 if (tl->pixbuf) g_object_unref(tl->pixbuf);
110 image_loader_free(tl->il);
113 g_free(tl->source_path);
114 tl->source_path = NULL;
116 g_free(tl->thumb_path);
117 tl->thumb_path = NULL;
119 g_free(tl->thumb_uri);
120 tl->thumb_uri = NULL;
121 tl->local_uri = NULL;
123 tl->thumb_path_local = FALSE;
125 tl->cache_hit = FALSE;
127 tl->source_mtime = 0;
134 static gchar *thumb_std_cache_path(const gchar *path, const gchar *uri, gint local,
135 const gchar *cache_subfolder)
137 gchar *result = NULL;
142 if (!path || !uri || !cache_subfolder) return NULL;
148 base = remove_level_from_path(path);
149 cache_base = g_strconcat(base, "/", THUMB_FOLDER_LOCAL, "/", cache_subfolder, NULL);
154 cache_base = g_strconcat(homedir(), "/", THUMB_FOLDER_GLOBAL, "/", cache_subfolder, NULL);
157 md5_get_digest((guchar *)uri, strlen(uri), digest);
158 md5_text = md5_digest_to_text(digest);
160 if (cache_base && md5_text)
162 result = g_strconcat(cache_base, "/", md5_text, THUMB_NAME_EXTENSION, NULL);
171 static gchar *thumb_loader_std_cache_path(ThumbLoaderStd *tl, gint local, GdkPixbuf *pixbuf, gint fail)
176 if (!tl->source_path || !tl->thumb_uri) return NULL;
180 w = gdk_pixbuf_get_width(pixbuf);
181 h = gdk_pixbuf_get_height(pixbuf);
185 w = tl->requested_width;
186 h = tl->requested_height;
191 folder = THUMB_FOLDER_FAIL;
193 else if (w > THUMB_SIZE_NORMAL || h > THUMB_SIZE_NORMAL)
195 folder = THUMB_FOLDER_LARGE;
199 folder = THUMB_FOLDER_NORMAL;
202 return thumb_std_cache_path(tl->source_path,
203 (local) ? tl->local_uri : tl->thumb_uri,
207 static gint thumb_loader_std_fail_check(ThumbLoaderStd *tl)
212 fail_path = thumb_loader_std_cache_path(tl, FALSE, NULL, TRUE);
213 if (isfile(fail_path))
225 pathl = path_from_utf8(fail_path);
226 pixbuf = gdk_pixbuf_new_from_file(pathl, NULL);
232 const gchar *mtime_str;
234 mtime_str = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_MTIME);
235 if (mtime_str && strtol(mtime_str, NULL, 10) == tl->source_mtime)
238 DEBUG_1("thumb fail valid: %s", tl->source_path);
239 DEBUG_1(" thumb: %s", fail_path);
242 g_object_unref(G_OBJECT(pixbuf));
245 if (!result) unlink_file(fail_path);
252 static gint thumb_loader_std_validate(ThumbLoaderStd *tl, GdkPixbuf *pixbuf)
254 const gchar *valid_uri;
256 const gchar *mtime_str;
260 if (!pixbuf) return FALSE;
262 w = gdk_pixbuf_get_width(pixbuf);
263 h = gdk_pixbuf_get_height(pixbuf);
265 if (w != THUMB_SIZE_NORMAL && w != THUMB_SIZE_LARGE &&
266 h != THUMB_SIZE_NORMAL && h != THUMB_SIZE_LARGE) return FALSE;
268 valid_uri = (tl->thumb_path_local) ? tl->local_uri : tl->thumb_uri;
270 uri = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_URI);
271 mtime_str = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_MTIME);
273 if (!mtime_str || !uri || !valid_uri) return FALSE;
274 if (strcmp(uri, valid_uri) != 0) return FALSE;
276 mtime = strtol(mtime_str, NULL, 10);
277 if (tl->source_mtime != mtime) return FALSE;
282 static void thumb_loader_std_save(ThumbLoaderStd *tl, GdkPixbuf *pixbuf)
288 if (!tl->cache_enable || tl->cache_hit) return;
289 if (tl->thumb_path) return;
293 /* local failures are not stored */
294 if (tl->cache_local) return;
296 pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 1, 1);
301 g_object_ref(G_OBJECT(pixbuf));
305 tl->thumb_path = thumb_loader_std_cache_path(tl, tl->cache_local, pixbuf, fail);
308 g_object_unref(G_OBJECT(pixbuf));
311 tl->thumb_path_local = tl->cache_local;
313 /* create thumbnail dir if needed */
314 base_path = remove_level_from_path(tl->thumb_path);
317 if (!isdir(base_path))
322 source_base = remove_level_from_path(tl->source_path);
323 if (stat_utf8(source_base, &st))
325 cache_ensure_dir_exists(base_path, st.st_mode);
332 cache_ensure_dir_exists(base_path, THUMB_PERMS_FOLDER);
336 DEBUG_1("thumb saving: %s", tl->source_path);
337 DEBUG_1(" saved: %s", tl->thumb_path);
339 /* save thumb, using a temp file then renaming into place */
340 tmp_path = unique_filename(tl->thumb_path, ".tmp", "_", 2);
343 const gchar *mark_uri;
349 mark_uri = (tl->cache_local) ? tl->local_uri :tl->thumb_uri;
351 mark_app = g_strdup_printf("%s %s", GQ_APPNAME, VERSION);
352 mark_mtime = g_strdup_printf("%lu", tl->source_mtime);
354 pathl = path_from_utf8(tmp_path);
355 success = gdk_pixbuf_save(pixbuf, pathl, "png", NULL,
356 THUMB_MARKER_URI, mark_uri,
357 THUMB_MARKER_MTIME, mark_mtime,
358 THUMB_MARKER_APP, mark_app,
362 chmod(pathl, (tl->cache_local) ? tl->source_mode : THUMB_PERMS_THUMB);
363 success = rename_file(tmp_path, tl->thumb_path);
374 DEBUG_1("thumb save failed: %s", tl->source_path);
375 DEBUG_1(" thumb: %s", tl->thumb_path);
380 g_object_unref(G_OBJECT(pixbuf));
383 static gint thumb_loader_std_scale_aspect(gint req_w, gint req_h, gint old_w, gint old_h,
384 gint *new_w, gint *new_h)
386 if (((gdouble)req_w / old_w) < ((gdouble)req_h / old_h))
389 *new_h = (gdouble)*new_w / old_w * old_h;
390 if (*new_h < 1) *new_h = 1;
395 *new_w = (gdouble)*new_h / old_h * old_w;
396 if (*new_w < 1) *new_w = 1;
399 return (*new_w != old_w || *new_h != old_h);
402 static GdkPixbuf *thumb_loader_std_finish(ThumbLoaderStd *tl, GdkPixbuf *pixbuf, gint shrunk)
404 GdkPixbuf *pixbuf_thumb = NULL;
408 sw = gdk_pixbuf_get_width(pixbuf);
409 sh = gdk_pixbuf_get_height(pixbuf);
411 if (tl->cache_enable)
415 gint cache_w, cache_h;
417 if (tl->requested_width > THUMB_SIZE_NORMAL || tl->requested_height > THUMB_SIZE_NORMAL)
419 cache_w = cache_h = THUMB_SIZE_LARGE;
423 cache_w = cache_h = THUMB_SIZE_NORMAL;
426 if (sw > cache_w || sh > cache_h || shrunk)
428 gint thumb_w, thumb_h;
430 if (thumb_loader_std_scale_aspect(cache_w, cache_h, sw, sh,
433 pixbuf_thumb = gdk_pixbuf_scale_simple(pixbuf, thumb_w, thumb_h,
434 (GdkInterpType)options->thumbnails.quality);
438 pixbuf_thumb = pixbuf;
439 g_object_ref(G_OBJECT(pixbuf_thumb));
442 thumb_loader_std_save(tl, pixbuf_thumb);
445 else if (tl->cache_hit &&
446 tl->cache_local && !tl->thumb_path_local)
448 /* A local cache save was requested, but a valid thumb is in $HOME,
449 * so specifically save as a local thumbnail.
451 g_free(tl->thumb_path);
452 tl->thumb_path = NULL;
454 tl->cache_hit = FALSE;
456 DEBUG_1("thumb copied: %s", tl->source_path);
458 thumb_loader_std_save(tl, pixbuf);
462 if (sw <= tl->requested_width && sh <= tl->requested_height)
465 g_object_ref(result);
469 gint thumb_w, thumb_h;
473 pixbuf = pixbuf_thumb;
474 sw = gdk_pixbuf_get_width(pixbuf);
475 sh = gdk_pixbuf_get_height(pixbuf);
478 if (thumb_loader_std_scale_aspect(tl->requested_width, tl->requested_height, sw, sh,
481 result = gdk_pixbuf_scale_simple(pixbuf, thumb_w, thumb_h,
482 (GdkInterpType)options->thumbnails.quality);
487 g_object_ref(result);
491 if (pixbuf_thumb) g_object_unref(pixbuf_thumb);
496 static gint thumb_loader_std_next_source(ThumbLoaderStd *tl, gint remove_broken)
498 image_loader_free(tl->il);
503 if (!tl->thumb_path_local && remove_broken)
505 DEBUG_1("thumb broken, unlinking: %s", tl->thumb_path);
506 unlink_file(tl->thumb_path);
509 g_free(tl->thumb_path);
510 tl->thumb_path = NULL;
512 if (!tl->thumb_path_local)
514 tl->thumb_path = thumb_loader_std_cache_path(tl, TRUE, NULL, FALSE);
515 if (isfile(tl->thumb_path) && thumb_loader_std_setup(tl, tl->thumb_path))
517 tl->thumb_path_local = TRUE;
521 g_free(tl->thumb_path);
522 tl->thumb_path = NULL;
525 if (thumb_loader_std_setup(tl, tl->source_path)) return TRUE;
528 thumb_loader_std_save(tl, NULL);
532 static void thumb_loader_std_done_cb(ImageLoader *il, gpointer data)
534 ThumbLoaderStd *tl = data;
537 DEBUG_1("thumb image done: %s", tl->source_path);
538 DEBUG_1(" from: %s", tl->il->path);
540 pixbuf = image_loader_get_pixbuf(tl->il);
543 DEBUG_1("...but no pixbuf");
544 thumb_loader_std_error_cb(il, data);
548 if (tl->thumb_path && !thumb_loader_std_validate(tl, pixbuf))
550 if (thumb_loader_std_next_source(tl, TRUE)) return;
552 if (tl->func_error) tl->func_error(tl, tl->data);
556 tl->cache_hit = (tl->thumb_path != NULL);
558 tl->pixbuf = thumb_loader_std_finish(tl, pixbuf, il->shrunk);
560 if (tl->func_done) tl->func_done(tl, tl->data);
563 static void thumb_loader_std_error_cb(ImageLoader *il, gpointer data)
565 ThumbLoaderStd *tl = data;
567 /* if at least some of the image is available, go to done */
568 if (image_loader_get_pixbuf(tl->il) != NULL)
570 thumb_loader_std_done_cb(il, data);
574 DEBUG_1("thumb image error: %s", tl->source_path);
575 DEBUG_1(" from: %s", tl->il->fd->path);
577 if (thumb_loader_std_next_source(tl, TRUE)) return;
579 if (tl->func_error) tl->func_error(tl, tl->data);
582 static void thumb_loader_std_progress_cb(ImageLoader *il, gdouble percent, gpointer data)
584 ThumbLoaderStd *tl = data;
586 tl->progress = (gdouble)percent;
588 if (tl->func_progress) tl->func_progress(tl, tl->data);
591 static gint thumb_loader_std_setup(ThumbLoaderStd *tl, const gchar *path)
593 tl->il = image_loader_new_from_path(path);
595 if (options->thumbnails.fast)
597 /* this will speed up jpegs by up to 3x in some cases */
598 if (tl->requested_width <= THUMB_SIZE_NORMAL &&
599 tl->requested_height <= THUMB_SIZE_NORMAL)
601 image_loader_set_requested_size(tl->il, THUMB_SIZE_NORMAL, THUMB_SIZE_NORMAL);
605 image_loader_set_requested_size(tl->il, THUMB_SIZE_LARGE, THUMB_SIZE_LARGE);
609 image_loader_set_error_func(tl->il, thumb_loader_std_error_cb, tl);
610 if (tl->func_progress)
612 image_loader_set_percent_func(tl->il, thumb_loader_std_progress_cb, tl);
615 if (image_loader_start(tl->il, thumb_loader_std_done_cb, tl))
620 image_loader_free(tl->il);
626 * Note: Currently local_cache only specifies where to save a _new_ thumb, if
627 * a valid existing thumb is found anywhere the local thumb will not be created.
629 void thumb_loader_std_set_cache(ThumbLoaderStd *tl, gint enable_cache, gint local, gint retry_failed)
633 tl->cache_enable = enable_cache;
634 tl->cache_local = local;
635 tl->cache_retry = retry_failed;
638 gint thumb_loader_std_start(ThumbLoaderStd *tl, const gchar *path)
640 static gchar *thumb_cache = NULL;
643 if (!tl || !path) return FALSE;
645 thumb_loader_std_reset(tl);
647 if (!stat_utf8(path, &st)) return FALSE;
649 tl->source_path = g_strdup(path);
650 tl->source_mtime = st.st_mtime;
651 tl->source_size = st.st_size;
652 tl->source_mode = st.st_mode;
654 if (!thumb_cache) thumb_cache = g_strconcat(homedir(), "/", THUMB_FOLDER_GLOBAL, NULL);
655 if (strncmp(tl->source_path, thumb_cache, strlen(thumb_cache)) != 0)
659 pathl = path_from_utf8(path);
660 tl->thumb_uri = g_filename_to_uri(pathl, NULL, NULL);
661 tl->local_uri = filename_from_path(tl->thumb_uri);
665 if (tl->cache_enable)
669 tl->thumb_path = thumb_loader_std_cache_path(tl, FALSE, NULL, FALSE);
670 tl->thumb_path_local = FALSE;
672 found = isfile(tl->thumb_path);
673 if (found && thumb_loader_std_setup(tl, tl->thumb_path)) return TRUE;
675 if (thumb_loader_std_fail_check(tl)) return FALSE;
677 return thumb_loader_std_next_source(tl, found);
680 if (!thumb_loader_std_setup(tl, tl->source_path))
682 thumb_loader_std_save(tl, NULL);
689 void thumb_loader_std_free(ThumbLoaderStd *tl)
693 thumb_loader_std_reset(tl);
697 GdkPixbuf *thumb_loader_std_get_pixbuf(ThumbLoaderStd *tl, gint with_fallback)
701 if (tl && tl->pixbuf)
704 g_object_ref(pixbuf);
706 else if (with_fallback)
710 pixbuf = pixbuf_inline(PIXBUF_INLINE_BROKEN);
711 w = gdk_pixbuf_get_width(pixbuf);
712 h = gdk_pixbuf_get_height(pixbuf);
714 if (w > tl->requested_width || h > tl->requested_height)
718 if (thumb_loader_std_scale_aspect(tl->requested_width, tl->requested_height,
724 pixbuf = gdk_pixbuf_scale_simple(tmp, nw, nh, GDK_INTERP_TILES);
725 g_object_unref(G_OBJECT(tmp));
738 typedef struct _ThumbValidate ThumbValidate;
739 struct _ThumbValidate
745 void (*func_valid)(const gchar *path, gint valid, gpointer data);
751 static void thumb_loader_std_thumb_file_validate_free(ThumbValidate *tv)
753 thumb_loader_std_free(tv->tl);
758 void thumb_loader_std_thumb_file_validate_cancel(ThumbLoaderStd *tl)
766 if (tv->idle_id != -1) g_source_remove(tv->idle_id);
769 thumb_loader_std_thumb_file_validate_free(tv);
772 static void thumb_loader_std_thumb_file_validate_finish(ThumbValidate *tv, gint valid)
774 if (tv->func_valid) tv->func_valid(tv->path, valid, tv->data);
776 thumb_loader_std_thumb_file_validate_free(tv);
779 static void thumb_loader_std_thumb_file_validate_done_cb(ThumbLoaderStd *tl, gpointer data)
781 ThumbValidate *tv = data;
785 pixbuf = thumb_loader_std_get_pixbuf(tv->tl, FALSE);
789 const gchar *mtime_str;
791 uri = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_URI);
792 mtime_str = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_MTIME);
793 if (uri && mtime_str)
795 if (strncmp(uri, "file:", strlen("file:")) == 0)
800 target = g_filename_from_uri(uri, NULL, NULL);
801 if (stat(target, &st) == 0 &&
802 st.st_mtime == strtol(mtime_str, NULL, 10))
812 DEBUG_1("thumb uri foreign, doing day check: %s", uri);
814 if (stat_utf8(tv->path, &st))
819 if (st.st_atime >= now - (time_t)tv->days * 24 * 60 * 60)
827 g_object_unref(pixbuf);
830 thumb_loader_std_thumb_file_validate_finish(tv, valid);
833 static void thumb_loader_std_thumb_file_validate_error_cb(ThumbLoaderStd *tl, gpointer data)
835 ThumbValidate *tv = data;
837 thumb_loader_std_thumb_file_validate_finish(tv, FALSE);
840 static gint thumb_loader_std_thumb_file_validate_idle_cb(gpointer data)
842 ThumbValidate *tv = data;
845 thumb_loader_std_thumb_file_validate_finish(tv, FALSE);
850 ThumbLoaderStd *thumb_loader_std_thumb_file_validate(const gchar *thumb_path, gint allowed_days,
851 void (*func_valid)(const gchar *path, gint valid, gpointer data),
856 tv = g_new0(ThumbValidate, 1);
858 tv->tl = thumb_loader_std_new(THUMB_SIZE_LARGE, THUMB_SIZE_LARGE);
859 thumb_loader_std_set_callbacks(tv->tl,
860 thumb_loader_std_thumb_file_validate_done_cb,
861 thumb_loader_std_thumb_file_validate_error_cb,
864 thumb_loader_std_reset(tv->tl);
866 tv->path = g_strdup(thumb_path);
867 tv->days = allowed_days;
868 tv->func_valid = func_valid;
871 if (!thumb_loader_std_setup(tv->tl, thumb_path))
873 tv->idle_id = g_idle_add(thumb_loader_std_thumb_file_validate_idle_cb, tv);
883 static void thumb_std_maint_remove_one(const gchar *source, const gchar *uri, gint local,
884 const gchar *subfolder)
888 thumb_path = thumb_std_cache_path(source,
889 (local) ? filename_from_path(uri) : uri,
891 if (isfile(thumb_path))
893 DEBUG_1("thumb removing: %s", thumb_path);
894 unlink_file(thumb_path);
899 /* this also removes local thumbnails (the source is gone so it makes sense) */
900 void thumb_std_maint_removed(const gchar *source)
905 sourcel = path_from_utf8(source);
906 uri = g_filename_to_uri(sourcel, NULL, NULL);
909 /* all this to remove a thumbnail? */
911 thumb_std_maint_remove_one(source, uri, FALSE, THUMB_FOLDER_NORMAL);
912 thumb_std_maint_remove_one(source, uri, FALSE, THUMB_FOLDER_LARGE);
913 thumb_std_maint_remove_one(source, uri, FALSE, THUMB_FOLDER_FAIL);
914 thumb_std_maint_remove_one(source, uri, TRUE, THUMB_FOLDER_NORMAL);
915 thumb_std_maint_remove_one(source, uri, TRUE, THUMB_FOLDER_LARGE);
920 typedef struct _TMaintMove TMaintMove;
933 static GList *thumb_std_maint_move_list = NULL;
934 static GList *thumb_std_maint_move_tail = NULL;
937 static void thumb_std_maint_move_step(TMaintMove *tm);
938 static gint thumb_std_maint_move_idle(gpointer data);
941 static void thumb_std_maint_move_validate_cb(const gchar *path, gint valid, gpointer data)
943 TMaintMove *tm = data;
946 pixbuf = thumb_loader_std_get_pixbuf(tm->tl, FALSE);
950 const gchar *mtime_str;
952 uri = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_URI);
953 mtime_str = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_MTIME);
955 if (uri && mtime_str && strcmp(uri, tm->source_uri) == 0)
959 /* The validation utility abuses ThumbLoader, and we
960 * abuse the utility just to load the thumbnail,
961 * but the loader needs to look sane for the save to complete.
964 tm->tl->cache_enable = TRUE;
965 tm->tl->cache_hit = FALSE;
966 tm->tl->cache_local = FALSE;
968 g_free(tm->tl->source_path);
969 tm->tl->source_path = g_strdup(tm->dest);
970 tm->tl->source_mtime = strtol(mtime_str, NULL, 10);
972 pathl = path_from_utf8(tm->tl->source_path);
973 g_free(tm->tl->thumb_uri);
974 tm->tl->thumb_uri = g_filename_to_uri(pathl, NULL, NULL);
975 tm->tl->local_uri = filename_from_path(tm->tl->thumb_uri);
978 g_free(tm->tl->thumb_path);
979 tm->tl->thumb_path = NULL;
980 tm->tl->thumb_path_local = FALSE;
982 DEBUG_1("thumb move attempting save:");
984 thumb_loader_std_save(tm->tl, pixbuf);
987 DEBUG_1("thumb move unlink: %s", tm->thumb_path);
988 unlink_file(tm->thumb_path);
991 thumb_std_maint_move_step(tm);
994 static void thumb_std_maint_move_step(TMaintMove *tm)
1003 g_free(tm->source_uri);
1004 g_free(tm->thumb_path);
1007 if (thumb_std_maint_move_list)
1009 g_idle_add_full(G_PRIORITY_LOW, thumb_std_maint_move_idle, NULL, NULL);
1015 folder = (tm->pass == 1) ? THUMB_FOLDER_NORMAL : THUMB_FOLDER_LARGE;
1017 g_free(tm->thumb_path);
1018 tm->thumb_path = thumb_std_cache_path(tm->source, tm->source_uri, FALSE, folder);
1019 tm->tl = thumb_loader_std_thumb_file_validate(tm->thumb_path, 0,
1020 thumb_std_maint_move_validate_cb, tm);
1023 static gint thumb_std_maint_move_idle(gpointer data)
1028 if (!thumb_std_maint_move_list) return FALSE;
1030 tm = thumb_std_maint_move_list->data;
1032 thumb_std_maint_move_list = g_list_remove(thumb_std_maint_move_list, tm);
1033 if (!thumb_std_maint_move_list) thumb_std_maint_move_tail = NULL;
1035 pathl = path_from_utf8(tm->source);
1036 tm->source_uri = g_filename_to_uri(pathl, NULL, NULL);
1041 thumb_std_maint_move_step(tm);
1046 /* This will schedule a move of the thumbnail for source image to dest when idle.
1047 * We do this so that file renaming or moving speed is not sacrificed by
1048 * moving the thumbnails at the same time because:
1050 * This cache design requires the tedious task of loading the png thumbnails and saving them.
1052 * The thumbnails are processed when the app is idle. If the app
1053 * exits early well too bad - they can simply be regenerated from scratch.
1055 * This does not manage local thumbnails (fixme ?)
1057 void thumb_std_maint_moved(const gchar *source, const gchar *dest)
1061 tm = g_new0(TMaintMove, 1);
1062 tm->source = g_strdup(source);
1063 tm->dest = g_strdup(dest);
1065 if (!thumb_std_maint_move_list)
1067 g_idle_add_full(G_PRIORITY_LOW, thumb_std_maint_move_idle, NULL, NULL);
1070 thumb_std_maint_move_tail = g_list_append(thumb_std_maint_move_tail, tm);
1071 if (!thumb_std_maint_move_list)
1072 thumb_std_maint_move_list = thumb_std_maint_move_tail;
1073 thumb_std_maint_move_tail = thumb_std_maint_move_tail->next;