]> git.0d.be Git - empathy.git/commitdiff
Adding capabilities contact property.
authorXavier Claessens <xclaesse@gmail.com>
Sat, 8 Sep 2007 19:15:34 +0000 (19:15 +0000)
committerXavier Claessens <xclaesse@src.gnome.org>
Sat, 8 Sep 2007 19:15:34 +0000 (19:15 +0000)
2007-09-08  Xavier Claessens  <xclaesse@gmail.com>

* libempathy/empathy-contact.c:
* libempathy/empathy-contact.h:
* libempathy/empathy-contact-factory.c: Adding capabilities contact
property.

svn path=/trunk/; revision=291

ChangeLog
libempathy/empathy-contact-factory.c
libempathy/empathy-contact.c
libempathy/empathy-contact.h

index c412068216217cbe709022a0884d1b139ad9b05c..3385d6aa0305fc3a079b0ed205b12291dceae38b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2007-09-08  Xavier Claessens  <xclaesse@gmail.com>
+
+       * libempathy/empathy-contact.c:
+       * libempathy/empathy-contact.h:
+       * libempathy/empathy-contact-factory.c: Adding capabilities contact
+       property.
+
 2007-09-08  Xavier Claessens  <xclaesse@gmail.com>
 
        * libempathy-gtk/empathy-contact-list-view.c:
index 96211ae47fec3c5eb191650e956752c8843bbee3..b4b3ba668e1617e5f35916f6095aaf2dcfe91c76 100644 (file)
@@ -28,6 +28,7 @@
 #include <libtelepathy/tp-conn-iface-aliasing-gen.h>
 #include <libtelepathy/tp-conn-iface-presence-gen.h>
 #include <libtelepathy/tp-conn-iface-avatars-gen.h>
+#include <libtelepathy/tp-conn-iface-capabilities-gen.h>
 #include <libmissioncontrol/mission-control.h>
 
 #include "empathy-contact-factory.h"
@@ -53,6 +54,7 @@ typedef struct {
        DBusGProxy            *aliasing_iface;
        DBusGProxy            *avatars_iface;
        DBusGProxy            *presence_iface;
+       DBusGProxy            *capabilities_iface;
 
        GList                 *contacts;
        guint                  self_handle;
@@ -375,6 +377,112 @@ contact_factory_avatar_retrieved_cb (DBusGProxy *proxy,
        empathy_avatar_unref (avatar);
 }
 
+static void
+contact_factory_update_capabilities (ContactFactoryAccountData *account_data,
+                                    guint                      handle,
+                                    const gchar               *channel_type,
+                                    guint                      generic,
+                                    guint                      specific)
+{
+       EmpathyContact      *contact;
+       EmpathyCapabilities  capabilities;
+
+       contact = contact_factory_account_data_find_by_handle (account_data,
+                                                              handle);
+       if (!contact) {
+               return;
+       }
+
+       capabilities = empathy_contact_get_capabilities (contact);
+
+       if (strcmp (channel_type, TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA) == 0) {
+               capabilities &= !(EMPATHY_CAPABILITIES_AUDIO);
+               capabilities &= !(EMPATHY_CAPABILITIES_VIDEO);
+               if (specific & TP_CHANNEL_MEDIA_CAPABILITY_AUDIO) {
+                       capabilities |= EMPATHY_CAPABILITIES_AUDIO;
+               }
+               if (specific & TP_CHANNEL_MEDIA_CAPABILITY_VIDEO) {
+                       capabilities |= EMPATHY_CAPABILITIES_VIDEO;
+               }
+       }
+
+       empathy_debug (DEBUG_DOMAIN, "Changing capabilities for contact %s (%d) to %d",
+                      empathy_contact_get_id (contact),
+                      empathy_contact_get_handle (contact),
+                      capabilities);
+
+       empathy_contact_set_capabilities (contact, capabilities);
+}
+
+static void
+contact_factory_get_capabilities_cb (DBusGProxy *proxy,
+                                    GPtrArray  *capabilities,
+                                    GError     *error,
+                                    gpointer    user_data)
+{
+       ContactFactoryAccountData *account_data = user_data;
+       guint                      i;
+
+       if (error) {
+               empathy_debug (DEBUG_DOMAIN, "Error getting capabilities: %s",
+                              error->message);
+               goto OUT;
+       }
+
+       for (i = 0; i < capabilities->len; i++) {
+               GValueArray *values;
+               guint        handle;
+               const gchar *channel_type;
+               guint        generic;
+               guint        specific;
+
+               values = g_ptr_array_index (capabilities, i);
+               handle = g_value_get_uint (g_value_array_get_nth (values, 0));
+               channel_type = g_value_get_string (g_value_array_get_nth (values, 1));
+               generic = g_value_get_uint (g_value_array_get_nth (values, 2));
+               specific = g_value_get_uint (g_value_array_get_nth (values, 3));
+
+               contact_factory_update_capabilities (account_data,
+                                                    handle,
+                                                    channel_type,
+                                                    generic,
+                                                    specific);
+       }
+
+
+OUT:
+       contact_factory_account_data_return_call (account_data);
+}
+
+static void
+contact_factory_capabilities_changed_cb (DBusGProxy *proxy,
+                                        GPtrArray  *capabilities,
+                                        gpointer    user_data)
+{
+       ContactFactoryAccountData *account_data = user_data;
+       guint                      i;
+
+       for (i = 0; i < capabilities->len; i++) {
+               GValueArray *values;
+               guint        handle;
+               const gchar *channel_type;
+               guint        generic;
+               guint        specific;
+
+               values = g_ptr_array_index (capabilities, i);
+               handle = g_value_get_uint (g_value_array_get_nth (values, 0));
+               channel_type = g_value_get_string (g_value_array_get_nth (values, 1));
+               generic = g_value_get_uint (g_value_array_get_nth (values, 3));
+               specific = g_value_get_uint (g_value_array_get_nth (values, 5));
+
+               contact_factory_update_capabilities (account_data,
+                                                    handle,
+                                                    channel_type,
+                                                    generic,
+                                                    specific);
+       }
+}
+
 static void
 contact_factory_request_everything (ContactFactoryAccountData *account_data,
                                    GArray                    *handles)
@@ -408,6 +516,14 @@ contact_factory_request_everything (ContactFactoryAccountData *account_data,
                                                             contact_factory_request_avatars_cb,
                                                             account_data);
        }
+
+       if (account_data->capabilities_iface) {
+               account_data->nb_pending_calls++;
+               tp_conn_iface_capabilities_get_capabilities_async (account_data->capabilities_iface,
+                                                                  handles,
+                                                                  contact_factory_get_capabilities_cb,
+                                                                  account_data);
+       }
 }
 
 static void
@@ -468,6 +584,7 @@ contact_factory_destroy_cb (TpConn                    *tp_conn,
        account_data->aliasing_iface = NULL;
        account_data->avatars_iface = NULL;
        account_data->presence_iface = NULL;
+       account_data->capabilities_iface = NULL;
 
        g_list_foreach (account_data->contacts,
                        contact_factory_disconnect_contact_foreach,
@@ -499,6 +616,12 @@ contact_factory_account_data_disconnect (ContactFactoryAccountData *account_data
                                                G_CALLBACK (contact_factory_presence_update_cb),
                                                account_data);
        }
+       if (account_data->capabilities_iface) {
+               dbus_g_proxy_disconnect_signal (account_data->capabilities_iface,
+                                               "CapabilitiesChanged",
+                                               G_CALLBACK (contact_factory_capabilities_changed_cb),
+                                               account_data);
+       }
        if (account_data->tp_conn) {
                g_signal_handlers_disconnect_by_func (account_data->tp_conn,
                                                      contact_factory_destroy_cb,
@@ -555,6 +678,8 @@ contact_factory_account_data_update (ContactFactoryAccountData *account_data)
                                                             TELEPATHY_CONN_IFACE_AVATARS_QUARK);
        account_data->presence_iface = tp_conn_get_interface (tp_conn,
                                                              TELEPATHY_CONN_IFACE_PRESENCE_QUARK);
+       account_data->capabilities_iface = tp_conn_get_interface (tp_conn,
+                                                                 TELEPATHY_CONN_IFACE_CAPABILITIES_QUARK);
 
        /* Connect signals */
        if (account_data->aliasing_iface) {
@@ -579,6 +704,12 @@ contact_factory_account_data_update (ContactFactoryAccountData *account_data)
                                             G_CALLBACK (contact_factory_presence_update_cb),
                                             account_data, NULL);
        }
+       if (account_data->capabilities_iface) {
+               dbus_g_proxy_connect_signal (account_data->capabilities_iface,
+                                            "CapabilitiesChanged",
+                                            G_CALLBACK (contact_factory_capabilities_changed_cb),
+                                            account_data, NULL);
+       }
        g_signal_connect (tp_conn, "destroy",
                          G_CALLBACK (contact_factory_destroy_cb),
                          account_data);
@@ -690,6 +821,7 @@ contact_factory_account_data_free (gpointer data)
                account_data->aliasing_iface = NULL;
                account_data->avatars_iface = NULL;
                account_data->presence_iface = NULL;
+               account_data->capabilities_iface = NULL;
        }
 
        /* Keep the struct alive if we have calls in flight, it will be
index 505e190c0d92da363739ab2c5252ae0a85840752..221b06e1720a61f880df326bc3b0df80a920db51 100644 (file)
@@ -47,6 +47,7 @@ struct _EmpathyContactPriv {
        McAccount          *account;
        EmpathyPresence    *presence;
        guint               handle;
+       EmpathyCapabilities capabilities;
        gboolean            is_user;
 };
 
@@ -74,6 +75,7 @@ enum {
        PROP_GROUPS,
        PROP_SUBSCRIPTION,
        PROP_HANDLE,
+       PROP_CAPABILITIES,
        PROP_IS_USER
 };
 
@@ -137,6 +139,16 @@ empathy_contact_class_init (EmpathyContactClass *class)
                                                            G_MAXUINT,
                                                            0,
                                                            G_PARAM_READWRITE));
+
+       g_object_class_install_property (object_class,
+                                        PROP_CAPABILITIES,
+                                        g_param_spec_flags ("capabilities",
+                                                            "Contact Capabilities",
+                                                            "Capabilities of the contact",
+                                                            EMPATHY_TYPE_CAPABILITIES,
+                                                            0,
+                                                            G_PARAM_READWRITE));
+
        g_object_class_install_property (object_class,
                                         PROP_IS_USER,
                                         g_param_spec_boolean ("is-user",
@@ -211,6 +223,9 @@ contact_get_property (GObject    *object,
        case PROP_HANDLE:
                g_value_set_uint (value, priv->handle);
                break;
+       case PROP_CAPABILITIES:
+               g_value_set_flags (value, priv->capabilities);
+               break;
        case PROP_IS_USER:
                g_value_set_boolean (value, priv->is_user);
                break;
@@ -255,6 +270,10 @@ contact_set_property (GObject      *object,
                empathy_contact_set_handle (EMPATHY_CONTACT (object),
                                           g_value_get_uint (value));
                break;
+       case PROP_CAPABILITIES:
+               empathy_contact_set_capabilities (EMPATHY_CONTACT (object),
+                                                 g_value_get_flags (value));
+               break;
        case PROP_IS_USER:
                empathy_contact_set_is_user (EMPATHY_CONTACT (object),
                                            g_value_get_boolean (value));
@@ -501,6 +520,37 @@ empathy_contact_set_handle (EmpathyContact *contact,
        g_object_notify (G_OBJECT (contact), "handle");
 }
 
+EmpathyCapabilities
+empathy_contact_get_capabilities (EmpathyContact *contact)
+{
+       EmpathyContactPriv *priv;
+
+       g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), 0);
+
+       priv = GET_PRIV (contact);
+
+       return priv->capabilities;
+}
+
+void
+empathy_contact_set_capabilities (EmpathyContact      *contact,
+                                 EmpathyCapabilities  capabilities)
+{
+       EmpathyContactPriv *priv;
+
+       g_return_if_fail (EMPATHY_IS_CONTACT (contact));
+
+       priv = GET_PRIV (contact);
+
+       if (priv->capabilities == capabilities) {
+               return;
+       }
+
+       priv->capabilities = capabilities;
+
+       g_object_notify (G_OBJECT (contact), "capabilities");
+}
+
 gboolean
 empathy_contact_is_user (EmpathyContact *contact)
 {
index 87a26f0dd9de793f827d0994db662402c112019f..d062885bc14a4d62af06eee675e3a8edc0d9bc1d 100644 (file)
@@ -53,37 +53,45 @@ struct _EmpathyContactClass {
        GObjectClass parent_class;
 };
 
-GType             empathy_contact_get_type     (void) G_GNUC_CONST;
-EmpathyContact *  empathy_contact_new          (McAccount       *account);
-EmpathyContact *  empathy_contact_new_full     (McAccount       *account,
-                                               const gchar     *id,
-                                               const gchar     *name);
-const gchar *     empathy_contact_get_id       (EmpathyContact  *contact);
-void              empathy_contact_set_id       (EmpathyContact  *contact,
-                                               const gchar     *id);
-const gchar *     empathy_contact_get_name     (EmpathyContact  *contact);
-void              empathy_contact_set_name     (EmpathyContact  *contact,
-                                               const gchar     *name);
-EmpathyAvatar *   empathy_contact_get_avatar   (EmpathyContact  *contact);
-void              empathy_contact_set_avatar   (EmpathyContact  *contact,
-                                               EmpathyAvatar   *avatar);
-McAccount *       empathy_contact_get_account  (EmpathyContact  *contact);
-void              empathy_contact_set_account  (EmpathyContact  *contact,
-                                               McAccount       *account);
-EmpathyPresence * empathy_contact_get_presence (EmpathyContact  *contact);
-void              empathy_contact_set_presence (EmpathyContact  *contact,
-                                               EmpathyPresence *presence);
-guint             empathy_contact_get_handle   (EmpathyContact  *contact);
-void              empathy_contact_set_handle   (EmpathyContact  *contact,
-                                               guint            handle);
-gboolean          empathy_contact_is_user      (EmpathyContact  *contact);
-void              empathy_contact_set_is_user  (EmpathyContact  *contact,
-                                               gboolean         is_user);
-gboolean          empathy_contact_is_online    (EmpathyContact  *contact);
-const gchar *     empathy_contact_get_status   (EmpathyContact  *contact);
-gboolean          empathy_contact_equal        (gconstpointer    v1,
-                                               gconstpointer    v2);
-guint             empathy_contact_hash         (gconstpointer    key);
+typedef enum {
+       EMPATHY_CAPABILITIES_AUDIO = 1 << 0,
+       EMPATHY_CAPABILITIES_VIDEO = 1 << 1,
+} EmpathyCapabilities;
+
+GType               empathy_contact_get_type           (void) G_GNUC_CONST;
+EmpathyContact *    empathy_contact_new                (McAccount           *account);
+EmpathyContact *    empathy_contact_new_full           (McAccount           *account,
+                                                       const gchar         *id,
+                                                       const gchar         *name);
+const gchar *       empathy_contact_get_id             (EmpathyContact      *contact);
+void                empathy_contact_set_id             (EmpathyContact      *contact,
+                                                       const gchar         *id);
+const gchar *       empathy_contact_get_name           (EmpathyContact      *contact);
+void                empathy_contact_set_name           (EmpathyContact      *contact,
+                                                       const gchar         *name);
+EmpathyAvatar *     empathy_contact_get_avatar         (EmpathyContact      *contact);
+void                empathy_contact_set_avatar         (EmpathyContact      *contact,
+                                                       EmpathyAvatar       *avatar);
+McAccount *         empathy_contact_get_account        (EmpathyContact      *contact);
+void                empathy_contact_set_account        (EmpathyContact      *contact,
+                                                       McAccount           *account);
+EmpathyPresence *   empathy_contact_get_presence       (EmpathyContact      *contact);
+void                empathy_contact_set_presence       (EmpathyContact      *contact,
+                                                       EmpathyPresence     *presence);
+guint               empathy_contact_get_handle         (EmpathyContact      *contact);
+void                empathy_contact_set_handle         (EmpathyContact      *contact,
+                                                       guint                handle);
+EmpathyCapabilities empathy_contact_get_capabilities   (EmpathyContact      *contact);
+void                empathy_contact_set_capabilities   (EmpathyContact      *contact,
+                                                       EmpathyCapabilities  capabilities);
+gboolean            empathy_contact_is_user            (EmpathyContact      *contact);
+void                empathy_contact_set_is_user        (EmpathyContact      *contact,
+                                                       gboolean             is_user);
+gboolean            empathy_contact_is_online          (EmpathyContact      *contact);
+const gchar *       empathy_contact_get_status         (EmpathyContact      *contact);
+gboolean            empathy_contact_equal              (gconstpointer        v1,
+                                                       gconstpointer        v2);
+guint               empathy_contact_hash               (gconstpointer        key);
 
 G_END_DECLS