Mercurial > geeqie
annotate src/cache-loader.c @ 1766:6e0f6d5e4c25
added a workaround for https://bugzilla.gnome.org/show_bug.cgi?id=590692
author | nadvornik |
---|---|
date | Sat, 10 Oct 2009 15:01:41 +0000 |
parents | 24a12aa0cb54 |
children | 956aab097ea7 |
rev | line source |
---|---|
37 | 1 /* |
196 | 2 * Geeqie |
37 | 3 * (C) 2005 John Ellis |
1284 | 4 * Copyright (C) 2008 - 2009 The Geeqie Team |
37 | 5 * |
6 * Author: John Ellis | |
7 * | |
8 * This software is released under the GNU General Public License (GNU GPL). | |
9 * Please read the included file COPYING for more information. | |
10 * This software comes with no warranty of any kind, use at your own risk! | |
11 */ | |
12 | |
281 | 13 #include "main.h" |
37 | 14 #include "cache-loader.h" |
138 | 15 #include "cache.h" |
37 | 16 |
586 | 17 #include "filedata.h" |
37 | 18 #include "exif.h" |
1288 | 19 #include "metadata.h" |
37 | 20 #include "md5-util.h" |
21 #include "ui_fileops.h" | |
22 | |
23 | |
24 static gboolean cache_loader_process(CacheLoader *cl); | |
25 | |
26 | |
27 static void cache_loader_done_cb(ImageLoader *il, gpointer data) | |
28 { | |
29 CacheLoader *cl = data; | |
30 | |
31 cache_loader_process(cl); | |
32 } | |
33 | |
34 static void cache_loader_error_cb(ImageLoader *il, gpointer data) | |
35 { | |
36 CacheLoader *cl = data; | |
37 | |
38 cl->error = TRUE; | |
39 cache_loader_done_cb(il, data); | |
40 } | |
41 | |
42 static gboolean cache_loader_process(CacheLoader *cl) | |
43 { | |
44 if (cl->todo_mask & CACHE_LOADER_SIMILARITY && | |
45 !cl->cd->similarity) | |
46 { | |
47 GdkPixbuf *pixbuf; | |
48 | |
49 if (!cl->il && !cl->error) | |
50 { | |
138 | 51 cl->il = image_loader_new(cl->fd); |
1346
c9949c19a6d0
No space between function name and first parenthesis, it eases greping (see CODING).
zas_
parents:
1288
diff
changeset
|
52 g_signal_connect(G_OBJECT(cl->il), "error", (GCallback)cache_loader_error_cb, cl); |
c9949c19a6d0
No space between function name and first parenthesis, it eases greping (see CODING).
zas_
parents:
1288
diff
changeset
|
53 g_signal_connect(G_OBJECT(cl->il), "done", (GCallback)cache_loader_done_cb, cl); |
1012
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
844
diff
changeset
|
54 if (image_loader_start(cl->il)) |
37 | 55 { |
56 return FALSE; | |
57 } | |
58 | |
59 cl->error = TRUE; | |
60 } | |
61 | |
62 pixbuf = image_loader_get_pixbuf(cl->il); | |
63 if (pixbuf) | |
64 { | |
65 if (!cl->error) | |
66 { | |
67 ImageSimilarityData *sim; | |
68 | |
69 sim = image_sim_new_from_pixbuf(pixbuf); | |
70 cache_sim_data_set_similarity(cl->cd, sim); | |
71 image_sim_free(sim); | |
72 | |
73 cl->done_mask |= CACHE_LOADER_SIMILARITY; | |
74 } | |
75 | |
76 /* we have the dimensions via pixbuf */ | |
77 if (!cl->cd->dimensions) | |
78 { | |
79 cache_sim_data_set_dimensions(cl->cd, gdk_pixbuf_get_width(pixbuf), | |
80 gdk_pixbuf_get_height(pixbuf)); | |
81 if (cl->todo_mask & CACHE_LOADER_DIMENSIONS) | |
82 { | |
83 cl->todo_mask &= ~CACHE_LOADER_DIMENSIONS; | |
84 cl->done_mask |= CACHE_LOADER_DIMENSIONS; | |
85 } | |
86 } | |
87 } | |
88 | |
89 image_loader_free(cl->il); | |
90 cl->il = NULL; | |
91 | |
92 cl->todo_mask &= ~CACHE_LOADER_SIMILARITY; | |
93 } | |
94 else if (cl->todo_mask & CACHE_LOADER_DIMENSIONS && | |
95 !cl->cd->dimensions) | |
96 { | |
97 if (!cl->error && | |
138 | 98 image_load_dimensions(cl->fd, &cl->cd->width, &cl->cd->height)) |
37 | 99 { |
100 cl->cd->dimensions = TRUE; | |
101 cl->done_mask |= CACHE_LOADER_DIMENSIONS; | |
102 } | |
103 else | |
104 { | |
105 cl->error = TRUE; | |
106 } | |
107 | |
108 cl->todo_mask &= ~CACHE_LOADER_DIMENSIONS; | |
109 } | |
110 else if (cl->todo_mask & CACHE_LOADER_MD5SUM && | |
111 !cl->cd->have_md5sum) | |
112 { | |
138 | 113 if (md5_get_digest_from_file_utf8(cl->fd->path, cl->cd->md5sum)) |
37 | 114 { |
115 cl->cd->have_md5sum = TRUE; | |
116 cl->done_mask |= CACHE_LOADER_MD5SUM; | |
117 } | |
118 else | |
119 { | |
120 cl->error = TRUE; | |
121 } | |
122 | |
123 cl->todo_mask &= ~CACHE_LOADER_MD5SUM; | |
124 } | |
125 else if (cl->todo_mask & CACHE_LOADER_DATE && | |
126 !cl->cd->have_date) | |
127 { | |
128 time_t date = -1; | |
1288 | 129 gchar *text; |
37 | 130 |
1288 | 131 text = metadata_read_string(cl->fd, "formatted.DateTime", METADATA_FORMATTED); |
132 if (text) | |
37 | 133 { |
1288 | 134 struct tm t; |
37 | 135 |
1288 | 136 memset(&t, 0, sizeof(t)); |
691 | 137 |
1288 | 138 if (sscanf(text, "%d:%d:%d %d:%d:%d", &t.tm_year, &t.tm_mon, &t.tm_mday, |
139 &t.tm_hour, &t.tm_min, &t.tm_sec) == 6) | |
140 { | |
141 t.tm_year -= 1900; | |
142 t.tm_mon -= 1; | |
143 t.tm_isdst = -1; | |
144 date = mktime(&t); | |
37 | 145 } |
1288 | 146 g_free(text); |
37 | 147 } |
148 | |
149 cl->cd->date = date; | |
150 cl->cd->have_date = TRUE; | |
151 | |
152 cl->done_mask |= CACHE_LOADER_DATE; | |
153 cl->todo_mask &= ~CACHE_LOADER_DATE; | |
154 } | |
155 else | |
156 { | |
157 /* done, save then call done function */ | |
333 | 158 if (options->thumbnails.enable_caching && |
37 | 159 cl->done_mask != CACHE_LOADER_NONE) |
160 { | |
161 gchar *base; | |
162 mode_t mode = 0755; | |
163 | |
138 | 164 base = cache_get_location(CACHE_TYPE_SIM, cl->fd->path, FALSE, &mode); |
1148
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1055
diff
changeset
|
165 if (recursive_mkdir_if_not_exists(base, mode)) |
37 | 166 { |
167 g_free(cl->cd->path); | |
138 | 168 cl->cd->path = cache_get_location(CACHE_TYPE_SIM, cl->fd->path, TRUE, NULL); |
37 | 169 if (cache_sim_data_save(cl->cd)) |
170 { | |
138 | 171 filetime_set(cl->cd->path, filetime(cl->fd->path)); |
37 | 172 } |
173 } | |
174 g_free(base); | |
175 } | |
176 | |
1523 | 177 cl->idle_id = 0; |
37 | 178 |
179 if (cl->done_func) | |
180 { | |
181 cl->done_func(cl, cl->error, cl->done_data); | |
182 } | |
183 | |
184 return FALSE; | |
185 } | |
186 | |
187 return TRUE; | |
188 } | |
189 | |
190 static gboolean cache_loader_idle_cb(gpointer data) | |
191 { | |
192 CacheLoader *cl = data; | |
193 | |
194 return cache_loader_process(cl); | |
195 } | |
196 | |
138 | 197 CacheLoader *cache_loader_new(FileData *fd, CacheDataType load_mask, |
37 | 198 CacheLoaderDoneFunc done_func, gpointer done_data) |
199 { | |
200 CacheLoader *cl; | |
201 gchar *found; | |
202 | |
138 | 203 if (!fd || !isfile(fd->path)) return NULL; |
37 | 204 |
205 cl = g_new0(CacheLoader, 1); | |
138 | 206 cl->fd = file_data_ref(fd); |
37 | 207 |
208 cl->done_func = done_func; | |
209 cl->done_data = done_data; | |
210 | |
138 | 211 found = cache_find_location(CACHE_TYPE_SIM, cl->fd->path); |
212 if (found && filetime(found) == filetime(cl->fd->path)) | |
37 | 213 { |
214 cl->cd = cache_sim_data_load(found); | |
215 } | |
216 g_free(found); | |
217 | |
218 if (!cl->cd) cl->cd = cache_sim_data_new(); | |
219 | |
220 cl->todo_mask = load_mask; | |
221 cl->done_mask = CACHE_LOADER_NONE; | |
222 | |
223 cl->il = NULL; | |
224 cl->idle_id = g_idle_add(cache_loader_idle_cb, cl); | |
225 | |
226 cl->error = FALSE; | |
227 | |
228 return cl; | |
229 } | |
230 | |
231 void cache_loader_free(CacheLoader *cl) | |
232 { | |
233 if (!cl) return; | |
234 | |
1523 | 235 if (cl->idle_id) |
37 | 236 { |
237 g_source_remove(cl->idle_id); | |
1523 | 238 cl->idle_id = 0; |
37 | 239 } |
240 | |
241 image_loader_free(cl->il); | |
242 cache_sim_data_free(cl->cd); | |
243 | |
138 | 244 file_data_unref(cl->fd); |
37 | 245 g_free(cl); |
246 } | |
1055
1646720364cf
Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents:
1012
diff
changeset
|
247 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |