Commit c65b0992 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

libgimpconfig/gimpconfig-serialize.[ch] add

2008-05-18  Michael Natterer  <mitch@gimp.org>

	* libgimpconfig/gimpconfig-serialize.[ch]
	* libgimpconfig/gimpconfig.def: add
	gimp_config_serialize_property_by_name().

	* app/gegl/gimpcolorbalanceconfig.c
	* app/gegl/gimpcurvesconfig.c
	* app/gegl/gimphuesaturationconfig.c
	* app/gegl/gimplevelsconfig.c: implement serialize() and
	deserialize() and make sure the properties which change when the
	channel/range property changes are handled correctly. Not too
	ugly but it's still a hack...


svn path=/trunk/; revision=25703
parent 4d0b4464
2008-05-18 Michael Natterer <mitch@gimp.org>
* libgimpconfig/gimpconfig-serialize.[ch]
* libgimpconfig/gimpconfig.def: add
gimp_config_serialize_property_by_name().
* app/gegl/gimpcolorbalanceconfig.c
* app/gegl/gimpcurvesconfig.c
* app/gegl/gimphuesaturationconfig.c
* app/gegl/gimplevelsconfig.c: implement serialize() and
deserialize() and make sure the properties which change when the
channel/range property changes are handled correctly. Not too
ugly but it's still a hack...
2008-05-18 Michael Natterer <mitch@gimp.org>
* app/tools/gimpimagemaptool.c: made the lists of recent settings
......
......@@ -48,21 +48,28 @@ enum
static void gimp_color_balance_config_iface_init (GimpConfigInterface *iface);
static void gimp_color_balance_config_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_color_balance_config_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static gboolean gimp_color_balance_config_equal (GimpConfig *a,
GimpConfig *b);
static void gimp_color_balance_config_reset (GimpConfig *config);
static gboolean gimp_color_balance_config_copy (GimpConfig *src,
GimpConfig *dest,
GParamFlags flags);
static void gimp_color_balance_config_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_color_balance_config_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static gboolean gimp_color_balance_config_serialize (GimpConfig *config,
GimpConfigWriter *writer,
gpointer data);
static gboolean gimp_color_balance_config_deserialize (GimpConfig *config,
GScanner *scanner,
gint nest_level,
gpointer data);
static gboolean gimp_color_balance_config_equal (GimpConfig *a,
GimpConfig *b);
static void gimp_color_balance_config_reset (GimpConfig *config);
static gboolean gimp_color_balance_config_copy (GimpConfig *src,
GimpConfig *dest,
GParamFlags flags);
G_DEFINE_TYPE_WITH_CODE (GimpColorBalanceConfig, gimp_color_balance_config,
......@@ -114,9 +121,11 @@ gimp_color_balance_config_class_init (GimpColorBalanceConfigClass *klass)
static void
gimp_color_balance_config_iface_init (GimpConfigInterface *iface)
{
iface->equal = gimp_color_balance_config_equal;
iface->reset = gimp_color_balance_config_reset;
iface->copy = gimp_color_balance_config_copy;
iface->serialize = gimp_color_balance_config_serialize;
iface->deserialize = gimp_color_balance_config_deserialize;
iface->equal = gimp_color_balance_config_equal;
iface->reset = gimp_color_balance_config_reset;
iface->copy = gimp_color_balance_config_copy;
}
static void
......@@ -200,6 +209,68 @@ gimp_color_balance_config_set_property (GObject *object,
}
}
static gboolean
gimp_color_balance_config_serialize (GimpConfig *config,
GimpConfigWriter *writer,
gpointer data)
{
GimpColorBalanceConfig *bc_config = GIMP_COLOR_BALANCE_CONFIG (config);
GimpTransferMode range;
GimpTransferMode old_range;
gboolean success = TRUE;
old_range = bc_config->range;
for (range = GIMP_SHADOWS; range <= GIMP_HIGHLIGHTS; range++)
{
bc_config->range = range;
success = (gimp_config_serialize_property_by_name (config,
"range",
writer) &&
gimp_config_serialize_property_by_name (config,
"cyan-red",
writer) &&
gimp_config_serialize_property_by_name (config,
"magenta-green",
writer) &&
gimp_config_serialize_property_by_name (config,
"yellow-blue",
writer));
if (! success)
break;
}
if (success)
success = gimp_config_serialize_property_by_name (config,
"preserve-luminosity",
writer);
bc_config->range = old_range;
return success;
}
static gboolean
gimp_color_balance_config_deserialize (GimpConfig *config,
GScanner *scanner,
gint nest_level,
gpointer data)
{
GimpColorBalanceConfig *cb_config = GIMP_COLOR_BALANCE_CONFIG (config);
GimpTransferMode old_range;
gboolean success = TRUE;
old_range = cb_config->range;
success = gimp_config_deserialize_properties (config, scanner, nest_level);
g_object_set (config, "range", old_range, NULL);
return success;
}
static gboolean
gimp_color_balance_config_equal (GimpConfig *a,
GimpConfig *b)
......
......@@ -64,6 +64,13 @@ static void gimp_curves_config_set_property (GObject *object,
const GValue *value,
GParamSpec *pspec);
static gboolean gimp_curves_config_serialize (GimpConfig *config,
GimpConfigWriter *writer,
gpointer data);
static gboolean gimp_curves_config_deserialize (GimpConfig *config,
GScanner *scanner,
gint nest_level,
gpointer data);
static gboolean gimp_curves_config_equal (GimpConfig *a,
GimpConfig *b);
static void gimp_curves_config_reset (GimpConfig *config);
......@@ -111,9 +118,11 @@ gimp_curves_config_class_init (GimpCurvesConfigClass *klass)
static void
gimp_curves_config_iface_init (GimpConfigInterface *iface)
{
iface->equal = gimp_curves_config_equal;
iface->reset = gimp_curves_config_reset;
iface->copy = gimp_curves_config_copy;
iface->serialize = gimp_curves_config_serialize;
iface->deserialize = gimp_curves_config_deserialize;
iface->equal = gimp_curves_config_equal;
iface->reset = gimp_curves_config_reset;
iface->copy = gimp_curves_config_copy;
}
static void
......@@ -216,6 +225,54 @@ gimp_curves_config_set_property (GObject *object,
}
}
static gboolean
gimp_curves_config_serialize (GimpConfig *config,
GimpConfigWriter *writer,
gpointer data)
{
GimpCurvesConfig *c_config = GIMP_CURVES_CONFIG (config);
GimpHistogramChannel channel;
GimpHistogramChannel old_channel;
gboolean success = TRUE;
old_channel = c_config->channel;
for (channel = GIMP_HISTOGRAM_VALUE;
channel <= GIMP_HISTOGRAM_ALPHA;
channel++)
{
c_config->channel = channel;
success = gimp_config_serialize_properties (config, writer);
if (! success)
break;
}
c_config->channel = old_channel;
return success;
}
static gboolean
gimp_curves_config_deserialize (GimpConfig *config,
GScanner *scanner,
gint nest_level,
gpointer data)
{
GimpCurvesConfig *c_config = GIMP_CURVES_CONFIG (config);
GimpHistogramChannel old_channel;
gboolean success = TRUE;
old_channel = c_config->channel;
success = gimp_config_deserialize_properties (config, scanner, nest_level);
g_object_set (config, "channel", old_channel, NULL);
return success;
}
static gboolean
gimp_curves_config_equal (GimpConfig *a,
GimpConfig *b)
......
......@@ -46,21 +46,28 @@ enum
static void gimp_hue_saturation_config_iface_init (GimpConfigInterface *iface);
static void gimp_hue_saturation_config_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_hue_saturation_config_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static gboolean gimp_hue_saturation_config_equal (GimpConfig *a,
GimpConfig *b);
static void gimp_hue_saturation_config_reset (GimpConfig *config);
static gboolean gimp_hue_saturation_config_copy (GimpConfig *src,
GimpConfig *dest,
GParamFlags flags);
static void gimp_hue_saturation_config_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_hue_saturation_config_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static gboolean gimp_hue_saturation_config_serialize (GimpConfig *config,
GimpConfigWriter *writer,
gpointer data);
static gboolean gimp_hue_saturation_config_deserialize (GimpConfig *config,
GScanner *scanner,
gint nest_level,
gpointer data);
static gboolean gimp_hue_saturation_config_equal (GimpConfig *a,
GimpConfig *b);
static void gimp_hue_saturation_config_reset (GimpConfig *config);
static gboolean gimp_hue_saturation_config_copy (GimpConfig *src,
GimpConfig *dest,
GParamFlags flags);
G_DEFINE_TYPE_WITH_CODE (GimpHueSaturationConfig, gimp_hue_saturation_config,
......@@ -112,9 +119,11 @@ gimp_hue_saturation_config_class_init (GimpHueSaturationConfigClass *klass)
static void
gimp_hue_saturation_config_iface_init (GimpConfigInterface *iface)
{
iface->equal = gimp_hue_saturation_config_equal;
iface->reset = gimp_hue_saturation_config_reset;
iface->copy = gimp_hue_saturation_config_copy;
iface->serialize = gimp_hue_saturation_config_serialize;
iface->deserialize = gimp_hue_saturation_config_deserialize;
iface->equal = gimp_hue_saturation_config_equal;
iface->reset = gimp_hue_saturation_config_reset;
iface->copy = gimp_hue_saturation_config_copy;
}
static void
......@@ -198,6 +207,63 @@ gimp_hue_saturation_config_set_property (GObject *object,
}
}
static gboolean
gimp_hue_saturation_config_serialize (GimpConfig *config,
GimpConfigWriter *writer,
gpointer data)
{
GimpHueSaturationConfig *hs_config = GIMP_HUE_SATURATION_CONFIG (config);
GimpHueRange range;
GimpHueRange old_range;
gboolean success = TRUE;
old_range = hs_config->range;
for (range = GIMP_ALL_HUES; range <= GIMP_MAGENTA_HUES; range++)
{
hs_config->range = range;
success = (gimp_config_serialize_property_by_name (config, "range",
writer) &&
gimp_config_serialize_property_by_name (config, "hue",
writer) &&
gimp_config_serialize_property_by_name (config, "saturation",
writer) &&
gimp_config_serialize_property_by_name (config, "lightness",
writer));
if (! success)
break;
}
if (success)
success = gimp_config_serialize_property_by_name (config, "overlap",
writer);
hs_config->range = old_range;
return success;
}
static gboolean
gimp_hue_saturation_config_deserialize (GimpConfig *config,
GScanner *scanner,
gint nest_level,
gpointer data)
{
GimpHueSaturationConfig *hs_config = GIMP_HUE_SATURATION_CONFIG (config);
GimpHueRange old_range;
gboolean success = TRUE;
old_range = hs_config->range;
success = gimp_config_deserialize_properties (config, scanner, nest_level);
g_object_set (config, "range", old_range, NULL);
return success;
}
static gboolean
gimp_hue_saturation_config_equal (GimpConfig *a,
GimpConfig *b)
......
......@@ -60,21 +60,28 @@ enum
static void gimp_levels_config_iface_init (GimpConfigInterface *iface);
static void gimp_levels_config_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_levels_config_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static gboolean gimp_levels_config_equal (GimpConfig *a,
GimpConfig *b);
static void gimp_levels_config_reset (GimpConfig *config);
static gboolean gimp_levels_config_copy (GimpConfig *src,
GimpConfig *dest,
GParamFlags flags);
static void gimp_levels_config_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_levels_config_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static gboolean gimp_levels_config_serialize (GimpConfig *config,
GimpConfigWriter *writer,
gpointer data);
static gboolean gimp_levels_config_deserialize (GimpConfig *config,
GScanner *scanner,
gint nest_level,
gpointer data);
static gboolean gimp_levels_config_equal (GimpConfig *a,
GimpConfig *b);
static void gimp_levels_config_reset (GimpConfig *config);
static gboolean gimp_levels_config_copy (GimpConfig *src,
GimpConfig *dest,
GParamFlags flags);
G_DEFINE_TYPE_WITH_CODE (GimpLevelsConfig, gimp_levels_config,
......@@ -131,9 +138,11 @@ gimp_levels_config_class_init (GimpLevelsConfigClass *klass)
static void
gimp_levels_config_iface_init (GimpConfigInterface *iface)
{
iface->equal = gimp_levels_config_equal;
iface->reset = gimp_levels_config_reset;
iface->copy = gimp_levels_config_copy;
iface->serialize = gimp_levels_config_serialize;
iface->deserialize = gimp_levels_config_deserialize;
iface->equal = gimp_levels_config_equal;
iface->reset = gimp_levels_config_reset;
iface->copy = gimp_levels_config_copy;
}
static void
......@@ -227,6 +236,54 @@ gimp_levels_config_set_property (GObject *object,
}
}
static gboolean
gimp_levels_config_serialize (GimpConfig *config,
GimpConfigWriter *writer,
gpointer data)
{
GimpLevelsConfig *l_config = GIMP_LEVELS_CONFIG (config);
GimpHistogramChannel channel;
GimpHistogramChannel old_channel;
gboolean success = TRUE;
old_channel = l_config->channel;
for (channel = GIMP_HISTOGRAM_VALUE;
channel <= GIMP_HISTOGRAM_ALPHA;
channel++)
{
l_config->channel = channel;
success = gimp_config_serialize_properties (config, writer);
if (! success)
break;
}
l_config->channel = old_channel;
return success;
}
static gboolean
gimp_levels_config_deserialize (GimpConfig *config,
GScanner *scanner,
gint nest_level,
gpointer data)
{
GimpLevelsConfig *l_config = GIMP_LEVELS_CONFIG (config);
GimpHistogramChannel old_channel;
gboolean success = TRUE;
old_channel = l_config->channel;
success = gimp_config_deserialize_properties (config, scanner, nest_level);
g_object_set (config, "channel", old_channel, NULL);
return success;
}
static gboolean
gimp_levels_config_equal (GimpConfig *a,
GimpConfig *b)
......
......@@ -308,6 +308,34 @@ gimp_config_serialize_property (GimpConfig *config,
return success;
}
/**
* gimp_config_serialize_property_by_name:
* @config: a #GimpConfig.
* @prop_name: the property's name.
* @writer: a #GimpConfigWriter.
*
* This function serializes a single object property to the @writer.
*
* Returns: %TRUE if serialization succeeded, %FALSE otherwise
*
* Since: GIMP 2.6
**/
gboolean
gimp_config_serialize_property_by_name (GimpConfig *config,
const gchar *prop_name,
GimpConfigWriter *writer)
{
GParamSpec *pspec;
pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (config),
prop_name);
if (! pspec)
return FALSE;
return gimp_config_serialize_property (config, pspec, writer);
}
/**
* gimp_config_serialize_value:
* @value: a #GValue.
......
......@@ -36,6 +36,9 @@ gboolean gimp_config_serialize_changed_properties (GimpConfig *config,
gboolean gimp_config_serialize_property (GimpConfig *config,
GParamSpec *param_spec,
GimpConfigWriter *writer);
gboolean gimp_config_serialize_property_by_name (GimpConfig *config,
const gchar *prop_name,
GimpConfigWriter *writer);
gboolean gimp_config_serialize_value (const GValue *value,
GString *str,
gboolean escaped);
......
......@@ -24,6 +24,7 @@ EXPORTS
gimp_config_serialize_changed_properties
gimp_config_serialize_properties
gimp_config_serialize_property
gimp_config_serialize_property_by_name
gimp_config_serialize_to_fd
gimp_config_serialize_to_file
gimp_config_serialize_to_string
......
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