mirror of https://github.com/GNOME/gimp.git
libgimpconfig: add gimp_file_new_for_config_path() and _get_config_path()
Which turn a UTF-8 encoded config path directly into a GFile and back, using gimp_config_path_expand() and _unexpand().
This commit is contained in:
parent
beb3279bf2
commit
d36d956770
|
@ -410,6 +410,85 @@ gimp_config_path_unexpand (const gchar *path,
|
|||
return gimp_config_path_unexpand_only (path);
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_file_new_for_config_path:
|
||||
* @path: a NUL-terminated string in UTF-8 encoding
|
||||
* @error: return location for errors
|
||||
*
|
||||
* Expands @path using gimp_config_path_expand() and returns a #GFile
|
||||
* for the expanded path.
|
||||
*
|
||||
* To reverse the expansion, use gimp_file_get_config_path().
|
||||
*
|
||||
* Return value: a newly allocated #GFile, or %NULL if the expansion failed.
|
||||
*
|
||||
* Since: 2.10
|
||||
**/
|
||||
GFile *
|
||||
gimp_file_new_for_config_path (const gchar *path,
|
||||
GError **error)
|
||||
{
|
||||
GFile *file = NULL;
|
||||
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)
|
||||
{
|
||||
file = g_file_new_for_path (expanded);
|
||||
g_free (expanded);
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_file_new_for_config_path:
|
||||
* @file: a #GFile
|
||||
* @error: return location for errors
|
||||
*
|
||||
* Unexpands @file's path using gimp_config_path_unexpand() and
|
||||
* returns the unexpanded path.
|
||||
*
|
||||
* The inverse operation of gimp_file_new_for_config_path().
|
||||
*
|
||||
* Return value: a newly allocated NUL-terminated UTF-8 string, or %NULL if
|
||||
* unexpanding failed.
|
||||
*
|
||||
* Since: 2.10
|
||||
**/
|
||||
gchar *
|
||||
gimp_file_get_config_path (GFile *file,
|
||||
GError **error)
|
||||
{
|
||||
gchar *unexpanded = NULL;
|
||||
gchar *path;
|
||||
|
||||
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
||||
|
||||
path = g_file_get_path (file);
|
||||
|
||||
if (path)
|
||||
{
|
||||
unexpanded = gimp_config_path_unexpand (path, TRUE, error);
|
||||
g_free (path);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_set_error_literal (error, 0, 0,
|
||||
_("File has no path represantation"));
|
||||
}
|
||||
|
||||
return unexpanded;
|
||||
}
|
||||
|
||||
|
||||
/* private functions */
|
||||
|
||||
#define SUBSTS_ALLOC 4
|
||||
|
||||
static gchar *
|
||||
|
|
|
@ -84,6 +84,11 @@ gchar * gimp_config_path_unexpand (const gchar *path,
|
|||
gboolean recode,
|
||||
GError **error) G_GNUC_MALLOC;
|
||||
|
||||
GFile * gimp_file_new_for_config_path (const gchar *path,
|
||||
GError **error) G_GNUC_MALLOC;
|
||||
gchar * gimp_file_get_config_path (GFile *file,
|
||||
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;
|
||||
gchar * gimp_config_build_plug_in_path (const gchar *name) G_GNUC_MALLOC;
|
||||
|
|
|
@ -70,6 +70,8 @@ EXPORTS
|
|||
gimp_config_writer_printf
|
||||
gimp_config_writer_revert
|
||||
gimp_config_writer_string
|
||||
gimp_file_get_config_path
|
||||
gimp_file_new_for_config_path
|
||||
gimp_param_config_path_get_type
|
||||
gimp_param_spec_config_path
|
||||
gimp_param_spec_config_path_type
|
||||
|
|
Loading…
Reference in New Issue