diff options
author | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2011-10-19 13:41:15 +0200 |
---|---|---|
committer | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2011-10-31 17:12:30 +0100 |
commit | 99faf245247dfd32ac21460b6e063655cdae2e60 (patch) | |
tree | 70eb7720d083da18f7ace5ad59a10f98fdf6cadd | |
parent | b6b7882ef113588583d32bd0a201e00d80ff3f6a (diff) |
add TpConnection:blocked-contacts property
https://bugs.freedesktop.org/show_bug.cgi?id=41801
-rw-r--r-- | docs/reference/telepathy-glib-sections.txt | 1 | ||||
-rw-r--r-- | telepathy-glib/connection-contact-list.c | 112 | ||||
-rw-r--r-- | telepathy-glib/connection-contact-list.h | 2 | ||||
-rw-r--r-- | telepathy-glib/connection-internal.h | 1 | ||||
-rw-r--r-- | telepathy-glib/connection.c | 28 | ||||
-rw-r--r-- | tests/dbus/contact-list-clt.c | 34 |
6 files changed, 176 insertions, 2 deletions
diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt index d1ab923e..92764efa 100644 --- a/docs/reference/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib-sections.txt @@ -3724,6 +3724,7 @@ tp_connection_block_contacts_finish tp_connection_unblock_contacts_async tp_connection_unblock_contacts_finish tp_connection_can_report_abusive +tp_connection_get_blocked_contacts <SUBSECTION> tp_cli_connection_callback_for_connect tp_cli_connection_call_connect diff --git a/telepathy-glib/connection-contact-list.c b/telepathy-glib/connection-contact-list.c index 707aa6b3..3363af19 100644 --- a/telepathy-glib/connection-contact-list.c +++ b/telepathy-glib/connection-contact-list.c @@ -1535,6 +1535,96 @@ tp_connection_get_feature_quark_contact_blocking (void) } static void +blocked_contacts_upgraded_cb (TpConnection *self, + guint n_contacts, + TpContact * const *contacts, + const GError *error, + gpointer user_data, + GObject *weak_object) +{ + GSimpleAsyncResult *result = user_data; + guint i; + + if (error != NULL) + { + DEBUG ("Error upgrading blocked contacts: %s", error->message); + goto out; + } + + for (i = 0; i < n_contacts; i++) + { + g_ptr_array_add (self->priv->blocked_contacts, + g_object_ref (contacts[i])); + } + + g_object_notify (G_OBJECT (self), "blocked-contacts"); + +out: + g_simple_async_result_complete (result); +} + +static void +request_blocked_contacts_cb (TpConnection *self, + GHashTable *contacts, + const GError *error, + gpointer user_data, + GObject *weak_object) +{ + GSimpleAsyncResult *result = user_data; + GHashTableIter iter; + gpointer key, value; + GPtrArray *contacts_arr; + GArray *features; + + if (error != NULL) + { + DEBUG ("Error calling RequestBlockedContacts: %s", error->message); + g_simple_async_result_set_from_error (result, error); + g_simple_async_result_complete (result); + return; + } + + contacts_arr = g_ptr_array_new_with_free_func (g_object_unref); + + g_hash_table_iter_init (&iter, contacts); + while (g_hash_table_iter_next (&iter, &key, &value)) + { + TpHandle handle = GPOINTER_TO_UINT (key); + const gchar *id = value; + TpContact *contact; + + contact = tp_connection_dup_contact_if_possible (self, handle, id); + if (contact == NULL) + { + DEBUG ("Failed to create contact %s (%d)", id, handle); + continue; + } + + g_ptr_array_add (contacts_arr, contact); + } + + if (contacts_arr->len == 0) + { + /* No blocked contacts, we're done */ + g_simple_async_result_complete (result); + g_ptr_array_unref (contacts_arr); + return; + } + + features = tp_simple_client_factory_dup_contact_features ( + tp_proxy_get_factory (self), self); + + tp_connection_upgrade_contacts (self, + contacts_arr->len, (TpContact **) contacts_arr->pdata, + features->len, (TpContactFeature *) features->data, + blocked_contacts_upgraded_cb, + g_object_ref (result), g_object_unref, G_OBJECT (self)); + + g_array_unref (features); + g_ptr_array_unref (contacts_arr); +} + +static void prepare_contact_blocking_cb (TpProxy *proxy, GHashTable *properties, const GError *error, @@ -1548,7 +1638,6 @@ prepare_contact_blocking_cb (TpProxy *proxy, if (error != NULL) { DEBUG ("Error preparing ContactBlocking properties: %s", error->message); - g_simple_async_result_set_from_error (result, error); goto out; } @@ -1561,7 +1650,9 @@ prepare_contact_blocking_cb (TpProxy *proxy, } out: - g_simple_async_result_complete (result); + tp_cli_connection_interface_contact_blocking_call_request_blocked_contacts ( + self, -1, request_blocked_contacts_cb, g_object_ref (result), + g_object_unref, G_OBJECT (self)); } void @@ -1597,3 +1688,20 @@ tp_connection_can_report_abusive (TpConnection *self) return (self->priv->contact_blocking_capabilities & TP_CONTACT_BLOCKING_CAPABILITY_CAN_REPORT_ABUSIVE) != 0; } + +/** + * tp_connection_get_blocked_contacts: + * @self: a #TpConnection + * + * <!-- --> + * + * Returns: (transfer none) (element-type TelepathyGLib.Contact): the value of + * #TpConnection:blocked-contacts + * + * Since: 0.UNRELEASED + */ +GPtrArray * +tp_connection_get_blocked_contacts (TpConnection *self) +{ + return self->priv->blocked_contacts; +} diff --git a/telepathy-glib/connection-contact-list.h b/telepathy-glib/connection-contact-list.h index 37e21f83..d04ba45b 100644 --- a/telepathy-glib/connection-contact-list.h +++ b/telepathy-glib/connection-contact-list.h @@ -165,6 +165,8 @@ GQuark tp_connection_get_feature_quark_contact_blocking (void) G_GNUC_CONST; gboolean tp_connection_can_report_abusive (TpConnection *self); +GPtrArray * tp_connection_get_blocked_contacts (TpConnection *self); + G_END_DECLS #endif diff --git a/telepathy-glib/connection-internal.h b/telepathy-glib/connection-internal.h index 164d4ccb..04648df7 100644 --- a/telepathy-glib/connection-internal.h +++ b/telepathy-glib/connection-internal.h @@ -95,6 +95,7 @@ struct _TpConnectionPrivate { /* ContactBlocking properies */ TpContactBlockingCapabilities contact_blocking_capabilities; + GPtrArray *blocked_contacts; TpProxyPendingCall *introspection_call; diff --git a/telepathy-glib/connection.c b/telepathy-glib/connection.c index f866f238..46ed3275 100644 --- a/telepathy-glib/connection.c +++ b/telepathy-glib/connection.c @@ -282,6 +282,7 @@ enum PROP_GROUP_STORAGE, PROP_CONTACT_GROUPS, PROP_CAN_REPORT_ABUSIVE, + PROP_BLOCKED_CONTACTS, N_PROPS }; @@ -370,6 +371,9 @@ tp_connection_get_property (GObject *object, case PROP_CAN_REPORT_ABUSIVE: g_value_set_boolean (value, tp_connection_can_report_abusive (self)); break; + case PROP_BLOCKED_CONTACTS: + g_value_set_boxed (value, tp_connection_get_blocked_contacts (self)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -1457,6 +1461,9 @@ tp_connection_init (TpConnection *self) self->priv->contacts_changed_queue = g_queue_new (); g_queue_init (&self->priv->capabilities_queue); + + self->priv->blocked_contacts = g_ptr_array_new_with_free_func ( + g_object_unref); } static void @@ -1583,6 +1590,8 @@ tp_connection_dispose (GObject *object) self->priv->interests = NULL; } + tp_clear_pointer (&self->priv->blocked_contacts, g_ptr_array_unref); + ((GObjectClass *) tp_connection_parent_class)->dispose (object); } @@ -2101,6 +2110,25 @@ tp_connection_class_init (TpConnectionClass *klass) param_spec); /** + * TpConnection:blocked-contacts: + * + * A #GPtrArray of blocked #TpContact. + * + * For this property to be valid, you must first call + * tp_proxy_prepare_async() with the feature + * %TP_CONNECTION_FEATURE_CONTACT_BLOCKING. + * + * Since: 0.UNRELEASED + */ + param_spec = g_param_spec_boxed ("blocked-contacts", + "blocked contacts", + "Blocked contacts", + G_TYPE_PTR_ARRAY, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, PROP_BLOCKED_CONTACTS, + param_spec); + + /** * TpConnection::groups-created: * @self: a #TpConnection * @added: a #GStrv with the names of the new groups. diff --git a/tests/dbus/contact-list-clt.c b/tests/dbus/contact-list-clt.c index 24c835de..2bf6926e 100644 --- a/tests/dbus/contact-list-clt.c +++ b/tests/dbus/contact-list-clt.c @@ -212,6 +212,38 @@ test_can_report_abusive (Test *test, g_assert (tp_connection_can_report_abusive (test->connection)); } +static void +test_blocked_contacts (Test *test, + gconstpointer data G_GNUC_UNUSED) +{ + GQuark features[] = { TP_CONNECTION_FEATURE_CONTACT_BLOCKING, 0 }; + GPtrArray *blocked; + + /* Feature is not prepared yet */ + g_object_get (test->connection, "blocked-contacts", &blocked, NULL); + g_assert_cmpuint (blocked->len, == , 0); + g_ptr_array_unref (blocked); + + blocked = tp_connection_get_blocked_contacts (test->connection); + g_assert_cmpuint (blocked->len, == , 0); + + /* Prepare the feature */ + tp_proxy_prepare_async (test->connection, features, + proxy_prepare_cb, test); + + test->wait = 1; + g_main_loop_run (test->mainloop); + g_assert_no_error (test->error); + + /* 2 contacts are already blocked in the CM */ + g_object_get (test->connection, "blocked-contacts", &blocked, NULL); + g_assert_cmpuint (blocked->len, == , 2); + g_ptr_array_unref (blocked); + + blocked = tp_connection_get_blocked_contacts (test->connection); + g_assert_cmpuint (blocked->len, == , 2); +} + int main (int argc, char **argv) @@ -223,6 +255,8 @@ main (int argc, test_block_unblock, teardown); g_test_add ("/contact-list-clt/blocking/can-report-abusive", Test, NULL, setup, test_can_report_abusive, teardown); + g_test_add ("/contact-list-clt/blocking/blocked-contacts", Test, NULL, + setup, test_blocked_contacts, teardown); return g_test_run (); } |