changeset 19464:ca45543c11a3

Change Yahoo prpl to use attention API in libpurple. Previous behavior can be reverted by not defining YAHOO_USE_ATTENTION_API.
author Jeffrey Connelly <jaconnel@calpoly.edu>
date Mon, 27 Aug 2007 06:08:14 +0000
parents 3f6f84d11ce2
children d9d9283680a4
files libpurple/protocols/yahoo/yahoo.c libpurple/protocols/yahoo/yahoo.h
diffstat 2 files changed, 68 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/yahoo/yahoo.c	Mon Aug 27 05:37:40 2007 +0000
+++ b/libpurple/protocols/yahoo/yahoo.c	Mon Aug 27 06:08:14 2007 +0000
@@ -899,6 +899,8 @@
 			PurpleConversation *c;
 			char *username, *str;
 
+			str = NULL;
+
 			account = purple_connection_get_account(gc);
 			c = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, im->from);
 
@@ -907,10 +909,13 @@
 			else
 				username = g_markup_escape_text(im->from, -1);
 
+#ifdef YAHOO_USE_ATTENTION_API
+			serv_got_attention(gc, username, YAHOO_BUZZ);
+#else
 			str = g_strdup_printf(_("%s just sent you a Buzz!"), username);
 
 			purple_conversation_write(c, NULL, str, PURPLE_MESSAGE_SYSTEM|PURPLE_MESSAGE_NOTIFY, im->time);
-
+#endif
 			g_free(username);
 			g_free(str);
 			g_free(m);
@@ -4012,17 +4017,24 @@
 
 static PurpleCmdRet
 yahoopurple_cmd_buzz(PurpleConversation *c, const gchar *cmd, gchar **args, gchar **error, void *data) {
-
 	PurpleAccount *account = purple_conversation_get_account(c);
+#ifndef YAHOO_USE_ATTENTION_API
 	const char *username = purple_account_get_username(account);
+#endif
 
 	if (*args && args[0])
 		return PURPLE_CMD_RET_FAILED;
 
+#ifdef YAHOO_USE_ATTENTION_API
+	serv_send_attention(account->gc, c->name, YAHOO_BUZZ);
+#else
+
 	purple_debug(PURPLE_DEBUG_INFO, "yahoo",
 	           "Sending <ding> on account %s to buddy %s.\n", username, c->name);
 	purple_conv_im_send(PURPLE_CONV_IM(c), "<ding>");
 	purple_conversation_write(c, NULL, _("You have just sent a Buzz!"), PURPLE_MESSAGE_SYSTEM, time(NULL));
+#endif
+
 	return PURPLE_CMD_RET_OK;
 }
 
@@ -4072,6 +4084,43 @@
 {
 	return TRUE;
 }
+	
+gboolean yahoo_send_attention(PurpleConnection *gc, const char *username, guint type)
+{
+	PurpleConversation *c;
+
+	c = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, 
+			username, gc->account);
+
+	g_return_val_if_fail(c != NULL, FALSE);
+
+	purple_debug(PURPLE_DEBUG_INFO, "yahoo",
+	           "Sending <ding> on account %s to buddy %s.\n", username, c->name);
+	/* TODO: find out how to send a <ding> without showing up as a blank line on
+	 * the conversation window. */
+	purple_conv_im_send(PURPLE_CONV_IM(c), "<ding>");
+
+	return TRUE;
+}
+
+GList *yahoo_attention_types(PurpleAccount *account)
+{
+	PurpleAttentionType *attn;
+	static GList *list;
+	static gboolean init = FALSE;
+
+	if (!init) {
+		/* Yahoo only supports one attention command: the 'buzz'. */
+		/* This is index number YAHOO_BUZZ. */
+		attn = g_new0(PurpleAttentionType, 1);
+		attn->name = "buzz";
+		attn->incoming_description = "buzzed";
+		attn->outgoing_description = "Buzzing";
+		list = g_list_append(NULL, attn);
+	} 
+
+	return list;
+}
 
 /************************** Plugin Initialization ****************************/
 static void
@@ -4281,9 +4330,15 @@
 	NULL, /* send_raw */
 	NULL, /* roomlist_room_serialize */
 
-	/* padding */
+#ifdef YAHOO_USE_ATTENTION_API
+	yahoo_send_attention,
+	yahoo_attention_types,
+#else
 	NULL,
 	NULL,
+#endif
+
+	/* padding */
 	NULL,
 	NULL
 };
--- a/libpurple/protocols/yahoo/yahoo.h	Mon Aug 27 05:37:40 2007 +0000
+++ b/libpurple/protocols/yahoo/yahoo.h	Mon Aug 27 06:08:14 2007 +0000
@@ -67,6 +67,13 @@
 #define YAHOO_STATUS_TYPE_INVISIBLE "invisible"
 #define YAHOO_STATUS_TYPE_MOBILE "mobile"
 
+#define YAHOO_USE_ATTENTION_API
+
+#ifdef YAHOO_USE_ATTENTION_API
+/* Index into attention types list. */
+#define YAHOO_BUZZ 0
+#endif
+
 enum yahoo_status {
 	YAHOO_STATUS_AVAILABLE = 0,
 	YAHOO_STATUS_BRB,
@@ -213,4 +220,7 @@
 gboolean yahoo_privacy_check
 	(PurpleConnection *gc, const char *who);
 
+gboolean yahoo_send_attention(PurpleConnection *gc, const char *username, guint type);
+GList *yahoo_attention_types(PurpleAccount *account);
+
 #endif /* _YAHOO_H_ */