Mercurial > geeqie
annotate src/filelist.c @ 360:822040a51249
Increase collection_load() buffer size and do not activate
error limiting for GQview collections.
author | zas_ |
---|---|
date | Mon, 14 Apr 2008 22:45:53 +0000 |
parents | 673d1eb5af73 |
children | 1eaea84877ce |
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 |
332 | 381 secure_fprintf(ssi, "file_filter.ext: \"%s%s\" %s %s\n", |
276 | 382 (fe->enabled) ? "" : "#", |
383 fe->key, extensions, description); | |
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; | |
396 | |
397 if (!text || text[0] != '"') return; | |
398 | |
217 | 399 key = quoted_value(text, &p); |
9 | 400 if (!key) return; |
401 | |
217 | 402 ext = quoted_value(p, &p); |
403 desc = quoted_value(p, &p); | |
9 | 404 |
405 if (key && key[0] == '#') | |
406 { | |
407 gchar *tmp; | |
408 tmp = g_strdup(key + 1); | |
409 g_free(key); | |
410 key = tmp; | |
411 | |
412 enabled = FALSE; | |
1 | 413 } |
414 | |
212
c7021159079d
differentiate among normal image, raw image and metadata
nadvornik
parents:
202
diff
changeset
|
415 if (key && strlen(key) > 0 && ext) filter_add(key, desc, ext, FORMAT_CLASS_UNKNOWN, enabled); |
9 | 416 |
417 g_free(key); | |
418 g_free(ext); | |
419 g_free(desc); | |
420 } | |
1 | 421 |
9 | 422 GList *path_list_filter(GList *list, gint is_dir_list) |
423 { | |
424 GList *work; | |
425 | |
356 | 426 if (!is_dir_list && options->file_filter.disable && options->file_filter.show_hidden_files) return list; |
9 | 427 |
428 work = list; | |
429 while (work) | |
1 | 430 { |
9 | 431 gchar *name = work->data; |
432 const gchar *base; | |
433 | |
434 base = filename_from_path(name); | |
435 | |
356 | 436 if ((!options->file_filter.show_hidden_files && ishidden(base)) || |
9 | 437 (!is_dir_list && !filter_name_exists(base)) || |
283 | 438 (is_dir_list && base[0] == '.' && (strcmp(base, GQ_CACHE_LOCAL_THUMB) == 0 || |
439 strcmp(base, GQ_CACHE_LOCAL_METADATA) == 0)) ) | |
9 | 440 { |
441 GList *link = work; | |
442 work = work->next; | |
443 list = g_list_remove_link(list, link); | |
444 g_free(name); | |
445 g_list_free(link); | |
446 } | |
447 else | |
1 | 448 { |
9 | 449 work = work->next; |
1 | 450 } |
451 } | |
9 | 452 |
453 return list; | |
454 } | |
455 | |
145
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 *----------------------------------------------------------------------------- |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
459 * sidecar extension list |
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 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
463 static GList *sidecar_ext_get_list(void) |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
464 { |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
465 return sidecar_ext_list; |
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 |
170
9a56e3d13e67
basic sidecar files configuration via preferences dialog
nadvornik
parents:
167
diff
changeset
|
468 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
|
469 { |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
470 GList *work; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
471 gchar *value; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
472 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
473 work = sidecar_ext_list; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
474 while (work) |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
475 { |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
476 gchar *ext = work->data; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
477 work = work->next; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
478 g_free(ext); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
479 } |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
480 g_list_free(sidecar_ext_list); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
481 sidecar_ext_list = NULL; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
482 |
170
9a56e3d13e67
basic sidecar files configuration via preferences dialog
nadvornik
parents:
167
diff
changeset
|
483 if (quoted) |
217 | 484 value = quoted_value(text, NULL); |
170
9a56e3d13e67
basic sidecar files configuration via preferences dialog
nadvornik
parents:
167
diff
changeset
|
485 else |
9a56e3d13e67
basic sidecar files configuration via preferences dialog
nadvornik
parents:
167
diff
changeset
|
486 value = g_strdup(text); |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
487 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
488 if (value == NULL) return; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
489 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
490 sidecar_ext_list = filter_to_list(value); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
491 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
492 g_free(value); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
493 } |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
494 |
276 | 495 void sidecar_ext_write(SecureSaveInfo *ssi) |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
496 { |
347 | 497 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
|
498 } |
9a56e3d13e67
basic sidecar files configuration via preferences dialog
nadvornik
parents:
167
diff
changeset
|
499 |
9a56e3d13e67
basic sidecar files configuration via preferences dialog
nadvornik
parents:
167
diff
changeset
|
500 char *sidecar_ext_to_string() |
9a56e3d13e67
basic sidecar files configuration via preferences dialog
nadvornik
parents:
167
diff
changeset
|
501 { |
9a56e3d13e67
basic sidecar files configuration via preferences dialog
nadvornik
parents:
167
diff
changeset
|
502 GList *work; |
9a56e3d13e67
basic sidecar files configuration via preferences dialog
nadvornik
parents:
167
diff
changeset
|
503 GString *str = g_string_new(""); |
9a56e3d13e67
basic sidecar files configuration via preferences dialog
nadvornik
parents:
167
diff
changeset
|
504 |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
505 work = sidecar_ext_list; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
506 while (work) |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
507 { |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
508 gchar *ext = work->data; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
509 work = work->next; |
170
9a56e3d13e67
basic sidecar files configuration via preferences dialog
nadvornik
parents:
167
diff
changeset
|
510 g_string_append(str, ext); |
9a56e3d13e67
basic sidecar files configuration via preferences dialog
nadvornik
parents:
167
diff
changeset
|
511 if (work) g_string_append(str, ";"); |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
512 } |
170
9a56e3d13e67
basic sidecar files configuration via preferences dialog
nadvornik
parents:
167
diff
changeset
|
513 return g_string_free(str, FALSE); |
145
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 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
516 void sidecar_ext_add_defaults() |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
517 { |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
172
diff
changeset
|
518 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
|
519 } |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
520 |
9 | 521 /* |
522 *----------------------------------------------------------------------------- | |
523 * path list recursive | |
524 *----------------------------------------------------------------------------- | |
525 */ | |
526 | |
527 static gint path_list_sort_cb(gconstpointer a, gconstpointer b) | |
528 { | |
529 return CASE_SORT((gchar *)a, (gchar *)b); | |
530 } | |
531 | |
532 GList *path_list_sort(GList *list) | |
533 { | |
534 return g_list_sort(list, path_list_sort_cb); | |
535 } | |
536 | |
537 static void path_list_recursive_append(GList **list, GList *dirs) | |
538 { | |
539 GList *work; | |
540 | |
541 work = dirs; | |
542 while (work) | |
543 { | |
544 const gchar *path = work->data; | |
545 GList *f = NULL; | |
546 GList *d = NULL; | |
547 | |
548 if (path_list(path, &f, &d)) | |
549 { | |
550 f = path_list_filter(f, FALSE); | |
551 f = path_list_sort(f); | |
552 *list = g_list_concat(*list, f); | |
553 | |
554 d = path_list_filter(d, TRUE); | |
555 d = path_list_sort(d); | |
556 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
|
557 path_list_free(d); |
9 | 558 } |
559 | |
560 work = work->next; | |
561 } | |
562 } | |
563 | |
564 GList *path_list_recursive(const gchar *path) | |
565 { | |
566 GList *list = NULL; | |
567 GList *d = NULL; | |
568 | |
569 if (!path_list(path, &list, &d)) return NULL; | |
570 list = path_list_filter(list, FALSE); | |
571 list = path_list_sort(list); | |
572 | |
573 d = path_list_filter(d, TRUE); | |
574 d = path_list_sort(d); | |
575 path_list_recursive_append(&list, d); | |
576 path_list_free(d); | |
577 | |
578 return list; | |
1 | 579 } |
580 | |
581 /* | |
582 *----------------------------------------------------------------------------- | |
9 | 583 * text conversion utils |
1 | 584 *----------------------------------------------------------------------------- |
585 */ | |
586 | |
9 | 587 gchar *text_from_size(gint64 size) |
1 | 588 { |
9 | 589 gchar *a, *b; |
590 gchar *s, *d; | |
591 gint l, n, i; | |
592 | |
593 /* what I would like to use is printf("%'d", size) | |
594 * BUT: not supported on every libc :( | |
595 */ | |
596 if (size > G_MAXUINT) | |
597 { | |
598 /* the %lld conversion is not valid in all libcs, so use a simple work-around */ | |
599 a = g_strdup_printf("%d%09d", (guint)(size / 1000000000), (guint)(size % 1000000000)); | |
600 } | |
601 else | |
602 { | |
603 a = g_strdup_printf("%d", (guint)size); | |
604 } | |
605 l = strlen(a); | |
606 n = (l - 1)/ 3; | |
607 if (n < 1) return a; | |
608 | |
609 b = g_new(gchar, l + n + 1); | |
610 | |
611 s = a; | |
612 d = b; | |
613 i = l - n * 3; | |
614 while (*s != '\0') | |
615 { | |
616 if (i < 1) | |
617 { | |
618 i = 3; | |
619 *d = ','; | |
620 d++; | |
621 } | |
622 | |
623 *d = *s; | |
624 s++; | |
625 d++; | |
626 i--; | |
627 } | |
628 *d = '\0'; | |
629 | |
630 g_free(a); | |
631 return b; | |
632 } | |
633 | |
634 gchar *text_from_size_abrev(gint64 size) | |
635 { | |
636 if (size < (gint64)1024) | |
637 { | |
638 return g_strdup_printf(_("%d bytes"), (gint)size); | |
639 } | |
640 if (size < (gint64)1048576) | |
641 { | |
15
3263965d5f9e
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
642 return g_strdup_printf(_("%.1f K"), (double)size / 1024.0); |
9 | 643 } |
644 if (size < (gint64)1073741824) | |
645 { | |
15
3263965d5f9e
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
646 return g_strdup_printf(_("%.1f MB"), (double)size / 1048576.0); |
9 | 647 } |
648 | |
15
3263965d5f9e
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
649 /* 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
|
650 size /= 1048576; |
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 GB"), (double)size / 1024.0); |
9 | 652 } |
653 | |
654 /* note: returned string is valid until next call to text_from_time() */ | |
655 const gchar *text_from_time(time_t t) | |
656 { | |
657 static gchar *ret = NULL; | |
658 gchar buf[128]; | |
659 gint buflen; | |
660 struct tm *btime; | |
661 GError *error = NULL; | |
662 | |
663 btime = localtime(&t); | |
664 | |
665 /* the %x warning about 2 digit years is not an error */ | |
666 buflen = strftime(buf, sizeof(buf), "%x %H:%M", btime); | |
667 if (buflen < 1) return ""; | |
668 | |
669 g_free(ret); | |
670 ret = g_locale_to_utf8(buf, buflen, NULL, NULL, &error); | |
671 if (error) | |
672 { | |
673 printf("Error converting locale strftime to UTF-8: %s\n", error->message); | |
674 g_error_free(error); | |
675 return ""; | |
676 } | |
677 | |
678 return ret; | |
1 | 679 } |
680 | |
9 | 681 /* |
682 *----------------------------------------------------------------------------- | |
683 * file info struct | |
684 *----------------------------------------------------------------------------- | |
685 */ | |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
686 |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
687 FileData *file_data_merge_sidecar_files(FileData *target, FileData *source); |
167 | 688 static void file_data_check_sidecars(FileData *fd); |
689 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
|
690 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
691 |
138 | 692 static void file_data_set_path(FileData *fd, const gchar *path) |
693 { | |
9 | 694 |
138 | 695 if (strcmp(path, "/") == 0) |
696 { | |
697 fd->path = g_strdup(path); | |
698 fd->name = fd->path; | |
699 fd->extension = fd->name + 1; | |
700 return; | |
701 } | |
702 | |
703 fd->path = g_strdup(path); | |
704 fd->name = filename_from_path(fd->path); | |
705 | |
706 if (strcmp(fd->name, "..") == 0) | |
707 { | |
708 gchar *dir = remove_level_from_path(path); | |
709 g_free(fd->path); | |
710 fd->path = remove_level_from_path(dir); | |
711 g_free(dir); | |
712 fd->name = ".."; | |
713 fd->extension = fd->name + 2; | |
714 return; | |
715 } | |
716 else if (strcmp(fd->name, ".") == 0) | |
717 { | |
718 g_free(fd->path); | |
719 fd->path = remove_level_from_path(path); | |
720 fd->name = "."; | |
721 fd->extension = fd->name + 1; | |
722 return; | |
723 } | |
724 | |
725 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
|
726 if (fd->extension == NULL) |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
727 fd->extension = fd->name + strlen(fd->name); |
138 | 728 } |
729 | |
167 | 730 static void file_data_check_changed_files(FileData *fd, struct stat *st) |
164 | 731 { |
167 | 732 GList *work; |
164 | 733 if (fd->size != st->st_size || |
734 fd->date != st->st_mtime) | |
735 { | |
736 fd->size = st->st_size; | |
737 fd->date = st->st_mtime; | |
738 if (fd->pixbuf) g_object_unref(fd->pixbuf); | |
739 fd->pixbuf = NULL; | |
740 } | |
167 | 741 |
742 work = fd->sidecar_files; | |
743 while (work) | |
744 { | |
745 FileData *sfd = work->data; | |
746 struct stat st; | |
747 | |
748 if (!stat_utf8(sfd->path, &st)) | |
749 { | |
750 file_data_disconnect_sidecar_file(fd, sfd); | |
751 } | |
752 | |
753 file_data_check_changed_files(sfd, &st); | |
754 work = work->next; | |
755 } | |
164 | 756 } |
757 | |
138 | 758 static GHashTable *file_data_pool = NULL; |
759 | |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
760 static FileData *file_data_new(const gchar *path_utf8, struct stat *st, gboolean check_sidecars) |
9 | 761 { |
762 FileData *fd; | |
763 | |
172 | 764 if (debug) printf("file_data_new: '%s' %d\n", path_utf8, check_sidecars); |
138 | 765 |
766 if (!file_data_pool) | |
767 file_data_pool = g_hash_table_new (g_str_hash, g_str_equal); | |
768 | |
769 fd = g_hash_table_lookup(file_data_pool, path_utf8); | |
770 if (fd) | |
771 { | |
167 | 772 file_data_check_changed_files(fd, st); |
172 | 773 if (debug) printf("file_data_pool hit: '%s'\n", fd->path); |
138 | 774 return file_data_ref(fd); |
775 } | |
776 | |
9 | 777 fd = g_new0(FileData, 1); |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
778 |
138 | 779 file_data_set_path(fd, path_utf8); |
780 | |
781 fd->original_path = g_strdup(path_utf8); | |
9 | 782 fd->size = st->st_size; |
783 fd->date = st->st_mtime; | |
784 fd->pixbuf = NULL; | |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
785 fd->sidecar_files = NULL; |
138 | 786 fd->ref = 1; |
787 fd->magick = 0x12345678; | |
788 | |
789 g_hash_table_insert(file_data_pool, fd->original_path, fd); | |
790 | |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
791 if (check_sidecars && sidecar_file_priority(fd->extension)) |
146 | 792 file_data_check_sidecars(fd); |
9 | 793 return fd; |
794 } | |
795 | |
146 | 796 static void file_data_check_sidecars(FileData *fd) |
797 { | |
798 int base_len = fd->extension - fd->path; | |
799 GString *fname = g_string_new_len(fd->path, base_len); | |
800 FileData *parent_fd = NULL; | |
801 GList *work = sidecar_ext_get_list(); | |
802 while (work) | |
803 { | |
804 /* check for possible sidecar files; | |
805 the sidecar files created here are referenced only via fd->sidecar_files or fd->parent, | |
806 they have fd->ref set to 0 and file_data unref must chack and free them all together | |
807 (using fd->ref would cause loops and leaks) | |
808 */ | |
809 | |
810 FileData *new_fd; | |
811 | |
812 gchar *ext = work->data; | |
813 work = work->next; | |
814 | |
815 if (strcmp(ext, fd->extension) == 0) | |
816 { | |
817 new_fd = fd; /* processing the original file */ | |
818 } | |
819 else | |
820 { | |
821 struct stat nst; | |
822 g_string_truncate(fname, base_len); | |
823 g_string_append(fname, ext); | |
824 | |
825 if (!stat_utf8(fname->str, &nst)) | |
826 continue; | |
827 | |
828 new_fd = file_data_new(fname->str, &nst, FALSE); | |
829 new_fd->ref--; /* do not use ref here */ | |
830 } | |
831 | |
832 if (!parent_fd) | |
833 parent_fd = new_fd; /* parent is the one with the highest prio, found first */ | |
834 else | |
835 file_data_merge_sidecar_files(parent_fd, new_fd); | |
836 } | |
837 g_string_free(fname, TRUE); | |
838 } | |
839 | |
840 | |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
841 static FileData *file_data_new_local(const gchar *path, struct stat *st, gboolean check_sidecars) |
138 | 842 { |
843 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
|
844 FileData *ret = file_data_new(path_utf8, st, check_sidecars); |
138 | 845 g_free(path_utf8); |
846 return ret; | |
847 } | |
848 | |
849 FileData *file_data_new_simple(const gchar *path_utf8) | |
9 | 850 { |
851 struct stat st; | |
852 | |
138 | 853 if (!stat_utf8(path_utf8, &st)) |
9 | 854 { |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
855 st.st_size = 0; |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
856 st.st_mtime = 0; |
9 | 857 } |
858 | |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
859 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
|
860 } |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
861 |
141 | 862 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
|
863 { |
141 | 864 sfd->parent = target; |
146 | 865 if(!g_list_find(target->sidecar_files, sfd)) |
866 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
|
867 return target; |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
868 } |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
869 |
167 | 870 |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
871 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
|
872 { |
141 | 873 GList *work; |
874 file_data_add_sidecar_file(target, source); | |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
875 |
141 | 876 work = source->sidecar_files; |
877 while (work) | |
878 { | |
879 FileData *sfd = work->data; | |
146 | 880 file_data_add_sidecar_file(target, sfd); |
141 | 881 work = work->next; |
882 } | |
883 | |
146 | 884 g_list_free(source->sidecar_files); |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
885 source->sidecar_files = NULL; |
167 | 886 |
887 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
|
888 return target; |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
889 } |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
890 |
167 | 891 |
892 | |
138 | 893 FileData *file_data_ref(FileData *fd) |
894 { | |
895 if (fd == NULL) return NULL; | |
896 | |
897 // return g_memdup(fd, sizeof(FileData)); | |
898 g_assert(fd->magick == 0x12345678); | |
899 fd->ref++; | |
900 return fd; | |
901 } | |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
902 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
903 static void file_data_free(FileData *fd) |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
904 { |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
905 g_assert(fd->magick == 0x12345678); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
906 g_assert(fd->ref == 0); |
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 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
|
909 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
910 g_free(fd->path); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
911 g_free(fd->original_path); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
912 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
|
913 |
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_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
|
916 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
917 file_data_change_info_free(NULL, fd); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
918 g_free(fd); |
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 |
138 | 921 void file_data_unref(FileData *fd) |
922 { | |
923 if (fd == NULL) return; | |
924 g_assert(fd->magick == 0x12345678); | |
172 | 925 if (debug) printf("file_data_unref: '%s'\n", fd->path); |
138 | 926 fd->ref--; |
927 if (fd->ref == 0) | |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
928 { |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
929 FileData *parent = fd->parent ? fd->parent : fd; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
930 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
931 GList *work; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
932 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
933 if (parent->ref > 0) |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
934 return; |
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 work = parent->sidecar_files; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
937 while (work) |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
938 { |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
939 FileData *sfd = work->data; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
940 if (sfd->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 work = work->next; |
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 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
945 /* 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
|
946 |
172 | 947 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
|
948 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
949 work = parent->sidecar_files; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
950 while (work) |
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 FileData *sfd = work->data; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
953 file_data_free(sfd); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
954 work = work->next; |
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 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
957 g_list_free(parent->sidecar_files); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
958 parent->sidecar_files = NULL; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
959 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
960 file_data_free(parent); |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
961 |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
962 } |
138 | 963 } |
964 | |
167 | 965 FileData *file_data_disconnect_sidecar_file(FileData *target, FileData *sfd) |
966 { | |
967 sfd->parent = target; | |
968 g_assert(g_list_find(target->sidecar_files, sfd)); | |
969 | |
970 target->sidecar_files = g_list_remove(target->sidecar_files, sfd); | |
971 sfd->parent = NULL; | |
972 | |
973 if (sfd->ref == 0) { | |
974 file_data_free(sfd); | |
975 return NULL; | |
976 } | |
977 | |
978 return sfd; | |
979 } | |
980 | |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
981 /* compare name without extension */ |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
982 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
|
983 { |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
984 size_t len1 = fd1->extension - fd1->name; |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
985 size_t len2 = fd2->extension - fd2->name; |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
986 |
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 if (len1 > len2) return 1; |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
989 |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
990 return strncmp(fd1->name, fd2->name, len1); |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
991 } |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
992 |
240
cce347409480
Fix two more gcc warnings related to function declarations.
zas_
parents:
217
diff
changeset
|
993 void file_data_do_change(FileData *fd) |
138 | 994 { |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
995 //FIXME sidecars |
138 | 996 g_assert(fd->change); |
997 g_free(fd->path); | |
998 g_hash_table_remove(file_data_pool, fd->original_path); | |
999 g_free(fd->original_path); | |
1000 file_data_set_path(fd, fd->change->dest); | |
1001 fd->original_path = g_strdup(fd->change->dest); | |
1002 g_hash_table_insert(file_data_pool, fd->original_path, fd); | |
1003 | |
1004 } | |
1005 | |
143
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
1006 gboolean file_data_add_change_info(FileData *fd, FileDataChangeType type, const gchar *src, const gchar *dest) |
138 | 1007 { |
143
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
1008 |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
1009 FileDataChangeInfo *fdci; |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
1010 |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
1011 if (fd->change) return FALSE; |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
1012 |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
1013 fdci = g_new0(FileDataChangeInfo, 1); |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
1014 |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
1015 fdci->type = type; |
138 | 1016 |
1017 if (src) | |
1018 fdci->source = g_strdup(src); | |
143
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
1019 else |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
1020 fdci->source = g_strdup(fd->path); |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
1021 |
138 | 1022 if (dest) |
1023 fdci->dest = g_strdup(dest); | |
1024 | |
143
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
1025 fd->change = fdci; |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
141
diff
changeset
|
1026 return TRUE; |
138 | 1027 } |
1028 | |
1029 void file_data_change_info_free(FileDataChangeInfo *fdci, FileData *fd) | |
1030 { | |
1031 if (!fdci && fd) | |
1032 fdci = fd->change; | |
1033 | |
1034 if (!fdci) | |
1035 return; | |
1036 | |
1037 g_free(fdci->source); | |
1038 g_free(fdci->dest); | |
1039 | |
1040 g_free(fdci); | |
1041 | |
1042 if (fd) | |
1043 fd->change = NULL; | |
1044 } | |
139 | 1045 |
1046 | |
1047 | |
138 | 1048 |
137
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 *----------------------------------------------------------------------------- |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
1051 * sidecar file info struct |
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 */ |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
1054 |
9 | 1055 |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
1056 |
240
cce347409480
Fix two more gcc warnings related to function declarations.
zas_
parents:
217
diff
changeset
|
1057 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
|
1058 { |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
1059 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
|
1060 int i = 1; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
1061 GList *work; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
1062 if (extension == NULL) |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
1063 return 0; |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
1064 |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
1065 work = sidecar_ext_get_list(); |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
1066 |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
1067 while (work) { |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
1068 gchar *ext = work->data; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
1069 work = work->next; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
1070 if (strcmp(extension, ext) == 0) return i; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
1071 i++; |
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
1072 } |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
1073 return 0; |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
1074 } |
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
1075 |
139 | 1076 gchar *sidecar_file_data_list_to_string(FileData *fd) |
1077 { | |
1078 GList *work; | |
1079 GString *result = g_string_new(""); | |
1080 | |
1081 work = fd->sidecar_files; | |
1082 while (work) | |
1083 { | |
141 | 1084 FileData *sfd = work->data; |
139 | 1085 result = g_string_append(result, "+ "); |
1086 result = g_string_append(result, sfd->extension); | |
1087 work = work->next; | |
1088 if (work) result = g_string_append_c(result, ' '); | |
1089 } | |
1090 | |
1091 return g_string_free(result, FALSE); | |
1092 } | |
1093 | |
9 | 1094 /* |
1095 *----------------------------------------------------------------------------- | |
1096 * load file list | |
1097 *----------------------------------------------------------------------------- | |
1098 */ | |
1099 | |
1100 static SortType filelist_sort_method = SORT_NONE; | |
1101 static gint filelist_sort_ascend = TRUE; | |
1102 | |
138 | 1103 |
1104 gint filelist_sort_compare_filedata(FileData *fa, FileData *fb) | |
9 | 1105 { |
1106 if (!filelist_sort_ascend) | |
1107 { | |
138 | 1108 FileData *tmp = fa; |
1109 fa = fb; | |
1110 fb = tmp; | |
9 | 1111 } |
1112 | |
1113 switch (filelist_sort_method) | |
1114 { | |
1115 case SORT_SIZE: | |
1116 if (fa->size < fb->size) return -1; | |
1117 if (fa->size > fb->size) return 1; | |
167 | 1118 return CASE_SORT(fa->name, fb->name); /* fall back to name */ |
9 | 1119 break; |
1120 case SORT_TIME: | |
1121 if (fa->date < fb->date) return -1; | |
1122 if (fa->date > fb->date) return 1; | |
167 | 1123 return CASE_SORT(fa->name, fb->name); /* fall back to name */ |
9 | 1124 break; |
1125 #ifdef HAVE_STRVERSCMP | |
1126 case SORT_NUMBER: | |
1127 return strverscmp(fa->name, fb->name); | |
1128 break; | |
1129 #endif | |
1130 case SORT_NAME: | |
1131 default: | |
1132 return CASE_SORT(fa->name, fb->name); | |
1133 break; | |
1134 } | |
1135 } | |
1136 | |
167 | 1137 gint filelist_sort_compare_filedata_full(FileData *fa, FileData *fb, SortType method, gint ascend) |
1138 { | |
1139 filelist_sort_method = method; | |
1140 filelist_sort_ascend = ascend; | |
1141 return filelist_sort_compare_filedata(fa, fb); | |
1142 } | |
1143 | |
138 | 1144 static gint filelist_sort_file_cb(void *a, void *b) |
1145 { | |
1146 return filelist_sort_compare_filedata(a, b); | |
1147 } | |
1148 | |
1149 GList *filelist_sort_full(GList *list, SortType method, gint ascend, GCompareFunc cb) | |
9 | 1150 { |
1151 filelist_sort_method = method; | |
1152 filelist_sort_ascend = ascend; | |
138 | 1153 return g_list_sort(list, cb); |
1154 } | |
1155 | |
1156 GList *filelist_insert_sort_full(GList *list, void *data, SortType method, gint ascend, GCompareFunc cb) | |
1157 { | |
1158 filelist_sort_method = method; | |
1159 filelist_sort_ascend = ascend; | |
1160 return g_list_insert_sorted(list, data, cb); | |
1161 } | |
1162 | |
1163 GList *filelist_sort(GList *list, SortType method, gint ascend) | |
1164 { | |
1165 return filelist_sort_full(list, method, ascend, (GCompareFunc) filelist_sort_file_cb); | |
9 | 1166 } |
1167 | |
1168 GList *filelist_insert_sort(GList *list, FileData *fd, SortType method, gint ascend) | |
1169 { | |
138 | 1170 return filelist_insert_sort_full(list, fd, method, ascend, (GCompareFunc) filelist_sort_file_cb); |
9 | 1171 } |
1172 | |
137
be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
nadvornik
parents:
101
diff
changeset
|
1173 |
148 | 1174 static GList *filelist_filter_out_sidecars(GList *flist) |
1175 { | |
1176 GList *work = flist; | |
1177 GList *flist_filtered = NULL; | |
1178 | |
1179 while (work) | |
1180 { | |
1181 FileData *fd = work->data; | |
1182 work = work->next; | |
1183 if (fd->parent) /* remove fd's that are children */ | |
1184 file_data_unref(fd); | |
1185 else | |
1186 flist_filtered = g_list_prepend(flist_filtered, fd); | |
1187 } | |
1188 g_list_free(flist); | |
1189 return flist_filtered; | |
1190 } | |
1191 | |
138 | 1192 static gint filelist_read_real(const gchar *path, GList **files, GList **dirs, gint follow_symlinks) |
1 | 1193 { |
1194 DIR *dp; | |
1195 struct dirent *dir; | |
1196 struct stat ent_sbuf; | |
9 | 1197 gchar *pathl; |
1198 GList *dlist; | |
1199 GList *flist; | |
1 | 1200 |
9 | 1201 dlist = NULL; |
1202 flist = NULL; | |
1203 | |
1204 pathl = path_from_utf8(path); | |
1205 if (!pathl || (dp = opendir(pathl)) == NULL) | |
1 | 1206 { |
9 | 1207 g_free(pathl); |
1208 if (files) *files = NULL; | |
1209 if (dirs) *dirs = NULL; | |
1210 return FALSE; | |
1 | 1211 } |
1212 | |
9 | 1213 /* root dir fix */ |
1214 if (pathl[0] == '/' && pathl[1] == '\0') | |
1215 { | |
1216 g_free(pathl); | |
1217 pathl = g_strdup(""); | |
1218 } | |
1 | 1219 |
1220 while ((dir = readdir(dp)) != NULL) | |
1221 { | |
9 | 1222 gchar *name = dir->d_name; |
356 | 1223 if (options->file_filter.show_hidden_files || !ishidden(name)) |
1 | 1224 { |
9 | 1225 gchar *filepath = g_strconcat(pathl, "/", name, NULL); |
138 | 1226 if ((follow_symlinks ? |
1227 stat(filepath, &ent_sbuf) : | |
1228 lstat(filepath, &ent_sbuf)) >= 0) | |
1 | 1229 { |
9 | 1230 if (S_ISDIR(ent_sbuf.st_mode)) |
1 | 1231 { |
9 | 1232 /* we ignore the .thumbnails dir for cleanliness */ |
1233 if ((dirs) && | |
1234 !(name[0] == '.' && (name[1] == '\0' || (name[1] == '.' && name[2] == '\0'))) && | |
283 | 1235 strcmp(name, GQ_CACHE_LOCAL_THUMB) != 0 && |
1236 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
|
1237 strcmp(name, THUMB_FOLDER_LOCAL) != 0) |
9 | 1238 { |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
143
diff
changeset
|
1239 dlist = g_list_prepend(dlist, file_data_new_local(filepath, &ent_sbuf, FALSE)); |
9 | 1240 } |
1 | 1241 } |
1242 else | |
1243 { | |
9 | 1244 if ((files) && filter_name_exists(name)) |
1245 { | |
148 | 1246 flist = g_list_prepend(flist, file_data_new_local(filepath, &ent_sbuf, TRUE)); |
9 | 1247 } |
1 | 1248 } |
1249 } | |
9 | 1250 g_free(filepath); |
1 | 1251 } |
1252 } | |
1253 | |
1254 closedir(dp); | |
1255 | |
9 | 1256 g_free(pathl); |
1 | 1257 |
148 | 1258 flist = filelist_filter_out_sidecars(flist); |
1259 | |
9 | 1260 if (dirs) *dirs = dlist; |
1261 if (files) *files = flist; | |
1 | 1262 |
9 | 1263 return TRUE; |
1 | 1264 } |
1265 | |
138 | 1266 gint filelist_read(const gchar *path, GList **files, GList **dirs) |
1267 { | |
1268 return filelist_read_real(path, files, dirs, TRUE); | |
1269 } | |
1270 | |
1271 gint filelist_read_lstat(const gchar *path, GList **files, GList **dirs) | |
1272 { | |
1273 return filelist_read_real(path, files, dirs, FALSE); | |
1274 } | |
1275 | |
9 | 1276 void filelist_free(GList *list) |
1 | 1277 { |
9 | 1278 GList *work; |
3 | 1279 |
9 | 1280 work = list; |
1281 while (work) | |
1 | 1282 { |
138 | 1283 file_data_unref((FileData *)work->data); |
1 | 1284 work = work->next; |
1285 } | |
1286 | |
9 | 1287 g_list_free(list); |
3 | 1288 } |
1289 | |
1 | 1290 |
138 | 1291 GList *filelist_copy(GList *list) |
1292 { | |
1293 GList *new_list = NULL; | |
1294 GList *work; | |
1295 | |
1296 work = list; | |
1297 while (work) | |
1298 { | |
1299 FileData *fd; | |
1300 | |
1301 fd = work->data; | |
1302 work = work->next; | |
1303 | |
1304 new_list = g_list_prepend(new_list, file_data_ref(fd)); | |
1305 } | |
1306 | |
1307 return g_list_reverse(new_list); | |
1308 } | |
1309 | |
1310 GList *filelist_from_path_list(GList *list) | |
1311 { | |
1312 GList *new_list = NULL; | |
1313 GList *work; | |
1314 | |
1315 work = list; | |
1316 while (work) | |
1317 { | |
1318 gchar *path; | |
1319 | |
1320 path = work->data; | |
1321 work = work->next; | |
1322 | |
1323 new_list = g_list_prepend(new_list, file_data_new_simple(path)); | |
1324 } | |
1325 | |
1326 return g_list_reverse(new_list); | |
1327 } | |
1328 | |
1329 GList *filelist_to_path_list(GList *list) | |
1330 { | |
1331 GList *new_list = NULL; | |
1332 GList *work; | |
1333 | |
1334 work = list; | |
1335 while (work) | |
1336 { | |
1337 FileData *fd; | |
1338 | |
1339 fd = work->data; | |
1340 work = work->next; | |
1341 | |
1342 new_list = g_list_prepend(new_list, g_strdup(fd->path)); | |
1343 } | |
1344 | |
1345 return g_list_reverse(new_list); | |
1346 } | |
1347 | |
1348 GList *filelist_filter(GList *list, gint is_dir_list) | |
1349 { | |
1350 GList *work; | |
1351 | |
356 | 1352 if (!is_dir_list && options->file_filter.disable && options->file_filter.show_hidden_files) return list; |
138 | 1353 |
1354 work = list; | |
1355 while (work) | |
1356 { | |
1357 FileData *fd = (FileData *)(work->data); | |
1358 const gchar *name = fd->name; | |
1359 | |
356 | 1360 if ((!options->file_filter.show_hidden_files && ishidden(name)) || |
138 | 1361 (!is_dir_list && !filter_name_exists(name)) || |
283 | 1362 (is_dir_list && name[0] == '.' && (strcmp(name, GQ_CACHE_LOCAL_THUMB) == 0 || |
1363 strcmp(name, GQ_CACHE_LOCAL_METADATA) == 0)) ) | |
138 | 1364 { |
1365 GList *link = work; | |
1366 work = work->next; | |
1367 list = g_list_remove_link(list, link); | |
1368 file_data_unref(fd); | |
1369 g_list_free(link); | |
1370 } | |
1371 else | |
1372 { | |
1373 work = work->next; | |
1374 } | |
1375 } | |
1376 | |
1377 return list; | |
1378 } | |
1379 | |
1380 /* | |
1381 *----------------------------------------------------------------------------- | |
1382 * filelist recursive | |
1383 *----------------------------------------------------------------------------- | |
1384 */ | |
1385 | |
1386 static gint filelist_sort_path_cb(gconstpointer a, gconstpointer b) | |
1387 { | |
1388 return CASE_SORT(((FileData *)a)->path, ((FileData *)b)->path); | |
1389 } | |
1390 | |
1391 GList *filelist_sort_path(GList *list) | |
1392 { | |
1393 return g_list_sort(list, filelist_sort_path_cb); | |
1394 } | |
1395 | |
1396 static void filelist_recursive_append(GList **list, GList *dirs) | |
1397 { | |
1398 GList *work; | |
1399 | |
1400 work = dirs; | |
1401 while (work) | |
1402 { | |
1403 FileData *fd = (FileData *)(work->data); | |
1404 const gchar *path = fd->path; | |
1405 GList *f = NULL; | |
1406 GList *d = NULL; | |
1407 | |
1408 if (filelist_read(path, &f, &d)) | |
1409 { | |
1410 f = filelist_filter(f, FALSE); | |
1411 f = filelist_sort_path(f); | |
1412 *list = g_list_concat(*list, f); | |
1413 | |
1414 d = filelist_filter(d, TRUE); | |
1415 d = filelist_sort_path(d); | |
1416 filelist_recursive_append(list, d); | |
1417 filelist_free(d); | |
1418 } | |
1419 | |
1420 work = work->next; | |
1421 } | |
1422 } | |
1423 | |
1424 GList *filelist_recursive(const gchar *path) | |
1425 { | |
1426 GList *list = NULL; | |
1427 GList *d = NULL; | |
1428 | |
1429 if (!filelist_read(path, &list, &d)) return NULL; | |
1430 list = filelist_filter(list, FALSE); | |
1431 list = filelist_sort_path(list); | |
1432 | |
1433 d = filelist_filter(d, TRUE); | |
1434 d = filelist_sort_path(d); | |
1435 filelist_recursive_append(&list, d); | |
1436 filelist_free(d); | |
1437 | |
1438 return list; | |
1439 } |