changeset 28923:fff8cf8459c4

Search friends by email addresses in the buddylist. Display names may change, but email addresses are not. I don't like to use mouse and my eyes to search in a buddy list with hundreds of entries. Closes #9322. committer: Sadrul Habib Chowdhury <imadil@gmail.com>
author Luoh Ren-Shan <lcamel@gmail.com>
date Fri, 29 Jan 2010 03:56:00 +0000
parents 45fce067c690
children 4931a24576bd
files COPYRIGHT ChangeLog pidgin/gtkblist.c
diffstat 3 files changed, 49 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/COPYRIGHT	Fri Jan 29 01:41:16 2010 +0000
+++ b/COPYRIGHT	Fri Jan 29 03:56:00 2010 +0000
@@ -379,6 +379,7 @@
 R. Ramkumar
 Mart Raudsepp
 Etan Reisner
+Luoh Ren-Shan
 Kristian Rietveld
 Pekka Riikonen
 Tim Ringenbach
--- a/ChangeLog	Fri Jan 29 01:41:16 2010 +0000
+++ b/ChangeLog	Fri Jan 29 03:56:00 2010 +0000
@@ -40,6 +40,7 @@
 	  interior-focus style property is diabled. (Gabriel Schulhof)
 	* Correctly handle a multiline text field being required in a
 	  request form.  (Thanks to Florian Zeitz for finding this problem)
+	* Search friends by email-addresses in the buddy list. (Luoh Ren-Shan)
 
 version 2.6.5 (01/08/2010):
 	libpurple:
--- a/pidgin/gtkblist.c	Fri Jan 29 01:41:16 2010 +0000
+++ b/pidgin/gtkblist.c	Fri Jan 29 03:56:00 2010 +0000
@@ -5616,6 +5616,51 @@
 
 }
 
+static gboolean
+pidgin_blist_search_equal_func(GtkTreeModel *model, gint column,
+			const gchar *key, GtkTreeIter *iter, gpointer data)
+{
+	PurpleBlistNode *node = NULL;
+	gboolean res = TRUE;
+	const char *compare = NULL;
+
+	if (!pidgin_tree_view_search_equal_func(model, column, key, iter, data))
+		return FALSE;
+
+	/* If the search string does not match the displayed label, then look
+	 * at the alternate labels for the nodes and search in them. Currently,
+	 * alternate labels that make sense are usernames/email addresses for
+	 * buddies (but only for the ones who don't have a local alias).
+	 */
+
+	gtk_tree_model_get(model, iter, NODE_COLUMN, &node, -1);
+	if (!node)
+		return TRUE;
+
+	compare = NULL;
+	if (PURPLE_BLIST_NODE_IS_CONTACT(node)) {
+		PurpleBuddy *b = purple_contact_get_priority_buddy(PURPLE_CONTACT(node));
+		if (!purple_buddy_get_local_buddy_alias(b))
+			compare = purple_buddy_get_name(b);
+	} else if (PURPLE_BLIST_NODE_IS_BUDDY(node)) {
+		if (!purple_buddy_get_local_buddy_alias(PURPLE_BUDDY(node)))
+			compare = purple_buddy_get_name(PURPLE_BUDDY(node));
+	}
+
+	if (compare) {
+		char *tmp, *enteredstring;
+		tmp = g_utf8_normalize(key, -1, G_NORMALIZE_DEFAULT);
+		enteredstring = g_utf8_casefold(tmp, -1);
+		g_free(tmp);
+
+		if (purple_str_has_prefix(compare, enteredstring))
+			res = FALSE;
+		g_free(enteredstring);
+	}
+
+	return res;
+}
+
 static void pidgin_blist_show(PurpleBuddyList *list)
 {
 	PidginBuddyListPrivate *priv;
@@ -5852,7 +5897,8 @@
 
 	/* Enable CTRL+F searching */
 	gtk_tree_view_set_search_column(GTK_TREE_VIEW(gtkblist->treeview), NAME_COLUMN);
-	gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(gtkblist->treeview), pidgin_tree_view_search_equal_func, NULL, NULL);
+	gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(gtkblist->treeview),
+			pidgin_blist_search_equal_func, NULL, NULL);
 
 	gtk_box_pack_start(GTK_BOX(gtkblist->vbox), sw, TRUE, TRUE, 0);
 	gtk_container_add(GTK_CONTAINER(sw), gtkblist->treeview);