From 38f57b9ec344142a829c2e54824f85ea77966b76 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Fri, 21 Nov 2008 16:20:43 +0000 Subject: Use the RequestableChannelClasses property instead of hardcoding salut to check if we can send file or not svn path=/trunk/; revision=1846 --- libempathy/empathy-contact.c | 85 +++++++++++++++++++++++++++++++++----------- 1 file changed, 65 insertions(+), 20 deletions(-) (limited to 'libempathy/empathy-contact.c') diff --git a/libempathy/empathy-contact.c b/libempathy/empathy-contact.c index d2c187a1d..ab22b4780 100644 --- a/libempathy/empathy-contact.c +++ b/libempathy/empathy-contact.c @@ -30,6 +30,9 @@ #include #include +#include + +#include #include "empathy-contact.h" #include "empathy-utils.h" @@ -468,18 +471,59 @@ empathy_contact_get_account (EmpathyContact *contact) return priv->account; } -static gboolean -contact_is_salut (EmpathyContact *contact) +static void +get_requestable_channel_classes_cb (TpProxy *connection, + const GValue *value, + const GError *error, + gpointer user_data, + GObject *weak_object) { - McAccount *account; - McProfile *profile; - const gchar *name; + GPtrArray *classes; + guint i; + + if (error != NULL) + { + DEBUG ("Error: %s", error->message); + return; + } + + classes = g_value_get_boxed (value); + + for (i = 0; i < classes->len; i++) + { + GValue class = {0,}; + GValue *chan_type, *handle_type; + GHashTable *fixed_prop; + EmpathyCapabilities caps; + EmpathyContact *contact; + + g_value_init (&class, TP_STRUCT_TYPE_REQUESTABLE_CHANNEL_CLASS); + g_value_set_static_boxed (&class, g_ptr_array_index (classes, i)); + + dbus_g_type_struct_get (&class, + 0, &fixed_prop, + G_MAXUINT); + + chan_type = g_hash_table_lookup (fixed_prop, + TP_IFACE_CHANNEL ".ChannelType"); + if (chan_type == NULL || tp_strdiff (g_value_get_string (chan_type), + EMP_IFACE_CHANNEL_TYPE_FILE_TRANSFER)) + continue; - account = empathy_contact_get_account (contact); - profile = mc_account_get_profile (account); - name = mc_profile_get_protocol_name (profile); + handle_type = g_hash_table_lookup (fixed_prop, + TP_IFACE_CHANNEL ".TargetHandleType"); - return (strcmp (name, "local-xmpp") == 0); + if (handle_type == NULL || g_value_get_uint (handle_type) + != TP_HANDLE_TYPE_CONTACT) + continue; + + /* We can request file transfer channel to contacts. Set the FT caps. */ + contact = EMPATHY_CONTACT (user_data); + caps = empathy_contact_get_capabilities (contact); + caps |= EMPATHY_CAPABILITIES_FT; + + empathy_contact_set_capabilities (contact, caps); + } } void @@ -487,6 +531,8 @@ empathy_contact_set_account (EmpathyContact *contact, McAccount *account) { EmpathyContactPriv *priv; + MissionControl *mc; + TpConnection *connection; g_return_if_fail (EMPATHY_IS_CONTACT (contact)); g_return_if_fail (MC_IS_ACCOUNT (account)); @@ -500,20 +546,19 @@ empathy_contact_set_account (EmpathyContact *contact, g_object_unref (priv->account); priv->account = g_object_ref (account); - /* FIXME salut does not yet support the Capabilities interface, so for - * now we use this hack. - */ - if (contact_is_salut (contact)) - { - EmpathyCapabilities caps; - - caps = empathy_contact_get_capabilities (contact); - caps |= EMPATHY_CAPABILITIES_FT; + /* FIXME: We should use the futur ContactCapabilities interface */ + /* Can we request FT channel on this connection? */ + mc = empathy_mission_control_new (); + connection = mission_control_get_tpconnection (mc, account, NULL); - empathy_contact_set_capabilities (contact, caps); - } + tp_cli_dbus_properties_call_get (connection, -1, + TP_IFACE_CONNECTION_INTERFACE_REQUESTS, "RequestableChannelClasses", + get_requestable_channel_classes_cb, contact, NULL, G_OBJECT (contact)); g_object_notify (G_OBJECT (contact), "account"); + + g_object_unref (mc); + g_object_unref (connection); } McPresence -- cgit v1.2.3