From 5206421264c993ab34599c63b3744e4a7f9e075a Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Fri, 28 Sep 2012 08:38:14 +0200 Subject: [PATCH] chat-manager: cache the individual mgr We want to keep it alive during the whole lifetime of empathy-chat. --- src/empathy-chat-manager.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/empathy-chat-manager.c b/src/empathy-chat-manager.c index 6a163aaa..f93b9023 100644 --- a/src/empathy-chat-manager.c +++ b/src/empathy-chat-manager.c @@ -25,6 +25,7 @@ #include #include #include +#include #include @@ -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); } -- 2.39.2