From 3f1c850efc2ecc7bb37c2e0d42b6067a4113bbdb Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 19 Sep 2012 12:52:43 +0100 Subject: [PATCH 09/15] tp_account_channel_request_dup_request, request-vardict property: add Signed-off-by: Simon McVittie Bug: https://bugs.freedesktop.org/show_bug.cgi?id=55099 --- docs/reference/telepathy-glib-sections.txt | 1 + telepathy-glib/account-channel-request.c | 89 ++++++++++++++++++++++++++-- telepathy-glib/account-channel-request.h | 3 + tests/dbus/account-channel-request.c | 21 +++++++ 4 files changed, 108 insertions(+), 6 deletions(-) diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt index 5ae79c3..e20651a 100644 --- a/docs/reference/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib-sections.txt @@ -6167,6 +6167,7 @@ TpAccountChannelRequest tp_account_channel_request_new tp_account_channel_request_new_vardict tp_account_channel_request_get_request +tp_account_channel_request_dup_request tp_account_channel_request_get_user_action_time tp_account_channel_request_get_account tp_account_channel_request_set_target_contact diff --git a/telepathy-glib/account-channel-request.c b/telepathy-glib/account-channel-request.c index 59cd1e3..2a9c981 100644 --- a/telepathy-glib/account-channel-request.c +++ b/telepathy-glib/account-channel-request.c @@ -110,6 +110,7 @@ G_DEFINE_TYPE(TpAccountChannelRequest, enum { PROP_ACCOUNT = 1, PROP_REQUEST, + PROP_REQUEST_VARDICT, PROP_USER_ACTION_TIME, PROP_CHANNEL_REQUEST, N_PROPS @@ -244,6 +245,11 @@ tp_account_channel_request_get_property (GObject *object, g_value_set_boxed (value, self->priv->request); break; + case PROP_REQUEST_VARDICT: + g_value_take_variant (value, + tp_account_channel_request_dup_request (self)); + break; + case PROP_USER_ACTION_TIME: g_value_set_int64 (value, self->priv->user_action_time); break; @@ -274,6 +280,14 @@ tp_account_channel_request_set_property (GObject *object, break; case PROP_REQUEST: + /* If this property remains unset, GObject will set it to a NULL + * value. Ignore that, so request-vardict can be set instead. */ + if (g_value_get_boxed (value) == NULL) + return; + + /* Construct-only and mutually exclusive with request-vardict */ + g_return_if_fail (self->priv->request == NULL); + /* We do not use tp_asv_new() and friends, because in principle, * the request can contain user-defined keys. */ self->priv->request = g_hash_table_new_full (g_str_hash, g_str_equal, @@ -284,6 +298,29 @@ tp_account_channel_request_set_property (GObject *object, (GBoxedCopyFunc) tp_g_value_slice_dup); break; + case PROP_REQUEST_VARDICT: + { + GHashTable *hash; + + /* If this property remains unset, GObject will set it to a NULL + * value. Ignore that, so request can be set instead. */ + if (g_value_get_variant (value) == NULL) + return; + + /* Construct-only and mutually exclusive with request */ + g_return_if_fail (self->priv->request == NULL); + + hash = _tp_asv_from_vardict (g_value_get_variant (value)); + self->priv->request = g_hash_table_new_full (g_str_hash, + g_str_equal, g_free, (GDestroyNotify) tp_g_value_slice_free); + + tp_g_hash_table_update (self->priv->request, + hash, (GBoxedCopyFunc) g_strdup, + (GBoxedCopyFunc) tp_g_value_slice_dup); + g_hash_table_unref (hash); + } + break; + case PROP_USER_ACTION_TIME: self->priv->user_action_time = g_value_get_int64 (value); break; @@ -350,7 +387,10 @@ tp_account_channel_request_class_init ( * The desired D-Bus properties for the channel, represented as a * #GHashTable where the keys are strings and the values are #GValue. * - * This property can't be %NULL. + * When constructing a new object, one of + * #TpAccountChannelRequest:request or + * #TpAccountChannelRequest:request-vardict must be set to a non-%NULL + * value, and the other must remain unspecified. * * Since: 0.11.12 */ @@ -362,6 +402,25 @@ tp_account_channel_request_class_init ( param_spec); /** + * TpAccountChannelRequest:request-vardict: + * + * The desired D-Bus properties for the channel. + * + * When constructing a new object, one of + * #TpAccountChannelRequest:request or + * #TpAccountChannelRequest:request-vardict must be set to a non-%NULL + * value, and the other must remain unspecified. + * + * Since: 0.UNRELEASED + */ + param_spec = g_param_spec_variant ("request-vardict", "Request", + "A dictionary containing desirable properties for the channel", + G_VARIANT_TYPE_VARDICT, NULL, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, PROP_REQUEST_VARDICT, + param_spec); + + /** * TpAccountChannelRequest:user-action-time: * * The user action time that will be passed to the channel dispatcher when @@ -519,7 +578,6 @@ tp_account_channel_request_new_vardict ( GVariant *request, gint64 user_action_time) { - GHashTable *hash; TpAccountChannelRequest *ret; g_return_val_if_fail (TP_IS_ACCOUNT (account), NULL); @@ -528,15 +586,13 @@ tp_account_channel_request_new_vardict ( NULL); g_variant_ref_sink (request); - hash = _tp_asv_from_vardict (request); - g_variant_unref (request); ret = g_object_new (TP_TYPE_ACCOUNT_CHANNEL_REQUEST, "account", account, - "request", hash, + "request-vardict", request, "user-action-time", user_action_time, NULL); - g_hash_table_unref (hash); + g_variant_unref (request); return ret; } @@ -575,6 +631,27 @@ tp_account_channel_request_get_request ( } /** + * tp_account_channel_request_dup_request: + * @self: a #TpAccountChannelRequest + * + * Return the #TpAccountChannelRequest:request-vardict construct-only + * property. + * + * Returns: (transfer full): the value of + * #TpAccountChannelRequest:request-vardict + * + * Since: 0.11.12 + */ +GVariant * +tp_account_channel_request_dup_request ( + TpAccountChannelRequest *self) +{ + g_return_val_if_fail (TP_IS_ACCOUNT_CHANNEL_REQUEST (self), NULL); + + return _tp_asv_to_vardict (self->priv->request); +} + +/** * tp_account_channel_request_get_user_action_time: * @self: a #TpAccountChannelRequest * diff --git a/telepathy-glib/account-channel-request.h b/telepathy-glib/account-channel-request.h index fe0b102..416c937 100644 --- a/telepathy-glib/account-channel-request.h +++ b/telepathy-glib/account-channel-request.h @@ -77,6 +77,9 @@ TpAccount * tp_account_channel_request_get_account ( GHashTable * tp_account_channel_request_get_request ( TpAccountChannelRequest *self); +_TP_AVAILABLE_IN_UNRELEASED +GVariant *tp_account_channel_request_dup_request ( + TpAccountChannelRequest *self); gint64 tp_account_channel_request_get_user_action_time ( TpAccountChannelRequest *self); diff --git a/tests/dbus/account-channel-request.c b/tests/dbus/account-channel-request.c index 895f1b8..0de180b 100644 --- a/tests/dbus/account-channel-request.c +++ b/tests/dbus/account-channel-request.c @@ -447,6 +447,8 @@ test_handle_ensure_success (Test *test, { TpAccountChannelRequest *req; TpContact *alice; + GHashTable *asv; + GVariant *vardict; alice = tp_tests_connection_run_until_contact_by_id (test->connection, "alice", 0, NULL); @@ -454,6 +456,25 @@ test_handle_ensure_success (Test *test, req = tp_account_channel_request_new_text (test->account, 0); tp_account_channel_request_set_target_contact (req, alice); + asv = (GHashTable *) tp_account_channel_request_get_request (req); + vardict = tp_account_channel_request_dup_request (req); + g_assert_cmpstr (tp_asv_get_string (asv, + TP_PROP_CHANNEL_TARGET_ID), ==, "alice"); + g_assert_cmpstr (tp_vardict_get_string (vardict, + TP_PROP_CHANNEL_TARGET_ID), ==, "alice"); + g_variant_unref (vardict); + + g_object_get (req, + "request", &asv, + "request-vardict", &vardict, + NULL); + g_assert_cmpstr (tp_asv_get_string (asv, + TP_PROP_CHANNEL_TARGET_ID), ==, "alice"); + g_assert_cmpstr (tp_vardict_get_string (vardict, + TP_PROP_CHANNEL_TARGET_ID), ==, "alice"); + g_hash_table_unref (asv); + g_variant_unref (vardict); + tp_account_channel_request_ensure_and_handle_channel_async (req, NULL, ensure_and_handle_cb, test); -- 1.7.10.4