diff options
author | Xavier Claessens <xavier.claessens@collabora.co.uk> | 2012-05-11 16:14:15 +0200 |
---|---|---|
committer | Xavier Claessens <xavier.claessens@collabora.co.uk> | 2012-05-11 16:30:37 +0200 |
commit | dacdc30b38a39ba2500ecfeb223bfb83e464340a (patch) | |
tree | 99d9c27a216a2fa1f3aa904381543367801c3439 | |
parent | 143b5ad6c4c9e17fff22652eaf93a45eb54b9596 (diff) |
_dup_contact_by_id_async() and _upgrade_contacts_async(): drop custom implementation
Simplify them by directly calling deprecated APIs, custom implementation
suffers the same problem with avatar than fixed in previous commit
-rw-r--r-- | telepathy-glib/contact.c | 280 |
1 files changed, 39 insertions, 241 deletions
diff --git a/telepathy-glib/contact.c b/telepathy-glib/contact.c index 9166888a8..64690f8bc 100644 --- a/telepathy-glib/contact.c +++ b/telepathy-glib/contact.c @@ -4573,38 +4573,6 @@ tp_connection_get_contacts_by_id (TpConnection *self, G_GNUC_END_IGNORE_DEPRECATIONS } -typedef struct -{ - GSimpleAsyncResult *result; - ContactFeatureFlags features; - - /* Used for fallback in tp_connection_dup_contact_by_id_async */ - gchar *id; - GArray *features_array; -} ContactsAsyncData; - -static ContactsAsyncData * -contacts_async_data_new (GSimpleAsyncResult *result, - ContactFeatureFlags features) -{ - ContactsAsyncData *data; - - data = g_slice_new0 (ContactsAsyncData); - data->result = g_object_ref (result); - data->features = features; - - return data; -} - -static void -contacts_async_data_free (ContactsAsyncData *data) -{ - g_object_unref (data->result); - g_free (data->id); - tp_clear_pointer (&data->features_array, g_array_unref); - g_slice_free (ContactsAsyncData, data); -} - static void got_contact_by_id_fallback_cb (TpConnection *self, guint n_contacts, @@ -4615,83 +4583,43 @@ got_contact_by_id_fallback_cb (TpConnection *self, gpointer user_data, GObject *weak_object) { - ContactsAsyncData *data = user_data; + const gchar *id = user_data; + GSimpleAsyncResult *result = (GSimpleAsyncResult *) weak_object; GError *e = NULL; if (error != NULL) { - g_simple_async_result_set_from_error (data->result, error); - g_simple_async_result_complete_in_idle (data->result); - return; + g_simple_async_result_set_from_error (result, error); } - if (g_hash_table_size (failed_id_errors) > 0) + else if (g_hash_table_size (failed_id_errors) > 0) { - e = g_hash_table_lookup (failed_id_errors, data->id); + e = g_hash_table_lookup (failed_id_errors, id); if (e == NULL) { g_set_error (&e, TP_DBUS_ERRORS, TP_DBUS_ERROR_INCONSISTENT, "We requested 1 id, and got an error for another id - Broken CM"); - g_simple_async_result_take_error (data->result, e); + g_simple_async_result_take_error (result, e); } else { - g_simple_async_result_set_from_error (data->result, e); + g_simple_async_result_set_from_error (result, e); } - - g_simple_async_result_complete_in_idle (data->result); - return; } - if (n_contacts != 1 || contacts[0] == NULL) + else if (n_contacts != 1 || contacts[0] == NULL) { g_set_error (&e, TP_DBUS_ERRORS, TP_DBUS_ERROR_INCONSISTENT, "We requested 1 id, but no contacts and no error - Broken CM"); - g_simple_async_result_take_error (data->result, e); - g_simple_async_result_complete_in_idle (data->result); - return; + g_simple_async_result_take_error (result, e); } - - g_simple_async_result_set_op_res_gpointer (data->result, - g_object_ref (contacts[0]), g_object_unref); - g_simple_async_result_complete (data->result); -} - -static void -got_contact_by_id_cb (TpConnection *self, - TpHandle handle, - GHashTable *attributes, - const GError *error, - gpointer user_data, - GObject *weak_object) -{ - ContactsAsyncData *data = user_data; - TpContact *contact; - GError *e = NULL; - - if (error != NULL) + else { - /* Retry the old way, for old CMs does that not exist in the real world */ - G_GNUC_BEGIN_IGNORE_DEPRECATIONS - tp_connection_get_contacts_by_id (self, 1, - (const gchar * const *) &data->id, - data->features_array->len, - (TpContactFeature *) data->features_array->data, - got_contact_by_id_fallback_cb, - data, (GDestroyNotify) contacts_async_data_free, NULL); - G_GNUC_END_IGNORE_DEPRECATIONS - return; + g_simple_async_result_set_op_res_gpointer (result, + g_object_ref (contacts[0]), g_object_unref); } - /* set up the contact with its attributes */ - contact = tp_contact_ensure (self, handle); - g_simple_async_result_set_op_res_gpointer (data->result, - contact, g_object_unref); - - if (!tp_contact_set_attributes (contact, attributes, data->features, &e)) - g_simple_async_result_take_error (data->result, e); - - g_simple_async_result_complete (data->result); - contacts_async_data_free (data); + g_simple_async_result_complete_in_idle (result); + g_object_unref (result); } /** @@ -4727,55 +4655,18 @@ tp_connection_dup_contact_by_id_async (TpConnection *self, GAsyncReadyCallback callback, gpointer user_data) { - ContactsAsyncData *data; GSimpleAsyncResult *result; - ContactFeatureFlags feature_flags = 0; - const gchar **supported_interfaces; - - g_return_if_fail (tp_proxy_is_prepared (self, - TP_CONNECTION_FEATURE_CONNECTED)); - g_return_if_fail (id != NULL); - g_return_if_fail (n_features == 0 || features != NULL); - - if (!get_feature_flags (n_features, features, &feature_flags)) - return; result = g_simple_async_result_new ((GObject *) self, callback, user_data, tp_connection_dup_contact_by_id_async); - data = contacts_async_data_new (result, feature_flags); - data->id = g_strdup (id); - data->features_array = g_array_sized_new (FALSE, FALSE, - sizeof (TpContactFeature), n_features); - g_array_append_vals (data->features_array, features, n_features); - - if (tp_proxy_has_interface_by_id (self, - TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACTS)) - { - supported_interfaces = contacts_bind_to_signals (self, feature_flags); - - tp_cli_connection_interface_contacts_call_get_contact_by_id (self, -1, - id, supported_interfaces, got_contact_by_id_cb, - data, NULL, NULL); - - g_free (supported_interfaces); - } - else - { - /* Proceed directly to the slow path, do not pass Go, do not collect - * £200. contacts_bind_to_signals() relies on having Contacts. */ - - G_GNUC_BEGIN_IGNORE_DEPRECATIONS - tp_connection_get_contacts_by_id (self, 1, - (const gchar * const *) &data->id, - data->features_array->len, - (TpContactFeature *) data->features_array->data, - got_contact_by_id_fallback_cb, - data, (GDestroyNotify) contacts_async_data_free, NULL); - G_GNUC_END_IGNORE_DEPRECATIONS - } - - g_object_unref (result); + G_GNUC_BEGIN_IGNORE_DEPRECATIONS + tp_connection_get_contacts_by_id (self, + 1, &id, + n_features, features, + got_contact_by_id_fallback_cb, + g_strdup (id), g_free, G_OBJECT (result)); + G_GNUC_END_IGNORE_DEPRECATIONS } /** @@ -4799,41 +4690,7 @@ tp_connection_dup_contact_by_id_finish (TpConnection *self, } static void -got_contact_attributes_cb (TpConnection *self, - GHashTable *attributes, - const GError *error, - gpointer user_data, - GObject *weak_object) -{ - ContactsAsyncData *data = user_data; - GHashTableIter iter; - gpointer key, value; - - if (error != NULL) - { - g_simple_async_result_set_from_error (data->result, error); - g_simple_async_result_complete_in_idle (data->result); - return; - } - - g_hash_table_iter_init (&iter, attributes); - while (g_hash_table_iter_next (&iter, &key, &value)) - { - TpHandle handle = GPOINTER_TO_UINT (key); - GHashTable *asv = value; - TpContact *contact; - - /* set up the contact with its attributes */ - contact = tp_contact_ensure (self, handle); - tp_contact_set_attributes (contact, asv, data->features, NULL); - g_object_unref (contact); - } - - g_simple_async_result_complete (data->result); -} - -static void -upgrade_contacts_async_fallback_cb (TpConnection *self, +upgrade_contacts_fallback_cb (TpConnection *connection, guint n_contacts, TpContact * const *contacts, const GError *error, @@ -4841,11 +4698,20 @@ upgrade_contacts_async_fallback_cb (TpConnection *self, GObject *weak_object) { GSimpleAsyncResult *result = user_data; + GPtrArray *contacts_array; + guint i; + + contacts_array = g_ptr_array_new_full (n_contacts, g_object_unref); + for (i = 0; i < n_contacts; i++) + g_ptr_array_add (contacts_array, g_object_ref (contacts[i])); + + g_simple_async_result_set_op_res_gpointer (result, contacts_array, + (GDestroyNotify) g_ptr_array_unref); if (error != NULL) g_simple_async_result_set_from_error (result, error); - g_simple_async_result_complete (result); + g_simple_async_result_complete_in_idle (result); } /** @@ -4881,86 +4747,18 @@ tp_connection_upgrade_contacts_async (TpConnection *self, GAsyncReadyCallback callback, gpointer user_data) { - ContactsAsyncData *data; GSimpleAsyncResult *result; - ContactFeatureFlags feature_flags = 0; - guint minimal_feature_flags = G_MAXUINT; - const gchar **supported_interfaces; - GPtrArray *contacts_array; - GArray *handles; - guint i; - - g_return_if_fail (tp_proxy_is_prepared (self, - TP_CONNECTION_FEATURE_CONNECTED)); - g_return_if_fail (n_contacts >= 1); - g_return_if_fail (contacts != NULL); - g_return_if_fail (n_features == 0 || features != NULL); - - for (i = 0; i < n_contacts; i++) - { - g_return_if_fail (contacts[i]->priv->connection == self); - g_return_if_fail (contacts[i]->priv->identifier != NULL); - } - - if (!get_feature_flags (n_features, features, &feature_flags)) - return; - - handles = g_array_sized_new (FALSE, FALSE, sizeof (TpHandle), n_contacts); - contacts_array = g_ptr_array_new_full (n_contacts, g_object_unref); - for (i = 0; i < n_contacts; i++) - { - /* feature flags that all contacts have */ - minimal_feature_flags &= contacts[i]->priv->has_features; - - /* Keep handles of contacts that does not already have all features */ - if ((feature_flags & (~contacts[i]->priv->has_features)) != 0) - g_array_append_val (handles, contacts[i]->priv->handle); - - /* Keep a ref on all contacts to ensure they do not disappear - * while upgrading them */ - g_ptr_array_add (contacts_array, g_object_ref (contacts[i])); - } - - /* Remove features that all contacts have */ - feature_flags &= (~minimal_feature_flags); result = g_simple_async_result_new ((GObject *) self, callback, user_data, tp_connection_upgrade_contacts_async); - g_simple_async_result_set_op_res_gpointer (result, contacts_array, - (GDestroyNotify) g_ptr_array_unref); - - if (tp_proxy_has_interface_by_id (self, - TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACTS)) - { - supported_interfaces = contacts_bind_to_signals (self, feature_flags); - - if (handles->len > 0 && supported_interfaces[0] != NULL) - { - data = contacts_async_data_new (result, feature_flags); - tp_cli_connection_interface_contacts_call_get_contact_attributes ( - self, -1, handles, supported_interfaces, TRUE, - got_contact_attributes_cb, data, - (GDestroyNotify) contacts_async_data_free, NULL); - } - else - { - g_simple_async_result_complete_in_idle (result); - } - - g_free (supported_interfaces); - } - else - { - G_GNUC_BEGIN_IGNORE_DEPRECATIONS - tp_connection_upgrade_contacts (self, n_contacts, contacts, n_features, - features, upgrade_contacts_async_fallback_cb, - g_object_ref (result), g_object_unref, NULL); - G_GNUC_END_IGNORE_DEPRECATIONS - } - - g_object_unref (result); - g_array_unref (handles); + G_GNUC_BEGIN_IGNORE_DEPRECATIONS + tp_connection_upgrade_contacts (self, + n_contacts, contacts, + n_features, features, + upgrade_contacts_fallback_cb, + result, g_object_unref, NULL); + G_GNUC_END_IGNORE_DEPRECATIONS } /** |