libgimpconfig: add function which (de)desialize from/to a GimpParasite

This commit is contained in:
Michael Natterer 2019-09-21 10:49:30 +02:00
parent 3c1871680c
commit 82b11c361a
3 changed files with 147 additions and 59 deletions

View File

@ -457,6 +457,46 @@ gimp_config_serialize_to_string (GimpConfig *config,
return g_string_free (str, FALSE);
}
/**
* gimp_config_serialize_to_parasite:
* @config: a #GObject that implements the #GimpConfigInterface.
* @parasite_name: the new parasite's name
* @pparasite_flags: the new parasite's flags
* @data: user data passed to the serialize implementation.
*
* Serializes the object properties of @config to a #GimpParasite.
*
* Returns: (transfer full): the newly allocated #GimpParasite.
*
* Since: 3.0
**/
GimpParasite *
gimp_config_serialize_to_parasite (GimpConfig *config,
const gchar *parasite_name,
guint parasite_flags,
gpointer data)
{
GimpParasite *parasite;
gchar *str;
g_return_val_if_fail (GIMP_IS_CONFIG (config), NULL);
g_return_val_if_fail (parasite_name != NULL, NULL);
str = gimp_config_serialize_to_string (config, data);
if (! str)
return NULL;
parasite = gimp_parasite_new (parasite_name,
parasite_flags,
0, NULL);
parasite->size = strlen (str) + 1;
parasite->data = str;
return parasite;
}
/**
* gimp_config_deserialize_file:
* @config: a #GObject that implements the #GimpConfigInterface.
@ -648,6 +688,41 @@ gimp_config_deserialize_string (GimpConfig *config,
return success;
}
/**
* gimp_config_deserialize_parasite:
* @config: a #GObject that implements the #GimpConfigInterface.
* @parasite: parasite containing a serialized config string
* @data: client data
* @error: return location for a possible error
*
* Configures @config from @parasite. Basically this function creates
* a properly configured #GScanner for you and calls the deserialize
* function of the @config's #GimpConfigInterface.
*
* Returns: %TRUE if deserialization succeeded, %FALSE otherwise.
*
* Since: 3.0
**/
gboolean
gimp_config_deserialize_parasite (GimpConfig *config,
const GimpParasite *parasite,
gpointer data,
GError **error)
{
g_return_val_if_fail (GIMP_IS_CONFIG (config), FALSE);
g_return_val_if_fail (parasite != NULL, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
if (! gimp_parasite_data (parasite))
return TRUE;
return gimp_config_deserialize_string (config,
gimp_parasite_data (parasite),
gimp_parasite_data_size (parasite),
data,
error);
}
/**
* gimp_config_deserialize_return:
* @scanner: a #GScanner

View File

@ -96,6 +96,12 @@ gboolean gimp_config_serialize_to_fd (GimpConfig *config,
gpointer data);
gchar * gimp_config_serialize_to_string (GimpConfig *config,
gpointer data);
GimpParasite *
gimp_config_serialize_to_parasite (GimpConfig *config,
const gchar *parasite_name,
guint parasite_flags,
gpointer data);
gboolean gimp_config_deserialize_file (GimpConfig *config,
const gchar *filename,
gpointer data,
@ -113,6 +119,11 @@ gboolean gimp_config_deserialize_string (GimpConfig *config,
gint text_len,
gpointer data,
GError **error);
gboolean gimp_config_deserialize_parasite (GimpConfig *config,
const GimpParasite *parasite,
gpointer data,
GError **error);
gboolean gimp_config_deserialize_return (GScanner *scanner,
GTokenType expected_token,
gint nest_level);

View File

@ -25,6 +25,7 @@ EXPORTS
gimp_config_deserialize
gimp_config_deserialize_file
gimp_config_deserialize_gfile
gimp_config_deserialize_parasite
gimp_config_deserialize_properties
gimp_config_deserialize_property
gimp_config_deserialize_return
@ -51,6 +52,7 @@ EXPORTS
gimp_config_serialize_to_fd
gimp_config_serialize_to_file
gimp_config_serialize_to_gfile
gimp_config_serialize_to_parasite
gimp_config_serialize_to_stream
gimp_config_serialize_to_string
gimp_config_serialize_value