changeset 19761:8c356223e182

Select the right account when a buddyname is selected from the suggest-list.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Wed, 12 Sep 2007 09:29:35 +0000
parents 96d4a3238029
children 656506d8935e
files finch/gntrequest.c
diffstat 1 files changed, 23 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/finch/gntrequest.c	Wed Sep 12 09:15:17 2007 +0000
+++ b/finch/gntrequest.c	Wed Sep 12 09:29:35 2007 +0000
@@ -368,6 +368,22 @@
 	purple_request_close(PURPLE_REQUEST_FIELDS, button);
 }
 
+static void
+update_selected_account(GntEntry *screenname, const char *start, const char *end,
+		GntComboBox *accountlist)
+{
+	GList *accounts = gnt_tree_get_rows(GNT_TREE(accountlist->dropdown));
+	const char *name = gnt_entry_get_text(screenname);
+	while (accounts) {
+		if (purple_find_buddy(accounts->data, name)) {
+			gnt_combo_box_set_selected(accountlist, accounts->data);
+			gnt_widget_draw(GNT_WIDGET(accountlist));
+			break;
+		}
+		accounts = accounts->next;
+	}
+}
+
 static void *
 finch_request_fields(const char *title, const char *primary,
 		const char *secondary, PurpleRequestFields *allfields,
@@ -378,6 +394,7 @@
 {
 	GntWidget *window, *box;
 	GList *grlist;
+	GntWidget *screenname = NULL, *accountlist = NULL;
 
 	window = setup_request_window(title, primary, secondary, PURPLE_REQUEST_FIELDS);
 
@@ -439,6 +456,7 @@
 						gnt_entry_add_suggest(GNT_ENTRY(entry), purple_buddy_get_name((PurpleBuddy*)node));
 					}
 					gnt_entry_set_always_suggest(GNT_ENTRY(entry), TRUE);
+					screenname = entry;
 				} else if (hint && !strcmp(hint, "group")) {
 					PurpleBlistNode *node;
 					for (node = purple_blist_get_root(); node; node = node->next) {
@@ -556,6 +574,7 @@
 						gnt_combo_box_set_selected(GNT_COMBO_BOX(combo), account);
 				}
 				gnt_widget_set_size(combo, 20, 3); /* ew */
+				accountlist = combo;
 			}
 			else
 			{
@@ -576,6 +595,10 @@
 	setup_default_callback(window, cancel_cb, userdata);
 	gnt_widget_show(window);
 
+	if (screenname && accountlist) {
+		g_signal_connect(screenname, "completion", G_CALLBACK(update_selected_account), accountlist);
+	}
+
 	g_object_set_data(G_OBJECT(window), "fields", allfields);
 	
 	return window;