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