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;
144 md5_get_digest((guchar *)uri, strlen(uri), digest);
145 md5_text = md5_digest_to_text(digest);
147 if (!md5_text) return NULL;
149 name = g_strconcat(md5_text, THUMB_NAME_EXTENSION, NULL);
153 gchar *base = remove_level_from_path(path);
155 result = g_build_filename(base, THUMB_FOLDER_LOCAL, cache_subfolder, name, NULL);
160 result = g_build_filename(homedir(), THUMB_FOLDER_GLOBAL, cache_subfolder, name, NULL);
169 static gchar *thumb_loader_std_cache_path(ThumbLoaderStd *tl, gint local, GdkPixbuf *pixbuf, gint fail)
174 if (!tl->source_path || !tl->thumb_uri) return NULL;
178 w = gdk_pixbuf_get_width(pixbuf);
179 h = gdk_pixbuf_get_height(pixbuf);
183 w = tl->requested_width;
184 h = tl->requested_height;
189 folder = THUMB_FOLDER_FAIL;
191 else if (w > THUMB_SIZE_NORMAL || h > THUMB_SIZE_NORMAL)
193 folder = THUMB_FOLDER_LARGE;
197 folder = THUMB_FOLDER_NORMAL;
200 return thumb_std_cache_path(tl->source_path,
201 (local) ? tl->local_uri : tl->thumb_uri,
205 static gint thumb_loader_std_fail_check(ThumbLoaderStd *tl)
210 fail_path = thumb_loader_std_cache_path(tl, FALSE, NULL, TRUE);
211 if (isfile(fail_path))
223 pathl = path_from_utf8(fail_path);
224 pixbuf = gdk_pixbuf_new_from_file(pathl, NULL);
230 const gchar *mtime_str;
232 mtime_str = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_MTIME);
233 if (mtime_str && strtol(mtime_str, NULL, 10) == tl->source_mtime)
236 DEBUG_1("thumb fail valid: %s", tl->source_path);
237 DEBUG_1(" thumb: %s", fail_path);
240 g_object_unref(G_OBJECT(pixbuf));
243 if (!result) unlink_file(fail_path);
250 static gint thumb_loader_std_validate(ThumbLoaderStd *tl, GdkPixbuf *pixbuf)
252 const gchar *valid_uri;
254 const gchar *mtime_str;
258 if (!pixbuf) return FALSE;
260 w = gdk_pixbuf_get_width(pixbuf);
261 h = gdk_pixbuf_get_height(pixbuf);
263 if (w != THUMB_SIZE_NORMAL && w != THUMB_SIZE_LARGE &&
264 h != THUMB_SIZE_NORMAL && h != THUMB_SIZE_LARGE) return FALSE;
266 valid_uri = (tl->thumb_path_local) ? tl->local_uri : tl->thumb_uri;
268 uri = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_URI);
269 mtime_str = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_MTIME);
271 if (!mtime_str || !uri || !valid_uri) return FALSE;
272 if (strcmp(uri, valid_uri) != 0) return FALSE;
274 mtime = strtol(mtime_str, NULL, 10);
275 if (tl->source_mtime != mtime) return FALSE;
280 static void thumb_loader_std_save(ThumbLoaderStd *tl, GdkPixbuf *pixbuf)
286 if (!tl->cache_enable || tl->cache_hit) return;
287 if (tl->thumb_path) return;
291 /* local failures are not stored */
292 if (tl->cache_local) return;
294 pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 1, 1);
299 g_object_ref(G_OBJECT(pixbuf));
303 tl->thumb_path = thumb_loader_std_cache_path(tl, tl->cache_local, pixbuf, fail);
306 g_object_unref(G_OBJECT(pixbuf));
309 tl->thumb_path_local = tl->cache_local;
311 /* create thumbnail dir if needed */
312 base_path = remove_level_from_path(tl->thumb_path);
315 if (!isdir(base_path))
320 source_base = remove_level_from_path(tl->source_path);
321 if (stat_utf8(source_base, &st))
323 cache_ensure_dir_exists(base_path, st.st_mode);
330 cache_ensure_dir_exists(base_path, THUMB_PERMS_FOLDER);
334 DEBUG_1("thumb saving: %s", tl->source_path);
335 DEBUG_1(" saved: %s", tl->thumb_path);
337 /* save thumb, using a temp file then renaming into place */
338 tmp_path = unique_filename(tl->thumb_path, ".tmp", "_", 2);
341 const gchar *mark_uri;
347 mark_uri = (tl->cache_local) ? tl->local_uri :tl->thumb_uri;
349 mark_app = g_strdup_printf("%s %s", GQ_APPNAME, VERSION);
350 mark_mtime = g_strdup_printf("%lu", tl->source_mtime);
352 pathl = path_from_utf8(tmp_path);
353 success = gdk_pixbuf_save(pixbuf, pathl, "png", NULL,
354 THUMB_MARKER_URI, mark_uri,
355 THUMB_MARKER_MTIME, mark_mtime,
356 THUMB_MARKER_APP, mark_app,
360 chmod(pathl, (tl->cache_local) ? tl->source_mode : THUMB_PERMS_THUMB);
361 success = rename_file(tmp_path, tl->thumb_path);
372 DEBUG_1("thumb save failed: %s", tl->source_path);
373 DEBUG_1(" thumb: %s", tl->thumb_path);
378 g_object_unref(G_OBJECT(pixbuf));
381 static gint thumb_loader_std_scale_aspect(gint req_w, gint req_h, gint old_w, gint old_h,
382 gint *new_w, gint *new_h)
384 if (((gdouble)req_w / old_w) < ((gdouble)req_h / old_h))
387 *new_h = (gdouble)*new_w / old_w * old_h;
388 if (*new_h < 1) *new_h = 1;
393 *new_w = (gdouble)*new_h / old_h * old_w;
394 if (*new_w < 1) *new_w = 1;
397 return (*new_w != old_w || *new_h != old_h);
400 static GdkPixbuf *thumb_loader_std_finish(ThumbLoaderStd *tl, GdkPixbuf *pixbuf, gint shrunk)
402 GdkPixbuf *pixbuf_thumb = NULL;
406 sw = gdk_pixbuf_get_width(pixbuf);
407 sh = gdk_pixbuf_get_height(pixbuf);
409 if (tl->cache_enable)
413 gint cache_w, cache_h;
415 if (tl->requested_width > THUMB_SIZE_NORMAL || tl->requested_height > THUMB_SIZE_NORMAL)
417 cache_w = cache_h = THUMB_SIZE_LARGE;
421 cache_w = cache_h = THUMB_SIZE_NORMAL;
424 if (sw > cache_w || sh > cache_h || shrunk)
426 gint thumb_w, thumb_h;
428 if (thumb_loader_std_scale_aspect(cache_w, cache_h, sw, sh,
431 pixbuf_thumb = gdk_pixbuf_scale_simple(pixbuf, thumb_w, thumb_h,
432 (GdkInterpType)options->thumbnails.quality);
436 pixbuf_thumb = pixbuf;
437 g_object_ref(G_OBJECT(pixbuf_thumb));
440 thumb_loader_std_save(tl, pixbuf_thumb);
443 else if (tl->cache_hit &&
444 tl->cache_local && !tl->thumb_path_local)
446 /* A local cache save was requested, but a valid thumb is in $HOME,
447 * so specifically save as a local thumbnail.
449 g_free(tl->thumb_path);
450 tl->thumb_path = NULL;
452 tl->cache_hit = FALSE;
454 DEBUG_1("thumb copied: %s", tl->source_path);
456 thumb_loader_std_save(tl, pixbuf);
460 if (sw <= tl->requested_width && sh <= tl->requested_height)
463 g_object_ref(result);
467 gint thumb_w, thumb_h;
471 pixbuf = pixbuf_thumb;
472 sw = gdk_pixbuf_get_width(pixbuf);
473 sh = gdk_pixbuf_get_height(pixbuf);
476 if (thumb_loader_std_scale_aspect(tl->requested_width, tl->requested_height, sw, sh,
479 result = gdk_pixbuf_scale_simple(pixbuf, thumb_w, thumb_h,
480 (GdkInterpType)options->thumbnails.quality);
485 g_object_ref(result);
489 if (pixbuf_thumb) g_object_unref(pixbuf_thumb);
494 static gint thumb_loader_std_next_source(ThumbLoaderStd *tl, gint remove_broken)
496 image_loader_free(tl->il);
501 if (!tl->thumb_path_local && remove_broken)
503 DEBUG_1("thumb broken, unlinking: %s", tl->thumb_path);
504 unlink_file(tl->thumb_path);
507 g_free(tl->thumb_path);
508 tl->thumb_path = NULL;
510 if (!tl->thumb_path_local)
512 tl->thumb_path = thumb_loader_std_cache_path(tl, TRUE, NULL, FALSE);
513 if (isfile(tl->thumb_path) && thumb_loader_std_setup(tl, tl->thumb_path))
515 tl->thumb_path_local = TRUE;
519 g_free(tl->thumb_path);
520 tl->thumb_path = NULL;
523 if (thumb_loader_std_setup(tl, tl->source_path)) return TRUE;
526 thumb_loader_std_save(tl, NULL);
530 static void thumb_loader_std_done_cb(ImageLoader *il, gpointer data)
532 ThumbLoaderStd *tl = data;
535 DEBUG_1("thumb image done: %s", tl->source_path);
536 DEBUG_1(" from: %s", tl->il->path);
538 pixbuf = image_loader_get_pixbuf(tl->il);
541 DEBUG_1("...but no pixbuf");
542 thumb_loader_std_error_cb(il, data);
546 if (tl->thumb_path && !thumb_loader_std_validate(tl, pixbuf))
548 if (thumb_loader_std_next_source(tl, TRUE)) return;
550 if (tl->func_error) tl->func_error(tl, tl->data);
554 tl->cache_hit = (tl->thumb_path != NULL);
556 tl->pixbuf = thumb_loader_std_finish(tl, pixbuf, il->shrunk);
558 if (tl->func_done) tl->func_done(tl, tl->data);
561 static void thumb_loader_std_error_cb(ImageLoader *il, gpointer data)
563 ThumbLoaderStd *tl = data;
565 /* if at least some of the image is available, go to done */
566 if (image_loader_get_pixbuf(tl->il) != NULL)
568 thumb_loader_std_done_cb(il, data);
572 DEBUG_1("thumb image error: %s", tl->source_path);
573 DEBUG_1(" from: %s", tl->il->fd->path);
575 if (thumb_loader_std_next_source(tl, TRUE)) return;
577 if (tl->func_error) tl->func_error(tl, tl->data);
580 static void thumb_loader_std_progress_cb(ImageLoader *il, gdouble percent, gpointer data)
582 ThumbLoaderStd *tl = data;
584 tl->progress = (gdouble)percent;
586 if (tl->func_progress) tl->func_progress(tl, tl->data);
589 static gint thumb_loader_std_setup(ThumbLoaderStd *tl, const gchar *path)
591 tl->il = image_loader_new_from_path(path);
593 if (options->thumbnails.fast)
595 /* this will speed up jpegs by up to 3x in some cases */
596 if (tl->requested_width <= THUMB_SIZE_NORMAL &&
597 tl->requested_height <= THUMB_SIZE_NORMAL)
599 image_loader_set_requested_size(tl->il, THUMB_SIZE_NORMAL, THUMB_SIZE_NORMAL);
603 image_loader_set_requested_size(tl->il, THUMB_SIZE_LARGE, THUMB_SIZE_LARGE);
607 image_loader_set_error_func(tl->il, thumb_loader_std_error_cb, tl);
608 if (tl->func_progress)
610 image_loader_set_percent_func(tl->il, thumb_loader_std_progress_cb, tl);
613 if (image_loader_start(tl->il, thumb_loader_std_done_cb, tl))
618 image_loader_free(tl->il);
624 * Note: Currently local_cache only specifies where to save a _new_ thumb, if
625 * a valid existing thumb is found anywhere the local thumb will not be created.
627 void thumb_loader_std_set_cache(ThumbLoaderStd *tl, gint enable_cache, gint local, gint retry_failed)
631 tl->cache_enable = enable_cache;
632 tl->cache_local = local;
633 tl->cache_retry = retry_failed;
636 gint thumb_loader_std_start(ThumbLoaderStd *tl, const gchar *path)
638 static gchar *thumb_cache = NULL;
641 if (!tl || !path) return FALSE;
643 thumb_loader_std_reset(tl);
645 if (!stat_utf8(path, &st)) return FALSE;
647 tl->source_path = g_strdup(path);
648 tl->source_mtime = st.st_mtime;
649 tl->source_size = st.st_size;
650 tl->source_mode = st.st_mode;
652 if (!thumb_cache) thumb_cache = g_build_filename(homedir(), THUMB_FOLDER_GLOBAL, NULL);
653 if (strncmp(tl->source_path, thumb_cache, strlen(thumb_cache)) != 0)
657 pathl = path_from_utf8(path);
658 tl->thumb_uri = g_filename_to_uri(pathl, NULL, NULL);
659 tl->local_uri = filename_from_path(tl->thumb_uri);
663 if (tl->cache_enable)
667 tl->thumb_path = thumb_loader_std_cache_path(tl, FALSE, NULL, FALSE);
668 tl->thumb_path_local = FALSE;
670 found = isfile(tl->thumb_path);
671 if (found && thumb_loader_std_setup(tl, tl->thumb_path)) return TRUE;
673 if (thumb_loader_std_fail_check(tl)) return FALSE;
675 return thumb_loader_std_next_source(tl, found);
678 if (!thumb_loader_std_setup(tl, tl->source_path))
680 thumb_loader_std_save(tl, NULL);
687 void thumb_loader_std_free(ThumbLoaderStd *tl)
691 thumb_loader_std_reset(tl);
695 GdkPixbuf *thumb_loader_std_get_pixbuf(ThumbLoaderStd *tl, gint with_fallback)
699 if (tl && tl->pixbuf)
702 g_object_ref(pixbuf);
704 else if (with_fallback)
708 pixbuf = pixbuf_inline(PIXBUF_INLINE_BROKEN);
709 w = gdk_pixbuf_get_width(pixbuf);
710 h = gdk_pixbuf_get_height(pixbuf);
712 if (w > tl->requested_width || h > tl->requested_height)
716 if (thumb_loader_std_scale_aspect(tl->requested_width, tl->requested_height,
722 pixbuf = gdk_pixbuf_scale_simple(tmp, nw, nh, GDK_INTERP_TILES);
723 g_object_unref(G_OBJECT(tmp));
736 typedef struct _ThumbValidate ThumbValidate;
737 struct _ThumbValidate
743 void (*func_valid)(const gchar *path, gint valid, gpointer data);
749 static void thumb_loader_std_thumb_file_validate_free(ThumbValidate *tv)
751 thumb_loader_std_free(tv->tl);
756 void thumb_loader_std_thumb_file_validate_cancel(ThumbLoaderStd *tl)
764 if (tv->idle_id != -1) g_source_remove(tv->idle_id);
767 thumb_loader_std_thumb_file_validate_free(tv);
770 static void thumb_loader_std_thumb_file_validate_finish(ThumbValidate *tv, gint valid)
772 if (tv->func_valid) tv->func_valid(tv->path, valid, tv->data);
774 thumb_loader_std_thumb_file_validate_free(tv);
777 static void thumb_loader_std_thumb_file_validate_done_cb(ThumbLoaderStd *tl, gpointer data)
779 ThumbValidate *tv = data;
783 pixbuf = thumb_loader_std_get_pixbuf(tv->tl, FALSE);
787 const gchar *mtime_str;
789 uri = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_URI);
790 mtime_str = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_MTIME);
791 if (uri && mtime_str)
793 if (strncmp(uri, "file:", strlen("file:")) == 0)
798 target = g_filename_from_uri(uri, NULL, NULL);
799 if (stat(target, &st) == 0 &&
800 st.st_mtime == strtol(mtime_str, NULL, 10))
810 DEBUG_1("thumb uri foreign, doing day check: %s", uri);
812 if (stat_utf8(tv->path, &st))
817 if (st.st_atime >= now - (time_t)tv->days * 24 * 60 * 60)
825 g_object_unref(pixbuf);
828 thumb_loader_std_thumb_file_validate_finish(tv, valid);
831 static void thumb_loader_std_thumb_file_validate_error_cb(ThumbLoaderStd *tl, gpointer data)
833 ThumbValidate *tv = data;
835 thumb_loader_std_thumb_file_validate_finish(tv, FALSE);
838 static gint thumb_loader_std_thumb_file_validate_idle_cb(gpointer data)
840 ThumbValidate *tv = data;
843 thumb_loader_std_thumb_file_validate_finish(tv, FALSE);
848 ThumbLoaderStd *thumb_loader_std_thumb_file_validate(const gchar *thumb_path, gint allowed_days,
849 void (*func_valid)(const gchar *path, gint valid, gpointer data),
854 tv = g_new0(ThumbValidate, 1);
856 tv->tl = thumb_loader_std_new(THUMB_SIZE_LARGE, THUMB_SIZE_LARGE);
857 thumb_loader_std_set_callbacks(tv->tl,
858 thumb_loader_std_thumb_file_validate_done_cb,
859 thumb_loader_std_thumb_file_validate_error_cb,
862 thumb_loader_std_reset(tv->tl);
864 tv->path = g_strdup(thumb_path);
865 tv->days = allowed_days;
866 tv->func_valid = func_valid;
869 if (!thumb_loader_std_setup(tv->tl, thumb_path))
871 tv->idle_id = g_idle_add(thumb_loader_std_thumb_file_validate_idle_cb, tv);
881 static void thumb_std_maint_remove_one(const gchar *source, const gchar *uri, gint local,
882 const gchar *subfolder)
886 thumb_path = thumb_std_cache_path(source,
887 (local) ? filename_from_path(uri) : uri,
889 if (isfile(thumb_path))
891 DEBUG_1("thumb removing: %s", thumb_path);
892 unlink_file(thumb_path);
897 /* this also removes local thumbnails (the source is gone so it makes sense) */
898 void thumb_std_maint_removed(const gchar *source)
903 sourcel = path_from_utf8(source);
904 uri = g_filename_to_uri(sourcel, NULL, NULL);
907 /* all this to remove a thumbnail? */
909 thumb_std_maint_remove_one(source, uri, FALSE, THUMB_FOLDER_NORMAL);
910 thumb_std_maint_remove_one(source, uri, FALSE, THUMB_FOLDER_LARGE);
911 thumb_std_maint_remove_one(source, uri, FALSE, THUMB_FOLDER_FAIL);
912 thumb_std_maint_remove_one(source, uri, TRUE, THUMB_FOLDER_NORMAL);
913 thumb_std_maint_remove_one(source, uri, TRUE, THUMB_FOLDER_LARGE);
918 typedef struct _TMaintMove TMaintMove;
931 static GList *thumb_std_maint_move_list = NULL;
932 static GList *thumb_std_maint_move_tail = NULL;
935 static void thumb_std_maint_move_step(TMaintMove *tm);
936 static gint thumb_std_maint_move_idle(gpointer data);
939 static void thumb_std_maint_move_validate_cb(const gchar *path, gint valid, gpointer data)
941 TMaintMove *tm = data;
944 pixbuf = thumb_loader_std_get_pixbuf(tm->tl, FALSE);
948 const gchar *mtime_str;
950 uri = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_URI);
951 mtime_str = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_MTIME);
953 if (uri && mtime_str && strcmp(uri, tm->source_uri) == 0)
957 /* The validation utility abuses ThumbLoader, and we
958 * abuse the utility just to load the thumbnail,
959 * but the loader needs to look sane for the save to complete.
962 tm->tl->cache_enable = TRUE;
963 tm->tl->cache_hit = FALSE;
964 tm->tl->cache_local = FALSE;
966 g_free(tm->tl->source_path);
967 tm->tl->source_path = g_strdup(tm->dest);
968 tm->tl->source_mtime = strtol(mtime_str, NULL, 10);
970 pathl = path_from_utf8(tm->tl->source_path);
971 g_free(tm->tl->thumb_uri);
972 tm->tl->thumb_uri = g_filename_to_uri(pathl, NULL, NULL);
973 tm->tl->local_uri = filename_from_path(tm->tl->thumb_uri);
976 g_free(tm->tl->thumb_path);
977 tm->tl->thumb_path = NULL;
978 tm->tl->thumb_path_local = FALSE;
980 DEBUG_1("thumb move attempting save:");
982 thumb_loader_std_save(tm->tl, pixbuf);
985 DEBUG_1("thumb move unlink: %s", tm->thumb_path);
986 unlink_file(tm->thumb_path);
989 thumb_std_maint_move_step(tm);
992 static void thumb_std_maint_move_step(TMaintMove *tm)
1001 g_free(tm->source_uri);
1002 g_free(tm->thumb_path);
1005 if (thumb_std_maint_move_list)
1007 g_idle_add_full(G_PRIORITY_LOW, thumb_std_maint_move_idle, NULL, NULL);
1013 folder = (tm->pass == 1) ? THUMB_FOLDER_NORMAL : THUMB_FOLDER_LARGE;
1015 g_free(tm->thumb_path);
1016 tm->thumb_path = thumb_std_cache_path(tm->source, tm->source_uri, FALSE, folder);
1017 tm->tl = thumb_loader_std_thumb_file_validate(tm->thumb_path, 0,
1018 thumb_std_maint_move_validate_cb, tm);
1021 static gint thumb_std_maint_move_idle(gpointer data)
1026 if (!thumb_std_maint_move_list) return FALSE;
1028 tm = thumb_std_maint_move_list->data;
1030 thumb_std_maint_move_list = g_list_remove(thumb_std_maint_move_list, tm);
1031 if (!thumb_std_maint_move_list) thumb_std_maint_move_tail = NULL;
1033 pathl = path_from_utf8(tm->source);
1034 tm->source_uri = g_filename_to_uri(pathl, NULL, NULL);
1039 thumb_std_maint_move_step(tm);
1044 /* This will schedule a move of the thumbnail for source image to dest when idle.
1045 * We do this so that file renaming or moving speed is not sacrificed by
1046 * moving the thumbnails at the same time because:
1048 * This cache design requires the tedious task of loading the png thumbnails and saving them.
1050 * The thumbnails are processed when the app is idle. If the app
1051 * exits early well too bad - they can simply be regenerated from scratch.
1053 * This does not manage local thumbnails (fixme ?)
1055 void thumb_std_maint_moved(const gchar *source, const gchar *dest)
1059 tm = g_new0(TMaintMove, 1);
1060 tm->source = g_strdup(source);
1061 tm->dest = g_strdup(dest);
1063 if (!thumb_std_maint_move_list)
1065 g_idle_add_full(G_PRIORITY_LOW, thumb_std_maint_move_idle, NULL, NULL);
1068 thumb_std_maint_move_tail = g_list_append(thumb_std_maint_move_tail, tm);
1069 if (!thumb_std_maint_move_list)
1070 thumb_std_maint_move_list = thumb_std_maint_move_tail;
1071 thumb_std_maint_move_tail = thumb_std_maint_move_tail->next;