pidgin.vv: 533a662a: Change purple_prpl_can_do_media to purpl...

maiku at soc.pidgin.im maiku at soc.pidgin.im
Thu Feb 19 06:35:36 EST 2009


-----------------------------------------------------------------
Revision: 533a662aae8a1598074ce8ffde9d2a5f68216f00
Ancestor: 32d2994216770da7c880f64143e2559b9e8c3e2a
Author: maiku at soc.pidgin.im
Date: 2009-02-11T00:01:20
Branch: im.pidgin.pidgin.vv
URL: http://d.pidgin.im/viewmtn/revision/info/533a662aae8a1598074ce8ffde9d2a5f68216f00

Modified files:
        libpurple/media.h libpurple/protocols/jabber/jabber.c
        libpurple/protocols/jabber/jabber.h
        libpurple/protocols/jabber/libxmpp.c libpurple/prpl.c
        libpurple/prpl.h pidgin/gtkblist.c pidgin/gtkconv.c

ChangeLog: 

Change purple_prpl_can_do_media to purple_prpl_get_media_caps.
This allows for it to only be called once. From the caps returned you 
can then tell which media capabilities a buddy has without having to 
call the function for each different type.

-------------- next part --------------
============================================================
--- libpurple/media.h	f35309f5550f135f95e0330c2c362a47c8fd1b9e
+++ libpurple/media.h	50a8ed2781ef0cc3a284c4566d262f895c3aa9d4
@@ -65,6 +65,18 @@ typedef void PurpleMedia;
 
 #endif /* USE_VV */
 
+/** Media caps */
+typedef enum {
+	PURPLE_MEDIA_CAPS_NONE = 0,
+	PURPLE_MEDIA_CAPS_AUDIO = 1,
+	PURPLE_MEDIA_CAPS_AUDIO_SINGLE_DIRECTION = 1 << 1,
+	PURPLE_MEDIA_CAPS_VIDEO = 1 << 2,
+	PURPLE_MEDIA_CAPS_VIDEO_SINGLE_DIRECTION = 1 << 3,
+	PURPLE_MEDIA_CAPS_AUDIO_VIDEO = 1 << 4,
+	PURPLE_MEDIA_CAPS_MODIFY_SESSION = 1 << 5,
+	PURPLE_MEDIA_CAPS_CHANGE_DIRECTION = 1 << 6,
+} PurpleMediaCaps;
+
 /** Media session types */
 typedef enum {
 	PURPLE_MEDIA_NONE	= 0,
============================================================
--- libpurple/protocols/jabber/jabber.c	ed98db16005f566485890d8da856da686e16a7c9
+++ libpurple/protocols/jabber/jabber.c	67a119291142be8e987e5ff2938d954e01232722
@@ -2591,11 +2591,11 @@ jabber_initiate_media(PurpleConnection *
 		return jingle_rtp_initiate_media(gc->proto_data, who, type);
 }
 
-gboolean jabber_can_do_media(PurpleConnection *gc, const char *who, 
-                             PurpleMediaSessionType type)
+PurpleMediaCaps jabber_get_media_caps(PurpleConnection *gc, const char *who)
 {
 	JabberStream *js = (JabberStream *) gc->proto_data;
 	JabberBuddy *jb;
+	PurpleMediaCaps caps = PURPLE_MEDIA_CAPS_NONE;
 
 	if (!js) {
 		purple_debug_error("jabber", "jabber_can_do_media: NULL stream\n");
@@ -2609,34 +2609,30 @@ gboolean jabber_can_do_media(PurpleConne
 		return FALSE;
 	}
 
-	if (!jabber_buddy_has_capability(jb, JINGLE_TRANSPORT_ICEUDP) &&
-			!jabber_buddy_has_capability(jb,
-			JINGLE_TRANSPORT_RAWUDP) &&
-			!jabber_buddy_has_capability(jb, GTALK_CAP)) {
-		purple_debug_info("jingle-rtp", "Buddy doesn't support "
-				"the same transport types\n");
-		return FALSE;
+	if (jabber_buddy_has_capability(jb, JINGLE_APP_RTP_SUPPORT_AUDIO))
+		caps |= PURPLE_MEDIA_CAPS_AUDIO |
+				PURPLE_MEDIA_CAPS_AUDIO_SINGLE_DIRECTION;
+	if (jabber_buddy_has_capability(jb, JINGLE_APP_RTP_SUPPORT_VIDEO))
+		caps |= PURPLE_MEDIA_CAPS_VIDEO |
+				PURPLE_MEDIA_CAPS_VIDEO_SINGLE_DIRECTION;
+	if (caps & PURPLE_MEDIA_CAPS_AUDIO && caps & PURPLE_MEDIA_CAPS_VIDEO)
+		caps |= PURPLE_MEDIA_CAPS_AUDIO_VIDEO;
+	if (caps != PURPLE_MEDIA_CAPS_NONE) {
+		if (!jabber_buddy_has_capability(jb,
+				JINGLE_TRANSPORT_ICEUDP) &&
+				!jabber_buddy_has_capability(jb,
+				JINGLE_TRANSPORT_RAWUDP)) {
+			purple_debug_info("jingle-rtp", "Buddy doesn't "
+					"support the same transport types\n");
+			caps = PURPLE_MEDIA_CAPS_NONE;
+		} else
+			caps |= PURPLE_MEDIA_CAPS_MODIFY_SESSION |
+					PURPLE_MEDIA_CAPS_CHANGE_DIRECTION;
 	}
+	if (jabber_buddy_has_capability(jb, GTALK_CAP))
+		caps |= PURPLE_MEDIA_CAPS_AUDIO;
 
-	/* XMPP will only support two-way media, AFAIK... */
-	if (type == (PURPLE_MEDIA_AUDIO | PURPLE_MEDIA_VIDEO)) {
-		purple_debug_info("jabber", 
-				  "Checking audio/video XEP support for %s\n", who);
-		return (jabber_buddy_has_capability(jb, JINGLE_APP_RTP_SUPPORT_AUDIO) ||
-				jabber_buddy_has_capability(jb, GTALK_CAP)) && 
-				jabber_buddy_has_capability(jb, JINGLE_APP_RTP_SUPPORT_VIDEO);
-	} else if (type == (PURPLE_MEDIA_AUDIO)) {
-		purple_debug_info("jabber", 
-				  "Checking audio XEP support for %s\n", who);
-		return jabber_buddy_has_capability(jb, JINGLE_APP_RTP_SUPPORT_AUDIO) ||
-				jabber_buddy_has_capability(jb, GTALK_CAP);
-	} else if (type == (PURPLE_MEDIA_VIDEO)) {
-		purple_debug_info("jabber", 
-				  "Checking video XEP support for %s\n", who);
-		return jabber_buddy_has_capability(jb, JINGLE_APP_RTP_SUPPORT_VIDEO);
-	}
-
-	return FALSE;
+	return caps;
 }
 
 #endif
============================================================
--- libpurple/protocols/jabber/jabber.h	b96ed9de1f0340bd808ab346ecff327fa6f4f914
+++ libpurple/protocols/jabber/jabber.h	50604d2d13d01d61dc70ceea6ff3c86e5a8093bc
@@ -329,7 +329,7 @@ PurpleMedia *jabber_initiate_media(Purpl
 
 #ifdef USE_VV
 PurpleMedia *jabber_initiate_media(PurpleConnection *gc, const char *who, PurpleMediaSessionType type);
-gboolean jabber_can_do_media(PurpleConnection *gc, const char *who, PurpleMediaSessionType type);
+PurpleMediaCaps jabber_get_media_caps(PurpleConnection *gc, const char *who);
 #endif
 
 #endif /* _PURPLE_JABBER_H_ */
============================================================
--- libpurple/protocols/jabber/libxmpp.c	0a73a0ad157357f72d7bcfaca810c928b4b75161
+++ libpurple/protocols/jabber/libxmpp.c	cead570f2d65f01c1bf938f8b5b438034c76b4cd
@@ -120,7 +120,7 @@ static PurplePluginProtocolInfo prpl_inf
 	NULL, /* get_account_text_table */
 #ifdef USE_VV
 	jabber_initiate_media,          /* initiate_media */
-	jabber_can_do_media             /* can_do_media */
+	jabber_get_media_caps,                  /* get_media_caps */
 #else
 	NULL,					/* initiate_media */
 	NULL					/* can_do_media */
============================================================
--- libpurple/prpl.c	44e7efe43b88ad62066609cfa40e0f131fc80a0c
+++ libpurple/prpl.c	3f609c950408eae405b48c9ad66ee26e9b8230f1
@@ -524,10 +524,8 @@ purple_prpl_initiate_media(PurpleAccount
 #endif
 }
 
-gboolean
-purple_prpl_can_do_media(PurpleAccount *account,
-			 const char *who, 
-			 PurpleMediaSessionType type)
+PurpleMediaCaps
+purple_prpl_get_media_caps(PurpleAccount *account, const char *who)
 {
 #ifdef USE_VV
 	PurpleConnection *gc = NULL;
@@ -541,14 +539,12 @@ purple_prpl_can_do_media(PurpleAccount *
 	if (prpl)
 		prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
 	
-	if (prpl_info && PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(prpl_info, can_do_media)) {
-		return prpl_info->can_do_media(gc, who, type);
-	} else {
-		return FALSE;
+	if (prpl_info && PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(prpl_info,
+			get_media_caps)) {
+		return prpl_info->get_media_caps(gc, who);
 	}
-#else
-	return FALSE;
 #endif
+	return PURPLE_MEDIA_CAPS_NONE;
 }
 
 /**************************************************************************
============================================================
--- libpurple/prpl.h	49efccdd12f0a3ab9662f24601327c844a6bd0ed
+++ libpurple/prpl.h	f2d0943c0ca2bd3e6301e3414ec3b47f1bd0cc1d
@@ -466,11 +466,10 @@ struct _PurplePluginProtocolInfo
 	 *
 	 * @param conn The connection the contact is on.
 	 * @param who The remote user to check for media capability with.
-	 * @param type The type of media session to check for.
-	 * @return @c TRUE The contact supports the given media type, or @c FALSE otherwise.
+	 * @return The media caps the contact supports.
 	 */
-	gboolean (*can_do_media)(PurpleConnection *gc, const char *who,
-				 PurpleMediaSessionType type);
+	PurpleMediaCaps (*get_media_caps)(PurpleConnection *gc,
+					  const char *who);
 };
 
 #define PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(prpl, member) \
@@ -765,13 +764,11 @@ void purple_prpl_got_attention_in_chat(P
  *
  * @param account The account the user is on.
  * @param who The name of the contact to check capabilities for.
- * @param type The type of media session to check for.
  *
- * @return @c TRUE if the contact supports the session type, else @c FALSE.
+ * @return The media caps the contact supports.
  */
-gboolean purple_prpl_can_do_media(PurpleAccount *account,
-				  const char *who, 
-				  PurpleMediaSessionType type);
+PurpleMediaCaps purple_prpl_get_media_caps(PurpleAccount *account,
+				  const char *who);
 
 /**
  * Initiates a media session with the given contact.
============================================================
--- pidgin/gtkblist.c	ce2c75051ae6bc58f81d30e354c00150edbe7fb8
+++ pidgin/gtkblist.c	614409e378d0e682a5177a3e3ed5f3c98271f9f4
@@ -348,8 +348,9 @@ static void gtk_blist_menu_video_call_cb
 {
 	/* if the buddy supports both audio and video, start a combined call,
 	 otherwise start a pure video session */
-	if (purple_prpl_can_do_media(purple_buddy_get_account(b),
-		purple_buddy_get_name(b), PURPLE_MEDIA_AUDIO)) {
+	if (purple_prpl_get_media_caps(purple_buddy_get_account(b),
+			purple_buddy_get_name(b)) &
+			PURPLE_MEDIA_CAPS_AUDIO_VIDEO) {
 		purple_prpl_initiate_media(purple_buddy_get_account(b),
 			purple_buddy_get_name(b), PURPLE_MEDIA_AUDIO | PURPLE_MEDIA_VIDEO);
 	} else {
@@ -1463,20 +1464,20 @@ pidgin_blist_make_buddy_menu(GtkWidget *
 			G_CALLBACK(gtk_blist_menu_im_cb), buddy, 0, 0, NULL);
 	
 #ifdef USE_VV
-	if (prpl_info && prpl_info->can_do_media) {
-		PurpleConnection *gc = 
-			purple_account_get_connection(purple_buddy_get_account(buddy));
+	if (prpl_info && prpl_info->get_media_caps) {
+		PurpleAccount *account = purple_buddy_get_account(buddy);
 		const gchar *who = purple_buddy_get_name(buddy);
-		if (prpl_info->can_do_media(gc, who, PURPLE_MEDIA_AUDIO)) {
+		PurpleMediaCaps caps = purple_prpl_get_media_caps(account, who);
+		if (caps & PURPLE_MEDIA_CAPS_AUDIO) {
 			pidgin_new_item_from_stock(menu, _("_Audio Call"),
 				PIDGIN_STOCK_TOOLBAR_AUDIO_CALL,
 				G_CALLBACK(gtk_blist_menu_audio_call_cb), buddy, 0, 0, NULL);
 		}
-		if (prpl_info->can_do_media(gc, who, PURPLE_MEDIA_VIDEO | PURPLE_MEDIA_AUDIO)) {
+		if (caps & PURPLE_MEDIA_CAPS_AUDIO_VIDEO) {
 			pidgin_new_item_from_stock(menu, _("Audio/_Video Call"),
 				PIDGIN_STOCK_TOOLBAR_VIDEO_CALL,
 				G_CALLBACK(gtk_blist_menu_video_call_cb), buddy, 0, 0, NULL);
-		} else if (prpl_info->can_do_media(gc, who, PURPLE_MEDIA_VIDEO)) {
+		} else if (caps & PURPLE_MEDIA_CAPS_VIDEO) {
 			pidgin_new_item_from_stock(menu, _("_Video Call"),
 				PIDGIN_STOCK_TOOLBAR_VIDEO_CALL,
 				G_CALLBACK(gtk_blist_menu_video_call_cb), buddy, 0, 0, NULL);
============================================================
--- pidgin/gtkconv.c	d142505dd08c1b156efd693faff433a141e57b35
+++ pidgin/gtkconv.c	33b6f187a2f06b378960f4e59534fdafb6796112
@@ -6446,19 +6446,19 @@ gray_stuff_out(PidginConversation *gtkco
 			supports it */
 		if (account != NULL && purple_conversation_get_type(conv)
 					== PURPLE_CONV_TYPE_IM) {
-			gboolean audio = purple_prpl_can_do_media(account,
-					purple_conversation_get_name(conv),
-					PURPLE_MEDIA_AUDIO);
-			gboolean video = purple_prpl_can_do_media(account,
-					purple_conversation_get_name(conv),
-					PURPLE_MEDIA_VIDEO);
-			gboolean av = purple_prpl_can_do_media(account,
-					purple_conversation_get_name(conv),
-					PURPLE_MEDIA_AUDIO | PURPLE_MEDIA_VIDEO);
+			PurpleMediaCaps caps =
+					purple_prpl_get_media_caps(account,
+					purple_conversation_get_name(conv));
 
-			gtk_widget_set_sensitive(win->menu.audio_call, audio ? TRUE : FALSE);
-			gtk_widget_set_sensitive(win->menu.video_call, video ? TRUE : FALSE);
-			gtk_widget_set_sensitive(win->menu.audio_video_call, av ? TRUE : FALSE);
+			gtk_widget_set_sensitive(win->menu.audio_call,
+					caps & PURPLE_MEDIA_CAPS_AUDIO
+					? TRUE : FALSE);
+			gtk_widget_set_sensitive(win->menu.video_call,
+					caps & PURPLE_MEDIA_CAPS_VIDEO
+					? TRUE : FALSE);
+			gtk_widget_set_sensitive(win->menu.audio_video_call, 
+					caps & PURPLE_MEDIA_CAPS_AUDIO_VIDEO
+					? TRUE : FALSE);
 		} else if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_CHAT) {
 			/* for now, don't care about chats... */
 			gtk_widget_set_sensitive(win->menu.audio_call, FALSE);


More information about the Commits mailing list