Mercurial > geeqie.yaz
annotate src/filefilter.c @ 1238:947e603a52c6
simplified metadata interface, dropped metadata_read,
fixes for older exiv2 versions
author | nadvornik |
---|---|
date | Sat, 10 Jan 2009 20:40:37 +0000 |
parents | 052f26dbe8cf |
children | 254b09942e68 |
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" |
586 | 15 #include "filefilter.h" |
1 | 16 |
9 | 17 #include "cache.h" |
1023
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
781
diff
changeset
|
18 #include "misc.h" |
307
667e49f52168
Move secure save code to its own files: secure_save.{c,h}.
zas_
parents:
283
diff
changeset
|
19 #include "secure_save.h" |
79
528e3432e0c0
Thu Oct 19 07:23:37 2006 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
20 #include "thumb_standard.h" |
9 | 21 #include "ui_fileops.h" |
1 | 22 |
23 /* | |
24 *----------------------------------------------------------------------------- | |
25 * file filtering | |
26 *----------------------------------------------------------------------------- | |
27 */ | |
28 | |
9 | 29 static GList *filter_list = NULL; |
30 static GList *extension_list = NULL; | |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
31 static GList *sidecar_ext_list = NULL; |
9 | 32 |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
33 static GList *file_class_extension_list[FILE_FORMAT_CLASSES]; |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
34 |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
35 |
9 | 36 gint ishidden(const gchar *name) |
1 | 37 { |
38 if (name[0] != '.') return FALSE; | |
39 if (name[1] == '\0' || (name[1] == '.' && name[2] == '\0')) return FALSE; | |
40 return TRUE; | |
41 } | |
42 | |
9 | 43 static FilterEntry *filter_entry_new(const gchar *key, const gchar *description, |
736 | 44 const gchar *extensions, FileFormatClass file_class, gboolean enabled) |
9 | 45 { |
46 FilterEntry *fe; | |
47 | |
48 fe = g_new0(FilterEntry, 1); | |
49 fe->key = g_strdup(key); | |
50 fe->description = g_strdup(description); | |
51 fe->extensions = g_strdup(extensions); | |
52 fe->enabled = enabled; | |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
53 fe->file_class = file_class; |
442 | 54 |
9 | 55 return fe; |
56 } | |
57 | |
58 static void filter_entry_free(FilterEntry *fe) | |
59 { | |
60 if (!fe) return; | |
61 | |
62 g_free(fe->key); | |
63 g_free(fe->description); | |
64 g_free(fe->extensions); | |
65 g_free(fe); | |
66 } | |
67 | |
68 GList *filter_get_list(void) | |
69 { | |
70 return filter_list; | |
71 } | |
72 | |
73 void filter_remove_entry(FilterEntry *fe) | |
74 { | |
75 if (!g_list_find(filter_list, fe)) return; | |
76 | |
77 filter_list = g_list_remove(filter_list, fe); | |
78 filter_entry_free(fe); | |
79 } | |
80 | |
743
77ff94c0490a
Try to load a system-wide rc file if any, before per-user rc file.
zas_
parents:
736
diff
changeset
|
81 static FilterEntry *filter_get_by_key(const gchar *key) |
9 | 82 { |
83 GList *work; | |
84 | |
743
77ff94c0490a
Try to load a system-wide rc file if any, before per-user rc file.
zas_
parents:
736
diff
changeset
|
85 if (!key) return NULL; |
9 | 86 |
87 work = filter_list; | |
88 while (work) | |
89 { | |
90 FilterEntry *fe = work->data; | |
91 work = work->next; | |
92 | |
743
77ff94c0490a
Try to load a system-wide rc file if any, before per-user rc file.
zas_
parents:
736
diff
changeset
|
93 if (strcmp(fe->key, key) == 0) return fe; |
9 | 94 } |
95 | |
743
77ff94c0490a
Try to load a system-wide rc file if any, before per-user rc file.
zas_
parents:
736
diff
changeset
|
96 return NULL; |
77ff94c0490a
Try to load a system-wide rc file if any, before per-user rc file.
zas_
parents:
736
diff
changeset
|
97 } |
77ff94c0490a
Try to load a system-wide rc file if any, before per-user rc file.
zas_
parents:
736
diff
changeset
|
98 |
77ff94c0490a
Try to load a system-wide rc file if any, before per-user rc file.
zas_
parents:
736
diff
changeset
|
99 static gint filter_key_exists(const gchar *key) |
77ff94c0490a
Try to load a system-wide rc file if any, before per-user rc file.
zas_
parents:
736
diff
changeset
|
100 { |
77ff94c0490a
Try to load a system-wide rc file if any, before per-user rc file.
zas_
parents:
736
diff
changeset
|
101 return (filter_get_by_key(key) == NULL ? FALSE : TRUE); |
9 | 102 } |
103 | |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
104 void filter_add(const gchar *key, const gchar *description, const gchar *extensions, FileFormatClass file_class, gint enabled) |
9 | 105 { |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
106 filter_list = g_list_append(filter_list, filter_entry_new(key, description, extensions, file_class, enabled)); |
9 | 107 } |
108 | |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
109 void filter_add_unique(const gchar *description, const gchar *extensions, FileFormatClass file_class, gint enabled) |
9 | 110 { |
111 gchar *key; | |
736 | 112 guint n; |
9 | 113 |
114 key = g_strdup("user0"); | |
115 n = 1; | |
116 while (filter_key_exists(key)) | |
117 { | |
118 g_free(key); | |
119 if (n > 999) return; | |
120 key = g_strdup_printf("user%d", n); | |
121 n++; | |
122 } | |
123 | |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
124 filter_add(key, description, extensions, file_class, enabled); |
9 | 125 g_free(key); |
126 } | |
127 | |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
128 static void filter_add_if_missing(const gchar *key, const gchar *description, const gchar *extensions, FileFormatClass file_class, gint enabled) |
9 | 129 { |
130 GList *work; | |
131 | |
132 if (!key) return; | |
133 | |
134 work = filter_list; | |
135 while (work) | |
136 { | |
137 FilterEntry *fe = work->data; | |
138 work = work->next; | |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
139 if (fe->key && strcmp(fe->key, key) == 0) |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
140 { |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
141 if (fe->file_class == FORMAT_CLASS_UNKNOWN) |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
142 fe->file_class = file_class; /* for compatibility */ |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
143 return; |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
144 } |
9 | 145 } |
146 | |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
147 filter_add(key, description, extensions, file_class, enabled); |
9 | 148 } |
149 | |
150 void filter_reset(void) | |
1 | 151 { |
152 GList *work; | |
9 | 153 |
154 work = filter_list; | |
155 while (work) | |
156 { | |
157 FilterEntry *fe = work->data; | |
158 work = work->next; | |
159 filter_entry_free(fe); | |
160 } | |
161 | |
162 g_list_free(filter_list); | |
163 filter_list = NULL; | |
164 } | |
165 | |
166 void filter_add_defaults(void) | |
167 { | |
168 GSList *list, *work; | |
169 | |
170 list = gdk_pixbuf_get_formats(); | |
171 work = list; | |
172 while (work) | |
173 { | |
174 GdkPixbufFormat *format; | |
175 gchar *name; | |
176 gchar *desc; | |
177 gchar **extensions; | |
178 GString *filter = NULL; | |
736 | 179 guint i; |
442 | 180 |
9 | 181 format = work->data; |
182 work = work->next; | |
183 | |
184 name = gdk_pixbuf_format_get_name(format); | |
185 desc = gdk_pixbuf_format_get_description(format); | |
186 extensions = gdk_pixbuf_format_get_extensions(format); | |
187 | |
188 i = 0; | |
189 while (extensions[i]) | |
190 { | |
191 if (!filter) | |
192 { | |
193 filter = g_string_new("."); | |
194 filter = g_string_append(filter, extensions[i]); | |
195 } | |
196 else | |
197 { | |
198 filter = g_string_append(filter, ";."); | |
199 filter = g_string_append(filter, extensions[i]); | |
200 } | |
201 i++; | |
202 } | |
203 | |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
495
diff
changeset
|
204 DEBUG_1("loader reported [%s] [%s] [%s]", name, desc, filter->str); |
9 | 205 |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
206 filter_add_if_missing(name, desc, filter->str, FORMAT_CLASS_IMAGE, TRUE); |
9 | 207 |
208 g_free(name); | |
209 g_free(desc); | |
210 g_strfreev(extensions); | |
211 g_string_free(filter, TRUE); | |
212 } | |
213 g_slist_free(list); | |
1 | 214 |
9 | 215 /* 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
|
216 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
|
217 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
|
218 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
|
219 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
|
220 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
|
221 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
|
222 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
|
223 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
|
224 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
|
225 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
|
226 filter_add_if_missing("svg", "Scalable Vector Graphics", ".svg", FORMAT_CLASS_IMAGE, FALSE); |
442 | 227 |
202
f95654aeec4b
added all possible raw extensions that I could find
nadvornik
parents:
196
diff
changeset
|
228 /* non-image files that might be desirable to show */ |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
229 filter_add_if_missing("xmp", "XMP sidecar", ".xmp", FORMAT_CLASS_META, TRUE); |
781
2d2cca2bceb0
Replace hardcoded collection filename extension by a macro (GQ_COLLECTION_EXT).
zas_
parents:
743
diff
changeset
|
230 filter_add_if_missing("gqv", GQ_APPNAME " image collection", GQ_COLLECTION_EXT, FORMAT_CLASS_META, TRUE); |
43
ee03f36e9e4b
Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
231 |
ee03f36e9e4b
Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
232 /* 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
|
233 * (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
|
234 */ |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
235 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
|
236 filter_add_if_missing("crw", "Canon raw format", ".crw;.cr2", FORMAT_CLASS_RAWIMAGE, TRUE); |
1190
a4ea0c74a6e2
File filters cleanup: add .pef .dng and .arw extensions to default sidecar extensions list, add .k25 in Kodak raw extensions, simplify and optimize sidecar_ext_parse().
zas_
parents:
1177
diff
changeset
|
237 filter_add_if_missing("kdc", "Kodak raw format", ".kdc;.dcr;.k25", FORMAT_CLASS_RAWIMAGE, TRUE); |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
238 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
|
239 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
|
240 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
|
241 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
|
242 filter_add_if_missing("orf", "Olympus raw format", ".orf", FORMAT_CLASS_RAWIMAGE, TRUE); |
277 | 243 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
|
244 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
|
245 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
|
246 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
|
247 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
|
248 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
|
249 filter_add_if_missing("erf", "Epson raw format", ".erf", FORMAT_CLASS_RAWIMAGE, TRUE); |
9 | 250 } |
251 | |
147
b2266996fa83
added possibility to specify prefered file type for external commands
nadvornik
parents:
146
diff
changeset
|
252 GList *filter_to_list(const gchar *extensions) |
9 | 253 { |
254 GList *list = NULL; | |
255 const gchar *p; | |
256 | |
257 if (!extensions) return NULL; | |
258 | |
259 p = extensions; | |
260 while (*p != '\0') | |
261 { | |
262 const gchar *b; | |
1235 | 263 gchar *ext; |
1229
878718372aca
sidecar files grouping was made case-insensitive
nadvornik
parents:
1207
diff
changeset
|
264 gint file_class = -1; |
736 | 265 guint l = 0; |
9 | 266 |
267 b = p; | |
268 while (*p != '\0' && *p != ';') | |
269 { | |
270 p++; | |
271 l++; | |
272 } | |
1229
878718372aca
sidecar files grouping was made case-insensitive
nadvornik
parents:
1207
diff
changeset
|
273 |
878718372aca
sidecar files grouping was made case-insensitive
nadvornik
parents:
1207
diff
changeset
|
274 ext = g_strndup(b, l); |
878718372aca
sidecar files grouping was made case-insensitive
nadvornik
parents:
1207
diff
changeset
|
275 |
878718372aca
sidecar files grouping was made case-insensitive
nadvornik
parents:
1207
diff
changeset
|
276 if (strcasecmp(ext, "%image") == 0) file_class = FORMAT_CLASS_IMAGE; |
878718372aca
sidecar files grouping was made case-insensitive
nadvornik
parents:
1207
diff
changeset
|
277 else if (strcasecmp(ext, "%raw") == 0) file_class = FORMAT_CLASS_RAWIMAGE; |
878718372aca
sidecar files grouping was made case-insensitive
nadvornik
parents:
1207
diff
changeset
|
278 else if (strcasecmp(ext, "%meta") == 0) file_class = FORMAT_CLASS_META; |
878718372aca
sidecar files grouping was made case-insensitive
nadvornik
parents:
1207
diff
changeset
|
279 |
878718372aca
sidecar files grouping was made case-insensitive
nadvornik
parents:
1207
diff
changeset
|
280 if (file_class == -1) |
878718372aca
sidecar files grouping was made case-insensitive
nadvornik
parents:
1207
diff
changeset
|
281 { |
878718372aca
sidecar files grouping was made case-insensitive
nadvornik
parents:
1207
diff
changeset
|
282 list = g_list_append(list, ext); |
878718372aca
sidecar files grouping was made case-insensitive
nadvornik
parents:
1207
diff
changeset
|
283 } |
878718372aca
sidecar files grouping was made case-insensitive
nadvornik
parents:
1207
diff
changeset
|
284 else |
878718372aca
sidecar files grouping was made case-insensitive
nadvornik
parents:
1207
diff
changeset
|
285 { |
878718372aca
sidecar files grouping was made case-insensitive
nadvornik
parents:
1207
diff
changeset
|
286 list = g_list_concat(list, string_list_copy(file_class_extension_list[file_class])); |
878718372aca
sidecar files grouping was made case-insensitive
nadvornik
parents:
1207
diff
changeset
|
287 g_free(ext); |
878718372aca
sidecar files grouping was made case-insensitive
nadvornik
parents:
1207
diff
changeset
|
288 } |
878718372aca
sidecar files grouping was made case-insensitive
nadvornik
parents:
1207
diff
changeset
|
289 |
9 | 290 if (*p == ';') p++; |
291 } | |
292 | |
293 return list; | |
294 } | |
295 | |
296 void filter_rebuild(void) | |
297 { | |
298 GList *work; | |
736 | 299 guint i; |
9 | 300 |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
301 string_list_free(extension_list); |
9 | 302 extension_list = NULL; |
303 | |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
304 for (i = 0; i < FILE_FORMAT_CLASSES; i++) |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
305 { |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
306 string_list_free(file_class_extension_list[i]); |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
307 file_class_extension_list[i] = NULL; |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
308 } |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
309 |
9 | 310 work = filter_list; |
311 while (work) | |
312 { | |
313 FilterEntry *fe; | |
314 | |
315 fe = work->data; | |
316 work = work->next; | |
317 | |
318 if (fe->enabled) | |
319 { | |
320 GList *ext; | |
321 | |
322 ext = filter_to_list(fe->extensions); | |
323 if (ext) extension_list = g_list_concat(extension_list, ext); | |
442 | 324 |
1177
5a20c47e7a14
Fix up unsigned expression always true/false warnings.
zas_
parents:
1055
diff
changeset
|
325 if (fe->file_class < FILE_FORMAT_CLASSES) |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
326 { |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
327 ext = filter_to_list(fe->extensions); |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
328 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
|
329 } |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
330 else |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
331 { |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
332 log_printf("WARNING: invalid file class %d\n", fe->file_class); |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
333 } |
9 | 334 } |
335 } | |
1229
878718372aca
sidecar files grouping was made case-insensitive
nadvornik
parents:
1207
diff
changeset
|
336 |
878718372aca
sidecar files grouping was made case-insensitive
nadvornik
parents:
1207
diff
changeset
|
337 sidecar_ext_parse(options->sidecar.ext, FALSE); /* this must be updated after changed file extensions */ |
9 | 338 } |
339 | |
340 gint filter_name_exists(const gchar *name) | |
341 { | |
342 GList *work; | |
736 | 343 guint ln; |
215 | 344 |
332 | 345 if (!extension_list || options->file_filter.disable) return TRUE; |
9 | 346 |
215 | 347 ln = strlen(name); |
9 | 348 work = extension_list; |
1 | 349 while (work) |
350 { | |
351 gchar *filter = work->data; | |
736 | 352 guint lf = strlen(filter); |
215 | 353 |
1 | 354 if (ln >= lf) |
355 { | |
605
651ae2be1031
Use g_ascii_strncasecmp() instead of strncasecmp() where applicable.
zas_
parents:
587
diff
changeset
|
356 /* FIXME: utf8 */ |
1 | 357 if (strncasecmp(name + ln - lf, filter, lf) == 0) return TRUE; |
358 } | |
359 work = work->next; | |
360 } | |
361 | |
362 return FALSE; | |
363 } | |
364 | |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
365 gint filter_file_class(const gchar *name, FileFormatClass file_class) |
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 GList *work; |
736 | 368 guint ln; |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
369 |
1177
5a20c47e7a14
Fix up unsigned expression always true/false warnings.
zas_
parents:
1055
diff
changeset
|
370 if (file_class >= FILE_FORMAT_CLASSES) |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
371 { |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
372 log_printf("WARNING: invalid file class %d\n", file_class); |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
373 return FALSE; |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
374 } |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
375 |
215 | 376 ln = strlen(name); |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
377 work = file_class_extension_list[file_class]; |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
378 while (work) |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
379 { |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
380 gchar *filter = work->data; |
736 | 381 guint lf = strlen(filter); |
215 | 382 |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
383 if (ln >= lf) |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
384 { |
605
651ae2be1031
Use g_ascii_strncasecmp() instead of strncasecmp() where applicable.
zas_
parents:
587
diff
changeset
|
385 /* FIXME: utf8 */ |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
386 if (strncasecmp(name + ln - lf, filter, lf) == 0) return TRUE; |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
387 } |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
388 work = work->next; |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
389 } |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
390 |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
391 return FALSE; |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
392 } |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
393 |
276 | 394 void filter_write_list(SecureSaveInfo *ssi) |
1 | 395 { |
9 | 396 GList *work; |
397 | |
398 work = filter_list; | |
399 while (work) | |
400 { | |
401 FilterEntry *fe = work->data; | |
402 work = work->next; | |
442 | 403 |
217 | 404 gchar *extensions = escquote_value(fe->extensions); |
405 gchar *description = escquote_value(fe->description); | |
9 | 406 |
370 | 407 secure_fprintf(ssi, "file_filter.ext: \"%s%s\" %s %s %d\n", |
276 | 408 (fe->enabled) ? "" : "#", |
370 | 409 fe->key, extensions, description, fe->file_class); |
217 | 410 g_free(extensions); |
411 g_free(description); | |
9 | 412 } |
1 | 413 } |
414 | |
9 | 415 void filter_parse(const gchar *text) |
1 | 416 { |
9 | 417 const gchar *p; |
418 gchar *key; | |
419 gchar *ext; | |
420 gchar *desc; | |
421 gint enabled = TRUE; | |
736 | 422 guint file_class; |
9 | 423 |
424 if (!text || text[0] != '"') return; | |
425 | |
217 | 426 key = quoted_value(text, &p); |
9 | 427 if (!key) return; |
428 | |
217 | 429 ext = quoted_value(p, &p); |
430 desc = quoted_value(p, &p); | |
442 | 431 |
736 | 432 file_class = strtoul(p, NULL, 10); |
442 | 433 |
736 | 434 if (file_class >= FILE_FORMAT_CLASSES) file_class = FORMAT_CLASS_UNKNOWN; |
9 | 435 |
436 if (key && key[0] == '#') | |
437 { | |
438 gchar *tmp; | |
439 tmp = g_strdup(key + 1); | |
440 g_free(key); | |
441 key = tmp; | |
442 | |
443 enabled = FALSE; | |
1 | 444 } |
445 | |
743
77ff94c0490a
Try to load a system-wide rc file if any, before per-user rc file.
zas_
parents:
736
diff
changeset
|
446 if (key && strlen(key) > 0 && ext) |
77ff94c0490a
Try to load a system-wide rc file if any, before per-user rc file.
zas_
parents:
736
diff
changeset
|
447 { |
77ff94c0490a
Try to load a system-wide rc file if any, before per-user rc file.
zas_
parents:
736
diff
changeset
|
448 FilterEntry *fe = filter_get_by_key(key); |
77ff94c0490a
Try to load a system-wide rc file if any, before per-user rc file.
zas_
parents:
736
diff
changeset
|
449 |
77ff94c0490a
Try to load a system-wide rc file if any, before per-user rc file.
zas_
parents:
736
diff
changeset
|
450 if (fe != NULL) filter_remove_entry(fe); |
77ff94c0490a
Try to load a system-wide rc file if any, before per-user rc file.
zas_
parents:
736
diff
changeset
|
451 filter_add(key, desc, ext, file_class, enabled); |
77ff94c0490a
Try to load a system-wide rc file if any, before per-user rc file.
zas_
parents:
736
diff
changeset
|
452 } |
9 | 453 |
454 g_free(key); | |
455 g_free(ext); | |
456 g_free(desc); | |
457 } | |
1 | 458 |
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 *----------------------------------------------------------------------------- |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
461 * sidecar extension list |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
462 *----------------------------------------------------------------------------- |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
463 */ |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
464 |
586 | 465 GList *sidecar_ext_get_list(void) |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
466 { |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
467 return sidecar_ext_list; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
468 } |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
469 |
1190
a4ea0c74a6e2
File filters cleanup: add .pef .dng and .arw extensions to default sidecar extensions list, add .k25 in Kodak raw extensions, simplify and optimize sidecar_ext_parse().
zas_
parents:
1177
diff
changeset
|
470 static void sidecar_ext_free_list(void) |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
471 { |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
472 GList *work; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
473 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
474 work = sidecar_ext_list; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
475 while (work) |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
476 { |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
477 gchar *ext = work->data; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
478 work = work->next; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
479 g_free(ext); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
480 } |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
481 g_list_free(sidecar_ext_list); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
482 sidecar_ext_list = NULL; |
1190
a4ea0c74a6e2
File filters cleanup: add .pef .dng and .arw extensions to default sidecar extensions list, add .k25 in Kodak raw extensions, simplify and optimize sidecar_ext_parse().
zas_
parents:
1177
diff
changeset
|
483 } |
a4ea0c74a6e2
File filters cleanup: add .pef .dng and .arw extensions to default sidecar extensions list, add .k25 in Kodak raw extensions, simplify and optimize sidecar_ext_parse().
zas_
parents:
1177
diff
changeset
|
484 |
a4ea0c74a6e2
File filters cleanup: add .pef .dng and .arw extensions to default sidecar extensions list, add .k25 in Kodak raw extensions, simplify and optimize sidecar_ext_parse().
zas_
parents:
1177
diff
changeset
|
485 void sidecar_ext_parse(const gchar *text, gboolean quoted) |
a4ea0c74a6e2
File filters cleanup: add .pef .dng and .arw extensions to default sidecar extensions list, add .k25 in Kodak raw extensions, simplify and optimize sidecar_ext_parse().
zas_
parents:
1177
diff
changeset
|
486 { |
a4ea0c74a6e2
File filters cleanup: add .pef .dng and .arw extensions to default sidecar extensions list, add .k25 in Kodak raw extensions, simplify and optimize sidecar_ext_parse().
zas_
parents:
1177
diff
changeset
|
487 gchar *value; |
a4ea0c74a6e2
File filters cleanup: add .pef .dng and .arw extensions to default sidecar extensions list, add .k25 in Kodak raw extensions, simplify and optimize sidecar_ext_parse().
zas_
parents:
1177
diff
changeset
|
488 |
a4ea0c74a6e2
File filters cleanup: add .pef .dng and .arw extensions to default sidecar extensions list, add .k25 in Kodak raw extensions, simplify and optimize sidecar_ext_parse().
zas_
parents:
1177
diff
changeset
|
489 sidecar_ext_free_list(); |
442 | 490 |
170
9a56e3d13e67
basic sidecar files configuration via preferences dialog
nadvornik
parents:
167
diff
changeset
|
491 if (quoted) |
217 | 492 value = quoted_value(text, NULL); |
170
9a56e3d13e67
basic sidecar files configuration via preferences dialog
nadvornik
parents:
167
diff
changeset
|
493 else |
1207 | 494 value = (gchar *) text; |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
495 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
496 if (value == NULL) return; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
497 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
498 sidecar_ext_list = filter_to_list(value); |
442 | 499 |
1190
a4ea0c74a6e2
File filters cleanup: add .pef .dng and .arw extensions to default sidecar extensions list, add .k25 in Kodak raw extensions, simplify and optimize sidecar_ext_parse().
zas_
parents:
1177
diff
changeset
|
500 if (quoted) g_free(value); |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
501 } |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
502 |
1190
a4ea0c74a6e2
File filters cleanup: add .pef .dng and .arw extensions to default sidecar extensions list, add .k25 in Kodak raw extensions, simplify and optimize sidecar_ext_parse().
zas_
parents:
1177
diff
changeset
|
503 |
1055
1646720364cf
Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents:
1023
diff
changeset
|
504 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |