Mercurial > geeqie
annotate src/filelist.c @ 154:6bcd037bf176
fixed image focus
author | nadvornik |
---|---|
date | Sun, 09 Dec 2007 21:20:27 +0000 |
parents | a8b4b99c9359 |
children | f8bd5d49eed8 |
rev | line source |
---|---|
1 | 1 /* |
9 | 2 * GQview |
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); | |
43
ee03f36e9e4b
Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
212 |
ee03f36e9e4b
Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
213 /* These are the raw camera formats with embedded jpeg/exif. |
ee03f36e9e4b
Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
214 * (see format_raw.c) |
ee03f36e9e4b
Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
215 */ |
53
00843150f7c8
Tue Jun 7 03:47:03 2005 John Ellis <johne@verizon.net>
gqview
parents:
52
diff
changeset
|
216 filter_add_if_missing("crw", "Canon raw format", ".crw;.cr2", TRUE); |
45
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
217 filter_add_if_missing("raf", "Fujifilm raw format", ".raf", TRUE); |
53
00843150f7c8
Tue Jun 7 03:47:03 2005 John Ellis <johne@verizon.net>
gqview
parents:
52
diff
changeset
|
218 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
|
219 filter_add_if_missing("orf", "Olympus raw format", ".orf", TRUE); |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
79
diff
changeset
|
220 filter_add_if_missing("pef", "Pentax raw format", ".pef", TRUE); |
9 | 221 } |
222 | |
147
b2266996fa83
added possibility to specify prefered file type for external commands
nadvornik
parents:
146
diff
changeset
|
223 GList *filter_to_list(const gchar *extensions) |
9 | 224 { |
225 GList *list = NULL; | |
226 const gchar *p; | |
227 | |
228 if (!extensions) return NULL; | |
229 | |
230 p = extensions; | |
231 while (*p != '\0') | |
232 { | |
233 const gchar *b; | |
234 gint l = 0; | |
235 | |
236 b = p; | |
237 while (*p != '\0' && *p != ';') | |
238 { | |
239 p++; | |
240 l++; | |
241 } | |
242 list = g_list_append(list, g_strndup(b, l)); | |
243 if (*p == ';') p++; | |
244 } | |
245 | |
246 return list; | |
247 } | |
248 | |
249 void filter_rebuild(void) | |
250 { | |
251 GList *work; | |
252 | |
253 path_list_free(extension_list); | |
254 extension_list = NULL; | |
255 | |
256 work = filter_list; | |
257 while (work) | |
258 { | |
259 FilterEntry *fe; | |
260 | |
261 fe = work->data; | |
262 work = work->next; | |
263 | |
264 if (fe->enabled) | |
265 { | |
266 GList *ext; | |
267 | |
268 ext = filter_to_list(fe->extensions); | |
269 if (ext) extension_list = g_list_concat(extension_list, ext); | |
270 } | |
271 } | |
272 } | |
273 | |
274 gint filter_name_exists(const gchar *name) | |
275 { | |
276 GList *work; | |
277 if (!extension_list || file_filter_disable) return TRUE; | |
278 | |
279 work = extension_list; | |
1 | 280 while (work) |
281 { | |
282 gchar *filter = work->data; | |
283 gint lf = strlen(filter); | |
284 gint ln = strlen(name); | |
285 if (ln >= lf) | |
286 { | |
287 if (strncasecmp(name + ln - lf, filter, lf) == 0) return TRUE; | |
288 } | |
289 work = work->next; | |
290 } | |
291 | |
292 return FALSE; | |
293 } | |
294 | |
9 | 295 void filter_write_list(FILE *f) |
1 | 296 { |
9 | 297 GList *work; |
298 | |
299 work = filter_list; | |
300 while (work) | |
301 { | |
302 FilterEntry *fe = work->data; | |
303 work = work->next; | |
304 | |
305 fprintf(f, "filter_ext: \"%s%s\" \"%s\" \"%s\"\n", (fe->enabled) ? "" : "#", | |
306 fe->key, fe->extensions, | |
307 (fe->description) ? fe->description : ""); | |
308 } | |
1 | 309 } |
310 | |
9 | 311 void filter_parse(const gchar *text) |
1 | 312 { |
9 | 313 const gchar *p; |
314 gchar *key; | |
315 gchar *ext; | |
316 gchar *desc; | |
317 gint enabled = TRUE; | |
318 | |
319 if (!text || text[0] != '"') return; | |
320 | |
321 key = quoted_value(text); | |
322 if (!key) return; | |
323 | |
324 p = text; | |
325 p++; | |
326 while (*p != '"' && *p != '\0') p++; | |
327 if (*p != '"') | |
328 { | |
329 g_free(key); | |
330 return; | |
331 } | |
332 p++; | |
333 while (*p != '"' && *p != '\0') p++; | |
334 if (*p != '"') | |
1 | 335 { |
9 | 336 g_free(key); |
337 return; | |
338 } | |
339 | |
340 ext = quoted_value(p); | |
341 | |
342 p++; | |
343 while (*p != '"' && *p != '\0') p++; | |
344 if (*p == '"') p++; | |
345 while (*p != '"' && *p != '\0') p++; | |
346 | |
347 if (*p == '"') | |
348 { | |
349 desc = quoted_value(p); | |
350 } | |
351 else | |
352 { | |
353 desc = NULL; | |
354 } | |
355 | |
356 if (key && key[0] == '#') | |
357 { | |
358 gchar *tmp; | |
359 tmp = g_strdup(key + 1); | |
360 g_free(key); | |
361 key = tmp; | |
362 | |
363 enabled = FALSE; | |
1 | 364 } |
365 | |
9 | 366 if (key && strlen(key) > 0 && ext) filter_add(key, desc, ext, enabled); |
367 | |
368 g_free(key); | |
369 g_free(ext); | |
370 g_free(desc); | |
371 } | |
1 | 372 |
9 | 373 GList *path_list_filter(GList *list, gint is_dir_list) |
374 { | |
375 GList *work; | |
376 | |
377 if (!is_dir_list && file_filter_disable && show_dot_files) return list; | |
378 | |
379 work = list; | |
380 while (work) | |
1 | 381 { |
9 | 382 gchar *name = work->data; |
383 const gchar *base; | |
384 | |
385 base = filename_from_path(name); | |
386 | |
387 if ((!show_dot_files && ishidden(base)) || | |
388 (!is_dir_list && !filter_name_exists(base)) || | |
389 (is_dir_list && base[0] == '.' && (strcmp(base, GQVIEW_CACHE_LOCAL_THUMB) == 0 || | |
390 strcmp(base, GQVIEW_CACHE_LOCAL_METADATA) == 0)) ) | |
391 { | |
392 GList *link = work; | |
393 work = work->next; | |
394 list = g_list_remove_link(list, link); | |
395 g_free(name); | |
396 g_list_free(link); | |
397 } | |
398 else | |
1 | 399 { |
9 | 400 work = work->next; |
1 | 401 } |
402 } | |
9 | 403 |
404 return list; | |
405 } | |
406 | |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
407 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
408 /* |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
409 *----------------------------------------------------------------------------- |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
410 * sidecar extension list |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
411 *----------------------------------------------------------------------------- |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
412 */ |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
413 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
414 static GList *sidecar_ext_get_list(void) |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
415 { |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
416 return sidecar_ext_list; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
417 } |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
418 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
419 void sidecar_ext_parse(const gchar *text) |
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 GList *work; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
422 gchar *value; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
423 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
424 work = sidecar_ext_list; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
425 while (work) |
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 gchar *ext = work->data; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
428 work = work->next; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
429 g_free(ext); |
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 g_list_free(sidecar_ext_list); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
432 sidecar_ext_list = NULL; |
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 value = quoted_value(text); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
435 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
436 if (value == NULL) return; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
437 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
438 sidecar_ext_list = filter_to_list(value); |
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 g_free(value); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
441 } |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
442 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
443 void sidecar_ext_write(FILE *f) |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
444 { |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
445 GList *work; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
446 fprintf(f, "\nsidecar_ext: \""); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
447 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
448 work = sidecar_ext_list; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
449 while (work) |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
450 { |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
451 gchar *ext = work->data; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
452 work = work->next; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
453 fprintf(f, "%s%s", ext, work ? ";" : ""); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
454 } |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
455 fprintf(f, "\"\n"); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
456 |
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_add_defaults() |
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 sidecar_ext_parse("\".jpg;.cr2;.nef;.crw\""); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
462 } |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
463 |
9 | 464 /* |
465 *----------------------------------------------------------------------------- | |
466 * path list recursive | |
467 *----------------------------------------------------------------------------- | |
468 */ | |
469 | |
470 static gint path_list_sort_cb(gconstpointer a, gconstpointer b) | |
471 { | |
472 return CASE_SORT((gchar *)a, (gchar *)b); | |
473 } | |
474 | |
475 GList *path_list_sort(GList *list) | |
476 { | |
477 return g_list_sort(list, path_list_sort_cb); | |
478 } | |
479 | |
480 static void path_list_recursive_append(GList **list, GList *dirs) | |
481 { | |
482 GList *work; | |
483 | |
484 work = dirs; | |
485 while (work) | |
486 { | |
487 const gchar *path = work->data; | |
488 GList *f = NULL; | |
489 GList *d = NULL; | |
490 | |
491 if (path_list(path, &f, &d)) | |
492 { | |
493 f = path_list_filter(f, FALSE); | |
494 f = path_list_sort(f); | |
495 *list = g_list_concat(*list, f); | |
496 | |
497 d = path_list_filter(d, TRUE); | |
498 d = path_list_sort(d); | |
499 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
|
500 path_list_free(d); |
9 | 501 } |
502 | |
503 work = work->next; | |
504 } | |
505 } | |
506 | |
507 GList *path_list_recursive(const gchar *path) | |
508 { | |
509 GList *list = NULL; | |
510 GList *d = NULL; | |
511 | |
512 if (!path_list(path, &list, &d)) return NULL; | |
513 list = path_list_filter(list, FALSE); | |
514 list = path_list_sort(list); | |
515 | |
516 d = path_list_filter(d, TRUE); | |
517 d = path_list_sort(d); | |
518 path_list_recursive_append(&list, d); | |
519 path_list_free(d); | |
520 | |
521 return list; | |
1 | 522 } |
523 | |
524 /* | |
525 *----------------------------------------------------------------------------- | |
9 | 526 * text conversion utils |
1 | 527 *----------------------------------------------------------------------------- |
528 */ | |
529 | |
9 | 530 gchar *text_from_size(gint64 size) |
1 | 531 { |
9 | 532 gchar *a, *b; |
533 gchar *s, *d; | |
534 gint l, n, i; | |
535 | |
536 /* what I would like to use is printf("%'d", size) | |
537 * BUT: not supported on every libc :( | |
538 */ | |
539 if (size > G_MAXUINT) | |
540 { | |
541 /* the %lld conversion is not valid in all libcs, so use a simple work-around */ | |
542 a = g_strdup_printf("%d%09d", (guint)(size / 1000000000), (guint)(size % 1000000000)); | |
543 } | |
544 else | |
545 { | |
546 a = g_strdup_printf("%d", (guint)size); | |
547 } | |
548 l = strlen(a); | |
549 n = (l - 1)/ 3; | |
550 if (n < 1) return a; | |
551 | |
552 b = g_new(gchar, l + n + 1); | |
553 | |
554 s = a; | |
555 d = b; | |
556 i = l - n * 3; | |
557 while (*s != '\0') | |
558 { | |
559 if (i < 1) | |
560 { | |
561 i = 3; | |
562 *d = ','; | |
563 d++; | |
564 } | |
565 | |
566 *d = *s; | |
567 s++; | |
568 d++; | |
569 i--; | |
570 } | |
571 *d = '\0'; | |
572 | |
573 g_free(a); | |
574 return b; | |
575 } | |
576 | |
577 gchar *text_from_size_abrev(gint64 size) | |
578 { | |
579 if (size < (gint64)1024) | |
580 { | |
581 return g_strdup_printf(_("%d bytes"), (gint)size); | |
582 } | |
583 if (size < (gint64)1048576) | |
584 { | |
15
3263965d5f9e
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
585 return g_strdup_printf(_("%.1f K"), (double)size / 1024.0); |
9 | 586 } |
587 if (size < (gint64)1073741824) | |
588 { | |
15
3263965d5f9e
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
589 return g_strdup_printf(_("%.1f MB"), (double)size / 1048576.0); |
9 | 590 } |
591 | |
15
3263965d5f9e
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
592 /* 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
|
593 size /= 1048576; |
3263965d5f9e
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
594 return g_strdup_printf(_("%.1f GB"), (double)size / 1024.0); |
9 | 595 } |
596 | |
597 /* note: returned string is valid until next call to text_from_time() */ | |
598 const gchar *text_from_time(time_t t) | |
599 { | |
600 static gchar *ret = NULL; | |
601 gchar buf[128]; | |
602 gint buflen; | |
603 struct tm *btime; | |
604 GError *error = NULL; | |
605 | |
606 btime = localtime(&t); | |
607 | |
608 /* the %x warning about 2 digit years is not an error */ | |
609 buflen = strftime(buf, sizeof(buf), "%x %H:%M", btime); | |
610 if (buflen < 1) return ""; | |
611 | |
612 g_free(ret); | |
613 ret = g_locale_to_utf8(buf, buflen, NULL, NULL, &error); | |
614 if (error) | |
615 { | |
616 printf("Error converting locale strftime to UTF-8: %s\n", error->message); | |
617 g_error_free(error); | |
618 return ""; | |
619 } | |
620 | |
621 return ret; | |
1 | 622 } |
623 | |
9 | 624 /* |
625 *----------------------------------------------------------------------------- | |
626 * file info struct | |
627 *----------------------------------------------------------------------------- | |
628 */ | |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
629 |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
630 FileData *file_data_merge_sidecar_files(FileData *target, FileData *source); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
631 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
632 |
138 | 633 static void file_data_set_path(FileData *fd, const gchar *path) |
634 { | |
9 | 635 |
138 | 636 if (strcmp(path, "/") == 0) |
637 { | |
638 fd->path = g_strdup(path); | |
639 fd->name = fd->path; | |
640 fd->extension = fd->name + 1; | |
641 return; | |
642 } | |
643 | |
644 fd->path = g_strdup(path); | |
645 fd->name = filename_from_path(fd->path); | |
646 | |
647 if (strcmp(fd->name, "..") == 0) | |
648 { | |
649 gchar *dir = remove_level_from_path(path); | |
650 g_free(fd->path); | |
651 fd->path = remove_level_from_path(dir); | |
652 g_free(dir); | |
653 fd->name = ".."; | |
654 fd->extension = fd->name + 2; | |
655 return; | |
656 } | |
657 else if (strcmp(fd->name, ".") == 0) | |
658 { | |
659 g_free(fd->path); | |
660 fd->path = remove_level_from_path(path); | |
661 fd->name = "."; | |
662 fd->extension = fd->name + 1; | |
663 return; | |
664 } | |
665 | |
666 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
|
667 if (fd->extension == NULL) |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
668 fd->extension = fd->name + strlen(fd->name); |
138 | 669 } |
670 | |
146 | 671 static void file_data_check_sidecars(FileData *fd); |
138 | 672 static GHashTable *file_data_pool = NULL; |
673 | |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
674 static FileData *file_data_new(const gchar *path_utf8, struct stat *st, gboolean check_sidecars) |
9 | 675 { |
676 FileData *fd; | |
677 | |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
678 printf("file_data_new: '%s' %d\n", path_utf8, check_sidecars); |
138 | 679 |
680 if (!file_data_pool) | |
681 file_data_pool = g_hash_table_new (g_str_hash, g_str_equal); | |
682 | |
683 fd = g_hash_table_lookup(file_data_pool, path_utf8); | |
684 if (fd) | |
685 { | |
686 printf("file_data_pool hit: '%s'\n", fd->path); | |
687 return file_data_ref(fd); | |
688 } | |
689 | |
9 | 690 fd = g_new0(FileData, 1); |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
691 |
138 | 692 file_data_set_path(fd, path_utf8); |
693 | |
694 fd->original_path = g_strdup(path_utf8); | |
9 | 695 fd->size = st->st_size; |
696 fd->date = st->st_mtime; | |
697 fd->pixbuf = NULL; | |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
698 fd->sidecar_files = NULL; |
138 | 699 fd->ref = 1; |
700 fd->magick = 0x12345678; | |
701 | |
702 g_hash_table_insert(file_data_pool, fd->original_path, fd); | |
703 | |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
704 if (check_sidecars && sidecar_file_priority(fd->extension)) |
146 | 705 file_data_check_sidecars(fd); |
9 | 706 return fd; |
707 } | |
708 | |
146 | 709 static void file_data_check_sidecars(FileData *fd) |
710 { | |
711 int i = 0; | |
712 int base_len = fd->extension - fd->path; | |
713 GString *fname = g_string_new_len(fd->path, base_len); | |
714 FileData *parent_fd = NULL; | |
715 GList *work = sidecar_ext_get_list(); | |
716 while (work) | |
717 { | |
718 /* check for possible sidecar files; | |
719 the sidecar files created here are referenced only via fd->sidecar_files or fd->parent, | |
720 they have fd->ref set to 0 and file_data unref must chack and free them all together | |
721 (using fd->ref would cause loops and leaks) | |
722 */ | |
723 | |
724 FileData *new_fd; | |
725 | |
726 gchar *ext = work->data; | |
727 work = work->next; | |
728 | |
729 if (strcmp(ext, fd->extension) == 0) | |
730 { | |
731 new_fd = fd; /* processing the original file */ | |
732 } | |
733 else | |
734 { | |
735 struct stat nst; | |
736 g_string_truncate(fname, base_len); | |
737 g_string_append(fname, ext); | |
738 | |
739 if (!stat_utf8(fname->str, &nst)) | |
740 continue; | |
741 | |
742 new_fd = file_data_new(fname->str, &nst, FALSE); | |
743 new_fd->ref--; /* do not use ref here */ | |
744 } | |
745 | |
746 if (!parent_fd) | |
747 parent_fd = new_fd; /* parent is the one with the highest prio, found first */ | |
748 else | |
749 file_data_merge_sidecar_files(parent_fd, new_fd); | |
750 } | |
751 g_string_free(fname, TRUE); | |
752 } | |
753 | |
754 | |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
755 static FileData *file_data_new_local(const gchar *path, struct stat *st, gboolean check_sidecars) |
138 | 756 { |
757 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
|
758 FileData *ret = file_data_new(path_utf8, st, check_sidecars); |
138 | 759 g_free(path_utf8); |
760 return ret; | |
761 } | |
762 | |
763 FileData *file_data_new_simple(const gchar *path_utf8) | |
9 | 764 { |
765 struct stat st; | |
766 | |
138 | 767 if (!stat_utf8(path_utf8, &st)) |
9 | 768 { |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
769 st.st_size = 0; |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
770 st.st_mtime = 0; |
9 | 771 } |
772 | |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
773 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
|
774 } |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
775 |
141 | 776 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
|
777 { |
141 | 778 sfd->parent = target; |
146 | 779 if(!g_list_find(target->sidecar_files, sfd)) |
780 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
|
781 return target; |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
782 } |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
783 |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
784 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
|
785 { |
141 | 786 GList *work; |
787 file_data_add_sidecar_file(target, source); | |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
788 |
141 | 789 work = source->sidecar_files; |
790 while (work) | |
791 { | |
792 FileData *sfd = work->data; | |
146 | 793 file_data_add_sidecar_file(target, sfd); |
141 | 794 work = work->next; |
795 } | |
796 | |
146 | 797 g_list_free(source->sidecar_files); |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
798 source->sidecar_files = NULL; |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
799 |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
800 return target; |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
801 } |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
802 |
138 | 803 FileData *file_data_ref(FileData *fd) |
804 { | |
805 if (fd == NULL) return NULL; | |
806 | |
807 // return g_memdup(fd, sizeof(FileData)); | |
808 g_assert(fd->magick == 0x12345678); | |
809 fd->ref++; | |
810 return fd; | |
811 } | |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
812 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
813 static void file_data_free(FileData *fd) |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
814 { |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
815 g_assert(fd->magick == 0x12345678); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
816 g_assert(fd->ref == 0); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
817 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
818 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
|
819 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
820 g_free(fd->path); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
821 g_free(fd->original_path); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
822 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
|
823 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
824 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
825 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
|
826 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
827 file_data_change_info_free(NULL, fd); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
828 g_free(fd); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
829 } |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
830 |
138 | 831 void file_data_unref(FileData *fd) |
832 { | |
833 if (fd == NULL) return; | |
834 g_assert(fd->magick == 0x12345678); | |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
835 printf("file_data_unref: '%s'\n", fd->path); |
138 | 836 fd->ref--; |
837 if (fd->ref == 0) | |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
838 { |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
839 FileData *parent = fd->parent ? fd->parent : fd; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
840 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
841 GList *work; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
842 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
843 if (parent->ref > 0) |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
844 return; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
845 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
846 work = parent->sidecar_files; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
847 while (work) |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
848 { |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
849 FileData *sfd = work->data; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
850 if (sfd->ref > 0) |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
851 return; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
852 work = work->next; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
853 } |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
854 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
855 /* 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
|
856 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
857 printf("file_data_unref: '%s', parent '%s'\n", fd->path, parent->path); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
858 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
859 work = parent->sidecar_files; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
860 while (work) |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
861 { |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
862 FileData *sfd = work->data; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
863 file_data_free(sfd); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
864 work = work->next; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
865 } |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
866 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
867 g_list_free(parent->sidecar_files); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
868 parent->sidecar_files = NULL; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
869 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
870 file_data_free(parent); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
871 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
872 } |
138 | 873 } |
874 | |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
875 /* compare name without extension */ |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
876 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
|
877 { |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
878 size_t len1 = fd1->extension - fd1->name; |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
879 size_t len2 = fd2->extension - fd2->name; |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
880 |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
881 if (len1 < len2) return -1; |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
882 if (len1 > len2) return 1; |
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 return strncmp(fd1->name, fd2->name, len1); |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
885 } |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
886 |
138 | 887 FileData *file_data_do_change(FileData *fd) |
888 { | |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
889 //FIXME sidecars |
138 | 890 g_assert(fd->change); |
891 g_free(fd->path); | |
892 g_hash_table_remove(file_data_pool, fd->original_path); | |
893 g_free(fd->original_path); | |
894 file_data_set_path(fd, fd->change->dest); | |
895 fd->original_path = g_strdup(fd->change->dest); | |
896 g_hash_table_insert(file_data_pool, fd->original_path, fd); | |
897 | |
898 } | |
899 | |
143
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
900 gboolean file_data_add_change_info(FileData *fd, FileDataChangeType type, const gchar *src, const gchar *dest) |
138 | 901 { |
143
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
902 |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
903 FileDataChangeInfo *fdci; |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
904 |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
905 if (fd->change) return FALSE; |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
906 |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
907 fdci = g_new0(FileDataChangeInfo, 1); |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
908 |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
909 fdci->type = type; |
138 | 910 |
911 if (src) | |
912 fdci->source = g_strdup(src); | |
143
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
913 else |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
914 fdci->source = g_strdup(fd->path); |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
915 |
138 | 916 if (dest) |
917 fdci->dest = g_strdup(dest); | |
918 | |
143
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
919 fd->change = fdci; |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
920 return TRUE; |
138 | 921 } |
922 | |
923 void file_data_change_info_free(FileDataChangeInfo *fdci, FileData *fd) | |
924 { | |
925 if (!fdci && fd) | |
926 fdci = fd->change; | |
927 | |
928 if (!fdci) | |
929 return; | |
930 | |
931 g_free(fdci->source); | |
932 g_free(fdci->dest); | |
933 | |
934 g_free(fdci); | |
935 | |
936 if (fd) | |
937 fd->change = NULL; | |
938 } | |
139 | 939 |
940 | |
941 | |
138 | 942 |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
943 /* |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
944 *----------------------------------------------------------------------------- |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
945 * sidecar file info struct |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
946 *----------------------------------------------------------------------------- |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
947 */ |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
948 |
9 | 949 |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
950 |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
951 gint sidecar_file_priority(const gchar *path) |
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 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
|
954 int i = 1; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
955 GList *work; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
956 if (extension == NULL) |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
957 return 0; |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
958 |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
959 work = sidecar_ext_get_list(); |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
960 |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
961 while (work) { |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
962 gchar *ext = work->data; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
963 work = work->next; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
964 if (strcmp(extension, ext) == 0) return i; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
965 i++; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
966 } |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
967 return 0; |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
968 } |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
969 |
139 | 970 gchar *sidecar_file_data_list_to_string(FileData *fd) |
971 { | |
972 GList *work; | |
973 GString *result = g_string_new(""); | |
974 | |
975 work = fd->sidecar_files; | |
976 while (work) | |
977 { | |
141 | 978 FileData *sfd = work->data; |
139 | 979 result = g_string_append(result, "+ "); |
980 result = g_string_append(result, sfd->extension); | |
981 work = work->next; | |
982 if (work) result = g_string_append_c(result, ' '); | |
983 } | |
984 | |
985 return g_string_free(result, FALSE); | |
986 } | |
987 | |
9 | 988 /* |
989 *----------------------------------------------------------------------------- | |
990 * load file list | |
991 *----------------------------------------------------------------------------- | |
992 */ | |
993 | |
994 static SortType filelist_sort_method = SORT_NONE; | |
995 static gint filelist_sort_ascend = TRUE; | |
996 | |
138 | 997 |
998 gint filelist_sort_compare_filedata(FileData *fa, FileData *fb) | |
9 | 999 { |
1000 if (!filelist_sort_ascend) | |
1001 { | |
138 | 1002 FileData *tmp = fa; |
1003 fa = fb; | |
1004 fb = tmp; | |
9 | 1005 } |
1006 | |
1007 switch (filelist_sort_method) | |
1008 { | |
1009 case SORT_SIZE: | |
1010 if (fa->size < fb->size) return -1; | |
1011 if (fa->size > fb->size) return 1; | |
1012 return 0; | |
1013 break; | |
1014 case SORT_TIME: | |
1015 if (fa->date < fb->date) return -1; | |
1016 if (fa->date > fb->date) return 1; | |
1017 return 0; | |
1018 break; | |
1019 #ifdef HAVE_STRVERSCMP | |
1020 case SORT_NUMBER: | |
1021 return strverscmp(fa->name, fb->name); | |
1022 break; | |
1023 #endif | |
1024 case SORT_NAME: | |
1025 default: | |
1026 return CASE_SORT(fa->name, fb->name); | |
1027 break; | |
1028 } | |
1029 } | |
1030 | |
138 | 1031 static gint filelist_sort_file_cb(void *a, void *b) |
1032 { | |
1033 return filelist_sort_compare_filedata(a, b); | |
1034 } | |
1035 | |
1036 GList *filelist_sort_full(GList *list, SortType method, gint ascend, GCompareFunc cb) | |
9 | 1037 { |
1038 filelist_sort_method = method; | |
1039 filelist_sort_ascend = ascend; | |
138 | 1040 return g_list_sort(list, cb); |
1041 } | |
1042 | |
1043 GList *filelist_insert_sort_full(GList *list, void *data, SortType method, gint ascend, GCompareFunc cb) | |
1044 { | |
1045 filelist_sort_method = method; | |
1046 filelist_sort_ascend = ascend; | |
1047 return g_list_insert_sorted(list, data, cb); | |
1048 } | |
1049 | |
1050 GList *filelist_sort(GList *list, SortType method, gint ascend) | |
1051 { | |
1052 return filelist_sort_full(list, method, ascend, (GCompareFunc) filelist_sort_file_cb); | |
9 | 1053 } |
1054 | |
1055 GList *filelist_insert_sort(GList *list, FileData *fd, SortType method, gint ascend) | |
1056 { | |
138 | 1057 return filelist_insert_sort_full(list, fd, method, ascend, (GCompareFunc) filelist_sort_file_cb); |
9 | 1058 } |
1059 | |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
1060 |
148 | 1061 static GList *filelist_filter_out_sidecars(GList *flist) |
1062 { | |
1063 GList *work = flist; | |
1064 GList *flist_filtered = NULL; | |
1065 | |
1066 while (work) | |
1067 { | |
1068 FileData *fd = work->data; | |
1069 work = work->next; | |
1070 if (fd->parent) /* remove fd's that are children */ | |
1071 file_data_unref(fd); | |
1072 else | |
1073 flist_filtered = g_list_prepend(flist_filtered, fd); | |
1074 } | |
1075 g_list_free(flist); | |
1076 return flist_filtered; | |
1077 } | |
1078 | |
138 | 1079 static gint filelist_read_real(const gchar *path, GList **files, GList **dirs, gint follow_symlinks) |
1 | 1080 { |
1081 DIR *dp; | |
1082 struct dirent *dir; | |
1083 struct stat ent_sbuf; | |
9 | 1084 gchar *pathl; |
1085 GList *dlist; | |
1086 GList *flist; | |
1 | 1087 |
9 | 1088 dlist = NULL; |
1089 flist = NULL; | |
1090 | |
1091 pathl = path_from_utf8(path); | |
1092 if (!pathl || (dp = opendir(pathl)) == NULL) | |
1 | 1093 { |
9 | 1094 g_free(pathl); |
1095 if (files) *files = NULL; | |
1096 if (dirs) *dirs = NULL; | |
1097 return FALSE; | |
1 | 1098 } |
1099 | |
9 | 1100 /* root dir fix */ |
1101 if (pathl[0] == '/' && pathl[1] == '\0') | |
1102 { | |
1103 g_free(pathl); | |
1104 pathl = g_strdup(""); | |
1105 } | |
1 | 1106 |
1107 while ((dir = readdir(dp)) != NULL) | |
1108 { | |
9 | 1109 gchar *name = dir->d_name; |
1110 if (show_dot_files || !ishidden(name)) | |
1 | 1111 { |
9 | 1112 gchar *filepath = g_strconcat(pathl, "/", name, NULL); |
138 | 1113 if ((follow_symlinks ? |
1114 stat(filepath, &ent_sbuf) : | |
1115 lstat(filepath, &ent_sbuf)) >= 0) | |
1 | 1116 { |
9 | 1117 if (S_ISDIR(ent_sbuf.st_mode)) |
1 | 1118 { |
9 | 1119 /* we ignore the .thumbnails dir for cleanliness */ |
1120 if ((dirs) && | |
1121 !(name[0] == '.' && (name[1] == '\0' || (name[1] == '.' && name[2] == '\0'))) && | |
1122 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
|
1123 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
|
1124 strcmp(name, THUMB_FOLDER_LOCAL) != 0) |
9 | 1125 { |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
1126 dlist = g_list_prepend(dlist, file_data_new_local(filepath, &ent_sbuf, FALSE)); |
9 | 1127 } |
1 | 1128 } |
1129 else | |
1130 { | |
9 | 1131 if ((files) && filter_name_exists(name)) |
1132 { | |
148 | 1133 flist = g_list_prepend(flist, file_data_new_local(filepath, &ent_sbuf, TRUE)); |
9 | 1134 } |
1 | 1135 } |
1136 } | |
9 | 1137 g_free(filepath); |
1 | 1138 } |
1139 } | |
1140 | |
1141 closedir(dp); | |
1142 | |
9 | 1143 g_free(pathl); |
1 | 1144 |
148 | 1145 flist = filelist_filter_out_sidecars(flist); |
1146 | |
9 | 1147 if (dirs) *dirs = dlist; |
1148 if (files) *files = flist; | |
1 | 1149 |
9 | 1150 return TRUE; |
1 | 1151 } |
1152 | |
138 | 1153 gint filelist_read(const gchar *path, GList **files, GList **dirs) |
1154 { | |
1155 return filelist_read_real(path, files, dirs, TRUE); | |
1156 } | |
1157 | |
1158 gint filelist_read_lstat(const gchar *path, GList **files, GList **dirs) | |
1159 { | |
1160 return filelist_read_real(path, files, dirs, FALSE); | |
1161 } | |
1162 | |
9 | 1163 void filelist_free(GList *list) |
1 | 1164 { |
9 | 1165 GList *work; |
3 | 1166 |
9 | 1167 work = list; |
1168 while (work) | |
1 | 1169 { |
138 | 1170 file_data_unref((FileData *)work->data); |
1 | 1171 work = work->next; |
1172 } | |
1173 | |
9 | 1174 g_list_free(list); |
3 | 1175 } |
1176 | |
1 | 1177 |
138 | 1178 GList *filelist_copy(GList *list) |
1179 { | |
1180 GList *new_list = NULL; | |
1181 GList *work; | |
1182 | |
1183 work = list; | |
1184 while (work) | |
1185 { | |
1186 FileData *fd; | |
1187 | |
1188 fd = work->data; | |
1189 work = work->next; | |
1190 | |
1191 new_list = g_list_prepend(new_list, file_data_ref(fd)); | |
1192 } | |
1193 | |
1194 return g_list_reverse(new_list); | |
1195 } | |
1196 | |
1197 GList *filelist_from_path_list(GList *list) | |
1198 { | |
1199 GList *new_list = NULL; | |
1200 GList *work; | |
1201 | |
1202 work = list; | |
1203 while (work) | |
1204 { | |
1205 gchar *path; | |
1206 | |
1207 path = work->data; | |
1208 work = work->next; | |
1209 | |
1210 new_list = g_list_prepend(new_list, file_data_new_simple(path)); | |
1211 } | |
1212 | |
1213 return g_list_reverse(new_list); | |
1214 } | |
1215 | |
1216 GList *filelist_to_path_list(GList *list) | |
1217 { | |
1218 GList *new_list = NULL; | |
1219 GList *work; | |
1220 | |
1221 work = list; | |
1222 while (work) | |
1223 { | |
1224 FileData *fd; | |
1225 | |
1226 fd = work->data; | |
1227 work = work->next; | |
1228 | |
1229 new_list = g_list_prepend(new_list, g_strdup(fd->path)); | |
1230 } | |
1231 | |
1232 return g_list_reverse(new_list); | |
1233 } | |
1234 | |
1235 GList *filelist_filter(GList *list, gint is_dir_list) | |
1236 { | |
1237 GList *work; | |
1238 | |
1239 if (!is_dir_list && file_filter_disable && show_dot_files) return list; | |
1240 | |
1241 work = list; | |
1242 while (work) | |
1243 { | |
1244 FileData *fd = (FileData *)(work->data); | |
1245 const gchar *name = fd->name; | |
1246 | |
1247 if ((!show_dot_files && ishidden(name)) || | |
1248 (!is_dir_list && !filter_name_exists(name)) || | |
1249 (is_dir_list && name[0] == '.' && (strcmp(name, GQVIEW_CACHE_LOCAL_THUMB) == 0 || | |
1250 strcmp(name, GQVIEW_CACHE_LOCAL_METADATA) == 0)) ) | |
1251 { | |
1252 GList *link = work; | |
1253 work = work->next; | |
1254 list = g_list_remove_link(list, link); | |
1255 file_data_unref(fd); | |
1256 g_list_free(link); | |
1257 } | |
1258 else | |
1259 { | |
1260 work = work->next; | |
1261 } | |
1262 } | |
1263 | |
1264 return list; | |
1265 } | |
1266 | |
1267 /* | |
1268 *----------------------------------------------------------------------------- | |
1269 * filelist recursive | |
1270 *----------------------------------------------------------------------------- | |
1271 */ | |
1272 | |
1273 static gint filelist_sort_path_cb(gconstpointer a, gconstpointer b) | |
1274 { | |
1275 return CASE_SORT(((FileData *)a)->path, ((FileData *)b)->path); | |
1276 } | |
1277 | |
1278 GList *filelist_sort_path(GList *list) | |
1279 { | |
1280 return g_list_sort(list, filelist_sort_path_cb); | |
1281 } | |
1282 | |
1283 static void filelist_recursive_append(GList **list, GList *dirs) | |
1284 { | |
1285 GList *work; | |
1286 | |
1287 work = dirs; | |
1288 while (work) | |
1289 { | |
1290 FileData *fd = (FileData *)(work->data); | |
1291 const gchar *path = fd->path; | |
1292 GList *f = NULL; | |
1293 GList *d = NULL; | |
1294 | |
1295 if (filelist_read(path, &f, &d)) | |
1296 { | |
1297 f = filelist_filter(f, FALSE); | |
1298 f = filelist_sort_path(f); | |
1299 *list = g_list_concat(*list, f); | |
1300 | |
1301 d = filelist_filter(d, TRUE); | |
1302 d = filelist_sort_path(d); | |
1303 filelist_recursive_append(list, d); | |
1304 filelist_free(d); | |
1305 } | |
1306 | |
1307 work = work->next; | |
1308 } | |
1309 } | |
1310 | |
1311 GList *filelist_recursive(const gchar *path) | |
1312 { | |
1313 GList *list = NULL; | |
1314 GList *d = NULL; | |
1315 | |
1316 if (!filelist_read(path, &list, &d)) return NULL; | |
1317 list = filelist_filter(list, FALSE); | |
1318 list = filelist_sort_path(list); | |
1319 | |
1320 d = filelist_filter(d, TRUE); | |
1321 d = filelist_sort_path(d); | |
1322 filelist_recursive_append(&list, d); | |
1323 filelist_free(d); | |
1324 | |
1325 return list; | |
1326 } |