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