From 8d8d4ae7e59d869c05251f9ad351f85e6784d136 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Mon, 16 Jan 2012 11:27:08 +0000 Subject: [PATCH] script: Add loading from a resource GLib has gained support for compiling ancillary data files into the same binary blob as a library or as an executable. We should add this feature to ClutterScript, so that it's possible to bundle UI definitions with an application. --- clutter/clutter-script.c | 39 +++++++++++++++++++++++++++++++++++++++ clutter/clutter-script.h | 3 +++ clutter/clutter.symbols | 1 + configure.ac | 2 +- 4 files changed, 44 insertions(+), 1 deletion(-) diff --git a/clutter/clutter-script.c b/clutter/clutter-script.c index 1ae6105e1..566adc83f 100644 --- a/clutter/clutter-script.c +++ b/clutter/clutter-script.c @@ -600,6 +600,45 @@ clutter_script_load_from_data (ClutterScript *script, return priv->last_merge_id; } +/** + * clutter_script_load_from_resource: + * @script: a #ClutterScript + * @resource_path: the resource path of the file to parse + * @error: return location for a #GError, or %NULL + * + * Loads the definitions from a resource file into @script and merges with + * the currently loaded ones, if any. + * + * Return value: on error, zero is returned and @error is set + * accordingly. On success, the merge id for the UI definitions is + * returned. You can use the merge id with clutter_script_unmerge_objects(). + * + * Since: 1.10 + */ +guint +clutter_script_load_from_resource (ClutterScript *script, + const gchar *resource_path, + GError **error) +{ + GBytes *data; + guint res; + + g_return_val_if_fail (CLUTTER_IS_SCRIPT (script), 0); + + data = g_resources_lookup_data (resource_path, 0, error); + if (data == NULL) + return 0; + + res = clutter_script_load_from_data (script, + g_bytes_get_data (data, NULL), + g_bytes_get_size (data), + error); + + g_bytes_unref (data); + + return res; +} + /** * clutter_script_get_object: * @script: a #ClutterScript diff --git a/clutter/clutter-script.h b/clutter/clutter-script.h index 1da98709a..db33c51fc 100644 --- a/clutter/clutter-script.h +++ b/clutter/clutter-script.h @@ -153,6 +153,9 @@ guint clutter_script_load_from_data (ClutterScript const gchar *data, gssize length, GError **error); +guint clutter_script_load_from_resource (ClutterScript *script, + const gchar *resource_path, + GError **error); GObject * clutter_script_get_object (ClutterScript *script, const gchar *name); diff --git a/clutter/clutter.symbols b/clutter/clutter.symbols index a3d679659..294200f4d 100644 --- a/clutter/clutter.symbols +++ b/clutter/clutter.symbols @@ -936,6 +936,7 @@ clutter_script_get_type_from_name clutter_script_list_objects clutter_script_load_from_data clutter_script_load_from_file +clutter_script_load_from_resource clutter_script_lookup_filename clutter_script_new clutter_script_unmerge_objects diff --git a/configure.ac b/configure.ac index 9ae7aea37..b6b58dd82 100644 --- a/configure.ac +++ b/configure.ac @@ -129,7 +129,7 @@ LT_INIT([disable-static]) AC_HEADER_STDC # required versions for dependencies -m4_define([glib_req_version], [2.31.0]) +m4_define([glib_req_version], [2.31.10]) m4_define([cogl_req_version], [1.9.4]) m4_define([json_glib_req_version], [0.12.0]) m4_define([atk_req_version], [2.1.5])