Codebase list telepathy-glib / b4012b9
tp_account_channel_request_dup_request, request-vardict property: add Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk> Bug: https://bugs.freedesktop.org/show_bug.cgi?id=55099 Simon McVittie authored 11 years ago Guillaume Desmottes committed 11 years ago
4 changed file(s) with 108 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
61716171 tp_account_channel_request_new
61726172 tp_account_channel_request_new_vardict
61736173 tp_account_channel_request_get_request
6174 tp_account_channel_request_dup_request
61746175 tp_account_channel_request_get_user_action_time
61756176 tp_account_channel_request_get_account
61766177 tp_account_channel_request_set_target_contact
109109 enum {
110110 PROP_ACCOUNT = 1,
111111 PROP_REQUEST,
112 PROP_REQUEST_VARDICT,
112113 PROP_USER_ACTION_TIME,
113114 PROP_CHANNEL_REQUEST,
114115 N_PROPS
243244 g_value_set_boxed (value, self->priv->request);
244245 break;
245246
247 case PROP_REQUEST_VARDICT:
248 g_value_take_variant (value,
249 tp_account_channel_request_dup_request (self));
250 break;
251
246252 case PROP_USER_ACTION_TIME:
247253 g_value_set_int64 (value, self->priv->user_action_time);
248254 break;
273279 break;
274280
275281 case PROP_REQUEST:
282 /* If this property remains unset, GObject will set it to a NULL
283 * value. Ignore that, so request-vardict can be set instead. */
284 if (g_value_get_boxed (value) == NULL)
285 return;
286
287 /* Construct-only and mutually exclusive with request-vardict */
288 g_return_if_fail (self->priv->request == NULL);
289
276290 /* We do not use tp_asv_new() and friends, because in principle,
277291 * the request can contain user-defined keys. */
278292 self->priv->request = g_hash_table_new_full (g_str_hash, g_str_equal,
283297 (GBoxedCopyFunc) tp_g_value_slice_dup);
284298 break;
285299
300 case PROP_REQUEST_VARDICT:
301 {
302 GHashTable *hash;
303
304 /* If this property remains unset, GObject will set it to a NULL
305 * value. Ignore that, so request can be set instead. */
306 if (g_value_get_variant (value) == NULL)
307 return;
308
309 /* Construct-only and mutually exclusive with request */
310 g_return_if_fail (self->priv->request == NULL);
311
312 hash = _tp_asv_from_vardict (g_value_get_variant (value));
313 self->priv->request = g_hash_table_new_full (g_str_hash,
314 g_str_equal, g_free, (GDestroyNotify) tp_g_value_slice_free);
315
316 tp_g_hash_table_update (self->priv->request,
317 hash, (GBoxedCopyFunc) g_strdup,
318 (GBoxedCopyFunc) tp_g_value_slice_dup);
319 g_hash_table_unref (hash);
320 }
321 break;
322
286323 case PROP_USER_ACTION_TIME:
287324 self->priv->user_action_time = g_value_get_int64 (value);
288325 break;
349386 * The desired D-Bus properties for the channel, represented as a
350387 * #GHashTable where the keys are strings and the values are #GValue.
351388 *
352 * This property can't be %NULL.
389 * When constructing a new object, one of
390 * #TpAccountChannelRequest:request or
391 * #TpAccountChannelRequest:request-vardict must be set to a non-%NULL
392 * value, and the other must remain unspecified.
353393 *
354394 * Since: 0.11.12
355395 */
358398 TP_HASH_TYPE_STRING_VARIANT_MAP,
359399 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
360400 g_object_class_install_property (object_class, PROP_REQUEST,
401 param_spec);
402
403 /**
404 * TpAccountChannelRequest:request-vardict:
405 *
406 * The desired D-Bus properties for the channel.
407 *
408 * When constructing a new object, one of
409 * #TpAccountChannelRequest:request or
410 * #TpAccountChannelRequest:request-vardict must be set to a non-%NULL
411 * value, and the other must remain unspecified.
412 *
413 * Since: 0.UNRELEASED
414 */
415 param_spec = g_param_spec_variant ("request-vardict", "Request",
416 "A dictionary containing desirable properties for the channel",
417 G_VARIANT_TYPE_VARDICT, NULL,
418 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
419 g_object_class_install_property (object_class, PROP_REQUEST_VARDICT,
361420 param_spec);
362421
363422 /**
518577 GVariant *request,
519578 gint64 user_action_time)
520579 {
521 GHashTable *hash;
522580 TpAccountChannelRequest *ret;
523581
524582 g_return_val_if_fail (TP_IS_ACCOUNT (account), NULL);
527585 NULL);
528586
529587 g_variant_ref_sink (request);
530 hash = _tp_asv_from_vardict (request);
531 g_variant_unref (request);
532588
533589 ret = g_object_new (TP_TYPE_ACCOUNT_CHANNEL_REQUEST,
534590 "account", account,
535 "request", hash,
591 "request-vardict", request,
536592 "user-action-time", user_action_time,
537593 NULL);
538 g_hash_table_unref (hash);
594 g_variant_unref (request);
539595 return ret;
540596 }
541597
571627 TpAccountChannelRequest *self)
572628 {
573629 return self->priv->request;
630 }
631
632 /**
633 * tp_account_channel_request_dup_request:
634 * @self: a #TpAccountChannelRequest
635 *
636 * Return the #TpAccountChannelRequest:request-vardict construct-only
637 * property.
638 *
639 * Returns: (transfer full): the value of
640 * #TpAccountChannelRequest:request-vardict
641 *
642 * Since: 0.11.UNRELEASED
643 */
644 GVariant *
645 tp_account_channel_request_dup_request (
646 TpAccountChannelRequest *self)
647 {
648 g_return_val_if_fail (TP_IS_ACCOUNT_CHANNEL_REQUEST (self), NULL);
649
650 return _tp_asv_to_vardict (self->priv->request);
574651 }
575652
576653 /**
7676
7777 GHashTable * tp_account_channel_request_get_request (
7878 TpAccountChannelRequest *self);
79 _TP_AVAILABLE_IN_UNRELEASED
80 GVariant *tp_account_channel_request_dup_request (
81 TpAccountChannelRequest *self);
7982
8083 gint64 tp_account_channel_request_get_user_action_time (
8184 TpAccountChannelRequest *self);
446446 {
447447 TpAccountChannelRequest *req;
448448 TpContact *alice;
449 GHashTable *asv;
450 GVariant *vardict;
449451
450452 alice = tp_tests_connection_run_until_contact_by_id (test->connection,
451453 "alice", 0, NULL);
452454
453455 req = tp_account_channel_request_new_text (test->account, 0);
454456 tp_account_channel_request_set_target_contact (req, alice);
457
458 asv = (GHashTable *) tp_account_channel_request_get_request (req);
459 vardict = tp_account_channel_request_dup_request (req);
460 g_assert_cmpstr (tp_asv_get_string (asv,
461 TP_PROP_CHANNEL_TARGET_ID), ==, "alice");
462 g_assert_cmpstr (tp_vardict_get_string (vardict,
463 TP_PROP_CHANNEL_TARGET_ID), ==, "alice");
464 g_variant_unref (vardict);
465
466 g_object_get (req,
467 "request", &asv,
468 "request-vardict", &vardict,
469 NULL);
470 g_assert_cmpstr (tp_asv_get_string (asv,
471 TP_PROP_CHANNEL_TARGET_ID), ==, "alice");
472 g_assert_cmpstr (tp_vardict_get_string (vardict,
473 TP_PROP_CHANNEL_TARGET_ID), ==, "alice");
474 g_hash_table_unref (asv);
475 g_variant_unref (vardict);
455476
456477 tp_account_channel_request_ensure_and_handle_channel_async (req,
457478 NULL, ensure_and_handle_cb, test);