X-Git-Url: http://geeqie.org/cgi-bin/gitweb.cgi?p=geeqie.git;a=blobdiff_plain;f=src%2Frcfile.c;h=52aa2b9022dce442c3ca1a31b0c6c050b3a8eb42;hp=5cc535188a3a7855c501ce7a6ee44f1a65f4d945;hb=36d2e8e15cf7e6e230664cea85a6ddf492f766fe;hpb=e9460139c2941c4df0f1058ba6ca121121339d98 diff --git a/src/rcfile.c b/src/rcfile.c index 5cc53518..52aa2b90 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -1,13 +1,22 @@ /* - * Geeqie - * (C) 2006 John Ellis - * Copyright (C) 2008 The Geeqie Team + * Copyright (C) 2006 John Ellis + * Copyright (C) 2008 - 2016 The Geeqie Team * * Author: John Ellis * - * This software is released under the GNU General Public License (GNU GPL). - * Please read the included file COPYING for more information. - * This software comes with no warranty of any kind, use at your own risk! + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include @@ -16,7 +25,12 @@ #include "main.h" #include "rcfile.h" +#include "bar.h" +#include "bar_comment.h" #include "bar_exif.h" +#include "bar_histogram.h" +#include "bar_keywords.h" +#include "bar_sort.h" #include "editors.h" #include "filefilter.h" #include "misc.h" @@ -24,29 +38,68 @@ #include "secure_save.h" #include "slideshow.h" #include "ui_fileops.h" +#include "layout.h" +#include "layout_util.h" +#include "bar.h" +#include "metadata.h" +#include "bar_gps.h" +#include "dupe.h" + /* *----------------------------------------------------------------------------- - * line write/parse routines (private) + * line write/parse routines (public) *----------------------------------------------------------------------------- */ +void write_indent(GString *str, gint indent) +{ + g_string_append_printf(str, "\n%*s", indent * 4, ""); +} -static void write_char_option(SecureSaveInfo *ssi, gchar *label, gchar *text) +void write_char_option(GString *str, gint indent, const gchar *label, const gchar *text) { - gchar *escval = escquote_value(text); + /* this is needed for overlay string, because g_markup_escape_text does not handle \n and such, + ideas for improvement are welcome + */ + static const unsigned char no_quote_utf[] = { + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, + 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, + 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, + 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, + 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, + 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, + 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, + 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, + 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, + 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, + 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, + '"', 0 /* '"' is handled in g_markup_escape_text */ + }; + + gchar *escval1 = g_strescape(text ? text : "", (gchar *) no_quote_utf); + gchar *escval2 = g_markup_escape_text(escval1, -1); + g_string_append_printf(str, "%s = \"%s\" ", label, escval2); + g_free(escval2); + g_free(escval1); +} - secure_fprintf(ssi, "%s: %s\n", label, escval); - g_free(escval); +/* dummy read for old/obsolete/futur/deprecated/unused options */ +gboolean read_dummy_option(const gchar *option, const gchar *label, const gchar *message) +{ + if (g_ascii_strcasecmp(option, label) != 0) return FALSE; + log_printf(_("Option %s ignored: %s\n"), option, message); + return TRUE; } -static gboolean read_char_option(FILE *f, gchar *option, gchar *label, gchar *value, gchar **text) + +gboolean read_char_option(const gchar *option, const gchar *label, const gchar *value, gchar **text) { if (g_ascii_strcasecmp(option, label) != 0) return FALSE; if (!text) return FALSE; g_free(*text); - *text = quoted_value(value, NULL); + *text = g_strcompress(value); return TRUE; } @@ -57,39 +110,35 @@ static gchar *color_to_string(GdkColor *color) return g_strdup_printf("#%04X%04X%04X", color->red, color->green, color->blue); } -static void write_color_option(SecureSaveInfo *ssi, gchar *label, GdkColor *color) +void write_color_option(GString *str, gint indent, gchar *label, GdkColor *color) { if (color) { gchar *colorstring = color_to_string(color); - write_char_option(ssi, label, colorstring); + write_char_option(str, indent, label, colorstring); g_free(colorstring); } else - secure_fprintf(ssi, "%s: \n", label); + write_char_option(str, indent, label, ""); } -static gboolean read_color_option(FILE *f, gchar *option, gchar *label, gchar *value, GdkColor *color) +gboolean read_color_option(const gchar *option, const gchar *label, const gchar *value, GdkColor *color) { - gchar *colorstr; - if (g_ascii_strcasecmp(option, label) != 0) return FALSE; if (!color) return FALSE; - colorstr = quoted_value(value, NULL); - if (!colorstr) return FALSE; - gdk_color_parse(colorstr, color); - g_free(colorstr); + if (!*value) return FALSE; + gdk_color_parse(value, color); return TRUE; } -static void write_int_option(SecureSaveInfo *ssi, gchar *label, gint n) +void write_int_option(GString *str, gint indent, const gchar *label, gint n) { - secure_fprintf(ssi, "%s: %d\n", label, n); + g_string_append_printf(str, "%s = \"%d\" ", label, n); } -static gboolean read_int_option(FILE *f, gchar *option, gchar *label, gchar *value, gint *n) +gboolean read_int_option(const gchar *option, const gchar *label, const gchar *value, gint *n) { if (g_ascii_strcasecmp(option, label) != 0) return FALSE; if (!n) return FALSE; @@ -109,12 +158,12 @@ static gboolean read_int_option(FILE *f, gchar *option, gchar *label, gchar *val return TRUE; } -static void write_uint_option(SecureSaveInfo *ssi, gchar *label, guint n) +void write_ushort_option(GString *str, gint indent, const gchar *label, guint16 n) { - secure_fprintf(ssi, "%s: %u\n", label, n); + g_string_append_printf(str, "%s = \"%uh\" ", label, n); } -static gboolean read_uint_option(FILE *f, gchar *option, gchar *label, gchar *value, guint *n) +gboolean read_ushort_option(const gchar *option, const gchar *label, const gchar *value, guint16 *n) { if (g_ascii_strcasecmp(option, label) != 0) return FALSE; if (!n) return FALSE; @@ -130,32 +179,57 @@ static gboolean read_uint_option(FILE *f, gchar *option, gchar *label, gchar *va else *n = 0; } - + return TRUE; } -static gboolean read_uint_option_clamp(FILE *f, gchar *option, gchar *label, gchar *value, guint *n, guint min, guint max) +void write_uint_option(GString *str, gint indent, const gchar *label, guint n) +{ + g_string_append_printf(str, "%s = \"%u\" ", label, n); +} + +gboolean read_uint_option(const gchar *option, const gchar *label, const gchar *value, guint *n) +{ + if (g_ascii_strcasecmp(option, label) != 0) return FALSE; + if (!n) return FALSE; + + if (g_ascii_isdigit(value[0])) + { + *n = strtoul(value, NULL, 10); + } + else + { + if (g_ascii_strcasecmp(value, "true") == 0) + *n = 1; + else + *n = 0; + } + + return TRUE; +} + +gboolean read_uint_option_clamp(const gchar *option, const gchar *label, const gchar *value, guint *n, guint min, guint max) { gboolean ret; - ret = read_uint_option(f, option, label, value, n); + ret = read_uint_option(option, label, value, n); if (ret) *n = CLAMP(*n, min, max); return ret; } -static gboolean read_int_option_clamp(FILE *f, gchar *option, gchar *label, gchar *value, gint *n, gint min, gint max) +gboolean read_int_option_clamp(const gchar *option, const gchar *label, const gchar *value, gint *n, gint min, gint max) { gboolean ret; - ret = read_int_option(f, option, label, value, n); + ret = read_int_option(option, label, value, n); if (ret) *n = CLAMP(*n, min, max); return ret; } -static void write_int_unit_option(SecureSaveInfo *ssi, gchar *label, gint n, gint subunits) +void write_int_unit_option(GString *str, gint indent, gchar *label, gint n, gint subunits) { gint l, r; @@ -170,18 +244,19 @@ static void write_int_unit_option(SecureSaveInfo *ssi, gchar *label, gint n, gin r = 0; } - secure_fprintf(ssi, "%s: %d.%d\n", label, l, r); + g_string_append_printf(str, "%s = \"%d.%d\" ", label, l, r); } -static gboolean read_int_unit_option(FILE *f, gchar *option, gchar *label, gchar *value, gint *n, gint subunits) +gboolean read_int_unit_option(const gchar *option, const gchar *label, const gchar *value, gint *n, gint subunits) { gint l, r; - gchar *ptr; + gchar *ptr, *buf; if (g_ascii_strcasecmp(option, label) != 0) return FALSE; if (!n) return FALSE; - ptr = value; + buf = g_strdup(value); + ptr = buf; while (*ptr != '\0' && *ptr != '.') ptr++; if (*ptr == '.') { @@ -198,17 +273,17 @@ static gboolean read_int_unit_option(FILE *f, gchar *option, gchar *label, gchar } *n = l * subunits + r; + g_free(buf); return TRUE; } -static void write_bool_option(SecureSaveInfo *ssi, gchar *label, gint n) +void write_bool_option(GString *str, gint indent, gchar *label, gint n) { - secure_fprintf(ssi, "%s: ", label); - if (n) secure_fprintf(ssi, "true\n"); else secure_fprintf(ssi, "false\n"); + g_string_append_printf(str, "%s = \"%s\" ", label, n ? "true" : "false"); } -static gboolean read_bool_option(FILE *f, gchar *option, gchar *label, gchar *value, gint *n) +gboolean read_bool_option(const gchar *option, const gchar *label, const gchar *value, gint *n) { if (g_ascii_strcasecmp(option, label) != 0) return FALSE; if (!n) return FALSE; @@ -221,6 +296,203 @@ static gboolean read_bool_option(FILE *f, gchar *option, gchar *label, gchar *va return TRUE; } +/* + *----------------------------------------------------------------------------- + * write fuctions for elements (private) + *----------------------------------------------------------------------------- + */ + +static void write_global_attributes(GString *outstr, gint indent) +{ + /* General Options */ + WRITE_NL(); WRITE_BOOL(*options, show_icon_names); + WRITE_SEPARATOR(); + + WRITE_NL(); WRITE_BOOL(*options, tree_descend_subdirs); + WRITE_NL(); WRITE_BOOL(*options, view_dir_list_single_click_enter); + WRITE_NL(); WRITE_BOOL(*options, lazy_image_sync); + WRITE_NL(); WRITE_BOOL(*options, update_on_time_change); + WRITE_SEPARATOR(); + + WRITE_NL(); WRITE_BOOL(*options, progressive_key_scrolling); + WRITE_NL(); WRITE_UINT(*options, keyboard_scroll_step); + + WRITE_NL(); WRITE_UINT(*options, duplicates_similarity_threshold); + WRITE_NL(); WRITE_UINT(*options, duplicates_match); + WRITE_NL(); WRITE_UINT(*options, duplicates_select_type); + WRITE_NL(); WRITE_BOOL(*options, duplicates_thumbnails); + WRITE_NL(); WRITE_BOOL(*options, rot_invariant_sim); + WRITE_SEPARATOR(); + + WRITE_NL(); WRITE_BOOL(*options, mousewheel_scrolls); + WRITE_NL(); WRITE_BOOL(*options, image_lm_click_nav); + WRITE_NL(); WRITE_INT(*options, open_recent_list_maxsize); + WRITE_NL(); WRITE_INT(*options, dnd_icon_size); + WRITE_NL(); WRITE_BOOL(*options, place_dialogs_under_mouse); + + WRITE_NL(); WRITE_BOOL(*options, save_window_positions); + WRITE_NL(); WRITE_BOOL(*options, use_saved_window_positions_for_new_windows); + WRITE_NL(); WRITE_BOOL(*options, tools_restore_state); + + /* File operations Options */ + WRITE_NL(); WRITE_BOOL(*options, file_ops.enable_in_place_rename); + WRITE_NL(); WRITE_BOOL(*options, file_ops.confirm_delete); + WRITE_NL(); WRITE_BOOL(*options, file_ops.enable_delete_key); + WRITE_NL(); WRITE_BOOL(*options, file_ops.safe_delete_enable); + WRITE_NL(); WRITE_CHAR(*options, file_ops.safe_delete_path); + WRITE_NL(); WRITE_INT(*options, file_ops.safe_delete_folder_maxsize); + + /* Properties dialog Options */ + WRITE_NL(); WRITE_CHAR(*options, properties.tabs_order); + + /* Image Options */ + WRITE_NL(); WRITE_UINT(*options, image.zoom_mode); + + WRITE_SEPARATOR(); + WRITE_NL(); WRITE_BOOL(*options, image.zoom_2pass); + WRITE_NL(); WRITE_BOOL(*options, image.zoom_to_fit_allow_expand); + WRITE_NL(); WRITE_UINT(*options, image.zoom_quality); + WRITE_NL(); WRITE_INT(*options, image.zoom_increment); + WRITE_NL(); WRITE_BOOL(*options, image.fit_window_to_image); + WRITE_NL(); WRITE_BOOL(*options, image.limit_window_size); + WRITE_NL(); WRITE_INT(*options, image.max_window_size); + WRITE_NL(); WRITE_BOOL(*options, image.limit_autofit_size); + WRITE_NL(); WRITE_INT(*options, image.max_autofit_size); + WRITE_NL(); WRITE_INT(*options, image.max_enlargement_size); + WRITE_NL(); WRITE_UINT(*options, image.scroll_reset_method); + WRITE_NL(); WRITE_INT(*options, image.tile_cache_max); + WRITE_NL(); WRITE_INT(*options, image.image_cache_max); + WRITE_NL(); WRITE_BOOL(*options, image.enable_read_ahead); + WRITE_NL(); WRITE_BOOL(*options, image.exif_rotate_enable); + WRITE_NL(); WRITE_BOOL(*options, image.use_custom_border_color); + WRITE_NL(); WRITE_BOOL(*options, image.use_custom_border_color_in_fullscreen); + WRITE_NL(); WRITE_COLOR(*options, image.border_color); + WRITE_NL(); WRITE_COLOR(*options, image.alpha_color_1); + WRITE_NL(); WRITE_COLOR(*options, image.alpha_color_2); + WRITE_NL(); WRITE_BOOL(*options, image.use_clutter_renderer); + + /* Thumbnails Options */ + WRITE_NL(); WRITE_INT(*options, thumbnails.max_width); + WRITE_NL(); WRITE_INT(*options, thumbnails.max_height); + WRITE_NL(); WRITE_BOOL(*options, thumbnails.enable_caching); + WRITE_NL(); WRITE_BOOL(*options, thumbnails.cache_into_dirs); + WRITE_NL(); WRITE_BOOL(*options, thumbnails.use_xvpics); + WRITE_NL(); WRITE_BOOL(*options, thumbnails.spec_standard); + WRITE_NL(); WRITE_UINT(*options, thumbnails.quality); + WRITE_NL(); WRITE_BOOL(*options, thumbnails.use_exif); + + /* File sorting Options */ + WRITE_NL(); WRITE_INT(*options, file_sort.method); + WRITE_NL(); WRITE_BOOL(*options, file_sort.ascending); + WRITE_NL(); WRITE_BOOL(*options, file_sort.case_sensitive); + WRITE_NL(); WRITE_BOOL(*options, file_sort.natural); + + /* Fullscreen Options */ + WRITE_NL(); WRITE_INT(*options, fullscreen.screen); + WRITE_NL(); WRITE_BOOL(*options, fullscreen.clean_flip); + WRITE_NL(); WRITE_BOOL(*options, fullscreen.disable_saver); + WRITE_NL(); WRITE_BOOL(*options, fullscreen.above); + + WRITE_SEPARATOR(); + + /* Image Overlay Options */ + WRITE_NL(); WRITE_CHAR(*options, image_overlay.template_string); + + WRITE_NL(); WRITE_INT(*options, image_overlay.x); + WRITE_NL(); WRITE_INT(*options, image_overlay.y); + WRITE_NL(); WRITE_INT(*options, image_overlay.text_red); + WRITE_NL(); WRITE_INT(*options, image_overlay.text_green); + WRITE_NL(); WRITE_INT(*options, image_overlay.text_blue); + WRITE_NL(); WRITE_INT(*options, image_overlay.text_alpha); + WRITE_NL(); WRITE_INT(*options, image_overlay.background_red); + WRITE_NL(); WRITE_INT(*options, image_overlay.background_green); + WRITE_NL(); WRITE_INT(*options, image_overlay.background_blue); + WRITE_NL(); WRITE_INT(*options, image_overlay.background_alpha); + WRITE_NL(); WRITE_CHAR(*options, image_overlay.font); + + /* Slideshow Options */ + WRITE_NL(); WRITE_INT_UNIT(*options, slideshow.delay, SLIDESHOW_SUBSECOND_PRECISION); + WRITE_NL(); WRITE_BOOL(*options, slideshow.random); + WRITE_NL(); WRITE_BOOL(*options, slideshow.repeat); + + /* Collection Options */ + WRITE_NL(); WRITE_BOOL(*options, collections.rectangular_selection); + + /* Filtering Options */ + WRITE_NL(); WRITE_BOOL(*options, file_filter.show_hidden_files); + WRITE_NL(); WRITE_BOOL(*options, file_filter.show_parent_directory); + WRITE_NL(); WRITE_BOOL(*options, file_filter.show_dot_directory); + WRITE_NL(); WRITE_BOOL(*options, file_filter.disable_file_extension_checks); + WRITE_NL(); WRITE_BOOL(*options, file_filter.disable); + WRITE_SEPARATOR(); + + /* Sidecars Options */ + WRITE_NL(); WRITE_CHAR(*options, sidecar.ext); + + /* Shell command */ + WRITE_NL(); WRITE_CHAR(*options, shell.path); + WRITE_NL(); WRITE_CHAR(*options, shell.options); + + /* Helpers */ + WRITE_NL(); WRITE_CHAR(*options, helpers.html_browser.command_name); + WRITE_NL(); WRITE_CHAR(*options, helpers.html_browser.command_line); + + /* Metadata Options */ + WRITE_NL(); WRITE_BOOL(*options, metadata.enable_metadata_dirs); + WRITE_NL(); WRITE_BOOL(*options, metadata.save_in_image_file); + WRITE_NL(); WRITE_BOOL(*options, metadata.save_legacy_IPTC); + WRITE_NL(); WRITE_BOOL(*options, metadata.warn_on_write_problems); + WRITE_NL(); WRITE_BOOL(*options, metadata.save_legacy_format); + WRITE_NL(); WRITE_BOOL(*options, metadata.sync_grouped_files); + WRITE_NL(); WRITE_BOOL(*options, metadata.confirm_write); + WRITE_NL(); WRITE_BOOL(*options, metadata.sidecar_extended_name); + WRITE_NL(); WRITE_INT(*options, metadata.confirm_timeout); + WRITE_NL(); WRITE_BOOL(*options, metadata.confirm_after_timeout); + WRITE_NL(); WRITE_BOOL(*options, metadata.confirm_on_image_change); + WRITE_NL(); WRITE_BOOL(*options, metadata.confirm_on_dir_change); + WRITE_NL(); WRITE_BOOL(*options, metadata.keywords_case_sensitive); + WRITE_NL(); WRITE_BOOL(*options, metadata.write_orientation); + + WRITE_NL(); WRITE_INT(*options, stereo.mode); + WRITE_NL(); WRITE_INT(*options, stereo.fsmode); + WRITE_NL(); WRITE_BOOL(*options, stereo.enable_fsmode); + WRITE_NL(); WRITE_INT(*options, stereo.fixed_w); + WRITE_NL(); WRITE_INT(*options, stereo.fixed_h); + WRITE_NL(); WRITE_INT(*options, stereo.fixed_x1); + WRITE_NL(); WRITE_INT(*options, stereo.fixed_y1); + WRITE_NL(); WRITE_INT(*options, stereo.fixed_x2); + WRITE_NL(); WRITE_INT(*options, stereo.fixed_y2); +} + +static void write_color_profile(GString *outstr, gint indent) +{ + gint i; +#ifndef HAVE_LCMS + g_string_append_printf(outstr, "\n", GQ_APPNAME); +#endif + + WRITE_NL(); WRITE_STRING("color_profile, screen_file); + WRITE_BOOL(options->color_profile, enabled); + WRITE_BOOL(options->color_profile, use_image); + WRITE_INT(options->color_profile, input_type); + WRITE_BOOL(options->color_profile, use_x11_screen_profile); + WRITE_INT(options->color_profile, render_intent); + WRITE_STRING(">"); + + indent++; + for (i = 0; i < COLOR_PROFILE_INPUTS; i++) + { + WRITE_NL(); WRITE_STRING("color_profile.input_file[i]); + write_char_option(outstr, indent, "input_name", options->color_profile.input_name[i]); + WRITE_STRING("/>"); + } + indent--; + WRITE_NL(); WRITE_STRING(""); +} + /* *----------------------------------------------------------------------------- @@ -228,11 +500,13 @@ static gboolean read_bool_option(FILE *f, gchar *option, gchar *label, gchar *va *----------------------------------------------------------------------------- */ -gboolean save_options_to(const gchar *utf8_path, ConfOptions *options) +gboolean save_config_to_file(const gchar *utf8_path, ConfOptions *options) { SecureSaveInfo *ssi; gchar *rc_pathl; - gint i; + GString *outstr; + gint indent = 0; + GList *work; rc_pathl = path_from_utf8(utf8_path); ssi = secure_open(rc_pathl); @@ -243,691 +517,761 @@ gboolean save_options_to(const gchar *utf8_path, ConfOptions *options) return FALSE; } -#define WRITE_BOOL(_name_) write_bool_option(ssi, #_name_, options->_name_) -#define WRITE_INT(_name_) write_int_option(ssi, #_name_, options->_name_) -#define WRITE_UINT(_name_) write_uint_option(ssi, #_name_, options->_name_) -#define WRITE_INT_UNIT(_name_, _unit_) write_int_unit_option(ssi, #_name_, options->_name_, _unit_) -#define WRITE_CHAR(_name_) write_char_option(ssi, #_name_, options->_name_) -#define WRITE_COLOR(_name_) write_color_option(ssi, #_name_, &options->_name_) - -#define WRITE_SEPARATOR() secure_fputc(ssi, '\n') -#define WRITE_SUBTITLE(_title_) secure_fprintf(ssi, "\n\n##### "_title_" #####\n\n") - - secure_fprintf(ssi, "######################################################################\n"); - secure_fprintf(ssi, "# %30s config file version %-10s #\n", GQ_APPNAME, VERSION); - secure_fprintf(ssi, "######################################################################\n"); + outstr = g_string_new(""); + g_string_append_printf(outstr, "\n"); WRITE_SEPARATOR(); - WRITE_SUBTITLE("General Options"); + WRITE_STRING("\n"); + indent++; - WRITE_BOOL(show_icon_names); - WRITE_BOOL(show_copy_path); - WRITE_SEPARATOR(); + WRITE_NL(); WRITE_STRING("\n"); - WRITE_BOOL(tree_descend_subdirs); - WRITE_BOOL(lazy_image_sync); - WRITE_BOOL(update_on_time_change); - WRITE_SEPARATOR(); + indent++; - WRITE_BOOL(progressive_key_scrolling); + write_color_profile(outstr, indent); - WRITE_UINT(duplicates_similarity_threshold); WRITE_SEPARATOR(); + filter_write_list(outstr, indent); - WRITE_BOOL(mousewheel_scrolls); - WRITE_INT(open_recent_list_maxsize); - WRITE_INT(dnd_icon_size); - WRITE_BOOL(place_dialogs_under_mouse); - + WRITE_SEPARATOR(); + keyword_tree_write_config(outstr, indent); + indent--; + WRITE_NL(); WRITE_STRING("\n"); - WRITE_SUBTITLE("Startup Options"); + WRITE_SEPARATOR(); - WRITE_BOOL(startup.restore_path); - WRITE_BOOL(startup.use_last_path); - WRITE_CHAR(startup.path); + /* Layout Options */ + work = layout_window_list; + while (work) + { + LayoutWindow *lw = work->data; + layout_write_config(lw, outstr, indent); + work = work->next; + } + indent--; + WRITE_NL(); WRITE_STRING("\n"); + WRITE_SEPARATOR(); - WRITE_SUBTITLE("File operations Options"); + secure_fputs(ssi, outstr->str); + g_string_free(outstr, TRUE); - WRITE_BOOL(file_ops.enable_in_place_rename); - WRITE_BOOL(file_ops.confirm_delete); - WRITE_BOOL(file_ops.enable_delete_key); - WRITE_BOOL(file_ops.safe_delete_enable); - WRITE_CHAR(file_ops.safe_delete_path); - WRITE_INT(file_ops.safe_delete_folder_maxsize); + if (secure_close(ssi)) + { + log_printf(_("error saving config file: %s\nerror: %s\n"), utf8_path, + secsave_strerror(secsave_errno)); + return FALSE; + } + return TRUE; +} - WRITE_SUBTITLE("Layout Options"); +/* + *----------------------------------------------------------------------------- + * loading attributes for elements (private) + *----------------------------------------------------------------------------- + */ - WRITE_INT(layout.style); - WRITE_CHAR(layout.order); - WRITE_UINT(layout.dir_view_type); - WRITE_UINT(layout.file_view_type); - WRITE_BOOL(layout.show_marks); - WRITE_BOOL(layout.show_thumbnails); - WRITE_BOOL(layout.show_directory_date); - WRITE_CHAR(layout.home_path); - WRITE_SEPARATOR(); - WRITE_BOOL(layout.save_window_positions); - WRITE_SEPARATOR(); +static gboolean load_global_params(const gchar **attribute_names, const gchar **attribute_values) +{ + while (*attribute_names) + { + const gchar *option = *attribute_names++; + const gchar *value = *attribute_values++; + + /* General options */ + if (READ_BOOL(*options, show_icon_names)) continue; + + if (READ_BOOL(*options, tree_descend_subdirs)) continue; + if (READ_BOOL(*options, view_dir_list_single_click_enter)) continue; + if (READ_BOOL(*options, lazy_image_sync)) continue; + if (READ_BOOL(*options, update_on_time_change)) continue; + + if (READ_UINT_CLAMP(*options, duplicates_similarity_threshold, 0, 100)) continue; + if (READ_UINT_CLAMP(*options, duplicates_match, 0, DUPE_MATCH_NAME_CI)) continue; + if (READ_UINT_CLAMP(*options, duplicates_select_type, 0, DUPE_SELECT_GROUP2)) continue; + if (READ_BOOL(*options, duplicates_thumbnails)) continue; + if (READ_BOOL(*options, rot_invariant_sim)) continue; + + if (READ_BOOL(*options, progressive_key_scrolling)) continue; + if (READ_UINT_CLAMP(*options, keyboard_scroll_step, 1, 32)) continue; + + if (READ_BOOL(*options, mousewheel_scrolls)) continue; + if (READ_BOOL(*options, image_lm_click_nav)) continue; + + if (READ_INT(*options, open_recent_list_maxsize)) continue; + if (READ_INT(*options, dnd_icon_size)) continue; + if (READ_BOOL(*options, place_dialogs_under_mouse)) continue; + + if (READ_BOOL(*options, save_window_positions)) continue; + if (READ_BOOL(*options, use_saved_window_positions_for_new_windows)) continue; + if (READ_BOOL(*options, tools_restore_state)) continue; + + /* Properties dialog options */ + if (READ_CHAR(*options, properties.tabs_order)) continue; + + /* Image options */ + if (READ_UINT_CLAMP(*options, image.zoom_mode, 0, ZOOM_RESET_NONE)) continue; + if (READ_BOOL(*options, image.zoom_2pass)) continue; + if (READ_BOOL(*options, image.zoom_to_fit_allow_expand)) continue; + if (READ_BOOL(*options, image.fit_window_to_image)) continue; + if (READ_BOOL(*options, image.limit_window_size)) continue; + if (READ_INT(*options, image.max_window_size)) continue; + if (READ_BOOL(*options, image.limit_autofit_size)) continue; + if (READ_INT(*options, image.max_autofit_size)) continue; + if (READ_INT(*options, image.max_enlargement_size)) continue; + if (READ_UINT_CLAMP(*options, image.scroll_reset_method, 0, PR_SCROLL_RESET_COUNT - 1)) continue; + if (READ_INT(*options, image.tile_cache_max)) continue; + if (READ_INT(*options, image.image_cache_max)) continue; + if (READ_UINT_CLAMP(*options, image.zoom_quality, GDK_INTERP_NEAREST, GDK_INTERP_HYPER)) continue; + if (READ_INT(*options, image.zoom_increment)) continue; + if (READ_BOOL(*options, image.enable_read_ahead)) continue; + if (READ_BOOL(*options, image.exif_rotate_enable)) continue; + if (READ_BOOL(*options, image.use_custom_border_color)) continue; + if (READ_BOOL(*options, image.use_custom_border_color_in_fullscreen)) continue; + if (READ_COLOR(*options, image.border_color)) continue; + if (READ_COLOR(*options, image.alpha_color_1)) continue; + if (READ_COLOR(*options, image.alpha_color_2)) continue; + if (READ_BOOL(*options, image.use_clutter_renderer)) continue; + + /* Thumbnails options */ + if (READ_INT_CLAMP(*options, thumbnails.max_width, 16, 512)) continue; + if (READ_INT_CLAMP(*options, thumbnails.max_height, 16, 512)) continue; + + if (READ_BOOL(*options, thumbnails.enable_caching)) continue; + if (READ_BOOL(*options, thumbnails.cache_into_dirs)) continue; + if (READ_BOOL(*options, thumbnails.use_xvpics)) continue; + if (READ_BOOL(*options, thumbnails.spec_standard)) continue; + if (READ_UINT_CLAMP(*options, thumbnails.quality, GDK_INTERP_NEAREST, GDK_INTERP_HYPER)) continue; + if (READ_BOOL(*options, thumbnails.use_exif)) continue; + + /* File sorting options */ + if (READ_UINT(*options, file_sort.method)) continue; + if (READ_BOOL(*options, file_sort.ascending)) continue; + if (READ_BOOL(*options, file_sort.case_sensitive)) continue; + if (READ_BOOL(*options, file_sort.natural)) continue; + + /* File operations *options */ + if (READ_BOOL(*options, file_ops.enable_in_place_rename)) continue; + if (READ_BOOL(*options, file_ops.confirm_delete)) continue; + if (READ_BOOL(*options, file_ops.enable_delete_key)) continue; + if (READ_BOOL(*options, file_ops.safe_delete_enable)) continue; + if (READ_CHAR(*options, file_ops.safe_delete_path)) continue; + if (READ_INT(*options, file_ops.safe_delete_folder_maxsize)) continue; + + /* Fullscreen options */ + if (READ_INT(*options, fullscreen.screen)) continue; + if (READ_BOOL(*options, fullscreen.clean_flip)) continue; + if (READ_BOOL(*options, fullscreen.disable_saver)) continue; + if (READ_BOOL(*options, fullscreen.above)) continue; + + /* Image overlay */ + if (READ_CHAR(*options, image_overlay.template_string)) continue; + if (READ_INT(*options, image_overlay.x)) continue; + if (READ_INT(*options, image_overlay.y)) continue; + if (READ_USHORT(*options, image_overlay.text_red)) continue; + if (READ_USHORT(*options, image_overlay.text_green)) continue; + if (READ_USHORT(*options, image_overlay.text_blue)) continue; + if (READ_USHORT(*options, image_overlay.text_alpha)) continue; + if (READ_USHORT(*options, image_overlay.background_red)) continue; + if (READ_USHORT(*options, image_overlay.background_green)) continue; + if (READ_USHORT(*options, image_overlay.background_blue)) continue; + if (READ_USHORT(*options, image_overlay.background_alpha)) continue; + if (READ_CHAR(*options, image_overlay.font)) continue; + + /* Slideshow options */ + if (READ_INT_UNIT(*options, slideshow.delay, SLIDESHOW_SUBSECOND_PRECISION)) continue; + if (READ_BOOL(*options, slideshow.random)) continue; + if (READ_BOOL(*options, slideshow.repeat)) continue; + + /* Collection options */ + if (READ_BOOL(*options, collections.rectangular_selection)) continue; + + /* Filtering options */ + if (READ_BOOL(*options, file_filter.show_hidden_files)) continue; + if (READ_BOOL(*options, file_filter.show_parent_directory)) continue; + if (READ_BOOL(*options, file_filter.show_dot_directory)) continue; + if (READ_BOOL(*options, file_filter.disable_file_extension_checks)) continue; + if (READ_BOOL(*options, file_filter.disable)) continue; + if (READ_CHAR(*options, sidecar.ext)) continue; - WRITE_INT(layout.main_window.x); - WRITE_INT(layout.main_window.y); - WRITE_INT(layout.main_window.w); - WRITE_INT(layout.main_window.h); - WRITE_BOOL(layout.main_window.maximized); - WRITE_INT(layout.main_window.hdivider_pos); - WRITE_INT(layout.main_window.vdivider_pos); - WRITE_SEPARATOR(); + /* Color Profiles */ - WRITE_INT(layout.float_window.x); - WRITE_INT(layout.float_window.y); - WRITE_INT(layout.float_window.w); - WRITE_INT(layout.float_window.h); - WRITE_INT(layout.float_window.vdivider_pos); - WRITE_SEPARATOR(); + /* Shell command */ + if (READ_CHAR(*options, shell.path)) continue; + if (READ_CHAR(*options, shell.options)) continue; - WRITE_INT(layout.properties_window.w); - WRITE_INT(layout.properties_window.h); - WRITE_SEPARATOR(); + /* Helpers */ + if (READ_CHAR(*options, helpers.html_browser.command_name)) continue; + if (READ_CHAR(*options, helpers.html_browser.command_line)) continue; + + /* Metadata */ + if (READ_BOOL(*options, metadata.enable_metadata_dirs)) continue; + if (READ_BOOL(*options, metadata.save_in_image_file)) continue; + if (READ_BOOL(*options, metadata.save_legacy_IPTC)) continue; + if (READ_BOOL(*options, metadata.warn_on_write_problems)) continue; + if (READ_BOOL(*options, metadata.save_legacy_format)) continue; + if (READ_BOOL(*options, metadata.sync_grouped_files)) continue; + if (READ_BOOL(*options, metadata.confirm_write)) continue; + if (READ_BOOL(*options, metadata.sidecar_extended_name)) continue; + if (READ_BOOL(*options, metadata.confirm_after_timeout)) continue; + if (READ_INT(*options, metadata.confirm_timeout)) continue; + if (READ_BOOL(*options, metadata.confirm_on_image_change)) continue; + if (READ_BOOL(*options, metadata.confirm_on_dir_change)) continue; + if (READ_BOOL(*options, metadata.keywords_case_sensitive)) continue; + if (READ_BOOL(*options, metadata.write_orientation)) continue; + + if (READ_INT(*options, stereo.mode)) continue; + if (READ_INT(*options, stereo.fsmode)) continue; + if (READ_BOOL(*options, stereo.enable_fsmode)) continue; + if (READ_INT(*options, stereo.fixed_w)) continue; + if (READ_INT(*options, stereo.fixed_h)) continue; + if (READ_INT(*options, stereo.fixed_x1)) continue; + if (READ_INT(*options, stereo.fixed_y1)) continue; + if (READ_INT(*options, stereo.fixed_x2)) continue; + if (READ_INT(*options, stereo.fixed_y2)) continue; + + /* Dummy options */ + if (READ_DUMMY(*options, image.dither_quality, "deprecated since 2012-08-13")) continue; + + /* Unknown options */ + log_printf("unknown attribute %s = %s\n", option, value); + } - WRITE_BOOL(layout.tools_float); - WRITE_BOOL(layout.tools_hidden); - WRITE_BOOL(layout.tools_restore_state); - WRITE_SEPARATOR(); + return TRUE; +} - WRITE_BOOL(layout.toolbar_hidden); - - WRITE_SUBTITLE("Panels Options"); - - WRITE_BOOL(panels.exif.enabled); - WRITE_INT(panels.exif.width); - WRITE_BOOL(panels.info.enabled); - WRITE_INT(panels.info.width); - WRITE_BOOL(panels.sort.enabled); - WRITE_INT(panels.sort.action_state); - WRITE_INT(panels.sort.mode_state); - WRITE_INT(panels.sort.selection_state); - - WRITE_SUBTITLE("Properties dialog Options"); - WRITE_CHAR(properties.tabs_order); - - WRITE_SUBTITLE("Image Options"); - - secure_fprintf(ssi, "# image.zoom_mode possible values are:\n" - "# original\n" - "# fit\n" - "# dont_change\n"); - secure_fprintf(ssi, "image.zoom_mode: "); - switch (options->image.zoom_mode) - { - case ZOOM_RESET_ORIGINAL: secure_fprintf(ssi, "original\n"); break; - case ZOOM_RESET_FIT_WINDOW: secure_fprintf(ssi, "fit\n"); break; - case ZOOM_RESET_NONE: secure_fprintf(ssi, "dont_change\n"); break; - } - WRITE_SEPARATOR(); - WRITE_BOOL(image.zoom_2pass); - WRITE_BOOL(image.zoom_to_fit_allow_expand); - WRITE_UINT(image.zoom_quality); - WRITE_INT(image.zoom_increment); - WRITE_BOOL(image.fit_window_to_image); - WRITE_BOOL(image.limit_window_size); - WRITE_INT(image.max_window_size); - WRITE_BOOL(image.limit_autofit_size); - WRITE_INT(image.max_autofit_size); - WRITE_UINT(image.scroll_reset_method); - WRITE_INT(image.tile_cache_max); - WRITE_INT(image.image_cache_max); - WRITE_UINT(image.dither_quality); - WRITE_BOOL(image.enable_read_ahead); - WRITE_BOOL(image.exif_rotate_enable); - WRITE_BOOL(image.use_custom_border_color); - WRITE_COLOR(image.border_color); - WRITE_INT(image.read_buffer_size); - WRITE_INT(image.idle_read_loop_count); - - WRITE_SUBTITLE("Thumbnails Options"); - - WRITE_INT(thumbnails.max_width); - WRITE_INT(thumbnails.max_height); - WRITE_BOOL(thumbnails.enable_caching); - WRITE_BOOL(thumbnails.cache_into_dirs); - WRITE_BOOL(thumbnails.fast); - WRITE_BOOL(thumbnails.use_xvpics); - WRITE_BOOL(thumbnails.spec_standard); - WRITE_UINT(thumbnails.quality); - WRITE_BOOL(thumbnails.use_exif); - - - WRITE_SUBTITLE("File sorting Options"); - - WRITE_INT(file_sort.method); - WRITE_BOOL(file_sort.ascending); - WRITE_BOOL(file_sort.case_sensitive); - - - WRITE_SUBTITLE("Fullscreen Options"); - - WRITE_INT(fullscreen.screen); - WRITE_BOOL(fullscreen.clean_flip); - WRITE_BOOL(fullscreen.disable_saver); - WRITE_BOOL(fullscreen.above); - - - WRITE_SUBTITLE("Histogram Options"); - WRITE_UINT(histogram.last_channel_mode); - WRITE_UINT(histogram.last_log_mode); - - - WRITE_SUBTITLE("Image Overlay Options"); - WRITE_UINT(image_overlay.common.state); - WRITE_BOOL(image_overlay.common.show_at_startup); - WRITE_CHAR(image_overlay.common.template_string); - WRITE_SEPARATOR(); +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) +{ + while (*attribute_names) + { + const gchar *option = *attribute_names++; + const gchar *value = *attribute_values++; - secure_fprintf(ssi, "# these are relative positions:\n"); - secure_fprintf(ssi, "# x >= 0: |x| pixels from left border\n"); - secure_fprintf(ssi, "# x < 0 : |x| pixels from right border\n"); - secure_fprintf(ssi, "# y >= 0: |y| pixels from top border\n"); - secure_fprintf(ssi, "# y < 0 : |y| pixels from bottom border\n"); - WRITE_INT(image_overlay.common.x); - WRITE_INT(image_overlay.common.y); + if (READ_BOOL(options->color_profile, enabled)) continue; + if (READ_BOOL(options->color_profile, use_image)) continue; + if (READ_INT(options->color_profile, input_type)) continue; + if (READ_CHAR(options->color_profile, screen_file)) continue; + if (READ_BOOL(options->color_profile, use_x11_screen_profile)) continue; + if (READ_INT(options->color_profile, render_intent)) continue; + log_printf("unknown attribute %s = %s\n", option, value); + } - WRITE_SUBTITLE("Slideshow Options"); +} - WRITE_INT_UNIT(slideshow.delay, SLIDESHOW_SUBSECOND_PRECISION); - WRITE_BOOL(slideshow.random); - WRITE_BOOL(slideshow.repeat); +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) +{ + gint i = GPOINTER_TO_INT(data); + if (i < 0 || i >= COLOR_PROFILE_INPUTS) return; + while (*attribute_names) + { + const gchar *option = *attribute_names++; + const gchar *value = *attribute_values++; + if (READ_CHAR_FULL("input_file", options->color_profile.input_file[i])) continue; + if (READ_CHAR_FULL("input_name", options->color_profile.input_name[i])) continue; - WRITE_SUBTITLE("Collection Options"); + log_printf("unknown attribute %s = %s\n", option, value); + } + i++; + options_parse_func_set_data(parser_data, GINT_TO_POINTER(i)); - WRITE_BOOL(collections.rectangular_selection); +} - WRITE_SUBTITLE("Filtering Options"); - WRITE_BOOL(file_filter.show_hidden_files); - WRITE_BOOL(file_filter.show_dot_directory); - WRITE_BOOL(file_filter.disable); - WRITE_SEPARATOR(); +/* + *----------------------------------------------------------------------------- + * xml file structure (private) + *----------------------------------------------------------------------------- + */ +struct _GQParserData +{ + GList *parse_func_stack; + gboolean startup; /* reading config for the first time - add commandline and defaults */ +}; - filter_write_list(ssi); +static const gchar *options_get_id(const gchar **attribute_names, const gchar **attribute_values) +{ + while (*attribute_names) + { + const gchar *option = *attribute_names++; + const gchar *value = *attribute_values++; + if (strcmp(option, "id") == 0) return value; - WRITE_SUBTITLE("Sidecars Options"); + } + return NULL; +} - sidecar_ext_write(ssi); +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) +{ + log_printf("unexpected: %s\n", element_name); + options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); +} - WRITE_SUBTITLE("Color Profiles"); +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) +{ + if (g_ascii_strcasecmp(element_name, "profile") == 0) + { + options_load_profile(parser_data, context, element_name, attribute_names, attribute_values, data, error); + options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); + } + else + { + log_printf("unexpected in : <%s>\n", element_name); + options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); + } +} -#ifndef HAVE_LCMS - secure_fprintf(ssi, "# NOTICE: %s was not built with support for color profiles,\n" - "# color profile options will have no effect.\n\n", GQ_APPNAME); -#endif +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) +{ + if (g_ascii_strcasecmp(element_name, "file_type") == 0) + { + filter_load_file_type(attribute_names, attribute_values); + options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); + } + else + { + log_printf("unexpected in : <%s>\n", element_name); + options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); + } +} - WRITE_BOOL(color_profile.enabled); - WRITE_BOOL(color_profile.use_image); - WRITE_INT(color_profile.input_type); - WRITE_SEPARATOR(); +static void options_parse_filter_end(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, gpointer data, GError **error) +{ + if (parser_data->startup) filter_add_defaults(); + filter_rebuild(); +} - for (i = 0; i < COLOR_PROFILE_INPUTS; i++) - { - gchar *buf; +static void options_parse_keyword_end(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, gpointer data, GError **error) +{ + GtkTreeIter *iter_ptr = data; + gtk_tree_iter_free(iter_ptr); +} - buf = g_strdup_printf("color_profile.input_file_%d", i + 1); - write_char_option(ssi, buf, options->color_profile.input_file[i]); - g_free(buf); - buf = g_strdup_printf("color_profile.input_name_%d", i + 1); - write_char_option(ssi, buf, options->color_profile.input_name[i]); - g_free(buf); +static void options_parse_keyword(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer data, GError **error) +{ + GtkTreeIter *iter_ptr = data; + if (g_ascii_strcasecmp(element_name, "keyword") == 0) + { + GtkTreeIter *child = keyword_add_from_config(keyword_tree, iter_ptr, attribute_names, attribute_values); + options_parse_func_push(parser_data, options_parse_keyword, options_parse_keyword_end, child); } - - WRITE_SEPARATOR(); - WRITE_INT(color_profile.screen_type); - WRITE_CHAR(color_profile.screen_file); + else + { + log_printf("unexpected in : <%s>\n", element_name); + options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); + } +} - WRITE_SUBTITLE("Shell command"); - WRITE_CHAR(shell.path); - WRITE_CHAR(shell.options); +static void options_parse_keyword_tree(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer data, GError **error) +{ + if (g_ascii_strcasecmp(element_name, "keyword") == 0) + { + GtkTreeIter *iter_ptr = keyword_add_from_config(keyword_tree, NULL, attribute_names, attribute_values); + options_parse_func_push(parser_data, options_parse_keyword, options_parse_keyword_end, iter_ptr); + } + else + { + log_printf("unexpected in : <%s>\n", element_name); + options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); + } +} - WRITE_SUBTITLE("Helpers"); - secure_fprintf(ssi, "# Html browser\n"); - secure_fprintf(ssi, "# command_name is: the binary's name to look for in the path\n"); - secure_fprintf(ssi, "# If command_name is empty, the program will try various common html browsers\n"); - secure_fprintf(ssi, "# command_line is:\n"); - secure_fprintf(ssi, "# \"\" (empty string) = execute binary with html file path as command line\n"); - secure_fprintf(ssi, "# \"string\" = execute string and use results for command line\n"); - secure_fprintf(ssi, "# \"!string\" = use text following ! as command line, replacing optional %%s with html file path\n"); - WRITE_CHAR(helpers.html_browser.command_name); - WRITE_CHAR(helpers.html_browser.command_line); +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) +{ + if (g_ascii_strcasecmp(element_name, "color_profiles") == 0) + { + options_load_color_profiles(parser_data, context, element_name, attribute_names, attribute_values, data, error); + options_parse_func_push(parser_data, options_parse_color_profiles, NULL, GINT_TO_POINTER(0)); + } + else if (g_ascii_strcasecmp(element_name, "filter") == 0) + { + options_parse_func_push(parser_data, options_parse_filter, options_parse_filter_end, NULL); + } + else if (g_ascii_strcasecmp(element_name, "keyword_tree") == 0) + { + if (!keyword_tree) keyword_tree_new(); + options_parse_func_push(parser_data, options_parse_keyword_tree, NULL, NULL); + } + else + { + log_printf("unexpected in : <%s>\n", element_name); + options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); + } +} - WRITE_SUBTITLE("External Programs"); - secure_fprintf(ssi, "# Maximum of %d programs (external_1 through external_%d)\n", GQ_EDITOR_GENERIC_SLOTS, GQ_EDITOR_GENERIC_SLOTS); - secure_fprintf(ssi, "# external_%d through external_%d are used for file ops\n", GQ_EDITOR_GENERIC_SLOTS + 1, GQ_EDITOR_SLOTS); - secure_fprintf(ssi, "# format: external_n: \"menu name\" \"command line\"\n\n"); +static void options_parse_global_end(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, gpointer data, GError **error) +{ +#ifndef HAVE_EXIV2 + /* some options do not work without exiv2 */ + options->metadata.save_in_image_file = FALSE; + options->metadata.save_legacy_format = TRUE; + options->metadata.write_orientation = FALSE; + DEBUG_1("compiled without Exiv2 - disabling XMP write support"); +#endif +} - for (i = 0; i < GQ_EDITOR_SLOTS; i++) +static void options_parse_pane_exif(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer data, GError **error) +{ + GtkWidget *pane = data; + if (g_ascii_strcasecmp(element_name, "entry") == 0) + { + bar_pane_exif_entry_add_from_config(pane, attribute_names, attribute_values); + options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); + } + else { - if (i == GQ_EDITOR_GENERIC_SLOTS) secure_fputc(ssi, '\n'); - gchar *qname = escquote_value(options->editor[i].name); - gchar *qcommand = escquote_value(options->editor[i].command); - secure_fprintf(ssi, "external_%d: %s %s\n", i+1, qname, qcommand); - g_free(qname); - g_free(qcommand); + log_printf("unexpected in : <%s>\n", element_name); + options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); } +} +static void options_parse_pane_keywords(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer data, GError **error) +{ + GtkWidget *pane = data; - WRITE_SUBTITLE("Exif Options"); - secure_fprintf(ssi, "# Display: 0: never\n" - "# 1: if set\n" - "# 2: always\n\n"); - for (i = 0; ExifUIList[i].key; i++) + if (g_ascii_strcasecmp(element_name, "expanded") == 0) { - secure_fprintf(ssi, "exif.display."); - write_int_option(ssi, (gchar *)ExifUIList[i].key, ExifUIList[i].current); + bar_pane_keywords_entry_add_from_config(pane, attribute_names, attribute_values); + options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); } + else + { + log_printf("unexpected in : <%s>\n", element_name); + options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); + } +} - WRITE_SUBTITLE("Metadata Options"); - WRITE_BOOL(metadata.enable_metadata_dirs); - WRITE_BOOL(metadata.save_in_image_file); - WRITE_BOOL(metadata.save_legacy_IPTC); - WRITE_BOOL(metadata.warn_on_write_problems); - WRITE_BOOL(metadata.save_legacy_format); - WRITE_BOOL(metadata.sync_grouped_files); - WRITE_BOOL(metadata.confirm_write); - WRITE_INT(metadata.confirm_timeout); - WRITE_BOOL(metadata.confirm_on_image_change); - WRITE_BOOL(metadata.confirm_on_dir_change); +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) +{ + GtkWidget *bar = data; + if (g_ascii_strcasecmp(element_name, "pane_comment") == 0) + { + GtkWidget *pane = bar_find_pane_by_id(bar, PANE_COMMENT, options_get_id(attribute_names, attribute_values)); + if (pane) + { + bar_pane_comment_update_from_config(pane, attribute_names, attribute_values); + } + else + { + pane = bar_pane_comment_new_from_config(attribute_names, attribute_values); + bar_add(bar, pane); + } + options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); + } +#ifdef HAVE_LIBCHAMPLAIN +#ifdef HAVE_LIBCHAMPLAIN_GTK + else if (g_ascii_strcasecmp(element_name, "pane_gps") == 0) + { + GtkWidget *pane = bar_find_pane_by_id(bar, PANE_GPS, options_get_id(attribute_names, attribute_values)); + if (pane) + { + bar_pane_gps_update_from_config(pane, attribute_names, attribute_values); + } + else + { + pane = bar_pane_gps_new_from_config(attribute_names, attribute_values); + bar_add(bar, pane); + } + options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); + } +#endif +#endif + else if (g_ascii_strcasecmp(element_name, "pane_exif") == 0) + { + GtkWidget *pane = bar_find_pane_by_id(bar, PANE_EXIF, options_get_id(attribute_names, attribute_values)); + if (pane) + { + bar_pane_exif_update_from_config(pane, attribute_names, attribute_values); + } + else + { + pane = bar_pane_exif_new_from_config(attribute_names, attribute_values); + bar_add(bar, pane); + } + options_parse_func_push(parser_data, options_parse_pane_exif, NULL, pane); + } + else if (g_ascii_strcasecmp(element_name, "pane_histogram") == 0) + { + GtkWidget *pane = bar_find_pane_by_id(bar, PANE_HISTOGRAM, options_get_id(attribute_names, attribute_values)); + if (pane) + { + bar_pane_histogram_update_from_config(pane, attribute_names, attribute_values); + } + else + { + pane = bar_pane_histogram_new_from_config(attribute_names, attribute_values); + bar_add(bar, pane); + } + options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); + } + else if (g_ascii_strcasecmp(element_name, "pane_keywords") == 0) + { + GtkWidget *pane = bar_find_pane_by_id(bar, PANE_KEYWORDS, options_get_id(attribute_names, attribute_values)); + if (pane) + { + bar_pane_keywords_update_from_config(pane, attribute_names, attribute_values); + } + else + { + pane = bar_pane_keywords_new_from_config(attribute_names, attribute_values); + bar_add(bar, pane); + } + options_parse_func_push(parser_data, options_parse_pane_keywords, NULL, pane); + } + else if (g_ascii_strcasecmp(element_name, "clear") == 0) + { + bar_clear(bar); + options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); + } + else + { + log_printf("unexpected in : <%s>\n", element_name); + options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); + } +} - WRITE_SUBTITLE("Documentation Options"); - WRITE_CHAR(documentation.helpdir); - WRITE_CHAR(documentation.htmldir); +/* Just a dummy function to parse out old leftovers + * + * This function can be cleaned somedays. + */ +static void options_parse_toolbar_and_statusbar(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer data, GError **error) +{ + options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); +} - WRITE_SEPARATOR(); - WRITE_SEPARATOR(); +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) +{ + LayoutWindow *lw = data; + if (g_ascii_strcasecmp(element_name, "bar") == 0) + { + if (!lw->bar) + { + GtkWidget *bar = bar_new_from_config(lw, attribute_names, attribute_values); + layout_bar_set(lw, bar); + } + else + { + bar_update_from_config(lw->bar, attribute_names, attribute_values); + } - secure_fprintf(ssi, "######################################################################\n"); - secure_fprintf(ssi, "# end of config file #\n"); - secure_fprintf(ssi, "######################################################################\n"); + options_parse_func_push(parser_data, options_parse_bar, NULL, lw->bar); + } +#if 0 +/* FIXME: The sort manager and desktop files are set up in the idle loop. + * Setup is not yet completed when the layout is first displayed. + */ + else if (g_ascii_strcasecmp(element_name, "bar_sort") == 0) + { + GtkWidget *bar = bar_sort_new_from_config(lw, attribute_names, attribute_values); + layout_bar_sort_set(lw, bar); + options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); + } +#endif + else if (g_ascii_strcasecmp(element_name, "toolbar") == 0) + { + options_parse_func_push(parser_data, options_parse_toolbar_and_statusbar, NULL, NULL); + } + else if (g_ascii_strcasecmp(element_name, "statusbar") == 0) + { + options_parse_func_push(parser_data, options_parse_toolbar_and_statusbar, NULL, NULL); + } + else + { + log_printf("unexpected in : <%s>\n", element_name); + options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); + } +} +static void options_parse_layout_end(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, gpointer data, GError **error) +{ + LayoutWindow *lw = data; + layout_util_sync(lw); +} - if (secure_close(ssi)) +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) +{ + if (g_ascii_strcasecmp(element_name, "gq") == 0) { - log_printf(_("error saving config file: %s\nerror: %s\n"), utf8_path, - secsave_strerror(secsave_errno)); - return FALSE; + /* optional top-level node */ + options_parse_func_push(parser_data, options_parse_toplevel, NULL, NULL); + return; + } + if (g_ascii_strcasecmp(element_name, "global") == 0) + { + load_global_params(attribute_names, attribute_values); + options_parse_func_push(parser_data, options_parse_global, options_parse_global_end, NULL); + return; } - return TRUE; + if (g_ascii_strcasecmp(element_name, "layout") == 0) + { + LayoutWindow *lw; + lw = layout_find_by_layout_id(options_get_id(attribute_names, attribute_values)); + if (lw) + { + layout_update_from_config(lw, attribute_names, attribute_values); + } + else + { + lw = layout_new_from_config(attribute_names, attribute_values, parser_data->startup); + } + options_parse_func_push(parser_data, options_parse_layout, options_parse_layout_end, lw); + } + else + { + log_printf("unexpected in : <%s>\n", element_name); + options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); + } } + /* *----------------------------------------------------------------------------- - * load configuration (public) + * parser *----------------------------------------------------------------------------- */ -static gboolean is_numbered_option(const gchar *option, const gchar *prefix, gint *number) + +struct _GQParserFuncData { - gsize n; - gsize option_len = strlen(option); - gsize prefix_len = strlen(prefix); - - if (option_len <= prefix_len) return FALSE; - if (g_ascii_strncasecmp(option, prefix, prefix_len) != 0) return FALSE; + GQParserStartFunc start_func; + GQParserEndFunc end_func; + gpointer data; +}; - n = prefix_len; - while (g_ascii_isdigit(option[n])) n++; - if (n < option_len) return FALSE; - - if (number) *number = atoi(option + prefix_len); - return TRUE; +void options_parse_func_push(GQParserData *parser_data, GQParserStartFunc start_func, GQParserEndFunc end_func, gpointer data) +{ + GQParserFuncData *func_data = g_new0(GQParserFuncData, 1); + func_data->start_func = start_func; + func_data->end_func = end_func; + func_data->data = data; + + parser_data->parse_func_stack = g_list_prepend(parser_data->parse_func_stack, func_data); } -#define OPTION_READ_BUFFER_SIZE 1024 +void options_parse_func_pop(GQParserData *parser_data) +{ + g_free(parser_data->parse_func_stack->data); + parser_data->parse_func_stack = g_list_delete_link(parser_data->parse_func_stack, parser_data->parse_func_stack); +} -gboolean load_options_from(const gchar *utf8_path, ConfOptions *options) +void options_parse_func_set_data(GQParserData *parser_data, gpointer data) { - FILE *f; - gchar *rc_pathl; - gchar s_buf[OPTION_READ_BUFFER_SIZE]; - gchar value_all[OPTION_READ_BUFFER_SIZE]; - gchar *option; - gchar *value; - gint i; + GQParserFuncData *func = parser_data->parse_func_stack->data; + func->data = data; +} - rc_pathl = path_from_utf8(utf8_path); - f = fopen(rc_pathl,"r"); - g_free(rc_pathl); - if (!f) return FALSE; - - while (fgets(s_buf, sizeof(s_buf), f)) - { - gchar *value_end; - gchar *p = s_buf; - - /* skip empty lines and comments */ - while (g_ascii_isspace(*p)) p++; - if (!*p || *p == '\n' || *p == '#') continue; - - /* parse option name */ - option = p; - while (g_ascii_isalnum(*p) || *p == '_' || *p == '.') p++; - if (!*p) continue; - *p = '\0'; - p++; - - /* search for value start, name and value are normally separated by ': ' - * but we allow relaxed syntax here, so '=', ':=' or just a tab will work too */ - while (*p == ':' || g_ascii_isspace(*p) || *p == '=') p++; - value = p; - - while (*p && !g_ascii_isspace(*p) && *p != '\n') p++; - value_end = p; /* value part up to the first whitespace or end of line */ - while (*p != '\0') p++; - memcpy(value_all, value, 1 + p - value); - - *value_end = '\0'; - -#define READ_BOOL(_name_) if (read_bool_option(f, option, #_name_, value, &options->_name_)) continue; -#define READ_INT(_name_) if (read_int_option(f, option, #_name_, value, &options->_name_)) continue; -#define READ_UINT(_name_) if (read_uint_option(f, option, #_name_, value, &options->_name_)) continue; -#define READ_INT_CLAMP(_name_, _min_, _max_) if (read_int_option_clamp(f, option, #_name_, value, &options->_name_, _min_, _max_)) continue; -#define READ_UINT_CLAMP(_name_, _min_, _max_) if (read_uint_option_clamp(f, option, #_name_, value, &options->_name_, _min_, _max_)) continue; -#define READ_INT_UNIT(_name_, _unit_) if (read_int_unit_option(f, option, #_name_, value, &options->_name_, _unit_)) continue; -#define READ_CHAR(_name_) if (read_char_option(f, option, #_name_, value_all, &options->_name_)) continue; -#define READ_COLOR(_name_) if (read_color_option(f, option, #_name_, value, &options->_name_)) continue; - -#define COMPAT_READ_BOOL(_oldname_, _name_) if (read_bool_option(f, option, #_oldname_, value, &options->_name_)) continue; -#define COMPAT_READ_INT(_oldname_, _name_) if (read_int_option(f, option, #_oldname_, value, &options->_name_)) continue; -#define COMPAT_READ_UINT(_oldname_, _name_) if (read_uint_option(f, option, #_oldname_, value, &options->_name_)) continue; -#define COMPAT_READ_INT_CLAMP(_oldname_, _name_, _min_, _max_) if (read_int_option_clamp(f, option, #_oldname_, value, &options->_name_, _min_, _max_)) continue; -#define COMPAT_READ_INT_UNIT(_oldname_, _name_, _unit_) if (read_int_unit_option(f, option, #_oldname_, value, &options->_name_, _unit_)) continue; -#define COMPAT_READ_CHAR(_oldname_, _name_) if (read_char_option(f, option, #_oldname_, value_all, &options->_name_)) continue; -#define COMPAT_READ_COLOR(_oldname_, _name_) if (read_color_option(f, option, #_oldname_, value, &options->_name_)) continue; - - /* general options */ - READ_BOOL(show_icon_names); - READ_BOOL(show_copy_path); - - READ_BOOL(tree_descend_subdirs); - READ_BOOL(lazy_image_sync); - READ_BOOL(update_on_time_change); - - READ_UINT_CLAMP(duplicates_similarity_threshold, 0, 100); - - READ_BOOL(progressive_key_scrolling); - - READ_BOOL(mousewheel_scrolls); - - READ_INT(open_recent_list_maxsize); - READ_INT(dnd_icon_size); - READ_BOOL(place_dialogs_under_mouse); - - /* startup options */ - - COMPAT_READ_BOOL(startup_path_enable, startup.restore_path); /* 2008/05/11 */ - READ_BOOL(startup.restore_path); - - READ_BOOL(startup.use_last_path); - - COMPAT_READ_CHAR(startup_path, startup.path); /* 2008/05/11 */ - READ_CHAR(startup.path); - - /* layout options */ - - READ_INT(layout.style); - READ_CHAR(layout.order); - - COMPAT_READ_UINT(layout.view_as_icons, layout.file_view_type); /* 2008/05/03 */ - - READ_UINT(layout.dir_view_type); - READ_UINT(layout.file_view_type); - READ_BOOL(layout.show_marks); - READ_BOOL(layout.show_thumbnails); - READ_BOOL(layout.show_directory_date); - READ_CHAR(layout.home_path); - - /* window positions */ - - READ_BOOL(layout.save_window_positions); - - READ_INT(layout.main_window.x); - READ_INT(layout.main_window.y); - READ_INT(layout.main_window.w); - READ_INT(layout.main_window.h); - READ_BOOL(layout.main_window.maximized); - READ_INT(layout.main_window.hdivider_pos); - READ_INT(layout.main_window.vdivider_pos); - - READ_INT(layout.float_window.x); - READ_INT(layout.float_window.y); - READ_INT(layout.float_window.w); - READ_INT(layout.float_window.h); - READ_INT(layout.float_window.vdivider_pos); - - READ_INT(layout.properties_window.w); - READ_INT(layout.properties_window.h); - - READ_BOOL(layout.tools_float); - READ_BOOL(layout.tools_hidden); - READ_BOOL(layout.tools_restore_state); - READ_BOOL(layout.toolbar_hidden); - - /* panels */ - READ_BOOL(panels.exif.enabled); - READ_INT_CLAMP(panels.exif.width, PANEL_MIN_WIDTH, PANEL_MAX_WIDTH); - READ_BOOL(panels.info.enabled); - READ_INT_CLAMP(panels.info.width, PANEL_MIN_WIDTH, PANEL_MAX_WIDTH); - READ_BOOL(panels.sort.enabled); - READ_INT(panels.sort.action_state); - READ_INT(panels.sort.mode_state); - READ_INT(panels.sort.selection_state); - - /* properties dialog options */ - READ_CHAR(properties.tabs_order); - - /* image options */ - if (g_ascii_strcasecmp(option, "image.zoom_mode") == 0) - { - if (g_ascii_strcasecmp(value, "original") == 0) - options->image.zoom_mode = ZOOM_RESET_ORIGINAL; - else if (g_ascii_strcasecmp(value, "fit") == 0) - options->image.zoom_mode = ZOOM_RESET_FIT_WINDOW; - else if (g_ascii_strcasecmp(value, "dont_change") == 0) - options->image.zoom_mode = ZOOM_RESET_NONE; - continue; - } - READ_BOOL(image.zoom_2pass); - READ_BOOL(image.zoom_to_fit_allow_expand); - READ_BOOL(image.fit_window_to_image); - READ_BOOL(image.limit_window_size); - READ_INT(image.max_window_size); - READ_BOOL(image.limit_autofit_size); - READ_INT(image.max_autofit_size); - READ_UINT_CLAMP(image.scroll_reset_method, 0, PR_SCROLL_RESET_COUNT - 1); - READ_INT(image.tile_cache_max); - READ_INT(image.image_cache_max); - READ_UINT_CLAMP(image.zoom_quality, GDK_INTERP_NEAREST, GDK_INTERP_HYPER); - READ_UINT_CLAMP(image.dither_quality, GDK_RGB_DITHER_NONE, GDK_RGB_DITHER_MAX); - READ_INT(image.zoom_increment); - READ_BOOL(image.enable_read_ahead); - READ_BOOL(image.exif_rotate_enable); - READ_BOOL(image.use_custom_border_color); - READ_COLOR(image.border_color); - READ_INT_CLAMP(image.read_buffer_size, IMAGE_LOADER_READ_BUFFER_SIZE_MIN, IMAGE_LOADER_READ_BUFFER_SIZE_MAX); - READ_INT_CLAMP(image.idle_read_loop_count, IMAGE_LOADER_IDLE_READ_LOOP_COUNT_MIN, IMAGE_LOADER_IDLE_READ_LOOP_COUNT_MAX); - - - /* thumbnails options */ - READ_INT_CLAMP(thumbnails.max_width, 16, 512); - READ_INT_CLAMP(thumbnails.max_height, 16, 512); - - READ_BOOL(thumbnails.enable_caching); - READ_BOOL(thumbnails.cache_into_dirs); - READ_BOOL(thumbnails.fast); - READ_BOOL(thumbnails.use_xvpics); - READ_BOOL(thumbnails.spec_standard); - READ_UINT_CLAMP(thumbnails.quality, GDK_INTERP_NEAREST, GDK_INTERP_HYPER); - READ_BOOL(thumbnails.use_exif); - - /* file sorting options */ - READ_UINT(file_sort.method); - READ_BOOL(file_sort.ascending); - READ_BOOL(file_sort.case_sensitive); - - /* file operations options */ - READ_BOOL(file_ops.enable_in_place_rename); - READ_BOOL(file_ops.confirm_delete); - READ_BOOL(file_ops.enable_delete_key); - READ_BOOL(file_ops.safe_delete_enable); - READ_CHAR(file_ops.safe_delete_path); - READ_INT(file_ops.safe_delete_folder_maxsize); - - /* fullscreen options */ - READ_INT(fullscreen.screen); - READ_BOOL(fullscreen.clean_flip); - READ_BOOL(fullscreen.disable_saver); - READ_BOOL(fullscreen.above); - - /* histogram */ - READ_UINT(histogram.last_channel_mode); - READ_UINT(histogram.last_log_mode); - - /* image overlay */ - COMPAT_READ_UINT(image_overlay.common.enabled, image_overlay.common.state); /* 2008-05-12 */ - READ_UINT(image_overlay.common.state); - COMPAT_READ_BOOL(fullscreen.show_info, image_overlay.common.show_at_startup); /* 2008-04-21 */ - READ_BOOL(image_overlay.common.show_at_startup); - COMPAT_READ_CHAR(fullscreen.info, image_overlay.common.template_string); /* 2008-04-21 */ - READ_CHAR(image_overlay.common.template_string); - - READ_INT(image_overlay.common.x); - READ_INT(image_overlay.common.y); - - - /* slideshow options */ - READ_INT_UNIT(slideshow.delay, SLIDESHOW_SUBSECOND_PRECISION); - READ_BOOL(slideshow.random); - READ_BOOL(slideshow.repeat); - - /* collection options */ - - READ_BOOL(collections.rectangular_selection); - - /* filtering options */ - - READ_BOOL(file_filter.show_hidden_files); - READ_BOOL(file_filter.show_dot_directory); - READ_BOOL(file_filter.disable); - - if (g_ascii_strcasecmp(option, "file_filter.ext") == 0) - { - filter_parse(value_all); - continue; - } - if (g_ascii_strcasecmp(option, "sidecar.ext") == 0) - { - sidecar_ext_parse(value_all, TRUE); - continue; - } +static void start_element(GMarkupParseContext *context, + const gchar *element_name, + const gchar **attribute_names, + const gchar **attribute_values, + gpointer user_data, + GError **error) +{ + GQParserData *parser_data = user_data; + GQParserFuncData *func = parser_data->parse_func_stack->data; + DEBUG_2("start %s", element_name); - /* Color Profiles */ + if (func->start_func) + func->start_func(parser_data, context, element_name, attribute_names, attribute_values, func->data, error); +} - READ_BOOL(color_profile.enabled); - READ_BOOL(color_profile.use_image); - READ_INT(color_profile.input_type); +static void end_element(GMarkupParseContext *context, + const gchar *element_name, + gpointer user_data, + GError **error) +{ + GQParserData *parser_data = user_data; + GQParserFuncData *func = parser_data->parse_func_stack->data; + DEBUG_2("end %s", element_name); - if (is_numbered_option(option, "color_profile.input_file_", &i)) - { - if (i > 0 && i <= COLOR_PROFILE_INPUTS) - { - i--; - read_char_option(f, option, option, value, &options->color_profile.input_file[i]); - } - continue; - } + if (func->end_func) + func->end_func(parser_data, context, element_name, func->data, error); - if (is_numbered_option(option, "color_profile.input_name_", &i)) - { - if (i > 0 && i <= COLOR_PROFILE_INPUTS) - { - i--; - read_char_option(f, option, option, value, &options->color_profile.input_name[i]); - } - continue; - } + options_parse_func_pop(parser_data); +} - READ_INT(color_profile.screen_type); - READ_CHAR(color_profile.screen_file); +static GMarkupParser parser = { + start_element, + end_element, + NULL, + NULL, + NULL +}; - /* Shell command */ - READ_CHAR(shell.path); - READ_CHAR(shell.options); +/* + *----------------------------------------------------------------------------- + * load configuration (public) + *----------------------------------------------------------------------------- + */ - /* Helpers */ - READ_CHAR(helpers.html_browser.command_name); - READ_CHAR(helpers.html_browser.command_line); +gboolean load_config_from_buf(const gchar *buf, gsize size, gboolean startup) +{ + GMarkupParseContext *context; + gboolean ret = TRUE; + GQParserData *parser_data; - /* External Programs */ + parser_data = g_new0(GQParserData, 1); - if (is_numbered_option(option, "external_", &i)) - { - if (i > 0 && i <= GQ_EDITOR_SLOTS) - { - const gchar *ptr; - - i--; - editor_set_name(i, quoted_value(value_all, &ptr)); - editor_set_command(i, quoted_value(ptr, NULL)); - } - continue; - } + parser_data->startup = startup; + options_parse_func_push(parser_data, options_parse_toplevel, NULL, NULL); - /* Exif */ - if (0 == g_ascii_strncasecmp(option, "exif.display.", 13)) - { - for (i = 0; ExifUIList[i].key; i++) - if (0 == g_ascii_strcasecmp(option + 13, ExifUIList[i].key)) - ExifUIList[i].current = strtol(value, NULL, 10); - continue; - } + context = g_markup_parse_context_new(&parser, 0, parser_data, NULL); - /* metadata */ - COMPAT_READ_BOOL(enable_metadata_dirs, metadata.enable_metadata_dirs); - COMPAT_READ_BOOL(save_metadata_in_image_file, metadata.save_in_image_file); /* 2008/12/20 */ - READ_BOOL(metadata.save_legacy_IPTC); - READ_BOOL(metadata.warn_on_write_problems); - READ_BOOL(metadata.save_legacy_format); - READ_BOOL(metadata.sync_grouped_files); - READ_BOOL(metadata.confirm_write); - READ_INT(metadata.confirm_timeout); - READ_BOOL(metadata.confirm_on_image_change); - READ_BOOL(metadata.confirm_on_dir_change); - - /* Documentation */ - READ_CHAR(documentation.helpdir); - READ_CHAR(documentation.htmldir); - - } - - fclose(f); - return TRUE; + if (g_markup_parse_context_parse(context, buf, size, NULL) == FALSE) + { + ret = FALSE; + DEBUG_1("Parse failed"); + } + + g_free(parser_data); + + g_markup_parse_context_free(context); + return ret; } + +gboolean load_config_from_file(const gchar *utf8_path, gboolean startup) +{ + gsize size; + gchar *buf; + gboolean ret = TRUE; + + if (g_file_get_contents(utf8_path, &buf, &size, NULL) == FALSE) + { + return FALSE; + } + ret = load_config_from_buf(buf, size, startup); + g_free(buf); + return ret; +} + + + /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */