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