empathy r830 - trunk/libempathy



Author: xclaesse
Date: Wed Apr  2 10:41:19 2008
New Revision: 830
URL: http://svn.gnome.org/viewvc/empathy?rev=830&view=rev

Log:
Unify EmpathyTpChatroom and EmpathyTpChat.


Removed:
   trunk/libempathy/empathy-tp-chatroom.c
   trunk/libempathy/empathy-tp-chatroom.h
Modified:
   trunk/libempathy/Makefile.am
   trunk/libempathy/empathy-tp-chat.c
   trunk/libempathy/empathy-tp-chat.h

Modified: trunk/libempathy/Makefile.am
==============================================================================
--- trunk/libempathy/Makefile.am	(original)
+++ trunk/libempathy/Makefile.am	Wed Apr  2 10:41:19 2008
@@ -35,7 +35,6 @@
 	empathy-tp-group.c				\
 	empathy-tp-contact-list.c			\
 	empathy-tp-chat.c				\
-	empathy-tp-chatroom.c				\
 	empathy-tp-roomlist.c				\
 	empathy-tp-call.c				\
 	empathy-chandler.c				\
@@ -76,7 +75,6 @@
 	empathy-tp-group.h			\
 	empathy-tp-contact-list.h		\
 	empathy-tp-chat.h			\
-	empathy-tp-chatroom.h			\
 	empathy-tp-roomlist.h			\
 	empathy-tp-call.h			\
 	empathy-chandler.h			\

Modified: trunk/libempathy/empathy-tp-chat.c
==============================================================================
--- trunk/libempathy/empathy-tp-chat.c	(original)
+++ trunk/libempathy/empathy-tp-chat.c	Wed Apr  2 10:41:19 2008
@@ -29,6 +29,7 @@
 
 #include "empathy-tp-chat.h"
 #include "empathy-contact-factory.h"
+#include "empathy-contact-list.h"
 #include "empathy-marshal.h"
 #include "empathy-debug.h"
 #include "empathy-time.h"
@@ -42,6 +43,8 @@
 struct _EmpathyTpChatPriv {
 	EmpathyContactFactory *factory;
 	EmpathyContact        *user;
+	EmpathyContact        *initiator;
+	EmpathyTpGroup        *group;
 	McAccount             *account;
 	TpChannel             *channel;
 	gchar                 *id;
@@ -61,8 +64,9 @@
 	GValue         *value;
 } TpChatProperty;
 
-static void empathy_tp_chat_class_init (EmpathyTpChatClass *klass);
-static void empathy_tp_chat_init       (EmpathyTpChat      *chat);
+static void empathy_tp_chat_class_init (EmpathyTpChatClass      *klass);
+static void empathy_tp_chat_init       (EmpathyTpChat           *chat);
+static void tp_chat_iface_init         (EmpathyContactListIface *iface);
 
 enum {
 	PROP_0,
@@ -83,7 +87,9 @@
 
 static guint signals[LAST_SIGNAL];
 
-G_DEFINE_TYPE (EmpathyTpChat, empathy_tp_chat, G_TYPE_OBJECT);
+G_DEFINE_TYPE_WITH_CODE (EmpathyTpChat, empathy_tp_chat, G_TYPE_OBJECT,
+			 G_IMPLEMENT_INTERFACE (EMPATHY_TYPE_CONTACT_LIST,
+						tp_chat_iface_init));
 
 static void
 tp_chat_invalidated_cb (TpProxy       *proxy,
@@ -116,6 +122,92 @@
 	}
 }
 
+static void
+tp_chat_member_added_cb (EmpathyTpGroup *group,
+			 EmpathyContact *contact,
+			 EmpathyContact *actor,
+			 guint           reason,
+			 const gchar    *message,
+			 EmpathyTpChat  *chat)
+{
+	g_signal_emit_by_name (chat, "members-changed",
+			       contact, actor, reason, message,
+			       TRUE);
+}
+
+static void
+tp_chat_member_removed_cb (EmpathyTpGroup *group,
+			   EmpathyContact *contact,
+			   EmpathyContact *actor,
+			   guint           reason,
+			   const gchar    *message,
+			   EmpathyTpChat  *chat)
+{
+	g_signal_emit_by_name (chat, "members-changed",
+			       contact, actor, reason, message,
+			       FALSE);
+}
+static void
+tp_chat_local_pending_cb  (EmpathyTpGroup *group,
+			   EmpathyContact *contact,
+			   EmpathyContact *actor,
+			   guint           reason,
+			   const gchar    *message,
+			   EmpathyTpChat  *chat)
+{
+	g_signal_emit_by_name (chat, "pendings-changed",
+			       contact, actor, reason, message,
+			       TRUE);
+}
+
+static void
+tp_chat_add (EmpathyContactList *list,
+	     EmpathyContact     *contact,
+	     const gchar        *message)
+{
+	EmpathyTpChatPriv *priv = GET_PRIV (list);
+
+	g_return_if_fail (EMPATHY_IS_TP_CHAT (list));
+	g_return_if_fail (EMPATHY_IS_CONTACT (contact));
+
+	if (priv->group) {
+		empathy_tp_group_add_member (priv->group, contact, message);
+	}
+}
+
+static void
+tp_chat_remove (EmpathyContactList *list,
+		EmpathyContact     *contact,
+		const gchar        *message)
+{
+	EmpathyTpChatPriv *priv = GET_PRIV (list);
+
+	g_return_if_fail (EMPATHY_IS_TP_CHAT (list));
+	g_return_if_fail (EMPATHY_IS_CONTACT (contact));
+
+	if (priv->group) {
+		empathy_tp_group_remove_member (priv->group, contact, message);
+	}
+}
+
+static GList *
+tp_chat_get_members (EmpathyContactList *list)
+{
+	EmpathyTpChatPriv *priv = GET_PRIV (list);
+	GList             *members = NULL;
+
+	g_return_val_if_fail (EMPATHY_IS_TP_CHAT (list), NULL);
+
+	if (priv->group) {
+		members = empathy_tp_group_get_members (priv->group);
+	} else {
+		members = g_list_prepend (members, g_object_ref (priv->user));
+		members = g_list_prepend (members, g_object_ref (priv->initiator));
+	}
+
+	return members;
+}
+
 static EmpathyMessage *
 tp_chat_build_message (EmpathyTpChat *chat,
 		       guint          type,
@@ -697,15 +789,32 @@
 
 	g_object_get (priv->channel, "channel-ready", &channel_ready, NULL);
 	if (channel_ready) {
-		/* FIXME: We do that in a cb to let time to set the acknowledge
-		 * property, this property should be required for construct. */
-		g_idle_add ((GSourceFunc) tp_chat_channel_ready_cb, chat);
+		tp_chat_channel_ready_cb (EMPATHY_TP_CHAT (chat));
 	} else {
 		g_signal_connect_swapped (priv->channel, "notify::channel-ready",
 					  G_CALLBACK (tp_chat_channel_ready_cb),
 					  chat);
 	}
 
+	if (tp_proxy_has_interface_by_id (priv->channel,
+					  TP_IFACE_QUARK_CHANNEL_INTERFACE_GROUP)) {
+		priv->group = empathy_tp_group_new (priv->account, priv->tp_chan);
+
+		g_signal_connect (priv->group, "member-added",
+				  G_CALLBACK (tp_chat_member_added_cb),
+				  chat);
+		g_signal_connect (priv->group, "member-removed",
+				  G_CALLBACK (tp_chat_member_removed_cb),
+				  chat);
+		g_signal_connect (priv->group, "local-pending",
+				  G_CALLBACK (tp_chat_local_pending_cb),
+				  chat);
+	} else {
+		priv->initiator = empathy_contact_factory_get_from_handle (priv->factory,
+									   priv->account,
+									   priv->tp_chan->handle);
+	}
+
 	return chat;
 }
 
@@ -755,8 +864,7 @@
 		priv->channel = g_object_ref (g_value_get_object (value));
 		break;
 	case PROP_ACKNOWLEDGE:
-		empathy_tp_chat_set_acknowledge (EMPATHY_TP_CHAT (object),
-						 g_value_get_boolean (value));
+		priv->acknowledge = g_value_get_boolean (value);
 		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
@@ -808,7 +916,7 @@
 							       "Wheter or not received messages should be acknowledged",
 							       FALSE,
 							       G_PARAM_READWRITE |
-							       G_PARAM_CONSTRUCT));
+							       G_PARAM_CONSTRUCT_ONLY));
 
 	/* Signals */
 	signals[MESSAGE_RECEIVED] =
@@ -869,9 +977,18 @@
 {
 }
 
+static void
+tp_chat_iface_init (EmpathyContactListIface *iface)
+{
+	iface->add         = tp_chat_add;
+	iface->remove      = tp_chat_remove;
+	iface->get_members = tp_chat_get_members;
+}
+
 EmpathyTpChat *
 empathy_tp_chat_new (McAccount *account,
-		     TpChan    *tp_chan)
+		     TpChan    *tp_chan,
+		     gboolean   acknowledge)
 {
 	EmpathyTpChat  *chat;
 	TpChannel      *channel;
@@ -888,6 +1005,7 @@
 			     "account", account,
 			     "channel", channel,
 			     "tp-chan", tp_chan,
+			     "acknowledge", acknowledge,
 			     NULL);
 
 	g_object_unref (channel);
@@ -932,7 +1050,7 @@
 					 handle,
 					 TRUE);
 
-	chat = empathy_tp_chat_new (account, text_chan);
+	chat = empathy_tp_chat_new (account, text_chan, TRUE);
 
 	g_object_unref (tp_conn);
 	g_object_unref (text_chan);
@@ -941,32 +1059,6 @@
 	return chat;
 }
 
-gboolean
-empathy_tp_chat_get_acknowledge (EmpathyTpChat *chat)
-{
-	EmpathyTpChatPriv *priv;
-
-	g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), FALSE);
-
-	priv = GET_PRIV (chat);
-
-	return priv->acknowledge;
-}
-
-void
-empathy_tp_chat_set_acknowledge (EmpathyTpChat *chat,
-				 gboolean       acknowledge)
-{
-	EmpathyTpChatPriv *priv;
-
-	g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
-
-	priv = GET_PRIV (chat);
-
-	priv->acknowledge = acknowledge;
-	g_object_notify (G_OBJECT (chat), "acknowledge");
-}
-
 TpChan *
 empathy_tp_chat_get_channel (EmpathyTpChat *chat)
 {

Modified: trunk/libempathy/empathy-tp-chat.h
==============================================================================
--- trunk/libempathy/empathy-tp-chat.h	(original)
+++ trunk/libempathy/empathy-tp-chat.h	Wed Apr  2 10:41:19 2008
@@ -56,11 +56,9 @@
 
 GType          empathy_tp_chat_get_type             (void) G_GNUC_CONST;
 EmpathyTpChat *empathy_tp_chat_new                  (McAccount          *account,
-						     TpChan             *tp_chan);
-EmpathyTpChat *empathy_tp_chat_new_with_contact     (EmpathyContact     *contact);
-gboolean       empathy_tp_chat_get_acknowledge      (EmpathyTpChat      *chat);
-void           empathy_tp_chat_set_acknowledge      (EmpathyTpChat      *chat,
+						     TpChan             *tp_chan,
 						     gboolean            acknowledge);
+EmpathyTpChat *empathy_tp_chat_new_with_contact     (EmpathyContact     *contact);
 McAccount *    empathy_tp_chat_get_account          (EmpathyTpChat      *chat);
 TpChan *       empathy_tp_chat_get_channel          (EmpathyTpChat      *chat);
 void           empathy_tp_chat_send                 (EmpathyTpChat      *chat,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]