changeset 5363:ebebc833cf77

[gaim-migrate @ 5739] You can now set your home, work, and mobile phone numbers. Trust me, I'm going somewhere with all this. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Tue, 13 May 2003 08:03:27 +0000
parents a206742d470d
children 379beab3d157
files src/protocols/msn/msn.c src/protocols/msn/notification.c src/protocols/msn/session.h src/protocols/msn/user.c src/protocols/msn/user.h
diffstat 5 files changed, 264 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/msn/msn.c	Tue May 13 04:37:37 2003 +0000
+++ b/src/protocols/msn/msn.c	Tue May 13 08:03:27 2003 +0000
@@ -67,12 +67,79 @@
 }
 
 static void
+msn_set_phone_number(gpointer data, const char *type, const char *entry)
+{
+	struct gaim_connection *gc = data;
+	MsnSession *session = gc->proto_data;
+	char outparams[MSN_BUF_LEN];
+
+	if (entry == NULL || *entry == '\0')
+		g_snprintf(outparams, sizeof(outparams), "%s  ", type);
+	else
+		g_snprintf(outparams, sizeof(outparams), "%s %s", type, entry);
+
+	if (!msn_servconn_send_command(session->notification_conn,
+								   "PRP", outparams)) {
+
+		hide_login_progress(gc, _("Write error"));
+		signoff(gc);
+	}
+}
+
+static void
+msn_set_home_phone_cb(gpointer data, char *entry)
+{
+	msn_set_phone_number(data, "PHH", entry);
+}
+
+static void
+msn_set_work_phone_cb(gpointer data, char *entry)
+{
+	msn_set_phone_number(data, "PHW", entry);
+}
+
+static void
+msn_set_mobile_phone_cb(gpointer data, char *entry)
+{
+	msn_set_phone_number(data, "PHM", entry);
+}
+
+static void
 msn_show_set_friendly_name(struct gaim_connection *gc)
 {
 	do_prompt_dialog(_("Set Friendly Name:"), gc->displayname,
 					 gc, msn_act_id, NULL);
 }
 
+static void
+msn_show_set_home_phone(struct gaim_connection *gc)
+{
+	MsnSession *session = gc->proto_data;
+
+	do_prompt_dialog(_("Set Home Phone Number:"),
+					 msn_user_get_home_phone(session->user),
+					 gc, msn_set_home_phone_cb, NULL);
+}
+
+static void
+msn_show_set_work_phone(struct gaim_connection *gc)
+{
+	MsnSession *session = gc->proto_data;
+
+	do_prompt_dialog(_("Set Work Phone Number:"),
+					 msn_user_get_work_phone(session->user),
+					 gc, msn_set_work_phone_cb, NULL);
+}
+
+static void
+msn_show_set_mobile_phone(struct gaim_connection *gc)
+{
+	MsnSession *session = gc->proto_data;
+
+	do_prompt_dialog(_("Set Mobile Phone Number:"),
+					 msn_user_get_mobile_phone(session->user),
+					 gc, msn_set_mobile_phone_cb, NULL);
+}
 
 /**************************************************************************
  * Protocol Plugin ops
@@ -120,12 +187,15 @@
 static char *
 msn_tooltip_text(struct buddy *b)
 {
+	char *text = NULL;
+	/* MsnUser *user = b->proto_data; */
+
 	if (GAIM_BUDDY_IS_ONLINE(b)) {
-		return g_strdup_printf(_("<b>Status:</b> %s"),
+		text = g_strdup_printf(_("<b>Status:</b> %s"),
 							   msn_away_get_text(MSN_AWAY_TYPE(b->uc)));
 	}
 
-	return NULL;
+	return text;
 }
 
 static GList *
@@ -156,6 +226,24 @@
 	pam->gc = gc;
 	m = g_list_append(m, pam);
 
+	pam = g_new0(struct proto_actions_menu, 1);
+	pam->label = _("Set Home Phone Number");
+	pam->callback = msn_show_set_home_phone;
+	pam->gc = gc;
+	m = g_list_append(m, pam);
+
+	pam = g_new0(struct proto_actions_menu, 1);
+	pam->label = _("Set Work Phone Number");
+	pam->callback = msn_show_set_work_phone;
+	pam->gc = gc;
+	m = g_list_append(m, pam);
+
+	pam = g_new0(struct proto_actions_menu, 1);
+	pam->label = _("Set Mobile Phone Number");
+	pam->callback = msn_show_set_mobile_phone;
+	pam->gc = gc;
+	m = g_list_append(m, pam);
+
 	return m;
 }
 
@@ -844,8 +932,10 @@
 static void
 msn_buddy_free(struct buddy *b)
 {
-	if (b->proto_data != NULL)
-		g_free(b->proto_data);
+	if (b->proto_data != NULL) {
+		msn_user_destroy(b->proto_data);
+		b->proto_data = NULL;
+	}
 }
 
 static void
--- a/src/protocols/msn/notification.c	Tue May 13 04:37:37 2003 +0000
+++ b/src/protocols/msn/notification.c	Tue May 13 08:03:27 2003 +0000
@@ -431,25 +431,37 @@
 __bpr_cmd(MsnServConn *servconn, const char *command, const char **params,
 		  size_t param_count)
 {
-	struct gaim_connection *gc = servconn->session->account->gc;
+	MsnSession *session = servconn->session;
+	struct gaim_connection *gc = session->account->gc;
 	struct buddy *b;
 	const char *passport, *type, *value;
 	int status = 0;
+	MsnUser *user;
 
 	passport = params[1];
 	type     = params[2];
 	value    = params[3];
 
-	if (!strcmp(type, "MOB")) {
-		if (value != NULL && !strcmp(value, "Y")) {
-			gaim_debug(GAIM_DEBUG_MISC, "msn",
-					   "%s has a pager\n", passport);
-			if ((b = gaim_find_buddy(gc->account, passport)) != NULL) {
-				status = b->uc | (1 << 5);
+	user = msn_users_find_with_passport(session->users, passport);
 
-				serv_got_update(gc, (char *)passport, 1, 0, 0, 0, status);
+	if (value != NULL) {
+		if (!strcmp(type, "MOB")) {
+			if (!strcmp(value, "Y")) {
+				gaim_debug(GAIM_DEBUG_MISC, "msn",
+						   "%s has a pager\n", passport);
+				if ((b = gaim_find_buddy(gc->account, passport)) != NULL) {
+					status = b->uc | (1 << 5);
+
+					serv_got_update(gc, (char *)passport, 1, 0, 0, 0, status);
+				}
 			}
 		}
+		else if (!strcmp(type, "PHH"))
+			msn_user_set_home_phone(user, msn_url_decode(value));
+		else if (!strcmp(type, "PHW"))
+			msn_user_set_work_phone(user, msn_url_decode(value));
+		else if (!strcmp(type, "PHM"))
+			msn_user_set_mobile_phone(user, msn_url_decode(value));
 	}
 
 	return TRUE;
@@ -696,13 +708,13 @@
 				b = gaim_buddy_new(gc->account,
 								   msn_user_get_passport(user), NULL);
 
+				b->proto_data = user;
+
 				gaim_blist_add_buddy(b, g, NULL);
 			}
 
 			serv_got_alias(gc, (char *)msn_user_get_passport(user),
 						   (char *)msn_user_get_name(user));
-
-			msn_user_destroy(user);
 		}
 	}
 
@@ -745,6 +757,28 @@
 }
 
 static gboolean
+__prp_cmd(MsnServConn *servconn, const char *command, const char **params,
+		  size_t param_count)
+{
+	MsnSession *session = servconn->session;
+	const char *type, *value;
+
+	type  = params[2];
+	value = params[3];
+
+	if (param_count == 4) {
+		if (!strcmp(type, "PHH"))
+			msn_user_set_home_phone(session->user, msn_url_decode(value));
+		else if (!strcmp(type, "PHW"))
+			msn_user_set_work_phone(session->user, msn_url_decode(value));
+		else if (!strcmp(type, "PHM"))
+			msn_user_set_mobile_phone(session->user, msn_url_decode(value));
+	}
+
+	return TRUE;
+}
+
+static gboolean
 __rea_cmd(MsnServConn *servconn, const char *command, const char **params,
 		  size_t param_count)
 {
@@ -1196,6 +1230,8 @@
 		return FALSE;
 	}
 
+	session->user = msn_user_new(session, gc->username, NULL);
+
 	set_login_progress(session->account->gc, 4, _("Syncing with server"));
 
 	return TRUE;
@@ -1241,7 +1277,7 @@
 		msn_servconn_register_command(notification, "MSG",       __msg_cmd);
 		msn_servconn_register_command(notification, "NLN",       __nln_cmd);
 		msn_servconn_register_command(notification, "OUT",       __out_cmd);
-		msn_servconn_register_command(notification, "PRP",       __blank_cmd);
+		msn_servconn_register_command(notification, "PRP",       __prp_cmd);
 		msn_servconn_register_command(notification, "QNG",       __blank_cmd);
 		msn_servconn_register_command(notification, "QRY",       __blank_cmd);
 		msn_servconn_register_command(notification, "REA",       __rea_cmd);
--- a/src/protocols/msn/session.h	Tue May 13 04:37:37 2003 +0000
+++ b/src/protocols/msn/session.h	Tue May 13 08:03:27 2003 +0000
@@ -31,6 +31,7 @@
 struct _MsnSession
 {
 	struct gaim_account *account;
+	MsnUser *user;
 
 	char *dispatch_server;
 	int dispatch_port;
--- a/src/protocols/msn/user.c	Tue May 13 04:37:37 2003 +0000
+++ b/src/protocols/msn/user.c	Tue May 13 08:03:27 2003 +0000
@@ -72,11 +72,12 @@
 	if (user->clientinfo != NULL)
 		g_hash_table_destroy(user->clientinfo);
 
-	if (user->passport != NULL)
-		g_free(user->passport);
+	if (user->passport != NULL) g_free(user->passport);
+	if (user->name     != NULL) g_free(user->name);
 
-	if (user->name != NULL)
-		g_free(user->name);
+	if (user->phone.home   != NULL) g_free(user->phone.home);
+	if (user->phone.work   != NULL) g_free(user->phone.work);
+	if (user->phone.mobile != NULL) g_free(user->phone.mobile);
 
 	g_free(user);
 }
@@ -140,6 +141,40 @@
 	user->group_id = id;
 }
 
+void
+msn_user_set_home_phone(MsnUser *user, const char *number)
+{
+	g_return_if_fail(user != NULL);
+
+	if (user->phone.home != NULL)
+		g_free(user->phone.home);
+
+	user->phone.home = (number == NULL ? NULL : g_strdup(number));
+}
+
+void
+msn_user_set_work_phone(MsnUser *user, const char *number)
+{
+	g_return_if_fail(user != NULL);
+
+	if (user->phone.work != NULL)
+		g_free(user->phone.work);
+
+	user->phone.work = (number == NULL ? NULL : g_strdup(number));
+}
+
+void
+msn_user_set_mobile_phone(MsnUser *user, const char *number)
+{
+	g_return_if_fail(user != NULL);
+
+	if (user->phone.mobile != NULL)
+		g_free(user->phone.mobile);
+
+	user->phone.mobile = (number == NULL ? NULL : g_strdup(number));
+}
+
+
 const char *
 msn_user_get_passport(const MsnUser *user)
 {
@@ -164,6 +199,30 @@
 	return user->group_id;
 }
 
+const char *
+msn_user_get_home_phone(const MsnUser *user)
+{
+	g_return_val_if_fail(user != NULL, NULL);
+
+	return user->phone.home;
+}
+
+const char *
+msn_user_get_work_phone(const MsnUser *user)
+{
+	g_return_val_if_fail(user != NULL, NULL);
+
+	return user->phone.work;
+}
+
+const char *
+msn_user_get_mobile_phone(const MsnUser *user)
+{
+	g_return_val_if_fail(user != NULL, NULL);
+
+	return user->phone.mobile;
+}
+
 void
 msn_user_set_client_info(MsnUser *user, GHashTable *info)
 {
--- a/src/protocols/msn/user.h	Tue May 13 04:37:37 2003 +0000
+++ b/src/protocols/msn/user.h	Tue May 13 08:03:27 2003 +0000
@@ -37,6 +37,14 @@
 	char *passport;         /**< The passport account.   */
 	char *name;             /**< The friendly name.      */
 
+	struct
+	{
+		char *home;         /**< Home phone number.      */
+		char *work;         /**< Work phone number.      */
+		char *mobile;       /**< Mobile phone number.    */
+
+	} phone;
+
 	int group_id;           /**< The group ID.           */
 
 	size_t ref_count;       /**< The reference count.    */
@@ -116,6 +124,30 @@
 void msn_user_set_group_id(MsnUser *user, int id);
 
 /**
+ * Sets the home phone number for a user.
+ *
+ * @param user   The user.
+ * @param number The home phone number.
+ */
+void msn_user_set_home_phone(MsnUser *user, const char *number);
+
+/**
+ * Sets the work phone number for a user.
+ *
+ * @param user   The user.
+ * @param number The work phone number.
+ */
+void msn_user_set_work_phone(MsnUser *user, const char *number);
+
+/**
+ * Sets the mobile phone number for a user.
+ *
+ * @param user   The user.
+ * @param number The mobile phone number.
+ */
+void msn_user_set_mobile_phone(MsnUser *user, const char *number);
+
+/**
  * Returns the passport account for a user.
  *
  * @param user The user.
@@ -143,6 +175,33 @@
 int msn_user_get_group_id(const MsnUser *user);
 
 /**
+ * Returns the home phone number for a user.
+ *
+ * @param user The user.
+ *
+ * @return The user's home phone number.
+ */
+const char *msn_user_get_home_phone(const MsnUser *user);
+
+/**
+ * Returns the work phone number for a user.
+ *
+ * @param user The user.
+ *
+ * @return The user's work phone number.
+ */
+const char *msn_user_get_work_phone(const MsnUser *user);
+
+/**
+ * Returns the mobile phone number for a user.
+ *
+ * @param user The user.
+ *
+ * @return The user's mobile phone number.
+ */
+const char *msn_user_get_mobile_phone(const MsnUser *user);
+
+/**
  * Sets the client information for a user.
  *
  * @param user The user.