From 1bcea5378f204f29b08a3b4d031c90459b414a4a Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Tue, 8 May 2012 18:44:52 +0200 Subject: Examples: do not use soon to be deprecated APIs --- examples/client/extended-client.c | 48 +++++++-------------- examples/client/inspect-contact.c | 91 ++++++++++++++++----------------------- 2 files changed, 54 insertions(+), 85 deletions(-) (limited to 'examples') diff --git a/examples/client/extended-client.c b/examples/client/extended-client.c index 724ff2c35..9231c0bf4 100644 --- a/examples/client/extended-client.c +++ b/examples/client/extended-client.c @@ -119,36 +119,25 @@ contact_pair_free (gpointer p) } static void -contacts_ready_cb (TpConnection *conn, - guint n_contacts, - TpContact * const *contacts, - const gchar * const *requested_ids, - GHashTable *failed_id_errors, - const GError *general_error, - gpointer user_data, - GObject *weak_object) +contact_ready_cb (GObject *object, + GAsyncResult *result, + gpointer user_data) { - GHashTableIter iter; - gpointer k, v; + TpConnection *conn = (TpConnection *) object; GHashTable *asv; ContactPair *pair; + GError *error = NULL; - /* This runs if tp_connection_get_contacts_by_id failed completely (e.g. - * the CM crashed) */ - if (die_if (general_error, "tp_connection_get_contacts_by_id()")) - return; - - /* If any making a TpContact for one of the requested IDs fails, they'll - * be present in this hash table with an error as value */ - g_hash_table_iter_init (&iter, failed_id_errors); + pair = g_slice_new0 (ContactPair); + pair->contacts[0] = tp_connection_dup_contact_by_id_finish (conn, + result, &error); + pair->contacts[1] = g_object_ref (tp_connection_get_self_contact (conn)); - while (g_hash_table_iter_next (&iter, &k, &v)) + if (die_if (error, "tp_connection_dup_contact_by_id_async()")) { - const gchar *failed_id = k; - const GError *contact_error = v; - - if (die_if (contact_error, failed_id)) - return; + g_clear_error (&error); + contact_pair_free (pair); + return; } asv = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, @@ -156,10 +145,6 @@ contacts_ready_cb (TpConnection *conn, g_hash_table_insert (asv, "previous-owner", tp_g_value_slice_new_static_string ("Shadowman")); - pair = g_slice_new0 (ContactPair); - pair->contacts[0] = g_object_ref (contacts[0]); - pair->contacts[1] = g_object_ref (contacts[1]); - example_cli_connection_interface_hats_call_set_hat (conn, -1, "red", EXAMPLE_HAT_STYLE_FEDORA, asv, set_hat_cb, pair, contact_pair_free, NULL); @@ -173,7 +158,6 @@ conn_ready (GObject *source, gpointer user_data) { GError *error = NULL; - static const gchar * const names[] = { "myself@server", "other@server" }; TpConnection *conn = TP_CONNECTION (source); if (!tp_proxy_prepare_finish (conn, result, &error)) @@ -192,9 +176,9 @@ conn_ready (GObject *source, return; } - /* Get contact objects for myself and someone else */ - tp_connection_get_contacts_by_id (conn, 2, names, 0, NULL, - contacts_ready_cb, NULL, NULL, NULL); + /* Get contact object for someone else */ + tp_connection_dup_contact_by_id_async (conn, "other@server", 0, NULL, + contact_ready_cb, NULL); } static void diff --git a/examples/client/inspect-contact.c b/examples/client/inspect-contact.c index 7c759bffa..2b79da08a 100644 --- a/examples/client/inspect-contact.c +++ b/examples/client/inspect-contact.c @@ -44,75 +44,62 @@ display_contact (TpContact *contact) } static void -contacts_upgraded_cb (TpConnection *connection, - guint n_contacts, - TpContact * const *contacts, - const GError *error, - gpointer user_data, - GObject *weak_object) +contacts_upgraded_cb (GObject *object, + GAsyncResult *result, + gpointer user_data) { + TpConnection *connection = (TpConnection *) object; InspectContactData *data = user_data; + GPtrArray *contacts; + GError *error = NULL; - if (error == NULL) + if (!tp_connection_upgrade_contacts_finish (connection, result, + &contacts, &error)) + { + g_warning ("Error getting contacts: %s", error->message); + data->exit_status = 1; + g_clear_error (&error); + } + else { guint i; data->exit_status = 0; - for (i = 0; i < n_contacts; i++) + for (i = 0; i < contacts->len; i++) { - display_contact (contacts[i]); + display_contact (g_ptr_array_index (contacts, i)); } - } - else - { - g_warning ("Error getting contacts: %s", error->message); - data->exit_status = 1; + g_ptr_array_unref (contacts); } g_main_loop_quit (data->main_loop); } static void -got_contacts_by_id (TpConnection *connection, - guint n_contacts, - TpContact * const *contacts, - const gchar * const *good_ids, - GHashTable *bad_ids, - const GError *error, - gpointer user_data, - GObject *weak_object) +got_contacts_by_id (GObject *object, + GAsyncResult *result, + gpointer user_data) { + TpConnection *connection = (TpConnection *) object; InspectContactData *data = user_data; + TpContact *contact; + GError *error = NULL; - if (error == NULL) - { - guint i; - GHashTableIter hash_iter; - gpointer key, value; - - data->exit_status = 0; - - for (i = 0; i < n_contacts; i++) - { - display_contact (contacts[i]); - } - - g_hash_table_iter_init (&hash_iter, bad_ids); - - while (g_hash_table_iter_next (&hash_iter, &key, &value)) - { - gchar *id = key; - GError *e = value; + contact = tp_connection_dup_contact_by_id_finish (connection, result, &error); - g_warning ("Invalid ID \"%s\": %s", id, e->message); - data->exit_status = 1; - } - } - else + if (contact == NULL) { g_warning ("Error getting contacts: %s", error->message); data->exit_status = 1; + g_clear_error (&error); + } + else + { + data->exit_status = 0; + + display_contact (contact); + g_object_unref (contact); } g_main_loop_quit (data->main_loop); @@ -145,21 +132,19 @@ connection_ready_cb (GObject *source, { TpContact *self_contact = tp_connection_get_self_contact (connection); - tp_connection_upgrade_contacts (connection, + tp_connection_upgrade_contacts_async (connection, 1, &self_contact, G_N_ELEMENTS (features), features, contacts_upgraded_cb, - data, NULL, NULL); + data); } else { - const gchar *contacts[] = { data->to_inspect, NULL }; - - tp_connection_get_contacts_by_id (connection, - 1, contacts, + tp_connection_dup_contact_by_id_async (connection, + data->to_inspect, G_N_ELEMENTS (features), features, got_contacts_by_id, - data, NULL, NULL); + data); } } -- cgit v1.2.1