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