annotate src/cache.c @ 506:fc9c8a3e1a8b

Handle the newline in DEBUG_N() macro instead of adding one in each debug message string.
author zas_
date Thu, 24 Apr 2008 00:15:03 +0000
parents c7a2471e5c4e
children 135570a8bd96
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
1 /*
196
f6e307c7bad6 rename GQview -> Geeqie over the code
nadvornik
parents: 65
diff changeset
2 * Geeqie
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
3 * (C) 2004 John Ellis
475
48c8e49b571c updated copyright in source files
nadvornik
parents: 446
diff changeset
4 * Copyright (C) 2008 The Geeqie Team
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
5 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
6 * Author: John Ellis
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
7 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
8 * This software is released under the GNU General Public License (GNU GPL).
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
9 * Please read the included file COPYING for more information.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
10 * This software comes with no warranty of any kind, use at your own risk!
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
11 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
12
281
9995c5fb202a gqview.h -> main.h
zas_
parents: 196
diff changeset
13 #include "main.h"
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
14 #include "cache.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
15
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
16 #include "md5-util.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
17 #include "ui_fileops.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
18
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
19 #include <utime.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
20 #include <errno.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
21
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
22
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
23 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
24 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
25 * Cache data file format:
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
26 *-------------------------------------------------------------------
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 333
diff changeset
27 *
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
28 * SIMcache
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
29 * #coment
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
30 * Dimensions=[<width> x <height>]
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
31 * Date=[<value in time_t format, or -1 if no embedded date>]
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
32 * Checksum=[<value>]
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
33 * MD5sum=[<32 character ascii text digest>]
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
34 * SimilarityGrid[32 x 32]=<3072 bytes of data (1024 pixels in RGB format, 1 pixel is 24bits)>
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 333
diff changeset
35 *
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 333
diff changeset
36 *
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
37 * The first line (9 bytes) indicates it is a SIMcache format file. (new line char must exist)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
38 * Comment lines starting with a # are ignored up to a new line.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
39 * All data lines should end with a new line char.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
40 * Format is very strict, data must begin with the char immediately following '='.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
41 * Currently SimilarityGrid is always assumed to be 32 x 32 RGB.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
42 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
43
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
44
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
45 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
46 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
47 * sim cache data
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
48 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
49 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
50
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
51 CacheData *cache_sim_data_new(void)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
52 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
53 CacheData *cd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
54
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
55 cd = g_new0(CacheData, 1);
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
56 cd->date = -1;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
57
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
58 return cd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
59 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
60
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
61 void cache_sim_data_free(CacheData *cd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
62 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
63 if (!cd) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
64
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
65 g_free(cd->path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
66 image_sim_free(cd->sim);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
67 g_free(cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
68 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
69
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
70 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
71 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
72 * sim cache write
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
73 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
74 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
75
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
76 static gint cache_sim_write_dimensions(FILE *f, CacheData *cd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
77 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
78 if (!f || !cd || !cd->dimensions) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
79
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
80 fprintf(f, "Dimensions=[%d x %d]\n", cd->width, cd->height);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
81
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
82 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
83 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
84
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
85 static gint cache_sim_write_date(FILE *f, CacheData *cd)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
86 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
87 if (!f || !cd || !cd->have_date) return FALSE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
88
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
89 fprintf(f, "Date=[%ld]\n", cd->date);
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
90
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
91 return TRUE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
92 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
93
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
94 static gint cache_sim_write_checksum(FILE *f, CacheData *cd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
95 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
96 if (!f || !cd || !cd->have_checksum) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
97
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
98 fprintf(f, "Checksum=[%ld]\n", cd->checksum);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
99
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
100 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
101 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
102
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
103 static gint cache_sim_write_md5sum(FILE *f, CacheData *cd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
104 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
105 gchar *text;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
106
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
107 if (!f || !cd || !cd->have_md5sum) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
108
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
109 text = md5_digest_to_text(cd->md5sum);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
110 fprintf(f, "MD5sum=[%s]\n", text);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
111 g_free(text);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
112
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
113 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
114 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
115
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
116 static gint cache_sim_write_similarity(FILE *f, CacheData *cd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
117 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
118 gint success = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
119
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
120 if (!f || !cd || !cd->similarity) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
121
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
122 if (cd->sim && cd->sim->filled)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
123 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
124 gint x, y;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
125 guint8 buf[96];
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
126
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
127 fprintf(f, "SimilarityGrid[32 x 32]=");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
128 for (y = 0; y < 32; y++)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
129 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
130 gint s;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
131 guint8 *p;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
132
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
133 s = y * 32;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
134 p = buf;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
135 for(x = 0; x < 32; x++)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
136 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
137 *p = cd->sim->avg_r[s + x]; p++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
138 *p = cd->sim->avg_g[s + x]; p++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
139 *p = cd->sim->avg_b[s + x]; p++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
140 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
141 fwrite(buf, sizeof(buf), 1, f);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
142 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
143
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
144 fprintf(f, "\n");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
145 success = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
146 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
147
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
148 return success;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
149 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
150
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
151 gint cache_sim_data_save(CacheData *cd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
152 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
153 FILE *f;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
154 gchar *pathl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
155
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
156 if (!cd || !cd->path) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
157
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
158 pathl = path_from_utf8(cd->path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
159 f = fopen(pathl, "w");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
160 g_free(pathl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
161
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
162 if (!f)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
163 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
164 printf("Unable to save sim cache data: %s\n", cd->path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
165 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
166 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
167
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
168 fprintf(f, "SIMcache\n#%s %s\n", PACKAGE, VERSION);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
169 cache_sim_write_dimensions(f, cd);
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
170 cache_sim_write_date(f, cd);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
171 cache_sim_write_checksum(f, cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
172 cache_sim_write_md5sum(f, cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
173 cache_sim_write_similarity(f, cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
174
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
175 fclose (f);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
176
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
177 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
178 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
179
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
180 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
181 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
182 * sim cache read
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
183 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
184 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
185
65
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
186 static gint cache_sim_read_skipline(FILE *f, int s)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
187 {
65
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
188 if (!f) return FALSE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
189
65
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
190 if (fseek(f, 0 - s, SEEK_CUR) == 0)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
191 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
192 char b;
65
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
193 while (fread(&b, sizeof(b), 1, f) == 1)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
194 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
195 if (b == '\n') return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
196 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
197 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
198 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
199
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
200 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
201 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
202
65
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
203 static gint cache_sim_read_comment(FILE *f, char *buf, int s, CacheData *cd)
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
204 {
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
205 if (!f || !buf || !cd) return FALSE;
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
206
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
207 if (s < 1 || buf[0] != '#') return FALSE;
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
208
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
209 return cache_sim_read_skipline(f, s - 1);
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
210 }
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
211
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
212 static gint cache_sim_read_dimensions(FILE *f, char *buf, int s, CacheData *cd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
213 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
214 if (!f || !buf || !cd) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
215
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
216 if (s < 10 || strncmp("Dimensions", buf, 10) != 0) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
217
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
218 if (fseek(f, - s, SEEK_CUR) == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
219 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
220 char b;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
221 char buf[1024];
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
222 gint p = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
223 gint w, h;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
224
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
225 b = 'X';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
226 while (b != '[')
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
227 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
228 if (fread(&b, sizeof(b), 1, f) != 1) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
229 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
230 while (b != ']' && p < 1023)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
231 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
232 if (fread(&b, sizeof(b), 1, f) != 1) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
233 buf[p] = b;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
234 p++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
235 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
236
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
237 while (b != '\n')
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
238 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
239 if (fread(&b, sizeof(b), 1, f) != 1) break;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
240 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
241
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
242 buf[p] = '\0';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
243 if (sscanf(buf, "%d x %d", &w, &h) != 2) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
244
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
245 cd->width = w;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
246 cd->height = h;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
247 cd->dimensions = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
248
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
249 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
250 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
251
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
252 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
253 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
254
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
255 static gint cache_sim_read_date(FILE *f, char *buf, int s, CacheData *cd)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
256 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
257 if (!f || !buf || !cd) return FALSE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
258
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
259 if (s < 4 || strncmp("Date", buf, 4) != 0) return FALSE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
260
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
261 if (fseek(f, - s, SEEK_CUR) == 0)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
262 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
263 char b;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
264 char buf[1024];
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
265 gint p = 0;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
266
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
267 b = 'X';
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
268 while (b != '[')
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
269 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
270 if (fread(&b, sizeof(b), 1, f) != 1) return FALSE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
271 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
272 while (b != ']' && p < 1023)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
273 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
274 if (fread(&b, sizeof(b), 1, f) != 1) return FALSE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
275 buf[p] = b;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
276 p++;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
277 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
278
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
279 while (b != '\n')
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
280 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
281 if (fread(&b, sizeof(b), 1, f) != 1) break;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
282 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
283
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
284 buf[p] = '\0';
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
285 cd->date = strtol(buf, NULL, 10);
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
286
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
287 cd->have_date = TRUE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
288
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
289 return TRUE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
290 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
291
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
292 return FALSE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
293 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
294
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
295 static gint cache_sim_read_checksum(FILE *f, char *buf, int s, CacheData *cd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
296 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
297 if (!f || !buf || !cd) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
298
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
299 if (s < 8 || strncmp("Checksum", buf, 8) != 0) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
300
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
301 if (fseek(f, - s, SEEK_CUR) == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
302 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
303 char b;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
304 char buf[1024];
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
305 gint p = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
306
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
307 b = 'X';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
308 while (b != '[')
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
309 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
310 if (fread(&b, sizeof(b), 1, f) != 1) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
311 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
312 while (b != ']' && p < 1023)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
313 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
314 if (fread(&b, sizeof(b), 1, f) != 1) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
315 buf[p] = b;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
316 p++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
317 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
318
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
319 while (b != '\n')
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
320 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
321 if (fread(&b, sizeof(b), 1, f) != 1) break;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
322 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
323
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
324 buf[p] = '\0';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
325 cd->checksum = strtol(buf, NULL, 10);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
326
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
327 cd->have_checksum = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
328
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
329 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
330 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
331
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
332 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
333 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
334
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
335 static gint cache_sim_read_md5sum(FILE *f, char *buf, int s, CacheData *cd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
336 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
337 if (!f || !buf || !cd) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
338
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
339 if (s < 8 || strncmp("MD5sum", buf, 6) != 0) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
340
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
341 if (fseek(f, - s, SEEK_CUR) == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
342 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
343 char b;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
344 char buf[64];
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
345 gint p = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
346
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
347 b = 'X';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
348 while (b != '[')
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
349 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
350 if (fread(&b, sizeof(b), 1, f) != 1) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
351 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
352 while (b != ']' && p < 63)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
353 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
354 if (fread(&b, sizeof(b), 1, f) != 1) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
355 buf[p] = b;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
356 p++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
357 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
358 while (b != '\n')
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
359 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
360 if (fread(&b, sizeof(b), 1, f) != 1) break;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
361 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
362
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
363 buf[p] = '\0';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
364 cd->have_md5sum = md5_digest_from_text(buf, cd->md5sum);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
365
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
366 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
367 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
368
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
369 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
370 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
371
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
372 static gint cache_sim_read_similarity(FILE *f, char *buf, int s, CacheData *cd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
373 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
374 if (!f || !buf || !cd) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
375
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
376 if (s < 11 || strncmp("Similarity", buf, 10) != 0) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
377
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
378 if (strncmp("Grid[32 x 32]", buf + 10, 13) != 0) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
379
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
380 if (fseek(f, - s, SEEK_CUR) == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
381 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
382 char b;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
383 guint8 pixel_buf[3];
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
384 ImageSimilarityData *sd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
385 gint x, y;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
386
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
387 b = 'X';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
388 while (b != '=')
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
389 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
390 if (fread(&b, sizeof(b), 1, f) != 1) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
391 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
392
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
393 if (cd->sim)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
394 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
395 /* use current sim that may already contain data we will not touch here */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
396 sd = cd->sim;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
397 cd->sim = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
398 cd->similarity = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
399 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
400 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
401 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
402 sd = image_sim_new();
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
403 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
404
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
405 for (y = 0; y < 32; y++)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
406 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
407 gint s = y * 32;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
408 for (x = 0; x < 32; x++)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
409 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
410 if (fread(&pixel_buf, sizeof(pixel_buf), 1, f) != 1)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
411 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
412 image_sim_free(sd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
413 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
414 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
415 sd->avg_r[s + x] = pixel_buf[0];
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
416 sd->avg_g[s + x] = pixel_buf[1];
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
417 sd->avg_b[s + x] = pixel_buf[2];
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
418 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
419 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
420
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
421 if (fread(&b, sizeof(b), 1, f) == 1)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
422 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
423 if (b != '\n') fseek(f, -1, SEEK_CUR);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
424 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
425
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
426 cd->sim = sd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
427 cd->sim->filled = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
428 cd->similarity = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
429
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
430 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
431 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
432
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
433 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
434 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
435
65
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
436 #define CACHE_LOAD_LINE_NOISE 8
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
437
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
438 CacheData *cache_sim_data_load(const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
439 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
440 FILE *f;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
441 CacheData *cd = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
442 char buf[32];
65
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
443 gint success = CACHE_LOAD_LINE_NOISE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
444 gchar *pathl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
445
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
446 if (!path) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
447
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
448 pathl = path_from_utf8(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
449 f = fopen(pathl, "r");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
450 g_free(pathl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
451
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
452 if (!f) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
453
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
454 cd = cache_sim_data_new();
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
455 cd->path = g_strdup(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
456
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
457 if (fread(&buf, sizeof(char), 9, f) != 9 ||
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
458 strncmp(buf, "SIMcache", 8) != 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
459 {
506
fc9c8a3e1a8b Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents: 495
diff changeset
460 DEBUG_1("%s is not a cache file", cd->path);
65
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
461 success = 0;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
462 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
463
65
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
464 while (success > 0)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
465 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
466 int s;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
467 s = fread(&buf, sizeof(char), sizeof(buf), f);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
468
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
469 if (s < 1)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
470 {
65
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
471 success = 0;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
472 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
473 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
474 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
475 if (!cache_sim_read_comment(f, buf, s, cd) &&
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
476 !cache_sim_read_dimensions(f, buf, s, cd) &&
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
477 !cache_sim_read_date(f, buf, s, cd) &&
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
478 !cache_sim_read_checksum(f, buf, s, cd) &&
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
479 !cache_sim_read_md5sum(f, buf, s, cd) &&
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
480 !cache_sim_read_similarity(f, buf, s, cd))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
481 {
65
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
482 if (!cache_sim_read_skipline(f, s))
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
483 {
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
484 success = 0;
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
485 }
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
486 else
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
487 {
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
488 success--;
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
489 }
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
490 }
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
491 else
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
492 {
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
493 success = CACHE_LOAD_LINE_NOISE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
494 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
495 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
496 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
497
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
498 fclose(f);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
499
39
64068b1bab89 Thu Apr 14 10:44:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 37
diff changeset
500 if (!cd->dimensions &&
64068b1bab89 Thu Apr 14 10:44:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 37
diff changeset
501 !cd->have_date &&
64068b1bab89 Thu Apr 14 10:44:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 37
diff changeset
502 !cd->have_checksum &&
64068b1bab89 Thu Apr 14 10:44:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 37
diff changeset
503 !cd->have_md5sum &&
64068b1bab89 Thu Apr 14 10:44:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 37
diff changeset
504 !cd->similarity)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
505 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
506 cache_sim_data_free(cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
507 cd = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
508 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
509
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
510 return cd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
511 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
512
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
513 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
514 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
515 * sim cache setting
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
516 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
517 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
518
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
519 void cache_sim_data_set_dimensions(CacheData *cd, gint w, gint h)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
520 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
521 if (!cd) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
522
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
523 cd->width = w;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
524 cd->height = h;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
525 cd->dimensions = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
526 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
527
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
528 void cache_sim_data_set_date(CacheData *cd, time_t date)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
529 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
530 if (!cd) return;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
531
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
532 cd->date = date;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
533 cd->have_date = TRUE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
534 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
535
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
536 void cache_sim_data_set_checksum(CacheData *cd, long checksum)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
537 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
538 if (!cd) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
539
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
540 cd->checksum = checksum;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
541 cd->have_checksum = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
542 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
543
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
544 void cache_sim_data_set_md5sum(CacheData *cd, guchar digest[16])
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
545 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
546 gint i;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
547
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
548 if (!cd) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
549
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
550 for (i = 0; i < 16; i++)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
551 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
552 cd->md5sum[i] = digest[i];
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
553 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
554 cd->have_md5sum = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
555 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
556
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
557 void cache_sim_data_set_similarity(CacheData *cd, ImageSimilarityData *sd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
558 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
559 if (!cd || !sd || !sd->filled) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
560
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
561 if (!cd->sim) cd->sim = image_sim_new();
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
562
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
563 memcpy(cd->sim->avg_r, sd->avg_r, 1024);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
564 memcpy(cd->sim->avg_g, sd->avg_g, 1024);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
565 memcpy(cd->sim->avg_b, sd->avg_b, 1024);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
566 cd->sim->filled = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
567
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
568 cd->similarity = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
569 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
570
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
571 gint cache_sim_data_filled(ImageSimilarityData *sd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
572 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
573 if (!sd) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
574 return sd->filled;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
575 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
576
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
577 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
578 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
579 * cache path location utils
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
580 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
581 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
582
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
583 /* warning: this func modifies path string contents!, on fail it is set to fail point */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
584 gint cache_ensure_dir_exists(gchar *path, mode_t mode)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
585 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
586 if (!path) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
587
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
588 if (!isdir(path))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
589 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
590 gchar *p = path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
591 while (p[0] != '\0')
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
592 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
593 p++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
594 if (p[0] == '/' || p[0] == '\0')
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
595 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
596 gint end = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
597 if (p[0] != '\0')
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
598 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
599 p[0] = '\0';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
600 end = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
601 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
602 if (!isdir(path))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
603 {
506
fc9c8a3e1a8b Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents: 495
diff changeset
604 DEBUG_1("creating sub dir:%s", path);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
605 if (!mkdir_utf8(path, mode))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
606 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
607 printf("create dir failed: %s\n", path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
608 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
609 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
610 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
611 if (!end) p[0] = '/';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
612 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
613 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
614 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
615 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
616 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
617
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
618 static void cache_path_parts(CacheType type,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
619 const gchar **cache_rc, const gchar **cache_local, const gchar **cache_ext)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
620 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
621 switch (type)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
622 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
623 case CACHE_TYPE_THUMB:
283
e213fb025621 GQVIEW_* -> GQ_*
zas_
parents: 281
diff changeset
624 *cache_rc = GQ_CACHE_RC_THUMB;
e213fb025621 GQVIEW_* -> GQ_*
zas_
parents: 281
diff changeset
625 *cache_local = GQ_CACHE_LOCAL_THUMB;
e213fb025621 GQVIEW_* -> GQ_*
zas_
parents: 281
diff changeset
626 *cache_ext = GQ_CACHE_EXT_THUMB;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
627 break;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
628 case CACHE_TYPE_SIM:
283
e213fb025621 GQVIEW_* -> GQ_*
zas_
parents: 281
diff changeset
629 *cache_rc = GQ_CACHE_RC_THUMB;
e213fb025621 GQVIEW_* -> GQ_*
zas_
parents: 281
diff changeset
630 *cache_local = GQ_CACHE_LOCAL_THUMB;
e213fb025621 GQVIEW_* -> GQ_*
zas_
parents: 281
diff changeset
631 *cache_ext = GQ_CACHE_EXT_SIM;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
632 break;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
633 case CACHE_TYPE_METADATA:
283
e213fb025621 GQVIEW_* -> GQ_*
zas_
parents: 281
diff changeset
634 *cache_rc = GQ_CACHE_RC_METADATA;
e213fb025621 GQVIEW_* -> GQ_*
zas_
parents: 281
diff changeset
635 *cache_local = GQ_CACHE_LOCAL_METADATA;
e213fb025621 GQVIEW_* -> GQ_*
zas_
parents: 281
diff changeset
636 *cache_ext = GQ_CACHE_EXT_METADATA;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
637 break;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
638 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
639 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
640
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
641 gchar *cache_get_location(CacheType type, const gchar *source, gint include_name, mode_t *mode)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
642 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
643 gchar *path = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
644 gchar *base;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
645 gchar *name = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
646 const gchar *cache_rc;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
647 const gchar *cache_local;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
648 const gchar *cache_ext;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
649
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
650 if (!source) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
651
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
652 cache_path_parts(type, &cache_rc, &cache_local, &cache_ext);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
653
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
654 base = remove_level_from_path(source);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
655 if (include_name)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
656 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
657 name = g_strconcat("/", filename_from_path(source), NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
658 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
659 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
660 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
661 cache_ext = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
662 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
663
333
767b53cd9ab7 Rename thumbnails related options.
zas_
parents: 318
diff changeset
664 if (((type != CACHE_TYPE_METADATA && options->thumbnails.cache_into_dirs) ||
318
b16b9b8979e5 Add a new struct ConfOptions to handle options.
zas_
parents: 283
diff changeset
665 (type == CACHE_TYPE_METADATA && options->enable_metadata_dirs)) &&
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
666 access_file(base, W_OK))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
667 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
668 path = g_strconcat(base, "/", cache_local, name, cache_ext, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
669 if (mode) *mode = 0775;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
670 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
671
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
672 if (!path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
673 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
674 path = g_strconcat(homedir(), "/", cache_rc, base, name, cache_ext, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
675 if (mode) *mode = 0755;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
676 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
677
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
678 g_free(base);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
679 if (name) g_free(name);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
680
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
681 return path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
682 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
683
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
684 gchar *cache_find_location(CacheType type, const gchar *source)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
685 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
686 gchar *path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
687 const gchar *name;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
688 gchar *base;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
689 const gchar *cache_rc;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
690 const gchar *cache_local;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
691 const gchar *cache_ext;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
692 gint prefer_local;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
693
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
694 if (!source) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
695
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
696 cache_path_parts(type, &cache_rc, &cache_local, &cache_ext);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
697
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
698 name = filename_from_path(source);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
699 base = remove_level_from_path(source);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
700
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
701 if (type == CACHE_TYPE_METADATA)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
702 {
318
b16b9b8979e5 Add a new struct ConfOptions to handle options.
zas_
parents: 283
diff changeset
703 prefer_local = options->enable_metadata_dirs;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
704 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
705 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
706 {
333
767b53cd9ab7 Rename thumbnails related options.
zas_
parents: 318
diff changeset
707 prefer_local = options->thumbnails.cache_into_dirs;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
708 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
709
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
710 if (prefer_local)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
711 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
712 path = g_strconcat(base, "/", cache_local, "/", name, cache_ext, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
713 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
714 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
715 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
716 path = g_strconcat(homedir(), "/", cache_rc, source, cache_ext, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
717 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
718
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
719 if (!isfile(path))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
720 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
721 g_free(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
722
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
723 /* try the opposite method if not found */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
724 if (!prefer_local)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
725 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
726 path = g_strconcat(base, "/", cache_local, "/", name, cache_ext, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
727 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
728 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
729 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
730 path = g_strconcat(homedir(), "/", cache_rc, source, cache_ext, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
731 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
732
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
733 if (!isfile(path))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
734 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
735 g_free(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
736 path = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
737 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
738 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
739
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
740 g_free(base);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
741
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
742 return path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
743 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
744
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
745 gint cache_time_valid(const gchar *cache, const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
746 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
747 struct stat cache_st;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
748 struct stat path_st;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
749 gchar *cachel;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
750 gchar *pathl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
751 gint ret = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
752
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
753 if (!cache || !path) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
754
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
755 cachel = path_from_utf8(cache);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
756 pathl = path_from_utf8(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
757
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
758 if (stat(cachel, &cache_st) == 0 &&
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
759 stat(pathl, &path_st) == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
760 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
761 if (cache_st.st_mtime == path_st.st_mtime)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
762 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
763 ret = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
764 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
765 else if (cache_st.st_mtime > path_st.st_mtime)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
766 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
767 struct utimbuf ut;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
768
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
769 ut.actime = ut.modtime = cache_st.st_mtime;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
770 if (utime(cachel, &ut) < 0 &&
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
771 errno == EPERM)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
772 {
506
fc9c8a3e1a8b Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents: 495
diff changeset
773 DEBUG_1("cache permission workaround: %s", cachel);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
774 ret = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
775 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
776 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
777 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
778
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
779 g_free(pathl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
780 g_free(cachel);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
781
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
782 return ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
783 }