changeset 10668:aafe8f30b826

[gaim-migrate @ 12208] Richard Laager again. committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Mon, 07 Mar 2005 19:12:15 +0000
parents 51ea57c36056
children 5fae2e790f5d
files src/gtkdialogs.c src/gtkrequest.c
diffstat 2 files changed, 132 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/src/gtkdialogs.c	Mon Mar 07 19:09:45 2005 +0000
+++ b/src/gtkdialogs.c	Mon Mar 07 19:12:15 2005 +0000
@@ -451,10 +451,9 @@
 	group = gaim_request_field_group_new(NULL);
 	gaim_request_fields_add_group(fields, group);
 
-	field = gaim_request_field_string_new("screenname", _("_Screen name"),
-										  NULL, FALSE);
+	field = gaim_request_field_string_new("screenname", _("_Name"), NULL, FALSE);
+	gaim_request_field_set_type_hint(field, "screenname");
 	gaim_request_field_set_required(field, TRUE);
-	gaim_request_field_set_type_hint(field, "screenname");
 	gaim_request_field_group_add_field(group, field);
 
 	field = gaim_request_field_account_new("account", _("_Account"), NULL);
@@ -466,8 +465,8 @@
 
 	gaim_request_fields(gaim_get_blist(), _("New Instant Message"),
 						NULL,
-						_("Please enter the screen name of the person you "
-						  "would like to IM."),
+						_("Please enter the screen name or alias of the person "
+						  "you would like to IM."),
 						fields,
 						_("OK"), G_CALLBACK(gaim_gtkdialogs_im_cb),
 						_("Cancel"), NULL,
@@ -594,8 +593,7 @@
 	group = gaim_request_field_group_new(NULL);
 	gaim_request_fields_add_group(fields, group);
 
-	field = gaim_request_field_string_new("screenname", _("_Screen name"),
-										  NULL, FALSE);
+	field = gaim_request_field_string_new("screenname", _("_Name"), NULL, FALSE);
 	gaim_request_field_set_type_hint(field, "screenname");
 	gaim_request_field_set_required(field, TRUE);
 	gaim_request_field_group_add_field(group, field);
@@ -609,8 +607,8 @@
 
 	gaim_request_fields(gaim_get_blist(), _("Get User Info"),
 						NULL,
-						_("Please enter the screen name of the person whose "
-						  "info you would like to view."),
+						_("Please enter the screen name or alias of the person "
+						  "whose info you would like to view."),
 						fields,
 						_("OK"), G_CALLBACK(gaim_gtkdialogs_info_cb),
 						_("Cancel"), NULL,
@@ -649,8 +647,7 @@
 	group = gaim_request_field_group_new(NULL);
 	gaim_request_fields_add_group(fields, group);
 
-	field = gaim_request_field_string_new("screenname", _("_Screen name"),
-										  NULL, FALSE);
+	field = gaim_request_field_string_new("screenname", _("_Name"), NULL, FALSE);
 	gaim_request_field_set_type_hint(field, "screenname");
 	gaim_request_field_set_required(field, TRUE);
 	gaim_request_field_group_add_field(group, field);
@@ -665,8 +662,8 @@
 
 	gaim_request_fields(gaim_get_blist(), _("Get User Log"),
 						NULL,
-						_("Please enter the screen name of the person whose "
-						  "log you would like to view."),
+						_("Please enter the screen name or alias of the person "
+						  "whose log you would like to view."),
 						fields,
 						_("OK"), G_CALLBACK(gaim_gtkdialogs_log_cb),
 						_("Cancel"), NULL,
--- a/src/gtkrequest.c	Mon Mar 07 19:09:45 2005 +0000
+++ b/src/gtkrequest.c	Mon Mar 07 19:12:15 2005 +0000
@@ -632,9 +632,9 @@
 }
 
 GList *
-get_online_screennames(void)
+get_online_names(void)
 {
-	GList *screennames = NULL;
+	GList *names = NULL;
 	GaimBlistNode *gnode, *cnode, *bnode;
 
 	for (gnode = gaim_get_blist()->root; gnode != NULL; gnode = gnode->next)
@@ -654,12 +654,18 @@
 				if (!gaim_account_is_connected(buddy->account))
 					continue;
 
-				screennames = g_list_append(screennames, g_strdup(buddy->name));
+#ifdef NEW_STYLE_COMPLETION
+				names = g_list_append(names, ((GaimContact *)cnode)->alias);
+				names = g_list_append(names,
+					(gpointer)gaim_buddy_get_contact_alias(buddy));
+#endif /* NEW_STYLE_COMPLETION */
+
+				names = g_list_append(names, buddy->name);
 			}
 		}
 	}
 
-	return screennames;
+	return names;
 }
 
 #ifndef NEW_STYLE_COMPLETION
@@ -736,13 +742,66 @@
 static void
 destroy_completion_data(GtkWidget *w, GaimGtkCompletionData *data)
 {
-	g_list_foreach(data->completion->items, (GFunc)g_free, NULL);
 	g_completion_free(data->completion);
 
 	g_free(data);
 }
 #endif /* !NEW_STYLE_COMPLETION */
 
+#ifdef NEW_STYLE_COMPLETION
+static gboolean screenname_completion_match_func(GtkEntryCompletion *completion,
+		const gchar *key, GtkTreeIter *iter, gpointer user_data) {
+
+	GValue val = { 0, };
+	GtkTreeModel *model;
+	char *screenname = NULL;
+	char *alias = NULL;
+	char *temp;
+	gboolean ret = FALSE;
+
+	model = gtk_entry_completion_get_model (completion);
+
+	gtk_tree_model_get_value(model, iter, 1, &val);
+	temp = (gchar *)g_value_get_string(&val);
+	if (temp) {
+		temp = g_utf8_normalize(temp, -1, G_NORMALIZE_DEFAULT);
+		screenname = g_utf8_casefold(temp, -1);
+		g_free(temp);
+	}
+	g_value_unset(&val);
+
+	gtk_tree_model_get_value(model, iter, 2, &val);
+	temp = (gchar *)g_value_get_string(&val);
+	if (temp) {
+		temp = g_utf8_normalize(temp, -1, G_NORMALIZE_DEFAULT);
+		alias = g_utf8_casefold(temp, -1);
+		g_free(temp);
+	}
+	g_value_unset(&val);
+
+	if (g_str_has_prefix(screenname, key) ||
+	    g_str_has_prefix(alias, key))
+		ret = TRUE;
+
+	g_free(screenname);
+	g_free(alias);
+
+	return ret;
+}
+
+static gboolean screenname_completion_match_selected_cb(GtkEntryCompletion *completion,
+		GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data) {
+
+	GValue val = { 0, };
+
+	gtk_tree_model_get_value(model, iter, 1, &val);
+	gtk_entry_set_text(GTK_ENTRY(user_data), g_value_get_string(&val));
+	g_value_unset(&val);
+
+	return TRUE;
+}
+#endif /* !NEW_STYLE_COMPLETION */
+
 static void
 setup_screenname_autocomplete(GtkWidget *entry, GaimRequestField *field)
 {
@@ -750,22 +809,70 @@
 	GtkListStore *store;
 	GtkTreeIter iter;
 	GtkEntryCompletion *completion;
-	GList *screennames, *l;
+	GList *aliases_and_screennames, *l;
+
+	/* Store the displayed completion value, the screenname, and the value for comparison. */
+	store = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
+
+	aliases_and_screennames = get_online_names();
 
-	store = gtk_list_store_new(1, G_TYPE_STRING);
+	/* Loop through the list three elements at a time. */
+	for (l = aliases_and_screennames; l != NULL; l = l->next->next->next)
+	{
+		char *contact_alias = l->data;
+		char *buddy_alias = l->next->data;
+		char *screenname = l->next->next->data;
+		gboolean completion_added = FALSE;
 
-	screennames = get_online_screennames();
+		/* There's no sense listing things like: 'xxx "xxx"'
+		   when the screenname and buddy alias match. */
+		if (buddy_alias && strcmp(buddy_alias, screenname)) {
+			char *completion_entry = g_strdup_printf("%s \"%s\"", screenname, buddy_alias);
+			gtk_list_store_append(store, &iter);
+			gtk_list_store_set(store, &iter,
+					0, completion_entry,
+					1, screenname,
+					2, buddy_alias,
+					-1);
+			g_free(completion_entry);
+			completion_added = TRUE;
+		}
 
-	for (l = screennames; l != NULL; l = l->next)
-	{
-		gtk_list_store_append(store, &iter);
-		gtk_list_store_set(store, &iter, 0, l->data, -1);
+		/* There's no sense listing things like: 'xxx "xxx"'
+		   when the screenname and contact alias match. */
+		if (contact_alias && strcmp(contact_alias, screenname)) {
+			/* We don't want duplicates when the contact and buddy alias match. */
+			if (strcmp(contact_alias, buddy_alias)) {
+				char *completion_entry = g_strdup_printf("%s \"%s\"",
+								screenname, contact_alias);
+				gtk_list_store_append(store, &iter);
+				gtk_list_store_set(store, &iter,
+						0, completion_entry,
+						1, screenname,
+						2, contact_alias,
+						-1);
+				g_free(completion_entry);
+				completion_added = TRUE;
+			}
+		}
+
+		if (completion_added == FALSE) {
+			/* Add the buddy's screenname. */
+			gtk_list_store_append(store, &iter);
+			gtk_list_store_set(store, &iter,
+					0, screenname,
+					1, screenname,
+					2, NULL,
+					-1);
+		}
 	}
 
-	g_list_foreach(screennames, (GFunc)g_free, NULL);
-	g_list_free(screennames);
+	g_list_free(aliases_and_screennames);
 
 	completion = gtk_entry_completion_new();
+	gtk_entry_completion_set_match_func(completion, screenname_completion_match_func, NULL, NULL);
+	g_signal_connect(G_OBJECT(completion), "match-selected",
+		G_CALLBACK(screenname_completion_match_selected_cb), entry);
 	gtk_entry_set_completion(GTK_ENTRY(entry), completion);
 	g_object_unref(completion);
 
@@ -784,7 +891,7 @@
 
 	g_completion_set_compare(data->completion, g_ascii_strncasecmp);
 
-	screennames = get_online_screennames();
+	screennames = get_online_names();
 
 	g_completion_add_items(data->completion, screennames);