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