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