Commit 82b11c36 authored by Michael Natterer's avatar Michael Natterer 😴

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

parent 3c187168
......@@ -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.
......@@ -618,7 +658,7 @@ gimp_config_deserialize_stream (GimpConfig *config,
* Since: 2.4
**/
gboolean
gimp_config_deserialize_string (GimpConfig *config,
gimp_config_deserialize_string (GimpConfig *config,
const gchar *text,
gint text_len,
gpointer data,
......@@ -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
......
......@@ -71,66 +71,77 @@ struct _GimpConfigInterface
};
GType gimp_config_get_type (void) G_GNUC_CONST;
gboolean gimp_config_serialize_to_file (GimpConfig *config,
const gchar *filename,
const gchar *header,
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_stream (GimpConfig *config,
GOutputStream *output,
const gchar *header,
const gchar *footer,
gpointer data,
GError **error);
gboolean gimp_config_serialize_to_fd (GimpConfig *config,
gint fd,
gpointer data);
gchar * gimp_config_serialize_to_string (GimpConfig *config,
gpointer data);
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_stream (GimpConfig *config,
GInputStream *input,
gpointer data,
GError **error);
gboolean gimp_config_deserialize_string (GimpConfig *config,
const gchar *text,
gint text_len,
gpointer data,
GError **error);
gboolean gimp_config_deserialize_return (GScanner *scanner,
GTokenType expected_token,
gint nest_level);
gboolean gimp_config_serialize (GimpConfig *config,
GimpConfigWriter *writer,
gpointer data);
gboolean gimp_config_deserialize (GimpConfig *config,
GScanner *scanner,
gint nest_level,
gpointer data);
gpointer gimp_config_duplicate (GimpConfig *config);
gboolean gimp_config_is_equal_to (GimpConfig *a,
GimpConfig *b);
void gimp_config_reset (GimpConfig *config);
gboolean gimp_config_copy (GimpConfig *src,
GimpConfig *dest,
GParamFlags flags);
GType gimp_config_get_type (void) G_GNUC_CONST;
gboolean gimp_config_serialize_to_file (GimpConfig *config,
const gchar *filename,
const gchar *header,
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_stream (GimpConfig *config,
GOutputStream *output,
const gchar *header,
const gchar *footer,
gpointer data,
GError **error);
gboolean gimp_config_serialize_to_fd (GimpConfig *config,
gint fd,
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,
GError **error);
gboolean gimp_config_deserialize_gfile (GimpConfig *config,
GFile *file,
gpointer data,
GError **error);
gboolean gimp_config_deserialize_stream (GimpConfig *config,
GInputStream *input,
gpointer data,
GError **error);
gboolean gimp_config_deserialize_string (GimpConfig *config,
const gchar *text,
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);
gboolean gimp_config_serialize (GimpConfig *config,
GimpConfigWriter *writer,
gpointer data);
gboolean gimp_config_deserialize (GimpConfig *config,
GScanner *scanner,
gint nest_level,
gpointer data);
gpointer gimp_config_duplicate (GimpConfig *config);
gboolean gimp_config_is_equal_to (GimpConfig *a,
GimpConfig *b);
void gimp_config_reset (GimpConfig *config);
gboolean gimp_config_copy (GimpConfig *src,
GimpConfig *dest,
GParamFlags flags);
G_END_DECLS
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment