comparison src/cache-loader.c @ 138:71e1ebee420e

replaced gchar* path with FileData *fd
author nadvornik
date Tue, 11 Sep 2007 20:06:29 +0000
parents 50fc73e08550
children 0ca3b4c8ffae
comparison
equal deleted inserted replaced
137:be3328a58875 138:71e1ebee420e
9 * This software comes with no warranty of any kind, use at your own risk! 9 * This software comes with no warranty of any kind, use at your own risk!
10 */ 10 */
11 11
12 #include "gqview.h" 12 #include "gqview.h"
13 #include "cache-loader.h" 13 #include "cache-loader.h"
14 14 #include "cache.h"
15
16 #include "filelist.h"
15 #include "exif.h" 17 #include "exif.h"
16 #include "md5-util.h" 18 #include "md5-util.h"
17 #include "ui_fileops.h" 19 #include "ui_fileops.h"
18 20
19 21
42 { 44 {
43 GdkPixbuf *pixbuf; 45 GdkPixbuf *pixbuf;
44 46
45 if (!cl->il && !cl->error) 47 if (!cl->il && !cl->error)
46 { 48 {
47 cl->il = image_loader_new(cl->path); 49 cl->il = image_loader_new(cl->fd);
48 image_loader_set_error_func(cl->il, cache_loader_error_cb, cl); 50 image_loader_set_error_func(cl->il, cache_loader_error_cb, cl);
49 if (image_loader_start(cl->il, cache_loader_done_cb, cl)) 51 if (image_loader_start(cl->il, cache_loader_done_cb, cl))
50 { 52 {
51 return FALSE; 53 return FALSE;
52 } 54 }
88 } 90 }
89 else if (cl->todo_mask & CACHE_LOADER_DIMENSIONS && 91 else if (cl->todo_mask & CACHE_LOADER_DIMENSIONS &&
90 !cl->cd->dimensions) 92 !cl->cd->dimensions)
91 { 93 {
92 if (!cl->error && 94 if (!cl->error &&
93 image_load_dimensions(cl->path, &cl->cd->width, &cl->cd->height)) 95 image_load_dimensions(cl->fd, &cl->cd->width, &cl->cd->height))
94 { 96 {
95 cl->cd->dimensions = TRUE; 97 cl->cd->dimensions = TRUE;
96 cl->done_mask |= CACHE_LOADER_DIMENSIONS; 98 cl->done_mask |= CACHE_LOADER_DIMENSIONS;
97 } 99 }
98 else 100 else
103 cl->todo_mask &= ~CACHE_LOADER_DIMENSIONS; 105 cl->todo_mask &= ~CACHE_LOADER_DIMENSIONS;
104 } 106 }
105 else if (cl->todo_mask & CACHE_LOADER_MD5SUM && 107 else if (cl->todo_mask & CACHE_LOADER_MD5SUM &&
106 !cl->cd->have_md5sum) 108 !cl->cd->have_md5sum)
107 { 109 {
108 if (md5_get_digest_from_file_utf8(cl->path, cl->cd->md5sum)) 110 if (md5_get_digest_from_file_utf8(cl->fd->path, cl->cd->md5sum))
109 { 111 {
110 cl->cd->have_md5sum = TRUE; 112 cl->cd->have_md5sum = TRUE;
111 cl->done_mask |= CACHE_LOADER_MD5SUM; 113 cl->done_mask |= CACHE_LOADER_MD5SUM;
112 } 114 }
113 else 115 else
121 !cl->cd->have_date) 123 !cl->cd->have_date)
122 { 124 {
123 time_t date = -1; 125 time_t date = -1;
124 ExifData *exif; 126 ExifData *exif;
125 127
126 exif = exif_read(cl->path, FALSE); 128 exif = exif_read(cl->fd, FALSE);
127 if (exif) 129 if (exif)
128 { 130 {
129 gchar *text; 131 gchar *text;
130 132
131 text = exif_get_data_as_text(exif, "fDateTime"); 133 text = exif_get_data_as_text(exif, "fDateTime");
159 cl->done_mask != CACHE_LOADER_NONE) 161 cl->done_mask != CACHE_LOADER_NONE)
160 { 162 {
161 gchar *base; 163 gchar *base;
162 mode_t mode = 0755; 164 mode_t mode = 0755;
163 165
164 base = cache_get_location(CACHE_TYPE_SIM, cl->path, FALSE, &mode); 166 base = cache_get_location(CACHE_TYPE_SIM, cl->fd->path, FALSE, &mode);
165 if (cache_ensure_dir_exists(base, mode)) 167 if (cache_ensure_dir_exists(base, mode))
166 { 168 {
167 g_free(cl->cd->path); 169 g_free(cl->cd->path);
168 cl->cd->path = cache_get_location(CACHE_TYPE_SIM, cl->path, TRUE, NULL); 170 cl->cd->path = cache_get_location(CACHE_TYPE_SIM, cl->fd->path, TRUE, NULL);
169 if (cache_sim_data_save(cl->cd)) 171 if (cache_sim_data_save(cl->cd))
170 { 172 {
171 filetime_set(cl->cd->path, filetime(cl->path)); 173 filetime_set(cl->cd->path, filetime(cl->fd->path));
172 } 174 }
173 } 175 }
174 g_free(base); 176 g_free(base);
175 } 177 }
176 178
192 CacheLoader *cl = data; 194 CacheLoader *cl = data;
193 195
194 return cache_loader_process(cl); 196 return cache_loader_process(cl);
195 } 197 }
196 198
197 CacheLoader *cache_loader_new(const gchar *path, CacheDataType load_mask, 199 CacheLoader *cache_loader_new(FileData *fd, CacheDataType load_mask,
198 CacheLoaderDoneFunc done_func, gpointer done_data) 200 CacheLoaderDoneFunc done_func, gpointer done_data)
199 { 201 {
200 CacheLoader *cl; 202 CacheLoader *cl;
201 gchar *found; 203 gchar *found;
202 204
203 if (!path || !isfile(path)) return NULL; 205 if (!fd || !isfile(fd->path)) return NULL;
204 206
205 cl = g_new0(CacheLoader, 1); 207 cl = g_new0(CacheLoader, 1);
206 cl->path = g_strdup(path); 208 cl->fd = file_data_ref(fd);
207 209
208 cl->done_func = done_func; 210 cl->done_func = done_func;
209 cl->done_data = done_data; 211 cl->done_data = done_data;
210 212
211 found = cache_find_location(CACHE_TYPE_SIM, path); 213 found = cache_find_location(CACHE_TYPE_SIM, cl->fd->path);
212 if (found && filetime(found) == filetime(path)) 214 if (found && filetime(found) == filetime(cl->fd->path))
213 { 215 {
214 cl->cd = cache_sim_data_load(found); 216 cl->cd = cache_sim_data_load(found);
215 } 217 }
216 g_free(found); 218 g_free(found);
217 219
239 } 241 }
240 242
241 image_loader_free(cl->il); 243 image_loader_free(cl->il);
242 cache_sim_data_free(cl->cd); 244 cache_sim_data_free(cl->cd);
243 245
244 g_free(cl->path); 246 file_data_unref(cl->fd);
245 g_free(cl); 247 g_free(cl);
246 } 248 }
247 249