changeset 26145:685c8f5f85c7

Separate PidginMedia from PidginConversation.
author Mike Ruprecht <maiku@soc.pidgin.im>
date Fri, 30 Jan 2009 04:40:54 +0000
parents 2091094745d9
children 4f013819e4e3
files libpurple/media.c libpurple/protocols/jabber/jabber.c pidgin/gtkconv.c pidgin/gtkconv.h pidgin/gtkmain.c pidgin/gtkmedia.c pidgin/gtkmedia.h
diffstat 7 files changed, 73 insertions(+), 100 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/media.c	Fri Jan 30 01:23:35 2009 +0000
+++ b/libpurple/media.c	Fri Jan 30 04:40:54 2009 +0000
@@ -1271,10 +1271,12 @@
 purple_media_end(PurpleMedia *media,
 		const gchar *session_id, const gchar *participant)
 {
-	if (session_id == NULL && participant == NULL)
+	if (session_id == NULL && participant == NULL) {
 		g_signal_emit(media, purple_media_signals[STATE_CHANGED],
 				0, PURPLE_MEDIA_STATE_CHANGED_END,
 				NULL, NULL);
+		g_object_unref(media);
+	}
 }
 
 GList*
--- a/libpurple/protocols/jabber/jabber.c	Fri Jan 30 01:23:35 2009 +0000
+++ b/libpurple/protocols/jabber/jabber.c	Fri Jan 30 04:40:54 2009 +0000
@@ -2067,9 +2067,6 @@
 	if(!(jid = jabber_id_new(who)))
 		return;
 
-#ifdef USE_VV
-	jingle_rtp_terminate_session(js, who);
-#endif
 	if((jb = jabber_buddy_find(js, who, TRUE)) &&
 			(jbr = jabber_buddy_find_resource(jb, jid->resource))) {
 		if(jbr->thread_id) {
--- a/pidgin/gtkconv.c	Fri Jan 30 01:23:35 2009 +0000
+++ b/pidgin/gtkconv.c	Fri Jan 30 04:40:54 2009 +0000
@@ -48,7 +48,6 @@
 #include "idle.h"
 #include "imgstore.h"
 #include "log.h"
-#include "mediamanager.h"
 #include "notify.h"
 #include "prpl.h"
 #include "request.h"
@@ -63,7 +62,6 @@
 #include "gtkimhtml.h"
 #include "gtkimhtmltoolbar.h"
 #include "gtklog.h"
-#include "gtkmedia.h"
 #include "gtkmenutray.h"
 #include "gtkpounce.h"
 #include "gtkprefs.h"
@@ -4818,10 +4816,7 @@
 	int buddyicon_size = 0;
 
 	/* Setup the top part of the pane */
-	gtkconv->tophbox = gtk_hbox_new(FALSE, PIDGIN_HIG_BOX_SPACE);
-	gtk_widget_show(gtkconv->tophbox);
 	vbox = gtk_vbox_new(FALSE, PIDGIN_HIG_BOX_SPACE);
-	gtk_box_pack_start(GTK_BOX(gtkconv->tophbox), vbox, TRUE, TRUE, 0);
 	gtk_widget_show(vbox);
 
 	/* Setup the info pane */
@@ -4970,7 +4965,7 @@
 	default_formatize(gtkconv);
 	g_signal_connect_after(G_OBJECT(gtkconv->entry), "format_function_clear",
 	                       G_CALLBACK(clear_formatting_cb), gtkconv);
-	return gtkconv->tophbox;
+	return vbox;
 }
 
 static void
@@ -6450,8 +6445,7 @@
 		/* check if account support voice calls, and if the current buddy
 			supports it */
 		if (account != NULL && purple_conversation_get_type(conv)
-					== PURPLE_CONV_TYPE_IM
-					&& gtkconv->gtkmedia == NULL) {
+					== PURPLE_CONV_TYPE_IM) {
 			gboolean audio = purple_prpl_can_do_media(account,
 					purple_conversation_get_name(conv),
 					PURPLE_MEDIA_AUDIO);
@@ -7753,64 +7747,6 @@
 	return TRUE;
 }
 
-
-#ifdef USE_VV
-
-static void
-pidgin_gtkmedia_message_cb(PidginMedia *media, const char *msg, PurpleConversation *conv)
-{
-	purple_conv_im_write(PURPLE_CONV_IM(conv), NULL, msg, PURPLE_MESSAGE_SYSTEM, time(NULL));
-}
-
-static void
-pidgin_gtkmedia_error_cb(PidginMedia *media, const char *msg, PurpleConversation *conv)
-{
-	purple_conv_im_write(PURPLE_CONV_IM(conv), NULL, msg, PURPLE_MESSAGE_ERROR, time(NULL));
-}
-
-static void
-pidgin_conv_gtkmedia_destroyed(GtkWidget *widget, PidginConversation *gtkconv)
-{
-	gtk_widget_destroyed(widget, &(gtkconv->gtkmedia));
-	pidgin_conv_update_buttons_by_protocol(gtkconv->active_conv);
-}
-
-static gboolean
-pidgin_conv_new_media_cb(PurpleMediaManager *manager, PurpleMedia *media,
-		PurpleConnection *gc, gchar *screenname, gpointer nul)
-{
-	GtkWidget *gtkmedia;
-	PurpleConversation *conv;
-	PidginConversation *gtkconv;
-
-	conv = purple_conversation_new(PURPLE_CONV_TYPE_IM,
-			purple_connection_get_account(gc), screenname);
-
-	gtkconv = PIDGIN_CONVERSATION(conv);
-
-	if (gtkconv->gtkmedia) {
-		purple_debug_info("gtkconv", "Media session exists for this conversation.\n");
-		return FALSE;
-	}
-
-	gtkmedia = pidgin_media_new(media, screenname);
-	g_object_unref(media);
-
-	gtk_box_pack_start(GTK_BOX(gtkconv->tophbox), gtkmedia, FALSE, FALSE, 0);
-	gtk_widget_show(gtkmedia);
-	g_signal_connect(G_OBJECT(gtkmedia), "message", G_CALLBACK(pidgin_gtkmedia_message_cb), conv);
-	g_signal_connect(G_OBJECT(gtkmedia), "error", G_CALLBACK(pidgin_gtkmedia_error_cb), conv);
-
-	gtkconv->gtkmedia = gtkmedia;
-	g_signal_connect(G_OBJECT(gtkmedia), "destroy", G_CALLBACK(
-			pidgin_conv_gtkmedia_destroyed), gtkconv);
-
-	pidgin_conv_update_buttons_by_protocol(conv);
-	return TRUE;
-}
-
-#endif
-
 void *
 pidgin_conversations_get_handle(void)
 {
@@ -7911,10 +7847,6 @@
 								show_protocol_icons_pref_cb, NULL);
 	purple_prefs_connect_callback(handle, PIDGIN_PREFS_ROOT "/conversations/im/hide_new",
                                 hide_new_pref_cb, NULL);
-#ifdef USE_VV
-	g_signal_connect(G_OBJECT(purple_media_manager_get()), "init-media",
-			 G_CALLBACK(pidgin_conv_new_media_cb), NULL);
-#endif
 
 
 	/**********************************************************************
--- a/pidgin/gtkconv.h	Fri Jan 30 01:23:35 2009 +0000
+++ b/pidgin/gtkconv.h	Fri Jan 30 04:40:54 2009 +0000
@@ -169,8 +169,6 @@
 	GtkWidget *infopane;
 	GtkListStore *infopane_model;
 	GtkTreeIter infopane_iter;
-	GtkWidget *tophbox;
-	GtkWidget *gtkmedia;
 
 	/* Used when attaching a PidginConversation to a PurpleConversation
 	 * with message history */
--- a/pidgin/gtkmain.c	Fri Jan 30 01:23:35 2009 +0000
+++ b/pidgin/gtkmain.c	Fri Jan 30 04:40:54 2009 +0000
@@ -53,6 +53,7 @@
 #include "gtkft.h"
 #include "gtkidle.h"
 #include "gtklog.h"
+#include "gtkmedia.h"
 #include "gtknotify.h"
 #include "gtkplugin.h"
 #include "gtkpounce.h"
@@ -310,6 +311,7 @@
 	pidgin_log_init();
 	pidgin_docklet_init();
 	pidgin_smileys_init();
+	pidgin_medias_init();
 }
 
 static GHashTable *ui_info = NULL;
--- a/pidgin/gtkmedia.c	Fri Jan 30 01:23:35 2009 +0000
+++ b/pidgin/gtkmedia.c	Fri Jan 30 04:40:54 2009 +0000
@@ -28,6 +28,7 @@
 #include "internal.h"
 #include "connection.h"
 #include "media.h"
+#include "mediamanager.h"
 #include "pidgin.h"
 
 #include "gtkmedia.h"
@@ -71,6 +72,7 @@
 	GtkWidget *recv_widget;
 	GtkWidget *local_video;
 	GtkWidget *remote_video;
+	PurpleConnection *pc;
 };
 
 #define PIDGIN_MEDIA_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), PIDGIN_TYPE_MEDIA, PidginMediaPrivate))
@@ -83,16 +85,15 @@
 static void pidgin_media_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
 static void pidgin_media_set_state(PidginMedia *gtkmedia, PidginMediaState state);
 
-static GtkHBoxClass *parent_class = NULL;
-
+static GtkWindowClass *parent_class = NULL;
 
 
+#if 0
 enum {
-	MESSAGE,
-	ERROR,
 	LAST_SIGNAL
 };
 static guint pidgin_media_signals[LAST_SIGNAL] = {0};
+#endif
 
 enum {
 	PROP_0,
@@ -120,7 +121,7 @@
 			(GInstanceInitFunc) pidgin_media_init,
 			NULL
 		};
-		type = g_type_register_static(GTK_TYPE_VBOX, "PidginMedia", &info, 0);
+		type = g_type_register_static(GTK_TYPE_WINDOW, "PidginMedia", &info, 0);
 	}
 	return type;
 }
@@ -163,15 +164,6 @@
 			GST_TYPE_ELEMENT,
 			G_PARAM_READWRITE));
 
-	pidgin_media_signals[MESSAGE] = g_signal_new("message", G_TYPE_FROM_CLASS(klass),
-					G_SIGNAL_RUN_LAST, 0, NULL, NULL,
-					g_cclosure_marshal_VOID__STRING,
-					G_TYPE_NONE, 1, G_TYPE_STRING);
-	pidgin_media_signals[ERROR] = g_signal_new("error", G_TYPE_FROM_CLASS(klass),
-					G_SIGNAL_RUN_LAST, 0, NULL, NULL,
-					g_cclosure_marshal_VOID__STRING,
-					G_TYPE_NONE, 1, G_TYPE_STRING);
-
 	g_type_class_add_private(klass, sizeof(PidginMediaPrivate));
 }
 
@@ -182,10 +174,24 @@
 			gtk_toggle_button_get_active(toggle));
 }
 
+static gboolean
+pidgin_media_delete_event_cb(GtkWidget *widget,
+		GdkEvent *event, PidginMedia *media)
+{
+	if (media->priv->media)
+		purple_media_hangup(media->priv->media);
+	return FALSE;
+}
+
 static void
 pidgin_media_init (PidginMedia *media)
 {
+	GtkWidget *vbox;
 	media->priv = PIDGIN_MEDIA_GET_PRIVATE(media);
+
+	vbox = gtk_vbox_new(FALSE, PIDGIN_HIG_BOX_SPACE);
+	gtk_container_add(GTK_CONTAINER(media), vbox);
+
 	media->priv->calling = gtk_label_new("Calling...");
 	media->priv->hangup = gtk_button_new_with_mnemonic("_Hangup");
 	media->priv->accept = gtk_button_new_with_mnemonic("_Accept");
@@ -195,18 +201,24 @@
 	g_signal_connect(media->priv->mute, "toggled",
 			G_CALLBACK(pidgin_media_mute_toggled), media);
 
-	gtk_box_pack_end(GTK_BOX(media), media->priv->reject, FALSE, FALSE, 0);
-	gtk_box_pack_end(GTK_BOX(media), media->priv->accept, FALSE, FALSE, 0);
-	gtk_box_pack_end(GTK_BOX(media), media->priv->hangup, FALSE, FALSE, 0);
-	gtk_box_pack_end(GTK_BOX(media), media->priv->mute, FALSE, FALSE, 0);
-	gtk_box_pack_end(GTK_BOX(media), media->priv->calling, FALSE, FALSE, 0);
+	gtk_box_pack_end(GTK_BOX(vbox), media->priv->reject, FALSE, FALSE, 0);
+	gtk_box_pack_end(GTK_BOX(vbox), media->priv->accept, FALSE, FALSE, 0);
+	gtk_box_pack_end(GTK_BOX(vbox), media->priv->hangup, FALSE, FALSE, 0);
+	gtk_box_pack_end(GTK_BOX(vbox), media->priv->mute, FALSE, FALSE, 0);
+	gtk_box_pack_end(GTK_BOX(vbox), media->priv->calling, FALSE, FALSE, 0);
 
 	gtk_widget_show_all(media->priv->accept);
 	gtk_widget_show_all(media->priv->reject);
 
 	media->priv->display = gtk_vbox_new(TRUE, PIDGIN_HIG_BOX_SPACE);
-	gtk_box_pack_start(GTK_BOX(media), media->priv->display,
+	gtk_box_pack_start(GTK_BOX(vbox), media->priv->display,
 			TRUE, TRUE, PIDGIN_HIG_BOX_SPACE);
+	gtk_widget_show(vbox);
+
+	g_signal_connect(G_OBJECT(media), "delete-event",
+			G_CALLBACK(pidgin_media_delete_event_cb), media);
+
+	gtk_widget_show(GTK_WIDGET(media));
 }
 
 static gboolean
@@ -315,7 +327,12 @@
 static void
 pidgin_media_emit_message(PidginMedia *gtkmedia, const char *msg)
 {
-	g_signal_emit(gtkmedia, pidgin_media_signals[MESSAGE], 0, msg);
+	PurpleConversation *conv = purple_find_conversation_with_account(
+			PURPLE_CONV_TYPE_ANY, gtkmedia->priv->screenname,
+			purple_connection_get_account(gtkmedia->priv->pc));
+	if (conv != NULL)
+		purple_conversation_write(conv, NULL, msg,
+				PURPLE_MESSAGE_SYSTEM, time(NULL));
 }
 
 typedef struct
@@ -354,7 +371,12 @@
 static void
 pidgin_media_error_cb(PidginMedia *media, const char *error, PidginMedia *gtkmedia)
 {
-	g_signal_emit(gtkmedia, pidgin_media_signals[ERROR], 0, error);
+	PurpleConversation *conv = purple_find_conversation_with_account(
+			PURPLE_CONV_TYPE_ANY, gtkmedia->priv->screenname,
+			purple_connection_get_account(gtkmedia->priv->pc));
+	if (conv != NULL)
+		purple_conversation_write(conv, NULL, error,
+				PURPLE_MESSAGE_ERROR, time(NULL));
 }
 
 static void
@@ -723,4 +745,22 @@
 	}
 }
 
+static gboolean
+pidgin_media_new_cb(PurpleMediaManager *manager, PurpleMedia *media,
+		PurpleConnection *pc, gchar *screenname, gpointer nul)
+{
+	PidginMedia *gtkmedia = PIDGIN_MEDIA(
+			pidgin_media_new(media, screenname));
+	gtkmedia->priv->pc = pc;
+
+	return TRUE;
+}
+
+void
+pidgin_medias_init(void)
+{
+	g_signal_connect(G_OBJECT(purple_media_manager_get()), "init-media",
+			 G_CALLBACK(pidgin_media_new_cb), NULL);
+}
+
 #endif  /* USE_VV */
--- a/pidgin/gtkmedia.h	Fri Jan 30 01:23:35 2009 +0000
+++ b/pidgin/gtkmedia.h	Fri Jan 30 04:40:54 2009 +0000
@@ -48,17 +48,19 @@
 
 struct _PidginMediaClass
 {
-	GtkHBoxClass parent_class;
+	GtkWindowClass parent_class;
 };
 
 struct _PidginMedia
 {
-	GtkHBox parent;
+	GtkWindow parent;
 	PidginMediaPrivate *priv;
 };
 
 GType pidgin_media_get_type(void);
 
+void pidgin_medias_init(void);
+
 GtkWidget *pidgin_media_new(PurpleMedia *media, const gchar *screenname);
 
 G_END_DECLS