gimp/libgimpconfig/gimpconfig-serialize.c

447 lines
12 KiB
C
Raw Normal View History

/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* Object properties serialization routines
* Copyright (C) 2001-2002 Sven Neumann <sven@gimp.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <stdio.h>
#include <string.h>
from now on use make.msc from $(TOP)/glib/build/win32; all occurences of 2001-02-17 Hans Breuer <hans@breuer.org> * */*/makefile.msc */makefile.msc : from now on use make.msc from $(TOP)/glib/build/win32; all occurences of DIRENT removed and general update * app/config/makefile.msc app/paint/makefile.msc app/plug-in/makefile.msc themes/Default/makefile.msc : new files * app/base/base.c : ported to GDir usage * app/config/gimpconfig-serialize.c : app/config/gimpconfig-deserialize.c : HAVE_UNISTD_H * app/config/gimpconfig.c : app/config/gimprc.c : HAVE_UNISTD_H, use <io.h> for open() prototype and merged pmode parameter (_S_IREAD | _S_IWRITE) * app/core/cpercep.c : msvc doesn't have cbrt(), provide it via pow(). Also include <glib.h> for painless 'inline' definition. * app/core/gimpdatafiles.c : ported to GDir usage * app/core/gimpimage-convert.c : work around a msvc compiler limitation (can't convert from uint64 to double) * app/file/file-open.c app/file/file-save.c : access() -> _access() for G_OS_WIN32 * app/plug-in/plug-in.c : HAVE_UNISTD_H and <io.h> * libgimpbase/gimpbase.def : updated externals * libgimpbase/gimpenv.c : define WIN32_LEAN_AND_MEAN to avoid clashes with incompatible DATADIR definitions * libgimpcolor/gimpcolor.def : updated externals * lingimpmath/gimpmath.def : updated externals * libgimpwidgets/gimpwidgets.def : updated externals * libgimpwidgets/libgimp-glue.c : adapt to const changes of some prototypes * plug-ins/makefile.msc : disabled gdyntext * plug-ins/gap/iter_ALT/*/*.inc : GimpRunModeType -> GimpRunMode * plug-ins/FractalExplorer/FractalExplorer.c : * plug-ins/gap/gap_lib.c : * plug-ins/gfig/gfig.c : * plug-ins/gflare/gflare.c : * plug-ins/gimpressionist/gimpressionist.c : replaced DIRENT usage with GDir * plug-ins/script-fu/script-fu-scripts.c : #include <windows.h> to get the Sleep() prototype
2002-02-17 23:55:54 +08:00
#ifdef HAVE_UNISTD_H
#include <unistd.h>
from now on use make.msc from $(TOP)/glib/build/win32; all occurences of 2001-02-17 Hans Breuer <hans@breuer.org> * */*/makefile.msc */makefile.msc : from now on use make.msc from $(TOP)/glib/build/win32; all occurences of DIRENT removed and general update * app/config/makefile.msc app/paint/makefile.msc app/plug-in/makefile.msc themes/Default/makefile.msc : new files * app/base/base.c : ported to GDir usage * app/config/gimpconfig-serialize.c : app/config/gimpconfig-deserialize.c : HAVE_UNISTD_H * app/config/gimpconfig.c : app/config/gimprc.c : HAVE_UNISTD_H, use <io.h> for open() prototype and merged pmode parameter (_S_IREAD | _S_IWRITE) * app/core/cpercep.c : msvc doesn't have cbrt(), provide it via pow(). Also include <glib.h> for painless 'inline' definition. * app/core/gimpdatafiles.c : ported to GDir usage * app/core/gimpimage-convert.c : work around a msvc compiler limitation (can't convert from uint64 to double) * app/file/file-open.c app/file/file-save.c : access() -> _access() for G_OS_WIN32 * app/plug-in/plug-in.c : HAVE_UNISTD_H and <io.h> * libgimpbase/gimpbase.def : updated externals * libgimpbase/gimpenv.c : define WIN32_LEAN_AND_MEAN to avoid clashes with incompatible DATADIR definitions * libgimpcolor/gimpcolor.def : updated externals * lingimpmath/gimpmath.def : updated externals * libgimpwidgets/gimpwidgets.def : updated externals * libgimpwidgets/libgimp-glue.c : adapt to const changes of some prototypes * plug-ins/makefile.msc : disabled gdyntext * plug-ins/gap/iter_ALT/*/*.inc : GimpRunModeType -> GimpRunMode * plug-ins/FractalExplorer/FractalExplorer.c : * plug-ins/gap/gap_lib.c : * plug-ins/gfig/gfig.c : * plug-ins/gflare/gflare.c : * plug-ins/gimpressionist/gimpressionist.c : replaced DIRENT usage with GDir * plug-ins/script-fu/script-fu-scripts.c : #include <windows.h> to get the Sleep() prototype
2002-02-17 23:55:54 +08:00
#endif
#include <glib-object.h>
#define GETTEXT_PACKAGE 2001-03-28 Hans Breuer <hans@breuer.org> * config.h.win32 : #define GETTEXT_PACKAGE * makefile.msc : add theme rule * app/makefile.msc : gimp.exe depends on all the libs and general update * app/base/makefile.msc : updated * app/config/gimpconfig-serialize.c : #include <io.h> for win32 * app/config/gimpconfig-types.c : #include <string.h> * app/core/gimpcontext.c app/core/gimpcontainer.c app/core/gimptoolinfo.c : #include <string.h> * app/core/gimpdocuments.c (gimp_documents_save_func) : need to g_strescape() the filename to not make backslashes vanish during de-serialization * app/core/gimpimagefile.c : #define S_ISREG for G_OS_WIN32 * app/core/makefile.msc : add -DGIMP_COMPILATION required for cpercep.c build * app/display/gimpdisplayshell.c : #include <string.h> * app/display/makefile.msc : -FImsvc_recommended_pragmas.h, G_LOG_DOMAIN definition and object file update * app/file/makefile.msc : -FImsvc_recommended_pragmas.h, G_LOG_DOMAIN definition * app/file/file-open.c (file_open_with_proc_and_display) : use absolute filename for gimp_documents_add() * app/gui/channel-commands.c app/gui/colormap-editor-commands.c app/gui/edit-commands.c app/gui/vectors-commands.c : #include <string.h> * app/gui/makefile.msc : updated * app/gui/menus.c : use g_file_test() instead of access() to avoid inclusion <unistd.h> * app/paint/makefile.msc : updated * app/plug-in/plug-in-params.c : #include <string.h> * app/plug-in/makefile.msc : updated * app/plug-in/plug-in-def.h : #include <time.h> for time_t * app/plug-in/plug-in.c : remove definition of S_IFREG * app/plug-in/gap/gap_arr_dialog.c : include <config.h> before including libgimp/libgimp-intl.h * app/tools/makefile.msc : updated * app/vectors/makefile.msc : new file * app/widgets/makefile.msc : updated * libgimp/gimp.def : updated externals * libgimpwidgets/gimpwidgets.def : updated externals * modules/makefile.msc : updated and disabled colorsel_gtk. * plug-in/makefile.msc : don't define GETTEXT_PACKAGE * themes/Default/images/makefile.msc : moved makefile.msc from .. and adapted pathes to images
2002-03-28 08:10:56 +08:00
#ifdef G_OS_WIN32
#include <io.h>
#endif
#include "libgimpbase/gimpbase.h"
#include "libgimpcolor/gimpcolor.h"
#include "gimpconfig.h"
#include "gimpconfig-params.h"
#include "gimpconfig-serialize.h"
#include "gimpconfig-types.h"
#include "gimpconfig-utils.h"
static gboolean gimp_config_serialize_property (GObject *object,
GParamSpec *param_spec,
GString *str,
gboolean escaped);
static void serialize_unknown_token (const gchar *key,
const gchar *value,
gpointer data);
/**
* gimp_config_serialize_properties:
* @object: a #GObject.
* @fd: a file descriptor to write to.
*
* This function writes all object properties to the file descriptor @fd.
**/
gboolean
removed from CVS, they are generated. 2001-12-07 Sven Neumann <sven@gimp.org> * app/core/gimpmarshal.[ch]: removed from CVS, they are generated. * app/base/Makefile.am * app/base/base-enums.h: new file defining enums that are to be registered. Used to build app/base/base-enums.c. * app/base/base-types.h: include base-enums.h. * tools/pdbgen/Makefile.am * tools/pdbgen/enumcode.pl * tools/pdbgen/enums.pl: parse the new base-enums.h file and modified the perl voodoo so it doesn't prefix enums with GIMP_ that are already properly namespaced. * app/core/core-types.h: don't need to chop GIMP from enum. * app/pdb/color_cmds.c * app/pdb/tools_cmds.c * libgimp/gimpenums.h * plug-ins/script-fu/script-fu-constants.c: regenerated. * app/config/gimpconfig-deserialize.[ch] * app/config/gimpconfig-serialize.[ch] * app/config/gimpconfig.[ch]: made GimpConfig an interface including a reasonable default implementation that works on object properties. * app/config/Makefile.am * app/config/gimpbaseconfig.[ch]: new GimpBaseConfig using the GimpConfig interface. Yet only used for testing from app/main.c. * app/main.c: test the new GimpBaseConfig object. * app/gimprc.c * app/base/base-config.h * app/base/*.c * app/core/gimpdatafiles.c * app/core/gimpdrawable-transform.c * app/core/gimppreviewcache.c * app/gui/preferences-dialog.c * app/paint-funcs/paint-funcs.c * app/xcf/xcf-seek.c: need to include glib-object.h since base-config contains registered enums now. Follow name change of InterpolationType to GimpInterpolationType.
2001-12-08 00:10:53 +08:00
gimp_config_serialize_properties (GObject *object,
gint fd,
gint indent_level)
{
removed from CVS, they are generated. 2001-12-07 Sven Neumann <sven@gimp.org> * app/core/gimpmarshal.[ch]: removed from CVS, they are generated. * app/base/Makefile.am * app/base/base-enums.h: new file defining enums that are to be registered. Used to build app/base/base-enums.c. * app/base/base-types.h: include base-enums.h. * tools/pdbgen/Makefile.am * tools/pdbgen/enumcode.pl * tools/pdbgen/enums.pl: parse the new base-enums.h file and modified the perl voodoo so it doesn't prefix enums with GIMP_ that are already properly namespaced. * app/core/core-types.h: don't need to chop GIMP from enum. * app/pdb/color_cmds.c * app/pdb/tools_cmds.c * libgimp/gimpenums.h * plug-ins/script-fu/script-fu-constants.c: regenerated. * app/config/gimpconfig-deserialize.[ch] * app/config/gimpconfig-serialize.[ch] * app/config/gimpconfig.[ch]: made GimpConfig an interface including a reasonable default implementation that works on object properties. * app/config/Makefile.am * app/config/gimpbaseconfig.[ch]: new GimpBaseConfig using the GimpConfig interface. Yet only used for testing from app/main.c. * app/main.c: test the new GimpBaseConfig object. * app/gimprc.c * app/base/base-config.h * app/base/*.c * app/core/gimpdatafiles.c * app/core/gimpdrawable-transform.c * app/core/gimppreviewcache.c * app/gui/preferences-dialog.c * app/paint-funcs/paint-funcs.c * app/xcf/xcf-seek.c: need to include glib-object.h since base-config contains registered enums now. Follow name change of InterpolationType to GimpInterpolationType.
2001-12-08 00:10:53 +08:00
GObjectClass *klass;
GParamSpec **property_specs;
guint n_property_specs;
guint i;
GString *str;
gboolean property_written = FALSE;
g_return_val_if_fail (G_IS_OBJECT (object), FALSE);
removed from CVS, they are generated. 2001-12-07 Sven Neumann <sven@gimp.org> * app/core/gimpmarshal.[ch]: removed from CVS, they are generated. * app/base/Makefile.am * app/base/base-enums.h: new file defining enums that are to be registered. Used to build app/base/base-enums.c. * app/base/base-types.h: include base-enums.h. * tools/pdbgen/Makefile.am * tools/pdbgen/enumcode.pl * tools/pdbgen/enums.pl: parse the new base-enums.h file and modified the perl voodoo so it doesn't prefix enums with GIMP_ that are already properly namespaced. * app/core/core-types.h: don't need to chop GIMP from enum. * app/pdb/color_cmds.c * app/pdb/tools_cmds.c * libgimp/gimpenums.h * plug-ins/script-fu/script-fu-constants.c: regenerated. * app/config/gimpconfig-deserialize.[ch] * app/config/gimpconfig-serialize.[ch] * app/config/gimpconfig.[ch]: made GimpConfig an interface including a reasonable default implementation that works on object properties. * app/config/Makefile.am * app/config/gimpbaseconfig.[ch]: new GimpBaseConfig using the GimpConfig interface. Yet only used for testing from app/main.c. * app/main.c: test the new GimpBaseConfig object. * app/gimprc.c * app/base/base-config.h * app/base/*.c * app/core/gimpdatafiles.c * app/core/gimpdrawable-transform.c * app/core/gimppreviewcache.c * app/gui/preferences-dialog.c * app/paint-funcs/paint-funcs.c * app/xcf/xcf-seek.c: need to include glib-object.h since base-config contains registered enums now. Follow name change of InterpolationType to GimpInterpolationType.
2001-12-08 00:10:53 +08:00
klass = G_OBJECT_GET_CLASS (object);
removed from CVS, they are generated. 2001-12-07 Sven Neumann <sven@gimp.org> * app/core/gimpmarshal.[ch]: removed from CVS, they are generated. * app/base/Makefile.am * app/base/base-enums.h: new file defining enums that are to be registered. Used to build app/base/base-enums.c. * app/base/base-types.h: include base-enums.h. * tools/pdbgen/Makefile.am * tools/pdbgen/enumcode.pl * tools/pdbgen/enums.pl: parse the new base-enums.h file and modified the perl voodoo so it doesn't prefix enums with GIMP_ that are already properly namespaced. * app/core/core-types.h: don't need to chop GIMP from enum. * app/pdb/color_cmds.c * app/pdb/tools_cmds.c * libgimp/gimpenums.h * plug-ins/script-fu/script-fu-constants.c: regenerated. * app/config/gimpconfig-deserialize.[ch] * app/config/gimpconfig-serialize.[ch] * app/config/gimpconfig.[ch]: made GimpConfig an interface including a reasonable default implementation that works on object properties. * app/config/Makefile.am * app/config/gimpbaseconfig.[ch]: new GimpBaseConfig using the GimpConfig interface. Yet only used for testing from app/main.c. * app/main.c: test the new GimpBaseConfig object. * app/gimprc.c * app/base/base-config.h * app/base/*.c * app/core/gimpdatafiles.c * app/core/gimpdrawable-transform.c * app/core/gimppreviewcache.c * app/gui/preferences-dialog.c * app/paint-funcs/paint-funcs.c * app/xcf/xcf-seek.c: need to include glib-object.h since base-config contains registered enums now. Follow name change of InterpolationType to GimpInterpolationType.
2001-12-08 00:10:53 +08:00
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;
prop_spec = property_specs[i];
if (! (prop_spec->flags & GIMP_PARAM_SERIALIZE))
continue;
if (property_written)
g_string_assign (str, "\n");
else
g_string_assign (str, "");
gimp_config_string_indent (str, indent_level);
g_string_append_printf (str, "(%s ", prop_spec->name);
if (gimp_config_serialize_property (object, prop_spec, str, TRUE))
{
g_string_append (str, ")");
property_written = TRUE;
if (write (fd, str->str, str->len) == -1)
return FALSE;
removed from CVS, they are generated. 2001-12-07 Sven Neumann <sven@gimp.org> * app/core/gimpmarshal.[ch]: removed from CVS, they are generated. * app/base/Makefile.am * app/base/base-enums.h: new file defining enums that are to be registered. Used to build app/base/base-enums.c. * app/base/base-types.h: include base-enums.h. * tools/pdbgen/Makefile.am * tools/pdbgen/enumcode.pl * tools/pdbgen/enums.pl: parse the new base-enums.h file and modified the perl voodoo so it doesn't prefix enums with GIMP_ that are already properly namespaced. * app/core/core-types.h: don't need to chop GIMP from enum. * app/pdb/color_cmds.c * app/pdb/tools_cmds.c * libgimp/gimpenums.h * plug-ins/script-fu/script-fu-constants.c: regenerated. * app/config/gimpconfig-deserialize.[ch] * app/config/gimpconfig-serialize.[ch] * app/config/gimpconfig.[ch]: made GimpConfig an interface including a reasonable default implementation that works on object properties. * app/config/Makefile.am * app/config/gimpbaseconfig.[ch]: new GimpBaseConfig using the GimpConfig interface. Yet only used for testing from app/main.c. * app/main.c: test the new GimpBaseConfig object. * app/gimprc.c * app/base/base-config.h * app/base/*.c * app/core/gimpdatafiles.c * app/core/gimpdrawable-transform.c * app/core/gimppreviewcache.c * app/gui/preferences-dialog.c * app/paint-funcs/paint-funcs.c * app/xcf/xcf-seek.c: need to include glib-object.h since base-config contains registered enums now. Follow name change of InterpolationType to GimpInterpolationType.
2001-12-08 00:10:53 +08:00
}
else if (prop_spec->value_type != G_TYPE_STRING)
{
2001-12-11 23:58:07 +08:00
g_warning ("couldn't serialize property %s::%s of type %s",
g_type_name (G_TYPE_FROM_INSTANCE (object)),
prop_spec->name,
g_type_name (prop_spec->value_type));
}
}
g_free (property_specs);
g_string_free (str, TRUE);
return TRUE;
}
/**
* gimp_config_serialize_properties:
* @new: a #GObject.
* @old: a #GObject of the same type as @new.
* @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.
**/
gboolean
gimp_config_serialize_changed_properties (GObject *new,
GObject *old,
gint fd,
gint indent_level)
{
GObjectClass *klass;
GList *diff;
GList *list;
GString *str;
gboolean property_written = FALSE;
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);
klass = G_OBJECT_GET_CLASS (new);
diff = gimp_config_diff (new, old, GIMP_PARAM_SERIALIZE);
if (! diff)
return TRUE;
str = g_string_new (NULL);
for (list = diff; list; list = g_list_next (list))
{
GParamSpec *prop_spec;
GValue new_value = { 0, };
prop_spec = (GParamSpec *) list->data;
g_value_init (&new_value, prop_spec->value_type);
g_object_get_property (new, prop_spec->name, &new_value);
if (property_written)
g_string_assign (str, "\n");
else
g_string_assign (str, "");
gimp_config_string_indent (str, indent_level);
g_string_append_printf (str, "(%s ", prop_spec->name);
if (gimp_config_serialize_value (&new_value, str, TRUE))
{
g_string_append (str, ")\n");
property_written = TRUE;
if (write (fd, str->str, str->len) == -1)
return FALSE;
}
else if (prop_spec->value_type != G_TYPE_STRING)
{
g_warning ("couldn't serialize property %s::%s of type %s",
g_type_name (G_TYPE_FROM_INSTANCE (new)),
prop_spec->name,
g_type_name (prop_spec->value_type));
}
g_value_unset (&new_value);
}
g_string_free (str, TRUE);
g_list_free (diff);
return TRUE;
}
/**
* gimp_config_serialize_value:
* @value: a #GValue.
* @str: a #Gstring.
* @escaped: whether to escape string values.
*
* This utility function appends a string representation of #GValue to @str.
*
* Return value: %TRUE if serialization succeeded, %FALSE otherwise.
**/
gboolean
gimp_config_serialize_value (const GValue *value,
GString *str,
gboolean escaped)
{
if (G_VALUE_HOLDS_BOOLEAN (value))
{
gboolean bool;
bool = g_value_get_boolean (value);
g_string_append (str, bool ? "yes" : "no");
return TRUE;
}
if (G_VALUE_HOLDS_ENUM (value))
{
GEnumClass *enum_class;
GEnumValue *enum_value;
enum_class = g_type_class_peek (G_VALUE_TYPE (value));
enum_value = g_enum_get_value (G_ENUM_CLASS (enum_class),
g_value_get_enum (value));
if (enum_value && enum_value->value_nick)
{
g_string_append (str, enum_value->value_nick);
return TRUE;
}
else
{
g_warning ("Couldn't get nick for enum_value of %s",
G_ENUM_CLASS_TYPE_NAME (enum_class));
return FALSE;
}
}
if (G_VALUE_HOLDS_STRING (value))
{
gchar *esc;
const gchar *cstr = g_value_get_string (value);
if (!cstr)
return FALSE;
if (escaped)
{
esc = g_strescape (cstr, NULL);
g_string_append_printf (str, "\"%s\"", esc);
g_free (esc);
}
else
{
g_string_append (str, cstr);
}
return TRUE;
}
if (G_VALUE_HOLDS_DOUBLE (value) || G_VALUE_HOLDS_FLOAT (value))
{
gdouble v_double;
gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
if (G_VALUE_HOLDS_DOUBLE (value))
v_double = g_value_get_double (value);
else
v_double = (gdouble) g_value_get_float (value);
g_ascii_formatd (buf, sizeof (buf), "%f", v_double);
g_string_append (str, buf);
return TRUE;
}
if (GIMP_VALUE_HOLDS_COLOR (value))
{
GimpRGB *color;
gchar buf[4][G_ASCII_DTOSTR_BUF_SIZE];
color = g_value_get_boxed (value);
g_ascii_formatd (buf[0], G_ASCII_DTOSTR_BUF_SIZE, "%f", color->r);
g_ascii_formatd (buf[1], G_ASCII_DTOSTR_BUF_SIZE, "%f", color->g);
g_ascii_formatd (buf[2], G_ASCII_DTOSTR_BUF_SIZE, "%f", color->b);
g_ascii_formatd (buf[3], G_ASCII_DTOSTR_BUF_SIZE, "%f", color->a);
g_string_append_printf (str, "(color-rgba %s %s %s %s)",
buf[0], buf[1], buf[2], buf[3]);
return TRUE;
}
if (G_VALUE_TYPE (value) == G_TYPE_VALUE_ARRAY)
{
GValueArray *array;
array = g_value_get_boxed (value);
if (array)
{
gint i;
g_string_append_printf (str, "%d", array->n_values);
for (i = 0; i < array->n_values; i++)
{
g_string_append (str, " ");
if (! gimp_config_serialize_value (g_value_array_get_nth (array, i),
str, escaped))
return FALSE;
}
}
else
{
g_string_append (str, "NULL");
}
return TRUE;
}
if (g_value_type_transformable (G_VALUE_TYPE (value), G_TYPE_STRING))
{
GValue tmp_value = { 0, };
g_value_init (&tmp_value, G_TYPE_STRING);
g_value_transform (value, &tmp_value);
g_string_append (str, g_value_get_string (&tmp_value));
g_value_unset (&tmp_value);
return TRUE;
}
return FALSE;
}
/**
* gimp_config_serialize_unknown_tokens:
* @object: a #GObject.
* @fd: a file descriptor to write to.
*
* Writes all unknown tokens attached to #object to the file descriptor @fd.
* See gimp_config_add_unknown_token().
**/
gboolean
gimp_config_serialize_unknown_tokens (GObject *object,
gint fd,
gint indent_level)
{
GString *str;
g_return_val_if_fail (G_IS_OBJECT (object), FALSE);
str = g_string_new (NULL);
gimp_config_foreach_unknown_token (object, serialize_unknown_token, str);
return (write (fd, str->str, str->len) != -1);
}
static gboolean
gimp_config_serialize_property (GObject *object,
GParamSpec *param_spec,
GString *str,
gboolean escaped)
{
added "gint nest_level" to the deserialization functions, so nested calls 2002-05-27 Michael Natterer <mitch@gimp.org> * app/config/gimpconfig.[ch]: added "gint nest_level" to the deserialization functions, so nested calls to deserialize() don't error on the trailing ')'. Made the scanner config parse one-character identifiers and allow G_CSET_A_2_Z for all identifiers. Added gimp_config_deserialize_return() because returning the correct return value from a deserialize() function is not trivial any more with nested calls. * app/config/gimpconfig-deserialize.[ch] * app/config/gimprc.c * app/core/gimpdocumentlist.c * app/core/gimpparasitelist.c: use the new return value utility function and made the main parsing loops simpler. * app/core/gimpunits.c: made the main parsing loops consistent with the stuff that uses GimpConfig. * app/config/gimpconfig-deserialize.c * app/config/gimpconfig-serialize.c: call the (de)serialize_property() functions only if the property's class implements the method itself (does *not* inherit it from one of it's parents). * app/core/gimpcontainer.c: implemented deserialization of containers. For each child entry encountered in the input, check if it's already contained in the container and create it if not. If a "gimp" pointer is passed as user_data pass it as construct property to g_object_new() when creating the object. * app/core/gimpcontext.c: changed deserialization of brush, pattern etc. to honor "no_data". * app/widgets/gimpdeviceinfo.c: added a "gimp" construct_only property which overrides GimpContext's "gimp" property. Moved all initialisation code from gimp_device_info_new() to gimp_device_info_set_property(PROP_GIMP) so it is properly performed if the object is created by GimpContainer's deserialize() implementation. * app/widgets/gimpdevices.c: made gimp_devices_restore_test() work.
2002-05-27 22:04:21 +08:00
GTypeClass *owner_class;
GimpConfigInterface *gimp_config_iface;
added "gint nest_level" to the deserialization functions, so nested calls 2002-05-27 Michael Natterer <mitch@gimp.org> * app/config/gimpconfig.[ch]: added "gint nest_level" to the deserialization functions, so nested calls to deserialize() don't error on the trailing ')'. Made the scanner config parse one-character identifiers and allow G_CSET_A_2_Z for all identifiers. Added gimp_config_deserialize_return() because returning the correct return value from a deserialize() function is not trivial any more with nested calls. * app/config/gimpconfig-deserialize.[ch] * app/config/gimprc.c * app/core/gimpdocumentlist.c * app/core/gimpparasitelist.c: use the new return value utility function and made the main parsing loops simpler. * app/core/gimpunits.c: made the main parsing loops consistent with the stuff that uses GimpConfig. * app/config/gimpconfig-deserialize.c * app/config/gimpconfig-serialize.c: call the (de)serialize_property() functions only if the property's class implements the method itself (does *not* inherit it from one of it's parents). * app/core/gimpcontainer.c: implemented deserialization of containers. For each child entry encountered in the input, check if it's already contained in the container and create it if not. If a "gimp" pointer is passed as user_data pass it as construct property to g_object_new() when creating the object. * app/core/gimpcontext.c: changed deserialization of brush, pattern etc. to honor "no_data". * app/widgets/gimpdeviceinfo.c: added a "gimp" construct_only property which overrides GimpContext's "gimp" property. Moved all initialisation code from gimp_device_info_new() to gimp_device_info_set_property(PROP_GIMP) so it is properly performed if the object is created by GimpContainer's deserialize() implementation. * app/widgets/gimpdevices.c: made gimp_devices_restore_test() work.
2002-05-27 22:04:21 +08:00
GimpConfigInterface *parent_iface;
GValue value = { 0, };
gboolean retval;
g_value_init (&value, param_spec->value_type);
g_object_get_property (object, param_spec->name, &value);
added "gint nest_level" to the deserialization functions, so nested calls 2002-05-27 Michael Natterer <mitch@gimp.org> * app/config/gimpconfig.[ch]: added "gint nest_level" to the deserialization functions, so nested calls to deserialize() don't error on the trailing ')'. Made the scanner config parse one-character identifiers and allow G_CSET_A_2_Z for all identifiers. Added gimp_config_deserialize_return() because returning the correct return value from a deserialize() function is not trivial any more with nested calls. * app/config/gimpconfig-deserialize.[ch] * app/config/gimprc.c * app/core/gimpdocumentlist.c * app/core/gimpparasitelist.c: use the new return value utility function and made the main parsing loops simpler. * app/core/gimpunits.c: made the main parsing loops consistent with the stuff that uses GimpConfig. * app/config/gimpconfig-deserialize.c * app/config/gimpconfig-serialize.c: call the (de)serialize_property() functions only if the property's class implements the method itself (does *not* inherit it from one of it's parents). * app/core/gimpcontainer.c: implemented deserialization of containers. For each child entry encountered in the input, check if it's already contained in the container and create it if not. If a "gimp" pointer is passed as user_data pass it as construct property to g_object_new() when creating the object. * app/core/gimpcontext.c: changed deserialization of brush, pattern etc. to honor "no_data". * app/widgets/gimpdeviceinfo.c: added a "gimp" construct_only property which overrides GimpContext's "gimp" property. Moved all initialisation code from gimp_device_info_new() to gimp_device_info_set_property(PROP_GIMP) so it is properly performed if the object is created by GimpContainer's deserialize() implementation. * app/widgets/gimpdevices.c: made gimp_devices_restore_test() work.
2002-05-27 22:04:21 +08:00
owner_class = g_type_class_peek (param_spec->owner_type);
gimp_config_iface = g_type_interface_peek (owner_class,
GIMP_TYPE_CONFIG_INTERFACE);
/* We must call deserialize_property() *only* if the *exact* class
* which implements it is param_spec->owner_type's class.
*
* Therefore, we ask param_spec->owner_type's immediate parent class
* for it's GimpConfigInterface and check if we get a different pointer.
*
* (if the pointers are the same, param_spec->owner_type's
* GimpConfigInterface is inherited from one of it's parent classes
* and thus not able to handle param_spec->owner_type's properties).
*/
if (gimp_config_iface)
{
GTypeClass *owner_parent_class;
owner_parent_class = g_type_class_peek_parent (owner_class),
parent_iface = g_type_interface_peek (owner_parent_class,
GIMP_TYPE_CONFIG_INTERFACE);
}
if (gimp_config_iface &&
added "gint nest_level" to the deserialization functions, so nested calls 2002-05-27 Michael Natterer <mitch@gimp.org> * app/config/gimpconfig.[ch]: added "gint nest_level" to the deserialization functions, so nested calls to deserialize() don't error on the trailing ')'. Made the scanner config parse one-character identifiers and allow G_CSET_A_2_Z for all identifiers. Added gimp_config_deserialize_return() because returning the correct return value from a deserialize() function is not trivial any more with nested calls. * app/config/gimpconfig-deserialize.[ch] * app/config/gimprc.c * app/core/gimpdocumentlist.c * app/core/gimpparasitelist.c: use the new return value utility function and made the main parsing loops simpler. * app/core/gimpunits.c: made the main parsing loops consistent with the stuff that uses GimpConfig. * app/config/gimpconfig-deserialize.c * app/config/gimpconfig-serialize.c: call the (de)serialize_property() functions only if the property's class implements the method itself (does *not* inherit it from one of it's parents). * app/core/gimpcontainer.c: implemented deserialization of containers. For each child entry encountered in the input, check if it's already contained in the container and create it if not. If a "gimp" pointer is passed as user_data pass it as construct property to g_object_new() when creating the object. * app/core/gimpcontext.c: changed deserialization of brush, pattern etc. to honor "no_data". * app/widgets/gimpdeviceinfo.c: added a "gimp" construct_only property which overrides GimpContext's "gimp" property. Moved all initialisation code from gimp_device_info_new() to gimp_device_info_set_property(PROP_GIMP) so it is properly performed if the object is created by GimpContainer's deserialize() implementation. * app/widgets/gimpdevices.c: made gimp_devices_restore_test() work.
2002-05-27 22:04:21 +08:00
gimp_config_iface != parent_iface && /* see comment above */
gimp_config_iface->serialize_property &&
gimp_config_iface->serialize_property (object,
param_spec->param_id,
(const GValue *) &value,
param_spec,
str))
{
retval = TRUE;
}
else
{
retval = gimp_config_serialize_value (&value, str, escaped);
}
g_value_unset (&value);
return retval;
}
static void
serialize_unknown_token (const gchar *key,
const gchar *value,
gpointer data)
{
gchar *escaped = g_strescape (value, NULL);
g_string_append_printf ((GString *) data, "(%s \"%s\")\n", key, escaped);
g_free (escaped);
}