changeset 642:9c74ff4bf1cd

Extract and append keywords from Iptc.Application2.Keywords tags. A function was added to make the keywords unique in the list. Note: Iptc.Application2.Keywords is only read, not written.
author zas_
date Mon, 12 May 2008 17:10:40 +0000
parents 81441380d3be
children eaf94facc190
files src/bar_info.c
diffstat 1 files changed, 35 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/bar_info.c	Mon May 12 10:46:23 2008 +0000
+++ b/src/bar_info.c	Mon May 12 17:10:40 2008 +0000
@@ -246,6 +246,30 @@
 	return success;
 }
 
+static GList *remove_duplicate_strings_from_list(GList *list)
+{
+	GList *work = list;
+	GHashTable *hashtable = g_hash_table_new(g_str_hash, g_str_equal);
+	GList *newlist = NULL;
+
+	while (work)
+		{
+		gchar *key = work->data;
+
+		if (g_hash_table_lookup(hashtable, key) == NULL)
+			{
+			g_hash_table_insert(hashtable, (gpointer) key, GINT_TO_POINTER(1));
+			newlist = g_list_prepend(newlist, key);
+			}
+		work = work->next; 
+		}
+
+	g_hash_table_destroy(hashtable);
+	g_list_free(list);
+
+	return g_list_reverse(newlist);
+}
+
 #define COMMENT_KEY "Xmp.dc.description"
 #define KEYWORD_KEY "Xmp.dc.subject"
 
@@ -276,6 +300,15 @@
 			if (!kw) break;
 			*keywords = g_list_append(*keywords, (gpointer) kw);
 			}
+		
+		item = exif_get_item(exif, "Iptc.Application2.Keywords");
+		for (i = 0; i < exif_item_get_elements(item); i++)
+			{
+			gchar *kw = exif_item_get_string(item, i);
+
+			if (!kw) break;
+			*keywords = g_list_append(*keywords, (gpointer) kw);
+			}
 		}
 
 	exif_free(exif);
@@ -367,6 +400,8 @@
 			*keywords = g_list_concat(keywords1, keywords2);
 		else
 			*keywords = res1 ? keywords1 : keywords2;
+
+		*keywords = remove_duplicate_strings_from_list(*keywords);
 		}
 	else
 		{