From 6af371ceb0d40dfe41fe3a44381d2893aa3bf980 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 8 Mar 2012 12:45:12 +0000 Subject: [PATCH 1/7] Add tp_account_dup_storage_identifier_variant Bug: https://bugs.freedesktop.org/show_bug.cgi?id=30422 --- docs/reference/telepathy-glib-sections.txt | 1 + telepathy-glib/account.c | 59 ++++++++++++++++++++++++++++ telepathy-glib/account.h | 1 + tests/dbus/account.c | 21 ++++++++++ 4 files changed, 82 insertions(+), 0 deletions(-) diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt index 244a2b0..ced5da7 100644 --- a/docs/reference/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib-sections.txt @@ -5114,6 +5114,7 @@ tp_account_set_uri_scheme_association_finish TP_ACCOUNT_FEATURE_STORAGE tp_account_get_storage_provider tp_account_get_storage_identifier +tp_account_dup_storage_identifier_variant tp_account_get_storage_restrictions tp_account_get_storage_specific_information_async tp_account_get_storage_specific_information_finish diff --git a/telepathy-glib/account.c b/telepathy-glib/account.c index 455f8c1..7b0b01b 100644 --- a/telepathy-glib/account.c +++ b/telepathy-glib/account.c @@ -174,6 +174,7 @@ enum { PROP_NORMALIZED_NAME, PROP_STORAGE_PROVIDER, PROP_STORAGE_IDENTIFIER, + PROP_STORAGE_IDENTIFIER_VARIANT, PROP_STORAGE_RESTRICTIONS, PROP_SUPERSEDES, N_PROPS @@ -1137,6 +1138,10 @@ _tp_account_get_property (GObject *object, case PROP_STORAGE_IDENTIFIER: g_value_set_boxed (value, self->priv->storage_identifier); break; + case PROP_STORAGE_IDENTIFIER_VARIANT: + g_value_take_variant (value, + tp_account_dup_storage_identifier_variant (self)); + break; case PROP_STORAGE_RESTRICTIONS: g_value_set_uint (value, self->priv->storage_restrictions); break; @@ -1891,6 +1896,34 @@ tp_account_class_init (TpAccountClass *klass) G_PARAM_STATIC_STRINGS | G_PARAM_READABLE)); /** + * TpAccount:storage-identifier-variant: + * + * Provider-specific information used to identify this + * account. Use g_variant_get_type() to check that the type + * is what you expect. For instance, if you use a + * #TpAccount:storage-provider with numeric identifiers for accounts, + * this variant might have type %G_VARIANT_TYPE_UINT32; + * if the storage provider has string-based identifiers, it should + * have type %G_VARIANT_TYPE_STRING. + * + * This property cannot change once an Account has been created. + * + * This is not guaranteed to have been retrieved until the + * %TP_ACCOUNT_FEATURE_STORAGE feature has been prepared; until then, + * the value is %NULL. + * + * Since: 0.13.2 + */ + g_object_class_install_property (object_class, + PROP_STORAGE_IDENTIFIER_VARIANT, + g_param_spec_variant ("storage-identifier-variant", + "StorageIdentifier as variant", + "The storage identifier for this account", + G_VARIANT_TYPE_ANY, + NULL, + G_PARAM_STATIC_STRINGS | G_PARAM_READABLE)); + + /** * TpAccount:storage-restrictions * * The storage restrictions for this account. @@ -3665,6 +3698,7 @@ tp_account_get_storage_provider (TpAccount *self) return self->priv->storage_provider; } +/* FIXME: in 1.0, remove */ /** * tp_account_get_storage_identifier: * @self: a #TpAccount @@ -3683,6 +3717,31 @@ tp_account_get_storage_identifier (TpAccount *self) return self->priv->storage_identifier; } +/* FIXME: in 1.0, rename to tp_account_get_storage_identifier */ +/** + * tp_account_dup_storage_identifier_variant: + * @self: a #TpAccount + * + * Return provider-specific information used to identify this + * account. Use g_variant_get_type() to check that the type + * is what you expect; for instance, if the + * #TpAccount:storage-provider has string-based user identifiers, + * this variant should have type %G_VARIANT_TYPE_STRING. + * + * Returns: (transfer full): the same as the + * #TpAccount:storage-identifier-variant property + * + * Since: 0.13.2 + */ +GVariant * +tp_account_dup_storage_identifier_variant (TpAccount *self) +{ + g_return_val_if_fail (TP_IS_ACCOUNT (self), NULL); + + return g_variant_ref_sink (dbus_g_value_build_g_variant ( + self->priv->storage_identifier)); +} + /** * tp_account_get_storage_restrictions: * @self: a #TpAccount diff --git a/telepathy-glib/account.h b/telepathy-glib/account.h index ddcd4c1..d5a57e2 100644 --- a/telepathy-glib/account.h +++ b/telepathy-glib/account.h @@ -242,6 +242,7 @@ gboolean tp_account_get_changing_presence (TpAccount *self); const gchar *tp_account_get_storage_provider (TpAccount *self); const GValue *tp_account_get_storage_identifier (TpAccount *self); +GVariant *tp_account_dup_storage_identifier_variant (TpAccount *self); TpStorageRestrictionFlags tp_account_get_storage_restrictions (TpAccount *self); void tp_account_get_storage_specific_information_async (TpAccount *self, GAsyncReadyCallback callback, gpointer user_data); diff --git a/tests/dbus/account.c b/tests/dbus/account.c index c05417c..d33e097 100644 --- a/tests/dbus/account.c +++ b/tests/dbus/account.c @@ -475,6 +475,7 @@ test_storage (Test *test, { GQuark account_features[] = { TP_ACCOUNT_FEATURE_STORAGE, 0 }; GValue *gvalue; + GVariant *gvariant; GHashTable *info; GError *error = NULL; @@ -496,6 +497,11 @@ test_storage (Test *test, "storage-identifier", &gvalue, NULL); g_assert (gvalue == NULL); + g_assert (tp_account_get_storage_identifier (test->account) == NULL); + g_object_get (test->account, + "storage-identifier", &gvariant, + NULL); + g_assert (gvariant == NULL); g_assert_cmpuint (tp_account_get_storage_restrictions (test->account), ==, 0); assert_uintprop (test->account, "storage-restrictions", 0); @@ -510,6 +516,7 @@ test_storage (Test *test, "org.freedesktop.Telepathy.glib.test"); assert_strprop (test->account, "storage-provider", "org.freedesktop.Telepathy.glib.test"); + g_assert_cmpstr ( g_value_get_string (tp_account_get_storage_identifier (test->account)), ==, "unique-identifier"); @@ -518,6 +525,20 @@ test_storage (Test *test, NULL); g_assert_cmpstr (g_value_get_string (gvalue), ==, "unique-identifier"); g_boxed_free (G_TYPE_VALUE, gvalue); + + gvariant = tp_account_dup_storage_identifier_variant (test->account); + g_assert_cmpstr (g_variant_get_type_string (gvariant), ==, "s"); + g_assert_cmpstr (g_variant_get_string (gvariant, NULL), ==, + "unique-identifier"); + g_variant_unref (gvariant); + g_object_get (test->account, + "storage-identifier-variant", &gvariant, + NULL); + g_assert_cmpstr (g_variant_get_type_string (gvariant), ==, "s"); + g_assert_cmpstr (g_variant_get_string (gvariant, NULL), ==, + "unique-identifier"); + g_variant_unref (gvariant); + g_assert_cmpuint (tp_account_get_storage_restrictions (test->account), ==, TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_ENABLED | TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_PARAMETERS); -- 1.7.9.1