Mercurial > geeqie
annotate src/filelist.c @ 215:f2b439c7f973
Move strlen() calls outside the while loop.
author | zas_ |
---|---|
date | Sun, 30 Mar 2008 19:26:35 +0000 |
parents | c7021159079d |
children | 5bdab7ed4bcd |
rev | line source |
---|---|
1 | 1 /* |
196 | 2 * Geeqie |
79
528e3432e0c0
Thu Oct 19 07:23:37 2006 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
3 * (C) 2006 John Ellis |
1 | 4 * |
5 * Author: John Ellis | |
6 * | |
9 | 7 * This software is released under the GNU General Public License (GNU GPL). |
8 * Please read the included file COPYING for more information. | |
9 * This software comes with no warranty of any kind, use at your own risk! | |
1 | 10 */ |
11 | |
12 | |
9 | 13 #include "gqview.h" |
14 #include "filelist.h" | |
1 | 15 |
9 | 16 #include "cache.h" |
17 #include "rcfile.h" | |
79
528e3432e0c0
Thu Oct 19 07:23:37 2006 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
18 #include "thumb_standard.h" |
9 | 19 #include "ui_fileops.h" |
1 | 20 |
21 | |
22 /* | |
23 *----------------------------------------------------------------------------- | |
24 * file filtering | |
25 *----------------------------------------------------------------------------- | |
26 */ | |
27 | |
9 | 28 static GList *filter_list = NULL; |
29 static GList *extension_list = NULL; | |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
30 static GList *sidecar_ext_list = NULL; |
9 | 31 |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
32 static GList *file_class_extension_list[FILE_FORMAT_CLASSES]; |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
33 |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
34 |
9 | 35 gint ishidden(const gchar *name) |
1 | 36 { |
37 if (name[0] != '.') return FALSE; | |
38 if (name[1] == '\0' || (name[1] == '.' && name[2] == '\0')) return FALSE; | |
39 return TRUE; | |
40 } | |
41 | |
9 | 42 static FilterEntry *filter_entry_new(const gchar *key, const gchar *description, |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
43 const gchar *extensions, FileFormatClass file_class, gint enabled) |
9 | 44 { |
45 FilterEntry *fe; | |
46 | |
47 fe = g_new0(FilterEntry, 1); | |
48 fe->key = g_strdup(key); | |
49 fe->description = g_strdup(description); | |
50 fe->extensions = g_strdup(extensions); | |
51 fe->enabled = enabled; | |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
52 fe->file_class = file_class; |
9 | 53 |
54 return fe; | |
55 } | |
56 | |
57 static void filter_entry_free(FilterEntry *fe) | |
58 { | |
59 if (!fe) return; | |
60 | |
61 g_free(fe->key); | |
62 g_free(fe->description); | |
63 g_free(fe->extensions); | |
64 g_free(fe); | |
65 } | |
66 | |
67 GList *filter_get_list(void) | |
68 { | |
69 return filter_list; | |
70 } | |
71 | |
72 void filter_remove_entry(FilterEntry *fe) | |
73 { | |
74 if (!g_list_find(filter_list, fe)) return; | |
75 | |
76 filter_list = g_list_remove(filter_list, fe); | |
77 filter_entry_free(fe); | |
78 } | |
79 | |
80 static gint filter_key_exists(const gchar *key) | |
81 { | |
82 GList *work; | |
83 | |
84 if (!key) return FALSE; | |
85 | |
86 work = filter_list; | |
87 while (work) | |
88 { | |
89 FilterEntry *fe = work->data; | |
90 work = work->next; | |
91 | |
92 if (strcmp(fe->key, key) == 0) return TRUE; | |
93 } | |
94 | |
95 return FALSE; | |
96 } | |
97 | |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
98 void filter_add(const gchar *key, const gchar *description, const gchar *extensions, FileFormatClass file_class, gint enabled) |
9 | 99 { |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
100 filter_list = g_list_append(filter_list, filter_entry_new(key, description, extensions, file_class, enabled)); |
9 | 101 } |
102 | |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
103 void filter_add_unique(const gchar *description, const gchar *extensions, FileFormatClass file_class, gint enabled) |
9 | 104 { |
105 gchar *key; | |
106 gint n; | |
107 | |
108 key = g_strdup("user0"); | |
109 n = 1; | |
110 while (filter_key_exists(key)) | |
111 { | |
112 g_free(key); | |
113 if (n > 999) return; | |
114 key = g_strdup_printf("user%d", n); | |
115 n++; | |
116 } | |
117 | |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
118 filter_add(key, description, extensions, file_class, enabled); |
9 | 119 g_free(key); |
120 } | |
121 | |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
122 static void filter_add_if_missing(const gchar *key, const gchar *description, const gchar *extensions, FileFormatClass file_class, gint enabled) |
9 | 123 { |
124 GList *work; | |
125 | |
126 if (!key) return; | |
127 | |
128 work = filter_list; | |
129 while (work) | |
130 { | |
131 FilterEntry *fe = work->data; | |
132 work = work->next; | |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
133 if (fe->key && strcmp(fe->key, key) == 0) |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
134 { |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
135 if (fe->file_class == FORMAT_CLASS_UNKNOWN) |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
136 fe->file_class = file_class; /* for compatibility */ |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
137 return; |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
138 } |
9 | 139 } |
140 | |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
141 filter_add(key, description, extensions, file_class, enabled); |
9 | 142 } |
143 | |
144 void filter_reset(void) | |
1 | 145 { |
146 GList *work; | |
9 | 147 |
148 work = filter_list; | |
149 while (work) | |
150 { | |
151 FilterEntry *fe = work->data; | |
152 work = work->next; | |
153 filter_entry_free(fe); | |
154 } | |
155 | |
156 g_list_free(filter_list); | |
157 filter_list = NULL; | |
158 } | |
159 | |
160 void filter_add_defaults(void) | |
161 { | |
162 GSList *list, *work; | |
163 | |
164 list = gdk_pixbuf_get_formats(); | |
165 work = list; | |
166 while (work) | |
167 { | |
168 GdkPixbufFormat *format; | |
169 gchar *name; | |
170 gchar *desc; | |
171 gchar **extensions; | |
172 GString *filter = NULL; | |
173 gint i; | |
174 | |
175 format = work->data; | |
176 work = work->next; | |
177 | |
178 name = gdk_pixbuf_format_get_name(format); | |
179 desc = gdk_pixbuf_format_get_description(format); | |
180 extensions = gdk_pixbuf_format_get_extensions(format); | |
181 | |
182 i = 0; | |
183 while (extensions[i]) | |
184 { | |
185 if (!filter) | |
186 { | |
187 filter = g_string_new("."); | |
188 filter = g_string_append(filter, extensions[i]); | |
189 } | |
190 else | |
191 { | |
192 filter = g_string_append(filter, ";."); | |
193 filter = g_string_append(filter, extensions[i]); | |
194 } | |
195 i++; | |
196 } | |
197 | |
198 if (debug) printf("loader reported [%s] [%s] [%s]\n", name, desc, filter->str); | |
199 | |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
200 filter_add_if_missing(name, desc, filter->str, FORMAT_CLASS_IMAGE, TRUE); |
9 | 201 |
202 g_free(name); | |
203 g_free(desc); | |
204 g_strfreev(extensions); | |
205 g_string_free(filter, TRUE); | |
206 } | |
207 g_slist_free(list); | |
1 | 208 |
9 | 209 /* add defaults even if gdk-pixbuf does not have them, but disabled */ |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
210 filter_add_if_missing("jpeg", "JPEG group", ".jpg;.jpeg;.jpe", FORMAT_CLASS_IMAGE, FALSE); |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
211 filter_add_if_missing("png", "Portable Network Graphic", ".png", FORMAT_CLASS_IMAGE, FALSE); |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
212 filter_add_if_missing("tiff", "Tiff", ".tif;.tiff", FORMAT_CLASS_IMAGE, FALSE); |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
213 filter_add_if_missing("pnm", "Packed Pixel formats", ".pbm;.pgm;.pnm;.ppm", FORMAT_CLASS_IMAGE, FALSE); |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
214 filter_add_if_missing("gif", "Graphics Interchange Format", ".gif", FORMAT_CLASS_IMAGE, FALSE); |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
215 filter_add_if_missing("xbm", "X bitmap", ".xbm", FORMAT_CLASS_IMAGE, FALSE); |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
216 filter_add_if_missing("xpm", "X pixmap", ".xpm", FORMAT_CLASS_IMAGE, FALSE); |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
217 filter_add_if_missing("bmp", "Bitmap", ".bmp", FORMAT_CLASS_IMAGE, FALSE); |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
218 filter_add_if_missing("ico", "Icon file", ".ico;.cur", FORMAT_CLASS_IMAGE, FALSE); |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
219 filter_add_if_missing("ras", "Raster", ".ras", FORMAT_CLASS_IMAGE, FALSE); |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
220 filter_add_if_missing("svg", "Scalable Vector Graphics", ".svg", FORMAT_CLASS_IMAGE, FALSE); |
202
f95654aeec4b
added all possible raw extensions that I could find
nadvornik
parents:
196
diff
changeset
|
221 |
f95654aeec4b
added all possible raw extensions that I could find
nadvornik
parents:
196
diff
changeset
|
222 /* non-image files that might be desirable to show */ |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
223 filter_add_if_missing("xmp", "XMP sidecar", ".xmp", FORMAT_CLASS_META, TRUE); |
43
ee03f36e9e4b
Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
224 |
ee03f36e9e4b
Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
225 /* These are the raw camera formats with embedded jpeg/exif. |
202
f95654aeec4b
added all possible raw extensions that I could find
nadvornik
parents:
196
diff
changeset
|
226 * (see format_raw.c and/or exiv2.cc) |
43
ee03f36e9e4b
Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
227 */ |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
228 filter_add_if_missing("arw", "Sony raw format", ".arw;.srf;.sr2", FORMAT_CLASS_RAWIMAGE, TRUE); |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
229 filter_add_if_missing("crw", "Canon raw format", ".crw;.cr2", FORMAT_CLASS_RAWIMAGE, TRUE); |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
230 filter_add_if_missing("kdc", "Kodak raw format", ".kdc;.dcr", FORMAT_CLASS_RAWIMAGE, TRUE); |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
231 filter_add_if_missing("raf", "Fujifilm raw format", ".raf", FORMAT_CLASS_RAWIMAGE, TRUE); |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
232 filter_add_if_missing("mef", "Mamiya raw format", ".mef;.mos", FORMAT_CLASS_RAWIMAGE, TRUE); |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
233 filter_add_if_missing("mrw", "Minolta raw format", ".mrw", FORMAT_CLASS_RAWIMAGE, TRUE); |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
234 filter_add_if_missing("nef", "Nikon raw format", ".nef", FORMAT_CLASS_RAWIMAGE, TRUE); |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
235 filter_add_if_missing("orf", "Olympus raw format", ".orf", FORMAT_CLASS_RAWIMAGE, TRUE); |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
236 filter_add_if_missing("pef", "Pentax raw format", ".pef;.ptx", FORMAT_CLASS_RAWIMAGE, TRUE); |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
237 filter_add_if_missing("dng", "Adobe Digital Negative raw format", ".dng", FORMAT_CLASS_RAWIMAGE, TRUE); |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
238 filter_add_if_missing("x3f", "Sigma raw format", ".x3f", FORMAT_CLASS_RAWIMAGE, TRUE); |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
239 filter_add_if_missing("raw", "Panasonic raw format", ".raw", FORMAT_CLASS_RAWIMAGE, TRUE); |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
240 filter_add_if_missing("r3d", "Red raw format", ".r3d", FORMAT_CLASS_RAWIMAGE, TRUE); |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
241 filter_add_if_missing("3fr", "Hasselblad raw format", ".3fr", FORMAT_CLASS_RAWIMAGE, TRUE); |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
242 filter_add_if_missing("erf", "Epson raw format", ".erf", FORMAT_CLASS_RAWIMAGE, TRUE); |
9 | 243 } |
244 | |
147
b2266996fa83
added possibility to specify prefered file type for external commands
nadvornik
parents:
146
diff
changeset
|
245 GList *filter_to_list(const gchar *extensions) |
9 | 246 { |
247 GList *list = NULL; | |
248 const gchar *p; | |
249 | |
250 if (!extensions) return NULL; | |
251 | |
252 p = extensions; | |
253 while (*p != '\0') | |
254 { | |
255 const gchar *b; | |
256 gint l = 0; | |
257 | |
258 b = p; | |
259 while (*p != '\0' && *p != ';') | |
260 { | |
261 p++; | |
262 l++; | |
263 } | |
264 list = g_list_append(list, g_strndup(b, l)); | |
265 if (*p == ';') p++; | |
266 } | |
267 | |
268 return list; | |
269 } | |
270 | |
271 void filter_rebuild(void) | |
272 { | |
273 GList *work; | |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
274 gint i; |
9 | 275 |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
276 string_list_free(extension_list); |
9 | 277 extension_list = NULL; |
278 | |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
279 for (i = 0; i < FILE_FORMAT_CLASSES; i++) |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
280 { |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
281 string_list_free(file_class_extension_list[i]); |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
282 file_class_extension_list[i] = NULL; |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
283 } |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
284 |
9 | 285 work = filter_list; |
286 while (work) | |
287 { | |
288 FilterEntry *fe; | |
289 | |
290 fe = work->data; | |
291 work = work->next; | |
292 | |
293 if (fe->enabled) | |
294 { | |
295 GList *ext; | |
296 | |
297 ext = filter_to_list(fe->extensions); | |
298 if (ext) extension_list = g_list_concat(extension_list, ext); | |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
299 |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
300 if (fe->file_class >= 0 && fe->file_class < FILE_FORMAT_CLASSES) |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
301 { |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
302 ext = filter_to_list(fe->extensions); |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
303 if (ext) file_class_extension_list[fe->file_class] = g_list_concat(file_class_extension_list[fe->file_class], ext); |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
304 } |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
305 else |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
306 { |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
307 printf("WARNING: invalid file class %d\n", fe->file_class); |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
308 } |
9 | 309 } |
310 } | |
311 } | |
312 | |
313 gint filter_name_exists(const gchar *name) | |
314 { | |
315 GList *work; | |
215 | 316 gint ln; |
317 | |
9 | 318 if (!extension_list || file_filter_disable) return TRUE; |
319 | |
215 | 320 ln = strlen(name); |
9 | 321 work = extension_list; |
1 | 322 while (work) |
323 { | |
324 gchar *filter = work->data; | |
325 gint lf = strlen(filter); | |
215 | 326 |
1 | 327 if (ln >= lf) |
328 { | |
329 if (strncasecmp(name + ln - lf, filter, lf) == 0) return TRUE; | |
330 } | |
331 work = work->next; | |
332 } | |
333 | |
334 return FALSE; | |
335 } | |
336 | |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
337 gint filter_file_class(const gchar *name, FileFormatClass file_class) |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
338 { |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
339 GList *work; |
215 | 340 gint ln; |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
341 |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
342 if (file_class < 0 || file_class >= FILE_FORMAT_CLASSES) |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
343 { |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
344 printf("WARNING: invalid file class %d\n", file_class); |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
345 return FALSE; |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
346 } |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
347 |
215 | 348 ln = strlen(name); |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
349 work = file_class_extension_list[file_class]; |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
350 while (work) |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
351 { |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
352 gchar *filter = work->data; |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
353 gint lf = strlen(filter); |
215 | 354 |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
355 if (ln >= lf) |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
356 { |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
357 if (strncasecmp(name + ln - lf, filter, lf) == 0) return TRUE; |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
358 } |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
359 work = work->next; |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
360 } |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
361 |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
362 return FALSE; |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
363 } |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
364 |
9 | 365 void filter_write_list(FILE *f) |
1 | 366 { |
9 | 367 GList *work; |
368 | |
369 work = filter_list; | |
370 while (work) | |
371 { | |
372 FilterEntry *fe = work->data; | |
373 work = work->next; | |
374 | |
375 fprintf(f, "filter_ext: \"%s%s\" \"%s\" \"%s\"\n", (fe->enabled) ? "" : "#", | |
376 fe->key, fe->extensions, | |
377 (fe->description) ? fe->description : ""); | |
378 } | |
1 | 379 } |
380 | |
9 | 381 void filter_parse(const gchar *text) |
1 | 382 { |
9 | 383 const gchar *p; |
384 gchar *key; | |
385 gchar *ext; | |
386 gchar *desc; | |
387 gint enabled = TRUE; | |
388 | |
389 if (!text || text[0] != '"') return; | |
390 | |
391 key = quoted_value(text); | |
392 if (!key) return; | |
393 | |
394 p = text; | |
395 p++; | |
396 while (*p != '"' && *p != '\0') p++; | |
397 if (*p != '"') | |
398 { | |
399 g_free(key); | |
400 return; | |
401 } | |
402 p++; | |
403 while (*p != '"' && *p != '\0') p++; | |
404 if (*p != '"') | |
1 | 405 { |
9 | 406 g_free(key); |
407 return; | |
408 } | |
409 | |
410 ext = quoted_value(p); | |
411 | |
412 p++; | |
413 while (*p != '"' && *p != '\0') p++; | |
414 if (*p == '"') p++; | |
415 while (*p != '"' && *p != '\0') p++; | |
416 | |
417 if (*p == '"') | |
418 { | |
419 desc = quoted_value(p); | |
420 } | |
421 else | |
422 { | |
423 desc = NULL; | |
424 } | |
425 | |
426 if (key && key[0] == '#') | |
427 { | |
428 gchar *tmp; | |
429 tmp = g_strdup(key + 1); | |
430 g_free(key); | |
431 key = tmp; | |
432 | |
433 enabled = FALSE; | |
1 | 434 } |
435 | |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
436 if (key && strlen(key) > 0 && ext) filter_add(key, desc, ext, FORMAT_CLASS_UNKNOWN, enabled); |
9 | 437 |
438 g_free(key); | |
439 g_free(ext); | |
440 g_free(desc); | |
441 } | |
1 | 442 |
9 | 443 GList *path_list_filter(GList *list, gint is_dir_list) |
444 { | |
445 GList *work; | |
446 | |
447 if (!is_dir_list && file_filter_disable && show_dot_files) return list; | |
448 | |
449 work = list; | |
450 while (work) | |
1 | 451 { |
9 | 452 gchar *name = work->data; |
453 const gchar *base; | |
454 | |
455 base = filename_from_path(name); | |
456 | |
457 if ((!show_dot_files && ishidden(base)) || | |
458 (!is_dir_list && !filter_name_exists(base)) || | |
459 (is_dir_list && base[0] == '.' && (strcmp(base, GQVIEW_CACHE_LOCAL_THUMB) == 0 || | |
460 strcmp(base, GQVIEW_CACHE_LOCAL_METADATA) == 0)) ) | |
461 { | |
462 GList *link = work; | |
463 work = work->next; | |
464 list = g_list_remove_link(list, link); | |
465 g_free(name); | |
466 g_list_free(link); | |
467 } | |
468 else | |
1 | 469 { |
9 | 470 work = work->next; |
1 | 471 } |
472 } | |
9 | 473 |
474 return list; | |
475 } | |
476 | |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
477 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
478 /* |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
479 *----------------------------------------------------------------------------- |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
480 * sidecar extension list |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
481 *----------------------------------------------------------------------------- |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
482 */ |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
483 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
484 static GList *sidecar_ext_get_list(void) |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
485 { |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
486 return sidecar_ext_list; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
487 } |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
488 |
170
9a56e3d13e67
basic sidecar files configuration via preferences dialog
nadvornik
parents:
167
diff
changeset
|
489 void sidecar_ext_parse(const gchar *text, gint quoted) |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
490 { |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
491 GList *work; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
492 gchar *value; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
493 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
494 work = sidecar_ext_list; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
495 while (work) |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
496 { |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
497 gchar *ext = work->data; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
498 work = work->next; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
499 g_free(ext); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
500 } |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
501 g_list_free(sidecar_ext_list); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
502 sidecar_ext_list = NULL; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
503 |
170
9a56e3d13e67
basic sidecar files configuration via preferences dialog
nadvornik
parents:
167
diff
changeset
|
504 if (quoted) |
9a56e3d13e67
basic sidecar files configuration via preferences dialog
nadvornik
parents:
167
diff
changeset
|
505 value = quoted_value(text); |
9a56e3d13e67
basic sidecar files configuration via preferences dialog
nadvornik
parents:
167
diff
changeset
|
506 else |
9a56e3d13e67
basic sidecar files configuration via preferences dialog
nadvornik
parents:
167
diff
changeset
|
507 value = g_strdup(text); |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
508 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
509 if (value == NULL) return; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
510 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
511 sidecar_ext_list = filter_to_list(value); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
512 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
513 g_free(value); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
514 } |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
515 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
516 void sidecar_ext_write(FILE *f) |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
517 { |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
518 GList *work; |
170
9a56e3d13e67
basic sidecar files configuration via preferences dialog
nadvornik
parents:
167
diff
changeset
|
519 fprintf(f, "\nsidecar_ext: \"%s\"\n", sidecar_ext_to_string()); |
9a56e3d13e67
basic sidecar files configuration via preferences dialog
nadvornik
parents:
167
diff
changeset
|
520 } |
9a56e3d13e67
basic sidecar files configuration via preferences dialog
nadvornik
parents:
167
diff
changeset
|
521 |
9a56e3d13e67
basic sidecar files configuration via preferences dialog
nadvornik
parents:
167
diff
changeset
|
522 char *sidecar_ext_to_string() |
9a56e3d13e67
basic sidecar files configuration via preferences dialog
nadvornik
parents:
167
diff
changeset
|
523 { |
9a56e3d13e67
basic sidecar files configuration via preferences dialog
nadvornik
parents:
167
diff
changeset
|
524 GList *work; |
9a56e3d13e67
basic sidecar files configuration via preferences dialog
nadvornik
parents:
167
diff
changeset
|
525 GString *str = g_string_new(""); |
9a56e3d13e67
basic sidecar files configuration via preferences dialog
nadvornik
parents:
167
diff
changeset
|
526 |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
527 work = sidecar_ext_list; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
528 while (work) |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
529 { |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
530 gchar *ext = work->data; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
531 work = work->next; |
170
9a56e3d13e67
basic sidecar files configuration via preferences dialog
nadvornik
parents:
167
diff
changeset
|
532 g_string_append(str, ext); |
9a56e3d13e67
basic sidecar files configuration via preferences dialog
nadvornik
parents:
167
diff
changeset
|
533 if (work) g_string_append(str, ";"); |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
534 } |
170
9a56e3d13e67
basic sidecar files configuration via preferences dialog
nadvornik
parents:
167
diff
changeset
|
535 return g_string_free(str, FALSE); |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
536 } |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
537 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
538 void sidecar_ext_add_defaults() |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
539 { |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
172
diff
changeset
|
540 sidecar_ext_parse(".jpg;.cr2;.nef;.crw;.xmp", FALSE); |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
541 } |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
542 |
9 | 543 /* |
544 *----------------------------------------------------------------------------- | |
545 * path list recursive | |
546 *----------------------------------------------------------------------------- | |
547 */ | |
548 | |
549 static gint path_list_sort_cb(gconstpointer a, gconstpointer b) | |
550 { | |
551 return CASE_SORT((gchar *)a, (gchar *)b); | |
552 } | |
553 | |
554 GList *path_list_sort(GList *list) | |
555 { | |
556 return g_list_sort(list, path_list_sort_cb); | |
557 } | |
558 | |
559 static void path_list_recursive_append(GList **list, GList *dirs) | |
560 { | |
561 GList *work; | |
562 | |
563 work = dirs; | |
564 while (work) | |
565 { | |
566 const gchar *path = work->data; | |
567 GList *f = NULL; | |
568 GList *d = NULL; | |
569 | |
570 if (path_list(path, &f, &d)) | |
571 { | |
572 f = path_list_filter(f, FALSE); | |
573 f = path_list_sort(f); | |
574 *list = g_list_concat(*list, f); | |
575 | |
576 d = path_list_filter(d, TRUE); | |
577 d = path_list_sort(d); | |
578 path_list_recursive_append(list, d); | |
52
a210a19f26da
Sun Jun 5 03:05:39 2005 John Ellis <johne@verizon.net>
gqview
parents:
45
diff
changeset
|
579 path_list_free(d); |
9 | 580 } |
581 | |
582 work = work->next; | |
583 } | |
584 } | |
585 | |
586 GList *path_list_recursive(const gchar *path) | |
587 { | |
588 GList *list = NULL; | |
589 GList *d = NULL; | |
590 | |
591 if (!path_list(path, &list, &d)) return NULL; | |
592 list = path_list_filter(list, FALSE); | |
593 list = path_list_sort(list); | |
594 | |
595 d = path_list_filter(d, TRUE); | |
596 d = path_list_sort(d); | |
597 path_list_recursive_append(&list, d); | |
598 path_list_free(d); | |
599 | |
600 return list; | |
1 | 601 } |
602 | |
603 /* | |
604 *----------------------------------------------------------------------------- | |
9 | 605 * text conversion utils |
1 | 606 *----------------------------------------------------------------------------- |
607 */ | |
608 | |
9 | 609 gchar *text_from_size(gint64 size) |
1 | 610 { |
9 | 611 gchar *a, *b; |
612 gchar *s, *d; | |
613 gint l, n, i; | |
614 | |
615 /* what I would like to use is printf("%'d", size) | |
616 * BUT: not supported on every libc :( | |
617 */ | |
618 if (size > G_MAXUINT) | |
619 { | |
620 /* the %lld conversion is not valid in all libcs, so use a simple work-around */ | |
621 a = g_strdup_printf("%d%09d", (guint)(size / 1000000000), (guint)(size % 1000000000)); | |
622 } | |
623 else | |
624 { | |
625 a = g_strdup_printf("%d", (guint)size); | |
626 } | |
627 l = strlen(a); | |
628 n = (l - 1)/ 3; | |
629 if (n < 1) return a; | |
630 | |
631 b = g_new(gchar, l + n + 1); | |
632 | |
633 s = a; | |
634 d = b; | |
635 i = l - n * 3; | |
636 while (*s != '\0') | |
637 { | |
638 if (i < 1) | |
639 { | |
640 i = 3; | |
641 *d = ','; | |
642 d++; | |
643 } | |
644 | |
645 *d = *s; | |
646 s++; | |
647 d++; | |
648 i--; | |
649 } | |
650 *d = '\0'; | |
651 | |
652 g_free(a); | |
653 return b; | |
654 } | |
655 | |
656 gchar *text_from_size_abrev(gint64 size) | |
657 { | |
658 if (size < (gint64)1024) | |
659 { | |
660 return g_strdup_printf(_("%d bytes"), (gint)size); | |
661 } | |
662 if (size < (gint64)1048576) | |
663 { | |
15
3263965d5f9e
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
664 return g_strdup_printf(_("%.1f K"), (double)size / 1024.0); |
9 | 665 } |
666 if (size < (gint64)1073741824) | |
667 { | |
15
3263965d5f9e
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
668 return g_strdup_printf(_("%.1f MB"), (double)size / 1048576.0); |
9 | 669 } |
670 | |
15
3263965d5f9e
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
671 /* to avoid overflowing the double, do division in two steps */ |
3263965d5f9e
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
672 size /= 1048576; |
3263965d5f9e
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
673 return g_strdup_printf(_("%.1f GB"), (double)size / 1024.0); |
9 | 674 } |
675 | |
676 /* note: returned string is valid until next call to text_from_time() */ | |
677 const gchar *text_from_time(time_t t) | |
678 { | |
679 static gchar *ret = NULL; | |
680 gchar buf[128]; | |
681 gint buflen; | |
682 struct tm *btime; | |
683 GError *error = NULL; | |
684 | |
685 btime = localtime(&t); | |
686 | |
687 /* the %x warning about 2 digit years is not an error */ | |
688 buflen = strftime(buf, sizeof(buf), "%x %H:%M", btime); | |
689 if (buflen < 1) return ""; | |
690 | |
691 g_free(ret); | |
692 ret = g_locale_to_utf8(buf, buflen, NULL, NULL, &error); | |
693 if (error) | |
694 { | |
695 printf("Error converting locale strftime to UTF-8: %s\n", error->message); | |
696 g_error_free(error); | |
697 return ""; | |
698 } | |
699 | |
700 return ret; | |
1 | 701 } |
702 | |
9 | 703 /* |
704 *----------------------------------------------------------------------------- | |
705 * file info struct | |
706 *----------------------------------------------------------------------------- | |
707 */ | |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
708 |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
709 FileData *file_data_merge_sidecar_files(FileData *target, FileData *source); |
167 | 710 static void file_data_check_sidecars(FileData *fd); |
711 FileData *file_data_disconnect_sidecar_file(FileData *target, FileData *sfd); | |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
712 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
713 |
138 | 714 static void file_data_set_path(FileData *fd, const gchar *path) |
715 { | |
9 | 716 |
138 | 717 if (strcmp(path, "/") == 0) |
718 { | |
719 fd->path = g_strdup(path); | |
720 fd->name = fd->path; | |
721 fd->extension = fd->name + 1; | |
722 return; | |
723 } | |
724 | |
725 fd->path = g_strdup(path); | |
726 fd->name = filename_from_path(fd->path); | |
727 | |
728 if (strcmp(fd->name, "..") == 0) | |
729 { | |
730 gchar *dir = remove_level_from_path(path); | |
731 g_free(fd->path); | |
732 fd->path = remove_level_from_path(dir); | |
733 g_free(dir); | |
734 fd->name = ".."; | |
735 fd->extension = fd->name + 2; | |
736 return; | |
737 } | |
738 else if (strcmp(fd->name, ".") == 0) | |
739 { | |
740 g_free(fd->path); | |
741 fd->path = remove_level_from_path(path); | |
742 fd->name = "."; | |
743 fd->extension = fd->name + 1; | |
744 return; | |
745 } | |
746 | |
747 fd->extension = extension_from_path(fd->path); | |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
748 if (fd->extension == NULL) |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
749 fd->extension = fd->name + strlen(fd->name); |
138 | 750 } |
751 | |
167 | 752 static void file_data_check_changed_files(FileData *fd, struct stat *st) |
164 | 753 { |
167 | 754 GList *work; |
164 | 755 if (fd->size != st->st_size || |
756 fd->date != st->st_mtime) | |
757 { | |
758 fd->size = st->st_size; | |
759 fd->date = st->st_mtime; | |
760 if (fd->pixbuf) g_object_unref(fd->pixbuf); | |
761 fd->pixbuf = NULL; | |
762 } | |
167 | 763 |
764 work = fd->sidecar_files; | |
765 while (work) | |
766 { | |
767 FileData *sfd = work->data; | |
768 struct stat st; | |
769 | |
770 if (!stat_utf8(sfd->path, &st)) | |
771 { | |
772 file_data_disconnect_sidecar_file(fd, sfd); | |
773 } | |
774 | |
775 file_data_check_changed_files(sfd, &st); | |
776 work = work->next; | |
777 } | |
164 | 778 } |
779 | |
138 | 780 static GHashTable *file_data_pool = NULL; |
781 | |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
782 static FileData *file_data_new(const gchar *path_utf8, struct stat *st, gboolean check_sidecars) |
9 | 783 { |
784 FileData *fd; | |
785 | |
172 | 786 if (debug) printf("file_data_new: '%s' %d\n", path_utf8, check_sidecars); |
138 | 787 |
788 if (!file_data_pool) | |
789 file_data_pool = g_hash_table_new (g_str_hash, g_str_equal); | |
790 | |
791 fd = g_hash_table_lookup(file_data_pool, path_utf8); | |
792 if (fd) | |
793 { | |
167 | 794 file_data_check_changed_files(fd, st); |
172 | 795 if (debug) printf("file_data_pool hit: '%s'\n", fd->path); |
138 | 796 return file_data_ref(fd); |
797 } | |
798 | |
9 | 799 fd = g_new0(FileData, 1); |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
800 |
138 | 801 file_data_set_path(fd, path_utf8); |
802 | |
803 fd->original_path = g_strdup(path_utf8); | |
9 | 804 fd->size = st->st_size; |
805 fd->date = st->st_mtime; | |
806 fd->pixbuf = NULL; | |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
807 fd->sidecar_files = NULL; |
138 | 808 fd->ref = 1; |
809 fd->magick = 0x12345678; | |
810 | |
811 g_hash_table_insert(file_data_pool, fd->original_path, fd); | |
812 | |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
813 if (check_sidecars && sidecar_file_priority(fd->extension)) |
146 | 814 file_data_check_sidecars(fd); |
9 | 815 return fd; |
816 } | |
817 | |
146 | 818 static void file_data_check_sidecars(FileData *fd) |
819 { | |
820 int i = 0; | |
821 int base_len = fd->extension - fd->path; | |
822 GString *fname = g_string_new_len(fd->path, base_len); | |
823 FileData *parent_fd = NULL; | |
824 GList *work = sidecar_ext_get_list(); | |
825 while (work) | |
826 { | |
827 /* check for possible sidecar files; | |
828 the sidecar files created here are referenced only via fd->sidecar_files or fd->parent, | |
829 they have fd->ref set to 0 and file_data unref must chack and free them all together | |
830 (using fd->ref would cause loops and leaks) | |
831 */ | |
832 | |
833 FileData *new_fd; | |
834 | |
835 gchar *ext = work->data; | |
836 work = work->next; | |
837 | |
838 if (strcmp(ext, fd->extension) == 0) | |
839 { | |
840 new_fd = fd; /* processing the original file */ | |
841 } | |
842 else | |
843 { | |
844 struct stat nst; | |
845 g_string_truncate(fname, base_len); | |
846 g_string_append(fname, ext); | |
847 | |
848 if (!stat_utf8(fname->str, &nst)) | |
849 continue; | |
850 | |
851 new_fd = file_data_new(fname->str, &nst, FALSE); | |
852 new_fd->ref--; /* do not use ref here */ | |
853 } | |
854 | |
855 if (!parent_fd) | |
856 parent_fd = new_fd; /* parent is the one with the highest prio, found first */ | |
857 else | |
858 file_data_merge_sidecar_files(parent_fd, new_fd); | |
859 } | |
860 g_string_free(fname, TRUE); | |
861 } | |
862 | |
863 | |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
864 static FileData *file_data_new_local(const gchar *path, struct stat *st, gboolean check_sidecars) |
138 | 865 { |
866 gchar *path_utf8 = path_to_utf8(path); | |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
867 FileData *ret = file_data_new(path_utf8, st, check_sidecars); |
138 | 868 g_free(path_utf8); |
869 return ret; | |
870 } | |
871 | |
872 FileData *file_data_new_simple(const gchar *path_utf8) | |
9 | 873 { |
874 struct stat st; | |
875 | |
138 | 876 if (!stat_utf8(path_utf8, &st)) |
9 | 877 { |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
878 st.st_size = 0; |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
879 st.st_mtime = 0; |
9 | 880 } |
881 | |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
882 return file_data_new(path_utf8, &st, TRUE); |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
883 } |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
884 |
141 | 885 FileData *file_data_add_sidecar_file(FileData *target, FileData *sfd) |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
886 { |
141 | 887 sfd->parent = target; |
146 | 888 if(!g_list_find(target->sidecar_files, sfd)) |
889 target->sidecar_files = g_list_prepend(target->sidecar_files, sfd); | |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
890 return target; |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
891 } |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
892 |
167 | 893 |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
894 FileData *file_data_merge_sidecar_files(FileData *target, FileData *source) |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
895 { |
141 | 896 GList *work; |
897 file_data_add_sidecar_file(target, source); | |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
898 |
141 | 899 work = source->sidecar_files; |
900 while (work) | |
901 { | |
902 FileData *sfd = work->data; | |
146 | 903 file_data_add_sidecar_file(target, sfd); |
141 | 904 work = work->next; |
905 } | |
906 | |
146 | 907 g_list_free(source->sidecar_files); |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
908 source->sidecar_files = NULL; |
167 | 909 |
910 target->sidecar_files = filelist_sort(target->sidecar_files, SORT_NAME, TRUE); | |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
911 return target; |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
912 } |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
913 |
167 | 914 |
915 | |
138 | 916 FileData *file_data_ref(FileData *fd) |
917 { | |
918 if (fd == NULL) return NULL; | |
919 | |
920 // return g_memdup(fd, sizeof(FileData)); | |
921 g_assert(fd->magick == 0x12345678); | |
922 fd->ref++; | |
923 return fd; | |
924 } | |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
925 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
926 static void file_data_free(FileData *fd) |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
927 { |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
928 g_assert(fd->magick == 0x12345678); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
929 g_assert(fd->ref == 0); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
930 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
931 g_hash_table_remove(file_data_pool, fd->original_path); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
932 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
933 g_free(fd->path); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
934 g_free(fd->original_path); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
935 if (fd->pixbuf) g_object_unref(fd->pixbuf); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
936 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
937 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
938 g_assert(fd->sidecar_files == NULL); /* sidecar files must be freed before calling this */ |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
939 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
940 file_data_change_info_free(NULL, fd); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
941 g_free(fd); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
942 } |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
943 |
138 | 944 void file_data_unref(FileData *fd) |
945 { | |
946 if (fd == NULL) return; | |
947 g_assert(fd->magick == 0x12345678); | |
172 | 948 if (debug) printf("file_data_unref: '%s'\n", fd->path); |
138 | 949 fd->ref--; |
950 if (fd->ref == 0) | |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
951 { |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
952 FileData *parent = fd->parent ? fd->parent : fd; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
953 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
954 GList *work; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
955 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
956 if (parent->ref > 0) |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
957 return; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
958 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
959 work = parent->sidecar_files; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
960 while (work) |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
961 { |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
962 FileData *sfd = work->data; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
963 if (sfd->ref > 0) |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
964 return; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
965 work = work->next; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
966 } |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
967 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
968 /* none of parent/children is referenced, we can free everything */ |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
969 |
172 | 970 if (debug) printf("file_data_unref: deleting '%s', parent '%s'\n", fd->path, parent->path); |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
971 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
972 work = parent->sidecar_files; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
973 while (work) |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
974 { |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
975 FileData *sfd = work->data; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
976 file_data_free(sfd); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
977 work = work->next; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
978 } |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
979 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
980 g_list_free(parent->sidecar_files); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
981 parent->sidecar_files = NULL; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
982 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
983 file_data_free(parent); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
984 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
985 } |
138 | 986 } |
987 | |
167 | 988 FileData *file_data_disconnect_sidecar_file(FileData *target, FileData *sfd) |
989 { | |
990 sfd->parent = target; | |
991 g_assert(g_list_find(target->sidecar_files, sfd)); | |
992 | |
993 target->sidecar_files = g_list_remove(target->sidecar_files, sfd); | |
994 sfd->parent = NULL; | |
995 | |
996 if (sfd->ref == 0) { | |
997 file_data_free(sfd); | |
998 return NULL; | |
999 } | |
1000 | |
1001 return sfd; | |
1002 } | |
1003 | |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
1004 /* compare name without extension */ |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
1005 gint file_data_compare_name_without_ext(FileData *fd1, FileData *fd2) |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
1006 { |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
1007 size_t len1 = fd1->extension - fd1->name; |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
1008 size_t len2 = fd2->extension - fd2->name; |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
1009 |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
1010 if (len1 < len2) return -1; |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
1011 if (len1 > len2) return 1; |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
1012 |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
1013 return strncmp(fd1->name, fd2->name, len1); |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
1014 } |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
1015 |
138 | 1016 FileData *file_data_do_change(FileData *fd) |
1017 { | |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
1018 //FIXME sidecars |
138 | 1019 g_assert(fd->change); |
1020 g_free(fd->path); | |
1021 g_hash_table_remove(file_data_pool, fd->original_path); | |
1022 g_free(fd->original_path); | |
1023 file_data_set_path(fd, fd->change->dest); | |
1024 fd->original_path = g_strdup(fd->change->dest); | |
1025 g_hash_table_insert(file_data_pool, fd->original_path, fd); | |
1026 | |
1027 } | |
1028 | |
143
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
1029 gboolean file_data_add_change_info(FileData *fd, FileDataChangeType type, const gchar *src, const gchar *dest) |
138 | 1030 { |
143
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
1031 |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
1032 FileDataChangeInfo *fdci; |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
1033 |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
1034 if (fd->change) return FALSE; |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
1035 |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
1036 fdci = g_new0(FileDataChangeInfo, 1); |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
1037 |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
1038 fdci->type = type; |
138 | 1039 |
1040 if (src) | |
1041 fdci->source = g_strdup(src); | |
143
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
1042 else |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
1043 fdci->source = g_strdup(fd->path); |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
1044 |
138 | 1045 if (dest) |
1046 fdci->dest = g_strdup(dest); | |
1047 | |
143
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
1048 fd->change = fdci; |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
1049 return TRUE; |
138 | 1050 } |
1051 | |
1052 void file_data_change_info_free(FileDataChangeInfo *fdci, FileData *fd) | |
1053 { | |
1054 if (!fdci && fd) | |
1055 fdci = fd->change; | |
1056 | |
1057 if (!fdci) | |
1058 return; | |
1059 | |
1060 g_free(fdci->source); | |
1061 g_free(fdci->dest); | |
1062 | |
1063 g_free(fdci); | |
1064 | |
1065 if (fd) | |
1066 fd->change = NULL; | |
1067 } | |
139 | 1068 |
1069 | |
1070 | |
138 | 1071 |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
1072 /* |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
1073 *----------------------------------------------------------------------------- |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
1074 * sidecar file info struct |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
1075 *----------------------------------------------------------------------------- |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
1076 */ |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
1077 |
9 | 1078 |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
1079 |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
1080 gint sidecar_file_priority(const gchar *path) |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
1081 { |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
1082 const char *extension = extension_from_path(path); |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
1083 int i = 1; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
1084 GList *work; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
1085 if (extension == NULL) |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
1086 return 0; |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
1087 |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
1088 work = sidecar_ext_get_list(); |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
1089 |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
1090 while (work) { |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
1091 gchar *ext = work->data; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
1092 work = work->next; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
1093 if (strcmp(extension, ext) == 0) return i; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
1094 i++; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
1095 } |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
1096 return 0; |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
1097 } |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
1098 |
139 | 1099 gchar *sidecar_file_data_list_to_string(FileData *fd) |
1100 { | |
1101 GList *work; | |
1102 GString *result = g_string_new(""); | |
1103 | |
1104 work = fd->sidecar_files; | |
1105 while (work) | |
1106 { | |
141 | 1107 FileData *sfd = work->data; |
139 | 1108 result = g_string_append(result, "+ "); |
1109 result = g_string_append(result, sfd->extension); | |
1110 work = work->next; | |
1111 if (work) result = g_string_append_c(result, ' '); | |
1112 } | |
1113 | |
1114 return g_string_free(result, FALSE); | |
1115 } | |
1116 | |
9 | 1117 /* |
1118 *----------------------------------------------------------------------------- | |
1119 * load file list | |
1120 *----------------------------------------------------------------------------- | |
1121 */ | |
1122 | |
1123 static SortType filelist_sort_method = SORT_NONE; | |
1124 static gint filelist_sort_ascend = TRUE; | |
1125 | |
138 | 1126 |
1127 gint filelist_sort_compare_filedata(FileData *fa, FileData *fb) | |
9 | 1128 { |
1129 if (!filelist_sort_ascend) | |
1130 { | |
138 | 1131 FileData *tmp = fa; |
1132 fa = fb; | |
1133 fb = tmp; | |
9 | 1134 } |
1135 | |
1136 switch (filelist_sort_method) | |
1137 { | |
1138 case SORT_SIZE: | |
1139 if (fa->size < fb->size) return -1; | |
1140 if (fa->size > fb->size) return 1; | |
167 | 1141 return CASE_SORT(fa->name, fb->name); /* fall back to name */ |
9 | 1142 break; |
1143 case SORT_TIME: | |
1144 if (fa->date < fb->date) return -1; | |
1145 if (fa->date > fb->date) return 1; | |
167 | 1146 return CASE_SORT(fa->name, fb->name); /* fall back to name */ |
9 | 1147 break; |
1148 #ifdef HAVE_STRVERSCMP | |
1149 case SORT_NUMBER: | |
1150 return strverscmp(fa->name, fb->name); | |
1151 break; | |
1152 #endif | |
1153 case SORT_NAME: | |
1154 default: | |
1155 return CASE_SORT(fa->name, fb->name); | |
1156 break; | |
1157 } | |
1158 } | |
1159 | |
167 | 1160 gint filelist_sort_compare_filedata_full(FileData *fa, FileData *fb, SortType method, gint ascend) |
1161 { | |
1162 filelist_sort_method = method; | |
1163 filelist_sort_ascend = ascend; | |
1164 return filelist_sort_compare_filedata(fa, fb); | |
1165 } | |
1166 | |
138 | 1167 static gint filelist_sort_file_cb(void *a, void *b) |
1168 { | |
1169 return filelist_sort_compare_filedata(a, b); | |
1170 } | |
1171 | |
1172 GList *filelist_sort_full(GList *list, SortType method, gint ascend, GCompareFunc cb) | |
9 | 1173 { |
1174 filelist_sort_method = method; | |
1175 filelist_sort_ascend = ascend; | |
138 | 1176 return g_list_sort(list, cb); |
1177 } | |
1178 | |
1179 GList *filelist_insert_sort_full(GList *list, void *data, SortType method, gint ascend, GCompareFunc cb) | |
1180 { | |
1181 filelist_sort_method = method; | |
1182 filelist_sort_ascend = ascend; | |
1183 return g_list_insert_sorted(list, data, cb); | |
1184 } | |
1185 | |
1186 GList *filelist_sort(GList *list, SortType method, gint ascend) | |
1187 { | |
1188 return filelist_sort_full(list, method, ascend, (GCompareFunc) filelist_sort_file_cb); | |
9 | 1189 } |
1190 | |
1191 GList *filelist_insert_sort(GList *list, FileData *fd, SortType method, gint ascend) | |
1192 { | |
138 | 1193 return filelist_insert_sort_full(list, fd, method, ascend, (GCompareFunc) filelist_sort_file_cb); |
9 | 1194 } |
1195 | |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
1196 |
148 | 1197 static GList *filelist_filter_out_sidecars(GList *flist) |
1198 { | |
1199 GList *work = flist; | |
1200 GList *flist_filtered = NULL; | |
1201 | |
1202 while (work) | |
1203 { | |
1204 FileData *fd = work->data; | |
1205 work = work->next; | |
1206 if (fd->parent) /* remove fd's that are children */ | |
1207 file_data_unref(fd); | |
1208 else | |
1209 flist_filtered = g_list_prepend(flist_filtered, fd); | |
1210 } | |
1211 g_list_free(flist); | |
1212 return flist_filtered; | |
1213 } | |
1214 | |
138 | 1215 static gint filelist_read_real(const gchar *path, GList **files, GList **dirs, gint follow_symlinks) |
1 | 1216 { |
1217 DIR *dp; | |
1218 struct dirent *dir; | |
1219 struct stat ent_sbuf; | |
9 | 1220 gchar *pathl; |
1221 GList *dlist; | |
1222 GList *flist; | |
1 | 1223 |
9 | 1224 dlist = NULL; |
1225 flist = NULL; | |
1226 | |
1227 pathl = path_from_utf8(path); | |
1228 if (!pathl || (dp = opendir(pathl)) == NULL) | |
1 | 1229 { |
9 | 1230 g_free(pathl); |
1231 if (files) *files = NULL; | |
1232 if (dirs) *dirs = NULL; | |
1233 return FALSE; | |
1 | 1234 } |
1235 | |
9 | 1236 /* root dir fix */ |
1237 if (pathl[0] == '/' && pathl[1] == '\0') | |
1238 { | |
1239 g_free(pathl); | |
1240 pathl = g_strdup(""); | |
1241 } | |
1 | 1242 |
1243 while ((dir = readdir(dp)) != NULL) | |
1244 { | |
9 | 1245 gchar *name = dir->d_name; |
1246 if (show_dot_files || !ishidden(name)) | |
1 | 1247 { |
9 | 1248 gchar *filepath = g_strconcat(pathl, "/", name, NULL); |
138 | 1249 if ((follow_symlinks ? |
1250 stat(filepath, &ent_sbuf) : | |
1251 lstat(filepath, &ent_sbuf)) >= 0) | |
1 | 1252 { |
9 | 1253 if (S_ISDIR(ent_sbuf.st_mode)) |
1 | 1254 { |
9 | 1255 /* we ignore the .thumbnails dir for cleanliness */ |
1256 if ((dirs) && | |
1257 !(name[0] == '.' && (name[1] == '\0' || (name[1] == '.' && name[2] == '\0'))) && | |
1258 strcmp(name, GQVIEW_CACHE_LOCAL_THUMB) != 0 && | |
79
528e3432e0c0
Thu Oct 19 07:23:37 2006 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
1259 strcmp(name, GQVIEW_CACHE_LOCAL_METADATA) != 0 && |
528e3432e0c0
Thu Oct 19 07:23:37 2006 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
1260 strcmp(name, THUMB_FOLDER_LOCAL) != 0) |
9 | 1261 { |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
1262 dlist = g_list_prepend(dlist, file_data_new_local(filepath, &ent_sbuf, FALSE)); |
9 | 1263 } |
1 | 1264 } |
1265 else | |
1266 { | |
9 | 1267 if ((files) && filter_name_exists(name)) |
1268 { | |
148 | 1269 flist = g_list_prepend(flist, file_data_new_local(filepath, &ent_sbuf, TRUE)); |
9 | 1270 } |
1 | 1271 } |
1272 } | |
9 | 1273 g_free(filepath); |
1 | 1274 } |
1275 } | |
1276 | |
1277 closedir(dp); | |
1278 | |
9 | 1279 g_free(pathl); |
1 | 1280 |
148 | 1281 flist = filelist_filter_out_sidecars(flist); |
1282 | |
9 | 1283 if (dirs) *dirs = dlist; |
1284 if (files) *files = flist; | |
1 | 1285 |
9 | 1286 return TRUE; |
1 | 1287 } |
1288 | |
138 | 1289 gint filelist_read(const gchar *path, GList **files, GList **dirs) |
1290 { | |
1291 return filelist_read_real(path, files, dirs, TRUE); | |
1292 } | |
1293 | |
1294 gint filelist_read_lstat(const gchar *path, GList **files, GList **dirs) | |
1295 { | |
1296 return filelist_read_real(path, files, dirs, FALSE); | |
1297 } | |
1298 | |
9 | 1299 void filelist_free(GList *list) |
1 | 1300 { |
9 | 1301 GList *work; |
3 | 1302 |
9 | 1303 work = list; |
1304 while (work) | |
1 | 1305 { |
138 | 1306 file_data_unref((FileData *)work->data); |
1 | 1307 work = work->next; |
1308 } | |
1309 | |
9 | 1310 g_list_free(list); |
3 | 1311 } |
1312 | |
1 | 1313 |
138 | 1314 GList *filelist_copy(GList *list) |
1315 { | |
1316 GList *new_list = NULL; | |
1317 GList *work; | |
1318 | |
1319 work = list; | |
1320 while (work) | |
1321 { | |
1322 FileData *fd; | |
1323 | |
1324 fd = work->data; | |
1325 work = work->next; | |
1326 | |
1327 new_list = g_list_prepend(new_list, file_data_ref(fd)); | |
1328 } | |
1329 | |
1330 return g_list_reverse(new_list); | |
1331 } | |
1332 | |
1333 GList *filelist_from_path_list(GList *list) | |
1334 { | |
1335 GList *new_list = NULL; | |
1336 GList *work; | |
1337 | |
1338 work = list; | |
1339 while (work) | |
1340 { | |
1341 gchar *path; | |
1342 | |
1343 path = work->data; | |
1344 work = work->next; | |
1345 | |
1346 new_list = g_list_prepend(new_list, file_data_new_simple(path)); | |
1347 } | |
1348 | |
1349 return g_list_reverse(new_list); | |
1350 } | |
1351 | |
1352 GList *filelist_to_path_list(GList *list) | |
1353 { | |
1354 GList *new_list = NULL; | |
1355 GList *work; | |
1356 | |
1357 work = list; | |
1358 while (work) | |
1359 { | |
1360 FileData *fd; | |
1361 | |
1362 fd = work->data; | |
1363 work = work->next; | |
1364 | |
1365 new_list = g_list_prepend(new_list, g_strdup(fd->path)); | |
1366 } | |
1367 | |
1368 return g_list_reverse(new_list); | |
1369 } | |
1370 | |
1371 GList *filelist_filter(GList *list, gint is_dir_list) | |
1372 { | |
1373 GList *work; | |
1374 | |
1375 if (!is_dir_list && file_filter_disable && show_dot_files) return list; | |
1376 | |
1377 work = list; | |
1378 while (work) | |
1379 { | |
1380 FileData *fd = (FileData *)(work->data); | |
1381 const gchar *name = fd->name; | |
1382 | |
1383 if ((!show_dot_files && ishidden(name)) || | |
1384 (!is_dir_list && !filter_name_exists(name)) || | |
1385 (is_dir_list && name[0] == '.' && (strcmp(name, GQVIEW_CACHE_LOCAL_THUMB) == 0 || | |
1386 strcmp(name, GQVIEW_CACHE_LOCAL_METADATA) == 0)) ) | |
1387 { | |
1388 GList *link = work; | |
1389 work = work->next; | |
1390 list = g_list_remove_link(list, link); | |
1391 file_data_unref(fd); | |
1392 g_list_free(link); | |
1393 } | |
1394 else | |
1395 { | |
1396 work = work->next; | |
1397 } | |
1398 } | |
1399 | |
1400 return list; | |
1401 } | |
1402 | |
1403 /* | |
1404 *----------------------------------------------------------------------------- | |
1405 * filelist recursive | |
1406 *----------------------------------------------------------------------------- | |
1407 */ | |
1408 | |
1409 static gint filelist_sort_path_cb(gconstpointer a, gconstpointer b) | |
1410 { | |
1411 return CASE_SORT(((FileData *)a)->path, ((FileData *)b)->path); | |
1412 } | |
1413 | |
1414 GList *filelist_sort_path(GList *list) | |
1415 { | |
1416 return g_list_sort(list, filelist_sort_path_cb); | |
1417 } | |
1418 | |
1419 static void filelist_recursive_append(GList **list, GList *dirs) | |
1420 { | |
1421 GList *work; | |
1422 | |
1423 work = dirs; | |
1424 while (work) | |
1425 { | |
1426 FileData *fd = (FileData *)(work->data); | |
1427 const gchar *path = fd->path; | |
1428 GList *f = NULL; | |
1429 GList *d = NULL; | |
1430 | |
1431 if (filelist_read(path, &f, &d)) | |
1432 { | |
1433 f = filelist_filter(f, FALSE); | |
1434 f = filelist_sort_path(f); | |
1435 *list = g_list_concat(*list, f); | |
1436 | |
1437 d = filelist_filter(d, TRUE); | |
1438 d = filelist_sort_path(d); | |
1439 filelist_recursive_append(list, d); | |
1440 filelist_free(d); | |
1441 } | |
1442 | |
1443 work = work->next; | |
1444 } | |
1445 } | |
1446 | |
1447 GList *filelist_recursive(const gchar *path) | |
1448 { | |
1449 GList *list = NULL; | |
1450 GList *d = NULL; | |
1451 | |
1452 if (!filelist_read(path, &list, &d)) return NULL; | |
1453 list = filelist_filter(list, FALSE); | |
1454 list = filelist_sort_path(list); | |
1455 | |
1456 d = filelist_filter(d, TRUE); | |
1457 d = filelist_sort_path(d); | |
1458 filelist_recursive_append(&list, d); | |
1459 filelist_free(d); | |
1460 | |
1461 return list; | |
1462 } |