changeset 29847:2a436e0ce977

Add purple_account_[gs]et_public_alias functions, per discussion in d@cpi
author Paul Aurich <paul@darkrain42.org>
date Thu, 29 Apr 2010 05:58:02 +0000
parents 75ea2a624b10
children 38d5dd9c9a07 5bac51b394e6 bb6e0a21823e
files ChangeLog.API libpurple/account.c libpurple/account.h libpurple/protocols/bonjour/bonjour.c libpurple/protocols/gg/gg.c libpurple/protocols/irc/irc.c libpurple/protocols/jabber/libxmpp.c libpurple/protocols/msn/msn.c libpurple/protocols/mxit/mxit.c libpurple/protocols/myspace/myspace.c libpurple/protocols/novell/novell.c libpurple/protocols/null/nullprpl.c libpurple/protocols/oscar/libaim.c libpurple/protocols/oscar/libicq.c libpurple/protocols/qq/qq.c libpurple/protocols/silc/silc.c libpurple/protocols/silc10/silc.c libpurple/protocols/simple/simple.c libpurple/protocols/yahoo/libyahoo.c libpurple/protocols/yahoo/libyahoojp.c libpurple/protocols/zephyr/zephyr.c libpurple/prpl.h
diffstat 22 files changed, 221 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog.API	Thu Apr 29 05:55:14 2010 +0000
+++ b/ChangeLog.API	Thu Apr 29 05:58:02 2010 +0000
@@ -8,7 +8,9 @@
 		   * account-signed-off
 		   * account-connection-error
 		* purple_account_get_name_for_display
+		* purple_account_get_public_alias
 		* purple_account_get_privacy_type
+		* purple_account_set_public_alias
 		* purple_account_set_privacy_type
 		* purple_buddy_get_media_caps
 		* purple_buddy_set_media_caps
--- a/libpurple/account.c	Thu Apr 29 05:55:14 2010 +0000
+++ b/libpurple/account.c	Thu Apr 29 05:58:02 2010 +0000
@@ -1782,6 +1782,92 @@
 	schedule_accounts_save();
 }
 
+struct public_alias_closure
+{
+	PurpleAccount *account;
+	gpointer failure_cb;
+};
+
+static gboolean
+set_public_alias_unsupported(gpointer data)
+{
+	struct public_alias_closure *closure = data;
+	PurpleSetPublicAliasFailureCallback failure_cb = closure->failure_cb;
+
+	failure_cb(closure->account,
+	           _("This protocol does not support setting a public alias."));
+	g_free(closure);
+
+	return FALSE;
+}
+
+void
+purple_account_set_public_alias(PurpleAccount *account,
+		const char *alias, PurpleSetPublicAliasSuccessCallback success_cb,
+		PurpleSetPublicAliasFailureCallback failure_cb)
+{
+	PurpleConnection *gc;
+	PurplePlugin *prpl = NULL;
+	PurplePluginProtocolInfo *prpl_info = NULL;
+
+	g_return_if_fail(account != NULL);
+	g_return_if_fail(purple_account_is_connected(account));
+
+	gc = purple_account_get_connection(account);
+	prpl = purple_connection_get_prpl(gc);
+	prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
+
+	if (PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(prpl_info, set_public_alias))
+		prpl_info->set_public_alias(gc, alias, success_cb, failure_cb);
+	else {
+		struct public_alias_closure *closure =
+				g_new0(struct public_alias_closure, 1);
+		closure->account = account;
+		closure->failure_cb = failure_cb;
+		purple_timeout_add(0, set_public_alias_unsupported, closure);
+	}
+}
+
+static gboolean
+get_public_alias_unsupported(gpointer data)
+{
+	struct public_alias_closure *closure = data;
+	PurpleGetPublicAliasFailureCallback failure_cb = closure->failure_cb;
+
+	failure_cb(closure->account,
+	           _("This protocol does not support fetching the public alias."));
+	g_free(closure);
+
+	return FALSE;
+}
+
+void
+purple_account_get_public_alias(PurpleAccount *account,
+		PurpleGetPublicAliasSuccessCallback success_cb,
+		PurpleGetPublicAliasFailureCallback failure_cb)
+{
+	PurpleConnection *gc;
+	PurplePlugin *prpl = NULL;
+	PurplePluginProtocolInfo *prpl_info = NULL;
+
+	g_return_if_fail(account != NULL);
+	g_return_if_fail(purple_account_is_connected(account));
+
+	gc = purple_account_get_connection(account);
+	prpl = purple_connection_get_prpl(gc);
+	prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
+
+	if (PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(prpl_info, get_public_alias))
+		prpl_info->get_public_alias(gc, success_cb, failure_cb);
+	else {
+		struct public_alias_closure *closure =
+				g_new0(struct public_alias_closure, 1);
+		closure->account = account;
+		closure->failure_cb = failure_cb;
+		purple_timeout_add(0, get_public_alias_unsupported, closure);
+	}
+}
+
 void
 purple_account_clear_settings(PurpleAccount *account)
 {
--- a/libpurple/account.h	Thu Apr 29 05:55:14 2010 +0000
+++ b/libpurple/account.h	Thu Apr 29 05:58:02 2010 +0000
@@ -39,6 +39,10 @@
 typedef void (*PurpleAccountRequestAuthorizationCb)(void *);
 typedef void (*PurpleAccountRegistrationCb)(PurpleAccount *account, gboolean succeeded, void *user_data);
 typedef void (*PurpleAccountUnregistrationCb)(PurpleAccount *account, gboolean succeeded, void *user_data);
+typedef void (*PurpleSetPublicAliasSuccessCallback)(PurpleAccount *account, const char *new_alias);
+typedef void (*PurpleSetPublicAliasFailureCallback)(PurpleAccount *account, const char *error);
+typedef void (*PurpleGetPublicAliasSuccessCallback)(PurpleAccount *account, const char *alias);
+typedef void (*PurpleGetPublicAliasFailureCallback)(PurpleAccount *account, const char *error);
 
 #include "connection.h"
 #include "log.h"
@@ -462,6 +466,42 @@
 	const char *status_id, gboolean active, GList *attrs);
 
 /**
+ * Set a server-side (public) alias for this account.  The account
+ * must already be connected.
+ *
+ * Currently, the public alias is not stored locally, although this
+ * may change in a later version.
+ *
+ * @param account    The account
+ * @param alias      The new public alias for this account or NULL
+ *                   to unset the alias/nickname (or return it to
+ *                   a protocol-specific "default", like the username)
+ * @param success_cb A callback which will be called if the alias
+ *                   is successfully set on the server (or NULL).
+ * @param failure_cb A callback which will be called if the alias
+ *                   is not successfully set on the server (or NULL).
+ *
+ * @since 2.7.0
+ */
+void purple_account_set_public_alias(PurpleAccount *account,
+	const char *alias, PurpleSetPublicAliasSuccessCallback success_cb,
+	PurpleSetPublicAliasFailureCallback failure_cb);
+
+/**
+ * Fetch the server-side (public) alias for this account.  The account
+ * must already be connected.
+ *
+ * @param account    The account
+ * @param success_cb A callback which will be called with the alias
+ * @param failure_cb A callback which will be called if the prpl is
+ *                   unable to retrieve the server-side alias.
+ * @since 2.7.0
+ */
+void purple_account_get_public_alias(PurpleAccount *account,
+	PurpleGetPublicAliasSuccessCallback success_cb,
+	PurpleGetPublicAliasFailureCallback failure_cb);
+
+/**
  * Clears all protocol-specific settings on an account.
  *
  * @param account The account.
--- a/libpurple/protocols/bonjour/bonjour.c	Thu Apr 29 05:55:14 2010 +0000
+++ b/libpurple/protocols/bonjour/bonjour.c	Thu Apr 29 05:58:02 2010 +0000
@@ -528,7 +528,9 @@
 	NULL,                                                    /* get_account_text_table */
 	NULL,                                                    /* initiate_media */
 	NULL,                                                    /* get_media_caps */
-	NULL                                                     /* get_moods */
+	NULL,                                                    /* get_moods */
+	NULL,                                                    /* set_public_alias */
+	NULL                                                     /* get_public_alias */
 };
 
 static PurplePluginInfo info =
--- a/libpurple/protocols/gg/gg.c	Thu Apr 29 05:55:14 2010 +0000
+++ b/libpurple/protocols/gg/gg.c	Thu Apr 29 05:58:02 2010 +0000
@@ -2506,7 +2506,9 @@
 	NULL,                           /* get_account_text_table */
 	NULL,                           /* initiate_media */
 	NULL,                            /* can_do_media */
-	NULL 				/* get_moods */
+	NULL,				/* get_moods */
+	NULL,				/* set_public_alias */
+	NULL				/* get_public_alias */
 };
 
 static PurplePluginInfo info = {
--- a/libpurple/protocols/irc/irc.c	Thu Apr 29 05:55:14 2010 +0000
+++ b/libpurple/protocols/irc/irc.c	Thu Apr 29 05:58:02 2010 +0000
@@ -945,7 +945,9 @@
 	NULL,                    /* get_account_text_table */
 	NULL,                    /* initiate_media */
 	NULL,					 /* get_media_caps */
-	NULL					 /* get_moods */
+	NULL,					 /* get_moods */
+	NULL,					 /* set_public_alias */
+	NULL					 /* get_public_alias */
 };
 
 static gboolean load_plugin (PurplePlugin *plugin) {
--- a/libpurple/protocols/jabber/libxmpp.c	Thu Apr 29 05:55:14 2010 +0000
+++ b/libpurple/protocols/jabber/libxmpp.c	Thu Apr 29 05:58:02 2010 +0000
@@ -127,7 +127,9 @@
 	NULL, /* get_account_text_table */
 	jabber_initiate_media,          /* initiate_media */
 	jabber_get_media_caps,                  /* get_media_caps */
-	jabber_get_moods  							/* get_moods */
+	jabber_get_moods,  							/* get_moods */
+	NULL, /* set_public_alias */
+	NULL  /* get_public_alias */
 };
 
 static gboolean load_plugin(PurplePlugin *plugin)
--- a/libpurple/protocols/msn/msn.c	Thu Apr 29 05:55:14 2010 +0000
+++ b/libpurple/protocols/msn/msn.c	Thu Apr 29 05:58:02 2010 +0000
@@ -2742,7 +2742,9 @@
 	msn_get_account_text_table,             /* get_account_text_table */
 	NULL,                                   /* initiate_media */
 	NULL,                                   /* get_media_caps */
-	NULL                                    /* get_moods */
+	NULL,                                   /* get_moods */
+	NULL,                                   /* set_public_alias */
+	NULL                                    /* get_public_alias */
 };
 
 static PurplePluginInfo info =
--- a/libpurple/protocols/mxit/mxit.c	Thu Apr 29 05:55:14 2010 +0000
+++ b/libpurple/protocols/mxit/mxit.c	Thu Apr 29 05:58:02 2010 +0000
@@ -635,7 +635,9 @@
 	mxit_get_text_table,	/* get_account_text_table */
 	NULL,					/* initiate_media */
 	NULL,					/* get_media_caps */
-	NULL					/* get_moods */
+	NULL,					/* get_moods */
+	NULL,					/* set_public_alias */
+	NULL					/* get_public_alias */
 };
 
 
--- a/libpurple/protocols/myspace/myspace.c	Thu Apr 29 05:55:14 2010 +0000
+++ b/libpurple/protocols/myspace/myspace.c	Thu Apr 29 05:58:02 2010 +0000
@@ -3094,7 +3094,9 @@
 	msim_get_account_text_table,              /* get_account_text_table */
 	NULL,                   /* initiate_media */
 	NULL,                   /* get_media_caps */
-	NULL                    /* get_moods */
+	NULL,                   /* get_moods */
+	NULL,                   /* set_public_alias */
+	NULL                    /* get_public_alias */
 };
 
 /**
--- a/libpurple/protocols/novell/novell.c	Thu Apr 29 05:55:14 2010 +0000
+++ b/libpurple/protocols/novell/novell.c	Thu Apr 29 05:58:02 2010 +0000
@@ -3530,7 +3530,9 @@
 	NULL,						/* get_account_text_table */
 	NULL,						/* initiate_media */
 	NULL,						/* get_media_caps */
-	NULL						/* get_moods */
+	NULL,						/* get_moods */
+	NULL,						/* set_public_alias */
+	NULL						/* get_public_alias */
 };
 
 static PurplePluginInfo info = {
--- a/libpurple/protocols/null/nullprpl.c	Thu Apr 29 05:55:14 2010 +0000
+++ b/libpurple/protocols/null/nullprpl.c	Thu Apr 29 05:58:02 2010 +0000
@@ -1120,6 +1120,8 @@
   NULL,                                /* get_account_text_table */
   NULL,                                /* initiate_media */
   NULL,                                /* get_media_caps */
+  NULL,                                /* set_public_alias */
+  NULL,                                /* get_public_alias */
   NULL                                 /* get_moods */
 };
 
--- a/libpurple/protocols/oscar/libaim.c	Thu Apr 29 05:55:14 2010 +0000
+++ b/libpurple/protocols/oscar/libaim.c	Thu Apr 29 05:58:02 2010 +0000
@@ -97,7 +97,9 @@
 	NULL,					/* get_account_text_table */
 	NULL,					/* initiate_media */
 	NULL,					/* get_media_caps */
-	NULL					/* get_moods */
+	NULL,					/* get_moods */
+	NULL,					/* set_public_alias */
+	NULL					/* get_public_alias */
 };
 
 static PurplePluginInfo info =
--- a/libpurple/protocols/oscar/libicq.c	Thu Apr 29 05:55:14 2010 +0000
+++ b/libpurple/protocols/oscar/libicq.c	Thu Apr 29 05:58:02 2010 +0000
@@ -109,6 +109,8 @@
 	NULL,					/* initiate_media */
 	NULL,					/* can_do_media */
 	oscar_get_purple_moods, /* get_moods */
+	NULL,					/* set_public_alias */
+	NULL					/* get_public_alias */
 };
 
 static PurplePluginInfo info =
--- a/libpurple/protocols/qq/qq.c	Thu Apr 29 05:55:14 2010 +0000
+++ b/libpurple/protocols/qq/qq.c	Thu Apr 29 05:58:02 2010 +0000
@@ -1041,7 +1041,9 @@
 	NULL,							/* get_account_text_table */
 	NULL,							/* initiate_media */
 	NULL,							/* get_media_caps */
-	NULL							/* get_moods */
+	NULL,							/* get_moods */
+	NULL,							/* set_public_alias */
+	NULL							/* get_public_alias */
 };
 
 static PurplePluginInfo info = {
--- a/libpurple/protocols/silc/silc.c	Thu Apr 29 05:55:14 2010 +0000
+++ b/libpurple/protocols/silc/silc.c	Thu Apr 29 05:58:02 2010 +0000
@@ -2117,7 +2117,9 @@
 	NULL,				        /* get_account_text_table */
 	NULL,				        /* initiate_media */
 	NULL,				        /* get_media_caps */
-	NULL				        /* get_moods */
+	NULL,				        /* get_moods */
+	NULL,				        /* set_public_alias */
+	NULL				        /* get_public_alias */
 };
 
 static PurplePluginInfo info =
--- a/libpurple/protocols/silc10/silc.c	Thu Apr 29 05:55:14 2010 +0000
+++ b/libpurple/protocols/silc10/silc.c	Thu Apr 29 05:58:02 2010 +0000
@@ -1842,7 +1842,10 @@
 	sizeof(PurplePluginProtocolInfo),       /* struct_size */
 	NULL,                       /* get_account_text_table */
 	NULL,                       /* initiate_media */
-	NULL                       /* can_do_media */
+	NULL,                       /* get_media_caps */
+	NULL,                       /* get_moods */
+	NULL,                       /* set_public_alias */
+	NULL                        /* get_public_alias */
 };
 
 static PurplePluginInfo info =
--- a/libpurple/protocols/simple/simple.c	Thu Apr 29 05:55:14 2010 +0000
+++ b/libpurple/protocols/simple/simple.c	Thu Apr 29 05:58:02 2010 +0000
@@ -2110,7 +2110,9 @@
 	NULL,					/* get_account_text_table */
 	NULL,					/* initiate_media */
 	NULL,					/* get_media_caps */
-	NULL					/* get_moods */
+	NULL,					/* get_moods */
+	NULL,					/* set_public_alias */
+	NULL					/* get_public_alias */
 };
 
 
--- a/libpurple/protocols/yahoo/libyahoo.c	Thu Apr 29 05:55:14 2010 +0000
+++ b/libpurple/protocols/yahoo/libyahoo.c	Thu Apr 29 05:58:02 2010 +0000
@@ -265,7 +265,9 @@
 	yahoo_get_account_text_table,    /* get_account_text_table */
 	NULL, /* initiate_media */
 	NULL,  /* get_media_caps */
-	NULL   /* get_moods */
+	NULL,  /* get_moods */
+	NULL,  /* set_public_alias */
+	NULL   /* get_public_alias */
 };
 
 static PurplePluginInfo info =
--- a/libpurple/protocols/yahoo/libyahoojp.c	Thu Apr 29 05:55:14 2010 +0000
+++ b/libpurple/protocols/yahoo/libyahoojp.c	Thu Apr 29 05:58:02 2010 +0000
@@ -161,7 +161,9 @@
 	yahoojp_get_account_text_table,    /* get_account_text_table */
 	NULL, /* initiate_media */
 	NULL, /* get_media_caps */
-	NULL  /* get_moods */
+	NULL, /* get_moods */
+	NULL, /* set_public_alias */
+	NULL  /* get_public_alias */
 };
 
 static PurplePluginInfo info =
--- a/libpurple/protocols/zephyr/zephyr.c	Thu Apr 29 05:55:14 2010 +0000
+++ b/libpurple/protocols/zephyr/zephyr.c	Thu Apr 29 05:58:02 2010 +0000
@@ -2909,7 +2909,9 @@
 	NULL,					/* get_account_text_table */
 	NULL,					/* initate_media */
 	NULL,					/* get_media_caps */
-	NULL					/* get_moods */
+	NULL,					/* get_moods */
+	NULL,					/* set_public_alias */
+	NULL					/* get_public_alias */
 };
 
 static PurplePluginInfo info = {
--- a/libpurple/prpl.h	Thu Apr 29 05:55:14 2010 +0000
+++ b/libpurple/prpl.h	Thu Apr 29 05:58:02 2010 +0000
@@ -580,8 +580,48 @@
 	/**
 	 * Returns an array of "PurpleMood"s, with the last one having
 	 * "mood" set to @c NULL.
+	 * @since 2.7.0
 	 */
 	PurpleMood *(*get_moods)(PurpleAccount *account);
+
+	/**
+	 * Set the user's "friendly name" (or alias or nickname or
+	 * whatever term you want to call it) on the server.  The
+	 * protocol plugin should call success_cb or failure_cb
+	 * *asynchronously* (if it knows immediately that the set will fail,
+	 * call one of the callbacks from an idle/0-second timeout) depending
+	 * on if the nickname is set successfully.
+	 *
+	 * @param gc    The connection for which to set an alias
+	 * @param alias The new server-side alias/nickname for this account,
+	 *              or NULL to unset the alias/nickname (or return it to
+	 *              a protocol-specific "default").
+	 * @param success_cb Callback to be called if the public alias is set
+	 * @param failure_cb Callback to be called if setting the public alias
+	 *                   fails
+	 * @see purple_account_set_public_alias
+	 * @since 2.7.0
+	 */
+	void (*set_public_alias)(PurpleConnection *gc, const char *alias,
+	                         PurpleSetPublicAliasSuccessCallback success_cb,
+	                         PurpleSetPublicAliasFailureCallback failure_cb);
+	/**
+	 * Retrieve the user's "friendly name" as set on the server.
+	 * The protocol plugin should call success_cb or failure_cb
+	 * *asynchronously* (even if it knows immediately that the set will fail,
+	 * call one of the callbacks from an idle/0-second timeout) depending
+	 * on if the nickname is retrieved.
+	 *
+	 * @param gc    The connection for which to retireve the alias
+	 * @param success_cb Callback to be called with the retrieved alias
+	 * @param failure_cb Callback to be called if the prpl is unable to
+	 *                   retrieve the alias
+	 * @see purple_account_get_public_alias
+	 * @since 2.7.0
+	 */
+	void (*get_public_alias)(PurpleConnection *gc,
+	                         PurpleSetPublicAliasSuccessCallback success_cb,
+	                         PurpleSetPublicAliasFailureCallback failure_cb);
 };
 
 #define PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(prpl, member) \