[gimp] libgimpconfig: add gimp_config_path_expand_to_files()



commit 32f29db8b0f6edef0694eaba4e51643b03552dc1
Author: Michael Natterer <mitch gimp org>
Date:   Tue Jul 15 23:11:27 2014 +0200

    libgimpconfig: add gimp_config_path_expand_to_files()
    
    which returns a list of newly allocated GFiles.

 libgimpconfig/gimpconfig-path.c |   48 +++++++++++++++++++++++++++++++++++++++
 libgimpconfig/gimpconfig-path.h |    2 +
 libgimpconfig/gimpconfig.def    |    1 +
 3 files changed, 51 insertions(+), 0 deletions(-)
---
diff --git a/libgimpconfig/gimpconfig-path.c b/libgimpconfig/gimpconfig-path.c
index d6388d4..2a53573 100644
--- a/libgimpconfig/gimpconfig-path.c
+++ b/libgimpconfig/gimpconfig-path.c
@@ -311,6 +311,54 @@ gimp_config_path_expand (const gchar  *path,
   return gimp_config_path_expand_only (path, error);
 }
 
+/**
+ * gimp_config_path_expand_to_files:
+ * @path: a NUL-terminated string in UTF-8 encoding
+ * @error: return location for errors
+ *
+ * Paths as stored in the gimprc have to be treated special. The
+ * string may contain special identifiers such as for example
+ * ${gimp_dir} that have to be substituted before use. Also the user's
+ * filesystem may be in a different encoding than UTF-8 (which is what
+ * is used for the gimprc).
+ *
+ * This function runs @path through gimp_config_path_expand() and
+ * gimp_path_parse(), then turns the filenames returned by gimp_path_parse()
+ * into GFile using g_file_new_for_path().
+ *
+ * Return value: a #GList of newly allocated #GFile objects.
+ *
+ * Since: GIMP 2.10
+ **/
+GList *
+gimp_config_path_expand_to_files (const gchar  *path,
+                                  GError      **error)
+{
+  GList *files;
+  GList *list;
+  gchar *expanded;
+
+  g_return_val_if_fail (path != NULL, NULL);
+  g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+
+  expanded = gimp_config_path_expand (path, TRUE, error);
+
+  if (! expanded)
+    return NULL;
+
+  files = gimp_path_parse (expanded, 256, FALSE, NULL);
+
+  for (list = files; list; list = g_list_next (list))
+    {
+      gchar *dir = list->data;
+
+      list->data = g_file_new_for_path (dir);
+      g_free (dir);
+    }
+
+  return files;
+}
+
 
 #define SUBSTS_ALLOC 4
 
diff --git a/libgimpconfig/gimpconfig-path.h b/libgimpconfig/gimpconfig-path.h
index 4512e2c..9139d81 100644
--- a/libgimpconfig/gimpconfig-path.h
+++ b/libgimpconfig/gimpconfig-path.h
@@ -77,6 +77,8 @@ GimpConfigPathType  gimp_param_spec_config_path_type (GParamSpec   *pspec);
 gchar             * gimp_config_path_expand          (const gchar  *path,
                                                       gboolean      recode,
                                                       GError      **error) G_GNUC_MALLOC;
+GList             * gimp_config_path_expand_to_files (const gchar  *path,
+                                                      GError      **error) G_GNUC_MALLOC;
 
 gchar             * gimp_config_build_data_path      (const gchar  *name) G_GNUC_MALLOC;
 gchar             * gimp_config_build_writable_path  (const gchar  *name) G_GNUC_MALLOC;
diff --git a/libgimpconfig/gimpconfig.def b/libgimpconfig/gimpconfig.def
index f3c558f..30907b1 100644
--- a/libgimpconfig/gimpconfig.def
+++ b/libgimpconfig/gimpconfig.def
@@ -20,6 +20,7 @@ EXPORTS
        gimp_config_interface_get_type
        gimp_config_is_equal_to
        gimp_config_path_expand
+       gimp_config_path_expand_to_files
        gimp_config_path_get_type
        gimp_config_reset
        gimp_config_reset_properties


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