# HG changeset patch # User mow # Date 1239479463 0 # Node ID 286ed7c6cae6aab2f41052a92411e441ba2a44b4 # Parent 4df9f4712d1ad87bf8abceb8fe568805ae8e875d Allow to configure case handling of keywords Sometimes I use just different case for keywords. This should be chooseable. diff -r 4df9f4712d1a -r 286ed7c6cae6 src/metadata.c --- a/src/metadata.c Sat Apr 11 19:35:03 2009 +0000 +++ b/src/metadata.c Sat Apr 11 19:51:03 2009 +0000 @@ -854,9 +854,18 @@ { if (!(exclude_sibling && sibling && keyword_compare(keyword_tree, &iter, sibling) == 0)) { - gchar *iter_casefold = keyword_get_casefold(keyword_tree, &iter); - ret = strcmp(casefold, iter_casefold) == 0; - g_free(iter_casefold); + if (options->metadata.tags_case_sensitive) + { + gchar *iter_name = keyword_get_name(keyword_tree, &iter); + ret = strcmp(name, iter_name) == 0; + g_free(iter_name); + } + else + { + gchar *iter_casefold = keyword_get_casefold(keyword_tree, &iter); + ret = strcmp(casefold, iter_casefold) == 0; + g_free(iter_casefold); + } // if (options->metadata.tags_cas... } if (ret) { @@ -1005,24 +1014,79 @@ } } +static gboolean keyword_tree_is_set_casefull(GtkTreeModel *keyword_tree, GtkTreeIter iter, GList *kw_list) +{ + if (!kw_list) return FALSE; + + if (!keyword_get_is_keyword(keyword_tree, &iter)) + { + /* for the purpose of expanding and hiding, a helper is set if it has any children set */ + GtkTreeIter child; + if (!gtk_tree_model_iter_children(keyword_tree, &child, &iter)) + return FALSE; /* this should happen only on empty helpers */ + + while (TRUE) + { + if (keyword_tree_is_set_casefull(keyword_tree, child, kw_list)) return TRUE; + if (!gtk_tree_model_iter_next(keyword_tree, &child)) return FALSE; + } + } + + while (TRUE) + { + GtkTreeIter parent; + + if (keyword_get_is_keyword(keyword_tree, &iter)) + { + GList *work = kw_list; + gboolean found = FALSE; + gchar *iter_name = keyword_get_name(keyword_tree, &iter); + while (work) + { + const gchar *name = work->data; + work = work->next; + + if (strcmp(iter_name, name) == 0) + { + found = TRUE; + break; + } + } + g_free(iter_name); + if (!found) return FALSE; + } + + if (!gtk_tree_model_iter_parent(keyword_tree, &parent, &iter)) return TRUE; + iter = parent; + } +} + gboolean keyword_tree_is_set(GtkTreeModel *keyword_tree, GtkTreeIter *iter, GList *kw_list) { gboolean ret; GList *casefold_list = NULL; GList *work; - work = kw_list; - while (work) + if (options->metadata.tags_case_sensitive) + { + ret = keyword_tree_is_set_casefull(keyword_tree, *iter, kw_list); + } + else { - const gchar *kw = work->data; - work = work->next; + work = kw_list; + while (work) + { + const gchar *kw = work->data; + work = work->next; - casefold_list = g_list_prepend(casefold_list, g_utf8_casefold(kw, -1)); + casefold_list = g_list_prepend(casefold_list, g_utf8_casefold(kw, -1)); + } + + ret = keyword_tree_is_set_casefold(keyword_tree, *iter, casefold_list); + + string_list_free(casefold_list); } - - ret = keyword_tree_is_set_casefold(keyword_tree, *iter, casefold_list); - - string_list_free(casefold_list); + return ret; } diff -r 4df9f4712d1a -r 286ed7c6cae6 src/options.c --- a/src/options.c Sat Apr 11 19:35:03 2009 +0000 +++ b/src/options.c Sat Apr 11 19:51:03 2009 +0000 @@ -103,6 +103,7 @@ options->metadata.confirm_timeout = 10; options->metadata.confirm_on_image_change = FALSE; options->metadata.confirm_on_dir_change = TRUE; + options->metadata.tags_case_sensitive = FALSE; options->show_icon_names = TRUE; diff -r 4df9f4712d1a -r 286ed7c6cae6 src/options.h --- a/src/options.h Sat Apr 11 19:35:03 2009 +0000 +++ b/src/options.h Sat Apr 11 19:51:03 2009 +0000 @@ -177,6 +177,7 @@ gboolean confirm_after_timeout; gboolean confirm_on_image_change; gboolean confirm_on_dir_change; + gboolean tags_case_sensitive; } metadata; }; diff -r 4df9f4712d1a -r 286ed7c6cae6 src/preferences.c --- a/src/preferences.c Sat Apr 11 19:35:03 2009 +0000 +++ b/src/preferences.c Sat Apr 11 19:51:03 2009 +0000 @@ -324,6 +324,7 @@ options->metadata.confirm_after_timeout = c_options->metadata.confirm_after_timeout; options->metadata.confirm_on_image_change = c_options->metadata.confirm_on_image_change; options->metadata.confirm_on_dir_change = c_options->metadata.confirm_on_dir_change; + options->metadata.tags_case_sensitive = c_options->metadata.tags_case_sensitive; #ifdef DEBUG set_debug_level(debug_c); @@ -1364,6 +1365,9 @@ pref_checkbox_new_int(group, _("Write metadata on directory change"), options->metadata.confirm_on_dir_change, &c_options->metadata.confirm_on_dir_change); + + pref_checkbox_new_int(group, _("Allow keywords to differ only in case"), + options->metadata.tags_case_sensitive, &c_options->metadata.tags_case_sensitive); } /* metadata tab */ diff -r 4df9f4712d1a -r 286ed7c6cae6 src/rcfile.c --- a/src/rcfile.c Sat Apr 11 19:35:03 2009 +0000 +++ b/src/rcfile.c Sat Apr 11 19:51:03 2009 +0000 @@ -437,6 +437,7 @@ 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); } @@ -695,6 +696,7 @@ 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; log_printf("unknown attribute %s = %s\n", option, value); }