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