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"
25 #include "filefilter.h"
27 #include "pixbuf-renderer.h"
28 #include "secure_save.h"
29 #include "slideshow.h"
30 #include "ui_fileops.h"
32 #include "layout_util.h"
37 *-----------------------------------------------------------------------------
38 * line write/parse routines (public)
39 *-----------------------------------------------------------------------------
42 void write_indent(GString *str, gint indent)
44 g_string_append_printf(str, "%*s", indent * 4, "");
47 void write_char_option(GString *str, gint indent, const gchar *label, const gchar *text)
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);
55 gboolean read_char_option(const gchar *option, const gchar *label, const gchar *value, gchar **text)
57 if (g_ascii_strcasecmp(option, label) != 0) return FALSE;
58 if (!text) return FALSE;
61 *text = g_strdup(value);
65 /* Since gdk_color_to_string() is only available since gtk 2.12
66 * here is an equivalent stub function. */
67 static gchar *color_to_string(GdkColor *color)
69 return g_strdup_printf("#%04X%04X%04X", color->red, color->green, color->blue);
72 void write_color_option(GString *str, gint indent, gchar *label, GdkColor *color)
76 gchar *colorstring = color_to_string(color);
78 write_char_option(str, indent, label, colorstring);
82 write_char_option(str, indent, label, "");
85 gboolean read_color_option(const gchar *option, const gchar *label, const gchar *value, GdkColor *color)
87 if (g_ascii_strcasecmp(option, label) != 0) return FALSE;
88 if (!color) return FALSE;
90 if (!*value) return FALSE;
91 gdk_color_parse(value, color);
95 void write_int_option(GString *str, gint indent, const gchar *label, gint n)
97 write_indent(str, indent);
98 g_string_append_printf(str, "%s = \"%d\"\n", label, n);
101 gboolean read_int_option(const gchar *option, const gchar *label, const gchar *value, gint *n)
103 if (g_ascii_strcasecmp(option, label) != 0) return FALSE;
104 if (!n) return FALSE;
106 if (g_ascii_isdigit(value[0]) || (value[0] == '-' && g_ascii_isdigit(value[1])))
108 *n = strtol(value, NULL, 10);
112 if (g_ascii_strcasecmp(value, "true") == 0)
121 void write_uint_option(GString *str, gint indent, const gchar *label, guint n)
123 write_indent(str, indent);
124 g_string_append_printf(str, "%s = \"%u\"\n", label, n);
127 gboolean read_uint_option(const gchar *option, const gchar *label, const gchar *value, guint *n)
129 if (g_ascii_strcasecmp(option, label) != 0) return FALSE;
130 if (!n) return FALSE;
132 if (g_ascii_isdigit(value[0]))
134 *n = strtoul(value, NULL, 10);
138 if (g_ascii_strcasecmp(value, "true") == 0)
147 gboolean read_uint_option_clamp(const gchar *option, const gchar *label, const gchar *value, guint *n, guint min, guint max)
151 ret = read_uint_option(option, label, value, n);
152 if (ret) *n = CLAMP(*n, min, max);
158 gboolean read_int_option_clamp(const gchar *option, const gchar *label, const gchar *value, gint *n, gint min, gint max)
162 ret = read_int_option(option, label, value, n);
163 if (ret) *n = CLAMP(*n, min, max);
168 void write_int_unit_option(GString *str, gint indent, gchar *label, gint n, gint subunits)
183 write_indent(str, indent);
184 g_string_append_printf(str, "%s = \"%d.%d\"\n", label, l, r);
187 gboolean read_int_unit_option(const gchar *option, const gchar *label, const gchar *value, gint *n, gint subunits)
192 if (g_ascii_strcasecmp(option, label) != 0) return FALSE;
193 if (!n) return FALSE;
195 buf = g_strdup(value);
197 while (*ptr != '\0' && *ptr != '.') ptr++;
201 l = strtol(value, NULL, 10);
204 r = strtol(ptr, NULL, 10);
208 l = strtol(value, NULL, 10);
212 *n = l * subunits + r;
218 void write_bool_option(GString *str, gint indent, gchar *label, gint n)
220 write_indent(str, indent);
221 g_string_append_printf(str, "%s = \"%s\"\n", label, n ? "true" : "false");
224 gboolean read_bool_option(const gchar *option, const gchar *label, const gchar *value, gint *n)
226 if (g_ascii_strcasecmp(option, label) != 0) return FALSE;
227 if (!n) return FALSE;
229 if (g_ascii_strcasecmp(value, "true") == 0 || atoi(value) != 0)
238 *-----------------------------------------------------------------------------
239 * write fuctions for elements (private)
240 *-----------------------------------------------------------------------------
243 static void write_global_attributes(GString *outstr, gint indent)
245 // WRITE_SUBTITLE("General Options");
247 WRITE_BOOL(*options, show_icon_names);
248 WRITE_BOOL(*options, show_copy_path);
251 WRITE_BOOL(*options, tree_descend_subdirs);
252 WRITE_BOOL(*options, lazy_image_sync);
253 WRITE_BOOL(*options, update_on_time_change);
256 WRITE_BOOL(*options, progressive_key_scrolling);
258 WRITE_UINT(*options, duplicates_similarity_threshold);
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);
267 // WRITE_SUBTITLE("Startup Options");
269 WRITE_BOOL(*options, startup.restore_path);
270 WRITE_BOOL(*options, startup.use_last_path);
271 WRITE_CHAR(*options, startup.path);
274 // WRITE_SUBTITLE("File operations Options");
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);
286 // WRITE_SUBTITLE("Properties dialog Options");
287 WRITE_CHAR(*options, properties.tabs_order);
289 // WRITE_SUBTITLE("Image Options");
291 WRITE_UINT(*options, image.zoom_mode);
293 // g_string_append_printf(outstr, "# image.zoom_mode possible values are:\n"
296 // "# dont_change\n");
297 // g_string_append_printf(outstr, "image.zoom_mode: ");
298 // switch (options->image.zoom_mode)
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;
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);
325 // WRITE_SUBTITLE("Thumbnails Options");
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);
338 // WRITE_SUBTITLE("File sorting Options");
340 WRITE_INT(*options, file_sort.method);
341 WRITE_BOOL(*options, file_sort.ascending);
342 WRITE_BOOL(*options, file_sort.case_sensitive);
345 // WRITE_SUBTITLE("Fullscreen Options");
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);
353 // WRITE_SUBTITLE("Histogram Options");
354 WRITE_UINT(*options, histogram.last_channel_mode);
355 WRITE_UINT(*options, histogram.last_log_mode);
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);
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);
373 // WRITE_SUBTITLE("Slideshow Options");
375 WRITE_INT_UNIT(*options, slideshow.delay, SLIDESHOW_SUBSECOND_PRECISION);
376 WRITE_BOOL(*options, slideshow.random);
377 WRITE_BOOL(*options, slideshow.repeat);
380 // WRITE_SUBTITLE("Collection Options");
382 WRITE_BOOL(*options, collections.rectangular_selection);
385 // WRITE_SUBTITLE("Filtering Options");
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);
393 // WRITE_SUBTITLE("Sidecars Options");
395 WRITE_CHAR(*options, sidecar.ext);
399 // WRITE_SUBTITLE("Shell command");
400 WRITE_CHAR(*options, shell.path);
401 WRITE_CHAR(*options, shell.options);
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);
416 WRITE_SUBTITLE("Exif Options");
417 g_string_append_printf(outstr, "# Display: 0: never\n"
420 for (i = 0; ExifUIList[i].key; i++)
422 g_string_append_printf(outstr, "exif.display.");
423 write_int_option(outstr, 2, (gchar *)ExifUIList[i].key, ExifUIList[i].current);
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);
442 static void write_color_profile(GString *outstr, gint indent)
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);
450 WRITE_STRING("<color_profiles\n");
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);
461 for (i = 0; i < COLOR_PROFILE_INPUTS; i++)
463 WRITE_STRING("<profile\n");
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]);
468 WRITE_STRING("/>\n");
471 WRITE_STRING("</color_profiles>\n");
476 *-----------------------------------------------------------------------------
477 * save configuration (public)
478 *-----------------------------------------------------------------------------
481 gboolean save_options_to(const gchar *utf8_path, ConfOptions *options)
489 rc_pathl = path_from_utf8(utf8_path);
490 ssi = secure_open(rc_pathl);
494 log_printf(_("error saving config file: %s\n"), utf8_path);
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");
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");
508 WRITE_STRING("-->\n");
510 WRITE_STRING("<global\n");
511 write_global_attributes(outstr, indent + 1);
516 write_color_profile(outstr, indent);
519 filter_write_list(outstr, indent);
522 WRITE_SUBTITLE("Layout Options - defaults");
523 WRITE_STRING("<layout\n");
524 layout_write_attributes(&options->layout, outstr, indent + 1);
525 WRITE_STRING("/>\n");
528 WRITE_STRING("</global>\n");
531 WRITE_SUBTITLE("Layout Options");
533 work = layout_window_list;
536 LayoutWindow *lw = work->data;
537 layout_write_config(lw, outstr, indent);
544 secure_fputs(ssi, outstr->str);
545 g_string_free(outstr, TRUE);
547 if (secure_close(ssi))
549 log_printf(_("error saving config file: %s\nerror: %s\n"), utf8_path,
550 secsave_strerror(secsave_errno));
558 *-----------------------------------------------------------------------------
559 * loading attributes for elements (private)
560 *-----------------------------------------------------------------------------
564 static gboolean load_global_params(const gchar **attribute_names, const gchar **attribute_values)
566 while (*attribute_names)
568 const gchar *option = *attribute_names++;
569 const gchar *value = *attribute_values++;
572 /* general options */
573 if (READ_BOOL(*options, show_icon_names)) continue;
574 if (READ_BOOL(*options, show_copy_path)) continue;
576 if (READ_BOOL(*options, tree_descend_subdirs)) continue;
577 if (READ_BOOL(*options, lazy_image_sync)) continue;
578 if (READ_BOOL(*options, update_on_time_change)) continue;
580 if (READ_UINT_CLAMP(*options, duplicates_similarity_threshold, 0, 100)) continue;
582 if (READ_BOOL(*options, progressive_key_scrolling)) continue;
584 if (READ_BOOL(*options, mousewheel_scrolls)) continue;
586 if (READ_INT(*options, open_recent_list_maxsize)) continue;
587 if (READ_INT(*options, dnd_icon_size)) continue;
588 if (READ_BOOL(*options, place_dialogs_under_mouse)) continue;
590 /* startup options */
592 if (READ_BOOL(*options, startup.restore_path)) continue;
594 if (READ_BOOL(*options, startup.use_last_path)) continue;
596 if (READ_CHAR(*options, startup.path)) continue;
599 /* properties dialog options */
600 if (READ_CHAR(*options, properties.tabs_order)) continue;
603 if (READ_UINT_CLAMP(*options, image.zoom_mode, 0, ZOOM_RESET_NONE)) continue;
604 if (READ_BOOL(*options, image.zoom_2pass)) continue;
605 if (READ_BOOL(*options, image.zoom_to_fit_allow_expand)) continue;
606 if (READ_BOOL(*options, image.fit_window_to_image)) continue;
607 if (READ_BOOL(*options, image.limit_window_size)) continue;
608 if (READ_INT(*options, image.max_window_size)) continue;
609 if (READ_BOOL(*options, image.limit_autofit_size)) continue;
610 if (READ_INT(*options, image.max_autofit_size)) continue;
611 if (READ_UINT_CLAMP(*options, image.scroll_reset_method, 0, PR_SCROLL_RESET_COUNT - 1)) continue;
612 if (READ_INT(*options, image.tile_cache_max)) continue;
613 if (READ_INT(*options, image.image_cache_max)) continue;
614 if (READ_UINT_CLAMP(*options, image.zoom_quality, GDK_INTERP_NEAREST, GDK_INTERP_HYPER)) continue;
615 if (READ_UINT_CLAMP(*options, image.dither_quality, GDK_RGB_DITHER_NONE, GDK_RGB_DITHER_MAX)) continue;
616 if (READ_INT(*options, image.zoom_increment)) continue;
617 if (READ_BOOL(*options, image.enable_read_ahead)) continue;
618 if (READ_BOOL(*options, image.exif_rotate_enable)) continue;
619 if (READ_BOOL(*options, image.use_custom_border_color)) continue;
620 if (READ_COLOR(*options, image.border_color)) continue;
621 if (READ_INT_CLAMP(*options, image.read_buffer_size, IMAGE_LOADER_READ_BUFFER_SIZE_MIN, IMAGE_LOADER_READ_BUFFER_SIZE_MAX)) continue;
622 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;
625 /* thumbnails options */
626 if (READ_INT_CLAMP(*options, thumbnails.max_width, 16, 512)) continue;
627 if (READ_INT_CLAMP(*options, thumbnails.max_height, 16, 512)) continue;
629 if (READ_BOOL(*options, thumbnails.enable_caching)) continue;
630 if (READ_BOOL(*options, thumbnails.cache_into_dirs)) continue;
631 if (READ_BOOL(*options, thumbnails.fast)) continue;
632 if (READ_BOOL(*options, thumbnails.use_xvpics)) continue;
633 if (READ_BOOL(*options, thumbnails.spec_standard)) continue;
634 if (READ_UINT_CLAMP(*options, thumbnails.quality, GDK_INTERP_NEAREST, GDK_INTERP_HYPER)) continue;
635 if (READ_BOOL(*options, thumbnails.use_exif)) continue;
637 /* file sorting options */
638 if (READ_UINT(*options, file_sort.method)) continue;
639 if (READ_BOOL(*options, file_sort.ascending)) continue;
640 if (READ_BOOL(*options, file_sort.case_sensitive)) continue;
642 /* file operations *options */
643 if (READ_BOOL(*options, file_ops.enable_in_place_rename)) continue;
644 if (READ_BOOL(*options, file_ops.confirm_delete)) continue;
645 if (READ_BOOL(*options, file_ops.enable_delete_key)) continue;
646 if (READ_BOOL(*options, file_ops.safe_delete_enable)) continue;
647 if (READ_CHAR(*options, file_ops.safe_delete_path)) continue;
648 if (READ_INT(*options, file_ops.safe_delete_folder_maxsize)) continue;
650 /* fullscreen options */
651 if (READ_INT(*options, fullscreen.screen)) continue;
652 if (READ_BOOL(*options, fullscreen.clean_flip)) continue;
653 if (READ_BOOL(*options, fullscreen.disable_saver)) continue;
654 if (READ_BOOL(*options, fullscreen.above)) continue;
657 if (READ_UINT(*options, histogram.last_channel_mode)) continue;
658 if (READ_UINT(*options, histogram.last_log_mode)) continue;
661 if (READ_UINT(*options, image_overlay.common.state)) continue;
662 if (READ_BOOL(*options, image_overlay.common.show_at_startup)) continue;
663 if (READ_CHAR(*options, image_overlay.common.template_string)) continue;
665 if (READ_INT(*options, image_overlay.common.x)) continue;
666 if (READ_INT(*options, image_overlay.common.y)) continue;
669 /* slideshow options */
670 if (READ_INT_UNIT(*options, slideshow.delay, SLIDESHOW_SUBSECOND_PRECISION)) continue;
671 if (READ_BOOL(*options, slideshow.random)) continue;
672 if (READ_BOOL(*options, slideshow.repeat)) continue;
674 /* collection options */
676 if (READ_BOOL(*options, collections.rectangular_selection)) continue;
678 /* filtering options */
680 if (READ_BOOL(*options, file_filter.show_hidden_files)) continue;
681 if (READ_BOOL(*options, file_filter.show_dot_directory)) continue;
682 if (READ_BOOL(*options, file_filter.disable)) continue;
683 if (READ_CHAR(*options, sidecar.ext)) continue;
688 if (READ_CHAR(*options, shell.path)) continue;
689 if (READ_CHAR(*options, shell.options)) continue;
692 if (READ_CHAR(*options, helpers.html_browser.command_name)) continue;
693 if (READ_CHAR(*options, helpers.html_browser.command_line)) continue;
696 if (0 == g_ascii_strncasecmp(option, "exif.display.", 13))
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);
705 if (READ_BOOL(*options, metadata.enable_metadata_dirs)) continue;
706 if (READ_BOOL(*options, metadata.save_in_image_file)) continue;
707 if (READ_BOOL(*options, metadata.save_legacy_IPTC)) continue;
708 if (READ_BOOL(*options, metadata.warn_on_write_problems)) continue;
709 if (READ_BOOL(*options, metadata.save_legacy_format)) continue;
710 if (READ_BOOL(*options, metadata.sync_grouped_files)) continue;
711 if (READ_BOOL(*options, metadata.confirm_write)) continue;
712 if (READ_BOOL(*options, metadata.confirm_after_timeout)) continue;
713 if (READ_INT(*options, metadata.confirm_timeout)) continue;
714 if (READ_BOOL(*options, metadata.confirm_on_image_change)) continue;
715 if (READ_BOOL(*options, metadata.confirm_on_dir_change)) continue;
717 DEBUG_1("unknown attribute %s = %s", option, value);
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)
725 while (*attribute_names)
727 const gchar *option = *attribute_names++;
728 const gchar *value = *attribute_values++;
731 if (READ_BOOL(options->color_profile, enabled)) continue;
732 if (READ_BOOL(options->color_profile, use_image)) continue;
733 if (READ_INT(options->color_profile, input_type)) continue;
734 if (READ_INT(options->color_profile, screen_type)) continue;
735 if (READ_CHAR(options->color_profile, screen_file)) continue;
737 DEBUG_1("unknown attribute %s = %s", option, value);
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)
744 gint i = GPOINTER_TO_INT(data);
745 if (i < 0 || i >= COLOR_PROFILE_INPUTS) return;
746 while (*attribute_names)
748 const gchar *option = *attribute_names++;
749 const gchar *value = *attribute_values++;
751 if (READ_CHAR_FULL("input_file", options->color_profile.input_file[i])) continue;
752 if (READ_CHAR_FULL("input_name", options->color_profile.input_name[i])) continue;
755 DEBUG_1("unknown attribute %s = %s", option, value);
758 options_parse_func_set_data(parser_data, GINT_TO_POINTER(i));
765 *-----------------------------------------------------------------------------
766 * xml file structure (private)
767 *-----------------------------------------------------------------------------
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;
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)
779 DEBUG_1("unexpected: %s", element_name);
780 options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL);
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)
785 if (g_ascii_strcasecmp(element_name, "profile") == 0)
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);
792 DEBUG_1("unexpected profile: %s", element_name);
793 options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL);
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)
799 if (g_ascii_strcasecmp(element_name, "file_type") == 0)
801 filter_load_file_type(attribute_names, attribute_values);
802 options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL);
806 DEBUG_1("unexpected filter: %s", element_name);
807 options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL);
811 static void options_parse_filter_end(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, gpointer data, GError **error)
813 DEBUG_1(" filter end");
814 filter_add_defaults();
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);
886 DEBUG_1("unexpected in <layout>: <%s>", element_name);
887 options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL);
891 static void options_parse_layout_end(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, gpointer data, GError **error)
893 LayoutWindow *lw = data;
894 layout_util_sync(lw);
897 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)
899 if (g_ascii_strcasecmp(element_name, "global") == 0)
901 load_global_params(attribute_names, attribute_values);
902 options_parse_func_push(parser_data, options_parse_global, NULL, NULL);
906 if (parser_data->startup && !parser_data->global_found)
908 DEBUG_1(" global end");
909 parser_data->global_found = TRUE;
910 init_after_global_options();
913 if (g_ascii_strcasecmp(element_name, "layout") == 0)
916 lw = layout_new_from_config(attribute_names, attribute_values, parser_data->startup);
917 options_parse_func_push(parser_data, options_parse_layout, options_parse_layout_end, lw);
921 DEBUG_1("unexpected in <toplevel>: <%s>", element_name);
922 options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL);
931 *-----------------------------------------------------------------------------
933 *-----------------------------------------------------------------------------
937 struct _GQParserFuncData
939 GQParserStartFunc start_func;
940 GQParserEndFunc end_func;
941 // GQParserTextFunc text_func;
945 void options_parse_func_push(GQParserData *parser_data, GQParserStartFunc start_func, GQParserEndFunc end_func, gpointer data)
947 GQParserFuncData *func_data = g_new0(GQParserFuncData, 1);
948 func_data->start_func = start_func;
949 func_data->end_func = end_func;
950 func_data->data = data;
952 parser_data->parse_func_stack = g_list_prepend(parser_data->parse_func_stack, func_data);
955 void options_parse_func_pop(GQParserData *parser_data)
957 g_free(parser_data->parse_func_stack->data);
958 parser_data->parse_func_stack = g_list_delete_link(parser_data->parse_func_stack, parser_data->parse_func_stack);
961 void options_parse_func_set_data(GQParserData *parser_data, gpointer data)
963 GQParserFuncData *func = parser_data->parse_func_stack->data;
968 static void start_element(GMarkupParseContext *context,
969 const gchar *element_name,
970 const gchar **attribute_names,
971 const gchar **attribute_values,
975 GQParserData *parser_data = user_data;
976 GQParserFuncData *func = parser_data->parse_func_stack->data;
977 DEBUG_1("start %s", element_name);
979 if (func->start_func)
980 func->start_func(parser_data, context, element_name, attribute_names, attribute_values, func->data, error);
983 static void end_element(GMarkupParseContext *context,
984 const gchar *element_name,
988 GQParserData *parser_data = user_data;
989 GQParserFuncData *func = parser_data->parse_func_stack->data;
990 DEBUG_1("end %s", element_name);
993 func->end_func(parser_data, context, element_name, func->data, error);
995 options_parse_func_pop(parser_data);
998 static GMarkupParser parser = {
1007 *-----------------------------------------------------------------------------
1008 * load configuration (public)
1009 *-----------------------------------------------------------------------------
1012 gboolean load_options_from(const gchar *utf8_path, ConfOptions *options, gboolean startup)
1016 GMarkupParseContext *context;
1017 gboolean ret = TRUE;
1018 GQParserData *parser_data;
1020 if (g_file_get_contents (utf8_path, &buf, &size, NULL) == FALSE)
1025 parser_data = g_new0(GQParserData, 1);
1027 parser_data->startup = startup;
1028 options_parse_func_push(parser_data, options_parse_toplevel, NULL, NULL);
1030 context = g_markup_parse_context_new(&parser, 0, parser_data, NULL);
1032 if (g_markup_parse_context_parse (context, buf, size, NULL) == FALSE)
1035 DEBUG_1("Parse failed");
1038 g_free(parser_data);
1041 g_markup_parse_context_free (context);
1047 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */