changeset 1340:361120a66609

Use g_utf8_casefold() to compare keywords, uppercased/lowercased keywords are now matched against predefined list.
author zas_
date Sat, 28 Feb 2009 18:01:16 +0000
parents 45bcfcb69f56
children 63eb48237608
files src/bar_keywords.c src/metadata.c src/metadata.h
diffstat 3 files changed, 29 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/src/bar_keywords.c	Sat Feb 28 17:20:16 2009 +0000
+++ b/src/bar_keywords.c	Sat Feb 28 18:01:16 2009 +0000
@@ -419,7 +419,7 @@
 		gchar *key = list->data;
 
 		gtk_list_store_append(store, &iter);
-		gtk_list_store_set(store, &iter, KEYWORD_COLUMN_TOGGLE, find_string_in_list(keywords, key),
+		gtk_list_store_set(store, &iter, KEYWORD_COLUMN_TOGGLE, !!find_string_in_list_utf8nocase(keywords, key),
 						 KEYWORD_COLUMN_TEXT, key,
 						 KEYWORD_COLUMN_MARK, bar_pane_keywords_get_mark_text(key), -1);
 
@@ -506,30 +506,19 @@
 static void bar_pane_keywords_keyword_set(PaneKeywordsData *pkd, const gchar *keyword, gint active)
 {
 	GList *list;
-	gint found;
+	gchar *found;
 
 	if (!keyword) return;
 
 	list = keyword_list_pull(pkd->keyword_view);
-	found = find_string_in_list(list, keyword);
+	found = find_string_in_list_utf8nocase(list, keyword);
 
-	if (active != found)
+	if ((!active && found) || (active && !found))
 		{
 		if (found)
 			{
-			GList *work = list;
-
-			while (work)
-				{
-				gchar *key = work->data;
-				work = work->next;
-
-				if (key && keyword && strcmp(key, keyword) == 0)
-					{
-					list = g_list_remove(list, key);
-					g_free(key);
-					}
-				}
+			list = g_list_remove(list, found);
+			g_free(found);
 			}
 		else
 			{
--- a/src/metadata.c	Sat Feb 28 17:20:16 2009 +0000
+++ b/src/metadata.c	Sat Feb 28 18:01:16 2009 +0000
@@ -549,19 +549,36 @@
 		}
 }
 
-gboolean find_string_in_list(GList *list, const gchar *string)
+gchar *find_string_in_list_utf8nocase(GList *list, const gchar *string)
 {
+	gchar *string_casefold = g_utf8_casefold(string, -1);
+
 	while (list)
 		{
 		gchar *haystack = list->data;
+		
+		if (haystack)
+			{
+			gboolean equal;
+			gchar *haystack_casefold = g_utf8_casefold(haystack, -1);
 
-		if (haystack && string && strcmp(haystack, string) == 0) return TRUE;
+			equal = (strcmp(haystack_casefold, string_casefold) == 0);
+			g_free(haystack_casefold);
 
+			if (equal)
+				{
+				g_free(string_casefold);
+				return haystack;
+				}
+			}
+	
 		list = list->next;
 		}
+	
+	g_free(string_casefold);
+	return NULL;
+}
 
-	return FALSE;
-}
 
 #define KEYWORDS_SEPARATOR(c) ((c) == ',' || (c) == ';' || (c) == '\n' || (c) == '\r' || (c) == '\b')
 
@@ -592,7 +609,7 @@
 			gchar *keyword = g_strndup(begin, l);
 
 			/* only add if not already in the list */
-			if (find_string_in_list(list, keyword) == FALSE)
+			if (!find_string_in_list_utf8nocase(list, keyword))
 				list = g_list_append(list, keyword);
 			else
 				g_free(keyword);
--- a/src/metadata.h	Sat Feb 28 17:20:16 2009 +0000
+++ b/src/metadata.h	Sat Feb 28 18:01:16 2009 +0000
@@ -34,8 +34,8 @@
 gboolean metadata_append_string(FileData *fd, const gchar *key, const char *value);
 gboolean metadata_append_list(FileData *fd, const gchar *key, const GList *values);
 
-gboolean find_string_in_list(GList *list, const gchar *keyword);
 GList *string_to_keywords_list(const gchar *text);
+gchar *find_string_in_list_utf8nocase(GList *list, const gchar *string);
 
 gboolean meta_data_get_keyword_mark(FileData *fd, gint n, gpointer data);
 gboolean meta_data_set_keyword_mark(FileData *fd, gint n, gboolean value, gpointer data);