- handle color profile and write metadata buttons on statusbar by ui_manager
[geeqie.git] / src / rcfile.c
index 8c9da17..7a2b527 100644 (file)
@@ -262,7 +262,6 @@ static void write_global_attributes(GString *outstr, gint indent)
 //     WRITE_SUBTITLE("General Options");
 
        WRITE_NL(); WRITE_BOOL(*options, show_icon_names);
-       WRITE_NL(); WRITE_BOOL(*options, show_copy_path);
        WRITE_SEPARATOR();
 
        WRITE_NL(); WRITE_BOOL(*options, tree_descend_subdirs);
@@ -283,13 +282,6 @@ static void write_global_attributes(GString *outstr, gint indent)
        WRITE_NL(); WRITE_BOOL(*options, save_window_positions);
        WRITE_NL(); WRITE_BOOL(*options, tools_restore_state);
 
-//     WRITE_SUBTITLE("Startup Options");
-
-       WRITE_NL(); WRITE_BOOL(*options, startup.restore_path);
-       WRITE_NL(); WRITE_BOOL(*options, startup.use_last_path);
-       WRITE_NL(); WRITE_CHAR(*options, startup.path);
-
-
 //     WRITE_SUBTITLE("File operations Options");
 
        WRITE_NL(); WRITE_BOOL(*options, file_ops.enable_in_place_rename);
@@ -338,8 +330,6 @@ static void write_global_attributes(GString *outstr, gint indent)
        WRITE_NL(); WRITE_BOOL(*options, image.exif_rotate_enable);
        WRITE_NL(); WRITE_BOOL(*options, image.use_custom_border_color);
        WRITE_NL(); WRITE_COLOR(*options, image.border_color);
-       WRITE_NL(); WRITE_INT(*options, image.read_buffer_size);
-       WRITE_NL(); WRITE_INT(*options, image.idle_read_loop_count);
 
 //     WRITE_SUBTITLE("Thumbnails Options");
 
@@ -347,7 +337,6 @@ static void write_global_attributes(GString *outstr, gint indent)
        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.fast);
        WRITE_NL(); WRITE_BOOL(*options, thumbnails.use_xvpics);
        WRITE_NL(); WRITE_BOOL(*options, thumbnails.spec_standard);
        WRITE_NL(); WRITE_UINT(*options, thumbnails.quality);
@@ -448,6 +437,8 @@ static void write_global_attributes(GString *outstr, gint indent)
        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.tags_case_sensitive);
+       WRITE_NL(); WRITE_BOOL(*options, metadata.write_orientation);
 
 }
 
@@ -460,11 +451,11 @@ static void write_color_profile(GString *outstr, gint indent)
 #endif
 
        WRITE_NL(); WRITE_STRING("<color_profiles ");
-       WRITE_INT(options->color_profile, screen_type);
        WRITE_CHAR(options->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_STRING(">");
 
        indent++;
@@ -486,7 +477,7 @@ static void write_color_profile(GString *outstr, gint indent)
  *-----------------------------------------------------------------------------
  */
 
-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;
@@ -582,7 +573,6 @@ static gboolean load_global_params(const gchar **attribute_names, const gchar **
 
                /* general options */
                if (READ_BOOL(*options, show_icon_names)) continue;
-               if (READ_BOOL(*options, show_copy_path)) continue;
 
                if (READ_BOOL(*options, tree_descend_subdirs)) continue;
                if (READ_BOOL(*options, lazy_image_sync)) continue;
@@ -601,15 +591,6 @@ static gboolean load_global_params(const gchar **attribute_names, const gchar **
                if (READ_BOOL(*options, save_window_positions)) continue;
                if (READ_BOOL(*options, tools_restore_state)) continue;
 
-               /* startup options */
-               
-               if (READ_BOOL(*options, startup.restore_path)) continue;
-
-               if (READ_BOOL(*options, startup.use_last_path)) continue;
-
-               if (READ_CHAR(*options, startup.path)) continue;
-       
-
                /* properties dialog options */
                if (READ_CHAR(*options, properties.tabs_order)) continue;
 
@@ -632,9 +613,6 @@ static gboolean load_global_params(const gchar **attribute_names, const gchar **
                if (READ_BOOL(*options, image.exif_rotate_enable)) continue;
                if (READ_BOOL(*options, image.use_custom_border_color)) continue;
                if (READ_COLOR(*options, image.border_color)) continue;
-               if (READ_INT_CLAMP(*options, image.read_buffer_size, IMAGE_LOADER_READ_BUFFER_SIZE_MIN, IMAGE_LOADER_READ_BUFFER_SIZE_MAX)) continue;
-               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;
-
 
                /* thumbnails options */
                if (READ_INT_CLAMP(*options, thumbnails.max_width, 16, 512)) continue;
@@ -642,7 +620,6 @@ static gboolean load_global_params(const gchar **attribute_names, const gchar **
 
                if (READ_BOOL(*options, thumbnails.enable_caching)) continue;
                if (READ_BOOL(*options, thumbnails.cache_into_dirs)) continue;
-               if (READ_BOOL(*options, thumbnails.fast)) 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;
@@ -720,8 +697,10 @@ static gboolean load_global_params(const gchar **attribute_names, const gchar **
                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.tags_case_sensitive)) continue;
+               if (READ_BOOL(*options, metadata.write_orientation)) continue;
 
-               DEBUG_1("unknown attribute %s = %s", option, value);
+               log_printf("unknown attribute %s = %s\n", option, value);
                }
 
        return TRUE;
@@ -737,10 +716,10 @@ static void options_load_color_profiles(GQParserData *parser_data, GMarkupParseC
                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_INT(options->color_profile, screen_type)) continue;
                if (READ_CHAR(options->color_profile, screen_file)) continue;
+               if (READ_BOOL(options->color_profile, use_x11_screen_profile)) continue;
 
-               DEBUG_1("unknown attribute %s = %s", option, value);
+               log_printf("unknown attribute %s = %s\n", option, value);
                }
 
 }
@@ -756,9 +735,8 @@ static void options_load_profile(GQParserData *parser_data, GMarkupParseContext
 
                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;
-               
 
-               DEBUG_1("unknown attribute %s = %s", option, value);
+               log_printf("unknown attribute %s = %s\n", option, value);
                }
        i++;
        options_parse_func_set_data(parser_data, GINT_TO_POINTER(i));
@@ -778,10 +756,23 @@ struct _GQParserData
        gboolean startup; /* reading config for the first time - add commandline and defaults */
 };
 
+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;
+
+               }
+       return NULL;
+}
+
 
 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)
 {
-       DEBUG_1("unexpected: %s", element_name);
+       log_printf("unexpected: %s\n", element_name);
        options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL);
 }
 
@@ -794,7 +785,7 @@ static void options_parse_color_profiles(GQParserData *parser_data, GMarkupParse
                }
        else
                {
-               DEBUG_1("unexpected profile: %s", element_name);
+               log_printf("unexpected in <profile>: <%s>\n", element_name);
                options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL);
                }
 }
@@ -808,7 +799,7 @@ static void options_parse_filter(GQParserData *parser_data, GMarkupParseContext
                }
        else
                {
-               DEBUG_1("unexpected filter: %s", element_name);
+               log_printf("unexpected in <filter>: <%s>\n", element_name);
                options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL);
                }
 }
@@ -836,7 +827,7 @@ static void options_parse_keyword(GQParserData *parser_data, GMarkupParseContext
                }
        else
                {
-               DEBUG_1("unexpected in <keyword>: <%s>", element_name);
+               log_printf("unexpected in <keyword>: <%s>\n", element_name);
                options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL);
                }
 }
@@ -852,7 +843,7 @@ static void options_parse_keyword_tree(GQParserData *parser_data, GMarkupParseCo
                }
        else
                {
-               DEBUG_1("unexpected in <keyword_tree>: <%s>", element_name);
+               log_printf("unexpected in <keyword_tree>: <%s>\n", element_name);
                options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL);
                }
 }
@@ -876,7 +867,7 @@ static void options_parse_global(GQParserData *parser_data, GMarkupParseContext
                }
        else
                {
-               DEBUG_1("unexpected global: %s", element_name);
+               log_printf("unexpected in <global>: <%s>\n", element_name);
                options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL);
                }
 }
@@ -897,7 +888,7 @@ static void options_parse_pane_exif(GQParserData *parser_data, GMarkupParseConte
                }
        else
                {
-               DEBUG_1("unexpected in <pane_exif>: <%s>", element_name);
+               log_printf("unexpected in <pane_exif>: <%s>\n", element_name);
                options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL);
                }
 }
@@ -907,31 +898,68 @@ static void options_parse_bar(GQParserData *parser_data, GMarkupParseContext *co
        GtkWidget *bar = data;
        if (g_ascii_strcasecmp(element_name, "pane_comment") == 0)
                {
-               GtkWidget *pane = bar_pane_comment_new_from_config(attribute_names, attribute_values);
-               bar_add(bar, pane);
+               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);
                }
        else if (g_ascii_strcasecmp(element_name, "pane_exif") == 0)
                {
-               GtkWidget *pane = bar_pane_exif_new_from_config(attribute_names, attribute_values);
-               bar_add(bar, pane);
+               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_pane_histogram_new_from_config(attribute_names, attribute_values);
-               bar_add(bar, pane);
+               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_pane_keywords_new_from_config(attribute_names, attribute_values);
-               bar_add(bar, pane);
+               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_leaf, NULL, NULL);
+               }
+       else if (g_ascii_strcasecmp(element_name, "clear") == 0)
+               {
+               bar_clear(bar);
                options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL);
                }
        else
                {
-               DEBUG_1("unexpected in <bar>: <%s>", element_name);
+               log_printf("unexpected in <bar>: <%s>\n", element_name);
                options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL);
                }
 }
@@ -941,12 +969,37 @@ static void options_parse_toolbar(GQParserData *parser_data, GMarkupParseContext
        LayoutWindow *lw = data;
        if (g_ascii_strcasecmp(element_name, "toolitem") == 0)
                {
-               layout_toolbar_add_from_config(lw, attribute_names, attribute_values);
+               layout_toolbar_add_from_config(lw, TOOLBAR_MAIN, attribute_names, attribute_values);
+               options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL);
+               }
+       else if (g_ascii_strcasecmp(element_name, "clear") == 0)
+               {
+               layout_toolbar_clear(lw, TOOLBAR_MAIN);
+               options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL);
+               }
+       else
+               {
+               log_printf("unexpected in <toolbar>: <%s>\n", element_name);
+               options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL);
+               }
+}
+
+static void options_parse_statusbar(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, "toolitem") == 0)
+               {
+               layout_toolbar_add_from_config(lw, TOOLBAR_STATUS, attribute_names, attribute_values);
+               options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL);
+               }
+       else if (g_ascii_strcasecmp(element_name, "clear") == 0)
+               {
+               layout_toolbar_clear(lw, TOOLBAR_STATUS);
                options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL);
                }
        else
                {
-               DEBUG_1("unexpected in <toolbar>: <%s>", element_name);
+               log_printf("unexpected in <statusbar>: <%s>\n", element_name);
                options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL);
                }
 }
@@ -956,8 +1009,16 @@ static void options_parse_layout(GQParserData *parser_data, GMarkupParseContext
        LayoutWindow *lw = data;
        if (g_ascii_strcasecmp(element_name, "bar") == 0)
                {
-               GtkWidget *bar = bar_new_from_config(lw, attribute_names, attribute_values);
-               layout_bar_set(lw, bar);
+               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);
+                       }
+                       
                options_parse_func_push(parser_data, options_parse_bar, NULL, lw->bar);
                }
        else if (g_ascii_strcasecmp(element_name, "bar_sort") == 0)
@@ -968,12 +1029,15 @@ static void options_parse_layout(GQParserData *parser_data, GMarkupParseContext
                }
        else if (g_ascii_strcasecmp(element_name, "toolbar") == 0)
                {
-               layout_toolbar_clear(lw);
                options_parse_func_push(parser_data, options_parse_toolbar, NULL, lw);
                }
+       else if (g_ascii_strcasecmp(element_name, "statusbar") == 0)
+               {
+               options_parse_func_push(parser_data, options_parse_statusbar, NULL, lw);
+               }
        else
                {
-               DEBUG_1("unexpected in <layout>: <%s>", element_name);
+               log_printf("unexpected in <layout>: <%s>\n", element_name);
                options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL);
                }
 }
@@ -1002,12 +1066,20 @@ static void options_parse_toplevel(GQParserData *parser_data, GMarkupParseContex
        if (g_ascii_strcasecmp(element_name, "layout") == 0)
                {
                LayoutWindow *lw;
-               lw = layout_new_from_config(attribute_names, attribute_values, parser_data->startup);
+               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
                {
-               DEBUG_1("unexpected in <toplevel>: <%s>", element_name);
+               log_printf("unexpected in <toplevel>: <%s>\n", element_name);
                options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL);
                }
 }
@@ -1098,19 +1170,12 @@ static GMarkupParser parser = {
  *-----------------------------------------------------------------------------
  */
 
-gboolean load_options_from(const gchar *utf8_path, ConfOptions *options, gboolean startup)
+gboolean load_config_from_buf(const gchar *buf, gsize size, gboolean startup)
 {
-       gsize size;
-       gchar *buf;
        GMarkupParseContext *context;
        gboolean ret = TRUE;
        GQParserData *parser_data;
 
-       if (g_file_get_contents(utf8_path, &buf, &size, NULL) == FALSE) 
-               {
-               return FALSE;
-               }
-       
        parser_data = g_new0(GQParserData, 1);
        
        parser_data->startup = startup;
@@ -1126,10 +1191,24 @@ gboolean load_options_from(const gchar *utf8_path, ConfOptions *options, gboolea
                
        g_free(parser_data);
 
-       g_free(buf);
        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;
+}