annotate src/thumb_standard.c @ 33:a41ecbb26a96

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