Mercurial > geeqie
annotate src/filelist.c @ 43:ee03f36e9e4b
Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
* format_raw.[ch]: New files to parse image data and exif offsets for
the raw camera formats.
* exif.c, image-load.c: Add support calls to format_raw.c functions
above.
* filelist.c: Add Fujifilm raw file extension to known formats.
* thumb_standard.c (thumb_loader_std_start): Check for existing
thumbnail file before checking for a failure mark.
* src/Makefile.am: Add format_raw.[ch].
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
##### an offical release when making enhancements and translation updates. #####
author | gqview |
---|---|
date | Mon, 16 May 2005 01:49:51 +0000 |
parents | 3263965d5f9e |
children | 7cfa60beda76 |
rev | line source |
---|---|
1 | 1 /* |
9 | 2 * GQview |
3 * (C) 2004 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" | |
18 #include "ui_fileops.h" | |
1 | 19 |
20 | |
21 /* | |
22 *----------------------------------------------------------------------------- | |
23 * file filtering | |
24 *----------------------------------------------------------------------------- | |
25 */ | |
26 | |
9 | 27 static GList *filter_list = NULL; |
28 static GList *extension_list = NULL; | |
29 | |
30 gint ishidden(const gchar *name) | |
1 | 31 { |
32 if (name[0] != '.') return FALSE; | |
33 if (name[1] == '\0' || (name[1] == '.' && name[2] == '\0')) return FALSE; | |
34 return TRUE; | |
35 } | |
36 | |
9 | 37 static FilterEntry *filter_entry_new(const gchar *key, const gchar *description, |
38 const gchar *extensions, gint enabled) | |
39 { | |
40 FilterEntry *fe; | |
41 | |
42 fe = g_new0(FilterEntry, 1); | |
43 fe->key = g_strdup(key); | |
44 fe->description = g_strdup(description); | |
45 fe->extensions = g_strdup(extensions); | |
46 fe->enabled = enabled; | |
47 | |
48 return fe; | |
49 } | |
50 | |
51 static void filter_entry_free(FilterEntry *fe) | |
52 { | |
53 if (!fe) return; | |
54 | |
55 g_free(fe->key); | |
56 g_free(fe->description); | |
57 g_free(fe->extensions); | |
58 g_free(fe); | |
59 } | |
60 | |
61 GList *filter_get_list(void) | |
62 { | |
63 return filter_list; | |
64 } | |
65 | |
66 void filter_remove_entry(FilterEntry *fe) | |
67 { | |
68 if (!g_list_find(filter_list, fe)) return; | |
69 | |
70 filter_list = g_list_remove(filter_list, fe); | |
71 filter_entry_free(fe); | |
72 } | |
73 | |
74 static gint filter_key_exists(const gchar *key) | |
75 { | |
76 GList *work; | |
77 | |
78 if (!key) return FALSE; | |
79 | |
80 work = filter_list; | |
81 while (work) | |
82 { | |
83 FilterEntry *fe = work->data; | |
84 work = work->next; | |
85 | |
86 if (strcmp(fe->key, key) == 0) return TRUE; | |
87 } | |
88 | |
89 return FALSE; | |
90 } | |
91 | |
92 void filter_add(const gchar *key, const gchar *description, const gchar *extensions, gint enabled) | |
93 { | |
94 filter_list = g_list_append(filter_list, filter_entry_new(key, description, extensions, enabled)); | |
95 } | |
96 | |
97 void filter_add_unique(const gchar *description, const gchar *extensions, gint enabled) | |
98 { | |
99 gchar *key; | |
100 gint n; | |
101 | |
102 key = g_strdup("user0"); | |
103 n = 1; | |
104 while (filter_key_exists(key)) | |
105 { | |
106 g_free(key); | |
107 if (n > 999) return; | |
108 key = g_strdup_printf("user%d", n); | |
109 n++; | |
110 } | |
111 | |
112 filter_add(key, description, extensions, enabled); | |
113 g_free(key); | |
114 } | |
115 | |
116 static void filter_add_if_missing(const gchar *key, const gchar *description, const gchar *extensions, gint enabled) | |
117 { | |
118 GList *work; | |
119 | |
120 if (!key) return; | |
121 | |
122 work = filter_list; | |
123 while (work) | |
124 { | |
125 FilterEntry *fe = work->data; | |
126 work = work->next; | |
127 if (fe->key && strcmp(fe->key, key) == 0) return; | |
128 } | |
129 | |
130 filter_add(key, description, extensions, enabled); | |
131 } | |
132 | |
133 void filter_reset(void) | |
1 | 134 { |
135 GList *work; | |
9 | 136 |
137 work = filter_list; | |
138 while (work) | |
139 { | |
140 FilterEntry *fe = work->data; | |
141 work = work->next; | |
142 filter_entry_free(fe); | |
143 } | |
144 | |
145 g_list_free(filter_list); | |
146 filter_list = NULL; | |
147 } | |
148 | |
149 void filter_add_defaults(void) | |
150 { | |
151 GSList *list, *work; | |
152 | |
153 list = gdk_pixbuf_get_formats(); | |
154 work = list; | |
155 while (work) | |
156 { | |
157 GdkPixbufFormat *format; | |
158 gchar *name; | |
159 gchar *desc; | |
160 gchar **extensions; | |
161 GString *filter = NULL; | |
162 gint i; | |
163 | |
164 format = work->data; | |
165 work = work->next; | |
166 | |
167 name = gdk_pixbuf_format_get_name(format); | |
168 desc = gdk_pixbuf_format_get_description(format); | |
169 extensions = gdk_pixbuf_format_get_extensions(format); | |
170 | |
171 i = 0; | |
172 while (extensions[i]) | |
173 { | |
174 if (!filter) | |
175 { | |
176 filter = g_string_new("."); | |
177 filter = g_string_append(filter, extensions[i]); | |
178 } | |
179 else | |
180 { | |
181 filter = g_string_append(filter, ";."); | |
182 filter = g_string_append(filter, extensions[i]); | |
183 } | |
184 i++; | |
185 } | |
186 | |
187 if (debug) printf("loader reported [%s] [%s] [%s]\n", name, desc, filter->str); | |
188 | |
189 filter_add_if_missing(name, desc, filter->str, TRUE); | |
190 | |
191 g_free(name); | |
192 g_free(desc); | |
193 g_strfreev(extensions); | |
194 g_string_free(filter, TRUE); | |
195 } | |
196 g_slist_free(list); | |
1 | 197 |
9 | 198 /* add defaults even if gdk-pixbuf does not have them, but disabled */ |
199 filter_add_if_missing("jpeg", "JPEG group", ".jpg;.jpeg;.jpe", FALSE); | |
200 filter_add_if_missing("png", "Portable Network Graphic", ".png", FALSE); | |
201 filter_add_if_missing("tiff", "Tiff", ".tif;.tiff", FALSE); | |
202 filter_add_if_missing("pnm", "Packed Pixel formats", ".pbm;.pgm;.pnm;.ppm", FALSE); | |
203 filter_add_if_missing("gif", "Graphics Interchange Format", ".gif", FALSE); | |
204 filter_add_if_missing("xbm", "X bitmap", ".xbm", FALSE); | |
205 filter_add_if_missing("xpm", "X pixmap", ".xpm", FALSE); | |
206 filter_add_if_missing("bmp", "Bitmap", ".bmp", FALSE); | |
207 filter_add_if_missing("ico", "Icon file", ".ico;.cur", FALSE); | |
208 filter_add_if_missing("ras", "Raster", ".ras", FALSE); | |
209 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
|
210 |
ee03f36e9e4b
Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
211 /* 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
|
212 * (see format_raw.c) |
ee03f36e9e4b
Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
213 */ |
ee03f36e9e4b
Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
214 filter_add_if_missing("raf", "Fujifilm raw camera format", ".raf", TRUE); |
9 | 215 } |
216 | |
217 static GList *filter_to_list(const gchar *extensions) | |
218 { | |
219 GList *list = NULL; | |
220 const gchar *p; | |
221 | |
222 if (!extensions) return NULL; | |
223 | |
224 p = extensions; | |
225 while (*p != '\0') | |
226 { | |
227 const gchar *b; | |
228 gint l = 0; | |
229 | |
230 b = p; | |
231 while (*p != '\0' && *p != ';') | |
232 { | |
233 p++; | |
234 l++; | |
235 } | |
236 list = g_list_append(list, g_strndup(b, l)); | |
237 if (*p == ';') p++; | |
238 } | |
239 | |
240 return list; | |
241 } | |
242 | |
243 void filter_rebuild(void) | |
244 { | |
245 GList *work; | |
246 | |
247 path_list_free(extension_list); | |
248 extension_list = NULL; | |
249 | |
250 work = filter_list; | |
251 while (work) | |
252 { | |
253 FilterEntry *fe; | |
254 | |
255 fe = work->data; | |
256 work = work->next; | |
257 | |
258 if (fe->enabled) | |
259 { | |
260 GList *ext; | |
261 | |
262 ext = filter_to_list(fe->extensions); | |
263 if (ext) extension_list = g_list_concat(extension_list, ext); | |
264 } | |
265 } | |
266 } | |
267 | |
268 gint filter_name_exists(const gchar *name) | |
269 { | |
270 GList *work; | |
271 if (!extension_list || file_filter_disable) return TRUE; | |
272 | |
273 work = extension_list; | |
1 | 274 while (work) |
275 { | |
276 gchar *filter = work->data; | |
277 gint lf = strlen(filter); | |
278 gint ln = strlen(name); | |
279 if (ln >= lf) | |
280 { | |
281 if (strncasecmp(name + ln - lf, filter, lf) == 0) return TRUE; | |
282 } | |
283 work = work->next; | |
284 } | |
285 | |
286 return FALSE; | |
287 } | |
288 | |
9 | 289 void filter_write_list(FILE *f) |
1 | 290 { |
9 | 291 GList *work; |
292 | |
293 work = filter_list; | |
294 while (work) | |
295 { | |
296 FilterEntry *fe = work->data; | |
297 work = work->next; | |
298 | |
299 fprintf(f, "filter_ext: \"%s%s\" \"%s\" \"%s\"\n", (fe->enabled) ? "" : "#", | |
300 fe->key, fe->extensions, | |
301 (fe->description) ? fe->description : ""); | |
302 } | |
1 | 303 } |
304 | |
9 | 305 void filter_parse(const gchar *text) |
1 | 306 { |
9 | 307 const gchar *p; |
308 gchar *key; | |
309 gchar *ext; | |
310 gchar *desc; | |
311 gint enabled = TRUE; | |
312 | |
313 if (!text || text[0] != '"') return; | |
314 | |
315 key = quoted_value(text); | |
316 if (!key) return; | |
317 | |
318 p = text; | |
319 p++; | |
320 while (*p != '"' && *p != '\0') p++; | |
321 if (*p != '"') | |
322 { | |
323 g_free(key); | |
324 return; | |
325 } | |
326 p++; | |
327 while (*p != '"' && *p != '\0') p++; | |
328 if (*p != '"') | |
1 | 329 { |
9 | 330 g_free(key); |
331 return; | |
332 } | |
333 | |
334 ext = quoted_value(p); | |
335 | |
336 p++; | |
337 while (*p != '"' && *p != '\0') p++; | |
338 if (*p == '"') p++; | |
339 while (*p != '"' && *p != '\0') p++; | |
340 | |
341 if (*p == '"') | |
342 { | |
343 desc = quoted_value(p); | |
344 } | |
345 else | |
346 { | |
347 desc = NULL; | |
348 } | |
349 | |
350 if (key && key[0] == '#') | |
351 { | |
352 gchar *tmp; | |
353 tmp = g_strdup(key + 1); | |
354 g_free(key); | |
355 key = tmp; | |
356 | |
357 enabled = FALSE; | |
1 | 358 } |
359 | |
9 | 360 if (key && strlen(key) > 0 && ext) filter_add(key, desc, ext, enabled); |
361 | |
362 g_free(key); | |
363 g_free(ext); | |
364 g_free(desc); | |
365 } | |
1 | 366 |
9 | 367 GList *path_list_filter(GList *list, gint is_dir_list) |
368 { | |
369 GList *work; | |
370 | |
371 if (!is_dir_list && file_filter_disable && show_dot_files) return list; | |
372 | |
373 work = list; | |
374 while (work) | |
1 | 375 { |
9 | 376 gchar *name = work->data; |
377 const gchar *base; | |
378 | |
379 base = filename_from_path(name); | |
380 | |
381 if ((!show_dot_files && ishidden(base)) || | |
382 (!is_dir_list && !filter_name_exists(base)) || | |
383 (is_dir_list && base[0] == '.' && (strcmp(base, GQVIEW_CACHE_LOCAL_THUMB) == 0 || | |
384 strcmp(base, GQVIEW_CACHE_LOCAL_METADATA) == 0)) ) | |
385 { | |
386 GList *link = work; | |
387 work = work->next; | |
388 list = g_list_remove_link(list, link); | |
389 g_free(name); | |
390 g_list_free(link); | |
391 } | |
392 else | |
1 | 393 { |
9 | 394 work = work->next; |
1 | 395 } |
396 } | |
9 | 397 |
398 return list; | |
399 } | |
400 | |
401 /* | |
402 *----------------------------------------------------------------------------- | |
403 * path list recursive | |
404 *----------------------------------------------------------------------------- | |
405 */ | |
406 | |
407 static gint path_list_sort_cb(gconstpointer a, gconstpointer b) | |
408 { | |
409 return CASE_SORT((gchar *)a, (gchar *)b); | |
410 } | |
411 | |
412 GList *path_list_sort(GList *list) | |
413 { | |
414 return g_list_sort(list, path_list_sort_cb); | |
415 } | |
416 | |
417 static void path_list_recursive_append(GList **list, GList *dirs) | |
418 { | |
419 GList *work; | |
420 | |
421 work = dirs; | |
422 while (work) | |
423 { | |
424 const gchar *path = work->data; | |
425 GList *f = NULL; | |
426 GList *d = NULL; | |
427 | |
428 if (path_list(path, &f, &d)) | |
429 { | |
430 f = path_list_filter(f, FALSE); | |
431 f = path_list_sort(f); | |
432 *list = g_list_concat(*list, f); | |
433 | |
434 d = path_list_filter(d, TRUE); | |
435 d = path_list_sort(d); | |
436 path_list_recursive_append(list, d); | |
437 g_list_free(d); | |
438 } | |
439 | |
440 work = work->next; | |
441 } | |
442 } | |
443 | |
444 GList *path_list_recursive(const gchar *path) | |
445 { | |
446 GList *list = NULL; | |
447 GList *d = NULL; | |
448 | |
449 if (!path_list(path, &list, &d)) return NULL; | |
450 list = path_list_filter(list, FALSE); | |
451 list = path_list_sort(list); | |
452 | |
453 d = path_list_filter(d, TRUE); | |
454 d = path_list_sort(d); | |
455 path_list_recursive_append(&list, d); | |
456 path_list_free(d); | |
457 | |
458 return list; | |
1 | 459 } |
460 | |
461 /* | |
462 *----------------------------------------------------------------------------- | |
9 | 463 * text conversion utils |
1 | 464 *----------------------------------------------------------------------------- |
465 */ | |
466 | |
9 | 467 gchar *text_from_size(gint64 size) |
1 | 468 { |
9 | 469 gchar *a, *b; |
470 gchar *s, *d; | |
471 gint l, n, i; | |
472 | |
473 /* what I would like to use is printf("%'d", size) | |
474 * BUT: not supported on every libc :( | |
475 */ | |
476 if (size > G_MAXUINT) | |
477 { | |
478 /* the %lld conversion is not valid in all libcs, so use a simple work-around */ | |
479 a = g_strdup_printf("%d%09d", (guint)(size / 1000000000), (guint)(size % 1000000000)); | |
480 } | |
481 else | |
482 { | |
483 a = g_strdup_printf("%d", (guint)size); | |
484 } | |
485 l = strlen(a); | |
486 n = (l - 1)/ 3; | |
487 if (n < 1) return a; | |
488 | |
489 b = g_new(gchar, l + n + 1); | |
490 | |
491 s = a; | |
492 d = b; | |
493 i = l - n * 3; | |
494 while (*s != '\0') | |
495 { | |
496 if (i < 1) | |
497 { | |
498 i = 3; | |
499 *d = ','; | |
500 d++; | |
501 } | |
502 | |
503 *d = *s; | |
504 s++; | |
505 d++; | |
506 i--; | |
507 } | |
508 *d = '\0'; | |
509 | |
510 g_free(a); | |
511 return b; | |
512 } | |
513 | |
514 gchar *text_from_size_abrev(gint64 size) | |
515 { | |
516 if (size < (gint64)1024) | |
517 { | |
518 return g_strdup_printf(_("%d bytes"), (gint)size); | |
519 } | |
520 if (size < (gint64)1048576) | |
521 { | |
15
3263965d5f9e
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
522 return g_strdup_printf(_("%.1f K"), (double)size / 1024.0); |
9 | 523 } |
524 if (size < (gint64)1073741824) | |
525 { | |
15
3263965d5f9e
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
526 return g_strdup_printf(_("%.1f MB"), (double)size / 1048576.0); |
9 | 527 } |
528 | |
15
3263965d5f9e
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
529 /* 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
|
530 size /= 1048576; |
3263965d5f9e
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
531 return g_strdup_printf(_("%.1f GB"), (double)size / 1024.0); |
9 | 532 } |
533 | |
534 /* note: returned string is valid until next call to text_from_time() */ | |
535 const gchar *text_from_time(time_t t) | |
536 { | |
537 static gchar *ret = NULL; | |
538 gchar buf[128]; | |
539 gint buflen; | |
540 struct tm *btime; | |
541 GError *error = NULL; | |
542 | |
543 btime = localtime(&t); | |
544 | |
545 /* the %x warning about 2 digit years is not an error */ | |
546 buflen = strftime(buf, sizeof(buf), "%x %H:%M", btime); | |
547 if (buflen < 1) return ""; | |
548 | |
549 g_free(ret); | |
550 ret = g_locale_to_utf8(buf, buflen, NULL, NULL, &error); | |
551 if (error) | |
552 { | |
553 printf("Error converting locale strftime to UTF-8: %s\n", error->message); | |
554 g_error_free(error); | |
555 return ""; | |
556 } | |
557 | |
558 return ret; | |
1 | 559 } |
560 | |
9 | 561 /* |
562 *----------------------------------------------------------------------------- | |
563 * file info struct | |
564 *----------------------------------------------------------------------------- | |
565 */ | |
566 | |
567 FileData *file_data_new(const gchar *path, struct stat *st) | |
568 { | |
569 FileData *fd; | |
570 | |
571 fd = g_new0(FileData, 1); | |
572 fd->path = path_to_utf8(path); | |
573 fd->name = filename_from_path(fd->path); | |
574 fd->size = st->st_size; | |
575 fd->date = st->st_mtime; | |
576 fd->pixbuf = NULL; | |
577 | |
578 return fd; | |
579 } | |
580 | |
581 FileData *file_data_new_simple(const gchar *path) | |
582 { | |
583 FileData *fd; | |
584 struct stat st; | |
585 | |
586 fd = g_new0(FileData, 1); | |
587 fd->path = g_strdup(path); | |
588 fd->name = filename_from_path(fd->path); | |
589 | |
590 if (stat_utf8(fd->path, &st)) | |
591 { | |
592 fd->size = st.st_size; | |
593 fd->date = st.st_mtime; | |
594 } | |
595 | |
596 fd->pixbuf = NULL; | |
597 | |
598 return fd; | |
599 } | |
600 | |
601 void file_data_free(FileData *fd) | |
602 { | |
603 g_free(fd->path); | |
604 if (fd->pixbuf) g_object_unref(fd->pixbuf); | |
605 g_free(fd); | |
606 } | |
607 | |
608 /* | |
609 *----------------------------------------------------------------------------- | |
610 * load file list | |
611 *----------------------------------------------------------------------------- | |
612 */ | |
613 | |
614 static SortType filelist_sort_method = SORT_NONE; | |
615 static gint filelist_sort_ascend = TRUE; | |
616 | |
617 static gint sort_file_cb(void *a, void *b) | |
618 { | |
619 FileData *fa = a; | |
620 FileData *fb = b; | |
621 | |
622 if (!filelist_sort_ascend) | |
623 { | |
624 fa = b; | |
625 fb = a; | |
626 } | |
627 | |
628 switch (filelist_sort_method) | |
629 { | |
630 case SORT_SIZE: | |
631 if (fa->size < fb->size) return -1; | |
632 if (fa->size > fb->size) return 1; | |
633 return 0; | |
634 break; | |
635 case SORT_TIME: | |
636 if (fa->date < fb->date) return -1; | |
637 if (fa->date > fb->date) return 1; | |
638 return 0; | |
639 break; | |
640 #ifdef HAVE_STRVERSCMP | |
641 case SORT_NUMBER: | |
642 return strverscmp(fa->name, fb->name); | |
643 break; | |
644 #endif | |
645 case SORT_NAME: | |
646 default: | |
647 return CASE_SORT(fa->name, fb->name); | |
648 break; | |
649 } | |
650 } | |
651 | |
652 GList *filelist_sort(GList *list, SortType method, gint ascend) | |
653 { | |
654 filelist_sort_method = method; | |
655 filelist_sort_ascend = ascend; | |
656 return g_list_sort(list, (GCompareFunc) sort_file_cb); | |
657 } | |
658 | |
659 GList *filelist_insert_sort(GList *list, FileData *fd, SortType method, gint ascend) | |
660 { | |
661 filelist_sort_method = method; | |
662 filelist_sort_ascend = ascend; | |
663 return g_list_insert_sorted(list, fd, (GCompareFunc) sort_file_cb); | |
664 } | |
665 | |
666 gint filelist_read(const gchar *path, GList **files, GList **dirs) | |
1 | 667 { |
668 DIR *dp; | |
669 struct dirent *dir; | |
670 struct stat ent_sbuf; | |
9 | 671 gchar *pathl; |
672 GList *dlist; | |
673 GList *flist; | |
1 | 674 |
9 | 675 dlist = NULL; |
676 flist = NULL; | |
677 | |
678 pathl = path_from_utf8(path); | |
679 if (!pathl || (dp = opendir(pathl)) == NULL) | |
1 | 680 { |
9 | 681 g_free(pathl); |
682 if (files) *files = NULL; | |
683 if (dirs) *dirs = NULL; | |
684 return FALSE; | |
1 | 685 } |
686 | |
9 | 687 /* root dir fix */ |
688 if (pathl[0] == '/' && pathl[1] == '\0') | |
689 { | |
690 g_free(pathl); | |
691 pathl = g_strdup(""); | |
692 } | |
1 | 693 |
694 while ((dir = readdir(dp)) != NULL) | |
695 { | |
9 | 696 gchar *name = dir->d_name; |
697 if (show_dot_files || !ishidden(name)) | |
1 | 698 { |
9 | 699 gchar *filepath = g_strconcat(pathl, "/", name, NULL); |
700 if (stat(filepath, &ent_sbuf) >= 0) | |
1 | 701 { |
9 | 702 if (S_ISDIR(ent_sbuf.st_mode)) |
1 | 703 { |
9 | 704 /* we ignore the .thumbnails dir for cleanliness */ |
705 if ((dirs) && | |
706 !(name[0] == '.' && (name[1] == '\0' || (name[1] == '.' && name[2] == '\0'))) && | |
707 strcmp(name, GQVIEW_CACHE_LOCAL_THUMB) != 0 && | |
708 strcmp(name, GQVIEW_CACHE_LOCAL_METADATA) != 0) | |
709 { | |
710 dlist = g_list_prepend(dlist, file_data_new(filepath, &ent_sbuf)); | |
711 } | |
1 | 712 } |
713 else | |
714 { | |
9 | 715 if ((files) && filter_name_exists(name)) |
716 { | |
717 flist = g_list_prepend(flist, file_data_new(filepath, &ent_sbuf)); | |
718 } | |
1 | 719 } |
720 } | |
9 | 721 g_free(filepath); |
1 | 722 } |
723 } | |
724 | |
725 closedir(dp); | |
726 | |
9 | 727 g_free(pathl); |
1 | 728 |
9 | 729 if (dirs) *dirs = dlist; |
730 if (files) *files = flist; | |
1 | 731 |
9 | 732 return TRUE; |
1 | 733 } |
734 | |
9 | 735 void filelist_free(GList *list) |
1 | 736 { |
9 | 737 GList *work; |
3 | 738 |
9 | 739 work = list; |
740 while (work) | |
1 | 741 { |
9 | 742 file_data_free((FileData *)work->data); |
1 | 743 work = work->next; |
744 } | |
745 | |
9 | 746 g_list_free(list); |
3 | 747 } |
748 | |
1 | 749 |