diff options
author | Xavier Claessens <xclaesse@gmail.com> | 2007-09-09 03:15:34 +0800 |
---|---|---|
committer | Xavier Claessens <xclaesse@src.gnome.org> | 2007-09-09 03:15:34 +0800 |
commit | d3e46f8c3570d2486eeab6255899daaaf308b036 (patch) | |
tree | bac0e9570e62a84efa9dbc317976f5a8fadb63b2 /libempathy | |
parent | c84cf8d5e36241d2ccb48589496f4d54752a5c54 (diff) | |
download | gsoc2013-empathy-d3e46f8c3570d2486eeab6255899daaaf308b036.tar gsoc2013-empathy-d3e46f8c3570d2486eeab6255899daaaf308b036.tar.gz gsoc2013-empathy-d3e46f8c3570d2486eeab6255899daaaf308b036.tar.bz2 gsoc2013-empathy-d3e46f8c3570d2486eeab6255899daaaf308b036.tar.lz gsoc2013-empathy-d3e46f8c3570d2486eeab6255899daaaf308b036.tar.xz gsoc2013-empathy-d3e46f8c3570d2486eeab6255899daaaf308b036.tar.zst gsoc2013-empathy-d3e46f8c3570d2486eeab6255899daaaf308b036.zip |
Adding capabilities contact property.
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
Diffstat (limited to 'libempathy')
-rw-r--r-- | libempathy/empathy-contact-factory.c | 132 | ||||
-rw-r--r-- | libempathy/empathy-contact.c | 50 | ||||
-rw-r--r-- | libempathy/empathy-contact.h | 70 |
3 files changed, 221 insertions, 31 deletions
diff --git a/libempathy/empathy-contact-factory.c b/libempathy/empathy-contact-factory.c index 96211ae47..b4b3ba668 100644 --- a/libempathy/empathy-contact-factory.c +++ b/libempathy/empathy-contact-factory.c @@ -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; @@ -376,6 +378,112 @@ contact_factory_avatar_retrieved_cb (DBusGProxy *proxy, } 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 diff --git a/libempathy/empathy-contact.c b/libempathy/empathy-contact.c index 505e190c0..221b06e17 100644 --- a/libempathy/empathy-contact.c +++ b/libempathy/empathy-contact.c @@ -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) { diff --git a/libempathy/empathy-contact.h b/libempathy/empathy-contact.h index 87a26f0dd..d062885bc 100644 --- a/libempathy/empathy-contact.h +++ b/libempathy/empathy-contact.h @@ -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 |