Mercurial > pidgin.yaz
diff gtk/gtkutils.c @ 15116:6cb9996fcc97
[gaim-migrate @ 17901]
Rename gtkblist.c:_search_func to gtkutils.c:gaim_gtk_tree_view_search_equal_func.
Use this in the buddylist, the statusbox dropdown and in the plugins dialog. This
can also be used in the smiley-theme-list.
Process Escape and Return key-presses in the statusbox dropdown.
seanegan: I hope I didn't step on your toes O:-)
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Wed, 06 Dec 2006 07:24:41 +0000 |
parents | 51f3c0df6ab4 |
children | 31603a03cc02 |
line wrap: on
line diff
--- a/gtk/gtkutils.c Wed Dec 06 02:15:28 2006 +0000 +++ b/gtk/gtkutils.c Wed Dec 06 07:24:41 2006 +0000 @@ -2964,3 +2964,111 @@ return vbox; } + +/* + * "This is so dead sexy." + * "Two thumbs up." + * "Best movie of the year." + * + * This is the function that handles CTRL+F searching in the buddy list. + * It finds the top-most buddy/group/chat/whatever containing the + * entered string. + * + * It's somewhat ineffecient, because we strip all the HTML from the + * "name" column of the buddy list (because the GtkTreeModel does not + * contain the screen name in a non-markedup format). But the alternative + * is to add an extra column to the GtkTreeModel. And this function is + * used rarely, so it shouldn't matter TOO much. + */ +gboolean gaim_gtk_tree_view_search_equal_func(GtkTreeModel *model, gint column, + const gchar *key, GtkTreeIter *iter, gpointer data) +{ + gchar *enteredstring; + gchar *tmp; + gchar *withmarkup; + gchar *nomarkup; + gchar *normalized; + gboolean result; + size_t i; + size_t len; + PangoLogAttr *log_attrs; + gchar *word; + + if (strcasecmp(key, "Global Thermonuclear War") == 0) + { + gaim_notify_info(NULL, "WOPR", + "Wouldn't you prefer a nice game of chess?", NULL); + return FALSE; + } + + gtk_tree_model_get(model, iter, column, &withmarkup, -1); + if (withmarkup == NULL) /* This is probably a separator */ + return TRUE; + + tmp = g_utf8_normalize(key, -1, G_NORMALIZE_DEFAULT); + enteredstring = g_utf8_casefold(tmp, -1); + g_free(tmp); + + nomarkup = gaim_markup_strip_html(withmarkup); + tmp = g_utf8_normalize(nomarkup, -1, G_NORMALIZE_DEFAULT); + g_free(nomarkup); + normalized = g_utf8_casefold(tmp, -1); + g_free(tmp); + + if (gaim_str_has_prefix(normalized, enteredstring)) + { + g_free(withmarkup); + g_free(enteredstring); + g_free(normalized); + return FALSE; + } + + + /* Use Pango to separate by words. */ + len = g_utf8_strlen(normalized, -1); + log_attrs = g_new(PangoLogAttr, len + 1); + + pango_get_log_attrs(normalized, strlen(normalized), -1, NULL, log_attrs, len + 1); + + word = normalized; + result = TRUE; + for (i = 0; i < (len - 1) ; i++) + { + if (log_attrs[i].is_word_start && + gaim_str_has_prefix(word, enteredstring)) + { + result = FALSE; + break; + } + word = g_utf8_next_char(word); + } + g_free(log_attrs); + +/* The non-Pango version. */ +#if 0 + word = normalized; + result = TRUE; + while (word[0] != '\0') + { + gunichar c = g_utf8_get_char(word); + if (!g_unichar_isalnum(c)) + { + word = g_utf8_find_next_char(word, NULL); + if (gaim_str_has_prefix(word, enteredstring)) + { + result = FALSE; + break; + } + } + else + word = g_utf8_find_next_char(word, NULL); + } +#endif + + g_free(withmarkup); + g_free(enteredstring); + g_free(normalized); + + return result; +} +