Mercurial > geeqie
annotate src/rcfile.c @ 1321:50b325a2386e
fixed filter initialization
author | nadvornik |
---|---|
date | Wed, 25 Feb 2009 18:21:20 +0000 |
parents | 055ed09d5a03 |
children | b93b39fb30c9 |
rev | line source |
---|---|
1 | 1 /* |
196 | 2 * Geeqie |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
41
diff
changeset
|
3 * (C) 2006 John Ellis |
1284 | 4 * Copyright (C) 2008 - 2009 The Geeqie Team |
1 | 5 * |
6 * Author: John Ellis | |
7 * | |
9 | 8 * This software is released under the GNU General Public License (GNU GPL). |
9 * Please read the included file COPYING for more information. | |
10 * This software comes with no warranty of any kind, use at your own risk! | |
1 | 11 */ |
12 | |
276 | 13 #include <glib/gstdio.h> |
14 #include <errno.h> | |
9 | 15 |
281 | 16 #include "main.h" |
9 | 17 #include "rcfile.h" |
1 | 18 |
1309 | 19 #include "bar.h" |
20 #include "bar_comment.h" | |
307
667e49f52168
Move secure save code to its own files: secure_save.{c,h}.
zas_
parents:
288
diff
changeset
|
21 #include "bar_exif.h" |
1309 | 22 #include "bar_histogram.h" |
23 #include "bar_keywords.h" | |
1320 | 24 #include "bar_sort.h" |
768
ff51413f098d
Use functions to set editors name and command and ensure they are
zas_
parents:
764
diff
changeset
|
25 #include "editors.h" |
586 | 26 #include "filefilter.h" |
1023
650c02c0c8ff
Move quoted_value() and escquote_value() to misc.[ch].
zas_
parents:
1019
diff
changeset
|
27 #include "misc.h" |
858 | 28 #include "pixbuf-renderer.h" |
307
667e49f52168
Move secure save code to its own files: secure_save.{c,h}.
zas_
parents:
288
diff
changeset
|
29 #include "secure_save.h" |
9 | 30 #include "slideshow.h" |
31 #include "ui_fileops.h" | |
1309 | 32 #include "layout.h" |
33 #include "layout_util.h" | |
34 #include "bar.h" | |
35 | |
9 | 36 |
1 | 37 /* |
38 *----------------------------------------------------------------------------- | |
1309 | 39 * line write/parse routines (public) |
1 | 40 *----------------------------------------------------------------------------- |
442 | 41 */ |
42 | |
1309 | 43 void write_indent(GString *str, gint indent) |
1 | 44 { |
1309 | 45 g_string_append_printf(str, "%*s", indent * 4, ""); |
46 } | |
210
3fa93ab9b119
Improve escaping and quoting of strings saved in rc files.
zas_
parents:
209
diff
changeset
|
47 |
1309 | 48 void write_char_option(GString *str, gint indent, const gchar *label, const gchar *text) |
49 { | |
50 gchar *escval = g_markup_escape_text(text ? text : "", -1); | |
51 write_indent(str, indent); | |
52 g_string_append_printf(str, "%s = \"%s\"\n", label, escval); | |
217 | 53 g_free(escval); |
1 | 54 } |
55 | |
1309 | 56 gboolean read_char_option(const gchar *option, const gchar *label, const gchar *value, gchar **text) |
1 | 57 { |
639 | 58 if (g_ascii_strcasecmp(option, label) != 0) return FALSE; |
59 if (!text) return FALSE; | |
60 | |
61 g_free(*text); | |
1309 | 62 *text = g_strdup(value); |
639 | 63 return TRUE; |
1 | 64 } |
65 | |
267
a9adf9e1a746
Remove dependency on GTK 2.12, reported by John Vodden and Vladimir
zas_
parents:
250
diff
changeset
|
66 /* Since gdk_color_to_string() is only available since gtk 2.12 |
a9adf9e1a746
Remove dependency on GTK 2.12, reported by John Vodden and Vladimir
zas_
parents:
250
diff
changeset
|
67 * here is an equivalent stub function. */ |
a9adf9e1a746
Remove dependency on GTK 2.12, reported by John Vodden and Vladimir
zas_
parents:
250
diff
changeset
|
68 static gchar *color_to_string(GdkColor *color) |
a9adf9e1a746
Remove dependency on GTK 2.12, reported by John Vodden and Vladimir
zas_
parents:
250
diff
changeset
|
69 { |
a9adf9e1a746
Remove dependency on GTK 2.12, reported by John Vodden and Vladimir
zas_
parents:
250
diff
changeset
|
70 return g_strdup_printf("#%04X%04X%04X", color->red, color->green, color->blue); |
a9adf9e1a746
Remove dependency on GTK 2.12, reported by John Vodden and Vladimir
zas_
parents:
250
diff
changeset
|
71 } |
a9adf9e1a746
Remove dependency on GTK 2.12, reported by John Vodden and Vladimir
zas_
parents:
250
diff
changeset
|
72 |
1309 | 73 void write_color_option(GString *str, gint indent, gchar *label, GdkColor *color) |
208
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
196
diff
changeset
|
74 { |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
196
diff
changeset
|
75 if (color) |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
196
diff
changeset
|
76 { |
267
a9adf9e1a746
Remove dependency on GTK 2.12, reported by John Vodden and Vladimir
zas_
parents:
250
diff
changeset
|
77 gchar *colorstring = color_to_string(color); |
208
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
196
diff
changeset
|
78 |
1309 | 79 write_char_option(str, indent, label, colorstring); |
208
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
196
diff
changeset
|
80 g_free(colorstring); |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
196
diff
changeset
|
81 } |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
196
diff
changeset
|
82 else |
1309 | 83 write_char_option(str, indent, label, ""); |
208
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
196
diff
changeset
|
84 } |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
196
diff
changeset
|
85 |
1309 | 86 gboolean read_color_option(const gchar *option, const gchar *label, const gchar *value, GdkColor *color) |
208
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
196
diff
changeset
|
87 { |
639 | 88 if (g_ascii_strcasecmp(option, label) != 0) return FALSE; |
89 if (!color) return FALSE; | |
90 | |
1309 | 91 if (!*value) return FALSE; |
92 gdk_color_parse(value, color); | |
639 | 93 return TRUE; |
208
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
196
diff
changeset
|
94 } |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
196
diff
changeset
|
95 |
1309 | 96 void write_int_option(GString *str, gint indent, const gchar *label, gint n) |
1 | 97 { |
1309 | 98 write_indent(str, indent); |
99 g_string_append_printf(str, "%s = \"%d\"\n", label, n); | |
1 | 100 } |
101 | |
1309 | 102 gboolean read_int_option(const gchar *option, const gchar *label, const gchar *value, gint *n) |
995 | 103 { |
639 | 104 if (g_ascii_strcasecmp(option, label) != 0) return FALSE; |
105 if (!n) return FALSE; | |
106 | |
107 if (g_ascii_isdigit(value[0]) || (value[0] == '-' && g_ascii_isdigit(value[1]))) | |
351
55ee774d5bc3
Simplify read_*_option() stuff by passing pointer to option value.
zas_
parents:
350
diff
changeset
|
108 { |
55ee774d5bc3
Simplify read_*_option() stuff by passing pointer to option value.
zas_
parents:
350
diff
changeset
|
109 *n = strtol(value, NULL, 10); |
55ee774d5bc3
Simplify read_*_option() stuff by passing pointer to option value.
zas_
parents:
350
diff
changeset
|
110 } |
639 | 111 else |
112 { | |
113 if (g_ascii_strcasecmp(value, "true") == 0) | |
114 *n = 1; | |
115 else | |
116 *n = 0; | |
117 } | |
118 | |
119 return TRUE; | |
351
55ee774d5bc3
Simplify read_*_option() stuff by passing pointer to option value.
zas_
parents:
350
diff
changeset
|
120 } |
55ee774d5bc3
Simplify read_*_option() stuff by passing pointer to option value.
zas_
parents:
350
diff
changeset
|
121 |
1309 | 122 void write_uint_option(GString *str, gint indent, const gchar *label, guint n) |
380
5afe77bb563a
Introduce a new struct ViewDir to handle directory views common
zas_
parents:
377
diff
changeset
|
123 { |
1309 | 124 write_indent(str, indent); |
125 g_string_append_printf(str, "%s = \"%u\"\n", label, n); | |
380
5afe77bb563a
Introduce a new struct ViewDir to handle directory views common
zas_
parents:
377
diff
changeset
|
126 } |
5afe77bb563a
Introduce a new struct ViewDir to handle directory views common
zas_
parents:
377
diff
changeset
|
127 |
1309 | 128 gboolean read_uint_option(const gchar *option, const gchar *label, const gchar *value, guint *n) |
351
55ee774d5bc3
Simplify read_*_option() stuff by passing pointer to option value.
zas_
parents:
350
diff
changeset
|
129 { |
639 | 130 if (g_ascii_strcasecmp(option, label) != 0) return FALSE; |
131 if (!n) return FALSE; | |
132 | |
133 if (g_ascii_isdigit(value[0])) | |
9 | 134 { |
351
55ee774d5bc3
Simplify read_*_option() stuff by passing pointer to option value.
zas_
parents:
350
diff
changeset
|
135 *n = strtoul(value, NULL, 10); |
9 | 136 } |
639 | 137 else |
138 { | |
139 if (g_ascii_strcasecmp(value, "true") == 0) | |
140 *n = 1; | |
141 else | |
142 *n = 0; | |
143 } | |
144 | |
145 return TRUE; | |
9 | 146 } |
147 | |
1309 | 148 gboolean read_uint_option_clamp(const gchar *option, const gchar *label, const gchar *value, guint *n, guint min, guint max) |
858 | 149 { |
150 gboolean ret; | |
151 | |
1309 | 152 ret = read_uint_option(option, label, value, n); |
858 | 153 if (ret) *n = CLAMP(*n, min, max); |
154 | |
155 return ret; | |
156 } | |
157 | |
158 | |
1309 | 159 gboolean read_int_option_clamp(const gchar *option, const gchar *label, const gchar *value, gint *n, gint min, gint max) |
351
55ee774d5bc3
Simplify read_*_option() stuff by passing pointer to option value.
zas_
parents:
350
diff
changeset
|
160 { |
639 | 161 gboolean ret; |
162 | |
1309 | 163 ret = read_int_option(option, label, value, n); |
639 | 164 if (ret) *n = CLAMP(*n, min, max); |
165 | |
166 return ret; | |
351
55ee774d5bc3
Simplify read_*_option() stuff by passing pointer to option value.
zas_
parents:
350
diff
changeset
|
167 } |
55ee774d5bc3
Simplify read_*_option() stuff by passing pointer to option value.
zas_
parents:
350
diff
changeset
|
168 |
1309 | 169 void write_int_unit_option(GString *str, gint indent, gchar *label, gint n, gint subunits) |
9 | 170 { |
171 gint l, r; | |
172 | |
173 if (subunits > 0) | |
174 { | |
175 l = n / subunits; | |
176 r = n % subunits; | |
177 } | |
178 else | |
1 | 179 { |
9 | 180 l = n; |
181 r = 0; | |
182 } | |
183 | |
1309 | 184 write_indent(str, indent); |
185 g_string_append_printf(str, "%s = \"%d.%d\"\n", label, l, r); | |
9 | 186 } |
187 | |
1309 | 188 gboolean read_int_unit_option(const gchar *option, const gchar *label, const gchar *value, gint *n, gint subunits) |
9 | 189 { |
639 | 190 gint l, r; |
1309 | 191 gchar *ptr, *buf; |
639 | 192 |
193 if (g_ascii_strcasecmp(option, label) != 0) return FALSE; | |
194 if (!n) return FALSE; | |
9 | 195 |
1309 | 196 buf = g_strdup(value); |
197 ptr = buf; | |
639 | 198 while (*ptr != '\0' && *ptr != '.') ptr++; |
199 if (*ptr == '.') | |
200 { | |
201 *ptr = '\0'; | |
202 l = strtol(value, NULL, 10); | |
203 *ptr = '.'; | |
204 ptr++; | |
205 r = strtol(ptr, NULL, 10); | |
206 } | |
207 else | |
208 { | |
209 l = strtol(value, NULL, 10); | |
210 r = 0; | |
211 } | |
9 | 212 |
639 | 213 *n = l * subunits + r; |
1309 | 214 g_free(buf); |
215 | |
639 | 216 return TRUE; |
1 | 217 } |
218 | |
1309 | 219 void write_bool_option(GString *str, gint indent, gchar *label, gint n) |
1 | 220 { |
1309 | 221 write_indent(str, indent); |
222 g_string_append_printf(str, "%s = \"%s\"\n", label, n ? "true" : "false"); | |
1 | 223 } |
224 | |
1309 | 225 gboolean read_bool_option(const gchar *option, const gchar *label, const gchar *value, gint *n) |
1 | 226 { |
639 | 227 if (g_ascii_strcasecmp(option, label) != 0) return FALSE; |
228 if (!n) return FALSE; | |
229 | |
230 if (g_ascii_strcasecmp(value, "true") == 0 || atoi(value) != 0) | |
231 *n = TRUE; | |
232 else | |
233 *n = FALSE; | |
234 | |
235 return TRUE; | |
1 | 236 } |
237 | |
1309 | 238 /* |
239 *----------------------------------------------------------------------------- | |
240 * write fuctions for elements (private) | |
241 *----------------------------------------------------------------------------- | |
242 */ | |
243 | |
244 static void write_global_attributes(GString *outstr, gint indent) | |
245 { | |
246 // WRITE_SUBTITLE("General Options"); | |
247 | |
248 WRITE_BOOL(*options, show_icon_names); | |
249 WRITE_BOOL(*options, show_copy_path); | |
250 WRITE_SEPARATOR(); | |
251 | |
252 WRITE_BOOL(*options, tree_descend_subdirs); | |
253 WRITE_BOOL(*options, lazy_image_sync); | |
254 WRITE_BOOL(*options, update_on_time_change); | |
255 WRITE_SEPARATOR(); | |
256 | |
257 WRITE_BOOL(*options, progressive_key_scrolling); | |
258 | |
259 WRITE_UINT(*options, duplicates_similarity_threshold); | |
260 WRITE_SEPARATOR(); | |
261 | |
262 WRITE_BOOL(*options, mousewheel_scrolls); | |
263 WRITE_INT(*options, open_recent_list_maxsize); | |
264 WRITE_INT(*options, dnd_icon_size); | |
265 WRITE_BOOL(*options, place_dialogs_under_mouse); | |
266 | |
267 | |
268 // WRITE_SUBTITLE("Startup Options"); | |
269 | |
270 WRITE_BOOL(*options, startup.restore_path); | |
271 WRITE_BOOL(*options, startup.use_last_path); | |
272 WRITE_CHAR(*options, startup.path); | |
273 | |
274 | |
275 // WRITE_SUBTITLE("File operations Options"); | |
276 | |
277 WRITE_BOOL(*options, file_ops.enable_in_place_rename); | |
278 WRITE_BOOL(*options, file_ops.confirm_delete); | |
279 WRITE_BOOL(*options, file_ops.enable_delete_key); | |
280 WRITE_BOOL(*options, file_ops.safe_delete_enable); | |
281 WRITE_CHAR(*options, file_ops.safe_delete_path); | |
282 WRITE_INT(*options, file_ops.safe_delete_folder_maxsize); | |
283 | |
284 | |
285 | |
286 | |
287 // WRITE_SUBTITLE("Properties dialog Options"); | |
288 WRITE_CHAR(*options, properties.tabs_order); | |
289 | |
290 // WRITE_SUBTITLE("Image Options"); | |
291 | |
292 WRITE_UINT(*options, image.zoom_mode); | |
293 | |
294 // g_string_append_printf(outstr, "# image.zoom_mode possible values are:\n" | |
295 // "# original\n" | |
296 // "# fit\n" | |
297 // "# dont_change\n"); | |
298 // g_string_append_printf(outstr, "image.zoom_mode: "); | |
299 // switch (options->image.zoom_mode) | |
300 // { | |
301 // case ZOOM_RESET_ORIGINAL: g_string_append_printf(outstr, "original\n"); break; | |
302 // case ZOOM_RESET_FIT_WINDOW: g_string_append_printf(outstr, "fit\n"); break; | |
303 // case ZOOM_RESET_NONE: g_string_append_printf(outstr, "dont_change\n"); break; | |
304 // } | |
305 WRITE_SEPARATOR(); | |
306 WRITE_BOOL(*options, image.zoom_2pass); | |
307 WRITE_BOOL(*options, image.zoom_to_fit_allow_expand); | |
308 WRITE_UINT(*options, image.zoom_quality); | |
309 WRITE_INT(*options, image.zoom_increment); | |
310 WRITE_BOOL(*options, image.fit_window_to_image); | |
311 WRITE_BOOL(*options, image.limit_window_size); | |
312 WRITE_INT(*options, image.max_window_size); | |
313 WRITE_BOOL(*options, image.limit_autofit_size); | |
314 WRITE_INT(*options, image.max_autofit_size); | |
315 WRITE_UINT(*options, image.scroll_reset_method); | |
316 WRITE_INT(*options, image.tile_cache_max); | |
317 WRITE_INT(*options, image.image_cache_max); | |
318 WRITE_UINT(*options, image.dither_quality); | |
319 WRITE_BOOL(*options, image.enable_read_ahead); | |
320 WRITE_BOOL(*options, image.exif_rotate_enable); | |
321 WRITE_BOOL(*options, image.use_custom_border_color); | |
322 WRITE_COLOR(*options, image.border_color); | |
323 WRITE_INT(*options, image.read_buffer_size); | |
324 WRITE_INT(*options, image.idle_read_loop_count); | |
325 | |
326 // WRITE_SUBTITLE("Thumbnails Options"); | |
327 | |
328 WRITE_INT(*options, thumbnails.max_width); | |
329 WRITE_INT(*options, thumbnails.max_height); | |
330 WRITE_BOOL(*options, thumbnails.enable_caching); | |
331 WRITE_BOOL(*options, thumbnails.cache_into_dirs); | |
332 WRITE_BOOL(*options, thumbnails.fast); | |
333 WRITE_BOOL(*options, thumbnails.use_xvpics); | |
334 WRITE_BOOL(*options, thumbnails.spec_standard); | |
335 WRITE_UINT(*options, thumbnails.quality); | |
336 WRITE_BOOL(*options, thumbnails.use_exif); | |
337 | |
338 | |
339 // WRITE_SUBTITLE("File sorting Options"); | |
340 | |
341 WRITE_INT(*options, file_sort.method); | |
342 WRITE_BOOL(*options, file_sort.ascending); | |
343 WRITE_BOOL(*options, file_sort.case_sensitive); | |
344 | |
345 | |
346 // WRITE_SUBTITLE("Fullscreen Options"); | |
347 | |
348 WRITE_INT(*options, fullscreen.screen); | |
349 WRITE_BOOL(*options, fullscreen.clean_flip); | |
350 WRITE_BOOL(*options, fullscreen.disable_saver); | |
351 WRITE_BOOL(*options, fullscreen.above); | |
352 | |
353 | |
354 // WRITE_SUBTITLE("Histogram Options"); | |
355 WRITE_UINT(*options, histogram.last_channel_mode); | |
356 WRITE_UINT(*options, histogram.last_log_mode); | |
357 | |
358 | |
359 // WRITE_SUBTITLE("Image Overlay Options"); | |
360 WRITE_UINT(*options, image_overlay.common.state); | |
361 WRITE_BOOL(*options, image_overlay.common.show_at_startup); | |
362 WRITE_CHAR(*options, image_overlay.common.template_string); | |
363 WRITE_SEPARATOR(); | |
364 | |
365 // g_string_append_printf(outstr, "# these are relative positions:\n"); | |
366 // g_string_append_printf(outstr, "# x >= 0: |x| pixels from left border\n"); | |
367 // g_string_append_printf(outstr, "# x < 0 : |x| pixels from right border\n"); | |
368 // g_string_append_printf(outstr, "# y >= 0: |y| pixels from top border\n"); | |
369 // g_string_append_printf(outstr, "# y < 0 : |y| pixels from bottom border\n"); | |
370 WRITE_INT(*options, image_overlay.common.x); | |
371 WRITE_INT(*options, image_overlay.common.y); | |
372 | |
373 | |
374 // WRITE_SUBTITLE("Slideshow Options"); | |
375 | |
376 WRITE_INT_UNIT(*options, slideshow.delay, SLIDESHOW_SUBSECOND_PRECISION); | |
377 WRITE_BOOL(*options, slideshow.random); | |
378 WRITE_BOOL(*options, slideshow.repeat); | |
379 | |
380 | |
381 // WRITE_SUBTITLE("Collection Options"); | |
382 | |
383 WRITE_BOOL(*options, collections.rectangular_selection); | |
384 | |
385 | |
386 // WRITE_SUBTITLE("Filtering Options"); | |
387 | |
388 WRITE_BOOL(*options, file_filter.show_hidden_files); | |
389 WRITE_BOOL(*options, file_filter.show_dot_directory); | |
390 WRITE_BOOL(*options, file_filter.disable); | |
391 WRITE_SEPARATOR(); | |
392 | |
393 | |
394 // WRITE_SUBTITLE("Sidecars Options"); | |
395 | |
396 WRITE_CHAR(*options, sidecar.ext); | |
397 | |
398 | |
399 | |
400 // WRITE_SUBTITLE("Shell command"); | |
401 WRITE_CHAR(*options, shell.path); | |
402 WRITE_CHAR(*options, shell.options); | |
403 | |
404 | |
405 // WRITE_SUBTITLE("Helpers"); | |
406 // g_string_append_printf(outstr, "# Html browser\n"); | |
407 // g_string_append_printf(outstr, "# command_name is: the binary's name to look for in the path\n"); | |
408 // g_string_append_printf(outstr, "# If command_name is empty, the program will try various common html browsers\n"); | |
409 // g_string_append_printf(outstr, "# command_line is:\n"); | |
410 // g_string_append_printf(outstr, "# \"\" (empty string) = execute binary with html file path as command line\n"); | |
411 // g_string_append_printf(outstr, "# \"string\" = execute string and use results for command line\n"); | |
412 // g_string_append_printf(outstr, "# \"!string\" = use text following ! as command line, replacing optional %%s with html file path\n"); | |
413 WRITE_CHAR(*options, helpers.html_browser.command_name); | |
414 WRITE_CHAR(*options, helpers.html_browser.command_line); | |
415 | |
416 /* FIXME: | |
417 WRITE_SUBTITLE("Exif Options"); | |
418 g_string_append_printf(outstr, "# Display: 0: never\n" | |
419 "# 1: if set\n" | |
420 "# 2: always\n\n"); | |
421 for (i = 0; ExifUIList[i].key; i++) | |
422 { | |
423 g_string_append_printf(outstr, "exif.display."); | |
424 write_int_option(outstr, 2, (gchar *)ExifUIList[i].key, ExifUIList[i].current); | |
425 } | |
426 */ | |
427 | |
428 // WRITE_SUBTITLE("Metadata Options"); | |
429 WRITE_BOOL(*options, metadata.enable_metadata_dirs); | |
430 WRITE_BOOL(*options, metadata.save_in_image_file); | |
431 WRITE_BOOL(*options, metadata.save_legacy_IPTC); | |
432 WRITE_BOOL(*options, metadata.warn_on_write_problems); | |
433 WRITE_BOOL(*options, metadata.save_legacy_format); | |
434 WRITE_BOOL(*options, metadata.sync_grouped_files); | |
435 WRITE_BOOL(*options, metadata.confirm_write); | |
436 WRITE_INT(*options, metadata.confirm_timeout); | |
437 WRITE_BOOL(*options, metadata.confirm_after_timeout); | |
438 WRITE_BOOL(*options, metadata.confirm_on_image_change); | |
439 WRITE_BOOL(*options, metadata.confirm_on_dir_change); | |
440 | |
441 } | |
442 | |
443 static void write_color_profile(GString *outstr, gint indent) | |
444 { | |
445 gint i; | |
446 #ifndef HAVE_LCMS | |
447 g_string_append_printf(outstr, "<!-- NOTICE: %s was not built with support for color profiles,\n" | |
448 " color profile options will have no effect.\n-->\n", GQ_APPNAME); | |
449 #endif | |
450 | |
1314 | 451 WRITE_STRING("<color_profiles\n"); |
1309 | 452 indent++; |
453 WRITE_INT(options->color_profile, screen_type); | |
454 WRITE_CHAR(options->color_profile, screen_file); | |
455 WRITE_BOOL(options->color_profile, enabled); | |
456 WRITE_BOOL(options->color_profile, use_image); | |
457 WRITE_INT(options->color_profile, input_type); | |
458 indent--; | |
1314 | 459 WRITE_STRING(">\n"); |
1309 | 460 |
461 indent++; | |
462 for (i = 0; i < COLOR_PROFILE_INPUTS; i++) | |
463 { | |
1314 | 464 WRITE_STRING("<profile\n"); |
1309 | 465 indent++; |
466 write_char_option(outstr, indent, "input_file", options->color_profile.input_file[i]); | |
467 write_char_option(outstr, indent, "input_name", options->color_profile.input_name[i]); | |
468 indent--; | |
1314 | 469 WRITE_STRING("/>\n"); |
1309 | 470 } |
471 indent--; | |
1314 | 472 WRITE_STRING("</color_profiles>\n"); |
1309 | 473 } |
474 | |
639 | 475 |
1 | 476 /* |
477 *----------------------------------------------------------------------------- | |
478 * save configuration (public) | |
479 *----------------------------------------------------------------------------- | |
442 | 480 */ |
1 | 481 |
1019 | 482 gboolean save_options_to(const gchar *utf8_path, ConfOptions *options) |
1 | 483 { |
276 | 484 SecureSaveInfo *ssi; |
9 | 485 gchar *rc_pathl; |
1309 | 486 GString *outstr; |
487 gint indent = 0; | |
488 GList *work; | |
489 | |
741
0e8b802e54d5
Move code from save_options() to new save_options_to() which takes
zas_
parents:
738
diff
changeset
|
490 rc_pathl = path_from_utf8(utf8_path); |
276 | 491 ssi = secure_open(rc_pathl); |
9 | 492 g_free(rc_pathl); |
276 | 493 if (!ssi) |
1 | 494 { |
741
0e8b802e54d5
Move code from save_options() to new save_options_to() which takes
zas_
parents:
738
diff
changeset
|
495 log_printf(_("error saving config file: %s\n"), utf8_path); |
0e8b802e54d5
Move code from save_options() to new save_options_to() which takes
zas_
parents:
738
diff
changeset
|
496 return FALSE; |
1 | 497 } |
442 | 498 |
1309 | 499 outstr = g_string_new(""); |
500 g_string_append_printf(outstr, "<!--\n"); | |
501 g_string_append_printf(outstr, "######################################################################\n"); | |
502 g_string_append_printf(outstr, "# %30s config file version %-10s #\n", GQ_APPNAME, VERSION); | |
503 g_string_append_printf(outstr, "######################################################################\n"); | |
372 | 504 WRITE_SEPARATOR(); |
338
41c3cb73120f
Rename window options (moved to layout) and re-order rc file.
zas_
parents:
337
diff
changeset
|
505 |
1314 | 506 WRITE_STRING("# Note: This file is autogenerated. Options can be changed here,\n"); |
507 WRITE_STRING("# but user comments and formatting will be lost.\n"); | |
1309 | 508 WRITE_SEPARATOR(); |
1314 | 509 WRITE_STRING("-->\n"); |
1309 | 510 WRITE_SEPARATOR(); |
1314 | 511 WRITE_STRING("<global\n"); |
512 write_global_attributes(outstr, indent + 1); | |
513 WRITE_STRING(">\n"); | |
514 | |
1309 | 515 indent++; |
442 | 516 |
1309 | 517 write_color_profile(outstr, indent); |
518 | |
377 | 519 WRITE_SEPARATOR(); |
1309 | 520 filter_write_list(outstr, indent); |
335 | 521 |
1309 | 522 WRITE_SEPARATOR(); |
523 WRITE_SUBTITLE("Layout Options - defaults"); | |
1314 | 524 WRITE_STRING("<layout\n"); |
1309 | 525 layout_write_attributes(&options->layout, outstr, indent + 1); |
1314 | 526 WRITE_STRING("/>\n"); |
9 | 527 |
1309 | 528 indent--; |
1314 | 529 WRITE_STRING("</global>\n"); |
468
2df505c60459
Replace fullscreen.info and fullscreen.show_info options by:
zas_
parents:
458
diff
changeset
|
530 |
823
ed82f5bf8082
Add a comment about relative positions of image overlay in the rc file.
zas_
parents:
822
diff
changeset
|
531 WRITE_SEPARATOR(); |
1309 | 532 WRITE_SUBTITLE("Layout Options"); |
823
ed82f5bf8082
Add a comment about relative positions of image overlay in the rc file.
zas_
parents:
822
diff
changeset
|
533 |
1309 | 534 work = layout_window_list; |
535 while (work) | |
536 { | |
537 LayoutWindow *lw = work->data; | |
538 layout_write_config(lw, outstr, indent); | |
539 work = work->next; | |
1 | 540 |
1309 | 541 } |
276 | 542 |
335 | 543 |
338
41c3cb73120f
Rename window options (moved to layout) and re-order rc file.
zas_
parents:
337
diff
changeset
|
544 |
1309 | 545 secure_fputs(ssi, outstr->str); |
546 g_string_free(outstr, TRUE); | |
442 | 547 |
276 | 548 if (secure_close(ssi)) |
741
0e8b802e54d5
Move code from save_options() to new save_options_to() which takes
zas_
parents:
738
diff
changeset
|
549 { |
0e8b802e54d5
Move code from save_options() to new save_options_to() which takes
zas_
parents:
738
diff
changeset
|
550 log_printf(_("error saving config file: %s\nerror: %s\n"), utf8_path, |
0e8b802e54d5
Move code from save_options() to new save_options_to() which takes
zas_
parents:
738
diff
changeset
|
551 secsave_strerror(secsave_errno)); |
0e8b802e54d5
Move code from save_options() to new save_options_to() which takes
zas_
parents:
738
diff
changeset
|
552 return FALSE; |
0e8b802e54d5
Move code from save_options() to new save_options_to() which takes
zas_
parents:
738
diff
changeset
|
553 } |
1 | 554 |
741
0e8b802e54d5
Move code from save_options() to new save_options_to() which takes
zas_
parents:
738
diff
changeset
|
555 return TRUE; |
0e8b802e54d5
Move code from save_options() to new save_options_to() which takes
zas_
parents:
738
diff
changeset
|
556 } |
0e8b802e54d5
Move code from save_options() to new save_options_to() which takes
zas_
parents:
738
diff
changeset
|
557 |
1309 | 558 /* |
559 *----------------------------------------------------------------------------- | |
560 * loading attributes for elements (private) | |
561 *----------------------------------------------------------------------------- | |
562 */ | |
563 | |
564 | |
565 static gboolean load_global_params(const gchar **attribute_names, const gchar **attribute_values) | |
566 { | |
567 while (*attribute_names) | |
568 { | |
569 const gchar *option = *attribute_names++; | |
570 const gchar *value = *attribute_values++; | |
571 | |
572 | |
573 /* general options */ | |
1315 | 574 if (READ_BOOL(*options, show_icon_names)) continue; |
575 if (READ_BOOL(*options, show_copy_path)) continue; | |
1309 | 576 |
1315 | 577 if (READ_BOOL(*options, tree_descend_subdirs)) continue; |
578 if (READ_BOOL(*options, lazy_image_sync)) continue; | |
579 if (READ_BOOL(*options, update_on_time_change)) continue; | |
1309 | 580 |
1315 | 581 if (READ_UINT_CLAMP(*options, duplicates_similarity_threshold, 0, 100)) continue; |
1309 | 582 |
1315 | 583 if (READ_BOOL(*options, progressive_key_scrolling)) continue; |
1309 | 584 |
1315 | 585 if (READ_BOOL(*options, mousewheel_scrolls)) continue; |
1309 | 586 |
1315 | 587 if (READ_INT(*options, open_recent_list_maxsize)) continue; |
588 if (READ_INT(*options, dnd_icon_size)) continue; | |
589 if (READ_BOOL(*options, place_dialogs_under_mouse)) continue; | |
1309 | 590 |
591 /* startup options */ | |
592 | |
1315 | 593 if (READ_BOOL(*options, startup.restore_path)) continue; |
1309 | 594 |
1315 | 595 if (READ_BOOL(*options, startup.use_last_path)) continue; |
1309 | 596 |
1315 | 597 if (READ_CHAR(*options, startup.path)) continue; |
1309 | 598 |
599 | |
600 /* properties dialog options */ | |
1315 | 601 if (READ_CHAR(*options, properties.tabs_order)) continue; |
1309 | 602 |
603 /* image options */ | |
1315 | 604 if (READ_UINT_CLAMP(*options, image.zoom_mode, 0, ZOOM_RESET_NONE)) continue; |
605 if (READ_BOOL(*options, image.zoom_2pass)) continue; | |
606 if (READ_BOOL(*options, image.zoom_to_fit_allow_expand)) continue; | |
607 if (READ_BOOL(*options, image.fit_window_to_image)) continue; | |
608 if (READ_BOOL(*options, image.limit_window_size)) continue; | |
609 if (READ_INT(*options, image.max_window_size)) continue; | |
610 if (READ_BOOL(*options, image.limit_autofit_size)) continue; | |
611 if (READ_INT(*options, image.max_autofit_size)) continue; | |
612 if (READ_UINT_CLAMP(*options, image.scroll_reset_method, 0, PR_SCROLL_RESET_COUNT - 1)) continue; | |
613 if (READ_INT(*options, image.tile_cache_max)) continue; | |
614 if (READ_INT(*options, image.image_cache_max)) continue; | |
615 if (READ_UINT_CLAMP(*options, image.zoom_quality, GDK_INTERP_NEAREST, GDK_INTERP_HYPER)) continue; | |
616 if (READ_UINT_CLAMP(*options, image.dither_quality, GDK_RGB_DITHER_NONE, GDK_RGB_DITHER_MAX)) continue; | |
617 if (READ_INT(*options, image.zoom_increment)) continue; | |
618 if (READ_BOOL(*options, image.enable_read_ahead)) continue; | |
619 if (READ_BOOL(*options, image.exif_rotate_enable)) continue; | |
620 if (READ_BOOL(*options, image.use_custom_border_color)) continue; | |
621 if (READ_COLOR(*options, image.border_color)) continue; | |
622 if (READ_INT_CLAMP(*options, image.read_buffer_size, IMAGE_LOADER_READ_BUFFER_SIZE_MIN, IMAGE_LOADER_READ_BUFFER_SIZE_MAX)) continue; | |
623 if (READ_INT_CLAMP(*options, image.idle_read_loop_count, IMAGE_LOADER_IDLE_READ_LOOP_COUNT_MIN, IMAGE_LOADER_IDLE_READ_LOOP_COUNT_MAX)) continue; | |
1309 | 624 |
625 | |
626 /* thumbnails options */ | |
1315 | 627 if (READ_INT_CLAMP(*options, thumbnails.max_width, 16, 512)) continue; |
628 if (READ_INT_CLAMP(*options, thumbnails.max_height, 16, 512)) continue; | |
1309 | 629 |
1315 | 630 if (READ_BOOL(*options, thumbnails.enable_caching)) continue; |
631 if (READ_BOOL(*options, thumbnails.cache_into_dirs)) continue; | |
632 if (READ_BOOL(*options, thumbnails.fast)) continue; | |
633 if (READ_BOOL(*options, thumbnails.use_xvpics)) continue; | |
634 if (READ_BOOL(*options, thumbnails.spec_standard)) continue; | |
635 if (READ_UINT_CLAMP(*options, thumbnails.quality, GDK_INTERP_NEAREST, GDK_INTERP_HYPER)) continue; | |
636 if (READ_BOOL(*options, thumbnails.use_exif)) continue; | |
1309 | 637 |
638 /* file sorting options */ | |
1315 | 639 if (READ_UINT(*options, file_sort.method)) continue; |
640 if (READ_BOOL(*options, file_sort.ascending)) continue; | |
641 if (READ_BOOL(*options, file_sort.case_sensitive)) continue; | |
1309 | 642 |
643 /* file operations *options */ | |
1315 | 644 if (READ_BOOL(*options, file_ops.enable_in_place_rename)) continue; |
645 if (READ_BOOL(*options, file_ops.confirm_delete)) continue; | |
646 if (READ_BOOL(*options, file_ops.enable_delete_key)) continue; | |
647 if (READ_BOOL(*options, file_ops.safe_delete_enable)) continue; | |
648 if (READ_CHAR(*options, file_ops.safe_delete_path)) continue; | |
649 if (READ_INT(*options, file_ops.safe_delete_folder_maxsize)) continue; | |
1309 | 650 |
651 /* fullscreen options */ | |
1315 | 652 if (READ_INT(*options, fullscreen.screen)) continue; |
653 if (READ_BOOL(*options, fullscreen.clean_flip)) continue; | |
654 if (READ_BOOL(*options, fullscreen.disable_saver)) continue; | |
655 if (READ_BOOL(*options, fullscreen.above)) continue; | |
1309 | 656 |
657 /* histogram */ | |
1315 | 658 if (READ_UINT(*options, histogram.last_channel_mode)) continue; |
659 if (READ_UINT(*options, histogram.last_log_mode)) continue; | |
1309 | 660 |
661 /* image overlay */ | |
1315 | 662 if (READ_UINT(*options, image_overlay.common.state)) continue; |
663 if (READ_BOOL(*options, image_overlay.common.show_at_startup)) continue; | |
664 if (READ_CHAR(*options, image_overlay.common.template_string)) continue; | |
1309 | 665 |
1315 | 666 if (READ_INT(*options, image_overlay.common.x)) continue; |
667 if (READ_INT(*options, image_overlay.common.y)) continue; | |
1309 | 668 |
669 | |
670 /* slideshow options */ | |
1315 | 671 if (READ_INT_UNIT(*options, slideshow.delay, SLIDESHOW_SUBSECOND_PRECISION)) continue; |
672 if (READ_BOOL(*options, slideshow.random)) continue; | |
673 if (READ_BOOL(*options, slideshow.repeat)) continue; | |
1309 | 674 |
675 /* collection options */ | |
676 | |
1315 | 677 if (READ_BOOL(*options, collections.rectangular_selection)) continue; |
1309 | 678 |
679 /* filtering options */ | |
680 | |
1315 | 681 if (READ_BOOL(*options, file_filter.show_hidden_files)) continue; |
682 if (READ_BOOL(*options, file_filter.show_dot_directory)) continue; | |
683 if (READ_BOOL(*options, file_filter.disable)) continue; | |
684 if (READ_CHAR(*options, sidecar.ext)) continue; | |
1309 | 685 |
686 /* Color Profiles */ | |
687 | |
688 /* Shell command */ | |
1315 | 689 if (READ_CHAR(*options, shell.path)) continue; |
690 if (READ_CHAR(*options, shell.options)) continue; | |
1309 | 691 |
692 /* Helpers */ | |
1315 | 693 if (READ_CHAR(*options, helpers.html_browser.command_name)) continue; |
694 if (READ_CHAR(*options, helpers.html_browser.command_line)) continue; | |
1309 | 695 /* Exif */ |
696 /* | |
697 if (0 == g_ascii_strncasecmp(option, "exif.display.", 13)) | |
698 { | |
699 for (i = 0; ExifUIList[i].key; i++) | |
700 if (0 == g_ascii_strcasecmp(option + 13, ExifUIList[i].key)) | |
701 ExifUIList[i].current = strtol(value, NULL, 10); | |
702 continue; | |
703 } | |
704 */ | |
705 /* metadata */ | |
1315 | 706 if (READ_BOOL(*options, metadata.enable_metadata_dirs)) continue; |
707 if (READ_BOOL(*options, metadata.save_in_image_file)) continue; | |
708 if (READ_BOOL(*options, metadata.save_legacy_IPTC)) continue; | |
709 if (READ_BOOL(*options, metadata.warn_on_write_problems)) continue; | |
710 if (READ_BOOL(*options, metadata.save_legacy_format)) continue; | |
711 if (READ_BOOL(*options, metadata.sync_grouped_files)) continue; | |
712 if (READ_BOOL(*options, metadata.confirm_write)) continue; | |
713 if (READ_BOOL(*options, metadata.confirm_after_timeout)) continue; | |
714 if (READ_INT(*options, metadata.confirm_timeout)) continue; | |
715 if (READ_BOOL(*options, metadata.confirm_on_image_change)) continue; | |
716 if (READ_BOOL(*options, metadata.confirm_on_dir_change)) continue; | |
1309 | 717 |
718 DEBUG_1("unknown attribute %s = %s", option, value); | |
719 } | |
720 | |
721 return TRUE; | |
722 } | |
723 | |
724 static void options_load_color_profiles(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer data, GError **error) | |
725 { | |
726 while (*attribute_names) | |
727 { | |
728 const gchar *option = *attribute_names++; | |
729 const gchar *value = *attribute_values++; | |
730 | |
731 | |
1315 | 732 if (READ_BOOL(options->color_profile, enabled)) continue; |
733 if (READ_BOOL(options->color_profile, use_image)) continue; | |
734 if (READ_INT(options->color_profile, input_type)) continue; | |
735 if (READ_INT(options->color_profile, screen_type)) continue; | |
736 if (READ_CHAR(options->color_profile, screen_file)) continue; | |
1309 | 737 |
738 DEBUG_1("unknown attribute %s = %s", option, value); | |
739 } | |
740 | |
741 } | |
742 | |
743 static void options_load_profile(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer data, GError **error) | |
744 { | |
745 gint i = GPOINTER_TO_INT(data); | |
746 if (i < 0 || i >= COLOR_PROFILE_INPUTS) return; | |
747 while (*attribute_names) | |
748 { | |
749 const gchar *option = *attribute_names++; | |
750 const gchar *value = *attribute_values++; | |
751 | |
1315 | 752 if (READ_CHAR_FULL("input_file", options->color_profile.input_file[i])) continue; |
753 if (READ_CHAR_FULL("input_name", options->color_profile.input_name[i])) continue; | |
1309 | 754 |
755 | |
756 DEBUG_1("unknown attribute %s = %s", option, value); | |
757 } | |
758 i++; | |
759 options_parse_func_set_data(parser_data, GINT_TO_POINTER(i)); | |
760 | |
761 } | |
762 | |
763 | |
764 | |
765 /* | |
766 *----------------------------------------------------------------------------- | |
767 * xml file structure (private) | |
768 *----------------------------------------------------------------------------- | |
769 */ | |
1313 | 770 struct _GQParserData |
771 { | |
772 GList *parse_func_stack; | |
773 gboolean startup; /* reading config for the first time - add commandline and call init_after_global_options() */ | |
774 gboolean global_found; | |
775 }; | |
1 | 776 |
741
0e8b802e54d5
Move code from save_options() to new save_options_to() which takes
zas_
parents:
738
diff
changeset
|
777 |
1309 | 778 void options_parse_leaf(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer data, GError **error) |
779 { | |
780 DEBUG_1("unexpected: %s", element_name); | |
781 options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); | |
782 } | |
783 | |
784 static void options_parse_color_profiles(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer data, GError **error) | |
785 { | |
786 if (g_ascii_strcasecmp(element_name, "profile") == 0) | |
787 { | |
788 options_load_profile(parser_data, context, element_name, attribute_names, attribute_values, data, error); | |
789 options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); | |
790 } | |
791 else | |
792 { | |
793 DEBUG_1("unexpected profile: %s", element_name); | |
794 options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); | |
795 } | |
796 } | |
797 | |
798 static void options_parse_filter(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer data, GError **error) | |
799 { | |
800 if (g_ascii_strcasecmp(element_name, "file_type") == 0) | |
801 { | |
802 filter_load_file_type(attribute_names, attribute_values); | |
803 options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); | |
804 } | |
805 else | |
806 { | |
807 DEBUG_1("unexpected filter: %s", element_name); | |
808 options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); | |
809 } | |
810 } | |
811 | |
812 static void options_parse_filter_end(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, gpointer data, GError **error) | |
813 { | |
1321 | 814 if (!parser_data->startup) filter_rebuild(); |
815 /* else this is called in init_after_global_options */ | |
1309 | 816 } |
817 | |
818 static void options_parse_global(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer data, GError **error) | |
819 { | |
820 if (g_ascii_strcasecmp(element_name, "color_profiles") == 0) | |
821 { | |
822 options_load_color_profiles(parser_data, context, element_name, attribute_names, attribute_values, data, error); | |
823 options_parse_func_push(parser_data, options_parse_color_profiles, NULL, GINT_TO_POINTER(0)); | |
824 } | |
825 else if (g_ascii_strcasecmp(element_name, "filter") == 0) | |
826 { | |
827 options_parse_func_push(parser_data, options_parse_filter, options_parse_filter_end, NULL); | |
828 } | |
829 else if (g_ascii_strcasecmp(element_name, "layout") == 0) | |
830 { | |
831 layout_load_attributes(&options->layout, attribute_names, attribute_values); | |
832 options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); | |
833 } | |
834 else | |
835 { | |
836 DEBUG_1("unexpected global: %s", element_name); | |
837 options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); | |
838 } | |
839 } | |
840 | |
841 static void options_parse_bar(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer data, GError **error) | |
842 { | |
843 GtkWidget *bar = data; | |
844 if (g_ascii_strcasecmp(element_name, "pane_comment") == 0) | |
845 { | |
846 GtkWidget *pane = bar_pane_comment_new_from_config(attribute_names, attribute_values); | |
847 bar_add(bar, pane); | |
848 options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); | |
849 } | |
850 else if (g_ascii_strcasecmp(element_name, "pane_exif") == 0) | |
851 { | |
852 GtkWidget *pane = bar_pane_exif_new_from_config(attribute_names, attribute_values); | |
853 bar_add(bar, pane); | |
854 options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); | |
855 } | |
856 else if (g_ascii_strcasecmp(element_name, "pane_histogram") == 0) | |
857 { | |
858 GtkWidget *pane = bar_pane_histogram_new_from_config(attribute_names, attribute_values); | |
859 bar_add(bar, pane); | |
860 options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); | |
861 } | |
862 else if (g_ascii_strcasecmp(element_name, "pane_keywords") == 0) | |
863 { | |
864 GtkWidget *pane = bar_pane_keywords_new_from_config(attribute_names, attribute_values); | |
865 bar_add(bar, pane); | |
866 options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); | |
867 } | |
868 else | |
869 { | |
870 DEBUG_1("unexpected in <bar>: <%s>", element_name); | |
871 options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); | |
872 } | |
873 } | |
874 | |
875 static void options_parse_layout(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer data, GError **error) | |
876 { | |
877 LayoutWindow *lw = data; | |
878 if (g_ascii_strcasecmp(element_name, "bar") == 0) | |
879 { | |
1317 | 880 GtkWidget *bar = bar_new_from_config(lw->utility_box, attribute_names, attribute_values); |
881 layout_bar_set(lw, bar); | |
1309 | 882 options_parse_func_push(parser_data, options_parse_bar, NULL, lw->bar); |
883 } | |
1320 | 884 else if (g_ascii_strcasecmp(element_name, "bar_sort") == 0) |
885 { | |
886 GtkWidget *bar = bar_sort_new_from_config(lw, attribute_names, attribute_values); | |
887 layout_bar_sort_set(lw, bar); | |
888 options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); | |
889 } | |
1309 | 890 else |
891 { | |
892 DEBUG_1("unexpected in <layout>: <%s>", element_name); | |
893 options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); | |
894 } | |
895 } | |
896 | |
1317 | 897 static void options_parse_layout_end(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, gpointer data, GError **error) |
898 { | |
899 LayoutWindow *lw = data; | |
900 layout_util_sync(lw); | |
901 } | |
902 | |
1309 | 903 static void options_parse_toplevel(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer data, GError **error) |
904 { | |
905 if (g_ascii_strcasecmp(element_name, "global") == 0) | |
906 { | |
907 load_global_params(attribute_names, attribute_values); | |
1313 | 908 options_parse_func_push(parser_data, options_parse_global, NULL, NULL); |
909 return; | |
1309 | 910 } |
1313 | 911 |
912 if (parser_data->startup && !parser_data->global_found) | |
913 { | |
914 DEBUG_1(" global end"); | |
915 parser_data->global_found = TRUE; | |
916 init_after_global_options(); | |
917 } | |
918 | |
919 if (g_ascii_strcasecmp(element_name, "layout") == 0) | |
1309 | 920 { |
921 LayoutWindow *lw; | |
1313 | 922 lw = layout_new_from_config(attribute_names, attribute_values, parser_data->startup); |
1317 | 923 options_parse_func_push(parser_data, options_parse_layout, options_parse_layout_end, lw); |
1309 | 924 } |
925 else | |
926 { | |
927 DEBUG_1("unexpected in <toplevel>: <%s>", element_name); | |
928 options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); | |
929 } | |
930 } | |
931 | |
932 | |
933 | |
934 | |
935 | |
936 /* | |
937 *----------------------------------------------------------------------------- | |
938 * parser | |
939 *----------------------------------------------------------------------------- | |
940 */ | |
941 | |
942 | |
943 struct _GQParserFuncData | |
944 { | |
945 GQParserStartFunc start_func; | |
946 GQParserEndFunc end_func; | |
947 // GQParserTextFunc text_func; | |
948 gpointer data; | |
949 }; | |
950 | |
951 void options_parse_func_push(GQParserData *parser_data, GQParserStartFunc start_func, GQParserEndFunc end_func, gpointer data) | |
952 { | |
953 GQParserFuncData *func_data = g_new0(GQParserFuncData, 1); | |
954 func_data->start_func = start_func; | |
955 func_data->end_func = end_func; | |
956 func_data->data = data; | |
957 | |
958 parser_data->parse_func_stack = g_list_prepend(parser_data->parse_func_stack, func_data); | |
959 } | |
960 | |
961 void options_parse_func_pop(GQParserData *parser_data) | |
962 { | |
963 g_free(parser_data->parse_func_stack->data); | |
964 parser_data->parse_func_stack = g_list_delete_link(parser_data->parse_func_stack, parser_data->parse_func_stack); | |
965 } | |
966 | |
967 void options_parse_func_set_data(GQParserData *parser_data, gpointer data) | |
968 { | |
969 GQParserFuncData *func = parser_data->parse_func_stack->data; | |
970 func->data = data; | |
971 } | |
972 | |
973 | |
974 static void start_element(GMarkupParseContext *context, | |
975 const gchar *element_name, | |
976 const gchar **attribute_names, | |
977 const gchar **attribute_values, | |
978 gpointer user_data, | |
979 GError **error) | |
980 { | |
981 GQParserData *parser_data = user_data; | |
982 GQParserFuncData *func = parser_data->parse_func_stack->data; | |
983 DEBUG_1("start %s", element_name); | |
984 | |
985 if (func->start_func) | |
986 func->start_func(parser_data, context, element_name, attribute_names, attribute_values, func->data, error); | |
987 } | |
988 | |
989 static void end_element(GMarkupParseContext *context, | |
990 const gchar *element_name, | |
991 gpointer user_data, | |
992 GError **error) | |
993 { | |
994 GQParserData *parser_data = user_data; | |
995 GQParserFuncData *func = parser_data->parse_func_stack->data; | |
996 DEBUG_1("end %s", element_name); | |
997 | |
998 if (func->end_func) | |
999 func->end_func(parser_data, context, element_name, func->data, error); | |
1000 | |
1001 options_parse_func_pop(parser_data); | |
1002 } | |
1003 | |
1004 static GMarkupParser parser = { | |
1005 start_element, | |
1006 end_element, | |
1007 NULL, | |
1008 NULL, | |
1009 NULL | |
1010 }; | |
741
0e8b802e54d5
Move code from save_options() to new save_options_to() which takes
zas_
parents:
738
diff
changeset
|
1011 |
1 | 1012 /* |
1013 *----------------------------------------------------------------------------- | |
1014 * load configuration (public) | |
1015 *----------------------------------------------------------------------------- | |
442 | 1016 */ |
1 | 1017 |
1313 | 1018 gboolean load_options_from(const gchar *utf8_path, ConfOptions *options, gboolean startup) |
1 | 1019 { |
1309 | 1020 gsize size; |
1021 gchar *buf; | |
1022 GMarkupParseContext *context; | |
1023 gboolean ret = TRUE; | |
1024 GQParserData *parser_data; | |
630
83d3ded39e49
An option to save and restore the last path used was added.
zas_
parents:
629
diff
changeset
|
1025 |
1309 | 1026 if (g_file_get_contents (utf8_path, &buf, &size, NULL) == FALSE) |
1027 { | |
1028 return FALSE; | |
1029 } | |
629 | 1030 |
1309 | 1031 parser_data = g_new0(GQParserData, 1); |
1313 | 1032 |
1033 parser_data->startup = startup; | |
1309 | 1034 options_parse_func_push(parser_data, options_parse_toplevel, NULL, NULL); |
764
ae618ebec3e9
Save properties window width and height to rc file and restore
zas_
parents:
743
diff
changeset
|
1035 |
1309 | 1036 context = g_markup_parse_context_new(&parser, 0, parser_data, NULL); |
338
41c3cb73120f
Rename window options (moved to layout) and re-order rc file.
zas_
parents:
337
diff
changeset
|
1037 |
1309 | 1038 if (g_markup_parse_context_parse (context, buf, size, NULL) == FALSE) |
1039 { | |
1040 ret = FALSE; | |
1041 DEBUG_1("Parse failed"); | |
1042 } | |
1043 | |
1044 g_free(parser_data); | |
684 | 1045 |
1309 | 1046 g_free(buf); |
1047 g_markup_parse_context_free (context); | |
1048 return ret; | |
1049 } | |
1050 | |
442 | 1051 |
1 | 1052 |
1055
1646720364cf
Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents:
1023
diff
changeset
|
1053 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |