Mercurial > geeqie
changeset 1404:de06d83e1adc
save and restore the keyword tree
author | nadvornik |
---|---|
date | Sun, 08 Mar 2009 23:09:27 +0000 |
parents | 9274b3b4eaad |
children | 03384485676d |
files | src/metadata.c src/metadata.h src/rcfile.c |
diffstat | 3 files changed, 128 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/metadata.c Sun Mar 08 21:12:45 2009 +0000 +++ b/src/metadata.c Sun Mar 08 23:09:27 2009 +0000 @@ -24,6 +24,7 @@ #include "utilops.h" #include "filefilter.h" #include "layout.h" +#include "rcfile.h" typedef enum { MK_NONE, @@ -982,10 +983,19 @@ } } +void keyword_tree_new(void) +{ + if (keyword_tree) return; + + keyword_tree = gtk_tree_store_new(KEYWORD_COLUMN_COUNT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN); +} + void keyword_tree_new_default(void) { - keyword_tree = gtk_tree_store_new(KEYWORD_COLUMN_COUNT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN); + if (keyword_tree) return; + + keyword_tree_new(); GtkTreeIter i1, i2, i3; @@ -1022,4 +1032,72 @@ } +static void keyword_tree_node_write_config(GtkTreeModel *keyword_tree, GtkTreeIter *iter_ptr, GString *outstr, gint indent) +{ + GtkTreeIter iter = *iter_ptr; + while (TRUE) + { + GtkTreeIter children; + gchar *name; + + WRITE_STRING("<keyword\n"); + indent++; + name = keyword_get_name(keyword_tree, &iter); + write_char_option(outstr, indent, "name", name); + g_free(name); + write_bool_option(outstr, indent, "kw", keyword_get_is_keyword(keyword_tree, &iter)); + indent--; + WRITE_STRING(">\n"); + indent++; + if (gtk_tree_model_iter_children(keyword_tree, &children, &iter)) + { + keyword_tree_node_write_config(keyword_tree, &children, outstr, indent); + } + indent--; + WRITE_STRING("</keyword>\n"); + if (!gtk_tree_model_iter_next(keyword_tree, &iter)) return; + } +} + +void keyword_tree_write_config(GString *outstr, gint indent) +{ + GtkTreeIter iter; + WRITE_STRING("<keyword_tree>\n"); + indent++; + + if (keyword_tree && gtk_tree_model_get_iter_first(GTK_TREE_MODEL(keyword_tree), &iter)) + { + keyword_tree_node_write_config(GTK_TREE_MODEL(keyword_tree), &iter, outstr, indent); + } + indent--; + WRITE_STRING("</keyword_tree>\n"); +} + +GtkTreeIter *keyword_add_from_config(GtkTreeStore *keyword_tree, GtkTreeIter *parent, const gchar **attribute_names, const gchar **attribute_values) +{ + gchar *name = NULL; + gboolean is_kw = TRUE; + + while (*attribute_names) + { + const gchar *option = *attribute_names++; + const gchar *value = *attribute_values++; + + if (READ_CHAR_FULL("name", name)) continue; + if (READ_BOOL_FULL("kw", is_kw)) continue; + + DEBUG_1("unknown attribute %s = %s", option, value); + } + if (name && name[0]) + { + GtkTreeIter iter; + gtk_tree_store_append(keyword_tree, &iter, parent); + keyword_set(keyword_tree, &iter, name, is_kw); + g_free(name); + return gtk_tree_iter_copy(&iter); + } + g_free(name); + return NULL; +} + /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
--- a/src/metadata.h Sun Mar 08 21:12:45 2009 +0000 +++ b/src/metadata.h Sun Mar 08 23:09:27 2009 +0000 @@ -70,7 +70,10 @@ void keyword_tree_reset(GtkTreeModel *keyword_tree, GtkTreeIter *iter_ptr, GList **kw_list); void keyword_tree_new_default(void); +void keyword_tree_new(void); +void keyword_tree_write_config(GString *outstr, gint indent); +GtkTreeIter *keyword_add_from_config(GtkTreeStore *keyword_tree, GtkTreeIter *parent, const gchar **attribute_names, const gchar **attribute_values); #endif /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
--- a/src/rcfile.c Sun Mar 08 21:12:45 2009 +0000 +++ b/src/rcfile.c Sun Mar 08 23:09:27 2009 +0000 @@ -32,6 +32,7 @@ #include "layout.h" #include "layout_util.h" #include "bar.h" +#include "metadata.h" /* @@ -537,7 +538,7 @@ WRITE_STRING("<layout\n"); layout_write_attributes(&options->layout, outstr, indent + 1); WRITE_STRING("/>\n"); - + keyword_tree_write_config(outstr, indent); indent--; WRITE_STRING("</global>\n"); @@ -821,6 +822,45 @@ /* else this is called in init_after_global_options */ } +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); +} + + +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); + } + else + { + DEBUG_1("unexpected in <keyword>: <%s>", element_name); + options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); + } +} + + + +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 + { + DEBUG_1("unexpected in <keyword_tree>: <%s>", element_name); + options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); + } +} + + 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) @@ -832,6 +872,11 @@ { 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 if (g_ascii_strcasecmp(element_name, "layout") == 0) { layout_load_attributes(&options->layout, attribute_names, attribute_values);