changeset 17890:935005186312

Added the option to enable/disable buzz via a status setting. It's default off for the pidgin folks.
author Andreas Monitzer <pidgin@monitzer.com>
date Tue, 03 Jul 2007 13:37:25 +0000
parents 9686d549f084
children 9d02fefaa589
files libpurple/protocols/jabber/jabber.c libpurple/protocols/jabber/jabber.h libpurple/protocols/jabber/libxmpp.c libpurple/protocols/jabber/message.c libpurple/protocols/jabber/message.h libpurple/protocols/jabber/presence.c
diffstat 6 files changed, 29 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/jabber.c	Tue Jul 03 11:04:50 2007 +0000
+++ b/libpurple/protocols/jabber/jabber.c	Tue Jul 03 13:37:25 2007 +0000
@@ -1426,6 +1426,7 @@
 			"tune_year", _("Tune Year"), purple_value_new(PURPLE_TYPE_INT),
 			"tune_url", _("Tune URL"), purple_value_new(PURPLE_TYPE_STRING),
 			"nick", _("Nickname"), purple_value_new(PURPLE_TYPE_STRING),
+			"buzz", _("Allow Buzz"), purple_value_new(PURPLE_TYPE_BOOLEAN),
 			NULL);
 	types = g_list_append(types, type);
 
@@ -1448,6 +1449,7 @@
 			"tune_year", _("Tune Year"), purple_value_new(PURPLE_TYPE_INT),
 			"tune_url", _("Tune URL"), purple_value_new(PURPLE_TYPE_STRING),
 			"nick", _("Nickname"), purple_value_new(PURPLE_TYPE_STRING),
+			"buzz", _("Allow Buzz"), purple_value_new(PURPLE_TYPE_BOOLEAN),
 			NULL);
 	types = g_list_append(types, type);
 
@@ -1470,6 +1472,7 @@
 			"tune_year", _("Tune Year"), purple_value_new(PURPLE_TYPE_INT),
 			"tune_url", _("Tune URL"), purple_value_new(PURPLE_TYPE_STRING),
 			"nick", _("Nickname"), purple_value_new(PURPLE_TYPE_STRING),
+			"buzz", _("Allow Buzz"), purple_value_new(PURPLE_TYPE_BOOLEAN),
 			NULL);
 	types = g_list_append(types, type);
 
@@ -1492,6 +1495,7 @@
 			"tune_year", _("Tune Year"), purple_value_new(PURPLE_TYPE_INT),
 			"tune_url", _("Tune URL"), purple_value_new(PURPLE_TYPE_STRING),
 			"nick", _("Nickname"), purple_value_new(PURPLE_TYPE_STRING),
+			"buzz", _("Allow Buzz"), purple_value_new(PURPLE_TYPE_BOOLEAN),
 			NULL);
 	types = g_list_append(types, type);
 
@@ -1514,6 +1518,7 @@
 			"tune_year", _("Tune Year"), purple_value_new(PURPLE_TYPE_INT),
 			"tune_url", _("Tune URL"), purple_value_new(PURPLE_TYPE_STRING),
 			"nick", _("Nickname"), purple_value_new(PURPLE_TYPE_STRING),
+			"buzz", _("Allow Buzz"), purple_value_new(PURPLE_TYPE_BOOLEAN),
 			NULL);
 	types = g_list_append(types, type);
 
--- a/libpurple/protocols/jabber/jabber.h	Tue Jul 03 11:04:50 2007 +0000
+++ b/libpurple/protocols/jabber/jabber.h	Tue Jul 03 13:37:25 2007 +0000
@@ -158,6 +158,9 @@
 	/* does the local server support PEP? */
 	gboolean pep;
 	
+	/* Is Buzz enabled? */
+	gboolean allowBuzz;
+	
 	/* A list of JabberAdHocCommands supported by the server */
 	GList *commands;
 	
--- a/libpurple/protocols/jabber/libxmpp.c	Tue Jul 03 11:04:50 2007 +0000
+++ b/libpurple/protocols/jabber/libxmpp.c	Tue Jul 03 13:37:25 2007 +0000
@@ -239,7 +239,7 @@
 
 		jabber_add_feature("avatarmeta", AVATARNAMESPACEMETA, jabber_pep_namespace_only_when_pep_enabled_cb);
 		jabber_add_feature("avatardata", AVATARNAMESPACEDATA, jabber_pep_namespace_only_when_pep_enabled_cb);
-		jabber_add_feature("buzz", "http://pidgin.im/libpurple/xmpp/attention", NULL);
+		jabber_add_feature("buzz", "http://pidgin.im/libpurple/xmpp/attention", jabber_buzz_isenabled);
 		
 		jabber_pep_register_handler("avatar", AVATARNAMESPACEMETA, jabber_buddy_avatar_update_metadata);
 }
--- a/libpurple/protocols/jabber/message.c	Tue Jul 03 11:04:50 2007 +0000
+++ b/libpurple/protocols/jabber/message.c	Tue Jul 03 13:37:25 2007 +0000
@@ -288,6 +288,10 @@
 	if(jm->delayed)
 		return;
 	
+	/* Reject buzz when it's not enabled */
+	if(!jm->js->allowBuzz)
+		return;
+	
 	account = purple_connection_get_account(jm->js->gc);
 	
 	if ((buddy = purple_find_buddy(account, jm->from)) != NULL)
@@ -737,3 +741,8 @@
 	jabber_message_send(jm);
 	jabber_message_free(jm);
 }
+
+gboolean jabber_buzz_isenabled(JabberStream *js, const gchar *shortname, const gchar *namespace) {
+	return js->allowBuzz;
+}
+
--- a/libpurple/protocols/jabber/message.h	Tue Jul 03 11:04:50 2007 +0000
+++ b/libpurple/protocols/jabber/message.h	Tue Jul 03 13:37:25 2007 +0000
@@ -78,4 +78,6 @@
 unsigned int jabber_send_typing(PurpleConnection *gc, const char *who, PurpleTypingState state);
 void jabber_message_conv_closed(JabberStream *js, const char *who);
 
+gboolean jabber_buzz_isenabled(JabberStream *js, const gchar *shortname, const gchar *namespace);
+
 #endif /* _PURPLE_JABBER_MESSAGE_H_ */
--- a/libpurple/protocols/jabber/presence.c	Tue Jul 03 11:04:50 2007 +0000
+++ b/libpurple/protocols/jabber/presence.c	Tue Jul 03 13:37:25 2007 +0000
@@ -106,6 +106,7 @@
 	int priority;
 	const char *artist, *title, *source, *uri, *track;
 	int length;
+	gboolean allowBuzz;
 
 	if(!purple_status_is_active(status))
 		return;
@@ -122,11 +123,16 @@
 
 	purple_status_to_jabber(status, &state, &stripped, &priority);
 	
+	/* check for buzz support */
+	allowBuzz = purple_status_get_attr_boolean(status,"buzz");
+	/* changing the buzz state has to trigger a re-broadcasting of the presence for caps */
+	
 #define CHANGED(a,b) ((!a && b) || (a && a[0] == '\0' && b && b[0] != '\0') || \
 					  (a && !b) || (a && a[0] != '\0' && b && b[0] == '\0') || (a && b && strcmp(a,b)))
 	/* check if there are any differences to the <presence> and send them in that case */
-	if (js->old_state != state || CHANGED(js->old_msg, stripped) ||
+	if (allowBuzz != js->allowBuzz || js->old_state != state || CHANGED(js->old_msg, stripped) ||
 		js->old_priority != priority || CHANGED(js->old_avatarhash, js->avatar_hash)) {
+		js->allowBuzz = allowBuzz;
 		presence = jabber_presence_create_js(js, state, stripped, priority);
 
 		if(js->avatar_hash) {
@@ -153,7 +159,7 @@
 		js->old_priority = priority;
 		g_free(stripped);
 	}
-	
+					  	
 	/* next, check if there are any changes to the tune values */
 	artist = purple_status_get_attr_string(status, PURPLE_TUNE_ARTIST);
 	title = purple_status_get_attr_string(status, PURPLE_TUNE_TITLE);
@@ -194,7 +200,7 @@
 	}
 	
 #undef CHANGED(a,b)
-	
+		
 	jabber_presence_fake_to_self(js, status);
 }