[empathy: 1/2] Display typing icon in MUC contact-list



commit 1acf8998707505a367ef27e04730907b56408b3d
Author: Chandni Verma <chandniverma2112 gmail com>
Date:   Sun Jan 16 20:19:49 2011 +0530

    Display typing icon in MUC contact-list
    
    Fixes: https://bugzilla.gnome.org/show_bug.cgi?id=609419

 libempathy-gtk/empathy-contact-list-store.c |   60 ++++++++++++++++++++++++++-
 libempathy/empathy-tp-chat.c                |    9 ++++
 libempathy/empathy-tp-chat.h                |    3 +
 src/empathy-chat-manager.c                  |    4 +-
 4 files changed, 74 insertions(+), 2 deletions(-)
---
diff --git a/libempathy-gtk/empathy-contact-list-store.c b/libempathy-gtk/empathy-contact-list-store.c
index d87461e..a8dbe6c 100644
--- a/libempathy-gtk/empathy-contact-list-store.c
+++ b/libempathy-gtk/empathy-contact-list-store.c
@@ -34,12 +34,14 @@
 #include <telepathy-glib/util.h>
 
 #include <libempathy/empathy-utils.h>
+#include <libempathy/empathy-tp-chat.h>
 #include <libempathy/empathy-enum-types.h>
 #include <libempathy/empathy-contact-manager.h>
 
 #include "empathy-contact-list-store.h"
 #include "empathy-ui-utils.h"
 #include "empathy-gtk-enum-types.h"
+#include "empathy-images.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
 #include <libempathy/empathy-debug.h>
@@ -181,6 +183,32 @@ enum {
 
 G_DEFINE_TYPE (EmpathyContactListStore, empathy_contact_list_store, GTK_TYPE_TREE_STORE);
 
+static void
+contact_list_store_chat_state_changed_cb (TpChannel *self,
+				     guint contact_handle,
+				     guint state,
+				     gpointer store)
+{
+	EmpathyContactListStorePriv *priv = GET_PRIV (store);
+	GList *contacts, *l;
+
+	contacts = empathy_contact_list_get_members (priv->list);
+
+	/* Find the contact in the list. After that l is the list elem or NULL */
+	for (l = contacts; l != NULL; l = l->next) {
+		if (empathy_contact_get_handle (EMPATHY_CONTACT (l->data)) ==
+		    contact_handle) {
+			break;
+		}
+	}
+
+	if (l != NULL)
+		contact_list_store_contact_update (store, l->data);
+
+	g_list_foreach (contacts, (GFunc) g_object_unref, NULL);
+	g_list_free (contacts);
+}
+
 static gboolean
 contact_list_store_iface_setup (gpointer user_data)
 {
@@ -206,6 +234,20 @@ contact_list_store_iface_setup (gpointer user_data)
 			  G_CALLBACK (contact_list_store_groups_changed_cb),
 			  store);
 
+	if (EMPATHY_IS_TP_CHAT (priv->list)) {
+		TpChannel *channel;
+
+		channel = empathy_tp_chat_get_channel (EMPATHY_TP_CHAT (priv->list));
+		if (!tp_proxy_is_prepared (channel, TP_CHANNEL_FEATURE_CHAT_STATES)) {
+			DEBUG ("Chat state feature not prepared");
+		} else {
+			g_signal_connect (channel,
+					  "chat-state-changed",
+					  G_CALLBACK (contact_list_store_chat_state_changed_cb),
+					  store);
+		}
+	}
+
 	/* Add contacts already created. */
 	contacts = empathy_contact_list_get_members (priv->list);
 	for (l = contacts; l; l = l->next) {
@@ -1835,9 +1877,25 @@ contact_list_store_get_contact_status_icon (EmpathyContactListStore *store,
 					    EmpathyContact *contact)
 {
 	GdkPixbuf                   *pixbuf_status = NULL;
+	EmpathyContactListStorePriv *priv;
 	const gchar                 *status_icon_name = NULL;
+	gboolean                     composing = FALSE;
+
+	priv = GET_PRIV (store);
+
+	if (EMPATHY_IS_TP_CHAT (priv->list)) {
+		if (empathy_tp_chat_get_chat_state (EMPATHY_TP_CHAT (priv->list),
+		      contact) ==
+			TP_CHANNEL_CHAT_STATE_COMPOSING)
+		composing = TRUE;
+	}
+
+	if (composing) {
+		status_icon_name = EMPATHY_IMAGE_TYPING;
+	} else {
+		status_icon_name = empathy_icon_name_for_contact (contact);
+	}
 
-	status_icon_name = empathy_icon_name_for_contact (contact);
 	if (status_icon_name == NULL)
 		return NULL;
 
diff --git a/libempathy/empathy-tp-chat.c b/libempathy/empathy-tp-chat.c
index f135104..e24ba84 100644
--- a/libempathy/empathy-tp-chat.c
+++ b/libempathy/empathy-tp-chat.c
@@ -1959,3 +1959,12 @@ empathy_tp_chat_is_invited (EmpathyTpChat *self,
 	return tp_channel_group_get_local_pending_info (priv->channel, self_handle,
 		inviter, NULL, NULL);
 }
+
+TpChannelChatState
+empathy_tp_chat_get_chat_state (EmpathyTpChat *chat,
+			    EmpathyContact *contact)
+{
+	EmpathyTpChatPriv *priv = GET_PRIV (chat);
+	return tp_channel_get_chat_state (priv->channel,
+		empathy_contact_get_handle (contact));
+}
diff --git a/libempathy/empathy-tp-chat.h b/libempathy/empathy-tp-chat.h
index 8858f49..8511335 100644
--- a/libempathy/empathy-tp-chat.h
+++ b/libempathy/empathy-tp-chat.h
@@ -105,6 +105,9 @@ void           empathy_tp_chat_join                 (EmpathyTpChat      *chat);
 
 gboolean       empathy_tp_chat_is_invited           (EmpathyTpChat      *chat,
 						     TpHandle *inviter);
+TpChannelChatState
+               empathy_tp_chat_get_chat_state       (EmpathyTpChat      *chat,
+               	             EmpathyContact *contact);
 
 G_END_DECLS
 
diff --git a/src/empathy-chat-manager.c b/src/empathy-chat-manager.c
index 38c91fa..c84b5f4 100644
--- a/src/empathy-chat-manager.c
+++ b/src/empathy-chat-manager.c
@@ -289,9 +289,11 @@ empathy_chat_manager_init (EmpathyChatManager *self)
   priv->handler = tp_simple_handler_new (dbus, FALSE, FALSE, "Empathy.Chat",
       FALSE, handle_channels, self, NULL);
 
-  /* EmpathyTpChat relies on this feature being prepared */
+  /* EmpathyTpChat relies on these features being prepared */
   tp_base_client_add_connection_features_varargs (priv->handler,
     TP_CONNECTION_FEATURE_CAPABILITIES, 0);
+  tp_base_client_add_channel_features_varargs (priv->handler,
+      TP_CHANNEL_FEATURE_CHAT_STATES, 0);
 
   g_object_unref (dbus);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]