[empathy/gnome-3-0] empathy-chat: track chat displayed instead of channels being handled (#649273)
- From: Guillaume Desmottes <gdesmott src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [empathy/gnome-3-0] empathy-chat: track chat displayed instead of channels being handled (#649273)
- Date: Tue, 3 May 2011 14:49:24 +0000 (UTC)
commit 7454d321ebacdcd7a5484a2926cafe8a664cca95
Author: Guillaume Desmottes <guillaume desmottes collabora co uk>
Date: Tue May 3 14:43:34 2011 +0200
empathy-chat: track chat displayed instead of channels being handled (#649273)
src/empathy-chat-manager.c | 71 ++++++++++++++++++++------------------------
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 518b63e..02d3ed3 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))
{
@@ -231,7 +238,7 @@ handle_channels (TpSimpleHandler *handler,
if (tp_proxy_get_invalidated (channel) != NULL)
continue;
- handling = TRUE;
+ DEBUG ("Now handling channel %s", tp_proxy_get_object_path (channel));
tp_chat = empathy_tp_chat_new (account, channel);
@@ -247,23 +254,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
@@ -380,8 +373,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 73d8ce8..43ab002 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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]