Mercurial > hg > forks > geeqie
annotate src/thumb_standard.c @ 2916:ae6cdcd69d9f default tip
Merge with upstream/master.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 14 May 2019 11:46:50 +0300 |
parents | ea4163f0c769 |
children |
rev | line source |
---|---|
9 | 1 /* |
2350
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2185
diff
changeset
|
2 * Copyright (C) 2006 John Ellis |
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2185
diff
changeset
|
3 * Copyright (C) 2008 - 2016 The Geeqie Team |
9 | 4 * |
5 * Author: John Ellis | |
6 * | |
2350
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2185
diff
changeset
|
7 * This program is free software; you can redistribute it and/or modify |
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2185
diff
changeset
|
8 * it under the terms of the GNU General Public License as published by |
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2185
diff
changeset
|
9 * the Free Software Foundation; either version 2 of the License, or |
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2185
diff
changeset
|
10 * (at your option) any later version. |
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2185
diff
changeset
|
11 * |
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2185
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, |
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2185
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2185
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2185
diff
changeset
|
15 * GNU General Public License for more details. |
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2185
diff
changeset
|
16 * |
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2185
diff
changeset
|
17 * You should have received a copy of the GNU General Public License along |
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2185
diff
changeset
|
18 * with this program; if not, write to the Free Software Foundation, Inc., |
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2185
diff
changeset
|
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
9 | 20 */ |
21 | |
281 | 22 #include "main.h" |
9 | 23 #include "thumb_standard.h" |
24 | |
2566
034d8772d6d8
Fix #500: Geeqie doesn’t use shared thumbnail folder
Colin Clark <colin.clark@cclark.uk>
parents:
2350
diff
changeset
|
25 #include "cache.h" |
9 | 26 #include "image-load.h" |
27 #include "md5-util.h" | |
28 #include "pixbuf_util.h" | |
29 #include "ui_fileops.h" | |
838
fd3a200281f6
use FileData in thumb_loader
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
827
diff
changeset
|
30 #include "filedata.h" |
839
74af80c4c972
rotate thumbnails by exif
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
838
diff
changeset
|
31 #include "exif.h" |
1288
01a4a8674c8b
use metadata_read_* functions where possible
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1284
diff
changeset
|
32 #include "metadata.h" |
9 | 33 |
34 | |
35 /* | |
36 * This thumbnail caching implementation attempts to conform | |
37 * to the Thumbnail Managing Standard proposed on freedesktop.org | |
38 * The standard is documented here: | |
39 * http://triq.net/~jens/thumbnail-spec/index.html | |
40 * (why isn't it actually hosted on freedesktop.org?) | |
41 * | |
42 * This code attempts to conform to version 0.7.0 of the standard. | |
43 * | |
44 * Notes: | |
45 * > Validation of the thumb's embedded uri is a simple strcmp between our | |
46 * version of the escaped uri and the thumb's escaped uri. But not all uri | |
47 * escape functions escape the same set of chars, comparing the unescaped | |
48 * versions may be more accurate. | |
49 * > Only Thumb::URI and Thumb::MTime are stored in a thumb at this time. | |
50 * Storing the Size, Width, Height should probably be implemented. | |
51 */ | |
52 | |
53 | |
54 #define THUMB_SIZE_NORMAL 128 | |
55 #define THUMB_SIZE_LARGE 256 | |
56 | |
57 #define THUMB_MARKER_URI "tEXt::Thumb::URI" | |
58 #define THUMB_MARKER_MTIME "tEXt::Thumb::MTime" | |
59 #define THUMB_MARKER_SIZE "tEXt::Thumb::Size" | |
60 #define THUMB_MARKER_WIDTH "tEXt::Thumb::Image::Width" | |
61 #define THUMB_MARKER_HEIGHT "tEXt::Thumb::Image::Height" | |
62 #define THUMB_MARKER_APP "tEXt::Software" | |
63 | |
64 #define THUMB_PERMS_FOLDER 0700 | |
65 #define THUMB_PERMS_THUMB 0600 | |
66 | |
67 | |
68 | |
69 /* | |
70 *----------------------------------------------------------------------------- | |
71 * thumbnail loader | |
72 *----------------------------------------------------------------------------- | |
73 */ | |
74 | |
75 | |
76 static void thumb_loader_std_error_cb(ImageLoader *il, gpointer data); | |
1009
5847765e8189
fixed thumbnail loader for the new raw preview interface
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
972
diff
changeset
|
77 static gint thumb_loader_std_setup(ThumbLoaderStd *tl, FileData *fd); |
9 | 78 |
79 | |
80 ThumbLoaderStd *thumb_loader_std_new(gint width, gint height) | |
81 { | |
82 ThumbLoaderStd *tl; | |
83 | |
84 tl = g_new0(ThumbLoaderStd, 1); | |
85 | |
86 tl->standard_loader = TRUE; | |
87 tl->requested_width = width; | |
88 tl->requested_height = height; | |
333
1ebdf8fb2c1a
Rename thumbnails related options.
Laurent Monin <geeqie@norz.org>
parents:
318
diff
changeset
|
89 tl->cache_enable = options->thumbnails.enable_caching; |
9 | 90 |
91 return tl; | |
92 } | |
93 | |
94 void thumb_loader_std_set_callbacks(ThumbLoaderStd *tl, | |
95 ThumbLoaderStdFunc func_done, | |
96 ThumbLoaderStdFunc func_error, | |
97 ThumbLoaderStdFunc func_progress, | |
98 gpointer data) | |
99 { | |
100 if (!tl) return; | |
101 | |
102 tl->func_done = func_done; | |
103 tl->func_error = func_error; | |
104 tl->func_progress = func_progress; | |
105 tl->data = data; | |
106 } | |
107 | |
108 static void thumb_loader_std_reset(ThumbLoaderStd *tl) | |
109 { | |
110 image_loader_free(tl->il); | |
111 tl->il = NULL; | |
112 | |
838
fd3a200281f6
use FileData in thumb_loader
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
827
diff
changeset
|
113 file_data_unref(tl->fd); |
fd3a200281f6
use FileData in thumb_loader
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
827
diff
changeset
|
114 tl->fd = NULL; |
9 | 115 |
116 g_free(tl->thumb_path); | |
117 tl->thumb_path = NULL; | |
118 | |
119 g_free(tl->thumb_uri); | |
120 tl->thumb_uri = NULL; | |
121 tl->local_uri = NULL; | |
122 | |
123 tl->thumb_path_local = FALSE; | |
124 | |
125 tl->cache_hit = FALSE; | |
126 | |
127 tl->source_mtime = 0; | |
128 tl->source_size = 0; | |
129 tl->source_mode = 0; | |
130 | |
131 tl->progress = 0.0; | |
132 } | |
133 | |
1446 | 134 static gchar *thumb_std_cache_path(const gchar *path, const gchar *uri, gboolean local, |
9 | 135 const gchar *cache_subfolder) |
136 { | |
137 gchar *result = NULL; | |
138 gchar *md5_text; | |
139 guchar digest[16]; | |
716
98293de3c9b4
thumb_std_cache_path(): use g_build_filename() and simplify.
Laurent Monin <geeqie@norz.org>
parents:
671
diff
changeset
|
140 gchar *name; |
9 | 141 |
142 if (!path || !uri || !cache_subfolder) return NULL; | |
143 | |
716
98293de3c9b4
thumb_std_cache_path(): use g_build_filename() and simplify.
Laurent Monin <geeqie@norz.org>
parents:
671
diff
changeset
|
144 md5_get_digest((guchar *)uri, strlen(uri), digest); |
98293de3c9b4
thumb_std_cache_path(): use g_build_filename() and simplify.
Laurent Monin <geeqie@norz.org>
parents:
671
diff
changeset
|
145 md5_text = md5_digest_to_text(digest); |
98293de3c9b4
thumb_std_cache_path(): use g_build_filename() and simplify.
Laurent Monin <geeqie@norz.org>
parents:
671
diff
changeset
|
146 |
98293de3c9b4
thumb_std_cache_path(): use g_build_filename() and simplify.
Laurent Monin <geeqie@norz.org>
parents:
671
diff
changeset
|
147 if (!md5_text) return NULL; |
98293de3c9b4
thumb_std_cache_path(): use g_build_filename() and simplify.
Laurent Monin <geeqie@norz.org>
parents:
671
diff
changeset
|
148 |
98293de3c9b4
thumb_std_cache_path(): use g_build_filename() and simplify.
Laurent Monin <geeqie@norz.org>
parents:
671
diff
changeset
|
149 name = g_strconcat(md5_text, THUMB_NAME_EXTENSION, NULL); |
98293de3c9b4
thumb_std_cache_path(): use g_build_filename() and simplify.
Laurent Monin <geeqie@norz.org>
parents:
671
diff
changeset
|
150 |
9 | 151 if (local) |
152 { | |
716
98293de3c9b4
thumb_std_cache_path(): use g_build_filename() and simplify.
Laurent Monin <geeqie@norz.org>
parents:
671
diff
changeset
|
153 gchar *base = remove_level_from_path(path); |
9 | 154 |
716
98293de3c9b4
thumb_std_cache_path(): use g_build_filename() and simplify.
Laurent Monin <geeqie@norz.org>
parents:
671
diff
changeset
|
155 result = g_build_filename(base, THUMB_FOLDER_LOCAL, cache_subfolder, name, NULL); |
9 | 156 g_free(base); |
157 } | |
158 else | |
159 { | |
2566
034d8772d6d8
Fix #500: Geeqie doesn’t use shared thumbnail folder
Colin Clark <colin.clark@cclark.uk>
parents:
2350
diff
changeset
|
160 result = g_build_filename(get_thumbnails_standard_cache_dir(), |
034d8772d6d8
Fix #500: Geeqie doesn’t use shared thumbnail folder
Colin Clark <colin.clark@cclark.uk>
parents:
2350
diff
changeset
|
161 cache_subfolder, name, NULL); |
9 | 162 } |
163 | |
716
98293de3c9b4
thumb_std_cache_path(): use g_build_filename() and simplify.
Laurent Monin <geeqie@norz.org>
parents:
671
diff
changeset
|
164 g_free(name); |
9 | 165 g_free(md5_text); |
166 | |
167 return result; | |
168 } | |
169 | |
1446 | 170 static gchar *thumb_loader_std_cache_path(ThumbLoaderStd *tl, gboolean local, GdkPixbuf *pixbuf, gboolean fail) |
9 | 171 { |
436
a907e03a85f7
Rename inappropriate folder_size to folder.
Laurent Monin <geeqie@norz.org>
parents:
333
diff
changeset
|
172 const gchar *folder; |
9 | 173 gint w, h; |
174 | |
838
fd3a200281f6
use FileData in thumb_loader
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
827
diff
changeset
|
175 if (!tl->fd || !tl->thumb_uri) return NULL; |
9 | 176 |
177 if (pixbuf) | |
178 { | |
179 w = gdk_pixbuf_get_width(pixbuf); | |
180 h = gdk_pixbuf_get_height(pixbuf); | |
181 } | |
182 else | |
183 { | |
184 w = tl->requested_width; | |
185 h = tl->requested_height; | |
186 } | |
187 | |
188 if (fail) | |
189 { | |
436
a907e03a85f7
Rename inappropriate folder_size to folder.
Laurent Monin <geeqie@norz.org>
parents:
333
diff
changeset
|
190 folder = THUMB_FOLDER_FAIL; |
9 | 191 } |
192 else if (w > THUMB_SIZE_NORMAL || h > THUMB_SIZE_NORMAL) | |
193 { | |
436
a907e03a85f7
Rename inappropriate folder_size to folder.
Laurent Monin <geeqie@norz.org>
parents:
333
diff
changeset
|
194 folder = THUMB_FOLDER_LARGE; |
9 | 195 } |
196 else | |
197 { | |
436
a907e03a85f7
Rename inappropriate folder_size to folder.
Laurent Monin <geeqie@norz.org>
parents:
333
diff
changeset
|
198 folder = THUMB_FOLDER_NORMAL; |
9 | 199 } |
200 | |
838
fd3a200281f6
use FileData in thumb_loader
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
827
diff
changeset
|
201 return thumb_std_cache_path(tl->fd->path, |
9 | 202 (local) ? tl->local_uri : tl->thumb_uri, |
436
a907e03a85f7
Rename inappropriate folder_size to folder.
Laurent Monin <geeqie@norz.org>
parents:
333
diff
changeset
|
203 local, folder); |
9 | 204 } |
205 | |
1446 | 206 static gboolean thumb_loader_std_fail_check(ThumbLoaderStd *tl) |
9 | 207 { |
208 gchar *fail_path; | |
1437 | 209 gboolean result = FALSE; |
9 | 210 |
211 fail_path = thumb_loader_std_cache_path(tl, FALSE, NULL, TRUE); | |
212 if (isfile(fail_path)) | |
213 { | |
214 GdkPixbuf *pixbuf; | |
215 | |
216 if (tl->cache_retry) | |
217 { | |
218 pixbuf = NULL; | |
219 } | |
220 else | |
221 { | |
222 gchar *pathl; | |
223 | |
224 pathl = path_from_utf8(fail_path); | |
225 pixbuf = gdk_pixbuf_new_from_file(pathl, NULL); | |
226 g_free(pathl); | |
227 } | |
228 | |
229 if (pixbuf) | |
230 { | |
231 const gchar *mtime_str; | |
232 | |
233 mtime_str = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_MTIME); | |
234 if (mtime_str && strtol(mtime_str, NULL, 10) == tl->source_mtime) | |
235 { | |
236 result = TRUE; | |
838
fd3a200281f6
use FileData in thumb_loader
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
827
diff
changeset
|
237 DEBUG_1("thumb fail valid: %s", tl->fd->path); |
506
03d66738b225
Handle the newline in DEBUG_N() macro instead of adding one
Laurent Monin <geeqie@norz.org>
parents:
495
diff
changeset
|
238 DEBUG_1(" thumb: %s", fail_path); |
9 | 239 } |
240 | |
241 g_object_unref(G_OBJECT(pixbuf)); | |
242 } | |
243 | |
244 if (!result) unlink_file(fail_path); | |
245 } | |
246 g_free(fail_path); | |
247 | |
248 return result; | |
249 } | |
250 | |
1446 | 251 static gboolean thumb_loader_std_validate(ThumbLoaderStd *tl, GdkPixbuf *pixbuf) |
9 | 252 { |
253 const gchar *valid_uri; | |
254 const gchar *uri; | |
255 const gchar *mtime_str; | |
256 time_t mtime; | |
257 gint w, h; | |
258 | |
259 if (!pixbuf) return FALSE; | |
260 | |
261 w = gdk_pixbuf_get_width(pixbuf); | |
262 h = gdk_pixbuf_get_height(pixbuf); | |
263 | |
264 if (w != THUMB_SIZE_NORMAL && w != THUMB_SIZE_LARGE && | |
265 h != THUMB_SIZE_NORMAL && h != THUMB_SIZE_LARGE) return FALSE; | |
266 | |
267 valid_uri = (tl->thumb_path_local) ? tl->local_uri : tl->thumb_uri; | |
268 | |
269 uri = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_URI); | |
270 mtime_str = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_MTIME); | |
271 | |
272 if (!mtime_str || !uri || !valid_uri) return FALSE; | |
273 if (strcmp(uri, valid_uri) != 0) return FALSE; | |
274 | |
275 mtime = strtol(mtime_str, NULL, 10); | |
276 if (tl->source_mtime != mtime) return FALSE; | |
277 | |
278 return TRUE; | |
279 } | |
280 | |
281 static void thumb_loader_std_save(ThumbLoaderStd *tl, GdkPixbuf *pixbuf) | |
282 { | |
283 gchar *base_path; | |
284 gchar *tmp_path; | |
1446 | 285 gboolean fail; |
9 | 286 |
287 if (!tl->cache_enable || tl->cache_hit) return; | |
288 if (tl->thumb_path) return; | |
289 | |
290 if (!pixbuf) | |
291 { | |
292 /* local failures are not stored */ | |
293 if (tl->cache_local) return; | |
294 | |
436
a907e03a85f7
Rename inappropriate folder_size to folder.
Laurent Monin <geeqie@norz.org>
parents:
333
diff
changeset
|
295 pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 1, 1); |
9 | 296 fail = TRUE; |
297 } | |
298 else | |
299 { | |
300 g_object_ref(G_OBJECT(pixbuf)); | |
301 fail = FALSE; | |
302 } | |
303 | |
304 tl->thumb_path = thumb_loader_std_cache_path(tl, tl->cache_local, pixbuf, fail); | |
305 if (!tl->thumb_path) | |
306 { | |
307 g_object_unref(G_OBJECT(pixbuf)); | |
308 return; | |
309 } | |
310 tl->thumb_path_local = tl->cache_local; | |
311 | |
312 /* create thumbnail dir if needed */ | |
313 base_path = remove_level_from_path(tl->thumb_path); | |
314 if (tl->cache_local) | |
315 { | |
316 if (!isdir(base_path)) | |
317 { | |
318 struct stat st; | |
319 gchar *source_base; | |
320 | |
838
fd3a200281f6
use FileData in thumb_loader
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
827
diff
changeset
|
321 source_base = remove_level_from_path(tl->fd->path); |
9 | 322 if (stat_utf8(source_base, &st)) |
323 { | |
1148
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1055
diff
changeset
|
324 recursive_mkdir_if_not_exists(base_path, st.st_mode); |
9 | 325 } |
326 g_free(source_base); | |
327 } | |
328 } | |
329 else | |
330 { | |
1148
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1055
diff
changeset
|
331 recursive_mkdir_if_not_exists(base_path, THUMB_PERMS_FOLDER); |
9 | 332 } |
333 g_free(base_path); | |
334 | |
838
fd3a200281f6
use FileData in thumb_loader
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
827
diff
changeset
|
335 DEBUG_1("thumb saving: %s", tl->fd->path); |
506
03d66738b225
Handle the newline in DEBUG_N() macro instead of adding one
Laurent Monin <geeqie@norz.org>
parents:
495
diff
changeset
|
336 DEBUG_1(" saved: %s", tl->thumb_path); |
9 | 337 |
338 /* save thumb, using a temp file then renaming into place */ | |
339 tmp_path = unique_filename(tl->thumb_path, ".tmp", "_", 2); | |
340 if (tmp_path) | |
341 { | |
342 const gchar *mark_uri; | |
343 gchar *mark_app; | |
344 gchar *mark_mtime; | |
345 gchar *pathl; | |
1446 | 346 gboolean success; |
9 | 347 |
348 mark_uri = (tl->cache_local) ? tl->local_uri :tl->thumb_uri; | |
349 | |
288
e675073bcca0
Replace occurences of Geeqie / geeqie by constants defined in main.h.
Laurent Monin <geeqie@norz.org>
parents:
281
diff
changeset
|
350 mark_app = g_strdup_printf("%s %s", GQ_APPNAME, VERSION); |
2785 | 351 mark_mtime = g_strdup_printf("%llu", (unsigned long long)tl->source_mtime); |
9 | 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, | |
357 NULL); | |
358 if (success) | |
359 { | |
360 chmod(pathl, (tl->cache_local) ? tl->source_mode : THUMB_PERMS_THUMB); | |
361 success = rename_file(tmp_path, tl->thumb_path); | |
362 } | |
363 | |
364 g_free(pathl); | |
365 | |
366 g_free(mark_mtime); | |
367 g_free(mark_app); | |
368 | |
369 g_free(tmp_path); | |
506
03d66738b225
Handle the newline in DEBUG_N() macro instead of adding one
Laurent Monin <geeqie@norz.org>
parents:
495
diff
changeset
|
370 if (!success) |
9 | 371 { |
838
fd3a200281f6
use FileData in thumb_loader
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
827
diff
changeset
|
372 DEBUG_1("thumb save failed: %s", tl->fd->path); |
506
03d66738b225
Handle the newline in DEBUG_N() macro instead of adding one
Laurent Monin <geeqie@norz.org>
parents:
495
diff
changeset
|
373 DEBUG_1(" thumb: %s", tl->thumb_path); |
9 | 374 } |
375 | |
376 } | |
377 | |
378 g_object_unref(G_OBJECT(pixbuf)); | |
379 } | |
380 | |
876
0348bca8bb71
set fallback thumbnail pixbuf only if the loading really fails
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
864
diff
changeset
|
381 static void thumb_loader_std_set_fallback(ThumbLoaderStd *tl) |
0348bca8bb71
set fallback thumbnail pixbuf only if the loading really fails
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
864
diff
changeset
|
382 { |
0348bca8bb71
set fallback thumbnail pixbuf only if the loading really fails
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
864
diff
changeset
|
383 if (tl->fd->thumb_pixbuf) g_object_unref(tl->fd->thumb_pixbuf); |
0348bca8bb71
set fallback thumbnail pixbuf only if the loading really fails
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
864
diff
changeset
|
384 tl->fd->thumb_pixbuf = pixbuf_fallback(tl->fd, tl->requested_width, tl->requested_height); |
0348bca8bb71
set fallback thumbnail pixbuf only if the loading really fails
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
864
diff
changeset
|
385 } |
0348bca8bb71
set fallback thumbnail pixbuf only if the loading really fails
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
864
diff
changeset
|
386 |
1446 | 387 static GdkPixbuf *thumb_loader_std_finish(ThumbLoaderStd *tl, GdkPixbuf *pixbuf, gboolean shrunk) |
9 | 388 { |
389 GdkPixbuf *pixbuf_thumb = NULL; | |
390 GdkPixbuf *result; | |
839
74af80c4c972
rotate thumbnails by exif
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
838
diff
changeset
|
391 GdkPixbuf *rotated = NULL; |
9 | 392 gint sw, sh; |
393 | |
839
74af80c4c972
rotate thumbnails by exif
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
838
diff
changeset
|
394 |
74af80c4c972
rotate thumbnails by exif
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
838
diff
changeset
|
395 if (!tl->cache_hit && options->image.exif_rotate_enable) |
74af80c4c972
rotate thumbnails by exif
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
838
diff
changeset
|
396 { |
74af80c4c972
rotate thumbnails by exif
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
838
diff
changeset
|
397 if (!tl->fd->exif_orientation) |
74af80c4c972
rotate thumbnails by exif
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
838
diff
changeset
|
398 { |
1567
ef3ca18df43f
added an option to write image orientation to the metadata
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1523
diff
changeset
|
399 tl->fd->exif_orientation = metadata_read_int(tl->fd, ORIENTATION_KEY, EXIF_ORIENTATION_TOP_LEFT); |
839
74af80c4c972
rotate thumbnails by exif
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
838
diff
changeset
|
400 } |
2185
c14a1d8e6aa4
Trim trailing white spaces on empty lines.
Laurent Monin <zas@norz.org>
parents:
2184
diff
changeset
|
401 |
842
fee57526f434
do not allocate new buffer for thumbnails with correct orientation
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
841
diff
changeset
|
402 if (tl->fd->exif_orientation != EXIF_ORIENTATION_TOP_LEFT) |
fee57526f434
do not allocate new buffer for thumbnails with correct orientation
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
841
diff
changeset
|
403 { |
fee57526f434
do not allocate new buffer for thumbnails with correct orientation
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
841
diff
changeset
|
404 rotated = pixbuf_apply_orientation(pixbuf, tl->fd->exif_orientation); |
fee57526f434
do not allocate new buffer for thumbnails with correct orientation
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
841
diff
changeset
|
405 pixbuf = rotated; |
fee57526f434
do not allocate new buffer for thumbnails with correct orientation
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
841
diff
changeset
|
406 } |
839
74af80c4c972
rotate thumbnails by exif
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
838
diff
changeset
|
407 } |
74af80c4c972
rotate thumbnails by exif
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
838
diff
changeset
|
408 |
9 | 409 sw = gdk_pixbuf_get_width(pixbuf); |
410 sh = gdk_pixbuf_get_height(pixbuf); | |
411 | |
40
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
14
diff
changeset
|
412 if (tl->cache_enable) |
9 | 413 { |
40
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
14
diff
changeset
|
414 if (!tl->cache_hit) |
9 | 415 { |
40
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
14
diff
changeset
|
416 gint cache_w, cache_h; |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
14
diff
changeset
|
417 |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
14
diff
changeset
|
418 if (tl->requested_width > THUMB_SIZE_NORMAL || tl->requested_height > THUMB_SIZE_NORMAL) |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
14
diff
changeset
|
419 { |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
14
diff
changeset
|
420 cache_w = cache_h = THUMB_SIZE_LARGE; |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
14
diff
changeset
|
421 } |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
14
diff
changeset
|
422 else |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
14
diff
changeset
|
423 { |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
14
diff
changeset
|
424 cache_w = cache_h = THUMB_SIZE_NORMAL; |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
14
diff
changeset
|
425 } |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
14
diff
changeset
|
426 |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
14
diff
changeset
|
427 if (sw > cache_w || sh > cache_h || shrunk) |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
14
diff
changeset
|
428 { |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
14
diff
changeset
|
429 gint thumb_w, thumb_h; |
1762
e7b6b1933b26
do not cache incomplete thumbnails
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1721
diff
changeset
|
430 struct stat st; |
9 | 431 |
864
83be8234df2d
added pixbuf_fallback function
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
845
diff
changeset
|
432 if (pixbuf_scale_aspect(cache_w, cache_h, sw, sh, |
40
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
14
diff
changeset
|
433 &thumb_w, &thumb_h)) |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
14
diff
changeset
|
434 { |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
14
diff
changeset
|
435 pixbuf_thumb = gdk_pixbuf_scale_simple(pixbuf, thumb_w, thumb_h, |
333
1ebdf8fb2c1a
Rename thumbnails related options.
Laurent Monin <geeqie@norz.org>
parents:
318
diff
changeset
|
436 (GdkInterpType)options->thumbnails.quality); |
40
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
14
diff
changeset
|
437 } |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
14
diff
changeset
|
438 else |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
14
diff
changeset
|
439 { |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
14
diff
changeset
|
440 pixbuf_thumb = pixbuf; |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
14
diff
changeset
|
441 g_object_ref(G_OBJECT(pixbuf_thumb)); |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
14
diff
changeset
|
442 } |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
14
diff
changeset
|
443 |
1762
e7b6b1933b26
do not cache incomplete thumbnails
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1721
diff
changeset
|
444 /* do not save the thumbnail if the source file has changed meanwhile - |
e7b6b1933b26
do not cache incomplete thumbnails
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1721
diff
changeset
|
445 the thumbnail is most probably broken */ |
2184 | 446 if (stat_utf8(tl->fd->path, &st) && |
1762
e7b6b1933b26
do not cache incomplete thumbnails
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1721
diff
changeset
|
447 tl->source_mtime == st.st_mtime && |
e7b6b1933b26
do not cache incomplete thumbnails
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1721
diff
changeset
|
448 tl->source_size == st.st_size) |
e7b6b1933b26
do not cache incomplete thumbnails
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1721
diff
changeset
|
449 { |
e7b6b1933b26
do not cache incomplete thumbnails
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1721
diff
changeset
|
450 thumb_loader_std_save(tl, pixbuf_thumb); |
e7b6b1933b26
do not cache incomplete thumbnails
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1721
diff
changeset
|
451 } |
40
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
14
diff
changeset
|
452 } |
9 | 453 } |
40
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
14
diff
changeset
|
454 else if (tl->cache_hit && |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
14
diff
changeset
|
455 tl->cache_local && !tl->thumb_path_local) |
9 | 456 { |
40
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
14
diff
changeset
|
457 /* A local cache save was requested, but a valid thumb is in $HOME, |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
14
diff
changeset
|
458 * so specifically save as a local thumbnail. |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
14
diff
changeset
|
459 */ |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
14
diff
changeset
|
460 g_free(tl->thumb_path); |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
14
diff
changeset
|
461 tl->thumb_path = NULL; |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
14
diff
changeset
|
462 |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
14
diff
changeset
|
463 tl->cache_hit = FALSE; |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
14
diff
changeset
|
464 |
838
fd3a200281f6
use FileData in thumb_loader
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
827
diff
changeset
|
465 DEBUG_1("thumb copied: %s", tl->fd->path); |
40
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
14
diff
changeset
|
466 |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
14
diff
changeset
|
467 thumb_loader_std_save(tl, pixbuf); |
9 | 468 } |
469 } | |
470 | |
471 if (sw <= tl->requested_width && sh <= tl->requested_height) | |
472 { | |
473 result = pixbuf; | |
474 g_object_ref(result); | |
475 } | |
476 else | |
477 { | |
478 gint thumb_w, thumb_h; | |
479 | |
480 if (pixbuf_thumb) | |
481 { | |
482 pixbuf = pixbuf_thumb; | |
483 sw = gdk_pixbuf_get_width(pixbuf); | |
484 sh = gdk_pixbuf_get_height(pixbuf); | |
485 } | |
486 | |
864
83be8234df2d
added pixbuf_fallback function
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
845
diff
changeset
|
487 if (pixbuf_scale_aspect(tl->requested_width, tl->requested_height, sw, sh, |
9 | 488 &thumb_w, &thumb_h)) |
489 { | |
490 result = gdk_pixbuf_scale_simple(pixbuf, thumb_w, thumb_h, | |
333
1ebdf8fb2c1a
Rename thumbnails related options.
Laurent Monin <geeqie@norz.org>
parents:
318
diff
changeset
|
491 (GdkInterpType)options->thumbnails.quality); |
9 | 492 } |
493 else | |
494 { | |
495 result = pixbuf; | |
496 g_object_ref(result); | |
497 } | |
498 } | |
499 | |
500 if (pixbuf_thumb) g_object_unref(pixbuf_thumb); | |
839
74af80c4c972
rotate thumbnails by exif
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
838
diff
changeset
|
501 if (rotated) g_object_unref(rotated); |
9 | 502 |
503 return result; | |
504 } | |
505 | |
1446 | 506 static gboolean thumb_loader_std_next_source(ThumbLoaderStd *tl, gboolean remove_broken) |
9 | 507 { |
508 image_loader_free(tl->il); | |
509 tl->il = NULL; | |
510 | |
511 if (tl->thumb_path) | |
512 { | |
513 if (!tl->thumb_path_local && remove_broken) | |
514 { | |
506
03d66738b225
Handle the newline in DEBUG_N() macro instead of adding one
Laurent Monin <geeqie@norz.org>
parents:
495
diff
changeset
|
515 DEBUG_1("thumb broken, unlinking: %s", tl->thumb_path); |
9 | 516 unlink_file(tl->thumb_path); |
517 } | |
518 | |
519 g_free(tl->thumb_path); | |
520 tl->thumb_path = NULL; | |
521 | |
522 if (!tl->thumb_path_local) | |
523 { | |
524 tl->thumb_path = thumb_loader_std_cache_path(tl, TRUE, NULL, FALSE); | |
1927
d1a5b8633919
always check for sidecars by readdir
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1802
diff
changeset
|
525 if (isfile(tl->thumb_path)) |
9 | 526 { |
1927
d1a5b8633919
always check for sidecars by readdir
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1802
diff
changeset
|
527 FileData *fd = file_data_new_no_grouping(tl->thumb_path); |
d1a5b8633919
always check for sidecars by readdir
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1802
diff
changeset
|
528 if (thumb_loader_std_setup(tl, fd)) |
d1a5b8633919
always check for sidecars by readdir
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1802
diff
changeset
|
529 { |
d1a5b8633919
always check for sidecars by readdir
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1802
diff
changeset
|
530 file_data_unref(fd); |
d1a5b8633919
always check for sidecars by readdir
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1802
diff
changeset
|
531 tl->thumb_path_local = TRUE; |
d1a5b8633919
always check for sidecars by readdir
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1802
diff
changeset
|
532 return TRUE; |
d1a5b8633919
always check for sidecars by readdir
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1802
diff
changeset
|
533 } |
d1a5b8633919
always check for sidecars by readdir
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1802
diff
changeset
|
534 file_data_unref(fd); |
9 | 535 } |
536 | |
537 g_free(tl->thumb_path); | |
538 tl->thumb_path = NULL; | |
539 } | |
540 | |
1009
5847765e8189
fixed thumbnail loader for the new raw preview interface
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
972
diff
changeset
|
541 if (thumb_loader_std_setup(tl, tl->fd)) return TRUE; |
9 | 542 } |
543 | |
544 thumb_loader_std_save(tl, NULL); | |
545 return FALSE; | |
546 } | |
547 | |
548 static void thumb_loader_std_done_cb(ImageLoader *il, gpointer data) | |
549 { | |
550 ThumbLoaderStd *tl = data; | |
551 GdkPixbuf *pixbuf; | |
552 | |
881
eb2e2dac4517
Prevent segfault in certain conditions when displaying debug message.
Laurent Monin <geeqie@norz.org>
parents:
876
diff
changeset
|
553 DEBUG_1("thumb image done: %s", tl->fd ? tl->fd->path : "???"); |
1011
66037ee8b4d6
do not access image_loader directly
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1009
diff
changeset
|
554 DEBUG_1(" from: %s", image_loader_get_fd(tl->il)->path); |
9 | 555 |
556 pixbuf = image_loader_get_pixbuf(tl->il); | |
557 if (!pixbuf) | |
558 { | |
506
03d66738b225
Handle the newline in DEBUG_N() macro instead of adding one
Laurent Monin <geeqie@norz.org>
parents:
495
diff
changeset
|
559 DEBUG_1("...but no pixbuf"); |
9 | 560 thumb_loader_std_error_cb(il, data); |
561 return; | |
562 } | |
563 | |
564 if (tl->thumb_path && !thumb_loader_std_validate(tl, pixbuf)) | |
565 { | |
566 if (thumb_loader_std_next_source(tl, TRUE)) return; | |
567 | |
568 if (tl->func_error) tl->func_error(tl, tl->data); | |
569 return; | |
570 } | |
571 | |
572 tl->cache_hit = (tl->thumb_path != NULL); | |
573 | |
838
fd3a200281f6
use FileData in thumb_loader
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
827
diff
changeset
|
574 if (tl->fd) |
fd3a200281f6
use FileData in thumb_loader
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
827
diff
changeset
|
575 { |
845
06f57cd7f595
renamed fd->pixbuf to fd->thumb_pixbuf
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
844
diff
changeset
|
576 if (tl->fd->thumb_pixbuf) g_object_unref(tl->fd->thumb_pixbuf); |
1011
66037ee8b4d6
do not access image_loader directly
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1009
diff
changeset
|
577 tl->fd->thumb_pixbuf = thumb_loader_std_finish(tl, pixbuf, image_loader_get_shrunk(il)); |
838
fd3a200281f6
use FileData in thumb_loader
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
827
diff
changeset
|
578 } |
9 | 579 |
580 if (tl->func_done) tl->func_done(tl, tl->data); | |
581 } | |
582 | |
583 static void thumb_loader_std_error_cb(ImageLoader *il, gpointer data) | |
584 { | |
585 ThumbLoaderStd *tl = data; | |
586 | |
587 /* if at least some of the image is available, go to done */ | |
588 if (image_loader_get_pixbuf(tl->il) != NULL) | |
589 { | |
590 thumb_loader_std_done_cb(il, data); | |
591 return; | |
592 } | |
2185
c14a1d8e6aa4
Trim trailing white spaces on empty lines.
Laurent Monin <zas@norz.org>
parents:
2184
diff
changeset
|
593 |
838
fd3a200281f6
use FileData in thumb_loader
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
827
diff
changeset
|
594 DEBUG_1("thumb image error: %s", tl->fd->path); |
1011
66037ee8b4d6
do not access image_loader directly
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1009
diff
changeset
|
595 DEBUG_1(" from: %s", image_loader_get_fd(tl->il)->path); |
9 | 596 |
597 if (thumb_loader_std_next_source(tl, TRUE)) return; | |
598 | |
876
0348bca8bb71
set fallback thumbnail pixbuf only if the loading really fails
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
864
diff
changeset
|
599 thumb_loader_std_set_fallback(tl); |
2185
c14a1d8e6aa4
Trim trailing white spaces on empty lines.
Laurent Monin <zas@norz.org>
parents:
2184
diff
changeset
|
600 |
9 | 601 if (tl->func_error) tl->func_error(tl, tl->data); |
602 } | |
603 | |
604 static void thumb_loader_std_progress_cb(ImageLoader *il, gdouble percent, gpointer data) | |
605 { | |
606 ThumbLoaderStd *tl = data; | |
607 | |
608 tl->progress = (gdouble)percent; | |
609 | |
610 if (tl->func_progress) tl->func_progress(tl, tl->data); | |
611 } | |
612 | |
1446 | 613 static gboolean thumb_loader_std_setup(ThumbLoaderStd *tl, FileData *fd) |
9 | 614 { |
1009
5847765e8189
fixed thumbnail loader for the new raw preview interface
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
972
diff
changeset
|
615 tl->il = image_loader_new(fd); |
1036
e796b3d7cd87
load thumbnails with lower priority
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1012
diff
changeset
|
616 image_loader_set_priority(tl->il, G_PRIORITY_LOW); |
9 | 617 |
1521
ad1d92c39b30
unconditionally enable fast jpeg thumbnailing
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1446
diff
changeset
|
618 /* this will speed up jpegs by up to 3x in some cases */ |
ad1d92c39b30
unconditionally enable fast jpeg thumbnailing
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1446
diff
changeset
|
619 if (tl->requested_width <= THUMB_SIZE_NORMAL && |
ad1d92c39b30
unconditionally enable fast jpeg thumbnailing
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1446
diff
changeset
|
620 tl->requested_height <= THUMB_SIZE_NORMAL) |
9 | 621 { |
1521
ad1d92c39b30
unconditionally enable fast jpeg thumbnailing
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1446
diff
changeset
|
622 image_loader_set_requested_size(tl->il, THUMB_SIZE_NORMAL, THUMB_SIZE_NORMAL); |
ad1d92c39b30
unconditionally enable fast jpeg thumbnailing
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1446
diff
changeset
|
623 } |
ad1d92c39b30
unconditionally enable fast jpeg thumbnailing
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1446
diff
changeset
|
624 else |
ad1d92c39b30
unconditionally enable fast jpeg thumbnailing
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1446
diff
changeset
|
625 { |
ad1d92c39b30
unconditionally enable fast jpeg thumbnailing
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1446
diff
changeset
|
626 image_loader_set_requested_size(tl->il, THUMB_SIZE_LARGE, THUMB_SIZE_LARGE); |
9 | 627 } |
628 | |
1346
b3378273091e
No space between function name and first parenthesis, it eases greping (see CODING).
Laurent Monin <geeqie@norz.org>
parents:
1288
diff
changeset
|
629 g_signal_connect(G_OBJECT(tl->il), "error", (GCallback)thumb_loader_std_error_cb, tl); |
9 | 630 if (tl->func_progress) |
631 { | |
1346
b3378273091e
No space between function name and first parenthesis, it eases greping (see CODING).
Laurent Monin <geeqie@norz.org>
parents:
1288
diff
changeset
|
632 g_signal_connect(G_OBJECT(tl->il), "percent", (GCallback)thumb_loader_std_progress_cb, tl); |
9 | 633 } |
1346
b3378273091e
No space between function name and first parenthesis, it eases greping (see CODING).
Laurent Monin <geeqie@norz.org>
parents:
1288
diff
changeset
|
634 g_signal_connect(G_OBJECT(tl->il), "done", (GCallback)thumb_loader_std_done_cb, tl); |
9 | 635 |
1012
409b52dfe683
converted image loader to a GObject and use signals for notification
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1011
diff
changeset
|
636 if (image_loader_start(tl->il)) |
9 | 637 { |
638 return TRUE; | |
639 } | |
640 | |
641 image_loader_free(tl->il); | |
642 tl->il = NULL; | |
643 return FALSE; | |
644 } | |
645 | |
646 /* | |
647 * Note: Currently local_cache only specifies where to save a _new_ thumb, if | |
648 * a valid existing thumb is found anywhere the local thumb will not be created. | |
649 */ | |
1446 | 650 void thumb_loader_std_set_cache(ThumbLoaderStd *tl, gboolean enable_cache, gboolean local, gboolean retry_failed) |
9 | 651 { |
652 if (!tl) return; | |
653 | |
654 tl->cache_enable = enable_cache; | |
655 tl->cache_local = local; | |
656 tl->cache_retry = retry_failed; | |
657 } | |
658 | |
1446 | 659 gboolean thumb_loader_std_start(ThumbLoaderStd *tl, FileData *fd) |
9 | 660 { |
661 static gchar *thumb_cache = NULL; | |
662 struct stat st; | |
663 | |
838
fd3a200281f6
use FileData in thumb_loader
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
827
diff
changeset
|
664 if (!tl || !fd) return FALSE; |
9 | 665 |
666 thumb_loader_std_reset(tl); | |
667 | |
668 | |
838
fd3a200281f6
use FileData in thumb_loader
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
827
diff
changeset
|
669 tl->fd = file_data_ref(fd); |
2799
ea4163f0c769
Ref #332: include pdf-view
Colin Clark <colin.clark@cclark.uk>
parents:
2798
diff
changeset
|
670 if (!stat_utf8(fd->path, &st) || (tl->fd->format_class != FORMAT_CLASS_IMAGE && tl->fd->format_class != FORMAT_CLASS_RAWIMAGE && tl->fd->format_class != FORMAT_CLASS_VIDEO && tl->fd->format_class != FORMAT_CLASS_COLLECTION && tl->fd->format_class != FORMAT_CLASS_PDF && !options->file_filter.disable)) |
972
709edc695101
set fallback pixbuf in case of missing file
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
881
diff
changeset
|
671 { |
709edc695101
set fallback pixbuf in case of missing file
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
881
diff
changeset
|
672 thumb_loader_std_set_fallback(tl); |
709edc695101
set fallback pixbuf in case of missing file
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
881
diff
changeset
|
673 return FALSE; |
709edc695101
set fallback pixbuf in case of missing file
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
881
diff
changeset
|
674 } |
9 | 675 tl->source_mtime = st.st_mtime; |
676 tl->source_size = st.st_size; | |
677 tl->source_mode = st.st_mode; | |
678 | |
2566
034d8772d6d8
Fix #500: Geeqie doesn’t use shared thumbnail folder
Colin Clark <colin.clark@cclark.uk>
parents:
2350
diff
changeset
|
679 if (!thumb_cache) |
034d8772d6d8
Fix #500: Geeqie doesn’t use shared thumbnail folder
Colin Clark <colin.clark@cclark.uk>
parents:
2350
diff
changeset
|
680 { |
034d8772d6d8
Fix #500: Geeqie doesn’t use shared thumbnail folder
Colin Clark <colin.clark@cclark.uk>
parents:
2350
diff
changeset
|
681 thumb_cache = g_strdup(get_thumbnails_standard_cache_dir()); |
034d8772d6d8
Fix #500: Geeqie doesn’t use shared thumbnail folder
Colin Clark <colin.clark@cclark.uk>
parents:
2350
diff
changeset
|
682 } |
034d8772d6d8
Fix #500: Geeqie doesn’t use shared thumbnail folder
Colin Clark <colin.clark@cclark.uk>
parents:
2350
diff
changeset
|
683 |
838
fd3a200281f6
use FileData in thumb_loader
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
827
diff
changeset
|
684 if (strncmp(tl->fd->path, thumb_cache, strlen(thumb_cache)) != 0) |
9 | 685 { |
686 gchar *pathl; | |
687 | |
838
fd3a200281f6
use FileData in thumb_loader
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
827
diff
changeset
|
688 pathl = path_from_utf8(fd->path); |
9 | 689 tl->thumb_uri = g_filename_to_uri(pathl, NULL, NULL); |
690 tl->local_uri = filename_from_path(tl->thumb_uri); | |
691 g_free(pathl); | |
692 } | |
693 | |
694 if (tl->cache_enable) | |
695 { | |
696 gint found; | |
697 | |
698 tl->thumb_path = thumb_loader_std_cache_path(tl, FALSE, NULL, FALSE); | |
699 tl->thumb_path_local = FALSE; | |
700 | |
701 found = isfile(tl->thumb_path); | |
1927
d1a5b8633919
always check for sidecars by readdir
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1802
diff
changeset
|
702 if (found) |
d1a5b8633919
always check for sidecars by readdir
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1802
diff
changeset
|
703 { |
d1a5b8633919
always check for sidecars by readdir
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1802
diff
changeset
|
704 FileData *fd = file_data_new_no_grouping(tl->thumb_path); |
d1a5b8633919
always check for sidecars by readdir
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1802
diff
changeset
|
705 if (thumb_loader_std_setup(tl, fd)) |
d1a5b8633919
always check for sidecars by readdir
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1802
diff
changeset
|
706 { |
d1a5b8633919
always check for sidecars by readdir
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1802
diff
changeset
|
707 file_data_unref(fd); |
d1a5b8633919
always check for sidecars by readdir
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1802
diff
changeset
|
708 return TRUE; |
d1a5b8633919
always check for sidecars by readdir
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1802
diff
changeset
|
709 } |
d1a5b8633919
always check for sidecars by readdir
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1802
diff
changeset
|
710 file_data_unref(fd); |
d1a5b8633919
always check for sidecars by readdir
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1802
diff
changeset
|
711 } |
9 | 712 |
876
0348bca8bb71
set fallback thumbnail pixbuf only if the loading really fails
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
864
diff
changeset
|
713 if (thumb_loader_std_fail_check(tl) || |
0348bca8bb71
set fallback thumbnail pixbuf only if the loading really fails
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
864
diff
changeset
|
714 !thumb_loader_std_next_source(tl, found)) |
0348bca8bb71
set fallback thumbnail pixbuf only if the loading really fails
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
864
diff
changeset
|
715 { |
0348bca8bb71
set fallback thumbnail pixbuf only if the loading really fails
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
864
diff
changeset
|
716 thumb_loader_std_set_fallback(tl); |
0348bca8bb71
set fallback thumbnail pixbuf only if the loading really fails
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
864
diff
changeset
|
717 return FALSE; |
0348bca8bb71
set fallback thumbnail pixbuf only if the loading really fails
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
864
diff
changeset
|
718 } |
0348bca8bb71
set fallback thumbnail pixbuf only if the loading really fails
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
864
diff
changeset
|
719 return TRUE; |
9 | 720 } |
721 | |
1009
5847765e8189
fixed thumbnail loader for the new raw preview interface
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
972
diff
changeset
|
722 if (!thumb_loader_std_setup(tl, tl->fd)) |
9 | 723 { |
724 thumb_loader_std_save(tl, NULL); | |
876
0348bca8bb71
set fallback thumbnail pixbuf only if the loading really fails
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
864
diff
changeset
|
725 thumb_loader_std_set_fallback(tl); |
9 | 726 return FALSE; |
727 } | |
728 | |
729 return TRUE; | |
730 } | |
731 | |
732 void thumb_loader_std_free(ThumbLoaderStd *tl) | |
733 { | |
734 if (!tl) return; | |
735 | |
736 thumb_loader_std_reset(tl); | |
737 g_free(tl); | |
738 } | |
739 | |
864
83be8234df2d
added pixbuf_fallback function
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
845
diff
changeset
|
740 GdkPixbuf *thumb_loader_std_get_pixbuf(ThumbLoaderStd *tl) |
9 | 741 { |
742 GdkPixbuf *pixbuf; | |
743 | |
845
06f57cd7f595
renamed fd->pixbuf to fd->thumb_pixbuf
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
844
diff
changeset
|
744 if (tl && tl->fd && tl->fd->thumb_pixbuf) |
9 | 745 { |
845
06f57cd7f595
renamed fd->pixbuf to fd->thumb_pixbuf
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
844
diff
changeset
|
746 pixbuf = tl->fd->thumb_pixbuf; |
9 | 747 g_object_ref(pixbuf); |
748 } | |
749 else | |
750 { | |
864
83be8234df2d
added pixbuf_fallback function
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
845
diff
changeset
|
751 pixbuf = pixbuf_fallback(NULL, tl->requested_width, tl->requested_height); |
9 | 752 } |
753 | |
754 return pixbuf; | |
755 } | |
756 | |
757 | |
758 typedef struct _ThumbValidate ThumbValidate; | |
759 struct _ThumbValidate | |
760 { | |
761 ThumbLoaderStd *tl; | |
762 gchar *path; | |
763 gint days; | |
764 | |
1446 | 765 void (*func_valid)(const gchar *path, gboolean valid, gpointer data); |
9 | 766 gpointer data; |
767 | |
1523
e52aabe8fc7a
Fix up event source ids type: gint -> guint.
Laurent Monin <geeqie@norz.org>
parents:
1521
diff
changeset
|
768 guint idle_id; /* event source id */ |
9 | 769 }; |
770 | |
771 static void thumb_loader_std_thumb_file_validate_free(ThumbValidate *tv) | |
772 { | |
773 thumb_loader_std_free(tv->tl); | |
774 g_free(tv->path); | |
775 g_free(tv); | |
776 } | |
777 | |
778 void thumb_loader_std_thumb_file_validate_cancel(ThumbLoaderStd *tl) | |
779 { | |
780 ThumbValidate *tv; | |
781 | |
782 if (!tl) return; | |
783 | |
784 tv = tl->data; | |
785 | |
1523
e52aabe8fc7a
Fix up event source ids type: gint -> guint.
Laurent Monin <geeqie@norz.org>
parents:
1521
diff
changeset
|
786 if (tv->idle_id) |
e52aabe8fc7a
Fix up event source ids type: gint -> guint.
Laurent Monin <geeqie@norz.org>
parents:
1521
diff
changeset
|
787 { |
e52aabe8fc7a
Fix up event source ids type: gint -> guint.
Laurent Monin <geeqie@norz.org>
parents:
1521
diff
changeset
|
788 g_source_remove(tv->idle_id); |
e52aabe8fc7a
Fix up event source ids type: gint -> guint.
Laurent Monin <geeqie@norz.org>
parents:
1521
diff
changeset
|
789 tv->idle_id = 0; |
e52aabe8fc7a
Fix up event source ids type: gint -> guint.
Laurent Monin <geeqie@norz.org>
parents:
1521
diff
changeset
|
790 } |
9 | 791 |
792 thumb_loader_std_thumb_file_validate_free(tv); | |
793 } | |
794 | |
1446 | 795 static void thumb_loader_std_thumb_file_validate_finish(ThumbValidate *tv, gboolean valid) |
9 | 796 { |
797 if (tv->func_valid) tv->func_valid(tv->path, valid, tv->data); | |
798 | |
799 thumb_loader_std_thumb_file_validate_free(tv); | |
800 } | |
801 | |
802 static void thumb_loader_std_thumb_file_validate_done_cb(ThumbLoaderStd *tl, gpointer data) | |
803 { | |
804 ThumbValidate *tv = data; | |
805 GdkPixbuf *pixbuf; | |
1437 | 806 gboolean valid = FALSE; |
9 | 807 |
2184 | 808 /* get the original thumbnail pixbuf (unrotated, with original options) |
1721
888d345c60b8
fixed moving and maintenance of std. thumbnails
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1567
diff
changeset
|
809 this is called from image_loader done callback, so tv->tl->il must exist*/ |
2184 | 810 pixbuf = image_loader_get_pixbuf(tv->tl->il); |
9 | 811 if (pixbuf) |
812 { | |
813 const gchar *uri; | |
814 const gchar *mtime_str; | |
815 | |
816 uri = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_URI); | |
817 mtime_str = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_MTIME); | |
818 if (uri && mtime_str) | |
819 { | |
820 if (strncmp(uri, "file:", strlen("file:")) == 0) | |
821 { | |
822 struct stat st; | |
823 gchar *target; | |
824 | |
825 target = g_filename_from_uri(uri, NULL, NULL); | |
826 if (stat(target, &st) == 0 && | |
827 st.st_mtime == strtol(mtime_str, NULL, 10)) | |
828 { | |
829 valid = TRUE; | |
830 } | |
831 g_free(target); | |
832 } | |
833 else | |
834 { | |
835 struct stat st; | |
836 | |
506
03d66738b225
Handle the newline in DEBUG_N() macro instead of adding one
Laurent Monin <geeqie@norz.org>
parents:
495
diff
changeset
|
837 DEBUG_1("thumb uri foreign, doing day check: %s", uri); |
9 | 838 |
839 if (stat_utf8(tv->path, &st)) | |
840 { | |
841 time_t now; | |
842 | |
843 now = time(NULL); | |
844 if (st.st_atime >= now - (time_t)tv->days * 24 * 60 * 60) | |
845 { | |
846 valid = TRUE; | |
847 } | |
848 } | |
849 } | |
850 } | |
1721
888d345c60b8
fixed moving and maintenance of std. thumbnails
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1567
diff
changeset
|
851 else |
888d345c60b8
fixed moving and maintenance of std. thumbnails
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1567
diff
changeset
|
852 { |
888d345c60b8
fixed moving and maintenance of std. thumbnails
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1567
diff
changeset
|
853 DEBUG_1("invalid image found in std cache: %s", tv->path); |
888d345c60b8
fixed moving and maintenance of std. thumbnails
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1567
diff
changeset
|
854 } |
9 | 855 } |
856 | |
857 thumb_loader_std_thumb_file_validate_finish(tv, valid); | |
858 } | |
859 | |
860 static void thumb_loader_std_thumb_file_validate_error_cb(ThumbLoaderStd *tl, gpointer data) | |
861 { | |
862 ThumbValidate *tv = data; | |
863 | |
864 thumb_loader_std_thumb_file_validate_finish(tv, FALSE); | |
865 } | |
866 | |
1446 | 867 static gboolean thumb_loader_std_thumb_file_validate_idle_cb(gpointer data) |
9 | 868 { |
869 ThumbValidate *tv = data; | |
870 | |
1523
e52aabe8fc7a
Fix up event source ids type: gint -> guint.
Laurent Monin <geeqie@norz.org>
parents:
1521
diff
changeset
|
871 tv->idle_id = 0; |
9 | 872 thumb_loader_std_thumb_file_validate_finish(tv, FALSE); |
873 | |
874 return FALSE; | |
875 } | |
876 | |
877 ThumbLoaderStd *thumb_loader_std_thumb_file_validate(const gchar *thumb_path, gint allowed_days, | |
1446 | 878 void (*func_valid)(const gchar *path, gboolean valid, gpointer data), |
9 | 879 gpointer data) |
880 { | |
881 ThumbValidate *tv; | |
882 | |
883 tv = g_new0(ThumbValidate, 1); | |
884 | |
885 tv->tl = thumb_loader_std_new(THUMB_SIZE_LARGE, THUMB_SIZE_LARGE); | |
886 thumb_loader_std_set_callbacks(tv->tl, | |
887 thumb_loader_std_thumb_file_validate_done_cb, | |
888 thumb_loader_std_thumb_file_validate_error_cb, | |
889 NULL, | |
890 tv); | |
891 thumb_loader_std_reset(tv->tl); | |
892 | |
893 tv->path = g_strdup(thumb_path); | |
894 tv->days = allowed_days; | |
895 tv->func_valid = func_valid; | |
896 tv->data = data; | |
897 | |
1927
d1a5b8633919
always check for sidecars by readdir
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1802
diff
changeset
|
898 FileData *fd = file_data_new_no_grouping(thumb_path); |
d1a5b8633919
always check for sidecars by readdir
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1802
diff
changeset
|
899 if (!thumb_loader_std_setup(tv->tl, fd)) |
9 | 900 { |
901 tv->idle_id = g_idle_add(thumb_loader_std_thumb_file_validate_idle_cb, tv); | |
902 } | |
903 else | |
904 { | |
1523
e52aabe8fc7a
Fix up event source ids type: gint -> guint.
Laurent Monin <geeqie@norz.org>
parents:
1521
diff
changeset
|
905 tv->idle_id = 0; |
9 | 906 } |
907 | |
1927
d1a5b8633919
always check for sidecars by readdir
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1802
diff
changeset
|
908 file_data_unref(fd); |
9 | 909 return tv->tl; |
910 } | |
911 | |
1446 | 912 static void thumb_std_maint_remove_one(const gchar *source, const gchar *uri, gboolean local, |
9 | 913 const gchar *subfolder) |
914 { | |
915 gchar *thumb_path; | |
916 | |
917 thumb_path = thumb_std_cache_path(source, | |
918 (local) ? filename_from_path(uri) : uri, | |
919 local, subfolder); | |
920 if (isfile(thumb_path)) | |
921 { | |
506
03d66738b225
Handle the newline in DEBUG_N() macro instead of adding one
Laurent Monin <geeqie@norz.org>
parents:
495
diff
changeset
|
922 DEBUG_1("thumb removing: %s", thumb_path); |
9 | 923 unlink_file(thumb_path); |
924 } | |
925 g_free(thumb_path); | |
926 } | |
927 | |
928 /* this also removes local thumbnails (the source is gone so it makes sense) */ | |
929 void thumb_std_maint_removed(const gchar *source) | |
930 { | |
931 gchar *uri; | |
932 gchar *sourcel; | |
933 | |
934 sourcel = path_from_utf8(source); | |
935 uri = g_filename_to_uri(sourcel, NULL, NULL); | |
936 g_free(sourcel); | |
937 | |
938 /* all this to remove a thumbnail? */ | |
939 | |
940 thumb_std_maint_remove_one(source, uri, FALSE, THUMB_FOLDER_NORMAL); | |
941 thumb_std_maint_remove_one(source, uri, FALSE, THUMB_FOLDER_LARGE); | |
942 thumb_std_maint_remove_one(source, uri, FALSE, THUMB_FOLDER_FAIL); | |
943 thumb_std_maint_remove_one(source, uri, TRUE, THUMB_FOLDER_NORMAL); | |
944 thumb_std_maint_remove_one(source, uri, TRUE, THUMB_FOLDER_LARGE); | |
945 | |
946 g_free(uri); | |
947 } | |
948 | |
949 typedef struct _TMaintMove TMaintMove; | |
950 struct _TMaintMove | |
951 { | |
952 gchar *source; | |
953 gchar *dest; | |
954 | |
955 ThumbLoaderStd *tl; | |
956 gchar *source_uri; | |
957 gchar *thumb_path; | |
958 | |
959 gint pass; | |
960 }; | |
961 | |
962 static GList *thumb_std_maint_move_list = NULL; | |
963 static GList *thumb_std_maint_move_tail = NULL; | |
964 | |
965 | |
966 static void thumb_std_maint_move_step(TMaintMove *tm); | |
1446 | 967 static gboolean thumb_std_maint_move_idle(gpointer data); |
9 | 968 |
969 | |
1446 | 970 static void thumb_std_maint_move_validate_cb(const gchar *path, gboolean valid, gpointer data) |
9 | 971 { |
972 TMaintMove *tm = data; | |
973 GdkPixbuf *pixbuf; | |
974 | |
2184 | 975 /* get the original thumbnail pixbuf (unrotated, with original options) |
1721
888d345c60b8
fixed moving and maintenance of std. thumbnails
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1567
diff
changeset
|
976 this is called from image_loader done callback, so tm->tl->il must exist*/ |
2184 | 977 pixbuf = image_loader_get_pixbuf(tm->tl->il); |
9 | 978 if (pixbuf) |
979 { | |
980 const gchar *uri; | |
981 const gchar *mtime_str; | |
982 | |
983 uri = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_URI); | |
984 mtime_str = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_MTIME); | |
985 | |
986 if (uri && mtime_str && strcmp(uri, tm->source_uri) == 0) | |
987 { | |
988 gchar *pathl; | |
989 | |
990 /* The validation utility abuses ThumbLoader, and we | |
991 * abuse the utility just to load the thumbnail, | |
992 * but the loader needs to look sane for the save to complete. | |
993 */ | |
994 | |
995 tm->tl->cache_enable = TRUE; | |
996 tm->tl->cache_hit = FALSE; | |
997 tm->tl->cache_local = FALSE; | |
838
fd3a200281f6
use FileData in thumb_loader
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
827
diff
changeset
|
998 file_data_unref(tm->tl->fd); |
1936
ed6aa14b66c9
rename file_data_new_simple to file_data_new_group, filedata.c cleanup
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1927
diff
changeset
|
999 tm->tl->fd = file_data_new_group(tm->dest); |
9 | 1000 tm->tl->source_mtime = strtol(mtime_str, NULL, 10); |
1001 | |
838
fd3a200281f6
use FileData in thumb_loader
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
827
diff
changeset
|
1002 pathl = path_from_utf8(tm->tl->fd->path); |
9 | 1003 g_free(tm->tl->thumb_uri); |
1004 tm->tl->thumb_uri = g_filename_to_uri(pathl, NULL, NULL); | |
1005 tm->tl->local_uri = filename_from_path(tm->tl->thumb_uri); | |
1006 g_free(pathl); | |
1007 | |
1008 g_free(tm->tl->thumb_path); | |
1009 tm->tl->thumb_path = NULL; | |
1010 tm->tl->thumb_path_local = FALSE; | |
1011 | |
506
03d66738b225
Handle the newline in DEBUG_N() macro instead of adding one
Laurent Monin <geeqie@norz.org>
parents:
495
diff
changeset
|
1012 DEBUG_1("thumb move attempting save:"); |
9 | 1013 |
1014 thumb_loader_std_save(tm->tl, pixbuf); | |
1015 } | |
1016 | |
506
03d66738b225
Handle the newline in DEBUG_N() macro instead of adding one
Laurent Monin <geeqie@norz.org>
parents:
495
diff
changeset
|
1017 DEBUG_1("thumb move unlink: %s", tm->thumb_path); |
9 | 1018 unlink_file(tm->thumb_path); |
1019 } | |
1020 | |
1021 thumb_std_maint_move_step(tm); | |
1022 } | |
1023 | |
1024 static void thumb_std_maint_move_step(TMaintMove *tm) | |
1025 { | |
1026 const gchar *folder; | |
1027 | |
1028 tm->pass++; | |
1029 if (tm->pass > 2) | |
1030 { | |
1031 g_free(tm->source); | |
1032 g_free(tm->dest); | |
1033 g_free(tm->source_uri); | |
1034 g_free(tm->thumb_path); | |
1035 g_free(tm); | |
1036 | |
1037 if (thumb_std_maint_move_list) | |
1038 { | |
1039 g_idle_add_full(G_PRIORITY_LOW, thumb_std_maint_move_idle, NULL, NULL); | |
1040 } | |
1041 | |
1042 return; | |
1043 } | |
1044 | |
1045 folder = (tm->pass == 1) ? THUMB_FOLDER_NORMAL : THUMB_FOLDER_LARGE; | |
442 | 1046 |
9 | 1047 g_free(tm->thumb_path); |
1048 tm->thumb_path = thumb_std_cache_path(tm->source, tm->source_uri, FALSE, folder); | |
1049 tm->tl = thumb_loader_std_thumb_file_validate(tm->thumb_path, 0, | |
1050 thumb_std_maint_move_validate_cb, tm); | |
1051 } | |
1052 | |
1446 | 1053 static gboolean thumb_std_maint_move_idle(gpointer data) |
9 | 1054 { |
1055 TMaintMove *tm; | |
1056 gchar *pathl; | |
1057 | |
1058 if (!thumb_std_maint_move_list) return FALSE; | |
1059 | |
1060 tm = thumb_std_maint_move_list->data; | |
1061 | |
1062 thumb_std_maint_move_list = g_list_remove(thumb_std_maint_move_list, tm); | |
1063 if (!thumb_std_maint_move_list) thumb_std_maint_move_tail = NULL; | |
1064 | |
1065 pathl = path_from_utf8(tm->source); | |
1066 tm->source_uri = g_filename_to_uri(pathl, NULL, NULL); | |
1067 g_free(pathl); | |
1068 | |
1069 tm->pass = 0; | |
1070 | |
1071 thumb_std_maint_move_step(tm); | |
1072 | |
1073 return FALSE; | |
1074 } | |
1075 | |
1076 /* This will schedule a move of the thumbnail for source image to dest when idle. | |
1077 * We do this so that file renaming or moving speed is not sacrificed by | |
1078 * moving the thumbnails at the same time because: | |
1079 * | |
1080 * This cache design requires the tedious task of loading the png thumbnails and saving them. | |
1081 * | |
1082 * The thumbnails are processed when the app is idle. If the app | |
1083 * exits early well too bad - they can simply be regenerated from scratch. | |
1084 * | |
1085 * This does not manage local thumbnails (fixme ?) | |
1086 */ | |
1087 void thumb_std_maint_moved(const gchar *source, const gchar *dest) | |
1088 { | |
1089 TMaintMove *tm; | |
1090 | |
1091 tm = g_new0(TMaintMove, 1); | |
1092 tm->source = g_strdup(source); | |
1093 tm->dest = g_strdup(dest); | |
1094 | |
1095 if (!thumb_std_maint_move_list) | |
1096 { | |
1097 g_idle_add_full(G_PRIORITY_LOW, thumb_std_maint_move_idle, NULL, NULL); | |
1098 } | |
1099 | |
827
e3272195662c
Revert patches 759 and 760.
Laurent Monin <geeqie@norz.org>
parents:
717
diff
changeset
|
1100 if (thumb_std_maint_move_tail) |
e3272195662c
Revert patches 759 and 760.
Laurent Monin <geeqie@norz.org>
parents:
717
diff
changeset
|
1101 { |
e3272195662c
Revert patches 759 and 760.
Laurent Monin <geeqie@norz.org>
parents:
717
diff
changeset
|
1102 thumb_std_maint_move_tail = g_list_append(thumb_std_maint_move_tail, tm); |
e3272195662c
Revert patches 759 and 760.
Laurent Monin <geeqie@norz.org>
parents:
717
diff
changeset
|
1103 thumb_std_maint_move_tail = thumb_std_maint_move_tail->next; |
e3272195662c
Revert patches 759 and 760.
Laurent Monin <geeqie@norz.org>
parents:
717
diff
changeset
|
1104 } |
e3272195662c
Revert patches 759 and 760.
Laurent Monin <geeqie@norz.org>
parents:
717
diff
changeset
|
1105 else |
e3272195662c
Revert patches 759 and 760.
Laurent Monin <geeqie@norz.org>
parents:
717
diff
changeset
|
1106 { |
e3272195662c
Revert patches 759 and 760.
Laurent Monin <geeqie@norz.org>
parents:
717
diff
changeset
|
1107 thumb_std_maint_move_list = g_list_append(thumb_std_maint_move_list, tm); |
e3272195662c
Revert patches 759 and 760.
Laurent Monin <geeqie@norz.org>
parents:
717
diff
changeset
|
1108 thumb_std_maint_move_tail = thumb_std_maint_move_list; |
e3272195662c
Revert patches 759 and 760.
Laurent Monin <geeqie@norz.org>
parents:
717
diff
changeset
|
1109 } |
9 | 1110 } |
1055
4bbdfab3c89a
Adding a vim modeline to all files - patch by Klaus Ethgen
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1036
diff
changeset
|
1111 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |