4 * Copyright (C) 2008 - 2010 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 "image-load.h"
19 #include "pixbuf_util.h"
20 #include "ui_fileops.h"
27 * This thumbnail caching implementation attempts to conform
28 * to the Thumbnail Managing Standard proposed on freedesktop.org
29 * The standard is documented here:
30 * http://triq.net/~jens/thumbnail-spec/index.html
31 * (why isn't it actually hosted on freedesktop.org?)
33 * This code attempts to conform to version 0.7.0 of the standard.
36 * > Validation of the thumb's embedded uri is a simple strcmp between our
37 * version of the escaped uri and the thumb's escaped uri. But not all uri
38 * escape functions escape the same set of chars, comparing the unescaped
39 * versions may be more accurate.
40 * > Only Thumb::URI and Thumb::MTime are stored in a thumb at this time.
41 * Storing the Size, Width, Height should probably be implemented.
45 #define THUMB_SIZE_NORMAL 128
46 #define THUMB_SIZE_LARGE 256
48 #define THUMB_MARKER_URI "tEXt::Thumb::URI"
49 #define THUMB_MARKER_MTIME "tEXt::Thumb::MTime"
50 #define THUMB_MARKER_SIZE "tEXt::Thumb::Size"
51 #define THUMB_MARKER_WIDTH "tEXt::Thumb::Image::Width"
52 #define THUMB_MARKER_HEIGHT "tEXt::Thumb::Image::Height"
53 #define THUMB_MARKER_APP "tEXt::Software"
55 #define THUMB_PERMS_FOLDER 0700
56 #define THUMB_PERMS_THUMB 0600
61 *-----------------------------------------------------------------------------
63 *-----------------------------------------------------------------------------
67 static void thumb_loader_std_error_cb(ImageLoader *il, gpointer data);
68 static gint thumb_loader_std_setup(ThumbLoaderStd *tl, FileData *fd);
71 ThumbLoaderStd *thumb_loader_std_new(gint width, gint height)
75 tl = g_new0(ThumbLoaderStd, 1);
77 tl->standard_loader = TRUE;
78 tl->requested_width = width;
79 tl->requested_height = height;
80 tl->cache_enable = options->thumbnails.enable_caching;
85 void thumb_loader_std_set_callbacks(ThumbLoaderStd *tl,
86 ThumbLoaderStdFunc func_done,
87 ThumbLoaderStdFunc func_error,
88 ThumbLoaderStdFunc func_progress,
93 tl->func_done = func_done;
94 tl->func_error = func_error;
95 tl->func_progress = func_progress;
99 static void thumb_loader_std_reset(ThumbLoaderStd *tl)
101 image_loader_free(tl->il);
104 file_data_unref(tl->fd);
107 g_free(tl->thumb_path);
108 tl->thumb_path = NULL;
110 g_free(tl->thumb_uri);
111 tl->thumb_uri = NULL;
112 tl->local_uri = NULL;
114 tl->thumb_path_local = FALSE;
116 tl->cache_hit = FALSE;
118 tl->source_mtime = 0;
125 static gchar *thumb_std_cache_path(const gchar *path, const gchar *uri, gboolean local,
126 const gchar *cache_subfolder)
128 gchar *result = NULL;
133 if (!path || !uri || !cache_subfolder) return NULL;
135 md5_get_digest((guchar *)uri, strlen(uri), digest);
136 md5_text = md5_digest_to_text(digest);
138 if (!md5_text) return NULL;
140 name = g_strconcat(md5_text, THUMB_NAME_EXTENSION, NULL);
144 gchar *base = remove_level_from_path(path);
146 result = g_build_filename(base, THUMB_FOLDER_LOCAL, cache_subfolder, name, NULL);
151 result = g_build_filename(homedir(), THUMB_FOLDER_GLOBAL, cache_subfolder, name, NULL);
160 static gchar *thumb_loader_std_cache_path(ThumbLoaderStd *tl, gboolean local, GdkPixbuf *pixbuf, gboolean fail)
165 if (!tl->fd || !tl->thumb_uri) return NULL;
169 w = gdk_pixbuf_get_width(pixbuf);
170 h = gdk_pixbuf_get_height(pixbuf);
174 w = tl->requested_width;
175 h = tl->requested_height;
180 folder = THUMB_FOLDER_FAIL;
182 else if (w > THUMB_SIZE_NORMAL || h > THUMB_SIZE_NORMAL)
184 folder = THUMB_FOLDER_LARGE;
188 folder = THUMB_FOLDER_NORMAL;
191 return thumb_std_cache_path(tl->fd->path,
192 (local) ? tl->local_uri : tl->thumb_uri,
196 static gboolean thumb_loader_std_fail_check(ThumbLoaderStd *tl)
199 gboolean result = FALSE;
201 fail_path = thumb_loader_std_cache_path(tl, FALSE, NULL, TRUE);
202 if (isfile(fail_path))
214 pathl = path_from_utf8(fail_path);
215 pixbuf = gdk_pixbuf_new_from_file(pathl, NULL);
221 const gchar *mtime_str;
223 mtime_str = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_MTIME);
224 if (mtime_str && strtol(mtime_str, NULL, 10) == tl->source_mtime)
227 DEBUG_1("thumb fail valid: %s", tl->fd->path);
228 DEBUG_1(" thumb: %s", fail_path);
231 g_object_unref(G_OBJECT(pixbuf));
234 if (!result) unlink_file(fail_path);
241 static gboolean thumb_loader_std_validate(ThumbLoaderStd *tl, GdkPixbuf *pixbuf)
243 const gchar *valid_uri;
245 const gchar *mtime_str;
249 if (!pixbuf) return FALSE;
251 w = gdk_pixbuf_get_width(pixbuf);
252 h = gdk_pixbuf_get_height(pixbuf);
254 if (w != THUMB_SIZE_NORMAL && w != THUMB_SIZE_LARGE &&
255 h != THUMB_SIZE_NORMAL && h != THUMB_SIZE_LARGE) return FALSE;
257 valid_uri = (tl->thumb_path_local) ? tl->local_uri : tl->thumb_uri;
259 uri = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_URI);
260 mtime_str = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_MTIME);
262 if (!mtime_str || !uri || !valid_uri) return FALSE;
263 if (strcmp(uri, valid_uri) != 0) return FALSE;
265 mtime = strtol(mtime_str, NULL, 10);
266 if (tl->source_mtime != mtime) return FALSE;
271 static void thumb_loader_std_save(ThumbLoaderStd *tl, GdkPixbuf *pixbuf)
277 if (!tl->cache_enable || tl->cache_hit) return;
278 if (tl->thumb_path) return;
282 /* local failures are not stored */
283 if (tl->cache_local) return;
285 pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 1, 1);
290 g_object_ref(G_OBJECT(pixbuf));
294 tl->thumb_path = thumb_loader_std_cache_path(tl, tl->cache_local, pixbuf, fail);
297 g_object_unref(G_OBJECT(pixbuf));
300 tl->thumb_path_local = tl->cache_local;
302 /* create thumbnail dir if needed */
303 base_path = remove_level_from_path(tl->thumb_path);
306 if (!isdir(base_path))
311 source_base = remove_level_from_path(tl->fd->path);
312 if (stat_utf8(source_base, &st))
314 recursive_mkdir_if_not_exists(base_path, st.st_mode);
321 recursive_mkdir_if_not_exists(base_path, THUMB_PERMS_FOLDER);
325 DEBUG_1("thumb saving: %s", tl->fd->path);
326 DEBUG_1(" saved: %s", tl->thumb_path);
328 /* save thumb, using a temp file then renaming into place */
329 tmp_path = unique_filename(tl->thumb_path, ".tmp", "_", 2);
332 const gchar *mark_uri;
338 mark_uri = (tl->cache_local) ? tl->local_uri :tl->thumb_uri;
340 mark_app = g_strdup_printf("%s %s", GQ_APPNAME, VERSION);
341 mark_mtime = g_strdup_printf("%lu", tl->source_mtime);
343 pathl = path_from_utf8(tmp_path);
344 success = gdk_pixbuf_save(pixbuf, pathl, "png", NULL,
345 THUMB_MARKER_URI, mark_uri,
346 THUMB_MARKER_MTIME, mark_mtime,
347 THUMB_MARKER_APP, mark_app,
351 chmod(pathl, (tl->cache_local) ? tl->source_mode : THUMB_PERMS_THUMB);
352 success = rename_file(tmp_path, tl->thumb_path);
363 DEBUG_1("thumb save failed: %s", tl->fd->path);
364 DEBUG_1(" thumb: %s", tl->thumb_path);
369 g_object_unref(G_OBJECT(pixbuf));
372 static void thumb_loader_std_set_fallback(ThumbLoaderStd *tl)
374 if (tl->fd->thumb_pixbuf) g_object_unref(tl->fd->thumb_pixbuf);
375 tl->fd->thumb_pixbuf = pixbuf_fallback(tl->fd, tl->requested_width, tl->requested_height);
378 static GdkPixbuf *thumb_loader_std_finish(ThumbLoaderStd *tl, GdkPixbuf *pixbuf, gboolean shrunk)
380 GdkPixbuf *pixbuf_thumb = NULL;
382 GdkPixbuf *rotated = NULL;
386 if (!tl->cache_hit && options->image.exif_rotate_enable)
388 if (!tl->fd->exif_orientation)
390 tl->fd->exif_orientation = metadata_read_int(tl->fd, ORIENTATION_KEY, EXIF_ORIENTATION_TOP_LEFT);
393 if (tl->fd->exif_orientation != EXIF_ORIENTATION_TOP_LEFT)
395 rotated = pixbuf_apply_orientation(pixbuf, tl->fd->exif_orientation);
400 sw = gdk_pixbuf_get_width(pixbuf);
401 sh = gdk_pixbuf_get_height(pixbuf);
403 if (tl->cache_enable)
407 gint cache_w, cache_h;
409 if (tl->requested_width > THUMB_SIZE_NORMAL || tl->requested_height > THUMB_SIZE_NORMAL)
411 cache_w = cache_h = THUMB_SIZE_LARGE;
415 cache_w = cache_h = THUMB_SIZE_NORMAL;
418 if (sw > cache_w || sh > cache_h || shrunk)
420 gint thumb_w, thumb_h;
423 if (pixbuf_scale_aspect(cache_w, cache_h, sw, sh,
426 pixbuf_thumb = gdk_pixbuf_scale_simple(pixbuf, thumb_w, thumb_h,
427 (GdkInterpType)options->thumbnails.quality);
431 pixbuf_thumb = pixbuf;
432 g_object_ref(G_OBJECT(pixbuf_thumb));
435 /* do not save the thumbnail if the source file has changed meanwhile -
436 the thumbnail is most probably broken */
437 if (stat_utf8(tl->fd->path, &st) &&
438 tl->source_mtime == st.st_mtime &&
439 tl->source_size == st.st_size)
441 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->fd->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 (pixbuf_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);
492 if (rotated) g_object_unref(rotated);
497 static gboolean thumb_loader_std_next_source(ThumbLoaderStd *tl, gboolean remove_broken)
499 image_loader_free(tl->il);
504 if (!tl->thumb_path_local && remove_broken)
506 DEBUG_1("thumb broken, unlinking: %s", tl->thumb_path);
507 unlink_file(tl->thumb_path);
510 g_free(tl->thumb_path);
511 tl->thumb_path = NULL;
513 if (!tl->thumb_path_local)
515 tl->thumb_path = thumb_loader_std_cache_path(tl, TRUE, NULL, FALSE);
516 if (isfile(tl->thumb_path))
518 FileData *fd = file_data_new_no_grouping(tl->thumb_path);
519 if (thumb_loader_std_setup(tl, fd))
522 tl->thumb_path_local = TRUE;
528 g_free(tl->thumb_path);
529 tl->thumb_path = NULL;
532 if (thumb_loader_std_setup(tl, tl->fd)) return TRUE;
535 thumb_loader_std_save(tl, NULL);
539 static void thumb_loader_std_done_cb(ImageLoader *il, gpointer data)
541 ThumbLoaderStd *tl = data;
544 DEBUG_1("thumb image done: %s", tl->fd ? tl->fd->path : "???");
545 DEBUG_1(" from: %s", image_loader_get_fd(tl->il)->path);
547 pixbuf = image_loader_get_pixbuf(tl->il);
550 DEBUG_1("...but no pixbuf");
551 thumb_loader_std_error_cb(il, data);
555 if (tl->thumb_path && !thumb_loader_std_validate(tl, pixbuf))
557 if (thumb_loader_std_next_source(tl, TRUE)) return;
559 if (tl->func_error) tl->func_error(tl, tl->data);
563 tl->cache_hit = (tl->thumb_path != NULL);
567 if (tl->fd->thumb_pixbuf) g_object_unref(tl->fd->thumb_pixbuf);
568 tl->fd->thumb_pixbuf = thumb_loader_std_finish(tl, pixbuf, image_loader_get_shrunk(il));
571 if (tl->func_done) tl->func_done(tl, tl->data);
574 static void thumb_loader_std_error_cb(ImageLoader *il, gpointer data)
576 ThumbLoaderStd *tl = data;
578 /* if at least some of the image is available, go to done */
579 if (image_loader_get_pixbuf(tl->il) != NULL)
581 thumb_loader_std_done_cb(il, data);
585 DEBUG_1("thumb image error: %s", tl->fd->path);
586 DEBUG_1(" from: %s", image_loader_get_fd(tl->il)->path);
588 if (thumb_loader_std_next_source(tl, TRUE)) return;
590 thumb_loader_std_set_fallback(tl);
592 if (tl->func_error) tl->func_error(tl, tl->data);
595 static void thumb_loader_std_progress_cb(ImageLoader *il, gdouble percent, gpointer data)
597 ThumbLoaderStd *tl = data;
599 tl->progress = (gdouble)percent;
601 if (tl->func_progress) tl->func_progress(tl, tl->data);
604 static gboolean thumb_loader_std_setup(ThumbLoaderStd *tl, FileData *fd)
606 tl->il = image_loader_new(fd);
607 image_loader_set_priority(tl->il, G_PRIORITY_LOW);
609 /* this will speed up jpegs by up to 3x in some cases */
610 if (tl->requested_width <= THUMB_SIZE_NORMAL &&
611 tl->requested_height <= THUMB_SIZE_NORMAL)
613 image_loader_set_requested_size(tl->il, THUMB_SIZE_NORMAL, THUMB_SIZE_NORMAL);
617 image_loader_set_requested_size(tl->il, THUMB_SIZE_LARGE, THUMB_SIZE_LARGE);
620 g_signal_connect(G_OBJECT(tl->il), "error", (GCallback)thumb_loader_std_error_cb, tl);
621 if (tl->func_progress)
623 g_signal_connect(G_OBJECT(tl->il), "percent", (GCallback)thumb_loader_std_progress_cb, tl);
625 g_signal_connect(G_OBJECT(tl->il), "done", (GCallback)thumb_loader_std_done_cb, tl);
627 if (image_loader_start(tl->il))
632 image_loader_free(tl->il);
638 * Note: Currently local_cache only specifies where to save a _new_ thumb, if
639 * a valid existing thumb is found anywhere the local thumb will not be created.
641 void thumb_loader_std_set_cache(ThumbLoaderStd *tl, gboolean enable_cache, gboolean local, gboolean retry_failed)
645 tl->cache_enable = enable_cache;
646 tl->cache_local = local;
647 tl->cache_retry = retry_failed;
650 gboolean thumb_loader_std_start(ThumbLoaderStd *tl, FileData *fd)
652 static gchar *thumb_cache = NULL;
655 if (!tl || !fd) return FALSE;
657 thumb_loader_std_reset(tl);
660 tl->fd = file_data_ref(fd);
661 if (!stat_utf8(fd->path, &st))
663 thumb_loader_std_set_fallback(tl);
666 tl->source_mtime = st.st_mtime;
667 tl->source_size = st.st_size;
668 tl->source_mode = st.st_mode;
670 if (!thumb_cache) thumb_cache = g_build_filename(homedir(), THUMB_FOLDER_GLOBAL, NULL);
671 if (strncmp(tl->fd->path, thumb_cache, strlen(thumb_cache)) != 0)
675 pathl = path_from_utf8(fd->path);
676 tl->thumb_uri = g_filename_to_uri(pathl, NULL, NULL);
677 tl->local_uri = filename_from_path(tl->thumb_uri);
681 if (tl->cache_enable)
685 tl->thumb_path = thumb_loader_std_cache_path(tl, FALSE, NULL, FALSE);
686 tl->thumb_path_local = FALSE;
688 found = isfile(tl->thumb_path);
691 FileData *fd = file_data_new_no_grouping(tl->thumb_path);
692 if (thumb_loader_std_setup(tl, fd))
700 if (thumb_loader_std_fail_check(tl) ||
701 !thumb_loader_std_next_source(tl, found))
703 thumb_loader_std_set_fallback(tl);
709 if (!thumb_loader_std_setup(tl, tl->fd))
711 thumb_loader_std_save(tl, NULL);
712 thumb_loader_std_set_fallback(tl);
719 void thumb_loader_std_free(ThumbLoaderStd *tl)
723 thumb_loader_std_reset(tl);
727 GdkPixbuf *thumb_loader_std_get_pixbuf(ThumbLoaderStd *tl)
731 if (tl && tl->fd && tl->fd->thumb_pixbuf)
733 pixbuf = tl->fd->thumb_pixbuf;
734 g_object_ref(pixbuf);
738 pixbuf = pixbuf_fallback(NULL, tl->requested_width, tl->requested_height);
745 typedef struct _ThumbValidate ThumbValidate;
746 struct _ThumbValidate
752 void (*func_valid)(const gchar *path, gboolean valid, gpointer data);
755 guint idle_id; /* event source id */
758 static void thumb_loader_std_thumb_file_validate_free(ThumbValidate *tv)
760 thumb_loader_std_free(tv->tl);
765 void thumb_loader_std_thumb_file_validate_cancel(ThumbLoaderStd *tl)
775 g_source_remove(tv->idle_id);
779 thumb_loader_std_thumb_file_validate_free(tv);
782 static void thumb_loader_std_thumb_file_validate_finish(ThumbValidate *tv, gboolean valid)
784 if (tv->func_valid) tv->func_valid(tv->path, valid, tv->data);
786 thumb_loader_std_thumb_file_validate_free(tv);
789 static void thumb_loader_std_thumb_file_validate_done_cb(ThumbLoaderStd *tl, gpointer data)
791 ThumbValidate *tv = data;
793 gboolean valid = FALSE;
795 /* get the original thumbnail pixbuf (unrotated, with original options)
796 this is called from image_loader done callback, so tv->tl->il must exist*/
797 pixbuf = image_loader_get_pixbuf(tv->tl->il);
801 const gchar *mtime_str;
803 uri = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_URI);
804 mtime_str = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_MTIME);
805 if (uri && mtime_str)
807 if (strncmp(uri, "file:", strlen("file:")) == 0)
812 target = g_filename_from_uri(uri, NULL, NULL);
813 if (stat(target, &st) == 0 &&
814 st.st_mtime == strtol(mtime_str, NULL, 10))
824 DEBUG_1("thumb uri foreign, doing day check: %s", uri);
826 if (stat_utf8(tv->path, &st))
831 if (st.st_atime >= now - (time_t)tv->days * 24 * 60 * 60)
840 DEBUG_1("invalid image found in std cache: %s", tv->path);
844 thumb_loader_std_thumb_file_validate_finish(tv, valid);
847 static void thumb_loader_std_thumb_file_validate_error_cb(ThumbLoaderStd *tl, gpointer data)
849 ThumbValidate *tv = data;
851 thumb_loader_std_thumb_file_validate_finish(tv, FALSE);
854 static gboolean thumb_loader_std_thumb_file_validate_idle_cb(gpointer data)
856 ThumbValidate *tv = data;
859 thumb_loader_std_thumb_file_validate_finish(tv, FALSE);
864 ThumbLoaderStd *thumb_loader_std_thumb_file_validate(const gchar *thumb_path, gint allowed_days,
865 void (*func_valid)(const gchar *path, gboolean valid, gpointer data),
870 tv = g_new0(ThumbValidate, 1);
872 tv->tl = thumb_loader_std_new(THUMB_SIZE_LARGE, THUMB_SIZE_LARGE);
873 thumb_loader_std_set_callbacks(tv->tl,
874 thumb_loader_std_thumb_file_validate_done_cb,
875 thumb_loader_std_thumb_file_validate_error_cb,
878 thumb_loader_std_reset(tv->tl);
880 tv->path = g_strdup(thumb_path);
881 tv->days = allowed_days;
882 tv->func_valid = func_valid;
885 FileData *fd = file_data_new_no_grouping(thumb_path);
886 if (!thumb_loader_std_setup(tv->tl, fd))
888 tv->idle_id = g_idle_add(thumb_loader_std_thumb_file_validate_idle_cb, tv);
899 static void thumb_std_maint_remove_one(const gchar *source, const gchar *uri, gboolean local,
900 const gchar *subfolder)
904 thumb_path = thumb_std_cache_path(source,
905 (local) ? filename_from_path(uri) : uri,
907 if (isfile(thumb_path))
909 DEBUG_1("thumb removing: %s", thumb_path);
910 unlink_file(thumb_path);
915 /* this also removes local thumbnails (the source is gone so it makes sense) */
916 void thumb_std_maint_removed(const gchar *source)
921 sourcel = path_from_utf8(source);
922 uri = g_filename_to_uri(sourcel, NULL, NULL);
925 /* all this to remove a thumbnail? */
927 thumb_std_maint_remove_one(source, uri, FALSE, THUMB_FOLDER_NORMAL);
928 thumb_std_maint_remove_one(source, uri, FALSE, THUMB_FOLDER_LARGE);
929 thumb_std_maint_remove_one(source, uri, FALSE, THUMB_FOLDER_FAIL);
930 thumb_std_maint_remove_one(source, uri, TRUE, THUMB_FOLDER_NORMAL);
931 thumb_std_maint_remove_one(source, uri, TRUE, THUMB_FOLDER_LARGE);
936 typedef struct _TMaintMove TMaintMove;
949 static GList *thumb_std_maint_move_list = NULL;
950 static GList *thumb_std_maint_move_tail = NULL;
953 static void thumb_std_maint_move_step(TMaintMove *tm);
954 static gboolean thumb_std_maint_move_idle(gpointer data);
957 static void thumb_std_maint_move_validate_cb(const gchar *path, gboolean valid, gpointer data)
959 TMaintMove *tm = data;
962 /* get the original thumbnail pixbuf (unrotated, with original options)
963 this is called from image_loader done callback, so tm->tl->il must exist*/
964 pixbuf = image_loader_get_pixbuf(tm->tl->il);
968 const gchar *mtime_str;
970 uri = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_URI);
971 mtime_str = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_MTIME);
973 if (uri && mtime_str && strcmp(uri, tm->source_uri) == 0)
977 /* The validation utility abuses ThumbLoader, and we
978 * abuse the utility just to load the thumbnail,
979 * but the loader needs to look sane for the save to complete.
982 tm->tl->cache_enable = TRUE;
983 tm->tl->cache_hit = FALSE;
984 tm->tl->cache_local = FALSE;
985 file_data_unref(tm->tl->fd);
986 tm->tl->fd = file_data_new_group(tm->dest);
987 tm->tl->source_mtime = strtol(mtime_str, NULL, 10);
989 pathl = path_from_utf8(tm->tl->fd->path);
990 g_free(tm->tl->thumb_uri);
991 tm->tl->thumb_uri = g_filename_to_uri(pathl, NULL, NULL);
992 tm->tl->local_uri = filename_from_path(tm->tl->thumb_uri);
995 g_free(tm->tl->thumb_path);
996 tm->tl->thumb_path = NULL;
997 tm->tl->thumb_path_local = FALSE;
999 DEBUG_1("thumb move attempting save:");
1001 thumb_loader_std_save(tm->tl, pixbuf);
1004 DEBUG_1("thumb move unlink: %s", tm->thumb_path);
1005 unlink_file(tm->thumb_path);
1008 thumb_std_maint_move_step(tm);
1011 static void thumb_std_maint_move_step(TMaintMove *tm)
1013 const gchar *folder;
1020 g_free(tm->source_uri);
1021 g_free(tm->thumb_path);
1024 if (thumb_std_maint_move_list)
1026 g_idle_add_full(G_PRIORITY_LOW, thumb_std_maint_move_idle, NULL, NULL);
1032 folder = (tm->pass == 1) ? THUMB_FOLDER_NORMAL : THUMB_FOLDER_LARGE;
1034 g_free(tm->thumb_path);
1035 tm->thumb_path = thumb_std_cache_path(tm->source, tm->source_uri, FALSE, folder);
1036 tm->tl = thumb_loader_std_thumb_file_validate(tm->thumb_path, 0,
1037 thumb_std_maint_move_validate_cb, tm);
1040 static gboolean thumb_std_maint_move_idle(gpointer data)
1045 if (!thumb_std_maint_move_list) return FALSE;
1047 tm = thumb_std_maint_move_list->data;
1049 thumb_std_maint_move_list = g_list_remove(thumb_std_maint_move_list, tm);
1050 if (!thumb_std_maint_move_list) thumb_std_maint_move_tail = NULL;
1052 pathl = path_from_utf8(tm->source);
1053 tm->source_uri = g_filename_to_uri(pathl, NULL, NULL);
1058 thumb_std_maint_move_step(tm);
1063 /* This will schedule a move of the thumbnail for source image to dest when idle.
1064 * We do this so that file renaming or moving speed is not sacrificed by
1065 * moving the thumbnails at the same time because:
1067 * This cache design requires the tedious task of loading the png thumbnails and saving them.
1069 * The thumbnails are processed when the app is idle. If the app
1070 * exits early well too bad - they can simply be regenerated from scratch.
1072 * This does not manage local thumbnails (fixme ?)
1074 void thumb_std_maint_moved(const gchar *source, const gchar *dest)
1078 tm = g_new0(TMaintMove, 1);
1079 tm->source = g_strdup(source);
1080 tm->dest = g_strdup(dest);
1082 if (!thumb_std_maint_move_list)
1084 g_idle_add_full(G_PRIORITY_LOW, thumb_std_maint_move_idle, NULL, NULL);
1087 if (thumb_std_maint_move_tail)
1089 thumb_std_maint_move_tail = g_list_append(thumb_std_maint_move_tail, tm);
1090 thumb_std_maint_move_tail = thumb_std_maint_move_tail->next;
1094 thumb_std_maint_move_list = g_list_append(thumb_std_maint_move_list, tm);
1095 thumb_std_maint_move_tail = thumb_std_maint_move_list;
1098 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */