annotate src/cache-loader.c @ 836:1af95bada7e7

preserve image center on refresh
author nadvornik
date Sat, 14 Jun 2008 18:41:30 +0000
parents 631d626c1f6b
children efed9a1520d6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
1 /*
196
f6e307c7bad6 rename GQview -> Geeqie over the code
nadvornik
parents: 188
diff changeset
2 * Geeqie
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
3 * (C) 2005 John Ellis
475
48c8e49b571c updated copyright in source files
nadvornik
parents: 449
diff changeset
4 * Copyright (C) 2008 The Geeqie Team
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
5 *
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
6 * Author: John Ellis
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
7 *
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
8 * This software is released under the GNU General Public License (GNU GPL).
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
9 * Please read the included file COPYING for more information.
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
10 * This software comes with no warranty of any kind, use at your own risk!
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
11 */
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
12
281
9995c5fb202a gqview.h -> main.h
zas_
parents: 196
diff changeset
13 #include "main.h"
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
14 #include "cache-loader.h"
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 114
diff changeset
15 #include "cache.h"
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
16
586
905688aa2317 split filelist.c to filefilter.c and filedata.c
nadvornik
parents: 566
diff changeset
17 #include "filedata.h"
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
18 #include "exif.h"
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
19 #include "md5-util.h"
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
20 #include "ui_fileops.h"
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
21
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
22
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
23 static gboolean cache_loader_process(CacheLoader *cl);
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
24
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
25
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
26 static void cache_loader_done_cb(ImageLoader *il, gpointer data)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
27 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
28 CacheLoader *cl = data;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
29
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
30 cache_loader_process(cl);
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
31 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
32
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
33 static void cache_loader_error_cb(ImageLoader *il, gpointer data)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
34 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
35 CacheLoader *cl = data;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
36
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
37 cl->error = TRUE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
38 cache_loader_done_cb(il, data);
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
39 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
40
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
41 static gboolean cache_loader_process(CacheLoader *cl)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
42 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
43 if (cl->todo_mask & CACHE_LOADER_SIMILARITY &&
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
44 !cl->cd->similarity)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
45 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
46 GdkPixbuf *pixbuf;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
47
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
48 if (!cl->il && !cl->error)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
49 {
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 114
diff changeset
50 cl->il = image_loader_new(cl->fd);
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
51 image_loader_set_error_func(cl->il, cache_loader_error_cb, cl);
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
52 if (image_loader_start(cl->il, cache_loader_done_cb, cl))
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
53 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
54 return FALSE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
55 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
56
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
57 cl->error = TRUE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
58 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
59
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
60 pixbuf = image_loader_get_pixbuf(cl->il);
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
61 if (pixbuf)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
62 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
63 if (!cl->error)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
64 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
65 ImageSimilarityData *sim;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
66
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
67 sim = image_sim_new_from_pixbuf(pixbuf);
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
68 cache_sim_data_set_similarity(cl->cd, sim);
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
69 image_sim_free(sim);
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
70
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
71 cl->done_mask |= CACHE_LOADER_SIMILARITY;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
72 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
73
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
74 /* we have the dimensions via pixbuf */
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
75 if (!cl->cd->dimensions)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
76 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
77 cache_sim_data_set_dimensions(cl->cd, gdk_pixbuf_get_width(pixbuf),
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
78 gdk_pixbuf_get_height(pixbuf));
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
79 if (cl->todo_mask & CACHE_LOADER_DIMENSIONS)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
80 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
81 cl->todo_mask &= ~CACHE_LOADER_DIMENSIONS;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
82 cl->done_mask |= CACHE_LOADER_DIMENSIONS;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
83 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
84 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
85 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
86
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
87 image_loader_free(cl->il);
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
88 cl->il = NULL;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
89
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
90 cl->todo_mask &= ~CACHE_LOADER_SIMILARITY;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
91 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
92 else if (cl->todo_mask & CACHE_LOADER_DIMENSIONS &&
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
93 !cl->cd->dimensions)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
94 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
95 if (!cl->error &&
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 114
diff changeset
96 image_load_dimensions(cl->fd, &cl->cd->width, &cl->cd->height))
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
97 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
98 cl->cd->dimensions = TRUE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
99 cl->done_mask |= CACHE_LOADER_DIMENSIONS;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
100 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
101 else
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
102 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
103 cl->error = TRUE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
104 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
105
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
106 cl->todo_mask &= ~CACHE_LOADER_DIMENSIONS;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
107 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
108 else if (cl->todo_mask & CACHE_LOADER_MD5SUM &&
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
109 !cl->cd->have_md5sum)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
110 {
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 114
diff changeset
111 if (md5_get_digest_from_file_utf8(cl->fd->path, cl->cd->md5sum))
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
112 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
113 cl->cd->have_md5sum = TRUE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
114 cl->done_mask |= CACHE_LOADER_MD5SUM;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
115 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
116 else
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
117 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
118 cl->error = TRUE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
119 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
120
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
121 cl->todo_mask &= ~CACHE_LOADER_MD5SUM;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
122 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
123 else if (cl->todo_mask & CACHE_LOADER_DATE &&
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
124 !cl->cd->have_date)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
125 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
126 time_t date = -1;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
127 ExifData *exif;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
128
449
115db540bd0c read color profiles from jpeg also with Exiv2
nadvornik
parents: 446
diff changeset
129 exif = exif_read_fd(cl->fd);
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
130 if (exif)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
131 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
132 gchar *text;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
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
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
135 if (text)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
136 {
691
631d626c1f6b Fix some incomplete initialization warnings.
zas_
parents: 586
diff changeset
137 struct tm t;
631d626c1f6b Fix some incomplete initialization warnings.
zas_
parents: 586
diff changeset
138
631d626c1f6b Fix some incomplete initialization warnings.
zas_
parents: 586
diff changeset
139 memset(&t, 0, sizeof(t));
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
140
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
141 if (sscanf(text, "%d:%d:%d %d:%d:%d", &t.tm_year, &t.tm_mon, &t.tm_mday,
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
142 &t.tm_hour, &t.tm_min, &t.tm_sec) == 6)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
143 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
144 t.tm_year -= 1900;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
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
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
147 date = mktime(&t);
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
148 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
149 g_free(text);
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
150 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
151 exif_free(exif);
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
152 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
153
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
154 cl->cd->date = date;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
155 cl->cd->have_date = TRUE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
156
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
157 cl->done_mask |= CACHE_LOADER_DATE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
158 cl->todo_mask &= ~CACHE_LOADER_DATE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
159 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
160 else
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
161 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
162 /* done, save then call done function */
333
767b53cd9ab7 Rename thumbnails related options.
zas_
parents: 318
diff changeset
163 if (options->thumbnails.enable_caching &&
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
164 cl->done_mask != CACHE_LOADER_NONE)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
165 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
166 gchar *base;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
167 mode_t mode = 0755;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
168
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 114
diff changeset
169 base = cache_get_location(CACHE_TYPE_SIM, cl->fd->path, FALSE, &mode);
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
170 if (cache_ensure_dir_exists(base, mode))
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
171 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
172 g_free(cl->cd->path);
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 114
diff changeset
173 cl->cd->path = cache_get_location(CACHE_TYPE_SIM, cl->fd->path, TRUE, NULL);
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
174 if (cache_sim_data_save(cl->cd))
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
175 {
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 114
diff changeset
176 filetime_set(cl->cd->path, filetime(cl->fd->path));
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
177 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
178 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
179 g_free(base);
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
180 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
181
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
182 cl->idle_id = -1;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
183
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
184 if (cl->done_func)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
185 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
186 cl->done_func(cl, cl->error, cl->done_data);
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
187 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
188
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
189 return FALSE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
190 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
191
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
192 return TRUE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
193 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
194
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
195 static gboolean cache_loader_idle_cb(gpointer data)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
196 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
197 CacheLoader *cl = data;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
198
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
199 return cache_loader_process(cl);
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
200 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
201
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 114
diff changeset
202 CacheLoader *cache_loader_new(FileData *fd, CacheDataType load_mask,
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
203 CacheLoaderDoneFunc done_func, gpointer done_data)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
204 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
205 CacheLoader *cl;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
206 gchar *found;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
207
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 114
diff changeset
208 if (!fd || !isfile(fd->path)) return NULL;
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
209
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
210 cl = g_new0(CacheLoader, 1);
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 114
diff changeset
211 cl->fd = file_data_ref(fd);
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
212
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
213 cl->done_func = done_func;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
214 cl->done_data = done_data;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
215
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 114
diff changeset
216 found = cache_find_location(CACHE_TYPE_SIM, cl->fd->path);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 114
diff changeset
217 if (found && filetime(found) == filetime(cl->fd->path))
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
218 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
219 cl->cd = cache_sim_data_load(found);
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
220 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
221 g_free(found);
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
222
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
223 if (!cl->cd) cl->cd = cache_sim_data_new();
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
224
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
225 cl->todo_mask = load_mask;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
226 cl->done_mask = CACHE_LOADER_NONE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
227
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
228 cl->il = NULL;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
229 cl->idle_id = g_idle_add(cache_loader_idle_cb, cl);
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
230
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
231 cl->error = FALSE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
232
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
233 return cl;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
234 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
235
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
236 void cache_loader_free(CacheLoader *cl)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
237 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
238 if (!cl) return;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
239
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
240 if (cl->idle_id != -1)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
241 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
242 g_source_remove(cl->idle_id);
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
243 cl->idle_id = -1;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
244 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
245
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
246 image_loader_free(cl->il);
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
247 cache_sim_data_free(cl->cd);
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
248
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 114
diff changeset
249 file_data_unref(cl->fd);
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
250 g_free(cl);
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
251 }