empathy r2189 - in trunk: libempathy libempathy-gtk



Author: xclaesse
Date: Fri Jan  9 16:15:31 2009
New Revision: 2189
URL: http://svn.gnome.org/viewvc/empathy?rev=2189&view=rev

Log:
Let a chatroom keep a reference to a its TpChat if applicable

Signed-off-by: Sjoerd Simons <sjoerd simons collabora co uk>

Modified:
   trunk/libempathy-gtk/empathy-contact-menu.c
   trunk/libempathy/empathy-chatroom-manager.c
   trunk/libempathy/empathy-chatroom.c
   trunk/libempathy/empathy-chatroom.h

Modified: trunk/libempathy-gtk/empathy-contact-menu.c
==============================================================================
--- trunk/libempathy-gtk/empathy-contact-menu.c	(original)
+++ trunk/libempathy-gtk/empathy-contact-menu.c	Fri Jan  9 16:15:31 2009
@@ -301,20 +301,20 @@
 {
 	TpHandle handle;
 	GArray handles = {(gchar *) &handle, 1};
+	EmpathyTpChat *chat;
 	TpChannel *channel;
 
-	g_object_get (data->chatroom, "tp-channel", &channel, NULL);
-	if (channel == NULL) {
+	chat = empathy_chatroom_get_tp_chat (data->chatroom);
+	if (chat == NULL) {
 		/* channel was invalidated. Ignoring */
 		return;
 	}
 
 	/* send invitation */
 	handle = empathy_contact_get_handle (data->contact);
+	channel = empathy_tp_chat_get_channel (chat);
 	tp_cli_channel_interface_group_call_add_members (channel, -1, &handles,
 		_("Inviting to this room"), NULL, NULL, NULL, NULL);
-
-	g_object_unref (channel);
 }
 
 static GtkWidget *
@@ -362,17 +362,13 @@
 
 	for (l = rooms; l != NULL; l = g_list_next (l)) {
 		EmpathyChatroom *chatroom = l->data;
-		TpChannel *channel;
 
-		g_object_get (chatroom, "tp-channel", &channel, NULL);
-		if (channel != NULL) {
+		if (empathy_chatroom_get_tp_chat (chatroom) != NULL) {
 			have_rooms = TRUE;
 
 			room_item = create_room_sub_menu (contact, chatroom);
 			gtk_menu_shell_append (submenu_shell, room_item);
 			gtk_widget_show (room_item);
-
-			g_object_unref (channel);
 		}
 	}
 

Modified: trunk/libempathy/empathy-chatroom-manager.c
==============================================================================
--- trunk/libempathy/empathy-chatroom-manager.c	(original)
+++ trunk/libempathy/empathy-chatroom-manager.c	Fri Jan  9 16:15:31 2009
@@ -667,6 +667,7 @@
   if (chatroom == NULL)
     return;
 
+  g_object_set (chatroom, "tp-chat", NULL, NULL);
   g_object_get (chatroom, "favorite", &favorite, NULL);
 
   if (!favorite)
@@ -715,9 +716,14 @@
     {
       chatroom = empathy_chatroom_new_full (account, roomname, roomname,
         FALSE);
+      g_object_set (G_OBJECT (chatroom), "tp-chat", chat, NULL);
       empathy_chatroom_manager_add (manager, chatroom);
       g_object_unref (chatroom);
     }
+  else
+    {
+      g_object_set (G_OBJECT (chatroom), "tp-chat", chat, NULL);
+    }
 
   /* A TpChat is always destroyed as it only gets unreffed after the channel
    * has been invalidated in the dispatcher..  */

Modified: trunk/libempathy/empathy-chatroom.c
==============================================================================
--- trunk/libempathy/empathy-chatroom.c	(original)
+++ trunk/libempathy/empathy-chatroom.c	Fri Jan  9 16:15:31 2009
@@ -35,7 +35,8 @@
 	gchar     *room;
 	gchar     *name;
 	gboolean   auto_connect;
-  gboolean favorite;
+	gboolean favorite;
+	EmpathyTpChat *tp_chat;
 } EmpathyChatroomPriv;
 
 
@@ -55,7 +56,8 @@
 	PROP_ROOM,
 	PROP_NAME,
 	PROP_AUTO_CONNECT,
-  PROP_FAVORITE,
+	PROP_FAVORITE,
+	PROP_TP_CHAT,
 };
 
 G_DEFINE_TYPE (EmpathyChatroom, empathy_chatroom, G_TYPE_OBJECT);
@@ -113,6 +115,14 @@
         G_PARAM_STATIC_NICK |
         G_PARAM_STATIC_BLURB));
 
+	g_object_class_install_property (object_class,
+					 PROP_TP_CHAT,
+					 g_param_spec_object ("tp-chat",
+							      "Chatroom channel wrapper",
+							      "The wrapper for the chatroom channel if there is one",
+							      EMPATHY_TYPE_TP_CHAT,
+							      G_PARAM_READWRITE));
+
 	g_type_class_add_private (object_class, sizeof (EmpathyChatroomPriv));
 }
 
@@ -132,6 +142,9 @@
 
 	priv = GET_PRIV (object);
 
+	if (priv->tp_chat != NULL)
+		g_object_unref (priv->tp_chat);
+
 	g_object_unref (priv->account);
 	g_free (priv->room);
 	g_free (priv->name);
@@ -165,6 +178,9 @@
   case PROP_FAVORITE:
     g_value_set_boolean (value, priv->favorite);
     break;
+	case PROP_TP_CHAT:
+		g_value_set_object (value, priv->tp_chat);
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
 		break;
@@ -206,6 +222,22 @@
             FALSE);
       }
     break;
+	case PROP_TP_CHAT: {
+		GObject *chat = g_value_dup_object (value);
+
+		if (chat == (GObject *) priv->tp_chat)
+			break;
+
+		g_assert (chat == NULL || priv->tp_chat == NULL);
+
+		if (priv->tp_chat != NULL) {
+			g_object_unref (priv->tp_chat);
+			priv->tp_chat = NULL;
+		} else {
+			priv->tp_chat = EMPATHY_TP_CHAT (chat);
+		}
+		break;
+	}
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
 		break;
@@ -389,3 +421,14 @@
 	return empathy_account_equal (account_a, account_b) && !tp_strdiff (room_a,
       room_b);
 }
+
+EmpathyTpChat *
+empathy_chatroom_get_tp_chat (EmpathyChatroom *chatroom) {
+	EmpathyChatroomPriv *priv;
+
+	g_return_val_if_fail (EMPATHY_IS_CHATROOM (chatroom), NULL);
+
+	priv = GET_PRIV (chatroom);
+
+	return priv->tp_chat;
+}

Modified: trunk/libempathy/empathy-chatroom.h
==============================================================================
--- trunk/libempathy/empathy-chatroom.h	(original)
+++ trunk/libempathy/empathy-chatroom.h	Fri Jan  9 16:15:31 2009
@@ -26,6 +26,8 @@
 
 #include <libmissioncontrol/mc-account.h>
 
+#include <libempathy/empathy-tp-chat.h>
+
 G_BEGIN_DECLS
 
 #define EMPATHY_TYPE_CHATROOM             (empathy_chatroom_get_type ())
@@ -69,8 +71,8 @@
 						   gboolean         auto_connect);
 gboolean        empathy_chatroom_equal            (gconstpointer    v1,
 						   gconstpointer    v2);
+EmpathyTpChat * empathy_chatroom_get_tp_chat      (EmpathyChatroom *chatroom);
 
-
-G_BEGIN_DECLS
+G_END_DECLS
 
 #endif /* __EMPATHY_CHATROOM_H__ */



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