4 * Copyright (C) 2008 - 2009 The Geeqie Team
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!
13 #include <glib/gstdio.h>
20 #include "bar_comment.h"
22 #include "bar_histogram.h"
23 #include "bar_keywords.h"
26 #include "filefilter.h"
28 #include "pixbuf-renderer.h"
29 #include "secure_save.h"
30 #include "slideshow.h"
31 #include "ui_fileops.h"
33 #include "layout_util.h"
38 *-----------------------------------------------------------------------------
39 * line write/parse routines (public)
40 *-----------------------------------------------------------------------------
43 void write_indent(GString *str, gint indent)
45 g_string_append_printf(str, "%*s", indent * 4, "");
48 void write_char_option(GString *str, gint indent, const gchar *label, const gchar *text)
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);
56 gboolean read_char_option(const gchar *option, const gchar *label, const gchar *value, gchar **text)
58 if (g_ascii_strcasecmp(option, label) != 0) return FALSE;
59 if (!text) return FALSE;
62 *text = g_strdup(value);
66 /* Since gdk_color_to_string() is only available since gtk 2.12
67 * here is an equivalent stub function. */
68 static gchar *color_to_string(GdkColor *color)
70 return g_strdup_printf("#%04X%04X%04X", color->red, color->green, color->blue);
73 void write_color_option(GString *str, gint indent, gchar *label, GdkColor *color)
77 gchar *colorstring = color_to_string(color);
79 write_char_option(str, indent, label, colorstring);
83 write_char_option(str, indent, label, "");
86 gboolean read_color_option(const gchar *option, const gchar *label, const gchar *value, GdkColor *color)
88 if (g_ascii_strcasecmp(option, label) != 0) return FALSE;
89 if (!color) return FALSE;
91 if (!*value) return FALSE;
92 gdk_color_parse(value, color);
96 void write_int_option(GString *str, gint indent, const gchar *label, gint n)
98 write_indent(str, indent);
99 g_string_append_printf(str, "%s = \"%d\"\n", label, n);
102 gboolean read_int_option(const gchar *option, const gchar *label, const gchar *value, gint *n)
104 if (g_ascii_strcasecmp(option, label) != 0) return FALSE;
105 if (!n) return FALSE;
107 if (g_ascii_isdigit(value[0]) || (value[0] == '-' && g_ascii_isdigit(value[1])))
109 *n = strtol(value, NULL, 10);
113 if (g_ascii_strcasecmp(value, "true") == 0)
122 void write_uint_option(GString *str, gint indent, const gchar *label, guint n)
124 write_indent(str, indent);
125 g_string_append_printf(str, "%s = \"%u\"\n", label, n);
128 gboolean read_uint_option(const gchar *option, const gchar *label, const gchar *value, guint *n)
130 if (g_ascii_strcasecmp(option, label) != 0) return FALSE;
131 if (!n) return FALSE;
133 if (g_ascii_isdigit(value[0]))
135 *n = strtoul(value, NULL, 10);
139 if (g_ascii_strcasecmp(value, "true") == 0)
148 gboolean read_uint_option_clamp(const gchar *option, const gchar *label, const gchar *value, guint *n, guint min, guint max)
152 ret = read_uint_option(option, label, value, n);
153 if (ret) *n = CLAMP(*n, min, max);
159 gboolean read_int_option_clamp(const gchar *option, const gchar *label, const gchar *value, gint *n, gint min, gint max)
163 ret = read_int_option(option, label, value, n);
164 if (ret) *n = CLAMP(*n, min, max);
169 void write_int_unit_option(GString *str, gint indent, gchar *label, gint n, gint subunits)
184 write_indent(str, indent);
185 g_string_append_printf(str, "%s = \"%d.%d\"\n", label, l, r);
188 gboolean read_int_unit_option(const gchar *option, const gchar *label, const gchar *value, gint *n, gint subunits)
193 if (g_ascii_strcasecmp(option, label) != 0) return FALSE;
194 if (!n) return FALSE;
196 buf = g_strdup(value);
198 while (*ptr != '\0' && *ptr != '.') ptr++;
202 l = strtol(value, NULL, 10);
205 r = strtol(ptr, NULL, 10);
209 l = strtol(value, NULL, 10);
213 *n = l * subunits + r;
219 void write_bool_option(GString *str, gint indent, gchar *label, gint n)
221 write_indent(str, indent);
222 g_string_append_printf(str, "%s = \"%s\"\n", label, n ? "true" : "false");
225 gboolean read_bool_option(const gchar *option, const gchar *label, const gchar *value, gint *n)
227 if (g_ascii_strcasecmp(option, label) != 0) return FALSE;
228 if (!n) return FALSE;
230 if (g_ascii_strcasecmp(value, "true") == 0 || atoi(value) != 0)
239 *-----------------------------------------------------------------------------
240 * write fuctions for elements (private)
241 *-----------------------------------------------------------------------------
244 static void write_global_attributes(GString *outstr, gint indent)
246 // WRITE_SUBTITLE("General Options");
248 WRITE_BOOL(*options, show_icon_names);
249 WRITE_BOOL(*options, show_copy_path);
252 WRITE_BOOL(*options, tree_descend_subdirs);
253 WRITE_BOOL(*options, lazy_image_sync);
254 WRITE_BOOL(*options, update_on_time_change);
257 WRITE_BOOL(*options, progressive_key_scrolling);
259 WRITE_UINT(*options, duplicates_similarity_threshold);
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);
268 // WRITE_SUBTITLE("Startup Options");
270 WRITE_BOOL(*options, startup.restore_path);
271 WRITE_BOOL(*options, startup.use_last_path);
272 WRITE_CHAR(*options, startup.path);
275 // WRITE_SUBTITLE("File operations Options");
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);
287 // WRITE_SUBTITLE("Properties dialog Options");
288 WRITE_CHAR(*options, properties.tabs_order);
290 // WRITE_SUBTITLE("Image Options");
292 WRITE_UINT(*options, image.zoom_mode);
294 // g_string_append_printf(outstr, "# image.zoom_mode possible values are:\n"
297 // "# dont_change\n");
298 // g_string_append_printf(outstr, "image.zoom_mode: ");
299 // switch (options->image.zoom_mode)
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;
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);
326 // WRITE_SUBTITLE("Thumbnails Options");
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);
339 // WRITE_SUBTITLE("File sorting Options");
341 WRITE_INT(*options, file_sort.method);
342 WRITE_BOOL(*options, file_sort.ascending);
343 WRITE_BOOL(*options, file_sort.case_sensitive);
346 // WRITE_SUBTITLE("Fullscreen Options");
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);
354 // WRITE_SUBTITLE("Histogram Options");
355 WRITE_UINT(*options, histogram.last_channel_mode);
356 WRITE_UINT(*options, histogram.last_log_mode);
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);
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);
374 // WRITE_SUBTITLE("Slideshow Options");
376 WRITE_INT_UNIT(*options, slideshow.delay, SLIDESHOW_SUBSECOND_PRECISION);
377 WRITE_BOOL(*options, slideshow.random);
378 WRITE_BOOL(*options, slideshow.repeat);
381 // WRITE_SUBTITLE("Collection Options");
383 WRITE_BOOL(*options, collections.rectangular_selection);
386 // WRITE_SUBTITLE("Filtering Options");
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);
394 // WRITE_SUBTITLE("Sidecars Options");
396 WRITE_CHAR(*options, sidecar.ext);
400 // WRITE_SUBTITLE("Shell command");
401 WRITE_CHAR(*options, shell.path);
402 WRITE_CHAR(*options, shell.options);
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);
417 WRITE_SUBTITLE("Exif Options");
418 g_string_append_printf(outstr, "# Display: 0: never\n"
421 for (i = 0; ExifUIList[i].key; i++)
423 g_string_append_printf(outstr, "exif.display.");
424 write_int_option(outstr, 2, (gchar *)ExifUIList[i].key, ExifUIList[i].current);
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);
443 static void write_color_profile(GString *outstr, gint indent)
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);
451 WRITE_STRING("<color_profiles\n");
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);
462 for (i = 0; i < COLOR_PROFILE_INPUTS; i++)
464 WRITE_STRING("<profile\n");
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]);
469 WRITE_STRING("/>\n");
472 WRITE_STRING("</color_profiles>\n");
477 *-----------------------------------------------------------------------------
478 * save configuration (public)
479 *-----------------------------------------------------------------------------
482 gboolean save_options_to(const gchar *utf8_path, ConfOptions *options)
490 rc_pathl = path_from_utf8(utf8_path);
491 ssi = secure_open(rc_pathl);
495 log_printf(_("error saving config file: %s\n"), utf8_path);
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");
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");
509 WRITE_STRING("-->\n");
511 WRITE_STRING("<global\n");
512 write_global_attributes(outstr, indent + 1);
517 write_color_profile(outstr, indent);
520 filter_write_list(outstr, indent);
523 WRITE_SUBTITLE("Layout Options - defaults");
524 WRITE_STRING("<layout\n");
525 layout_write_attributes(&options->layout, outstr, indent + 1);
526 WRITE_STRING("/>\n");
529 WRITE_STRING("</global>\n");
532 WRITE_SUBTITLE("Layout Options");
534 work = layout_window_list;
537 LayoutWindow *lw = work->data;
538 layout_write_config(lw, outstr, indent);
545 secure_fputs(ssi, outstr->str);
546 g_string_free(outstr, TRUE);
548 if (secure_close(ssi))
550 log_printf(_("error saving config file: %s\nerror: %s\n"), utf8_path,
551 secsave_strerror(secsave_errno));
559 *-----------------------------------------------------------------------------
560 * loading attributes for elements (private)
561 *-----------------------------------------------------------------------------
565 static gboolean load_global_params(const gchar **attribute_names, const gchar **attribute_values)
567 while (*attribute_names)
569 const gchar *option = *attribute_names++;
570 const gchar *value = *attribute_values++;
573 /* general options */
574 if (READ_BOOL(*options, show_icon_names)) continue;
575 if (READ_BOOL(*options, show_copy_path)) continue;
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;
581 if (READ_UINT_CLAMP(*options, duplicates_similarity_threshold, 0, 100)) continue;
583 if (READ_BOOL(*options, progressive_key_scrolling)) continue;
585 if (READ_BOOL(*options, mousewheel_scrolls)) continue;
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;
591 /* startup options */
593 if (READ_BOOL(*options, startup.restore_path)) continue;
595 if (READ_BOOL(*options, startup.use_last_path)) continue;
597 if (READ_CHAR(*options, startup.path)) continue;
600 /* properties dialog options */
601 if (READ_CHAR(*options, properties.tabs_order)) continue;
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;
626 /* thumbnails options */
627 if (READ_INT_CLAMP(*options, thumbnails.max_width, 16, 512)) continue;
628 if (READ_INT_CLAMP(*options, thumbnails.max_height, 16, 512)) continue;
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;
638 /* file sorting options */
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;
643 /* file operations *options */
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;
651 /* fullscreen options */
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;
658 if (READ_UINT(*options, histogram.last_channel_mode)) continue;
659 if (READ_UINT(*options, histogram.last_log_mode)) continue;
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;
666 if (READ_INT(*options, image_overlay.common.x)) continue;
667 if (READ_INT(*options, image_overlay.common.y)) continue;
670 /* slideshow options */
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;
675 /* collection options */
677 if (READ_BOOL(*options, collections.rectangular_selection)) continue;
679 /* filtering options */
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;
689 if (READ_CHAR(*options, shell.path)) continue;
690 if (READ_CHAR(*options, shell.options)) continue;
693 if (READ_CHAR(*options, helpers.html_browser.command_name)) continue;
694 if (READ_CHAR(*options, helpers.html_browser.command_line)) continue;
697 if (0 == g_ascii_strncasecmp(option, "exif.display.", 13))
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);
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;
718 DEBUG_1("unknown attribute %s = %s", option, value);
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)
726 while (*attribute_names)
728 const gchar *option = *attribute_names++;
729 const gchar *value = *attribute_values++;
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;
738 DEBUG_1("unknown attribute %s = %s", option, value);
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)
745 gint i = GPOINTER_TO_INT(data);
746 if (i < 0 || i >= COLOR_PROFILE_INPUTS) return;
747 while (*attribute_names)
749 const gchar *option = *attribute_names++;
750 const gchar *value = *attribute_values++;
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;
756 DEBUG_1("unknown attribute %s = %s", option, value);
759 options_parse_func_set_data(parser_data, GINT_TO_POINTER(i));
766 *-----------------------------------------------------------------------------
767 * xml file structure (private)
768 *-----------------------------------------------------------------------------
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;
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)
780 DEBUG_1("unexpected: %s", element_name);
781 options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL);
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)
786 if (g_ascii_strcasecmp(element_name, "profile") == 0)
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);
793 DEBUG_1("unexpected profile: %s", element_name);
794 options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL);
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)
800 if (g_ascii_strcasecmp(element_name, "file_type") == 0)
802 filter_load_file_type(attribute_names, attribute_values);
803 options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL);
807 DEBUG_1("unexpected filter: %s", element_name);
808 options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL);
812 static void options_parse_filter_end(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, gpointer data, GError **error)
814 if (!parser_data->startup) filter_rebuild();
815 /* else this is called in init_after_global_options */
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)
820 if (g_ascii_strcasecmp(element_name, "color_profiles") == 0)
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));
825 else if (g_ascii_strcasecmp(element_name, "filter") == 0)
827 options_parse_func_push(parser_data, options_parse_filter, options_parse_filter_end, NULL);
829 else if (g_ascii_strcasecmp(element_name, "layout") == 0)
831 layout_load_attributes(&options->layout, attribute_names, attribute_values);
832 options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL);
836 DEBUG_1("unexpected global: %s", element_name);
837 options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL);
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)
843 GtkWidget *bar = data;
844 if (g_ascii_strcasecmp(element_name, "pane_comment") == 0)
846 GtkWidget *pane = bar_pane_comment_new_from_config(attribute_names, attribute_values);
848 options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL);
850 else if (g_ascii_strcasecmp(element_name, "pane_exif") == 0)
852 GtkWidget *pane = bar_pane_exif_new_from_config(attribute_names, attribute_values);
854 options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL);
856 else if (g_ascii_strcasecmp(element_name, "pane_histogram") == 0)
858 GtkWidget *pane = bar_pane_histogram_new_from_config(attribute_names, attribute_values);
860 options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL);
862 else if (g_ascii_strcasecmp(element_name, "pane_keywords") == 0)
864 GtkWidget *pane = bar_pane_keywords_new_from_config(attribute_names, attribute_values);
866 options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL);
870 DEBUG_1("unexpected in <bar>: <%s>", element_name);
871 options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL);
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)
877 LayoutWindow *lw = data;
878 if (g_ascii_strcasecmp(element_name, "bar") == 0)
880 GtkWidget *bar = bar_new_from_config(lw->utility_box, attribute_names, attribute_values);
881 layout_bar_set(lw, bar);
882 options_parse_func_push(parser_data, options_parse_bar, NULL, lw->bar);
884 else if (g_ascii_strcasecmp(element_name, "bar_sort") == 0)
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);
892 DEBUG_1("unexpected in <layout>: <%s>", element_name);
893 options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL);
897 static void options_parse_layout_end(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, gpointer data, GError **error)
899 LayoutWindow *lw = data;
900 layout_util_sync(lw);
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)
905 if (g_ascii_strcasecmp(element_name, "global") == 0)
907 load_global_params(attribute_names, attribute_values);
908 options_parse_func_push(parser_data, options_parse_global, NULL, NULL);
912 if (parser_data->startup && !parser_data->global_found)
914 DEBUG_1(" global end");
915 parser_data->global_found = TRUE;
916 init_after_global_options();
919 if (g_ascii_strcasecmp(element_name, "layout") == 0)
922 lw = layout_new_from_config(attribute_names, attribute_values, parser_data->startup);
923 options_parse_func_push(parser_data, options_parse_layout, options_parse_layout_end, lw);
927 DEBUG_1("unexpected in <toplevel>: <%s>", element_name);
928 options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL);
937 *-----------------------------------------------------------------------------
939 *-----------------------------------------------------------------------------
943 struct _GQParserFuncData
945 GQParserStartFunc start_func;
946 GQParserEndFunc end_func;
947 // GQParserTextFunc text_func;
951 void options_parse_func_push(GQParserData *parser_data, GQParserStartFunc start_func, GQParserEndFunc end_func, gpointer data)
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;
958 parser_data->parse_func_stack = g_list_prepend(parser_data->parse_func_stack, func_data);
961 void options_parse_func_pop(GQParserData *parser_data)
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);
967 void options_parse_func_set_data(GQParserData *parser_data, gpointer data)
969 GQParserFuncData *func = parser_data->parse_func_stack->data;
974 static void start_element(GMarkupParseContext *context,
975 const gchar *element_name,
976 const gchar **attribute_names,
977 const gchar **attribute_values,
981 GQParserData *parser_data = user_data;
982 GQParserFuncData *func = parser_data->parse_func_stack->data;
983 DEBUG_1("start %s", element_name);
985 if (func->start_func)
986 func->start_func(parser_data, context, element_name, attribute_names, attribute_values, func->data, error);
989 static void end_element(GMarkupParseContext *context,
990 const gchar *element_name,
994 GQParserData *parser_data = user_data;
995 GQParserFuncData *func = parser_data->parse_func_stack->data;
996 DEBUG_1("end %s", element_name);
999 func->end_func(parser_data, context, element_name, func->data, error);
1001 options_parse_func_pop(parser_data);
1004 static GMarkupParser parser = {
1013 *-----------------------------------------------------------------------------
1014 * load configuration (public)
1015 *-----------------------------------------------------------------------------
1018 gboolean load_options_from(const gchar *utf8_path, ConfOptions *options, gboolean startup)
1022 GMarkupParseContext *context;
1023 gboolean ret = TRUE;
1024 GQParserData *parser_data;
1026 if (g_file_get_contents (utf8_path, &buf, &size, NULL) == FALSE)
1031 parser_data = g_new0(GQParserData, 1);
1033 parser_data->startup = startup;
1034 options_parse_func_push(parser_data, options_parse_toplevel, NULL, NULL);
1036 context = g_markup_parse_context_new(&parser, 0, parser_data, NULL);
1038 if (g_markup_parse_context_parse (context, buf, size, NULL) == FALSE)
1041 DEBUG_1("Parse failed");
1044 g_free(parser_data);
1047 g_markup_parse_context_free (context);
1053 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */