mirror of https://github.com/GNOME/gimp.git
libgimpconfig: add API operating on GFiles instead of filenames
to GimpConfigInterface's wrappers, to GimpConfigWriter and to GimpScanner.
This commit is contained in:
parent
9696e297ac
commit
6ec5fb80e4
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include <gegl.h>
|
||||
|
||||
#include "libgimpconfig/gimpconfig.h"
|
||||
|
|
|
@ -297,6 +297,47 @@ gimp_config_serialize_to_file (GimpConfig *config,
|
|||
return gimp_config_writer_finish (writer, footer, error);
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_config_serialize_to_gfile:
|
||||
* @config: a #GObject that implements the #GimpConfigInterface.
|
||||
* @file: the #GFile to write the configuration to.
|
||||
* @header: optional file header (must be ASCII only)
|
||||
* @footer: optional file footer (must be ASCII only)
|
||||
* @data: user data passed to the serialize implementation.
|
||||
* @error: return location for a possible error
|
||||
*
|
||||
* Serializes the object properties of @config to the file specified
|
||||
* by @file. If a file with that name already exists, it is
|
||||
* overwritten. Basically this function opens @file for you and calls
|
||||
* the serialize function of the @config's #GimpConfigInterface.
|
||||
*
|
||||
* Return value: %TRUE if serialization succeeded, %FALSE otherwise.
|
||||
*
|
||||
* Since: GIMP 2.10
|
||||
**/
|
||||
gboolean
|
||||
gimp_config_serialize_to_gfile (GimpConfig *config,
|
||||
GFile *file,
|
||||
const gchar *header,
|
||||
const gchar *footer,
|
||||
gpointer data,
|
||||
GError **error)
|
||||
{
|
||||
GimpConfigWriter *writer;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_CONFIG (config), FALSE);
|
||||
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||
|
||||
writer = gimp_config_writer_new_gfile (file, TRUE, header, error);
|
||||
if (!writer)
|
||||
return FALSE;
|
||||
|
||||
GIMP_CONFIG_GET_INTERFACE (config)->serialize (config, writer, data);
|
||||
|
||||
return gimp_config_writer_finish (writer, footer, error);
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_config_serialize_to_fd:
|
||||
* @config: a #GObject that implements the #GimpConfigInterface.
|
||||
|
@ -407,6 +448,54 @@ gimp_config_deserialize_file (GimpConfig *config,
|
|||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_config_deserialize_gfile:
|
||||
* @config: a #GObject that implements the #GimpConfigInterface.
|
||||
* @file: the #GFile to read configuration from.
|
||||
* @data: user data passed to the deserialize implementation.
|
||||
* @error: return location for a possible error
|
||||
*
|
||||
* Opens the file specified by @file, reads configuration data from it
|
||||
* and configures @config accordingly. Basically this function creates
|
||||
* a properly configured #GScanner for you and calls the deserialize
|
||||
* function of the @config's #GimpConfigInterface.
|
||||
*
|
||||
* Return value: %TRUE if deserialization succeeded, %FALSE otherwise.
|
||||
*
|
||||
* Since: GIMP 2.10
|
||||
**/
|
||||
gboolean
|
||||
gimp_config_deserialize_gfile (GimpConfig *config,
|
||||
GFile *file,
|
||||
gpointer data,
|
||||
GError **error)
|
||||
{
|
||||
GScanner *scanner;
|
||||
gboolean success;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_CONFIG (config), FALSE);
|
||||
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||
|
||||
scanner = gimp_scanner_new_gfile (file, error);
|
||||
if (! scanner)
|
||||
return FALSE;
|
||||
|
||||
g_object_freeze_notify (G_OBJECT (config));
|
||||
|
||||
success = GIMP_CONFIG_GET_INTERFACE (config)->deserialize (config,
|
||||
scanner, 0, data);
|
||||
|
||||
g_object_thaw_notify (G_OBJECT (config));
|
||||
|
||||
gimp_scanner_destroy (scanner);
|
||||
|
||||
if (! success)
|
||||
g_assert (error == NULL || *error != NULL);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_config_deserialize_string:
|
||||
* @config: a #GObject that implements the #GimpConfigInterface.
|
||||
|
|
|
@ -79,6 +79,12 @@ gboolean gimp_config_serialize_to_file (GimpConfig *config,
|
|||
const gchar *footer,
|
||||
gpointer data,
|
||||
GError **error);
|
||||
gboolean gimp_config_serialize_to_gfile (GimpConfig *config,
|
||||
GFile *file,
|
||||
const gchar *header,
|
||||
const gchar *footer,
|
||||
gpointer data,
|
||||
GError **error);
|
||||
gboolean gimp_config_serialize_to_fd (GimpConfig *config,
|
||||
gint fd,
|
||||
gpointer data);
|
||||
|
@ -88,6 +94,10 @@ gboolean gimp_config_deserialize_file (GimpConfig *config,
|
|||
const gchar *filename,
|
||||
gpointer data,
|
||||
GError **error);
|
||||
gboolean gimp_config_deserialize_gfile (GimpConfig *config,
|
||||
GFile *file,
|
||||
gpointer data,
|
||||
GError **error);
|
||||
gboolean gimp_config_deserialize_string (GimpConfig *config,
|
||||
const gchar *text,
|
||||
gint text_len,
|
||||
|
|
|
@ -8,6 +8,7 @@ EXPORTS
|
|||
gimp_config_copy
|
||||
gimp_config_deserialize
|
||||
gimp_config_deserialize_file
|
||||
gimp_config_deserialize_gfile
|
||||
gimp_config_deserialize_properties
|
||||
gimp_config_deserialize_property
|
||||
gimp_config_deserialize_return
|
||||
|
@ -29,6 +30,7 @@ EXPORTS
|
|||
gimp_config_serialize_property_by_name
|
||||
gimp_config_serialize_to_fd
|
||||
gimp_config_serialize_to_file
|
||||
gimp_config_serialize_to_gfile
|
||||
gimp_config_serialize_to_string
|
||||
gimp_config_serialize_value
|
||||
gimp_config_string_append_escaped
|
||||
|
@ -42,6 +44,7 @@ EXPORTS
|
|||
gimp_config_writer_linefeed
|
||||
gimp_config_writer_new_fd
|
||||
gimp_config_writer_new_file
|
||||
gimp_config_writer_new_gfile
|
||||
gimp_config_writer_new_string
|
||||
gimp_config_writer_open
|
||||
gimp_config_writer_print
|
||||
|
@ -53,6 +56,7 @@ EXPORTS
|
|||
gimp_param_spec_config_path_type
|
||||
gimp_scanner_destroy
|
||||
gimp_scanner_new_file
|
||||
gimp_scanner_new_gfile
|
||||
gimp_scanner_new_string
|
||||
gimp_scanner_parse_boolean
|
||||
gimp_scanner_parse_color
|
||||
|
|
|
@ -177,6 +177,42 @@ gimp_config_writer_new_file (const gchar *filename,
|
|||
return writer;
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_config_writer_new_gfile:
|
||||
* @file: a #GFile
|
||||
* @atomic: if %TRUE the file is written atomically
|
||||
* @header: text to include as comment at the top of the file
|
||||
* @error: return location for errors
|
||||
*
|
||||
* Creates a new #GimpConfigWriter and sets it up to write to
|
||||
* @file. If @atomic is %TRUE, a temporary file is used to avoid
|
||||
* possible race conditions. The temporary file is then moved to @file
|
||||
* when the writer is closed.
|
||||
*
|
||||
* Return value: a new #GimpConfigWriter or %NULL in case of an error
|
||||
*
|
||||
* Since: GIMP 2.10
|
||||
**/
|
||||
GimpConfigWriter *
|
||||
gimp_config_writer_new_gfile (GFile *file,
|
||||
gboolean atomic,
|
||||
const gchar *header,
|
||||
GError **error)
|
||||
{
|
||||
GimpConfigWriter *writer;
|
||||
gchar *path;
|
||||
|
||||
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
||||
|
||||
path = g_file_get_path (file);
|
||||
|
||||
writer = gimp_config_writer_new_file (path, atomic, header, error);
|
||||
|
||||
g_free (path);
|
||||
|
||||
return writer;
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_config_writer_new_fd:
|
||||
* @fd:
|
||||
|
|
|
@ -31,6 +31,10 @@ GimpConfigWriter * gimp_config_writer_new_file (const gchar *filename,
|
|||
gboolean atomic,
|
||||
const gchar *header,
|
||||
GError **error);
|
||||
GimpConfigWriter * gimp_config_writer_new_gfile (GFile *file,
|
||||
gboolean atomic,
|
||||
const gchar *header,
|
||||
GError **error);
|
||||
GimpConfigWriter * gimp_config_writer_new_fd (gint fd);
|
||||
GimpConfigWriter * gimp_config_writer_new_string (GString *string);
|
||||
|
||||
|
|
|
@ -112,6 +112,33 @@ gimp_scanner_new_file (const gchar *filename,
|
|||
return scanner;
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_scanner_new_gfile:
|
||||
* @file: a #GFile
|
||||
* @error: return location for #GError, or %NULL
|
||||
*
|
||||
* Return value: The new #GScanner.
|
||||
*
|
||||
* Since: GIMP 2.10
|
||||
**/
|
||||
GScanner *
|
||||
gimp_scanner_new_gfile (GFile *file,
|
||||
GError **error)
|
||||
{
|
||||
GScanner *scanner;
|
||||
gchar *path;
|
||||
|
||||
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
||||
|
||||
path = g_file_get_path (file);
|
||||
|
||||
scanner = gimp_scanner_new_file (path, error);
|
||||
|
||||
g_free (path);
|
||||
|
||||
return scanner;
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_scanner_new_string:
|
||||
* @text:
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
|
||||
GScanner * gimp_scanner_new_file (const gchar *filename,
|
||||
GError **error);
|
||||
GScanner * gimp_scanner_new_gfile (GFile *file,
|
||||
GError **error);
|
||||
GScanner * gimp_scanner_new_string (const gchar *text,
|
||||
gint text_len,
|
||||
GError **error);
|
||||
|
|
Loading…
Reference in New Issue