]> git.0d.be Git - empathy.git/commitdiff
chat-manager: cache the individual mgr
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Fri, 28 Sep 2012 06:38:14 +0000 (08:38 +0200)
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Wed, 3 Oct 2012 10:05:43 +0000 (12:05 +0200)
We want to keep it alive during the whole lifetime of empathy-chat.

src/empathy-chat-manager.c

index 6a163aaae8e3dd5707a91e938ee938cb237fc006..f93b90235afcd28eacfeac2ad5343e1a8860ff2b 100644 (file)
@@ -25,6 +25,7 @@
 #include <libempathy/empathy-chatroom-manager.h>
 #include <libempathy/empathy-request-util.h>
 #include <libempathy/empathy-utils.h>
+#include <libempathy/empathy-individual-manager.h>
 
 #include <libempathy-gtk/empathy-ui-utils.h>
 
@@ -70,6 +71,11 @@ struct _EmpathyChatManagerPriv
   GHashTable *messages;
 
   TpBaseClient *handler;
+
+  /* Cached to keep Folks in memory while empathy-chat is running; we don't
+   * want to reload it each time the last chat window is closed
+   * and re-opened. */
+  EmpathyIndividualManager *individual_mgr;
 };
 
 #define GET_PRIV(o) \
@@ -151,6 +157,20 @@ join_cb (GObject *source,
     }
 }
 
+static void
+individual_mgr_cb (EmpathyChatWindow *window,
+    GParamSpec *spec,
+    EmpathyChatManager *self)
+{
+  EmpathyChatManagerPriv *priv = GET_PRIV (self);
+
+  if (priv->individual_mgr != NULL)
+    return;
+
+  priv->individual_mgr = empathy_chat_window_get_individual_manager (window);
+  g_object_ref (priv->individual_mgr);
+}
+
 static void
 process_tp_chat (EmpathyChatManager *self,
     EmpathyTpChat *tp_chat,
@@ -160,6 +180,7 @@ process_tp_chat (EmpathyChatManager *self,
   EmpathyChatManagerPriv *priv = GET_PRIV (self);
   EmpathyChat *chat = NULL;
   const gchar *id;
+  EmpathyChatWindow *window;
 
   id = empathy_tp_chat_get_id (tp_chat);
   if (!tp_str_empty (id))
@@ -203,7 +224,15 @@ process_tp_chat (EmpathyChatManager *self,
 
       g_object_weak_ref ((GObject *) chat, chat_destroyed_cb, self);
     }
-  empathy_chat_window_present_chat (chat, user_action_time);
+
+  window = empathy_chat_window_present_chat (chat, user_action_time);
+
+  if (priv->individual_mgr == NULL)
+    {
+      /* We want to cache it as soon it's created */
+      tp_g_signal_connect_object (window, "notify::individual-manager",
+        G_CALLBACK (individual_mgr_cb), self, 0);
+    }
 
   if (empathy_tp_chat_is_invited (tp_chat, NULL))
     {
@@ -308,6 +337,7 @@ empathy_chat_manager_finalize (GObject *object)
 
   tp_clear_object (&priv->handler);
   tp_clear_object (&priv->chatroom_mgr);
+  tp_clear_object (&priv->individual_mgr);
 
   G_OBJECT_CLASS (empathy_chat_manager_parent_class)->finalize (object);
 }