changeset 1465:400ecfc3d8b1

do not add duplicate keywords from config file
author nadvornik
date Fri, 20 Mar 2009 11:52:29 +0000
parents 1b3751ac4743
children 6e020d3ab168
files src/bar_keywords.c src/metadata.c src/metadata.h
diffstat 3 files changed, 16 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/bar_keywords.c	Fri Mar 20 10:12:29 2009 +0000
+++ b/src/bar_keywords.c	Fri Mar 20 11:52:29 2009 +0000
@@ -535,7 +535,7 @@
 		}
 
 	src_name = keyword_get_name(keyword_tree, src_kw_iter);
-	if (keyword_exists(keyword_tree, NULL, dest_kw_iter, src_name, FALSE))
+	if (keyword_exists(keyword_tree, NULL, dest_kw_iter, src_name, FALSE, NULL))
 		{
 		g_free(src_name);
 		return FALSE;
@@ -551,7 +551,7 @@
 	while (work)
 		{
 		gchar *keyword = work->data;
-		if (keyword_exists(keyword_tree, NULL, dest_kw_iter, keyword, FALSE))
+		if (keyword_exists(keyword_tree, NULL, dest_kw_iter, keyword, FALSE, NULL))
 			{
 			GList *next = work->next;
 			g_free(keyword);
@@ -781,7 +781,7 @@
 	if (cdd->edit_existing)
 		{
 		if (keywords && keywords->data && /* there should be one keyword */
-		    !keyword_exists(keyword_tree, NULL, &kw_iter, keywords->data, TRUE))
+		    !keyword_exists(keyword_tree, NULL, &kw_iter, keywords->data, TRUE, NULL))
 			{
 			keyword_set(GTK_TREE_STORE(keyword_tree), &kw_iter, keywords->data, cdd->is_keyword);
 			}
@@ -793,7 +793,7 @@
 		while (work)
 			{
 			GtkTreeIter add;
-			if (keyword_exists(keyword_tree, NULL, have_dest ? &kw_iter : NULL, work->data, FALSE))
+			if (keyword_exists(keyword_tree, NULL, have_dest ? &kw_iter : NULL, work->data, FALSE, NULL))
 				{
 				work = work->next;
 				continue;
--- a/src/metadata.c	Fri Mar 20 10:12:29 2009 +0000
+++ b/src/metadata.c	Fri Mar 20 11:52:29 2009 +0000
@@ -784,7 +784,7 @@
 		}
 }
 
-gboolean keyword_exists(GtkTreeModel *keyword_tree, GtkTreeIter *parent_ptr, GtkTreeIter *sibling, const gchar *name, gboolean exclude_sibling)
+gboolean keyword_exists(GtkTreeModel *keyword_tree, GtkTreeIter *parent_ptr, GtkTreeIter *sibling, const gchar *name, gboolean exclude_sibling, GtkTreeIter *result)
 {
 	GtkTreeIter parent;
 	GtkTreeIter iter;
@@ -818,7 +818,11 @@
 			ret = strcmp(casefold, iter_casefold) == 0;
 			g_free(iter_casefold);
 			}
-		if (ret) break;
+		if (ret) 
+			{
+			if (result) *result = iter;
+			break;
+			}
 		if (!gtk_tree_model_iter_next(keyword_tree, &iter)) break;
 		}
 	g_free(casefold);
@@ -1292,7 +1296,11 @@
 	if (name && name[0]) 
 		{
 		GtkTreeIter iter;
-		gtk_tree_store_append(keyword_tree, &iter, parent);
+		/* re-use existing keyword if any */
+		if (!keyword_exists(GTK_TREE_MODEL(keyword_tree), parent, NULL, name, FALSE, &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);
--- a/src/metadata.h	Fri Mar 20 10:12:29 2009 +0000
+++ b/src/metadata.h	Fri Mar 20 11:52:29 2009 +0000
@@ -61,7 +61,7 @@
 
 gboolean keyword_compare(GtkTreeModel *keyword_tree, GtkTreeIter *a, GtkTreeIter *b);
 gboolean keyword_same_parent(GtkTreeModel *keyword_tree, GtkTreeIter *a, GtkTreeIter *b);
-gboolean keyword_exists(GtkTreeModel *keyword_tree, GtkTreeIter *parent_ptr, GtkTreeIter *sibling, const gchar *name, gboolean exclude_sibling);
+gboolean keyword_exists(GtkTreeModel *keyword_tree, GtkTreeIter *parent_ptr, GtkTreeIter *sibling, const gchar *name, gboolean exclude_sibling, GtkTreeIter *result);
 
 void keyword_copy(GtkTreeStore *keyword_tree, GtkTreeIter *to, GtkTreeIter *from);
 void keyword_copy_recursive(GtkTreeStore *keyword_tree, GtkTreeIter *to, GtkTreeIter *from);