]> git.0d.be Git - empathy.git/commitdiff
Let a chatroom keep a reference to a its TpChat if applicable
authorSjoerd Simons <sjoerd.simons@collabora.co.uk>
Fri, 9 Jan 2009 16:15:31 +0000 (16:15 +0000)
committerXavier Claessens <xclaesse@src.gnome.org>
Fri, 9 Jan 2009 16:15:31 +0000 (16:15 +0000)
Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk>
svn path=/trunk/; revision=2189

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

index 91138e293b6a8074bca2d1abfd69454f487694e4..e3fb3c9f766a6b60015fce20785cb44307a1c12c 100644 (file)
@@ -301,20 +301,20 @@ room_sub_menu_activate_cb (GtkWidget *item,
 {
        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 @@ empathy_contact_invite_menu_item_new (EmpathyContact *contact)
 
        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);
                }
        }
 
index 0a637a440d5d2dd7ea1ede6d32744a1963dff4ec..fdc6f3c0c95397d6e071b3497509ebbc017890ac 100644 (file)
@@ -667,6 +667,7 @@ chatroom_manager_chat_destroyed_cb (EmpathyTpChat *chat,
   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_manager_observe_channel_cb (EmpathyDispatcher *dispatcher,
     {
       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..  */
index 0920c8a144d31f6ba7496bab9b2a99e1e2a23151..16707bd15185911e6c9c64c9483be2e2df05e87c 100644 (file)
@@ -35,7 +35,8 @@ typedef struct {
        gchar     *room;
        gchar     *name;
        gboolean   auto_connect;
-  gboolean favorite;
+       gboolean favorite;
+       EmpathyTpChat *tp_chat;
 } EmpathyChatroomPriv;
 
 
@@ -55,7 +56,8 @@ enum {
        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 @@ empathy_chatroom_class_init (EmpathyChatroomClass *klass)
         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 @@ chatroom_finalize (GObject *object)
 
        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 @@ chatroom_get_property (GObject    *object,
   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 @@ chatroom_set_property (GObject      *object,
             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 @@ empathy_chatroom_equal (gconstpointer v1,
        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;
+}
index a4eecc04a92a8cc59ea65ba7819c4e7706cb30e7..3261c8d25c86ab8d66865937fcc9288d9f270dca 100644 (file)
@@ -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 @@ void            empathy_chatroom_set_auto_connect (EmpathyChatroom *chatroom,
                                                   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__ */