[empathy: 1/2] Add the method empathy_contact_can_stream_tubes in the empathy-tp-contact-factory



commit ce67f6901ba26b589345a8cdea110878bf6861c6
Author: Arnaud Maillet <arnaud maillet collabora co uk>
Date:   Fri May 29 15:18:52 2009 +0200

    Add the method empathy_contact_can_stream_tubes in the empathy-tp-contact-factory
---
 libempathy/empathy-contact.c            |   12 ++++++
 libempathy/empathy-contact.h            |    2 +
 libempathy/empathy-tp-contact-factory.c |   67 +++++++++++++++++++------------
 3 files changed, 55 insertions(+), 26 deletions(-)

diff --git a/libempathy/empathy-contact.c b/libempathy/empathy-contact.c
index eac087e..a08c629 100644
--- a/libempathy/empathy-contact.c
+++ b/libempathy/empathy-contact.c
@@ -814,6 +814,18 @@ empathy_contact_can_send_files (EmpathyContact *contact)
   return priv->capabilities & EMPATHY_CAPABILITIES_FT;
 }
 
+gboolean
+empathy_contact_can_use_stream_tube (EmpathyContact *contact)
+{
+  EmpathyContactPriv *priv;
+
+  g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), FALSE);
+
+  priv = GET_PRIV (contact);
+
+  return priv->capabilities & EMPATHY_CAPABILITIES_STREAM_TUBE;
+}
+
 static gchar *
 contact_get_avatar_filename (EmpathyContact *contact,
                              const gchar *token)
diff --git a/libempathy/empathy-contact.h b/libempathy/empathy-contact.h
index 0e6cfe2..ff8d426 100644
--- a/libempathy/empathy-contact.h
+++ b/libempathy/empathy-contact.h
@@ -63,6 +63,7 @@ typedef enum {
   EMPATHY_CAPABILITIES_AUDIO = 1 << 0,
   EMPATHY_CAPABILITIES_VIDEO = 1 << 1,
   EMPATHY_CAPABILITIES_FT = 1 << 2,
+  EMPATHY_CAPABILITIES_STREAM_TUBE = 1 << 3,
   EMPATHY_CAPABILITIES_UNKNOWN = 1 << 7
 } EmpathyCapabilities;
 
@@ -98,6 +99,7 @@ gboolean empathy_contact_is_online (EmpathyContact *contact);
 const gchar * empathy_contact_get_status (EmpathyContact *contact);
 gboolean empathy_contact_can_voip (EmpathyContact *contact);
 gboolean empathy_contact_can_send_files (EmpathyContact *contact);
+gboolean empathy_contact_can_use_stream_tube (EmpathyContact *contact);
 guint empathy_contact_hash (gconstpointer key);
 
 void empathy_contact_load_avatar_data (EmpathyContact *contact,
diff --git a/libempathy/empathy-tp-contact-factory.c b/libempathy/empathy-tp-contact-factory.c
index abef0c0..96fdfda 100644
--- a/libempathy/empathy-tp-contact-factory.c
+++ b/libempathy/empathy-tp-contact-factory.c
@@ -51,6 +51,7 @@ typedef struct {
 	guint           avatar_max_height;
 	guint           avatar_max_size;
 	gboolean        can_request_ft;
+	gboolean        can_request_st;
 } EmpathyTpContactFactoryPriv;
 
 G_DEFINE_TYPE (EmpathyTpContactFactory, empathy_tp_contact_factory, G_TYPE_OBJECT);
@@ -618,6 +619,7 @@ get_requestable_channel_classes_cb (TpProxy *connection,
 	EmpathyTpContactFactoryPriv *priv = GET_PRIV (self);
 	GPtrArray                   *classes;
 	guint                        i;
+	GList                       *l;
 
 	if (error != NULL) {
 		DEBUG ("Error: %s", error->message);
@@ -629,39 +631,46 @@ get_requestable_channel_classes_cb (TpProxy *connection,
 		GValueArray *class_struct;
 		GHashTable *fixed_prop;
 		GValue *chan_type, *handle_type;
-		GList *l;
 
 		class_struct = g_ptr_array_index (classes, i);
 		fixed_prop = g_value_get_boxed (g_value_array_get_nth (class_struct, 0));
 
-		chan_type = g_hash_table_lookup (fixed_prop,
-			TP_IFACE_CHANNEL ".ChannelType");
-		if (chan_type == NULL ||
-		    tp_strdiff (g_value_get_string (chan_type),
-		    		TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER)) {
-			continue;
-		}
-
 		handle_type = g_hash_table_lookup (fixed_prop,
 			TP_IFACE_CHANNEL ".TargetHandleType");
 		if (handle_type == NULL ||
-		    g_value_get_uint (handle_type) != TP_HANDLE_TYPE_CONTACT) {
+		    g_value_get_uint (handle_type) != TP_HANDLE_TYPE_CONTACT)
 			continue;
-		}
 
-		/* We can request file transfer channel to contacts. */
-		priv->can_request_ft = TRUE;
+		chan_type = g_hash_table_lookup (fixed_prop,
+			TP_IFACE_CHANNEL ".ChannelType");
+		if (chan_type == NULL)
+			continue;
 
-		/* Update the capabilities of all contacts */
-		for (l = priv->contacts; l != NULL; l = g_list_next (l)) {
-			EmpathyContact *contact = l->data;
-			EmpathyCapabilities caps;
+		if (!tp_strdiff (g_value_get_string (chan_type),
+		    TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER))
+			priv->can_request_ft = TRUE;
+		else if (!tp_strdiff (g_value_get_string (chan_type),
+		         TP_IFACE_CHANNEL_TYPE_STREAM_TUBE))
+			priv->can_request_st = TRUE;
+	}
 
-			caps = empathy_contact_get_capabilities (contact);
-			empathy_contact_set_capabilities (contact, caps |
-				EMPATHY_CAPABILITIES_FT);
-		}
-		break;
+	if (!priv->can_request_ft && !priv->can_request_st)
+		return ;
+
+	/* Update the capabilities of all contacts */
+	for (l = priv->contacts; l != NULL; l = g_list_next (l)) {
+		EmpathyContact *contact = l->data;
+		EmpathyCapabilities caps;
+
+		caps = empathy_contact_get_capabilities (contact);
+
+		if (priv->can_request_ft)
+			caps |= EMPATHY_CAPABILITIES_FT;
+
+		if (priv->can_request_st)
+			caps |= EMPATHY_CAPABILITIES_STREAM_TUBE;
+
+		empathy_contact_set_capabilities (contact, caps);
 	}
 }
 
@@ -706,6 +715,7 @@ tp_contact_factory_add_contact (EmpathyTpContactFactory *tp_factory,
 	GHashTable *tokens;
 	GPtrArray *capabilities;
 	GError *error = NULL;
+	EmpathyCapabilities caps;
 
 	/* Keep a weak ref to that contact */
 	g_object_weak_ref (G_OBJECT (contact),
@@ -718,16 +728,20 @@ tp_contact_factory_add_contact (EmpathyTpContactFactory *tp_factory,
 				g_object_ref (tp_factory),
 				g_object_unref);
 
+	caps = empathy_contact_get_capabilities (contact);
+
 	/* Set the FT capability */
 	if (priv->can_request_ft) {
-		EmpathyCapabilities caps;
-
-		caps = empathy_contact_get_capabilities (contact);
 		caps |= EMPATHY_CAPABILITIES_FT;
+	}
 
-		empathy_contact_set_capabilities (contact, caps);
+	/* Set the Stream Tube capability */
+	if (priv->can_request_st) {
+		caps |= EMPATHY_CAPABILITIES_STREAM_TUBE;
 	}
 
+	empathy_contact_set_capabilities (contact, caps);
+
 	/* Set is-user property. Note that it could still be the handle is
 	 * different from the connection's self handle, in the case the handle
 	 * comes from a group interface. */
@@ -1391,6 +1405,7 @@ empathy_tp_contact_factory_init (EmpathyTpContactFactory *tp_factory)
 
 	tp_factory->priv = priv;
 	priv->can_request_ft = FALSE;
+	priv->can_request_st = FALSE;
 }
 
 static GHashTable *factories = NULL;



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