changeset 30688:3d34a0870920

Add a dialog listing the other endpoints from which users can sign them out
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Tue, 15 Dec 2009 08:57:37 +0000
parents 4c8bd8efacb8
children fe607234b0d8
files libpurple/protocols/msn/msn.c
diffstat 1 files changed, 94 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/msn/msn.c	Tue Dec 15 08:12:52 2009 +0000
+++ b/libpurple/protocols/msn/msn.c	Tue Dec 15 08:57:37 2009 +0000
@@ -358,40 +358,110 @@
 					   gc);
 }
 
+typedef struct MsnLocationData {
+	PurpleAccount *account;
+	MsnSession *session;
+	PurpleRequestFieldGroup *group;
+} MsnLocationData;
+
 static void
-set_endpoint_cb(PurpleConnection *pc, const char *entry)
+update_endpoint_cb(MsnLocationData *data, PurpleRequestFields *fields)
 {
-	MsnSession *session;
 	PurpleAccount *account;
-
-	session = purple_connection_get_protocol_data(pc);
-	account = purple_connection_get_account(pc);
-
-	/* Empty endpoint names are not allowed */
-	if (!entry || !*entry)
-		return;
-
-	purple_account_set_string(account, "endpoint-name", entry);
-	msn_notification_send_uux_private_endpointdata(session);
+	MsnSession *session;
+	const char *old_name;
+	const char *name;
+	GList *others;
+
+	session = data->session;
+	account = data->account;
+
+	/* Update the current location's name */
+	old_name = purple_account_get_string(account, "endpoint-name", NULL);
+	name = purple_request_fields_get_string(fields, "endpoint-name");
+	if (!g_str_equal(old_name, name)) {
+		purple_account_set_string(account, "endpoint-name", name);
+		msn_notification_send_uux_private_endpointdata(session);
+	}
+
+	/* Sign out other locations */
+	for (others = purple_request_field_group_get_fields(data->group);
+	     others;
+	     others = g_list_next(others)) {
+		if (!purple_request_field_bool_get_value(others->data)) {
+			const char *id = purple_request_field_get_id(others->data);
+			char *user;
+			purple_debug_info("msn", "Disconnecting Endpoint %s\n", id);
+
+			user = g_strdup_printf("%s;%s", purple_account_get_username(account), id);
+			msn_notification_send_uun(session, user, MSN_UNIFIED_NOTIFICATION_MPOP, "goawyplzthxbye");
+			g_free(user);
+		}
+	}
+
+	g_free(data);
 }
 
 static void
-msn_show_set_endpoint_name(PurplePluginAction *action)
+create_endpoint_fields(gpointer key, gpointer value, gpointer user_data)
+{
+	const char *id = key;
+	MsnUserEndpoint *ep = value;
+	MsnLocationData *data = user_data;
+	PurpleRequestField *field;
+
+	if (g_str_equal(id, data->session->guid))
+		return;
+
+	field = purple_request_field_bool_new(id, ep->name, TRUE);
+	purple_request_field_group_add_field(data->group, field);
+}
+
+static void
+msn_show_locations(PurplePluginAction *action)
 {
 	PurpleConnection *pc;
 	PurpleAccount *account;
+	MsnSession *session;
+	PurpleRequestFields *fields;
+	PurpleRequestFieldGroup *group;
+	PurpleRequestField *field;
+	MsnLocationData *data;
 
 	pc = (PurpleConnection *)action->context;
 	account = purple_connection_get_account(pc);
-
-	purple_request_input(pc, NULL, _("Set your location name."),
-	                     _("This is the name that identifies this location."),
-	                     purple_account_get_string(account, "endpoint-name", NULL),
-	                     FALSE, FALSE, NULL,
-	                     _("OK"), G_CALLBACK(set_endpoint_cb),
-	                     _("Cancel"), NULL,
-	                     account, NULL, NULL,
-	                     pc);
+	session = purple_connection_get_protocol_data(pc);
+
+	fields = purple_request_fields_new();
+
+	group = purple_request_field_group_new(_("This Location"));
+	purple_request_fields_add_group(fields, group);
+	field = purple_request_field_label_new("endpoint-label", _("This is the name that identifies this location"));
+	purple_request_field_group_add_field(group, field);
+	field = purple_request_field_string_new("endpoint-name",
+	                                        _("Name"),
+	                                        purple_account_get_string(account, "endpoint-name", NULL),
+	                                        FALSE);
+	purple_request_field_set_required(field, TRUE);
+	purple_request_field_group_add_field(group, field);
+
+	group = purple_request_field_group_new(_("Other Locations"));
+	purple_request_fields_add_group(fields, group);
+	field = purple_request_field_label_new("others-label", _("You can sign out from other locations here"));
+	purple_request_field_group_add_field(group, field);
+	
+	data = g_new0(MsnLocationData, 1);
+	data->account = account;
+	data->session = session;
+	data->group = group;
+	g_hash_table_foreach(session->user->endpoints, create_endpoint_fields, data);
+
+	purple_request_fields(pc, NULL, NULL, NULL,
+	                      fields,
+	                      _("OK"), G_CALLBACK(update_endpoint_cb),
+	                      _("Cancel"), G_CALLBACK(g_free),
+	                      account, NULL, NULL,
+	                      data);
 }
 
 static void
@@ -967,8 +1037,8 @@
 	m = g_list_append(m, act);
 	m = g_list_append(m, NULL);
 
-	act = purple_plugin_action_new(_("Set Location Name..."),
-	                               msn_show_set_endpoint_name);
+	act = purple_plugin_action_new(_("View Locations..."),
+	                               msn_show_locations);
 	m = g_list_append(m, act);
 	m = g_list_append(m, NULL);