diff options
author | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2011-05-03 20:43:34 +0800 |
---|---|---|
committer | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2011-05-03 22:41:26 +0800 |
commit | a4c37d0cbf7030206a31a9eee838ae8b0d3f13d3 (patch) | |
tree | 62822075a67b93ee4d98f1c7143dcedd3d3b24cc /src | |
parent | 454bb79700b86511e3b0b03c7aab0d498e6a7258 (diff) | |
download | gsoc2013-empathy-a4c37d0cbf7030206a31a9eee838ae8b0d3f13d3.tar gsoc2013-empathy-a4c37d0cbf7030206a31a9eee838ae8b0d3f13d3.tar.gz gsoc2013-empathy-a4c37d0cbf7030206a31a9eee838ae8b0d3f13d3.tar.bz2 gsoc2013-empathy-a4c37d0cbf7030206a31a9eee838ae8b0d3f13d3.tar.lz gsoc2013-empathy-a4c37d0cbf7030206a31a9eee838ae8b0d3f13d3.tar.xz gsoc2013-empathy-a4c37d0cbf7030206a31a9eee838ae8b0d3f13d3.tar.zst gsoc2013-empathy-a4c37d0cbf7030206a31a9eee838ae8b0d3f13d3.zip |
empathy-chat: track chat displayed instead of channels being handled (#649273)
Diffstat (limited to 'src')
-rw-r--r-- | src/empathy-chat-manager.c | 71 | ||||
-rw-r--r-- | src/empathy-chat.c | 6 |
2 files changed, 35 insertions, 42 deletions
diff --git a/src/empathy-chat-manager.c b/src/empathy-chat-manager.c index de97c6c46..9c2a17891 100644 --- a/src/empathy-chat-manager.c +++ b/src/empathy-chat-manager.c @@ -32,7 +32,7 @@ enum { CLOSED_CHATS_CHANGED, - HANDLED_CHATS_CHANGED, + DISPLAYED_CHATS_CHANGED, LAST_SIGNAL }; @@ -49,7 +49,7 @@ struct _EmpathyChatManagerPriv /* Queue of (ChatData *) representing the closed chats */ GQueue *closed_queue; - guint num_handled_channels; + guint num_displayed_chat; TpBaseClient *handler; }; @@ -100,11 +100,28 @@ chat_data_free (ChatData *data) } static void +chat_destroyed_cb (gpointer data, + GObject *object) +{ + EmpathyChatManager *self = data; + EmpathyChatManagerPriv *priv = GET_PRIV (self); + + priv->num_displayed_chat--; + + DEBUG ("Chat destroyed; we are now displaying %u chats", + priv->num_displayed_chat); + + g_signal_emit (self, signals[DISPLAYED_CHATS_CHANGED], 0, + priv->num_displayed_chat); +} + +static void process_tp_chat (EmpathyChatManager *self, EmpathyTpChat *tp_chat, TpAccount *account, gint64 user_action_time) { + EmpathyChatManagerPriv *priv = GET_PRIV (self); EmpathyChat *chat = NULL; const gchar *id; @@ -124,6 +141,16 @@ process_tp_chat (EmpathyChatManager *self, /* empathy_chat_new returns a floating reference as EmpathyChat is * a GtkWidget. This reference will be taken by a container * (a GtkNotebook) when we'll call empathy_chat_window_present_chat */ + + priv->num_displayed_chat++; + + DEBUG ("Chat displayed; we are now displaying %u chat", + priv->num_displayed_chat); + + g_signal_emit (self, signals[DISPLAYED_CHATS_CHANGED], 0, + priv->num_displayed_chat); + + g_object_weak_ref ((GObject *) chat, chat_destroyed_cb, self); } empathy_chat_window_present_chat (chat, user_action_time); @@ -191,24 +218,6 @@ tp_chat_ready_cb (GObject *object, } static void -channel_invalidated (TpChannel *channel, - guint domain, - gint code, - gchar *message, - EmpathyChatManager *self) -{ - EmpathyChatManagerPriv *priv = GET_PRIV (self); - - priv->num_handled_channels--; - - DEBUG ("Channel closed; we are now handling %u text channels", - priv->num_handled_channels); - - g_signal_emit (self, signals[HANDLED_CHATS_CHANGED], 0, - priv->num_handled_channels); -} - -static void handle_channels (TpSimpleHandler *handler, TpAccount *account, TpConnection *connection, @@ -219,9 +228,7 @@ handle_channels (TpSimpleHandler *handler, gpointer user_data) { EmpathyChatManager *self = (EmpathyChatManager *) user_data; - EmpathyChatManagerPriv *priv = GET_PRIV (self); GList *l; - gboolean handling = FALSE; for (l = channels; l != NULL; l = g_list_next (l)) { @@ -238,7 +245,7 @@ handle_channels (TpSimpleHandler *handler, continue; } - handling = TRUE; + DEBUG ("Now handling channel %s", tp_proxy_get_object_path (channel)); tp_chat = empathy_tp_chat_new (account, channel); @@ -254,23 +261,9 @@ handle_channels (TpSimpleHandler *handler, ctx->sig_id = g_signal_connect (tp_chat, "notify::ready", G_CALLBACK (tp_chat_ready_cb), ctx); } - - priv->num_handled_channels++; - - g_signal_connect (channel, "invalidated", - G_CALLBACK (channel_invalidated), self); } tp_handle_channels_context_accept (context); - - if (handling) - { - DEBUG ("Channels handled; we are now handling %u text channels", - priv->num_handled_channels); - - g_signal_emit (self, signals[HANDLED_CHATS_CHANGED], 0, - priv->num_handled_channels); - } } static void @@ -387,8 +380,8 @@ empathy_chat_manager_class_init ( G_TYPE_NONE, 1, G_TYPE_UINT, NULL); - signals[HANDLED_CHATS_CHANGED] = - g_signal_new ("handled-chats-changed", + signals[DISPLAYED_CHATS_CHANGED] = + g_signal_new ("displayed-chats-changed", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, 0, diff --git a/src/empathy-chat.c b/src/empathy-chat.c index 73d8ce87c..43ab00270 100644 --- a/src/empathy-chat.c +++ b/src/empathy-chat.c @@ -52,7 +52,7 @@ static gboolean use_timer = TRUE; static EmpathyChatManager *chat_mgr = NULL; static void -handled_chats_changed_cb (EmpathyChatManager *mgr, +displayed_chats_changed_cb (EmpathyChatManager *mgr, guint nb_chats, gpointer user_data) { @@ -81,8 +81,8 @@ activate_cb (GApplication *application) g_assert (chat_mgr == NULL); chat_mgr = empathy_chat_manager_dup_singleton (); - g_signal_connect (chat_mgr, "handled-chats-changed", - G_CALLBACK (handled_chats_changed_cb), GUINT_TO_POINTER (1)); + g_signal_connect (chat_mgr, "displayed-chats-changed", + G_CALLBACK (displayed_chats_changed_cb), GUINT_TO_POINTER (1)); } int |