changeset 25687:ddbea813862e

Notify the user which type of media session the remote user wants to initiate.
author Mike Ruprecht <maiku@soc.pidgin.im>
date Thu, 12 Jun 2008 03:59:26 +0000
parents 3bf9748fdef0
children 9c6915254610
files libpurple/media.c libpurple/media.h libpurple/protocols/jabber/jingle.c pidgin/gtkmedia.c
diffstat 4 files changed, 56 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/media.c	Tue Jun 10 05:18:29 2008 +0000
+++ b/libpurple/media.c	Thu Jun 12 03:59:26 2008 +0000
@@ -83,6 +83,7 @@
 	ACCEPTED,
 	HANGUP,
 	REJECT,
+	GOT_REQUEST,
 	GOT_HANGUP,
 	GOT_ACCEPT,
 	NEW_CANDIDATE,
@@ -172,6 +173,10 @@
 					 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
 					 g_cclosure_marshal_VOID__VOID,
 					 G_TYPE_NONE, 0);
+	purple_media_signals[GOT_REQUEST] = g_signal_new("got-request", G_TYPE_FROM_CLASS(klass),
+					 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
+					 g_cclosure_marshal_VOID__VOID,
+					 G_TYPE_NONE, 0);
 	purple_media_signals[GOT_HANGUP] = g_signal_new("got-hangup", G_TYPE_FROM_CLASS(klass),
 					 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
 					 g_cclosure_marshal_VOID__VOID,
@@ -321,6 +326,21 @@
 	return result;
 }
 
+PurpleMediaStreamType
+purple_media_get_overall_type(PurpleMedia *media)
+{
+	GList *values = g_hash_table_get_values(media->priv->sessions);
+	PurpleMediaStreamType type = PURPLE_MEDIA_NONE;
+
+	for (; values; values = values->next) {
+		PurpleMediaSession *session = values->data;
+		type |= session->type;
+	}
+
+	g_list_free(values);
+	return type;
+}
+
 static PurpleMediaSession*
 purple_media_get_session(PurpleMedia *media, const gchar *sess_id)
 {
@@ -528,6 +548,12 @@
 }
 
 void
+purple_media_got_request(PurpleMedia *media)
+{
+	g_signal_emit(media, purple_media_signals[GOT_REQUEST], 0);
+}
+
+void
 purple_media_got_hangup(PurpleMedia *media)
 {
 	g_signal_emit(media, purple_media_signals[GOT_HANGUP], 0);
--- a/libpurple/media.h	Tue Jun 10 05:18:29 2008 +0000
+++ b/libpurple/media.h	Thu Jun 12 03:59:26 2008 +0000
@@ -77,6 +77,8 @@
 FsStreamDirection purple_media_to_fs_stream_direction(PurpleMediaStreamType type);
 PurpleMediaStreamType purple_media_from_fs(FsMediaType type, FsStreamDirection direction);
 
+PurpleMediaStreamType purple_media_get_overall_type(PurpleMedia *media);
+
 GList *purple_media_get_session_names(PurpleMedia *media);
 
 void purple_media_get_elements(PurpleMedia *media, GstElement **audio_src, GstElement **audio_sink,
@@ -97,6 +99,7 @@
 void purple_media_accept(PurpleMedia *media);
 void purple_media_reject(PurpleMedia *media);
 void purple_media_hangup(PurpleMedia *media);
+void purple_media_got_request(PurpleMedia *media);
 void purple_media_got_hangup(PurpleMedia *media);
 void purple_media_got_accept(PurpleMedia *media);
 
--- a/libpurple/protocols/jabber/jingle.c	Tue Jun 10 05:18:29 2008 +0000
+++ b/libpurple/protocols/jabber/jingle.c	Thu Jun 12 03:59:26 2008 +0000
@@ -1335,6 +1335,8 @@
 	}
 	jabber_iq_send(jabber_jingle_session_create_ack(js, packet));
 	jabber_iq_send(jabber_jingle_session_create_session_info(session, "ringing"));
+
+	purple_media_got_request(jabber_jingle_session_get_media(session));
 }
 
 void
--- a/pidgin/gtkmedia.c	Tue Jun 10 05:18:29 2008 +0000
+++ b/pidgin/gtkmedia.c	Thu Jun 12 03:59:26 2008 +0000
@@ -427,6 +427,29 @@
 }
 
 static void
+pidgin_media_got_request_cb(PurpleMedia *media, PidginMedia *gtkmedia)
+{
+	PurpleMediaStreamType type = purple_media_get_overall_type(media);
+	gchar *message;
+
+	if (type & PURPLE_MEDIA_AUDIO && type & PURPLE_MEDIA_VIDEO) {
+		message = g_strdup_printf(_("%s wishes to start an audio/video session with you."),
+					  purple_media_get_screenname(media));
+	} else if (type & PURPLE_MEDIA_AUDIO) {
+		message = g_strdup_printf(_("%s wishes to start an audio session with you."),
+					  purple_media_get_screenname(media));
+	} else if (type & PURPLE_MEDIA_VIDEO) {
+		message = g_strdup_printf(_("%s wishes to start a video session with you."),
+					  purple_media_get_screenname(media));
+	} else {
+		return;
+	}
+
+	pidgin_media_emit_message(gtkmedia, message);
+	g_free(message);
+}
+
+static void
 pidgin_media_got_hangup_cb(PurpleMedia *media, PidginMedia *gtkmedia)
 {
 	pidgin_media_emit_message(gtkmedia, _("The call has been terminated."));
@@ -470,6 +493,8 @@
 				G_CALLBACK(pidgin_media_hangup_cb), media);
 			g_signal_connect(G_OBJECT(media->priv->media), "reject",
 				G_CALLBACK(pidgin_media_reject_cb), media);
+			g_signal_connect(G_OBJECT(media->priv->media), "got-request",
+				G_CALLBACK(pidgin_media_got_request_cb), media);
 			g_signal_connect(G_OBJECT(media->priv->media), "got-hangup",
 				G_CALLBACK(pidgin_media_got_hangup_cb), media);
 			g_signal_connect(G_OBJECT(media->priv->media), "got-accept",