diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2013-01-21 18:45:17 -0500 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2013-01-21 19:33:54 -0500 |
commit | 42ccd142e30c046a525934749bdca780fd589834 (patch) | |
tree | 3e547628821f8ea2741363d6a1e23c91bebd95b8 /libebackend/e-source-registry-server.c | |
parent | e222299ccad509dd9f0dac1c3d767a80a771617d (diff) | |
download | evolution-data-server-42ccd142e30c046a525934749bdca780fd589834.tar.gz |
Add e_source_registry_server_load_resource().
Loads data source key files from a GResource by enumerating the children
at the given pathname and calling e_source_registry_server_load_file()
on each child.
Diffstat (limited to 'libebackend/e-source-registry-server.c')
-rw-r--r-- | libebackend/e-source-registry-server.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/libebackend/e-source-registry-server.c b/libebackend/e-source-registry-server.c index 753a7f0bc..4aecb22af 100644 --- a/libebackend/e-source-registry-server.c +++ b/libebackend/e-source-registry-server.c @@ -1795,6 +1795,79 @@ e_source_registry_server_load_directory (ESourceRegistryServer *server, return TRUE; } +/** + * e_source_registry_server_load_resource: + * @server: an #ESourceRegistryServer + * @resource: a #GResource containing data source key files + * @path: the path to the data source key files inside @resource + * @flags: permission flags for files loaded from @path + * @error: return location for a #GError, or %NULL + * + * Loads data source key files from @resource by enumerating the children + * at @path and calling e_source_registry_server_load_file() on each child. + * Because multiple errors can occur when loading multiple files, @error is + * only set if @path is invalid. If a key file fails to load, the error is + * broadcast through the #ESourceRegistryServer::load-error signal. + * + * Returns: %TRUE if @path was successfully located, but this does not + * imply the key files were successfully loaded + * + * Since: 3.8 + **/ +gboolean +e_source_registry_server_load_resource (ESourceRegistryServer *server, + GResource *resource, + const gchar *path, + ESourcePermissionFlags flags, + GError **error) +{ + gchar **children; + gint ii; + + g_return_val_if_fail (E_IS_SOURCE_REGISTRY_SERVER (server), FALSE); + g_return_val_if_fail (resource != NULL, FALSE); + g_return_val_if_fail (path != NULL, FALSE); + + children = g_resource_enumerate_children ( + resource, path, G_RESOURCE_LOOKUP_FLAGS_NONE, error); + + if (children == NULL) + return FALSE; + + for (ii = 0; children[ii] != NULL; ii++) { + ESource *source; + GFile *file; + gchar *child_path; + gchar *resource_uri; + GError *local_error = NULL; + + child_path = g_build_path ("/", path, children[ii], NULL); + resource_uri = g_strconcat ("resource://", child_path, NULL); + file = g_file_new_for_uri (resource_uri); + g_free (resource_uri); + g_free (child_path); + + source = e_source_registry_server_load_file ( + server, file, flags, &local_error); + + /* We don't need the returned reference. */ + if (source != NULL) + g_object_unref (source); + + if (local_error != NULL) { + e_source_registry_server_load_error ( + server, file, local_error); + g_error_free (local_error); + } + + g_object_unref (file); + } + + g_strfreev (children); + + return TRUE; +} + /* Helper for e_source_registry_server_load_file() */ static gboolean source_registry_server_tweak_key_file (ESourceRegistryServer *server, |