renamed gimp_config_serialize_changed_properties() to

2003-02-28  Sven Neumann  <sven@gimp.org>

	* app/config/gimpconfig-serialize.[ch]: renamed
	gimp_config_serialize_changed_properties() to
	gimp_config_serialize_properties_diff() and added a new function
	gimp_config_serialize_changed_properties() that saves only
	properties that have been changed from their default values.

	* app/config/gimprc.c: follow the function name change.

	* app/core/gimpcontext.c: override GimpConfigInterface::serialize
	with gimp_config_serialize_changed_properties() so we store only
	tool_options that have been changed from their default values.
This commit is contained in:
Sven Neumann 2003-02-28 13:58:19 +00:00 committed by Sven Neumann
parent 9519de07e1
commit 25c715c1f4
7 changed files with 198 additions and 36 deletions

View File

@ -1,3 +1,17 @@
2003-02-28 Sven Neumann <sven@gimp.org>
* app/config/gimpconfig-serialize.[ch]: renamed
gimp_config_serialize_changed_properties() to
gimp_config_serialize_properties_diff() and added a new function
gimp_config_serialize_changed_properties() that saves only
properties that have been changed from their default values.
* app/config/gimprc.c: follow the function name change.
* app/core/gimpcontext.c: override GimpConfigInterface::serialize
with gimp_config_serialize_changed_properties() so we store only
tool_options that have been changed from their default values.
2003-02-28 Sven Neumann <sven@gimp.org>
* app/config/gimpconfig-serialize.c

View File

@ -101,19 +101,82 @@ gimp_config_serialize_properties (GObject *object,
return TRUE;
}
/**
* gimp_config_serialize_properties:
* @new: a #GObject.
* @old: a #GObject of the same type as @new.
* gimp_config_serialize_changed_properties:
* @object: a #GObject.
* @fd: a file descriptor to write to.
*
* This function compares the objects @new and @old and writes all properties
* of @new that have different values than @old to the file descriptor @fd.
* This function writes all object properties that have been changed from
* their default values to the file descriptor @fd.
**/
gboolean
gimp_config_serialize_changed_properties (GObject *new,
GObject *old,
gimp_config_serialize_changed_properties (GObject *object,
gint fd,
gint indent_level)
{
GObjectClass *klass;
GParamSpec **property_specs;
guint n_property_specs;
guint i;
GString *str;
GValue value = { 0, };
g_return_val_if_fail (G_IS_OBJECT (object), FALSE);
klass = G_OBJECT_GET_CLASS (object);
property_specs = g_object_class_list_properties (klass, &n_property_specs);
if (! property_specs)
return TRUE;
str = g_string_new (NULL);
for (i = 0; i < n_property_specs; i++)
{
GParamSpec *prop_spec = property_specs[i];
if (! (prop_spec->flags & GIMP_PARAM_SERIALIZE))
continue;
g_value_init (&value, prop_spec->value_type);
g_object_get_property (object, prop_spec->name, &value);
if (! g_param_value_defaults (prop_spec, &value))
{
gimp_config_string_indent (str, indent_level);
if (gimp_config_serialize_property (object, prop_spec, str, TRUE))
{
if (write (fd, str->str, str->len) == -1)
return FALSE;
}
g_string_truncate (str, 0);
}
g_value_unset (&value);
}
g_free (property_specs);
g_string_free (str, TRUE);
return TRUE;
}
/**
* gimp_config_serialize_properties_diff:
* @object: a #GObject.
* @compare: a #GObject of the same type as @object.
* @fd: a file descriptor to write to.
*
* This function compares @object and @compare and writes all
* properties of @object that have different values than @compare to
* the file descriptor @fd.
**/
gboolean
gimp_config_serialize_properties_diff (GObject *object,
GObject *compare,
gint fd,
gint indent_level)
{
@ -122,14 +185,14 @@ gimp_config_serialize_changed_properties (GObject *new,
GList *list;
GString *str;
g_return_val_if_fail (G_IS_OBJECT (new), FALSE);
g_return_val_if_fail (G_IS_OBJECT (old), FALSE);
g_return_val_if_fail (G_TYPE_FROM_INSTANCE (new) ==
G_TYPE_FROM_INSTANCE (old), FALSE);
g_return_val_if_fail (G_IS_OBJECT (object), FALSE);
g_return_val_if_fail (G_IS_OBJECT (compare), FALSE);
g_return_val_if_fail (G_TYPE_FROM_INSTANCE (object) ==
G_TYPE_FROM_INSTANCE (compare), FALSE);
klass = G_OBJECT_GET_CLASS (new);
klass = G_OBJECT_GET_CLASS (object);
diff = gimp_config_diff (new, old, GIMP_PARAM_SERIALIZE);
diff = gimp_config_diff (object, compare, GIMP_PARAM_SERIALIZE);
if (! diff)
return TRUE;
@ -145,7 +208,7 @@ gimp_config_serialize_changed_properties (GObject *new,
gimp_config_string_indent (str, indent_level);
if (gimp_config_serialize_property (new, prop_spec, str, TRUE))
if (gimp_config_serialize_property (object, prop_spec, str, TRUE))
{
if (write (fd, str->str, str->len) == -1)
return FALSE;

View File

@ -26,8 +26,11 @@
gboolean gimp_config_serialize_properties (GObject *object,
gint fd,
gint indent_level);
gboolean gimp_config_serialize_changed_properties (GObject *new,
GObject *old,
gboolean gimp_config_serialize_changed_properties (GObject *object,
gint fd,
gint indent_level);
gboolean gimp_config_serialize_properties_diff (GObject *object,
GObject *compare,
gint fd,
gint indent_level);
gboolean gimp_config_serialize_unknown_tokens (GObject *object,

View File

@ -289,7 +289,7 @@ gimp_rc_serialize (GObject *object,
{
if (data && GIMP_IS_RC (data))
{
if (!gimp_config_serialize_changed_properties (object, G_OBJECT (data),
if (!gimp_config_serialize_properties_diff (object, G_OBJECT (data),
fd, indent_level))
return FALSE;
}

View File

@ -31,6 +31,7 @@
#include "base/temp-buf.h"
#include "config/gimpconfig-serialize.h"
#include "config/gimpcoreconfig.h"
#include "gimp.h"
@ -85,6 +86,10 @@ static void gimp_context_get_property (GObject *object,
GParamSpec *pspec);
static gsize gimp_context_get_memsize (GimpObject *object);
static gboolean gimp_context_serialize (GObject *object,
gint fd,
gint indent_level,
gpointer data);
static gboolean gimp_context_serialize_property (GObject *object,
guint property_id,
const GValue *value,
@ -622,6 +627,8 @@ gimp_context_init (GimpContext *context)
static void
gimp_context_config_iface_init (GimpConfigInterface *config_iface)
{
config_iface->serialize = gimp_context_serialize;
config_iface->serialize_property = gimp_context_serialize_property;
config_iface->deserialize_property = gimp_context_deserialize_property;
}
@ -970,6 +977,15 @@ gimp_context_get_memsize (GimpObject *object)
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object);
}
static gboolean
gimp_context_serialize (GObject *object,
gint fd,
gint indent_level,
gpointer data)
{
return gimp_config_serialize_changed_properties (object, fd, indent_level);
}
static gboolean
gimp_context_serialize_property (GObject *object,
guint property_id,

View File

@ -101,19 +101,82 @@ gimp_config_serialize_properties (GObject *object,
return TRUE;
}
/**
* gimp_config_serialize_properties:
* @new: a #GObject.
* @old: a #GObject of the same type as @new.
* gimp_config_serialize_changed_properties:
* @object: a #GObject.
* @fd: a file descriptor to write to.
*
* This function compares the objects @new and @old and writes all properties
* of @new that have different values than @old to the file descriptor @fd.
* This function writes all object properties that have been changed from
* their default values to the file descriptor @fd.
**/
gboolean
gimp_config_serialize_changed_properties (GObject *new,
GObject *old,
gimp_config_serialize_changed_properties (GObject *object,
gint fd,
gint indent_level)
{
GObjectClass *klass;
GParamSpec **property_specs;
guint n_property_specs;
guint i;
GString *str;
GValue value = { 0, };
g_return_val_if_fail (G_IS_OBJECT (object), FALSE);
klass = G_OBJECT_GET_CLASS (object);
property_specs = g_object_class_list_properties (klass, &n_property_specs);
if (! property_specs)
return TRUE;
str = g_string_new (NULL);
for (i = 0; i < n_property_specs; i++)
{
GParamSpec *prop_spec = property_specs[i];
if (! (prop_spec->flags & GIMP_PARAM_SERIALIZE))
continue;
g_value_init (&value, prop_spec->value_type);
g_object_get_property (object, prop_spec->name, &value);
if (! g_param_value_defaults (prop_spec, &value))
{
gimp_config_string_indent (str, indent_level);
if (gimp_config_serialize_property (object, prop_spec, str, TRUE))
{
if (write (fd, str->str, str->len) == -1)
return FALSE;
}
g_string_truncate (str, 0);
}
g_value_unset (&value);
}
g_free (property_specs);
g_string_free (str, TRUE);
return TRUE;
}
/**
* gimp_config_serialize_properties_diff:
* @object: a #GObject.
* @compare: a #GObject of the same type as @object.
* @fd: a file descriptor to write to.
*
* This function compares @object and @compare and writes all
* properties of @object that have different values than @compare to
* the file descriptor @fd.
**/
gboolean
gimp_config_serialize_properties_diff (GObject *object,
GObject *compare,
gint fd,
gint indent_level)
{
@ -122,14 +185,14 @@ gimp_config_serialize_changed_properties (GObject *new,
GList *list;
GString *str;
g_return_val_if_fail (G_IS_OBJECT (new), FALSE);
g_return_val_if_fail (G_IS_OBJECT (old), FALSE);
g_return_val_if_fail (G_TYPE_FROM_INSTANCE (new) ==
G_TYPE_FROM_INSTANCE (old), FALSE);
g_return_val_if_fail (G_IS_OBJECT (object), FALSE);
g_return_val_if_fail (G_IS_OBJECT (compare), FALSE);
g_return_val_if_fail (G_TYPE_FROM_INSTANCE (object) ==
G_TYPE_FROM_INSTANCE (compare), FALSE);
klass = G_OBJECT_GET_CLASS (new);
klass = G_OBJECT_GET_CLASS (object);
diff = gimp_config_diff (new, old, GIMP_PARAM_SERIALIZE);
diff = gimp_config_diff (object, compare, GIMP_PARAM_SERIALIZE);
if (! diff)
return TRUE;
@ -145,7 +208,7 @@ gimp_config_serialize_changed_properties (GObject *new,
gimp_config_string_indent (str, indent_level);
if (gimp_config_serialize_property (new, prop_spec, str, TRUE))
if (gimp_config_serialize_property (object, prop_spec, str, TRUE))
{
if (write (fd, str->str, str->len) == -1)
return FALSE;

View File

@ -26,8 +26,11 @@
gboolean gimp_config_serialize_properties (GObject *object,
gint fd,
gint indent_level);
gboolean gimp_config_serialize_changed_properties (GObject *new,
GObject *old,
gboolean gimp_config_serialize_changed_properties (GObject *object,
gint fd,
gint indent_level);
gboolean gimp_config_serialize_properties_diff (GObject *object,
GObject *compare,
gint fd,
gint indent_level);
gboolean gimp_config_serialize_unknown_tokens (GObject *object,