Mercurial > pidgin
changeset 26108:d6e23439b77c
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.
author | Mike Ruprecht <maiku@soc.pidgin.im> |
---|---|
date | Wed, 11 Feb 2009 00:01:20 +0000 |
parents | 76104100cb87 |
children | fcfb7571515c |
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 |
diffstat | 8 files changed, 73 insertions(+), 71 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/media.h Sun Feb 08 23:17:51 2009 +0000 +++ b/libpurple/media.h Wed Feb 11 00:01:20 2009 +0000 @@ -65,6 +65,18 @@ #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,
--- a/libpurple/protocols/jabber/jabber.c Sun Feb 08 23:17:51 2009 +0000 +++ b/libpurple/protocols/jabber/jabber.c Wed Feb 11 00:01:20 2009 +0000 @@ -2591,11 +2591,11 @@ 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 @@ 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; } - - /* 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; + if (jabber_buddy_has_capability(jb, GTALK_CAP)) + caps |= PURPLE_MEDIA_CAPS_AUDIO; + + return caps; } #endif
--- a/libpurple/protocols/jabber/jabber.h Sun Feb 08 23:17:51 2009 +0000 +++ b/libpurple/protocols/jabber/jabber.h Wed Feb 11 00:01:20 2009 +0000 @@ -329,7 +329,7 @@ #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_ */
--- a/libpurple/protocols/jabber/libxmpp.c Sun Feb 08 23:17:51 2009 +0000 +++ b/libpurple/protocols/jabber/libxmpp.c Wed Feb 11 00:01:20 2009 +0000 @@ -120,7 +120,7 @@ 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 */
--- a/libpurple/prpl.c Sun Feb 08 23:17:51 2009 +0000 +++ b/libpurple/prpl.c Wed Feb 11 00:01:20 2009 +0000 @@ -524,10 +524,8 @@ #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 @@ 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; } /**************************************************************************
--- a/libpurple/prpl.h Sun Feb 08 23:17:51 2009 +0000 +++ b/libpurple/prpl.h Wed Feb 11 00:01:20 2009 +0000 @@ -466,11 +466,10 @@ * * @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 @@ * * @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.
--- a/pidgin/gtkblist.c Sun Feb 08 23:17:51 2009 +0000 +++ b/pidgin/gtkblist.c Wed Feb 11 00:01:20 2009 +0000 @@ -348,8 +348,9 @@ { /* 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 @@ 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);
--- a/pidgin/gtkconv.c Sun Feb 08 23:17:51 2009 +0000 +++ b/pidgin/gtkconv.c Wed Feb 11 00:01:20 2009 +0000 @@ -6446,19 +6446,19 @@ 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); - - 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); + PurpleMediaCaps caps = + purple_prpl_get_media_caps(account, + purple_conversation_get_name(conv)); + + 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);