Mercurial > geeqie.yaz
annotate src/thumb_standard.c @ 865:8d0c91a0f461
do not read keywords and comment between exif_read_fd and exif_free_fd
calls (fd->exif does not have reference counting)
author | nadvornik |
---|---|
date | Fri, 27 Jun 2008 21:35:21 +0000 |
parents | f40509d56fe3 |
children | 2d8705f33da5 |
rev | line source |
---|---|
9 | 1 /* |
196 | 2 * Geeqie |
79
528e3432e0c0
Thu Oct 19 07:23:37 2006 John Ellis <johne@verizon.net>
gqview
parents:
66
diff
changeset
|
3 * (C) 2006 John Ellis |
475 | 4 * Copyright (C) 2008 The Geeqie Team |
9 | 5 * |
6 * Author: John Ellis | |
7 * | |
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! | |
11 */ | |
12 | |
13 | |
281 | 14 #include "main.h" |
9 | 15 #include "thumb_standard.h" |
16 | |
17 #include "cache.h" /* for cache_ensure_dir_exists */ | |
18 #include "image-load.h" | |
19 #include "md5-util.h" | |
20 #include "pixbuf_util.h" | |
21 #include "ui_fileops.h" | |
838 | 22 #include "filedata.h" |
839 | 23 #include "exif.h" |
9 | 24 |
25 | |
26 /* | |
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?) | |
32 * | |
33 * This code attempts to conform to version 0.7.0 of the standard. | |
34 * | |
35 * Notes: | |
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. | |
42 */ | |
43 | |
44 | |
45 #define THUMB_SIZE_NORMAL 128 | |
46 #define THUMB_SIZE_LARGE 256 | |
47 | |
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" | |
54 | |
55 #define THUMB_PERMS_FOLDER 0700 | |
56 #define THUMB_PERMS_THUMB 0600 | |
57 | |
58 | |
59 | |
60 /* | |
61 *----------------------------------------------------------------------------- | |
62 * thumbnail loader | |
63 *----------------------------------------------------------------------------- | |
64 */ | |
65 | |
66 | |
67 static void thumb_loader_std_error_cb(ImageLoader *il, gpointer data); | |
68 static gint thumb_loader_std_setup(ThumbLoaderStd *tl, const gchar *path); | |
69 | |
70 | |
71 ThumbLoaderStd *thumb_loader_std_new(gint width, gint height) | |
72 { | |
73 ThumbLoaderStd *tl; | |
74 | |
75 tl = g_new0(ThumbLoaderStd, 1); | |
76 | |
77 tl->standard_loader = TRUE; | |
78 | |
79 tl->requested_width = width; | |
80 tl->requested_height = height; | |
81 | |
82 tl->il = NULL; | |
838 | 83 tl->fd = NULL; |
9 | 84 |
333 | 85 tl->cache_enable = options->thumbnails.enable_caching; |
9 | 86 tl->cache_local = FALSE; |
87 tl->cache_retry = FALSE; | |
88 | |
89 return tl; | |
90 } | |
91 | |
92 void thumb_loader_std_set_callbacks(ThumbLoaderStd *tl, | |
93 ThumbLoaderStdFunc func_done, | |
94 ThumbLoaderStdFunc func_error, | |
95 ThumbLoaderStdFunc func_progress, | |
96 gpointer data) | |
97 { | |
98 if (!tl) return; | |
99 | |
100 tl->func_done = func_done; | |
101 tl->func_error = func_error; | |
102 tl->func_progress = func_progress; | |
103 tl->data = data; | |
104 } | |
105 | |
106 static void thumb_loader_std_reset(ThumbLoaderStd *tl) | |
107 { | |
108 image_loader_free(tl->il); | |
109 tl->il = NULL; | |
110 | |
838 | 111 file_data_unref(tl->fd); |
112 tl->fd = NULL; | |
9 | 113 |
114 g_free(tl->thumb_path); | |
115 tl->thumb_path = NULL; | |
116 | |
117 g_free(tl->thumb_uri); | |
118 tl->thumb_uri = NULL; | |
119 tl->local_uri = NULL; | |
120 | |
121 tl->thumb_path_local = FALSE; | |
122 | |
123 tl->cache_hit = FALSE; | |
124 | |
125 tl->source_mtime = 0; | |
126 tl->source_size = 0; | |
127 tl->source_mode = 0; | |
128 | |
129 tl->progress = 0.0; | |
130 } | |
131 | |
132 static gchar *thumb_std_cache_path(const gchar *path, const gchar *uri, gint local, | |
133 const gchar *cache_subfolder) | |
134 { | |
135 gchar *result = NULL; | |
136 gchar *md5_text; | |
137 guchar digest[16]; | |
716
c534b8cecc1f
thumb_std_cache_path(): use g_build_filename() and simplify.
zas_
parents:
671
diff
changeset
|
138 gchar *name; |
9 | 139 |
140 if (!path || !uri || !cache_subfolder) return NULL; | |
141 | |
716
c534b8cecc1f
thumb_std_cache_path(): use g_build_filename() and simplify.
zas_
parents:
671
diff
changeset
|
142 md5_get_digest((guchar *)uri, strlen(uri), digest); |
c534b8cecc1f
thumb_std_cache_path(): use g_build_filename() and simplify.
zas_
parents:
671
diff
changeset
|
143 md5_text = md5_digest_to_text(digest); |
c534b8cecc1f
thumb_std_cache_path(): use g_build_filename() and simplify.
zas_
parents:
671
diff
changeset
|
144 |
c534b8cecc1f
thumb_std_cache_path(): use g_build_filename() and simplify.
zas_
parents:
671
diff
changeset
|
145 if (!md5_text) return NULL; |
c534b8cecc1f
thumb_std_cache_path(): use g_build_filename() and simplify.
zas_
parents:
671
diff
changeset
|
146 |
c534b8cecc1f
thumb_std_cache_path(): use g_build_filename() and simplify.
zas_
parents:
671
diff
changeset
|
147 name = g_strconcat(md5_text, THUMB_NAME_EXTENSION, NULL); |
c534b8cecc1f
thumb_std_cache_path(): use g_build_filename() and simplify.
zas_
parents:
671
diff
changeset
|
148 |
9 | 149 if (local) |
150 { | |
716
c534b8cecc1f
thumb_std_cache_path(): use g_build_filename() and simplify.
zas_
parents:
671
diff
changeset
|
151 gchar *base = remove_level_from_path(path); |
9 | 152 |
716
c534b8cecc1f
thumb_std_cache_path(): use g_build_filename() and simplify.
zas_
parents:
671
diff
changeset
|
153 result = g_build_filename(base, THUMB_FOLDER_LOCAL, cache_subfolder, name, NULL); |
9 | 154 g_free(base); |
155 } | |
156 else | |
157 { | |
716
c534b8cecc1f
thumb_std_cache_path(): use g_build_filename() and simplify.
zas_
parents:
671
diff
changeset
|
158 result = g_build_filename(homedir(), THUMB_FOLDER_GLOBAL, cache_subfolder, name, NULL); |
9 | 159 } |
160 | |
716
c534b8cecc1f
thumb_std_cache_path(): use g_build_filename() and simplify.
zas_
parents:
671
diff
changeset
|
161 g_free(name); |
9 | 162 g_free(md5_text); |
163 | |
164 return result; | |
165 } | |
166 | |
167 static gchar *thumb_loader_std_cache_path(ThumbLoaderStd *tl, gint local, GdkPixbuf *pixbuf, gint fail) | |
168 { | |
436 | 169 const gchar *folder; |
9 | 170 gint w, h; |
171 | |
838 | 172 if (!tl->fd || !tl->thumb_uri) return NULL; |
9 | 173 |
174 if (pixbuf) | |
175 { | |
176 w = gdk_pixbuf_get_width(pixbuf); | |
177 h = gdk_pixbuf_get_height(pixbuf); | |
178 } | |
179 else | |
180 { | |
181 w = tl->requested_width; | |
182 h = tl->requested_height; | |
183 } | |
184 | |
185 if (fail) | |
186 { | |
436 | 187 folder = THUMB_FOLDER_FAIL; |
9 | 188 } |
189 else if (w > THUMB_SIZE_NORMAL || h > THUMB_SIZE_NORMAL) | |
190 { | |
436 | 191 folder = THUMB_FOLDER_LARGE; |
9 | 192 } |
193 else | |
194 { | |
436 | 195 folder = THUMB_FOLDER_NORMAL; |
9 | 196 } |
197 | |
838 | 198 return thumb_std_cache_path(tl->fd->path, |
9 | 199 (local) ? tl->local_uri : tl->thumb_uri, |
436 | 200 local, folder); |
9 | 201 } |
202 | |
203 static gint thumb_loader_std_fail_check(ThumbLoaderStd *tl) | |
204 { | |
205 gchar *fail_path; | |
206 gint result = FALSE; | |
207 | |
208 fail_path = thumb_loader_std_cache_path(tl, FALSE, NULL, TRUE); | |
209 if (isfile(fail_path)) | |
210 { | |
211 GdkPixbuf *pixbuf; | |
212 | |
213 if (tl->cache_retry) | |
214 { | |
215 pixbuf = NULL; | |
216 } | |
217 else | |
218 { | |
219 gchar *pathl; | |
220 | |
221 pathl = path_from_utf8(fail_path); | |
222 pixbuf = gdk_pixbuf_new_from_file(pathl, NULL); | |
223 g_free(pathl); | |
224 } | |
225 | |
226 if (pixbuf) | |
227 { | |
228 const gchar *mtime_str; | |
229 | |
230 mtime_str = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_MTIME); | |
231 if (mtime_str && strtol(mtime_str, NULL, 10) == tl->source_mtime) | |
232 { | |
233 result = TRUE; | |
838 | 234 DEBUG_1("thumb fail valid: %s", tl->fd->path); |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
495
diff
changeset
|
235 DEBUG_1(" thumb: %s", fail_path); |
9 | 236 } |
237 | |
238 g_object_unref(G_OBJECT(pixbuf)); | |
239 } | |
240 | |
241 if (!result) unlink_file(fail_path); | |
242 } | |
243 g_free(fail_path); | |
244 | |
245 return result; | |
246 } | |
247 | |
248 static gint thumb_loader_std_validate(ThumbLoaderStd *tl, GdkPixbuf *pixbuf) | |
249 { | |
250 const gchar *valid_uri; | |
251 const gchar *uri; | |
252 const gchar *mtime_str; | |
253 time_t mtime; | |
254 gint w, h; | |
255 | |
256 if (!pixbuf) return FALSE; | |
257 | |
258 w = gdk_pixbuf_get_width(pixbuf); | |
259 h = gdk_pixbuf_get_height(pixbuf); | |
260 | |
261 if (w != THUMB_SIZE_NORMAL && w != THUMB_SIZE_LARGE && | |
262 h != THUMB_SIZE_NORMAL && h != THUMB_SIZE_LARGE) return FALSE; | |
263 | |
264 valid_uri = (tl->thumb_path_local) ? tl->local_uri : tl->thumb_uri; | |
265 | |
266 uri = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_URI); | |
267 mtime_str = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_MTIME); | |
268 | |
269 if (!mtime_str || !uri || !valid_uri) return FALSE; | |
270 if (strcmp(uri, valid_uri) != 0) return FALSE; | |
271 | |
272 mtime = strtol(mtime_str, NULL, 10); | |
273 if (tl->source_mtime != mtime) return FALSE; | |
274 | |
275 return TRUE; | |
276 } | |
277 | |
278 static void thumb_loader_std_save(ThumbLoaderStd *tl, GdkPixbuf *pixbuf) | |
279 { | |
280 gchar *base_path; | |
281 gchar *tmp_path; | |
282 gint fail; | |
283 | |
284 if (!tl->cache_enable || tl->cache_hit) return; | |
285 if (tl->thumb_path) return; | |
286 | |
287 if (!pixbuf) | |
288 { | |
289 /* local failures are not stored */ | |
290 if (tl->cache_local) return; | |
291 | |
436 | 292 pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 1, 1); |
9 | 293 fail = TRUE; |
294 } | |
295 else | |
296 { | |
297 g_object_ref(G_OBJECT(pixbuf)); | |
298 fail = FALSE; | |
299 } | |
300 | |
301 tl->thumb_path = thumb_loader_std_cache_path(tl, tl->cache_local, pixbuf, fail); | |
302 if (!tl->thumb_path) | |
303 { | |
304 g_object_unref(G_OBJECT(pixbuf)); | |
305 return; | |
306 } | |
307 tl->thumb_path_local = tl->cache_local; | |
308 | |
309 /* create thumbnail dir if needed */ | |
310 base_path = remove_level_from_path(tl->thumb_path); | |
311 if (tl->cache_local) | |
312 { | |
313 if (!isdir(base_path)) | |
314 { | |
315 struct stat st; | |
316 gchar *source_base; | |
317 | |
838 | 318 source_base = remove_level_from_path(tl->fd->path); |
9 | 319 if (stat_utf8(source_base, &st)) |
320 { | |
321 cache_ensure_dir_exists(base_path, st.st_mode); | |
322 } | |
323 g_free(source_base); | |
324 } | |
325 } | |
326 else | |
327 { | |
328 cache_ensure_dir_exists(base_path, THUMB_PERMS_FOLDER); | |
329 } | |
330 g_free(base_path); | |
331 | |
838 | 332 DEBUG_1("thumb saving: %s", tl->fd->path); |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
495
diff
changeset
|
333 DEBUG_1(" saved: %s", tl->thumb_path); |
9 | 334 |
335 /* save thumb, using a temp file then renaming into place */ | |
336 tmp_path = unique_filename(tl->thumb_path, ".tmp", "_", 2); | |
337 if (tmp_path) | |
338 { | |
339 const gchar *mark_uri; | |
340 gchar *mark_app; | |
341 gchar *mark_mtime; | |
342 gchar *pathl; | |
343 gint success; | |
344 | |
345 mark_uri = (tl->cache_local) ? tl->local_uri :tl->thumb_uri; | |
346 | |
288
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
281
diff
changeset
|
347 mark_app = g_strdup_printf("%s %s", GQ_APPNAME, VERSION); |
9 | 348 mark_mtime = g_strdup_printf("%lu", tl->source_mtime); |
349 | |
350 pathl = path_from_utf8(tmp_path); | |
351 success = gdk_pixbuf_save(pixbuf, pathl, "png", NULL, | |
352 THUMB_MARKER_URI, mark_uri, | |
353 THUMB_MARKER_MTIME, mark_mtime, | |
354 THUMB_MARKER_APP, mark_app, | |
355 NULL); | |
356 if (success) | |
357 { | |
358 chmod(pathl, (tl->cache_local) ? tl->source_mode : THUMB_PERMS_THUMB); | |
359 success = rename_file(tmp_path, tl->thumb_path); | |
360 } | |
361 | |
362 g_free(pathl); | |
363 | |
364 g_free(mark_mtime); | |
365 g_free(mark_app); | |
366 | |
367 g_free(tmp_path); | |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
495
diff
changeset
|
368 if (!success) |
9 | 369 { |
838 | 370 DEBUG_1("thumb save failed: %s", tl->fd->path); |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
495
diff
changeset
|
371 DEBUG_1(" thumb: %s", tl->thumb_path); |
9 | 372 } |
373 | |
374 } | |
375 | |
376 g_object_unref(G_OBJECT(pixbuf)); | |
377 } | |
378 | |
14
25335c62cd9b
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
379 static GdkPixbuf *thumb_loader_std_finish(ThumbLoaderStd *tl, GdkPixbuf *pixbuf, gint shrunk) |
9 | 380 { |
381 GdkPixbuf *pixbuf_thumb = NULL; | |
382 GdkPixbuf *result; | |
839 | 383 GdkPixbuf *rotated = NULL; |
9 | 384 gint sw, sh; |
385 | |
839 | 386 |
387 if (!tl->cache_hit && options->image.exif_rotate_enable) | |
388 { | |
389 if (!tl->fd->exif_orientation) | |
390 { | |
391 ExifData *exif = exif_read_fd(tl->fd); | |
392 gint orientation; | |
393 | |
394 if (exif && exif_get_integer(exif, "Exif.Image.Orientation", &orientation)) | |
395 tl->fd->exif_orientation = orientation; | |
396 else | |
842
94048d7843ba
do not allocate new buffer for thumbnails with correct orientation
nadvornik
parents:
841
diff
changeset
|
397 tl->fd->exif_orientation = EXIF_ORIENTATION_TOP_LEFT; |
844 | 398 exif_free_fd(tl->fd, exif); |
839 | 399 } |
400 | |
842
94048d7843ba
do not allocate new buffer for thumbnails with correct orientation
nadvornik
parents:
841
diff
changeset
|
401 if (tl->fd->exif_orientation != EXIF_ORIENTATION_TOP_LEFT) |
94048d7843ba
do not allocate new buffer for thumbnails with correct orientation
nadvornik
parents:
841
diff
changeset
|
402 { |
94048d7843ba
do not allocate new buffer for thumbnails with correct orientation
nadvornik
parents:
841
diff
changeset
|
403 rotated = pixbuf_apply_orientation(pixbuf, tl->fd->exif_orientation); |
94048d7843ba
do not allocate new buffer for thumbnails with correct orientation
nadvornik
parents:
841
diff
changeset
|
404 pixbuf = rotated; |
94048d7843ba
do not allocate new buffer for thumbnails with correct orientation
nadvornik
parents:
841
diff
changeset
|
405 } |
839 | 406 } |
407 | |
9 | 408 sw = gdk_pixbuf_get_width(pixbuf); |
409 sh = gdk_pixbuf_get_height(pixbuf); | |
410 | |
40
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
411 if (tl->cache_enable) |
9 | 412 { |
40
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
413 if (!tl->cache_hit) |
9 | 414 { |
40
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
415 gint cache_w, cache_h; |
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
416 |
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
417 if (tl->requested_width > THUMB_SIZE_NORMAL || tl->requested_height > THUMB_SIZE_NORMAL) |
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
418 { |
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
419 cache_w = cache_h = THUMB_SIZE_LARGE; |
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
420 } |
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
421 else |
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
422 { |
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
423 cache_w = cache_h = THUMB_SIZE_NORMAL; |
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
424 } |
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
425 |
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
426 if (sw > cache_w || sh > cache_h || shrunk) |
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
427 { |
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
428 gint thumb_w, thumb_h; |
9 | 429 |
864 | 430 if (pixbuf_scale_aspect(cache_w, cache_h, sw, sh, |
40
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
431 &thumb_w, &thumb_h)) |
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
432 { |
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
433 pixbuf_thumb = gdk_pixbuf_scale_simple(pixbuf, thumb_w, thumb_h, |
333 | 434 (GdkInterpType)options->thumbnails.quality); |
40
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
435 } |
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
436 else |
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
437 { |
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
438 pixbuf_thumb = pixbuf; |
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
439 g_object_ref(G_OBJECT(pixbuf_thumb)); |
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
440 } |
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
441 |
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
442 thumb_loader_std_save(tl, pixbuf_thumb); |
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
443 } |
9 | 444 } |
40
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
445 else if (tl->cache_hit && |
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
446 tl->cache_local && !tl->thumb_path_local) |
9 | 447 { |
40
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
448 /* A local cache save was requested, but a valid thumb is in $HOME, |
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
449 * so specifically save as a local thumbnail. |
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
450 */ |
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
451 g_free(tl->thumb_path); |
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
452 tl->thumb_path = NULL; |
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
453 |
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
454 tl->cache_hit = FALSE; |
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
455 |
838 | 456 DEBUG_1("thumb copied: %s", tl->fd->path); |
40
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
457 |
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
458 thumb_loader_std_save(tl, pixbuf); |
9 | 459 } |
460 } | |
461 | |
462 if (sw <= tl->requested_width && sh <= tl->requested_height) | |
463 { | |
464 result = pixbuf; | |
465 g_object_ref(result); | |
466 } | |
467 else | |
468 { | |
469 gint thumb_w, thumb_h; | |
470 | |
471 if (pixbuf_thumb) | |
472 { | |
473 pixbuf = pixbuf_thumb; | |
474 sw = gdk_pixbuf_get_width(pixbuf); | |
475 sh = gdk_pixbuf_get_height(pixbuf); | |
476 } | |
477 | |
864 | 478 if (pixbuf_scale_aspect(tl->requested_width, tl->requested_height, sw, sh, |
9 | 479 &thumb_w, &thumb_h)) |
480 { | |
481 result = gdk_pixbuf_scale_simple(pixbuf, thumb_w, thumb_h, | |
333 | 482 (GdkInterpType)options->thumbnails.quality); |
9 | 483 } |
484 else | |
485 { | |
486 result = pixbuf; | |
487 g_object_ref(result); | |
488 } | |
489 } | |
490 | |
491 if (pixbuf_thumb) g_object_unref(pixbuf_thumb); | |
839 | 492 if (rotated) g_object_unref(rotated); |
9 | 493 |
494 return result; | |
495 } | |
496 | |
497 static gint thumb_loader_std_next_source(ThumbLoaderStd *tl, gint remove_broken) | |
498 { | |
499 image_loader_free(tl->il); | |
500 tl->il = NULL; | |
501 | |
502 if (tl->thumb_path) | |
503 { | |
504 if (!tl->thumb_path_local && remove_broken) | |
505 { | |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
495
diff
changeset
|
506 DEBUG_1("thumb broken, unlinking: %s", tl->thumb_path); |
9 | 507 unlink_file(tl->thumb_path); |
508 } | |
509 | |
510 g_free(tl->thumb_path); | |
511 tl->thumb_path = NULL; | |
512 | |
513 if (!tl->thumb_path_local) | |
514 { | |
515 tl->thumb_path = thumb_loader_std_cache_path(tl, TRUE, NULL, FALSE); | |
516 if (isfile(tl->thumb_path) && thumb_loader_std_setup(tl, tl->thumb_path)) | |
517 { | |
518 tl->thumb_path_local = TRUE; | |
519 return TRUE; | |
520 } | |
521 | |
522 g_free(tl->thumb_path); | |
523 tl->thumb_path = NULL; | |
524 } | |
525 | |
838 | 526 if (thumb_loader_std_setup(tl, tl->fd->path)) return TRUE; |
9 | 527 } |
528 | |
529 thumb_loader_std_save(tl, NULL); | |
530 return FALSE; | |
531 } | |
532 | |
533 static void thumb_loader_std_done_cb(ImageLoader *il, gpointer data) | |
534 { | |
535 ThumbLoaderStd *tl = data; | |
536 GdkPixbuf *pixbuf; | |
537 | |
838 | 538 DEBUG_1("thumb image done: %s", tl->fd->path); |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
495
diff
changeset
|
539 DEBUG_1(" from: %s", tl->il->path); |
9 | 540 |
541 pixbuf = image_loader_get_pixbuf(tl->il); | |
542 if (!pixbuf) | |
543 { | |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
495
diff
changeset
|
544 DEBUG_1("...but no pixbuf"); |
9 | 545 thumb_loader_std_error_cb(il, data); |
546 return; | |
547 } | |
548 | |
549 if (tl->thumb_path && !thumb_loader_std_validate(tl, pixbuf)) | |
550 { | |
551 if (thumb_loader_std_next_source(tl, TRUE)) return; | |
552 | |
553 if (tl->func_error) tl->func_error(tl, tl->data); | |
554 return; | |
555 } | |
556 | |
557 tl->cache_hit = (tl->thumb_path != NULL); | |
558 | |
838 | 559 if (tl->fd) |
560 { | |
845 | 561 if (tl->fd->thumb_pixbuf) g_object_unref(tl->fd->thumb_pixbuf); |
562 tl->fd->thumb_pixbuf = thumb_loader_std_finish(tl, pixbuf, il->shrunk); | |
838 | 563 } |
9 | 564 |
565 if (tl->func_done) tl->func_done(tl, tl->data); | |
566 } | |
567 | |
568 static void thumb_loader_std_error_cb(ImageLoader *il, gpointer data) | |
569 { | |
570 ThumbLoaderStd *tl = data; | |
571 | |
572 /* if at least some of the image is available, go to done */ | |
573 if (image_loader_get_pixbuf(tl->il) != NULL) | |
574 { | |
575 thumb_loader_std_done_cb(il, data); | |
576 return; | |
577 } | |
495 | 578 |
838 | 579 DEBUG_1("thumb image error: %s", tl->fd->path); |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
495
diff
changeset
|
580 DEBUG_1(" from: %s", tl->il->fd->path); |
9 | 581 |
582 if (thumb_loader_std_next_source(tl, TRUE)) return; | |
583 | |
584 if (tl->func_error) tl->func_error(tl, tl->data); | |
585 } | |
586 | |
587 static void thumb_loader_std_progress_cb(ImageLoader *il, gdouble percent, gpointer data) | |
588 { | |
589 ThumbLoaderStd *tl = data; | |
590 | |
591 tl->progress = (gdouble)percent; | |
592 | |
593 if (tl->func_progress) tl->func_progress(tl, tl->data); | |
594 } | |
595 | |
596 static gint thumb_loader_std_setup(ThumbLoaderStd *tl, const gchar *path) | |
597 { | |
138 | 598 tl->il = image_loader_new_from_path(path); |
9 | 599 |
333 | 600 if (options->thumbnails.fast) |
9 | 601 { |
14
25335c62cd9b
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
602 /* this will speed up jpegs by up to 3x in some cases */ |
25335c62cd9b
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
603 if (tl->requested_width <= THUMB_SIZE_NORMAL && |
25335c62cd9b
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
604 tl->requested_height <= THUMB_SIZE_NORMAL) |
25335c62cd9b
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
605 { |
25335c62cd9b
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
606 image_loader_set_requested_size(tl->il, THUMB_SIZE_NORMAL, THUMB_SIZE_NORMAL); |
25335c62cd9b
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
607 } |
25335c62cd9b
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
608 else |
25335c62cd9b
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
609 { |
25335c62cd9b
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
610 image_loader_set_requested_size(tl->il, THUMB_SIZE_LARGE, THUMB_SIZE_LARGE); |
25335c62cd9b
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
611 } |
9 | 612 } |
613 | |
614 image_loader_set_error_func(tl->il, thumb_loader_std_error_cb, tl); | |
615 if (tl->func_progress) | |
616 { | |
617 image_loader_set_percent_func(tl->il, thumb_loader_std_progress_cb, tl); | |
618 } | |
619 | |
620 if (image_loader_start(tl->il, thumb_loader_std_done_cb, tl)) | |
621 { | |
622 return TRUE; | |
623 } | |
624 | |
625 image_loader_free(tl->il); | |
626 tl->il = NULL; | |
627 return FALSE; | |
628 } | |
629 | |
630 /* | |
631 * Note: Currently local_cache only specifies where to save a _new_ thumb, if | |
632 * a valid existing thumb is found anywhere the local thumb will not be created. | |
633 */ | |
634 void thumb_loader_std_set_cache(ThumbLoaderStd *tl, gint enable_cache, gint local, gint retry_failed) | |
635 { | |
636 if (!tl) return; | |
637 | |
638 tl->cache_enable = enable_cache; | |
639 tl->cache_local = local; | |
640 tl->cache_retry = retry_failed; | |
641 } | |
642 | |
838 | 643 gint thumb_loader_std_start(ThumbLoaderStd *tl, FileData *fd) |
9 | 644 { |
645 static gchar *thumb_cache = NULL; | |
646 struct stat st; | |
647 | |
838 | 648 if (!tl || !fd) return FALSE; |
9 | 649 |
650 thumb_loader_std_reset(tl); | |
864 | 651 |
652 if (fd->thumb_pixbuf) g_object_unref(fd->thumb_pixbuf); | |
653 fd->thumb_pixbuf = pixbuf_fallback(fd, tl->requested_width, tl->requested_height); | |
654 | |
9 | 655 |
838 | 656 if (!stat_utf8(fd->path, &st)) return FALSE; |
9 | 657 |
838 | 658 tl->fd = file_data_ref(fd); |
9 | 659 tl->source_mtime = st.st_mtime; |
660 tl->source_size = st.st_size; | |
661 tl->source_mode = st.st_mode; | |
662 | |
717 | 663 if (!thumb_cache) thumb_cache = g_build_filename(homedir(), THUMB_FOLDER_GLOBAL, NULL); |
838 | 664 if (strncmp(tl->fd->path, thumb_cache, strlen(thumb_cache)) != 0) |
9 | 665 { |
666 gchar *pathl; | |
667 | |
838 | 668 pathl = path_from_utf8(fd->path); |
9 | 669 tl->thumb_uri = g_filename_to_uri(pathl, NULL, NULL); |
670 tl->local_uri = filename_from_path(tl->thumb_uri); | |
671 g_free(pathl); | |
672 } | |
673 | |
674 if (tl->cache_enable) | |
675 { | |
676 gint found; | |
677 | |
678 tl->thumb_path = thumb_loader_std_cache_path(tl, FALSE, NULL, FALSE); | |
679 tl->thumb_path_local = FALSE; | |
680 | |
681 found = isfile(tl->thumb_path); | |
682 if (found && thumb_loader_std_setup(tl, tl->thumb_path)) return TRUE; | |
683 | |
43
ee03f36e9e4b
Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
40
diff
changeset
|
684 if (thumb_loader_std_fail_check(tl)) return FALSE; |
ee03f36e9e4b
Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
40
diff
changeset
|
685 |
9 | 686 return thumb_loader_std_next_source(tl, found); |
687 } | |
688 | |
838 | 689 if (!thumb_loader_std_setup(tl, tl->fd->path)) |
9 | 690 { |
691 thumb_loader_std_save(tl, NULL); | |
692 return FALSE; | |
693 } | |
694 | |
695 return TRUE; | |
696 } | |
697 | |
698 void thumb_loader_std_free(ThumbLoaderStd *tl) | |
699 { | |
700 if (!tl) return; | |
701 | |
702 thumb_loader_std_reset(tl); | |
703 g_free(tl); | |
704 } | |
705 | |
864 | 706 GdkPixbuf *thumb_loader_std_get_pixbuf(ThumbLoaderStd *tl) |
9 | 707 { |
708 GdkPixbuf *pixbuf; | |
709 | |
845 | 710 if (tl && tl->fd && tl->fd->thumb_pixbuf) |
9 | 711 { |
845 | 712 pixbuf = tl->fd->thumb_pixbuf; |
9 | 713 g_object_ref(pixbuf); |
714 } | |
715 else | |
716 { | |
864 | 717 pixbuf = pixbuf_fallback(NULL, tl->requested_width, tl->requested_height); |
9 | 718 } |
719 | |
720 return pixbuf; | |
721 } | |
722 | |
723 | |
724 typedef struct _ThumbValidate ThumbValidate; | |
725 struct _ThumbValidate | |
726 { | |
727 ThumbLoaderStd *tl; | |
728 gchar *path; | |
729 gint days; | |
730 | |
731 void (*func_valid)(const gchar *path, gint valid, gpointer data); | |
732 gpointer data; | |
733 | |
734 gint idle_id; | |
735 }; | |
736 | |
737 static void thumb_loader_std_thumb_file_validate_free(ThumbValidate *tv) | |
738 { | |
739 thumb_loader_std_free(tv->tl); | |
740 g_free(tv->path); | |
741 g_free(tv); | |
742 } | |
743 | |
744 void thumb_loader_std_thumb_file_validate_cancel(ThumbLoaderStd *tl) | |
745 { | |
746 ThumbValidate *tv; | |
747 | |
748 if (!tl) return; | |
749 | |
750 tv = tl->data; | |
751 | |
752 if (tv->idle_id != -1) g_source_remove(tv->idle_id); | |
753 tv->idle_id = -1; | |
754 | |
755 thumb_loader_std_thumb_file_validate_free(tv); | |
756 } | |
757 | |
758 static void thumb_loader_std_thumb_file_validate_finish(ThumbValidate *tv, gint valid) | |
759 { | |
760 if (tv->func_valid) tv->func_valid(tv->path, valid, tv->data); | |
761 | |
762 thumb_loader_std_thumb_file_validate_free(tv); | |
763 } | |
764 | |
765 static void thumb_loader_std_thumb_file_validate_done_cb(ThumbLoaderStd *tl, gpointer data) | |
766 { | |
767 ThumbValidate *tv = data; | |
768 GdkPixbuf *pixbuf; | |
769 gint valid = FALSE; | |
770 | |
864 | 771 /* this function is called on success, so the pixbuf should not be a fallback*/ |
772 pixbuf = thumb_loader_std_get_pixbuf(tv->tl); | |
9 | 773 if (pixbuf) |
774 { | |
775 const gchar *uri; | |
776 const gchar *mtime_str; | |
777 | |
778 uri = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_URI); | |
779 mtime_str = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_MTIME); | |
780 if (uri && mtime_str) | |
781 { | |
782 if (strncmp(uri, "file:", strlen("file:")) == 0) | |
783 { | |
784 struct stat st; | |
785 gchar *target; | |
786 | |
787 target = g_filename_from_uri(uri, NULL, NULL); | |
788 if (stat(target, &st) == 0 && | |
789 st.st_mtime == strtol(mtime_str, NULL, 10)) | |
790 { | |
791 valid = TRUE; | |
792 } | |
793 g_free(target); | |
794 } | |
795 else | |
796 { | |
797 struct stat st; | |
798 | |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
495
diff
changeset
|
799 DEBUG_1("thumb uri foreign, doing day check: %s", uri); |
9 | 800 |
801 if (stat_utf8(tv->path, &st)) | |
802 { | |
803 time_t now; | |
804 | |
805 now = time(NULL); | |
806 if (st.st_atime >= now - (time_t)tv->days * 24 * 60 * 60) | |
807 { | |
808 valid = TRUE; | |
809 } | |
810 } | |
811 } | |
812 } | |
813 | |
814 g_object_unref(pixbuf); | |
815 } | |
816 | |
817 thumb_loader_std_thumb_file_validate_finish(tv, valid); | |
818 } | |
819 | |
820 static void thumb_loader_std_thumb_file_validate_error_cb(ThumbLoaderStd *tl, gpointer data) | |
821 { | |
822 ThumbValidate *tv = data; | |
823 | |
824 thumb_loader_std_thumb_file_validate_finish(tv, FALSE); | |
825 } | |
826 | |
827 static gint thumb_loader_std_thumb_file_validate_idle_cb(gpointer data) | |
828 { | |
829 ThumbValidate *tv = data; | |
830 | |
831 tv->idle_id = -1; | |
832 thumb_loader_std_thumb_file_validate_finish(tv, FALSE); | |
833 | |
834 return FALSE; | |
835 } | |
836 | |
837 ThumbLoaderStd *thumb_loader_std_thumb_file_validate(const gchar *thumb_path, gint allowed_days, | |
838 void (*func_valid)(const gchar *path, gint valid, gpointer data), | |
839 gpointer data) | |
840 { | |
841 ThumbValidate *tv; | |
842 | |
843 tv = g_new0(ThumbValidate, 1); | |
844 | |
845 tv->tl = thumb_loader_std_new(THUMB_SIZE_LARGE, THUMB_SIZE_LARGE); | |
846 thumb_loader_std_set_callbacks(tv->tl, | |
847 thumb_loader_std_thumb_file_validate_done_cb, | |
848 thumb_loader_std_thumb_file_validate_error_cb, | |
849 NULL, | |
850 tv); | |
851 thumb_loader_std_reset(tv->tl); | |
852 | |
853 tv->path = g_strdup(thumb_path); | |
854 tv->days = allowed_days; | |
855 tv->func_valid = func_valid; | |
856 tv->data = data; | |
857 | |
858 if (!thumb_loader_std_setup(tv->tl, thumb_path)) | |
859 { | |
860 tv->idle_id = g_idle_add(thumb_loader_std_thumb_file_validate_idle_cb, tv); | |
861 } | |
862 else | |
863 { | |
864 tv->idle_id = -1; | |
865 } | |
866 | |
867 return tv->tl; | |
868 } | |
869 | |
870 static void thumb_std_maint_remove_one(const gchar *source, const gchar *uri, gint local, | |
871 const gchar *subfolder) | |
872 { | |
873 gchar *thumb_path; | |
874 | |
875 thumb_path = thumb_std_cache_path(source, | |
876 (local) ? filename_from_path(uri) : uri, | |
877 local, subfolder); | |
878 if (isfile(thumb_path)) | |
879 { | |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
495
diff
changeset
|
880 DEBUG_1("thumb removing: %s", thumb_path); |
9 | 881 unlink_file(thumb_path); |
882 } | |
883 g_free(thumb_path); | |
884 } | |
885 | |
886 /* this also removes local thumbnails (the source is gone so it makes sense) */ | |
887 void thumb_std_maint_removed(const gchar *source) | |
888 { | |
889 gchar *uri; | |
890 gchar *sourcel; | |
891 | |
892 sourcel = path_from_utf8(source); | |
893 uri = g_filename_to_uri(sourcel, NULL, NULL); | |
894 g_free(sourcel); | |
895 | |
896 /* all this to remove a thumbnail? */ | |
897 | |
898 thumb_std_maint_remove_one(source, uri, FALSE, THUMB_FOLDER_NORMAL); | |
899 thumb_std_maint_remove_one(source, uri, FALSE, THUMB_FOLDER_LARGE); | |
900 thumb_std_maint_remove_one(source, uri, FALSE, THUMB_FOLDER_FAIL); | |
901 thumb_std_maint_remove_one(source, uri, TRUE, THUMB_FOLDER_NORMAL); | |
902 thumb_std_maint_remove_one(source, uri, TRUE, THUMB_FOLDER_LARGE); | |
903 | |
904 g_free(uri); | |
905 } | |
906 | |
907 typedef struct _TMaintMove TMaintMove; | |
908 struct _TMaintMove | |
909 { | |
910 gchar *source; | |
911 gchar *dest; | |
912 | |
913 ThumbLoaderStd *tl; | |
914 gchar *source_uri; | |
915 gchar *thumb_path; | |
916 | |
917 gint pass; | |
918 }; | |
919 | |
920 static GList *thumb_std_maint_move_list = NULL; | |
921 static GList *thumb_std_maint_move_tail = NULL; | |
922 | |
923 | |
924 static void thumb_std_maint_move_step(TMaintMove *tm); | |
925 static gint thumb_std_maint_move_idle(gpointer data); | |
926 | |
927 | |
928 static void thumb_std_maint_move_validate_cb(const gchar *path, gint valid, gpointer data) | |
929 { | |
930 TMaintMove *tm = data; | |
931 GdkPixbuf *pixbuf; | |
932 | |
864 | 933 /* this function is called on success, so the pixbuf should not be a fallback*/ |
934 pixbuf = thumb_loader_std_get_pixbuf(tm->tl); | |
9 | 935 if (pixbuf) |
936 { | |
937 const gchar *uri; | |
938 const gchar *mtime_str; | |
939 | |
940 uri = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_URI); | |
941 mtime_str = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_MTIME); | |
942 | |
943 if (uri && mtime_str && strcmp(uri, tm->source_uri) == 0) | |
944 { | |
945 gchar *pathl; | |
946 | |
947 /* The validation utility abuses ThumbLoader, and we | |
948 * abuse the utility just to load the thumbnail, | |
949 * but the loader needs to look sane for the save to complete. | |
950 */ | |
951 | |
952 tm->tl->cache_enable = TRUE; | |
953 tm->tl->cache_hit = FALSE; | |
954 tm->tl->cache_local = FALSE; | |
955 | |
838 | 956 file_data_unref(tm->tl->fd); |
957 tm->tl->fd = file_data_new_simple(tm->dest); | |
9 | 958 tm->tl->source_mtime = strtol(mtime_str, NULL, 10); |
959 | |
838 | 960 pathl = path_from_utf8(tm->tl->fd->path); |
9 | 961 g_free(tm->tl->thumb_uri); |
962 tm->tl->thumb_uri = g_filename_to_uri(pathl, NULL, NULL); | |
963 tm->tl->local_uri = filename_from_path(tm->tl->thumb_uri); | |
964 g_free(pathl); | |
965 | |
966 g_free(tm->tl->thumb_path); | |
967 tm->tl->thumb_path = NULL; | |
968 tm->tl->thumb_path_local = FALSE; | |
969 | |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
495
diff
changeset
|
970 DEBUG_1("thumb move attempting save:"); |
9 | 971 |
972 thumb_loader_std_save(tm->tl, pixbuf); | |
973 } | |
974 | |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
495
diff
changeset
|
975 DEBUG_1("thumb move unlink: %s", tm->thumb_path); |
9 | 976 unlink_file(tm->thumb_path); |
864 | 977 g_object_unref(pixbuf); |
9 | 978 } |
979 | |
980 thumb_std_maint_move_step(tm); | |
981 } | |
982 | |
983 static void thumb_std_maint_move_step(TMaintMove *tm) | |
984 { | |
985 const gchar *folder; | |
986 | |
987 tm->pass++; | |
988 if (tm->pass > 2) | |
989 { | |
990 g_free(tm->source); | |
991 g_free(tm->dest); | |
992 g_free(tm->source_uri); | |
993 g_free(tm->thumb_path); | |
994 g_free(tm); | |
995 | |
996 if (thumb_std_maint_move_list) | |
997 { | |
998 g_idle_add_full(G_PRIORITY_LOW, thumb_std_maint_move_idle, NULL, NULL); | |
999 } | |
1000 | |
1001 return; | |
1002 } | |
1003 | |
1004 folder = (tm->pass == 1) ? THUMB_FOLDER_NORMAL : THUMB_FOLDER_LARGE; | |
442 | 1005 |
9 | 1006 g_free(tm->thumb_path); |
1007 tm->thumb_path = thumb_std_cache_path(tm->source, tm->source_uri, FALSE, folder); | |
1008 tm->tl = thumb_loader_std_thumb_file_validate(tm->thumb_path, 0, | |
1009 thumb_std_maint_move_validate_cb, tm); | |
1010 } | |
1011 | |
1012 static gint thumb_std_maint_move_idle(gpointer data) | |
1013 { | |
1014 TMaintMove *tm; | |
1015 gchar *pathl; | |
1016 | |
1017 if (!thumb_std_maint_move_list) return FALSE; | |
1018 | |
1019 tm = thumb_std_maint_move_list->data; | |
1020 | |
1021 thumb_std_maint_move_list = g_list_remove(thumb_std_maint_move_list, tm); | |
1022 if (!thumb_std_maint_move_list) thumb_std_maint_move_tail = NULL; | |
1023 | |
1024 pathl = path_from_utf8(tm->source); | |
1025 tm->source_uri = g_filename_to_uri(pathl, NULL, NULL); | |
1026 g_free(pathl); | |
1027 | |
1028 tm->pass = 0; | |
1029 | |
1030 thumb_std_maint_move_step(tm); | |
1031 | |
1032 return FALSE; | |
1033 } | |
1034 | |
1035 /* This will schedule a move of the thumbnail for source image to dest when idle. | |
1036 * We do this so that file renaming or moving speed is not sacrificed by | |
1037 * moving the thumbnails at the same time because: | |
1038 * | |
1039 * This cache design requires the tedious task of loading the png thumbnails and saving them. | |
1040 * | |
1041 * The thumbnails are processed when the app is idle. If the app | |
1042 * exits early well too bad - they can simply be regenerated from scratch. | |
1043 * | |
1044 * This does not manage local thumbnails (fixme ?) | |
1045 */ | |
1046 void thumb_std_maint_moved(const gchar *source, const gchar *dest) | |
1047 { | |
1048 TMaintMove *tm; | |
1049 | |
1050 tm = g_new0(TMaintMove, 1); | |
1051 tm->source = g_strdup(source); | |
1052 tm->dest = g_strdup(dest); | |
1053 | |
1054 if (!thumb_std_maint_move_list) | |
1055 { | |
1056 g_idle_add_full(G_PRIORITY_LOW, thumb_std_maint_move_idle, NULL, NULL); | |
1057 } | |
1058 | |
827 | 1059 if (thumb_std_maint_move_tail) |
1060 { | |
1061 thumb_std_maint_move_tail = g_list_append(thumb_std_maint_move_tail, tm); | |
1062 thumb_std_maint_move_tail = thumb_std_maint_move_tail->next; | |
1063 } | |
1064 else | |
1065 { | |
1066 thumb_std_maint_move_list = g_list_append(thumb_std_maint_move_list, tm); | |
1067 thumb_std_maint_move_tail = thumb_std_maint_move_list; | |
1068 } | |
9 | 1069 } |