Mercurial > geeqie
annotate src/cache-loader.c @ 884:ff16ed0d2c8a
Improve ways to specify html browser (used for help, see bug 2015099).
Two new rc file options were added:
- helpers.html_browser.command_name
- helpers.html_browser.command_line
These are checked first before trying common browser locations.
If these do not lead to a valid browser, then geeqie will
search for geeqie_html_browser script in the path, then
it will try various common browsers.
| author | zas_ |
|---|---|
| date | Sun, 13 Jul 2008 14:50:07 +0000 |
| parents | efed9a1520d6 |
| children | fe82830ab8fd |
| rev | line source |
|---|---|
| 37 | 1 /* |
| 196 | 2 * Geeqie |
| 37 | 3 * (C) 2005 John Ellis |
| 475 | 4 * Copyright (C) 2008 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" |
| 19 #include "md5-util.h" | |
| 20 #include "ui_fileops.h" | |
| 21 | |
| 22 | |
| 23 static gboolean cache_loader_process(CacheLoader *cl); | |
| 24 | |
| 25 | |
| 26 static void cache_loader_done_cb(ImageLoader *il, gpointer data) | |
| 27 { | |
| 28 CacheLoader *cl = data; | |
| 29 | |
| 30 cache_loader_process(cl); | |
| 31 } | |
| 32 | |
| 33 static void cache_loader_error_cb(ImageLoader *il, gpointer data) | |
| 34 { | |
| 35 CacheLoader *cl = data; | |
| 36 | |
| 37 cl->error = TRUE; | |
| 38 cache_loader_done_cb(il, data); | |
| 39 } | |
| 40 | |
| 41 static gboolean cache_loader_process(CacheLoader *cl) | |
| 42 { | |
| 43 if (cl->todo_mask & CACHE_LOADER_SIMILARITY && | |
| 44 !cl->cd->similarity) | |
| 45 { | |
| 46 GdkPixbuf *pixbuf; | |
| 47 | |
| 48 if (!cl->il && !cl->error) | |
| 49 { | |
| 138 | 50 cl->il = image_loader_new(cl->fd); |
| 37 | 51 image_loader_set_error_func(cl->il, cache_loader_error_cb, cl); |
| 52 if (image_loader_start(cl->il, cache_loader_done_cb, cl)) | |
| 53 { | |
| 54 return FALSE; | |
| 55 } | |
| 56 | |
| 57 cl->error = TRUE; | |
| 58 } | |
| 59 | |
| 60 pixbuf = image_loader_get_pixbuf(cl->il); | |
| 61 if (pixbuf) | |
| 62 { | |
| 63 if (!cl->error) | |
| 64 { | |
| 65 ImageSimilarityData *sim; | |
| 66 | |
| 67 sim = image_sim_new_from_pixbuf(pixbuf); | |
| 68 cache_sim_data_set_similarity(cl->cd, sim); | |
| 69 image_sim_free(sim); | |
| 70 | |
| 71 cl->done_mask |= CACHE_LOADER_SIMILARITY; | |
| 72 } | |
| 73 | |
| 74 /* we have the dimensions via pixbuf */ | |
| 75 if (!cl->cd->dimensions) | |
| 76 { | |
| 77 cache_sim_data_set_dimensions(cl->cd, gdk_pixbuf_get_width(pixbuf), | |
| 78 gdk_pixbuf_get_height(pixbuf)); | |
| 79 if (cl->todo_mask & CACHE_LOADER_DIMENSIONS) | |
| 80 { | |
| 81 cl->todo_mask &= ~CACHE_LOADER_DIMENSIONS; | |
| 82 cl->done_mask |= CACHE_LOADER_DIMENSIONS; | |
| 83 } | |
| 84 } | |
| 85 } | |
| 86 | |
| 87 image_loader_free(cl->il); | |
| 88 cl->il = NULL; | |
| 89 | |
| 90 cl->todo_mask &= ~CACHE_LOADER_SIMILARITY; | |
| 91 } | |
| 92 else if (cl->todo_mask & CACHE_LOADER_DIMENSIONS && | |
| 93 !cl->cd->dimensions) | |
| 94 { | |
| 95 if (!cl->error && | |
| 138 | 96 image_load_dimensions(cl->fd, &cl->cd->width, &cl->cd->height)) |
| 37 | 97 { |
| 98 cl->cd->dimensions = TRUE; | |
| 99 cl->done_mask |= CACHE_LOADER_DIMENSIONS; | |
| 100 } | |
| 101 else | |
| 102 { | |
| 103 cl->error = TRUE; | |
| 104 } | |
| 105 | |
| 106 cl->todo_mask &= ~CACHE_LOADER_DIMENSIONS; | |
| 107 } | |
| 108 else if (cl->todo_mask & CACHE_LOADER_MD5SUM && | |
| 109 !cl->cd->have_md5sum) | |
| 110 { | |
| 138 | 111 if (md5_get_digest_from_file_utf8(cl->fd->path, cl->cd->md5sum)) |
| 37 | 112 { |
| 113 cl->cd->have_md5sum = TRUE; | |
| 114 cl->done_mask |= CACHE_LOADER_MD5SUM; | |
| 115 } | |
| 116 else | |
| 117 { | |
| 118 cl->error = TRUE; | |
| 119 } | |
| 120 | |
| 121 cl->todo_mask &= ~CACHE_LOADER_MD5SUM; | |
| 122 } | |
| 123 else if (cl->todo_mask & CACHE_LOADER_DATE && | |
| 124 !cl->cd->have_date) | |
| 125 { | |
| 126 time_t date = -1; | |
| 127 ExifData *exif; | |
| 128 | |
| 449 | 129 exif = exif_read_fd(cl->fd); |
| 37 | 130 if (exif) |
| 131 { | |
| 132 gchar *text; | |
| 133 | |
|
566
db08ccd54169
Change the prefix of formatted exif tags to a more explicit "formatted." prefix
zas_
parents:
475
diff
changeset
|
134 text = exif_get_data_as_text(exif, "formatted.DateTime"); |
| 37 | 135 if (text) |
| 136 { | |
| 691 | 137 struct tm t; |
| 138 | |
| 139 memset(&t, 0, sizeof(t)); | |
| 37 | 140 |
| 141 if (sscanf(text, "%d:%d:%d %d:%d:%d", &t.tm_year, &t.tm_mon, &t.tm_mday, | |
| 142 &t.tm_hour, &t.tm_min, &t.tm_sec) == 6) | |
| 143 { | |
| 144 t.tm_year -= 1900; | |
| 145 t.tm_mon -= 1; | |
|
62
5c9f78e1c5f5
Thu Jun 16 01:21:43 2005 John Ellis <johne@verizon.net>
gqview
parents:
37
diff
changeset
|
146 t.tm_isdst = -1; |
| 37 | 147 date = mktime(&t); |
| 148 } | |
| 149 g_free(text); | |
| 150 } | |
| 844 | 151 exif_free_fd(cl->fd, exif); |
| 37 | 152 } |
| 153 | |
| 154 cl->cd->date = date; | |
| 155 cl->cd->have_date = TRUE; | |
| 156 | |
| 157 cl->done_mask |= CACHE_LOADER_DATE; | |
| 158 cl->todo_mask &= ~CACHE_LOADER_DATE; | |
| 159 } | |
| 160 else | |
| 161 { | |
| 162 /* done, save then call done function */ | |
| 333 | 163 if (options->thumbnails.enable_caching && |
| 37 | 164 cl->done_mask != CACHE_LOADER_NONE) |
| 165 { | |
| 166 gchar *base; | |
| 167 mode_t mode = 0755; | |
| 168 | |
| 138 | 169 base = cache_get_location(CACHE_TYPE_SIM, cl->fd->path, FALSE, &mode); |
| 37 | 170 if (cache_ensure_dir_exists(base, mode)) |
| 171 { | |
| 172 g_free(cl->cd->path); | |
| 138 | 173 cl->cd->path = cache_get_location(CACHE_TYPE_SIM, cl->fd->path, TRUE, NULL); |
| 37 | 174 if (cache_sim_data_save(cl->cd)) |
| 175 { | |
| 138 | 176 filetime_set(cl->cd->path, filetime(cl->fd->path)); |
| 37 | 177 } |
| 178 } | |
| 179 g_free(base); | |
| 180 } | |
| 181 | |
| 182 cl->idle_id = -1; | |
| 183 | |
| 184 if (cl->done_func) | |
| 185 { | |
| 186 cl->done_func(cl, cl->error, cl->done_data); | |
| 187 } | |
| 188 | |
| 189 return FALSE; | |
| 190 } | |
| 191 | |
| 192 return TRUE; | |
| 193 } | |
| 194 | |
| 195 static gboolean cache_loader_idle_cb(gpointer data) | |
| 196 { | |
| 197 CacheLoader *cl = data; | |
| 198 | |
| 199 return cache_loader_process(cl); | |
| 200 } | |
| 201 | |
| 138 | 202 CacheLoader *cache_loader_new(FileData *fd, CacheDataType load_mask, |
| 37 | 203 CacheLoaderDoneFunc done_func, gpointer done_data) |
| 204 { | |
| 205 CacheLoader *cl; | |
| 206 gchar *found; | |
| 207 | |
| 138 | 208 if (!fd || !isfile(fd->path)) return NULL; |
| 37 | 209 |
| 210 cl = g_new0(CacheLoader, 1); | |
| 138 | 211 cl->fd = file_data_ref(fd); |
| 37 | 212 |
| 213 cl->done_func = done_func; | |
| 214 cl->done_data = done_data; | |
| 215 | |
| 138 | 216 found = cache_find_location(CACHE_TYPE_SIM, cl->fd->path); |
| 217 if (found && filetime(found) == filetime(cl->fd->path)) | |
| 37 | 218 { |
| 219 cl->cd = cache_sim_data_load(found); | |
| 220 } | |
| 221 g_free(found); | |
| 222 | |
| 223 if (!cl->cd) cl->cd = cache_sim_data_new(); | |
| 224 | |
| 225 cl->todo_mask = load_mask; | |
| 226 cl->done_mask = CACHE_LOADER_NONE; | |
| 227 | |
| 228 cl->il = NULL; | |
| 229 cl->idle_id = g_idle_add(cache_loader_idle_cb, cl); | |
| 230 | |
| 231 cl->error = FALSE; | |
| 232 | |
| 233 return cl; | |
| 234 } | |
| 235 | |
| 236 void cache_loader_free(CacheLoader *cl) | |
| 237 { | |
| 238 if (!cl) return; | |
| 239 | |
| 240 if (cl->idle_id != -1) | |
| 241 { | |
| 242 g_source_remove(cl->idle_id); | |
| 243 cl->idle_id = -1; | |
| 244 } | |
| 245 | |
| 246 image_loader_free(cl->il); | |
| 247 cache_sim_data_free(cl->cd); | |
| 248 | |
| 138 | 249 file_data_unref(cl->fd); |
| 37 | 250 g_free(cl); |
| 251 } |
