diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2014-02-03 20:22:32 +0000 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2014-02-04 13:57:33 +0000 |
commit | 7290f4e00a5eb3cd155998d7a0a81a14028ced7c (patch) | |
tree | 8bcbae78d666ba50b1edaae210a7123fab9336b4 /src | |
parent | ea63753dbccb7fa617496c3c0d3d0d2bc0351bc3 (diff) |
Require account plugins to provide the ability to list parameters
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=71093
Reviewed-by: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Diffstat (limited to 'src')
-rw-r--r-- | src/mcd-account-manager-default.c | 57 | ||||
-rw-r--r-- | src/mcd-storage.c | 48 |
2 files changed, 105 insertions, 0 deletions
diff --git a/src/mcd-account-manager-default.c b/src/mcd-account-manager-default.c index e9f2bf20..f4abd844 100644 --- a/src/mcd-account-manager-default.c +++ b/src/mcd-account-manager-default.c @@ -305,6 +305,9 @@ get_parameter (McpAccountStorage *self, if (variant != NULL) return g_variant_ref (variant); + if (type == NULL) + return NULL; + str = g_hash_table_lookup (sa->untyped_parameters, parameter); if (str == NULL) @@ -314,6 +317,58 @@ get_parameter (McpAccountStorage *self, str, type, NULL); } +static gchar ** +list_typed_parameters (McpAccountStorage *self, + McpAccountManager *am, + const gchar *account) +{ + McdAccountManagerDefault *amd = MCD_ACCOUNT_MANAGER_DEFAULT (self); + McdDefaultStoredAccount *sa = lookup_stored_account (amd, account); + GPtrArray *arr; + GHashTableIter iter; + gpointer k; + + g_return_val_if_fail (sa != NULL, NULL); + g_return_val_if_fail (!sa->absent, NULL); + + arr = g_ptr_array_sized_new (g_hash_table_size (sa->parameters) + 1); + + g_hash_table_iter_init (&iter, sa->parameters); + + while (g_hash_table_iter_next (&iter, &k, NULL)) + g_ptr_array_add (arr, g_strdup (k)); + + g_ptr_array_add (arr, NULL); + + return (gchar **) g_ptr_array_free (arr, FALSE); +} + +static gchar ** +list_untyped_parameters (McpAccountStorage *self, + McpAccountManager *am, + const gchar *account) +{ + McdAccountManagerDefault *amd = MCD_ACCOUNT_MANAGER_DEFAULT (self); + McdDefaultStoredAccount *sa = lookup_stored_account (amd, account); + GPtrArray *arr; + GHashTableIter iter; + gpointer k; + + g_return_val_if_fail (sa != NULL, NULL); + g_return_val_if_fail (!sa->absent, NULL); + + arr = g_ptr_array_sized_new (g_hash_table_size (sa->untyped_parameters) + 1); + + g_hash_table_iter_init (&iter, sa->untyped_parameters); + + while (g_hash_table_iter_next (&iter, &k, NULL)) + g_ptr_array_add (arr, g_strdup (k)); + + g_ptr_array_add (arr, NULL); + + return (gchar **) g_ptr_array_free (arr, FALSE); +} + static gchar * _create (McpAccountStorage *self, McpAccountManager *am, @@ -981,6 +1036,8 @@ account_storage_iface_init (McpAccountStorageIface *iface, iface->get_attribute = get_attribute; iface->get_parameter = get_parameter; + iface->list_typed_parameters = list_typed_parameters; + iface->list_untyped_parameters = list_untyped_parameters; iface->set_attribute = set_attribute; iface->set_parameter = set_parameter; iface->create = _create; diff --git a/src/mcd-storage.c b/src/mcd-storage.c index 828d5a1b..1db0717f 100644 --- a/src/mcd-storage.c +++ b/src/mcd-storage.c @@ -1942,6 +1942,9 @@ mcd_storage_add_account_from_plugin (McdStorage *self, GError **error) { McpAccountStorage *other = g_hash_table_lookup (self->accounts, account); + McpAccountManager *api = (McpAccountManager *) self; + gchar **typed_parameters; + gchar **untyped_parameters; if (other != NULL) { @@ -1956,5 +1959,50 @@ mcd_storage_add_account_from_plugin (McdStorage *self, g_hash_table_insert (self->accounts, g_strdup (account), g_object_ref (plugin)); + + typed_parameters = mcp_account_storage_list_typed_parameters (plugin, api, + account); + untyped_parameters = mcp_account_storage_list_untyped_parameters (plugin, + api, account); + + DEBUG ("Account parameters for %s", account); + + if (typed_parameters != NULL) + { + gsize i; + + for (i = 0; typed_parameters[i] != NULL; i++) + { + GVariant *v = mcp_account_storage_get_parameter (plugin, api, account, + typed_parameters[i], NULL, NULL); + + if (v == NULL) + { + CRITICAL ("%s: could not be retrieved", typed_parameters[i]); + } + else + { + DEBUG ("%s: type '%s'", typed_parameters[i], + g_variant_get_type_string (v)); + g_variant_unref (v); + } + } + } + + if (untyped_parameters != NULL) + { + gsize i; + + for (i = 0; untyped_parameters[i] != NULL; i++) + { + DEBUG ("%s: type not stored", untyped_parameters[i]); + } + } + + DEBUG ("End of parameters"); + + g_strfreev (typed_parameters); + g_strfreev (untyped_parameters); + return TRUE; } |