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"
26 * This thumbnail caching implementation attempts to conform
27 * to the Thumbnail Managing Standard proposed on freedesktop.org
28 * The standard is documented here:
29 * http://triq.net/~jens/thumbnail-spec/index.html
30 * (why isn't it actually hosted on freedesktop.org?)
32 * This code attempts to conform to version 0.7.0 of the standard.
35 * > Validation of the thumb's embedded uri is a simple strcmp between our
36 * version of the escaped uri and the thumb's escaped uri. But not all uri
37 * escape functions escape the same set of chars, comparing the unescaped
38 * versions may be more accurate.
39 * > Only Thumb::URI and Thumb::MTime are stored in a thumb at this time.
40 * Storing the Size, Width, Height should probably be implemented.
44 #define THUMB_SIZE_NORMAL 128
45 #define THUMB_SIZE_LARGE 256
47 #define THUMB_MARKER_URI "tEXt::Thumb::URI"
48 #define THUMB_MARKER_MTIME "tEXt::Thumb::MTime"
49 #define THUMB_MARKER_SIZE "tEXt::Thumb::Size"
50 #define THUMB_MARKER_WIDTH "tEXt::Thumb::Image::Width"
51 #define THUMB_MARKER_HEIGHT "tEXt::Thumb::Image::Height"
52 #define THUMB_MARKER_APP "tEXt::Software"
54 #define THUMB_PERMS_FOLDER 0700
55 #define THUMB_PERMS_THUMB 0600
60 *-----------------------------------------------------------------------------
62 *-----------------------------------------------------------------------------
66 static void thumb_loader_std_error_cb(ImageLoader *il, gpointer data);
67 static gint thumb_loader_std_setup(ThumbLoaderStd *tl, const gchar *path);
70 ThumbLoaderStd *thumb_loader_std_new(gint width, gint height)
74 tl = g_new0(ThumbLoaderStd, 1);
76 tl->standard_loader = TRUE;
78 tl->requested_width = width;
79 tl->requested_height = height;
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 image_loader_free(tl->il);
110 file_data_unref(tl->fd);
113 g_free(tl->thumb_path);
114 tl->thumb_path = NULL;
116 g_free(tl->thumb_uri);
117 tl->thumb_uri = NULL;
118 tl->local_uri = NULL;
120 tl->thumb_path_local = FALSE;
122 tl->cache_hit = FALSE;
124 tl->source_mtime = 0;
131 static gchar *thumb_std_cache_path(const gchar *path, const gchar *uri, gint local,
132 const gchar *cache_subfolder)
134 gchar *result = NULL;
139 if (!path || !uri || !cache_subfolder) return NULL;
141 md5_get_digest((guchar *)uri, strlen(uri), digest);
142 md5_text = md5_digest_to_text(digest);
144 if (!md5_text) return NULL;
146 name = g_strconcat(md5_text, THUMB_NAME_EXTENSION, NULL);
150 gchar *base = remove_level_from_path(path);
152 result = g_build_filename(base, THUMB_FOLDER_LOCAL, cache_subfolder, name, NULL);
157 result = g_build_filename(homedir(), THUMB_FOLDER_GLOBAL, cache_subfolder, name, NULL);
166 static gchar *thumb_loader_std_cache_path(ThumbLoaderStd *tl, gint local, GdkPixbuf *pixbuf, gint fail)
171 if (!tl->fd || !tl->thumb_uri) return NULL;
175 w = gdk_pixbuf_get_width(pixbuf);
176 h = gdk_pixbuf_get_height(pixbuf);
180 w = tl->requested_width;
181 h = tl->requested_height;
186 folder = THUMB_FOLDER_FAIL;
188 else if (w > THUMB_SIZE_NORMAL || h > THUMB_SIZE_NORMAL)
190 folder = THUMB_FOLDER_LARGE;
194 folder = THUMB_FOLDER_NORMAL;
197 return thumb_std_cache_path(tl->fd->path,
198 (local) ? tl->local_uri : tl->thumb_uri,
202 static gint thumb_loader_std_fail_check(ThumbLoaderStd *tl)
207 fail_path = thumb_loader_std_cache_path(tl, FALSE, NULL, TRUE);
208 if (isfile(fail_path))
220 pathl = path_from_utf8(fail_path);
221 pixbuf = gdk_pixbuf_new_from_file(pathl, NULL);
227 const gchar *mtime_str;
229 mtime_str = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_MTIME);
230 if (mtime_str && strtol(mtime_str, NULL, 10) == tl->source_mtime)
233 DEBUG_1("thumb fail valid: %s", tl->fd->path);
234 DEBUG_1(" thumb: %s", fail_path);
237 g_object_unref(G_OBJECT(pixbuf));
240 if (!result) unlink_file(fail_path);
247 static gint thumb_loader_std_validate(ThumbLoaderStd *tl, GdkPixbuf *pixbuf)
249 const gchar *valid_uri;
251 const gchar *mtime_str;
255 if (!pixbuf) return FALSE;
257 w = gdk_pixbuf_get_width(pixbuf);
258 h = gdk_pixbuf_get_height(pixbuf);
260 if (w != THUMB_SIZE_NORMAL && w != THUMB_SIZE_LARGE &&
261 h != THUMB_SIZE_NORMAL && h != THUMB_SIZE_LARGE) return FALSE;
263 valid_uri = (tl->thumb_path_local) ? tl->local_uri : tl->thumb_uri;
265 uri = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_URI);
266 mtime_str = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_MTIME);
268 if (!mtime_str || !uri || !valid_uri) return FALSE;
269 if (strcmp(uri, valid_uri) != 0) return FALSE;
271 mtime = strtol(mtime_str, NULL, 10);
272 if (tl->source_mtime != mtime) return FALSE;
277 static void thumb_loader_std_save(ThumbLoaderStd *tl, GdkPixbuf *pixbuf)
283 if (!tl->cache_enable || tl->cache_hit) return;
284 if (tl->thumb_path) return;
288 /* local failures are not stored */
289 if (tl->cache_local) return;
291 pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 1, 1);
296 g_object_ref(G_OBJECT(pixbuf));
300 tl->thumb_path = thumb_loader_std_cache_path(tl, tl->cache_local, pixbuf, fail);
303 g_object_unref(G_OBJECT(pixbuf));
306 tl->thumb_path_local = tl->cache_local;
308 /* create thumbnail dir if needed */
309 base_path = remove_level_from_path(tl->thumb_path);
312 if (!isdir(base_path))
317 source_base = remove_level_from_path(tl->fd->path);
318 if (stat_utf8(source_base, &st))
320 cache_ensure_dir_exists(base_path, st.st_mode);
327 cache_ensure_dir_exists(base_path, THUMB_PERMS_FOLDER);
331 DEBUG_1("thumb saving: %s", tl->fd->path);
332 DEBUG_1(" saved: %s", tl->thumb_path);
334 /* save thumb, using a temp file then renaming into place */
335 tmp_path = unique_filename(tl->thumb_path, ".tmp", "_", 2);
338 const gchar *mark_uri;
344 mark_uri = (tl->cache_local) ? tl->local_uri :tl->thumb_uri;
346 mark_app = g_strdup_printf("%s %s", GQ_APPNAME, VERSION);
347 mark_mtime = g_strdup_printf("%lu", tl->source_mtime);
349 pathl = path_from_utf8(tmp_path);
350 success = gdk_pixbuf_save(pixbuf, pathl, "png", NULL,
351 THUMB_MARKER_URI, mark_uri,
352 THUMB_MARKER_MTIME, mark_mtime,
353 THUMB_MARKER_APP, mark_app,
357 chmod(pathl, (tl->cache_local) ? tl->source_mode : THUMB_PERMS_THUMB);
358 success = rename_file(tmp_path, tl->thumb_path);
369 DEBUG_1("thumb save failed: %s", tl->fd->path);
370 DEBUG_1(" thumb: %s", tl->thumb_path);
375 g_object_unref(G_OBJECT(pixbuf));
378 static gint thumb_loader_std_scale_aspect(gint req_w, gint req_h, gint old_w, gint old_h,
379 gint *new_w, gint *new_h)
381 if (((gdouble)req_w / old_w) < ((gdouble)req_h / old_h))
384 *new_h = (gdouble)*new_w / old_w * old_h;
385 if (*new_h < 1) *new_h = 1;
390 *new_w = (gdouble)*new_h / old_h * old_w;
391 if (*new_w < 1) *new_w = 1;
394 return (*new_w != old_w || *new_h != old_h);
397 static GdkPixbuf *thumb_loader_std_finish(ThumbLoaderStd *tl, GdkPixbuf *pixbuf, gint shrunk)
399 GdkPixbuf *pixbuf_thumb = NULL;
403 sw = gdk_pixbuf_get_width(pixbuf);
404 sh = gdk_pixbuf_get_height(pixbuf);
406 if (tl->cache_enable)
410 gint cache_w, cache_h;
412 if (tl->requested_width > THUMB_SIZE_NORMAL || tl->requested_height > THUMB_SIZE_NORMAL)
414 cache_w = cache_h = THUMB_SIZE_LARGE;
418 cache_w = cache_h = THUMB_SIZE_NORMAL;
421 if (sw > cache_w || sh > cache_h || shrunk)
423 gint thumb_w, thumb_h;
425 if (thumb_loader_std_scale_aspect(cache_w, cache_h, sw, sh,
428 pixbuf_thumb = gdk_pixbuf_scale_simple(pixbuf, thumb_w, thumb_h,
429 (GdkInterpType)options->thumbnails.quality);
433 pixbuf_thumb = pixbuf;
434 g_object_ref(G_OBJECT(pixbuf_thumb));
437 thumb_loader_std_save(tl, pixbuf_thumb);
440 else if (tl->cache_hit &&
441 tl->cache_local && !tl->thumb_path_local)
443 /* A local cache save was requested, but a valid thumb is in $HOME,
444 * so specifically save as a local thumbnail.
446 g_free(tl->thumb_path);
447 tl->thumb_path = NULL;
449 tl->cache_hit = FALSE;
451 DEBUG_1("thumb copied: %s", tl->fd->path);
453 thumb_loader_std_save(tl, pixbuf);
457 if (sw <= tl->requested_width && sh <= tl->requested_height)
460 g_object_ref(result);
464 gint thumb_w, thumb_h;
468 pixbuf = pixbuf_thumb;
469 sw = gdk_pixbuf_get_width(pixbuf);
470 sh = gdk_pixbuf_get_height(pixbuf);
473 if (thumb_loader_std_scale_aspect(tl->requested_width, tl->requested_height, sw, sh,
476 result = gdk_pixbuf_scale_simple(pixbuf, thumb_w, thumb_h,
477 (GdkInterpType)options->thumbnails.quality);
482 g_object_ref(result);
486 if (pixbuf_thumb) g_object_unref(pixbuf_thumb);
491 static gint thumb_loader_std_next_source(ThumbLoaderStd *tl, gint remove_broken)
493 image_loader_free(tl->il);
498 if (!tl->thumb_path_local && remove_broken)
500 DEBUG_1("thumb broken, unlinking: %s", tl->thumb_path);
501 unlink_file(tl->thumb_path);
504 g_free(tl->thumb_path);
505 tl->thumb_path = NULL;
507 if (!tl->thumb_path_local)
509 tl->thumb_path = thumb_loader_std_cache_path(tl, TRUE, NULL, FALSE);
510 if (isfile(tl->thumb_path) && thumb_loader_std_setup(tl, tl->thumb_path))
512 tl->thumb_path_local = TRUE;
516 g_free(tl->thumb_path);
517 tl->thumb_path = NULL;
520 if (thumb_loader_std_setup(tl, tl->fd->path)) return TRUE;
523 thumb_loader_std_save(tl, NULL);
527 static void thumb_loader_std_done_cb(ImageLoader *il, gpointer data)
529 ThumbLoaderStd *tl = data;
532 DEBUG_1("thumb image done: %s", tl->fd->path);
533 DEBUG_1(" from: %s", tl->il->path);
535 pixbuf = image_loader_get_pixbuf(tl->il);
538 DEBUG_1("...but no pixbuf");
539 thumb_loader_std_error_cb(il, data);
543 if (tl->thumb_path && !thumb_loader_std_validate(tl, pixbuf))
545 if (thumb_loader_std_next_source(tl, TRUE)) return;
547 if (tl->func_error) tl->func_error(tl, tl->data);
551 tl->cache_hit = (tl->thumb_path != NULL);
555 if (tl->fd->pixbuf) g_object_unref(tl->fd->pixbuf);
556 tl->fd->pixbuf = thumb_loader_std_finish(tl, pixbuf, il->shrunk);
559 if (tl->func_done) tl->func_done(tl, tl->data);
562 static void thumb_loader_std_error_cb(ImageLoader *il, gpointer data)
564 ThumbLoaderStd *tl = data;
566 /* if at least some of the image is available, go to done */
567 if (image_loader_get_pixbuf(tl->il) != NULL)
569 thumb_loader_std_done_cb(il, data);
573 DEBUG_1("thumb image error: %s", tl->fd->path);
574 DEBUG_1(" from: %s", tl->il->fd->path);
576 if (thumb_loader_std_next_source(tl, TRUE)) return;
578 if (tl->func_error) tl->func_error(tl, tl->data);
581 static void thumb_loader_std_progress_cb(ImageLoader *il, gdouble percent, gpointer data)
583 ThumbLoaderStd *tl = data;
585 tl->progress = (gdouble)percent;
587 if (tl->func_progress) tl->func_progress(tl, tl->data);
590 static gint thumb_loader_std_setup(ThumbLoaderStd *tl, const gchar *path)
592 tl->il = image_loader_new_from_path(path);
594 if (options->thumbnails.fast)
596 /* this will speed up jpegs by up to 3x in some cases */
597 if (tl->requested_width <= THUMB_SIZE_NORMAL &&
598 tl->requested_height <= THUMB_SIZE_NORMAL)
600 image_loader_set_requested_size(tl->il, THUMB_SIZE_NORMAL, THUMB_SIZE_NORMAL);
604 image_loader_set_requested_size(tl->il, THUMB_SIZE_LARGE, THUMB_SIZE_LARGE);
608 image_loader_set_error_func(tl->il, thumb_loader_std_error_cb, tl);
609 if (tl->func_progress)
611 image_loader_set_percent_func(tl->il, thumb_loader_std_progress_cb, tl);
614 if (image_loader_start(tl->il, thumb_loader_std_done_cb, tl))
619 image_loader_free(tl->il);
625 * Note: Currently local_cache only specifies where to save a _new_ thumb, if
626 * a valid existing thumb is found anywhere the local thumb will not be created.
628 void thumb_loader_std_set_cache(ThumbLoaderStd *tl, gint enable_cache, gint local, gint retry_failed)
632 tl->cache_enable = enable_cache;
633 tl->cache_local = local;
634 tl->cache_retry = retry_failed;
637 gint thumb_loader_std_start(ThumbLoaderStd *tl, FileData *fd)
639 static gchar *thumb_cache = NULL;
642 if (!tl || !fd) return FALSE;
644 thumb_loader_std_reset(tl);
646 if (!stat_utf8(fd->path, &st)) return FALSE;
648 tl->fd = file_data_ref(fd);
649 tl->source_mtime = st.st_mtime;
650 tl->source_size = st.st_size;
651 tl->source_mode = st.st_mode;
653 if (!thumb_cache) thumb_cache = g_build_filename(homedir(), THUMB_FOLDER_GLOBAL, NULL);
654 if (strncmp(tl->fd->path, thumb_cache, strlen(thumb_cache)) != 0)
658 pathl = path_from_utf8(fd->path);
659 tl->thumb_uri = g_filename_to_uri(pathl, NULL, NULL);
660 tl->local_uri = filename_from_path(tl->thumb_uri);
664 if (tl->cache_enable)
668 tl->thumb_path = thumb_loader_std_cache_path(tl, FALSE, NULL, FALSE);
669 tl->thumb_path_local = FALSE;
671 found = isfile(tl->thumb_path);
672 if (found && thumb_loader_std_setup(tl, tl->thumb_path)) return TRUE;
674 if (thumb_loader_std_fail_check(tl)) return FALSE;
676 return thumb_loader_std_next_source(tl, found);
679 if (!thumb_loader_std_setup(tl, tl->fd->path))
681 thumb_loader_std_save(tl, NULL);
688 void thumb_loader_std_free(ThumbLoaderStd *tl)
692 thumb_loader_std_reset(tl);
696 GdkPixbuf *thumb_loader_std_get_pixbuf(ThumbLoaderStd *tl, gint with_fallback)
700 if (tl && tl->fd && tl->fd->pixbuf)
702 pixbuf = tl->fd->pixbuf;
703 g_object_ref(pixbuf);
705 else if (with_fallback)
709 pixbuf = pixbuf_inline(PIXBUF_INLINE_BROKEN);
710 w = gdk_pixbuf_get_width(pixbuf);
711 h = gdk_pixbuf_get_height(pixbuf);
713 if (w > tl->requested_width || h > tl->requested_height)
717 if (thumb_loader_std_scale_aspect(tl->requested_width, tl->requested_height,
723 pixbuf = gdk_pixbuf_scale_simple(tmp, nw, nh, GDK_INTERP_TILES);
724 g_object_unref(G_OBJECT(tmp));
737 typedef struct _ThumbValidate ThumbValidate;
738 struct _ThumbValidate
744 void (*func_valid)(const gchar *path, gint valid, gpointer data);
750 static void thumb_loader_std_thumb_file_validate_free(ThumbValidate *tv)
752 thumb_loader_std_free(tv->tl);
757 void thumb_loader_std_thumb_file_validate_cancel(ThumbLoaderStd *tl)
765 if (tv->idle_id != -1) g_source_remove(tv->idle_id);
768 thumb_loader_std_thumb_file_validate_free(tv);
771 static void thumb_loader_std_thumb_file_validate_finish(ThumbValidate *tv, gint valid)
773 if (tv->func_valid) tv->func_valid(tv->path, valid, tv->data);
775 thumb_loader_std_thumb_file_validate_free(tv);
778 static void thumb_loader_std_thumb_file_validate_done_cb(ThumbLoaderStd *tl, gpointer data)
780 ThumbValidate *tv = data;
784 pixbuf = thumb_loader_std_get_pixbuf(tv->tl, FALSE);
788 const gchar *mtime_str;
790 uri = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_URI);
791 mtime_str = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_MTIME);
792 if (uri && mtime_str)
794 if (strncmp(uri, "file:", strlen("file:")) == 0)
799 target = g_filename_from_uri(uri, NULL, NULL);
800 if (stat(target, &st) == 0 &&
801 st.st_mtime == strtol(mtime_str, NULL, 10))
811 DEBUG_1("thumb uri foreign, doing day check: %s", uri);
813 if (stat_utf8(tv->path, &st))
818 if (st.st_atime >= now - (time_t)tv->days * 24 * 60 * 60)
826 g_object_unref(pixbuf);
829 thumb_loader_std_thumb_file_validate_finish(tv, valid);
832 static void thumb_loader_std_thumb_file_validate_error_cb(ThumbLoaderStd *tl, gpointer data)
834 ThumbValidate *tv = data;
836 thumb_loader_std_thumb_file_validate_finish(tv, FALSE);
839 static gint thumb_loader_std_thumb_file_validate_idle_cb(gpointer data)
841 ThumbValidate *tv = data;
844 thumb_loader_std_thumb_file_validate_finish(tv, FALSE);
849 ThumbLoaderStd *thumb_loader_std_thumb_file_validate(const gchar *thumb_path, gint allowed_days,
850 void (*func_valid)(const gchar *path, gint valid, gpointer data),
855 tv = g_new0(ThumbValidate, 1);
857 tv->tl = thumb_loader_std_new(THUMB_SIZE_LARGE, THUMB_SIZE_LARGE);
858 thumb_loader_std_set_callbacks(tv->tl,
859 thumb_loader_std_thumb_file_validate_done_cb,
860 thumb_loader_std_thumb_file_validate_error_cb,
863 thumb_loader_std_reset(tv->tl);
865 tv->path = g_strdup(thumb_path);
866 tv->days = allowed_days;
867 tv->func_valid = func_valid;
870 if (!thumb_loader_std_setup(tv->tl, thumb_path))
872 tv->idle_id = g_idle_add(thumb_loader_std_thumb_file_validate_idle_cb, tv);
882 static void thumb_std_maint_remove_one(const gchar *source, const gchar *uri, gint local,
883 const gchar *subfolder)
887 thumb_path = thumb_std_cache_path(source,
888 (local) ? filename_from_path(uri) : uri,
890 if (isfile(thumb_path))
892 DEBUG_1("thumb removing: %s", thumb_path);
893 unlink_file(thumb_path);
898 /* this also removes local thumbnails (the source is gone so it makes sense) */
899 void thumb_std_maint_removed(const gchar *source)
904 sourcel = path_from_utf8(source);
905 uri = g_filename_to_uri(sourcel, NULL, NULL);
908 /* all this to remove a thumbnail? */
910 thumb_std_maint_remove_one(source, uri, FALSE, THUMB_FOLDER_NORMAL);
911 thumb_std_maint_remove_one(source, uri, FALSE, THUMB_FOLDER_LARGE);
912 thumb_std_maint_remove_one(source, uri, FALSE, THUMB_FOLDER_FAIL);
913 thumb_std_maint_remove_one(source, uri, TRUE, THUMB_FOLDER_NORMAL);
914 thumb_std_maint_remove_one(source, uri, TRUE, THUMB_FOLDER_LARGE);
919 typedef struct _TMaintMove TMaintMove;
932 static GList *thumb_std_maint_move_list = NULL;
933 static GList *thumb_std_maint_move_tail = NULL;
936 static void thumb_std_maint_move_step(TMaintMove *tm);
937 static gint thumb_std_maint_move_idle(gpointer data);
940 static void thumb_std_maint_move_validate_cb(const gchar *path, gint valid, gpointer data)
942 TMaintMove *tm = data;
945 pixbuf = thumb_loader_std_get_pixbuf(tm->tl, FALSE);
949 const gchar *mtime_str;
951 uri = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_URI);
952 mtime_str = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_MTIME);
954 if (uri && mtime_str && strcmp(uri, tm->source_uri) == 0)
958 /* The validation utility abuses ThumbLoader, and we
959 * abuse the utility just to load the thumbnail,
960 * but the loader needs to look sane for the save to complete.
963 tm->tl->cache_enable = TRUE;
964 tm->tl->cache_hit = FALSE;
965 tm->tl->cache_local = FALSE;
967 file_data_unref(tm->tl->fd);
968 tm->tl->fd = file_data_new_simple(tm->dest);
969 tm->tl->source_mtime = strtol(mtime_str, NULL, 10);
971 pathl = path_from_utf8(tm->tl->fd->path);
972 g_free(tm->tl->thumb_uri);
973 tm->tl->thumb_uri = g_filename_to_uri(pathl, NULL, NULL);
974 tm->tl->local_uri = filename_from_path(tm->tl->thumb_uri);
977 g_free(tm->tl->thumb_path);
978 tm->tl->thumb_path = NULL;
979 tm->tl->thumb_path_local = FALSE;
981 DEBUG_1("thumb move attempting save:");
983 thumb_loader_std_save(tm->tl, pixbuf);
986 DEBUG_1("thumb move unlink: %s", tm->thumb_path);
987 unlink_file(tm->thumb_path);
990 thumb_std_maint_move_step(tm);
993 static void thumb_std_maint_move_step(TMaintMove *tm)
1002 g_free(tm->source_uri);
1003 g_free(tm->thumb_path);
1006 if (thumb_std_maint_move_list)
1008 g_idle_add_full(G_PRIORITY_LOW, thumb_std_maint_move_idle, NULL, NULL);
1014 folder = (tm->pass == 1) ? THUMB_FOLDER_NORMAL : THUMB_FOLDER_LARGE;
1016 g_free(tm->thumb_path);
1017 tm->thumb_path = thumb_std_cache_path(tm->source, tm->source_uri, FALSE, folder);
1018 tm->tl = thumb_loader_std_thumb_file_validate(tm->thumb_path, 0,
1019 thumb_std_maint_move_validate_cb, tm);
1022 static gint thumb_std_maint_move_idle(gpointer data)
1027 if (!thumb_std_maint_move_list) return FALSE;
1029 tm = thumb_std_maint_move_list->data;
1031 thumb_std_maint_move_list = g_list_remove(thumb_std_maint_move_list, tm);
1032 if (!thumb_std_maint_move_list) thumb_std_maint_move_tail = NULL;
1034 pathl = path_from_utf8(tm->source);
1035 tm->source_uri = g_filename_to_uri(pathl, NULL, NULL);
1040 thumb_std_maint_move_step(tm);
1045 /* This will schedule a move of the thumbnail for source image to dest when idle.
1046 * We do this so that file renaming or moving speed is not sacrificed by
1047 * moving the thumbnails at the same time because:
1049 * This cache design requires the tedious task of loading the png thumbnails and saving them.
1051 * The thumbnails are processed when the app is idle. If the app
1052 * exits early well too bad - they can simply be regenerated from scratch.
1054 * This does not manage local thumbnails (fixme ?)
1056 void thumb_std_maint_moved(const gchar *source, const gchar *dest)
1060 tm = g_new0(TMaintMove, 1);
1061 tm->source = g_strdup(source);
1062 tm->dest = g_strdup(dest);
1064 if (!thumb_std_maint_move_list)
1066 g_idle_add_full(G_PRIORITY_LOW, thumb_std_maint_move_idle, NULL, NULL);
1069 if (thumb_std_maint_move_tail)
1071 thumb_std_maint_move_tail = g_list_append(thumb_std_maint_move_tail, tm);
1072 thumb_std_maint_move_tail = thumb_std_maint_move_tail->next;
1076 thumb_std_maint_move_list = g_list_append(thumb_std_maint_move_list, tm);
1077 thumb_std_maint_move_tail = thumb_std_maint_move_list;