Skip to content

Commit 32f29db

Browse files
committed
libgimpconfig: add gimp_config_path_expand_to_files()
which returns a list of newly allocated GFiles.
1 parent 35466d6 commit 32f29db

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

libgimpconfig/gimpconfig-path.c

+48
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,54 @@ gimp_config_path_expand (const gchar *path,
311311
return gimp_config_path_expand_only (path, error);
312312
}
313313

314+
/**
315+
* gimp_config_path_expand_to_files:
316+
* @path: a NUL-terminated string in UTF-8 encoding
317+
* @error: return location for errors
318+
*
319+
* Paths as stored in the gimprc have to be treated special. The
320+
* string may contain special identifiers such as for example
321+
* ${gimp_dir} that have to be substituted before use. Also the user's
322+
* filesystem may be in a different encoding than UTF-8 (which is what
323+
* is used for the gimprc).
324+
*
325+
* This function runs @path through gimp_config_path_expand() and
326+
* gimp_path_parse(), then turns the filenames returned by gimp_path_parse()
327+
* into GFile using g_file_new_for_path().
328+
*
329+
* Return value: a #GList of newly allocated #GFile objects.
330+
*
331+
* Since: GIMP 2.10
332+
**/
333+
GList *
334+
gimp_config_path_expand_to_files (const gchar *path,
335+
GError **error)
336+
{
337+
GList *files;
338+
GList *list;
339+
gchar *expanded;
340+
341+
g_return_val_if_fail (path != NULL, NULL);
342+
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
343+
344+
expanded = gimp_config_path_expand (path, TRUE, error);
345+
346+
if (! expanded)
347+
return NULL;
348+
349+
files = gimp_path_parse (expanded, 256, FALSE, NULL);
350+
351+
for (list = files; list; list = g_list_next (list))
352+
{
353+
gchar *dir = list->data;
354+
355+
list->data = g_file_new_for_path (dir);
356+
g_free (dir);
357+
}
358+
359+
return files;
360+
}
361+
314362

315363
#define SUBSTS_ALLOC 4
316364

libgimpconfig/gimpconfig-path.h

+2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ GimpConfigPathType gimp_param_spec_config_path_type (GParamSpec *pspec);
7777
gchar * gimp_config_path_expand (const gchar *path,
7878
gboolean recode,
7979
GError **error) G_GNUC_MALLOC;
80+
GList * gimp_config_path_expand_to_files (const gchar *path,
81+
GError **error) G_GNUC_MALLOC;
8082

8183
gchar * gimp_config_build_data_path (const gchar *name) G_GNUC_MALLOC;
8284
gchar * gimp_config_build_writable_path (const gchar *name) G_GNUC_MALLOC;

libgimpconfig/gimpconfig.def

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ EXPORTS
2020
gimp_config_interface_get_type
2121
gimp_config_is_equal_to
2222
gimp_config_path_expand
23+
gimp_config_path_expand_to_files
2324
gimp_config_path_get_type
2425
gimp_config_reset
2526
gimp_config_reset_properties

0 commit comments

Comments
 (0)