annotate src/cache-loader.c @ 1431:7e180091e0b7

More gboolean and tidy up.
author zas_
date Sat, 14 Mar 2009 11:26:43 +0000
parents c9949c19a6d0
children 24a12aa0cb54
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
1284
8b89e3ff286b Add year 2009 to copyright info everywhere.
zas_
parents: 1148
diff changeset
4 * Copyright (C) 2008 - 2009 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"
1288
10073464e6aa use metadata_read_* functions where possible
nadvornik
parents: 1284
diff changeset
19 #include "metadata.h"
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
20 #include "md5-util.h"
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
21 #include "ui_fileops.h"
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
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
24 static gboolean cache_loader_process(CacheLoader *cl);
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
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
27 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
28 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
29 CacheLoader *cl = data;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
30
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
31 cache_loader_process(cl);
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
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
34 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
35 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
36 CacheLoader *cl = data;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
38 cl->error = TRUE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
39 cache_loader_done_cb(il, data);
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
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
42 static gboolean cache_loader_process(CacheLoader *cl)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
43 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
44 if (cl->todo_mask & CACHE_LOADER_SIMILARITY &&
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
45 !cl->cd->similarity)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
46 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
47 GdkPixbuf *pixbuf;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
48
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
49 if (!cl->il && !cl->error)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
50 {
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 114
diff changeset
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
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 return FALSE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
57 }
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 cl->error = TRUE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
60 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
61
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
62 pixbuf = image_loader_get_pixbuf(cl->il);
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
63 if (pixbuf)
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 if (!cl->error)
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 ImageSimilarityData *sim;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
68
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
69 sim = image_sim_new_from_pixbuf(pixbuf);
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
70 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
71 image_sim_free(sim);
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 cl->done_mask |= CACHE_LOADER_SIMILARITY;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
74 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
75
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
76 /* we have the dimensions via pixbuf */
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
77 if (!cl->cd->dimensions)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
78 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
79 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
80 gdk_pixbuf_get_height(pixbuf));
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
81 if (cl->todo_mask & CACHE_LOADER_DIMENSIONS)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
82 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
83 cl->todo_mask &= ~CACHE_LOADER_DIMENSIONS;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
84 cl->done_mask |= CACHE_LOADER_DIMENSIONS;
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 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
88
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
89 image_loader_free(cl->il);
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
90 cl->il = NULL;
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 cl->todo_mask &= ~CACHE_LOADER_SIMILARITY;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
93 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
94 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
95 !cl->cd->dimensions)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
96 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
97 if (!cl->error &&
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 114
diff changeset
98 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
99 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
100 cl->cd->dimensions = TRUE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
101 cl->done_mask |= CACHE_LOADER_DIMENSIONS;
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 else
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 cl->error = TRUE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
106 }
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 cl->todo_mask &= ~CACHE_LOADER_DIMENSIONS;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
109 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
110 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
111 !cl->cd->have_md5sum)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
112 {
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 114
diff changeset
113 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
114 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
115 cl->cd->have_md5sum = TRUE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
116 cl->done_mask |= CACHE_LOADER_MD5SUM;
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 else
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 cl->error = TRUE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
121 }
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 cl->todo_mask &= ~CACHE_LOADER_MD5SUM;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
124 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
125 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
126 !cl->cd->have_date)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
127 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
128 time_t date = -1;
1288
10073464e6aa use metadata_read_* functions where possible
nadvornik
parents: 1284
diff changeset
129 gchar *text;
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
130
1288
10073464e6aa use metadata_read_* functions where possible
nadvornik
parents: 1284
diff changeset
131 text = metadata_read_string(cl->fd, "formatted.DateTime", METADATA_FORMATTED);
10073464e6aa use metadata_read_* functions where possible
nadvornik
parents: 1284
diff changeset
132 if (text)
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
133 {
1288
10073464e6aa use metadata_read_* functions where possible
nadvornik
parents: 1284
diff changeset
134 struct tm t;
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
135
1288
10073464e6aa use metadata_read_* functions where possible
nadvornik
parents: 1284
diff changeset
136 memset(&t, 0, sizeof(t));
691
631d626c1f6b Fix some incomplete initialization warnings.
zas_
parents: 586
diff changeset
137
1288
10073464e6aa use metadata_read_* functions where possible
nadvornik
parents: 1284
diff changeset
138 if (sscanf(text, "%d:%d:%d %d:%d:%d", &t.tm_year, &t.tm_mon, &t.tm_mday,
10073464e6aa use metadata_read_* functions where possible
nadvornik
parents: 1284
diff changeset
139 &t.tm_hour, &t.tm_min, &t.tm_sec) == 6)
10073464e6aa use metadata_read_* functions where possible
nadvornik
parents: 1284
diff changeset
140 {
10073464e6aa use metadata_read_* functions where possible
nadvornik
parents: 1284
diff changeset
141 t.tm_year -= 1900;
10073464e6aa use metadata_read_* functions where possible
nadvornik
parents: 1284
diff changeset
142 t.tm_mon -= 1;
10073464e6aa use metadata_read_* functions where possible
nadvornik
parents: 1284
diff changeset
143 t.tm_isdst = -1;
10073464e6aa use metadata_read_* functions where possible
nadvornik
parents: 1284
diff changeset
144 date = mktime(&t);
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
145 }
1288
10073464e6aa use metadata_read_* functions where possible
nadvornik
parents: 1284
diff changeset
146 g_free(text);
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
147 }
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 cl->cd->date = date;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
150 cl->cd->have_date = TRUE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
151
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
152 cl->done_mask |= CACHE_LOADER_DATE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
153 cl->todo_mask &= ~CACHE_LOADER_DATE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
154 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
155 else
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 /* done, save then call done function */
333
767b53cd9ab7 Rename thumbnails related options.
zas_
parents: 318
diff changeset
158 if (options->thumbnails.enable_caching &&
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
159 cl->done_mask != CACHE_LOADER_NONE)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
160 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
161 gchar *base;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
162 mode_t mode = 0755;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
163
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 114
diff changeset
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
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
166 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
167 g_free(cl->cd->path);
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 114
diff changeset
168 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
169 if (cache_sim_data_save(cl->cd))
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
170 {
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 114
diff changeset
171 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
172 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
173 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
174 g_free(base);
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
175 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
176
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
177 cl->idle_id = -1;
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 if (cl->done_func)
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 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
182 }
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 return FALSE;
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
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
187 return TRUE;
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
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
190 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
191 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
192 CacheLoader *cl = data;
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 return cache_loader_process(cl);
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
195 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
196
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 114
diff changeset
197 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
198 CacheLoaderDoneFunc done_func, gpointer done_data)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
199 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
200 CacheLoader *cl;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
201 gchar *found;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
202
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 114
diff changeset
203 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
204
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
205 cl = g_new0(CacheLoader, 1);
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 114
diff changeset
206 cl->fd = file_data_ref(fd);
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
207
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
208 cl->done_func = done_func;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
209 cl->done_data = done_data;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
210
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 114
diff changeset
211 found = cache_find_location(CACHE_TYPE_SIM, cl->fd->path);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 114
diff changeset
212 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
213 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
214 cl->cd = cache_sim_data_load(found);
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
215 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
216 g_free(found);
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
217
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
218 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
219
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
220 cl->todo_mask = load_mask;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
221 cl->done_mask = CACHE_LOADER_NONE;
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 cl->il = NULL;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
224 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
225
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
226 cl->error = FALSE;
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 return cl;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
229 }
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 void cache_loader_free(CacheLoader *cl)
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 if (!cl) return;
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 if (cl->idle_id != -1)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
236 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
237 g_source_remove(cl->idle_id);
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
238 cl->idle_id = -1;
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
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
241 image_loader_free(cl->il);
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
242 cache_sim_data_free(cl->cd);
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
243
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 114
diff changeset
244 file_data_unref(cl->fd);
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
245 g_free(cl);
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
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: */