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