Mercurial > geeqie
annotate src/filefilter.c @ 1727:68b791050958
fixed toggle_slideshow function
https://sourceforge.net/tracker/index.php?func=detail&aid=2844302&group_id=222125&atid=1054680
author | nadvornik |
---|---|
date | Thu, 27 Aug 2009 20:23:28 +0000 |
parents | 1b2ddc6b2b27 |
children | 956aab097ea7 |
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 |
1284 | 4 * Copyright (C) 2008 - 2009 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" |
1309 | 22 #include "rcfile.h" |
1 | 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 |
1239
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
36 static GList *file_writable_list = NULL; /* writable files */ |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
37 static GList *file_sidecar_list = NULL; /* files with allowed sidecar */ |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
38 |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
39 |
9 | 40 static FilterEntry *filter_entry_new(const gchar *key, const gchar *description, |
1239
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
41 const gchar *extensions, FileFormatClass file_class, |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
42 gboolean writable, gboolean allow_sidecar, gboolean enabled) |
9 | 43 { |
44 FilterEntry *fe; | |
45 | |
46 fe = g_new0(FilterEntry, 1); | |
47 fe->key = g_strdup(key); | |
48 fe->description = g_strdup(description); | |
49 fe->extensions = g_strdup(extensions); | |
50 fe->enabled = enabled; | |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
51 fe->file_class = file_class; |
1239
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
52 fe->writable = writable; |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
53 fe->allow_sidecar = allow_sidecar; |
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 |
1424 | 99 static gboolean filter_key_exists(const gchar *key) |
743
77ff94c0490a
Try to load a system-wide rc file if any, before per-user rc file.
zas_
parents:
736
diff
changeset
|
100 { |
1424 | 101 return (filter_get_by_key(key) != NULL); |
9 | 102 } |
103 | |
1424 | 104 void filter_add(const gchar *key, const gchar *description, const gchar *extensions, FileFormatClass file_class, gboolean writable, gboolean allow_sidecar, gboolean enabled) |
9 | 105 { |
1239
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
106 filter_list = g_list_append(filter_list, filter_entry_new(key, description, extensions, file_class, writable, allow_sidecar, enabled)); |
9 | 107 } |
108 | |
1424 | 109 void filter_add_unique(const gchar *description, const gchar *extensions, FileFormatClass file_class, gboolean writable, gboolean allow_sidecar, gboolean 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 | |
1239
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
124 filter_add(key, description, extensions, file_class, writable, allow_sidecar, enabled); |
9 | 125 g_free(key); |
126 } | |
127 | |
1424 | 128 static void filter_add_if_missing(const gchar *key, const gchar *description, const gchar *extensions, FileFormatClass file_class, gboolean writable, gboolean allow_sidecar, gboolean 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 */ |
1239
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
143 |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
144 if (fe->writable && fe->allow_sidecar) |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
145 { |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
146 fe->writable = writable; |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
147 fe->allow_sidecar = allow_sidecar; |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
148 } |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
149 return; |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
150 } |
9 | 151 } |
152 | |
1239
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
153 filter_add(key, description, extensions, file_class, writable, allow_sidecar, enabled); |
9 | 154 } |
155 | |
156 void filter_reset(void) | |
1 | 157 { |
158 GList *work; | |
9 | 159 |
160 work = filter_list; | |
161 while (work) | |
162 { | |
163 FilterEntry *fe = work->data; | |
164 work = work->next; | |
165 filter_entry_free(fe); | |
166 } | |
167 | |
168 g_list_free(filter_list); | |
169 filter_list = NULL; | |
170 } | |
171 | |
172 void filter_add_defaults(void) | |
173 { | |
174 GSList *list, *work; | |
175 | |
176 list = gdk_pixbuf_get_formats(); | |
177 work = list; | |
178 while (work) | |
179 { | |
180 GdkPixbufFormat *format; | |
181 gchar *name; | |
182 gchar *desc; | |
183 gchar **extensions; | |
184 GString *filter = NULL; | |
736 | 185 guint i; |
442 | 186 |
9 | 187 format = work->data; |
188 work = work->next; | |
189 | |
190 name = gdk_pixbuf_format_get_name(format); | |
191 desc = gdk_pixbuf_format_get_description(format); | |
192 extensions = gdk_pixbuf_format_get_extensions(format); | |
193 | |
194 i = 0; | |
195 while (extensions[i]) | |
196 { | |
197 if (!filter) | |
198 { | |
199 filter = g_string_new("."); | |
200 filter = g_string_append(filter, extensions[i]); | |
201 } | |
202 else | |
203 { | |
204 filter = g_string_append(filter, ";."); | |
205 filter = g_string_append(filter, extensions[i]); | |
206 } | |
207 i++; | |
208 } | |
209 | |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
495
diff
changeset
|
210 DEBUG_1("loader reported [%s] [%s] [%s]", name, desc, filter->str); |
9 | 211 |
1239
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
212 filter_add_if_missing(name, desc, filter->str, FORMAT_CLASS_IMAGE, TRUE, FALSE, TRUE); |
9 | 213 |
214 g_free(name); | |
215 g_free(desc); | |
216 g_strfreev(extensions); | |
217 g_string_free(filter, TRUE); | |
218 } | |
219 g_slist_free(list); | |
1 | 220 |
9 | 221 /* add defaults even if gdk-pixbuf does not have them, but disabled */ |
1239
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
222 filter_add_if_missing("jpeg", "JPEG group", ".jpg;.jpeg;.jpe", FORMAT_CLASS_IMAGE, TRUE, FALSE, FALSE); |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
223 filter_add_if_missing("png", "Portable Network Graphic", ".png", FORMAT_CLASS_IMAGE, TRUE, FALSE, FALSE); |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
224 filter_add_if_missing("tiff", "Tiff", ".tif;.tiff", FORMAT_CLASS_IMAGE, TRUE, FALSE, FALSE); |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
225 filter_add_if_missing("pnm", "Packed Pixel formats", ".pbm;.pgm;.pnm;.ppm", FORMAT_CLASS_IMAGE, TRUE, FALSE, FALSE); |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
226 filter_add_if_missing("gif", "Graphics Interchange Format", ".gif", FORMAT_CLASS_IMAGE, TRUE, FALSE, FALSE); |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
227 filter_add_if_missing("xbm", "X bitmap", ".xbm", FORMAT_CLASS_IMAGE, TRUE, FALSE, FALSE); |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
228 filter_add_if_missing("xpm", "X pixmap", ".xpm", FORMAT_CLASS_IMAGE, TRUE, FALSE, FALSE); |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
229 filter_add_if_missing("bmp", "Bitmap", ".bmp", FORMAT_CLASS_IMAGE, TRUE, FALSE, FALSE); |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
230 filter_add_if_missing("ico", "Icon file", ".ico;.cur", FORMAT_CLASS_IMAGE, TRUE, FALSE, FALSE); |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
231 filter_add_if_missing("ras", "Raster", ".ras", FORMAT_CLASS_IMAGE, TRUE, FALSE, FALSE); |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
232 filter_add_if_missing("svg", "Scalable Vector Graphics", ".svg", FORMAT_CLASS_IMAGE, TRUE, FALSE, FALSE); |
442 | 233 |
202
f95654aeec4b
added all possible raw extensions that I could find
nadvornik
parents:
196
diff
changeset
|
234 /* non-image files that might be desirable to show */ |
1239
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
235 filter_add_if_missing("xmp", "XMP sidecar", ".xmp", FORMAT_CLASS_META, TRUE, FALSE, TRUE); |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
236 filter_add_if_missing("gqv", GQ_APPNAME " image collection", GQ_COLLECTION_EXT, FORMAT_CLASS_META, FALSE, FALSE, TRUE); |
1486 | 237 filter_add_if_missing("ufraw", "UFRaw ID file", ".ufraw", FORMAT_CLASS_META, FALSE, FALSE, TRUE); |
43
ee03f36e9e4b
Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
238 |
ee03f36e9e4b
Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
15
diff
changeset
|
239 /* 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
|
240 * (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
|
241 */ |
1239
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
242 filter_add_if_missing("arw", "Sony raw format", ".arw;.srf;.sr2", FORMAT_CLASS_RAWIMAGE, FALSE, TRUE, TRUE); |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
243 filter_add_if_missing("crw", "Canon raw format", ".crw;.cr2", FORMAT_CLASS_RAWIMAGE, FALSE, TRUE, TRUE); |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
244 filter_add_if_missing("kdc", "Kodak raw format", ".kdc;.dcr;.k25", FORMAT_CLASS_RAWIMAGE, FALSE, TRUE, TRUE); |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
245 filter_add_if_missing("raf", "Fujifilm raw format", ".raf", FORMAT_CLASS_RAWIMAGE, FALSE, TRUE, TRUE); |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
246 filter_add_if_missing("mef", "Mamiya raw format", ".mef;.mos", FORMAT_CLASS_RAWIMAGE, FALSE, TRUE, TRUE); |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
247 filter_add_if_missing("mrw", "Minolta raw format", ".mrw", FORMAT_CLASS_RAWIMAGE, FALSE, TRUE, TRUE); |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
248 filter_add_if_missing("nef", "Nikon raw format", ".nef", FORMAT_CLASS_RAWIMAGE, FALSE, TRUE, TRUE); |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
249 filter_add_if_missing("orf", "Olympus raw format", ".orf", FORMAT_CLASS_RAWIMAGE, FALSE, TRUE, TRUE); |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
250 filter_add_if_missing("pef", "Pentax or Samsung raw format", ".pef;.ptx", FORMAT_CLASS_RAWIMAGE, FALSE, TRUE, TRUE); |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
251 filter_add_if_missing("dng", "Adobe Digital Negative raw format", ".dng", FORMAT_CLASS_RAWIMAGE, FALSE, TRUE, TRUE); |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
252 filter_add_if_missing("x3f", "Sigma raw format", ".x3f", FORMAT_CLASS_RAWIMAGE, FALSE, TRUE, TRUE); |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
253 filter_add_if_missing("raw", "Panasonic raw format", ".raw", FORMAT_CLASS_RAWIMAGE, FALSE, TRUE, TRUE); |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
254 filter_add_if_missing("r3d", "Red raw format", ".r3d", FORMAT_CLASS_RAWIMAGE, FALSE, TRUE, TRUE); |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
255 filter_add_if_missing("3fr", "Hasselblad raw format", ".3fr", FORMAT_CLASS_RAWIMAGE, FALSE, TRUE, TRUE); |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
256 filter_add_if_missing("erf", "Epson raw format", ".erf", FORMAT_CLASS_RAWIMAGE, FALSE, TRUE, TRUE); |
9 | 257 } |
258 | |
147
b2266996fa83
added possibility to specify prefered file type for external commands
nadvornik
parents:
146
diff
changeset
|
259 GList *filter_to_list(const gchar *extensions) |
9 | 260 { |
261 GList *list = NULL; | |
262 const gchar *p; | |
263 | |
264 if (!extensions) return NULL; | |
265 | |
266 p = extensions; | |
267 while (*p != '\0') | |
268 { | |
269 const gchar *b; | |
1235 | 270 gchar *ext; |
1229
878718372aca
sidecar files grouping was made case-insensitive
nadvornik
parents:
1207
diff
changeset
|
271 gint file_class = -1; |
736 | 272 guint l = 0; |
9 | 273 |
274 b = p; | |
275 while (*p != '\0' && *p != ';') | |
276 { | |
277 p++; | |
278 l++; | |
279 } | |
1229
878718372aca
sidecar files grouping was made case-insensitive
nadvornik
parents:
1207
diff
changeset
|
280 |
878718372aca
sidecar files grouping was made case-insensitive
nadvornik
parents:
1207
diff
changeset
|
281 ext = g_strndup(b, l); |
878718372aca
sidecar files grouping was made case-insensitive
nadvornik
parents:
1207
diff
changeset
|
282 |
1307 | 283 if (g_ascii_strcasecmp(ext, "%image") == 0) file_class = FORMAT_CLASS_IMAGE; |
284 else if (g_ascii_strcasecmp(ext, "%raw") == 0) file_class = FORMAT_CLASS_RAWIMAGE; | |
285 else if (g_ascii_strcasecmp(ext, "%meta") == 0) file_class = FORMAT_CLASS_META; | |
1229
878718372aca
sidecar files grouping was made case-insensitive
nadvornik
parents:
1207
diff
changeset
|
286 |
878718372aca
sidecar files grouping was made case-insensitive
nadvornik
parents:
1207
diff
changeset
|
287 if (file_class == -1) |
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 list = g_list_append(list, ext); |
878718372aca
sidecar files grouping was made case-insensitive
nadvornik
parents:
1207
diff
changeset
|
290 } |
878718372aca
sidecar files grouping was made case-insensitive
nadvornik
parents:
1207
diff
changeset
|
291 else |
878718372aca
sidecar files grouping was made case-insensitive
nadvornik
parents:
1207
diff
changeset
|
292 { |
878718372aca
sidecar files grouping was made case-insensitive
nadvornik
parents:
1207
diff
changeset
|
293 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
|
294 g_free(ext); |
878718372aca
sidecar files grouping was made case-insensitive
nadvornik
parents:
1207
diff
changeset
|
295 } |
878718372aca
sidecar files grouping was made case-insensitive
nadvornik
parents:
1207
diff
changeset
|
296 |
9 | 297 if (*p == ';') p++; |
298 } | |
299 | |
300 return list; | |
301 } | |
302 | |
303 void filter_rebuild(void) | |
304 { | |
305 GList *work; | |
736 | 306 guint i; |
9 | 307 |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
308 string_list_free(extension_list); |
9 | 309 extension_list = NULL; |
310 | |
1239
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
311 string_list_free(file_writable_list); |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
312 file_writable_list = NULL; |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
313 |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
314 string_list_free(file_sidecar_list); |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
315 file_sidecar_list = NULL; |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
316 |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
317 for (i = 0; i < FILE_FORMAT_CLASSES; i++) |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
318 { |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
319 string_list_free(file_class_extension_list[i]); |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
320 file_class_extension_list[i] = NULL; |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
321 } |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
322 |
9 | 323 work = filter_list; |
324 while (work) | |
325 { | |
326 FilterEntry *fe; | |
327 | |
328 fe = work->data; | |
329 work = work->next; | |
330 | |
331 if (fe->enabled) | |
332 { | |
333 GList *ext; | |
334 | |
335 ext = filter_to_list(fe->extensions); | |
336 if (ext) extension_list = g_list_concat(extension_list, ext); | |
442 | 337 |
1177
5a20c47e7a14
Fix up unsigned expression always true/false warnings.
zas_
parents:
1055
diff
changeset
|
338 if (fe->file_class < FILE_FORMAT_CLASSES) |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
339 { |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
340 ext = filter_to_list(fe->extensions); |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
341 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
|
342 } |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
343 else |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
344 { |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
345 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
|
346 } |
1239
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
347 |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
348 if (fe->writable) |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
349 { |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
350 ext = filter_to_list(fe->extensions); |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
351 if (ext) file_writable_list = g_list_concat(file_writable_list, ext); |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
352 } |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
353 |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
354 if (fe->allow_sidecar) |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
355 { |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
356 ext = filter_to_list(fe->extensions); |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
357 if (ext) file_sidecar_list = g_list_concat(file_sidecar_list, ext); |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
358 } |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
359 |
9 | 360 } |
361 } | |
1229
878718372aca
sidecar files grouping was made case-insensitive
nadvornik
parents:
1207
diff
changeset
|
362 |
1327 | 363 sidecar_ext_parse(options->sidecar.ext); /* this must be updated after changed file extensions */ |
9 | 364 } |
365 | |
1239
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
366 static gboolean filter_name_find(GList *filter, const gchar *name) |
9 | 367 { |
368 GList *work; | |
736 | 369 guint ln; |
215 | 370 |
371 ln = strlen(name); | |
1239
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
372 work = filter; |
1 | 373 while (work) |
374 { | |
375 gchar *filter = work->data; | |
736 | 376 guint lf = strlen(filter); |
215 | 377 |
1 | 378 if (ln >= lf) |
379 { | |
605
651ae2be1031
Use g_ascii_strncasecmp() instead of strncasecmp() where applicable.
zas_
parents:
587
diff
changeset
|
380 /* FIXME: utf8 */ |
1307 | 381 if (g_ascii_strncasecmp(name + ln - lf, filter, lf) == 0) return TRUE; |
1 | 382 } |
383 work = work->next; | |
384 } | |
385 | |
386 return FALSE; | |
387 } | |
388 | |
1239
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
389 |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
390 gboolean filter_name_exists(const gchar *name) |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
391 { |
1239
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
392 if (!extension_list || options->file_filter.disable) return TRUE; |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
393 |
1239
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
394 return filter_name_find(extension_list, name); |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
395 } |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
396 |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
397 gboolean filter_file_class(const gchar *name, FileFormatClass file_class) |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
398 { |
1177
5a20c47e7a14
Fix up unsigned expression always true/false warnings.
zas_
parents:
1055
diff
changeset
|
399 if (file_class >= FILE_FORMAT_CLASSES) |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
400 { |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
401 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
|
402 return FALSE; |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
403 } |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
404 |
1239
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
405 return filter_name_find(file_class_extension_list[file_class], name); |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
406 } |
215 | 407 |
1239
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
408 gboolean filter_name_is_writable(const gchar *name) |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
409 { |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
410 return filter_name_find(file_writable_list, name); |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
411 } |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
412 |
1239
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
413 gboolean filter_name_allow_sidecar(const gchar *name) |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
414 { |
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1235
diff
changeset
|
415 return filter_name_find(file_sidecar_list, name); |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
416 } |
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
417 |
1309 | 418 void filter_write_list(GString *outstr, gint indent) |
1 | 419 { |
9 | 420 GList *work; |
421 | |
1461 | 422 WRITE_NL(); WRITE_STRING("<filter>"); |
1309 | 423 indent++; |
424 | |
9 | 425 work = filter_list; |
426 while (work) | |
427 { | |
428 FilterEntry *fe = work->data; | |
429 work = work->next; | |
442 | 430 |
1461 | 431 WRITE_NL(); WRITE_STRING("<file_type "); |
1309 | 432 WRITE_CHAR(*fe, key); |
433 WRITE_BOOL(*fe, enabled); | |
434 WRITE_CHAR(*fe, extensions); | |
435 WRITE_CHAR(*fe, description); | |
436 WRITE_UINT(*fe, file_class); | |
437 WRITE_BOOL(*fe, writable); | |
438 WRITE_BOOL(*fe, allow_sidecar); | |
1461 | 439 WRITE_STRING("/>"); |
9 | 440 } |
1309 | 441 indent--; |
1461 | 442 WRITE_NL(); WRITE_STRING("</filter>"); |
1 | 443 } |
444 | |
1309 | 445 void filter_load_file_type(const gchar **attribute_names, const gchar **attribute_values) |
1 | 446 { |
1309 | 447 FilterEntry fe; |
448 FilterEntry *old_fe; | |
449 memset(&fe, 0, sizeof(fe)); | |
450 while (*attribute_names) | |
451 { | |
452 const gchar *option = *attribute_names++; | |
453 const gchar *value = *attribute_values++; | |
9 | 454 |
1315 | 455 if (READ_CHAR(fe, key)) continue; |
456 if (READ_BOOL(fe, enabled)) continue; | |
457 if (READ_CHAR(fe, extensions)) continue; | |
458 if (READ_CHAR(fe, description)) continue; | |
459 if (READ_UINT(fe, file_class)) continue; | |
460 if (READ_BOOL(fe, writable)) continue; | |
461 if (READ_BOOL(fe, allow_sidecar)) continue; | |
1 | 462 |
1464 | 463 log_printf("unknown attribute %s = %s\n", option, value); |
1309 | 464 } |
465 if (fe.file_class >= FILE_FORMAT_CLASSES) fe.file_class = FORMAT_CLASS_UNKNOWN; | |
466 | |
467 if (fe.key && fe.key[0] != 0) | |
743
77ff94c0490a
Try to load a system-wide rc file if any, before per-user rc file.
zas_
parents:
736
diff
changeset
|
468 { |
1309 | 469 old_fe = filter_get_by_key(fe.key); |
743
77ff94c0490a
Try to load a system-wide rc file if any, before per-user rc file.
zas_
parents:
736
diff
changeset
|
470 |
1309 | 471 if (old_fe != NULL) filter_remove_entry(old_fe); |
472 filter_add(fe.key, fe.description, fe.extensions, fe.file_class, fe.writable, fe.allow_sidecar, fe.enabled); | |
743
77ff94c0490a
Try to load a system-wide rc file if any, before per-user rc file.
zas_
parents:
736
diff
changeset
|
473 } |
1309 | 474 g_free(fe.key); |
475 g_free(fe.extensions); | |
476 g_free(fe.description); | |
477 } | |
9 | 478 |
1 | 479 |
145
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 *----------------------------------------------------------------------------- |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
482 * sidecar extension list |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
483 *----------------------------------------------------------------------------- |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
484 */ |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
485 |
586 | 486 GList *sidecar_ext_get_list(void) |
145
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 return sidecar_ext_list; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
489 } |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
490 |
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
|
491 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
|
492 { |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
493 GList *work; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
494 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
495 work = sidecar_ext_list; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
496 while (work) |
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 gchar *ext = work->data; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
499 work = work->next; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
500 g_free(ext); |
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 g_list_free(sidecar_ext_list); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
503 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
|
504 } |
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
|
505 |
1327 | 506 void sidecar_ext_parse(const gchar *text) |
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
|
507 { |
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
|
508 sidecar_ext_free_list(); |
1327 | 509 if (text == NULL) return; |
442 | 510 |
1327 | 511 sidecar_ext_list = filter_to_list(text); |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
512 } |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
513 |
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
|
514 |
1055
1646720364cf
Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents:
1023
diff
changeset
|
515 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |