changeset 23859:eb8c8a926589

Convert serv_* media functions to purple_prpl_* functions.
author Mike Ruprecht <maiku@soc.pidgin.im>
date Sat, 19 Jul 2008 03:10:00 +0000
parents 23a156abcb2a
children a1acca6ff789
files finch/gntmedia.c libpurple/media.h libpurple/prpl.c libpurple/prpl.h libpurple/server.c libpurple/server.h pidgin/gtkconv.c
diffstat 7 files changed, 117 insertions(+), 99 deletions(-) [+]
line wrap: on
line diff
--- a/finch/gntmedia.c	Thu Jul 17 23:09:58 2008 +0000
+++ b/finch/gntmedia.c	Sat Jul 19 03:10:00 2008 +0000
@@ -433,10 +433,10 @@
 call_cmd_cb(PurpleConversation *conv, const char *cmd, char **args,
 		char **eror, gpointer data)
 {
-	PurpleConnection *gc = purple_conversation_get_gc(conv);
+	PurpleAccount *account = purple_conversation_get_account(conv);
 
 	PurpleMedia *media =
-		serv_initiate_media(gc,
+		purple_prpl_initiate_media(account,
 							purple_conversation_get_name(conv),
 							PURPLE_MEDIA_RECV_AUDIO & PURPLE_MEDIA_SEND_AUDIO);
 
--- a/libpurple/media.h	Thu Jul 17 23:09:58 2008 +0000
+++ b/libpurple/media.h	Sat Jul 19 03:10:00 2008 +0000
@@ -50,6 +50,12 @@
 typedef struct _PurpleMediaPrivate PurpleMediaPrivate;
 typedef struct _PurpleMediaSession PurpleMediaSession;
 
+#else
+
+typedef void PurpleMedia;
+
+#endif /* USE_VV */
+
 typedef enum {
 	PURPLE_MEDIA_NONE	= 0,
 	PURPLE_MEDIA_RECV_AUDIO = 1 << 0,
@@ -60,6 +66,8 @@
 	PURPLE_MEDIA_VIDEO = PURPLE_MEDIA_RECV_VIDEO | PURPLE_MEDIA_SEND_VIDEO
 } PurpleMediaStreamType;
 
+#ifdef USE_VV
+
 struct _PurpleMediaClass
 {
 	GObjectClass parent_class;
--- a/libpurple/prpl.c	Thu Jul 17 23:09:58 2008 +0000
+++ b/libpurple/prpl.c	Sat Jul 19 03:10:00 2008 +0000
@@ -411,3 +411,61 @@
 
 	return NULL;
 }
+
+
+
+PurpleMedia *
+purple_prpl_initiate_media(PurpleAccount *account,
+			   const char *who,
+			   PurpleMediaStreamType type)
+{
+#ifdef USE_VV
+	PurpleConnection *gc = NULL;
+	PurplePlugin *prpl = NULL;
+	PurplePluginProtocolInfo *prpl_info = NULL;
+
+	if (account)
+		gc = purple_account_get_connection(account);
+	if (gc)
+		prpl = purple_connection_get_prpl(gc);
+	if (prpl)
+		prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
+
+	if (prpl_info && prpl_info->initiate_media) {
+		/* should check that the protocol supports this media type here? */
+		return prpl_info->initiate_media(gc, who, type);
+	} else {
+		return NULL;
+	}
+#else
+	return NULL;
+#endif
+}
+
+gboolean
+purple_prpl_can_do_media(PurpleAccount *account,
+			 const char *who, 
+			 PurpleMediaStreamType type)
+{
+#ifdef USE_VV
+	PurpleConnection *gc = NULL;
+	PurplePlugin *prpl = NULL;
+	PurplePluginProtocolInfo *prpl_info = NULL;
+	
+	if (account)
+		gc = purple_account_get_connection(account);
+	if (gc)
+		prpl = purple_connection_get_prpl(gc);
+	if (prpl)
+		prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
+	
+	if (prpl_info && prpl_info->can_do_media) {
+		return prpl_info->can_do_media(gc, who, type);
+	} else {
+		return FALSE;
+	}
+#else
+	return FALSE;
+#endif
+}
+
--- a/libpurple/prpl.h	Thu Jul 17 23:09:58 2008 +0000
+++ b/libpurple/prpl.h	Sat Jul 19 03:10:00 2008 +0000
@@ -442,23 +442,10 @@
 	 */
 	GHashTable *(*get_account_text_table)(PurpleAccount *account);
 
-#ifdef USE_VV
 	/** Initiate media with the given buddy */
 	PurpleMedia  *(*initiate_media)(PurpleConnection *conn, const char *who, PurpleMediaStreamType type);
 
 	gboolean (*can_do_media)(PurpleConnection *conn, const char *who, PurpleMediaStreamType type);
-    
-    /*
-	gboolean (*can_receive_video)(PurpleConnection *conn, const char *who);
-	gboolean (*can_send_video)(PurpleConnection *conn, const char *who);
-	gboolean (*can_receive_audio)(PurpleConnection *conn, const char *who);
-	gboolean (*can_send_audio)(PurpleConnection *conn, const char *who);
-	*/
-    
-#else
-	void (*initiate_media)(void);
-	void (*can_do_media)(void);
-#endif
 };
 
 #define PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(prpl, member) \
@@ -712,6 +699,32 @@
  */
 GList *purple_prpl_get_statuses(PurpleAccount *account, PurplePresence *presence);
 
+/**
+ * Determines if the contact supports the given media session type.
+ *
+ * @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.
+ */
+gboolean purple_prpl_can_do_media(PurpleAccount *account,
+				  const char *who, 
+				  PurpleMediaStreamType type);
+
+/**
+ * Initiates a media session with the given contact.
+ *
+ * @param account The account the user is on.
+ * @param who The name of the contact to start a session with.
+ * @param type The type of media session to start.
+ *
+ * @return The newly created session object.
+ */
+PurpleMedia *purple_prpl_initiate_media(PurpleAccount *account,
+					const char *who,
+					PurpleMediaStreamType type);
+
 /*@}*/
 
 /**************************************************************************/
--- a/libpurple/server.c	Thu Jul 17 23:09:58 2008 +0000
+++ b/libpurple/server.c	Sat Jul 19 03:10:00 2008 +0000
@@ -1057,57 +1057,3 @@
 	}
 }
 
-#ifdef USE_VV
-PurpleMedia *serv_initiate_media(PurpleConnection *gc, const char *who,
-								 PurpleMediaStreamType type)
-{
-	PurplePlugin *prpl = NULL;
-	PurplePluginProtocolInfo *prpl_info = NULL;
-
-	if (gc)
-		prpl = purple_connection_get_prpl(gc);
-	if (prpl)
-		prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
-
-	if (prpl_info && prpl_info->initiate_media) {
-		/* should check that the protol supports this media type here.... */
-		return prpl_info->initiate_media(gc, who, type);
-	} else {
-		return NULL;
-	}
-}
-
-gboolean
-serv_can_do_media(PurpleConnection *gc, const char *who, 
-                  PurpleMediaStreamType type)
-{
-    PurplePlugin *prpl = NULL;
-	PurplePluginProtocolInfo *prpl_info = NULL;
-	
-	if (gc)
-		prpl = purple_connection_get_prpl(gc);
-	if (prpl)
-		prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
-	
-	if (prpl_info && prpl_info->can_do_media) {
-		/* should check that the protol supports this media type here.... */
-		return prpl_info->can_do_media(gc, who, type);
-	} else {
-		return FALSE;
-	}
-}
-#else
-void *
-serv_initiate_media(void *gc, void *who, void *type)
-{
-	purple_debug_info("serv", "Blank serv_initiate_media called\n");
-	return NULL;
-}
-
-void *
-serv_can_do_media(void *gc, void *who, void *type)
-{
-	purple_debug_info("serv", "Blank serv_can_do_media called\n");
-	return NULL;
-}
-#endif /* USE_VV */
--- a/libpurple/server.h	Thu Jul 17 23:09:58 2008 +0000
+++ b/libpurple/server.h	Sat Jul 19 03:10:00 2008 +0000
@@ -183,17 +183,6 @@
 					  PurpleMessageFlags flags, const char *message, time_t mtime);
 void serv_send_file(PurpleConnection *gc, const char *who, const char *file);
 
-#ifdef USE_VV
-PurpleMedia *serv_initiate_media(PurpleConnection *gc, const char *who,
-						  PurpleMediaStreamType type);
-gboolean serv_can_do_media(PurpleConnection *gc, const char *who, 
-                           PurpleMediaStreamType type);
-#else
-/* hmm, is this really nice? */
-void *serv_initiate_media(void*, void*, void*);
-void *serv_can_do_media(void *, void *, void *);
-#endif
-	
 #ifdef __cplusplus
 }
 #endif
--- a/pidgin/gtkconv.c	Thu Jul 17 23:09:58 2008 +0000
+++ b/pidgin/gtkconv.c	Sat Jul 19 03:10:00 2008 +0000
@@ -6380,13 +6380,17 @@
 #ifdef USE_VV
 		/* check if account support voice calls, and if the current buddy
 			supports it */
-		if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM) {
-			gboolean audio = serv_can_do_media(gc, purple_conversation_get_name(conv), 
-							   PURPLE_MEDIA_AUDIO);
-			gboolean video = serv_can_do_media(gc, purple_conversation_get_name(conv), 
-							   PURPLE_MEDIA_VIDEO);
-			gboolean av = serv_can_do_media(gc, purple_conversation_get_name(conv),
-							PURPLE_MEDIA_AUDIO | PURPLE_MEDIA_VIDEO);
+		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);
@@ -7684,12 +7688,12 @@
 {
 	PidginWindow *win = (PidginWindow *)data;
 	PurpleConversation *conv = pidgin_conv_window_get_active_conversation(win);
-	PurpleConnection *gc = purple_conversation_get_gc(conv);
+	PurpleAccount *account = purple_conversation_get_account(conv);
 
 	PurpleMedia *media =
-		serv_initiate_media(gc,
-				    purple_conversation_get_name(conv),
-				    PURPLE_MEDIA_AUDIO);
+		purple_prpl_initiate_media(account,
+					   purple_conversation_get_name(conv),
+					   PURPLE_MEDIA_AUDIO);
 
 	if (media)
 		purple_media_wait(media);
@@ -7700,12 +7704,12 @@
 {
 	PidginWindow *win = (PidginWindow *)data;
 	PurpleConversation *conv = pidgin_conv_window_get_active_conversation(win);
-	PurpleConnection *gc = purple_conversation_get_gc(conv);
+	PurpleAccount *account = purple_conversation_get_account(conv);
 
 	PurpleMedia *media =
-		serv_initiate_media(gc,
-				    purple_conversation_get_name(conv),
-				    PURPLE_MEDIA_VIDEO);
+		purple_prpl_initiate_media(account,
+					   purple_conversation_get_name(conv),
+					   PURPLE_MEDIA_VIDEO);
 
 	if (media)
 		purple_media_wait(media);
@@ -7716,12 +7720,12 @@
 {
 	PidginWindow *win = (PidginWindow *)data;
 	PurpleConversation *conv = pidgin_conv_window_get_active_conversation(win);
-	PurpleConnection *gc = purple_conversation_get_gc(conv);
+	PurpleAccount *account = purple_conversation_get_account(conv);
 
 	PurpleMedia *media =
-		serv_initiate_media(gc,
-				    purple_conversation_get_name(conv),
-				    PURPLE_MEDIA_AUDIO | PURPLE_MEDIA_VIDEO);
+		purple_prpl_initiate_media(account,
+					   purple_conversation_get_name(conv),
+					   PURPLE_MEDIA_AUDIO | PURPLE_MEDIA_VIDEO);
 
 	if (media)
 		purple_media_wait(media);