# HG changeset patch # User zas_ # Date 1208633290 0 # Node ID 134beb10d916f57b25d09c45af5b9a443d3b623e # Parent 9fe0ca1b52631a6b3ffd4b7c2f24537d2c953c18 Accept keywords composed by two words ("Todo" = "A faire" in french). Prevent duplicate keywords in the list. diff -r 9fe0ca1b5263 -r 134beb10d916 src/bar_info.c --- a/src/bar_info.c Sat Apr 19 17:55:41 2008 +0000 +++ b/src/bar_info.c Sat Apr 19 19:28:10 2008 +0000 @@ -225,8 +225,8 @@ return success; } -gchar *comment_key = "Xmp.dc.description"; -gchar *keyword_key = "Xmp.dc.subject"; +const gchar *comment_key = "Xmp.dc.description"; +const gchar *keyword_key = "Xmp.dc.subject"; static gint comment_xmp_read(FileData *fd, GList **keywords, gchar **comment) { @@ -379,6 +379,20 @@ return gtk_text_buffer_get_text(buffer, &start, &end, FALSE); } +static gint keyword_list_find(GList *list, const gchar *keyword) +{ + while (list) + { + gchar *haystack = list->data; + + if (haystack && keyword && strcmp(haystack, keyword) == 0) return TRUE; + + list = list->next; + } + + return FALSE; +} + GList *keyword_list_pull(GtkWidget *text_widget) { GList *list = NULL; @@ -404,20 +418,29 @@ gchar *begin; gint l = 0; - while (*ptr == ' ' || *ptr == ',' || *ptr == '\n' || *ptr == '\r' || *ptr == '\b') ptr++; +#define KEYWORDS_SEPARATOR(c) ((c) == ',' || (c) == ';' || (c) == '\n' || (c) == '\r' || (c) == '\b') + while (KEYWORDS_SEPARATOR(*ptr)) ptr++; begin = ptr; - if (*ptr != '\0') + while (*ptr != '\0' && !KEYWORDS_SEPARATOR(*ptr)) { - while (*ptr != ' ' && *ptr != ',' && - *ptr != '\n' && *ptr != '\r' && *ptr != '\b' && - *ptr != '\0') - { - ptr++; - l++; - } + ptr++; + l++; } + + /* trim starting and ending whitespaces */ + while (l > 0 && g_ascii_isspace(*begin)) begin++, l--; + while (l > 0 && g_ascii_isspace(begin[l-1])) l--; - if (l > 0) list = g_list_append(list, g_strndup(begin, l)); + if (l > 0) + { + gchar *keyword = g_strndup(begin, l); + + /* only add if not already in the list */ + if (keyword_list_find(list, keyword) == FALSE) + list = g_list_append(list, keyword); + else + g_free(keyword); + } } g_free(text); @@ -822,20 +845,6 @@ } } -static gint bar_keyword_list_find(GList *list, const gchar *keyword) -{ - while (list) - { - gchar *haystack = list->data; - - if (haystack && keyword && strcmp(haystack, keyword) == 0) return TRUE; - - list = list->next; - } - - return FALSE; -} - static void bar_keyword_list_sync(BarInfoData *bd, GList *keywords) { GList *list; @@ -868,7 +877,7 @@ gchar *key = list->data; gtk_list_store_append(store, &iter); - gtk_list_store_set(store, &iter, KEYWORD_COLUMN_TOGGLE, bar_keyword_list_find(keywords, key), + gtk_list_store_set(store, &iter, KEYWORD_COLUMN_TOGGLE, keyword_list_find(keywords, key), KEYWORD_COLUMN_TEXT, key, -1); list = list->prev; @@ -986,7 +995,7 @@ if (!keyword) return; list = keyword_list_pull(bd->keyword_view); - found = bar_keyword_list_find(list, keyword); + found = keyword_list_find(list, keyword); if (active != found) {