[clutter/wip/resources] script: Add loading from a resource



commit 8b164e331914c28830a33706d17259de4aad41aa
Author: Emmanuele Bassi <ebassi linux intel com>
Date:   Mon Jan 16 11:27:08 2012 +0000

    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 +++
 2 files changed, 42 insertions(+), 0 deletions(-)
---
diff --git a/clutter/clutter-script.c b/clutter/clutter-script.c
index 1ae6105..566adc8 100644
--- a/clutter/clutter-script.c
+++ b/clutter/clutter-script.c
@@ -601,6 +601,45 @@ clutter_script_load_from_data (ClutterScript  *script,
 }
 
 /**
+ * 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
  * @name: the name of the object to retrieve
diff --git a/clutter/clutter-script.h b/clutter/clutter-script.h
index 1da9870..db33c51 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);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]