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