changeset 27615:b909c4a7bfc8

Allow changing contact details for folks in the buddylist.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Wed, 15 Jul 2009 03:17:54 +0000
parents fa827f6f990f
children a756b4ed306e
files libpurple/protocols/yahoo/libymsg.c libpurple/protocols/yahoo/yahoo_aliases.c libpurple/protocols/yahoo/yahoo_aliases.h
diffstat 3 files changed, 62 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/yahoo/libymsg.c	Tue Jul 14 21:08:56 2009 +0000
+++ b/libpurple/protocols/yahoo/libymsg.c	Wed Jul 15 03:17:54 2009 +0000
@@ -3871,6 +3871,16 @@
 	yahoo_doodle_initiate(gc, purple_buddy_get_name(b));
 }
 
+static void
+yahoo_userinfo_blist_node(PurpleBlistNode *node, gpointer data)
+{
+	PurpleBuddy *b = (PurpleBuddy *)node;
+	PurpleAccount *account = purple_buddy_get_account(b);
+	PurpleConnection *gc = purple_account_get_connection(account);
+
+	yahoo_set_userinfo_for_buddy(gc, b);
+}
+
 static GList *yahoo_buddy_menu(PurpleBuddy *buddy)
 {
 	GList *m = NULL;
@@ -3932,13 +3942,16 @@
 		act = purple_menu_action_new(_("Presence Settings"), NULL, NULL,
 		                           build_presence_submenu(f, gc));
 		m = g_list_append(m, act);
-	}
-
-	if (f) {
+
 		act = purple_menu_action_new(_("Start Doodling"),
 		                           PURPLE_CALLBACK(yahoo_doodle_blist_node),
 		                           NULL, NULL);
 		m = g_list_append(m, act);
+
+		act = purple_menu_action_new(_("Set User Info..."),
+		                           PURPLE_CALLBACK(yahoo_userinfo_blist_node),
+		                           NULL, NULL);
+		m = g_list_append(m, act);
 	}
 
 	return m;
--- a/libpurple/protocols/yahoo/yahoo_aliases.c	Tue Jul 14 21:08:56 2009 +0000
+++ b/libpurple/protocols/yahoo/yahoo_aliases.c	Wed Jul 15 03:17:54 2009 +0000
@@ -467,8 +467,8 @@
 	xmlnode_set_attrib(node, "cc", "1");		/* XXX: ? */
 
 	xmlnode_set_attrib(ct, "e", "1");
-	xmlnode_set_attrib(ct, "yi", purple_connection_get_display_name(gc));
-	xmlnode_set_attrib(ct, "id", yd->ypd.id);
+	xmlnode_set_attrib(ct, "yi", purple_request_fields_get_string(fields, "yname"));
+	xmlnode_set_attrib(ct, "id", purple_request_fields_get_string(fields, "yid"));
 	xmlnode_set_attrib(ct, "pr", "0");
 
 	for (i = 0; yfields[i]; i++) {
@@ -529,25 +529,25 @@
 	g_free(request);
 }
 
-void yahoo_set_userinfo(PurpleConnection *gc)
+static PurpleRequestFields *
+request_fields_from_personal_details(YahooPersonalDetails *ypd, const char *id)
 {
 	PurpleRequestFields *fields;
 	PurpleRequestFieldGroup *group;
 	PurpleRequestField *field;
-	struct yahoo_data *yd = purple_connection_get_protocol_data(gc);
 	int i;
 	struct {
 		char *id;
 		char *text;
 		char *value;
 	} yfields[] = {
-		{"fn", N_("First Name"), yd->ypd.names.first},
-		{"ln", N_("Last Name"), yd->ypd.names.last},
-		{"nn", N_("Nickname"), yd->ypd.names.nick},
-		{"mn", N_("Middle Name"), yd->ypd.names.middle},
-		{"hp", N_("Home Phone Number"), yd->ypd.phone.home},
-		{"wp", N_("Work Phone Number"), yd->ypd.phone.work},
-		{"mo", N_("Mobile Phone Number"), yd->ypd.phone.mobile},
+		{"fn", N_("First Name"), ypd->names.first},
+		{"ln", N_("Last Name"), ypd->names.last},
+		{"nn", N_("Nickname"), ypd->names.nick},
+		{"mn", N_("Middle Name"), ypd->names.middle},
+		{"hp", N_("Home Phone Number"), ypd->phone.home},
+		{"wp", N_("Work Phone Number"), ypd->phone.work},
+		{"mo", N_("Mobile Phone Number"), ypd->phone.mobile},
 		{NULL, NULL, NULL}
 	};
 
@@ -555,12 +555,46 @@
 	group = purple_request_field_group_new(NULL);
 	purple_request_fields_add_group(fields, group);
 
+	field = purple_request_field_string_new("yname", "", id, FALSE);
+	purple_request_field_set_visible(field, FALSE);
+	purple_request_field_group_add_field(group, field);
+
+	field = purple_request_field_string_new("yid", "", ypd->id, FALSE);
+	purple_request_field_set_visible(field, FALSE);
+	purple_request_field_group_add_field(group, field);
+
 	for (i = 0; yfields[i].id; i++) {
 		field = purple_request_field_string_new(yfields[i].id, _(yfields[i].text),
 				yfields[i].value, FALSE);
 		purple_request_field_group_add_field(group, field);
 	}
 
+	return fields;
+}
+
+void yahoo_set_userinfo_for_buddy(PurpleConnection *gc, PurpleBuddy *buddy)
+{
+	PurpleRequestFields *fields;
+	YahooFriend *f;
+	const char *name;
+
+	name = purple_buddy_get_name(buddy);
+	f = yahoo_friend_find(gc, name);
+	if (!f)
+		return;
+
+	fields = request_fields_from_personal_details(&f->ypd, name);
+	purple_request_fields(gc, NULL, _("Set User Info"), NULL, fields,
+			_("OK"), G_CALLBACK(yahoo_set_userinfo_cb),
+			_("Cancel"), NULL,
+			purple_connection_get_account(gc), NULL, NULL, gc);
+}
+
+void yahoo_set_userinfo(PurpleConnection *gc)
+{
+	struct yahoo_data *yd = purple_connection_get_protocol_data(gc);
+	PurpleRequestFields *fields = request_fields_from_personal_details(&yd->ypd,
+					purple_connection_get_display_name(gc));
 	purple_request_fields(gc, NULL, _("Set User Info"), NULL, fields,
 			_("OK"), G_CALLBACK(yahoo_set_userinfo_cb),
 			_("Cancel"), NULL,
--- a/libpurple/protocols/yahoo/yahoo_aliases.h	Tue Jul 14 21:08:56 2009 +0000
+++ b/libpurple/protocols/yahoo/yahoo_aliases.h	Wed Jul 15 03:17:54 2009 +0000
@@ -36,5 +36,6 @@
 void yahoo_update_alias(PurpleConnection *gc, const char *who, const char *alias);
 void yahoo_fetch_aliases(PurpleConnection *gc);
 void yahoo_set_userinfo(PurpleConnection *gc);
+void yahoo_set_userinfo_for_buddy(PurpleConnection *gc, PurpleBuddy *buddy);
 void yahoo_personal_details_reset(YahooPersonalDetails *ypd, gboolean all);
 void yahoo_process_contact_details(PurpleConnection *gc, struct yahoo_packet *pkt);