2001-11-27 03:52:11 +00:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* Object propoerties serialization routines
|
|
|
|
* Copyright (C) 2001 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>
|
|
|
|
|
|
|
|
#include <glib-object.h>
|
|
|
|
|
|
|
|
#include "gimpconfig-serialize.h"
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2001-12-07 16:10:53 +00:00
|
|
|
gimp_config_serialize_properties (GObject *object,
|
|
|
|
FILE *file)
|
2001-11-27 03:52:11 +00:00
|
|
|
{
|
2001-12-07 16:10:53 +00:00
|
|
|
GObjectClass *klass;
|
|
|
|
GParamSpec **property_specs;
|
|
|
|
guint n_property_specs;
|
|
|
|
guint i;
|
|
|
|
GValue value = { 0, };
|
2001-11-27 03:52:11 +00:00
|
|
|
|
2001-12-07 16:10:53 +00:00
|
|
|
klass = G_OBJECT_GET_CLASS (object);
|
2001-11-27 03:52:11 +00:00
|
|
|
|
2001-12-07 16:10:53 +00:00
|
|
|
property_specs = g_object_class_list_properties (klass, &n_property_specs);
|
2001-11-27 03:52:11 +00:00
|
|
|
|
|
|
|
for (i = 0; i < n_property_specs; i++)
|
|
|
|
{
|
2001-12-07 16:10:53 +00:00
|
|
|
GParamSpec *prop_spec;
|
|
|
|
const gchar *cstr;
|
|
|
|
gchar *str;
|
2001-11-27 03:52:11 +00:00
|
|
|
|
|
|
|
prop_spec = property_specs[i];
|
|
|
|
|
2001-12-07 16:10:53 +00:00
|
|
|
if (! (prop_spec->flags & G_PARAM_READWRITE))
|
2001-11-27 03:52:11 +00:00
|
|
|
continue;
|
|
|
|
|
2001-12-07 16:10:53 +00:00
|
|
|
str = NULL;
|
|
|
|
cstr = NULL;
|
2001-11-27 03:52:11 +00:00
|
|
|
g_value_init (&value, prop_spec->value_type);
|
|
|
|
|
2001-12-07 16:10:53 +00:00
|
|
|
g_object_get_property (object, prop_spec->name, &value);
|
2001-11-27 03:52:11 +00:00
|
|
|
|
2001-12-07 16:10:53 +00:00
|
|
|
if (G_VALUE_HOLDS_BOOLEAN (&value))
|
2001-11-27 03:52:11 +00:00
|
|
|
{
|
2001-12-07 16:10:53 +00:00
|
|
|
gboolean bool;
|
2001-11-27 03:52:11 +00:00
|
|
|
|
2001-12-07 16:10:53 +00:00
|
|
|
bool = g_value_get_boolean (&value);
|
|
|
|
cstr = bool ? "yes" : "no";
|
|
|
|
}
|
|
|
|
else if (G_VALUE_HOLDS_STRING (&value))
|
|
|
|
{
|
|
|
|
cstr = g_value_get_string (&value);
|
2001-11-27 03:52:11 +00:00
|
|
|
|
2001-12-07 16:10:53 +00:00
|
|
|
if (cstr)
|
2001-11-27 03:52:11 +00:00
|
|
|
{
|
2001-12-07 16:10:53 +00:00
|
|
|
gchar *s = g_strescape (cstr, NULL);
|
2001-11-27 03:52:11 +00:00
|
|
|
|
|
|
|
str = g_strdup_printf ("\"%s\"", s);
|
|
|
|
g_free (s);
|
2001-12-07 16:10:53 +00:00
|
|
|
cstr = NULL;
|
2001-11-27 03:52:11 +00:00
|
|
|
}
|
|
|
|
}
|
2001-12-07 16:10:53 +00:00
|
|
|
else if (G_VALUE_HOLDS_ENUM (&value))
|
|
|
|
{
|
|
|
|
GEnumClass *enum_class;
|
|
|
|
GEnumValue *enum_value;
|
|
|
|
|
2001-12-08 03:35:38 +00:00
|
|
|
enum_class = g_type_class_peek (prop_spec->value_type);
|
2001-12-07 16:10:53 +00:00
|
|
|
enum_value = g_enum_get_value (G_ENUM_CLASS (enum_class),
|
|
|
|
g_value_get_enum (&value));
|
|
|
|
|
|
|
|
if (enum_value && enum_value->value_nick)
|
|
|
|
cstr = enum_value->value_nick;
|
|
|
|
else
|
|
|
|
g_warning ("Couldn't get nick for enum_value of %s",
|
|
|
|
G_ENUM_CLASS_TYPE_NAME (enum_class));
|
|
|
|
}
|
2001-12-08 03:35:38 +00:00
|
|
|
else if (g_value_type_transformable (prop_spec->value_type,
|
2001-11-27 03:52:11 +00:00
|
|
|
G_TYPE_STRING))
|
|
|
|
{
|
|
|
|
GValue tmp_value = { 0, };
|
|
|
|
|
|
|
|
g_value_init (&tmp_value, G_TYPE_STRING);
|
|
|
|
g_value_transform (&value, &tmp_value);
|
2001-12-08 03:35:38 +00:00
|
|
|
str = g_value_dup_string (&tmp_value);
|
2001-11-27 03:52:11 +00:00
|
|
|
g_value_unset (&tmp_value);
|
|
|
|
}
|
|
|
|
|
2001-12-07 16:10:53 +00:00
|
|
|
if (cstr || str)
|
|
|
|
{
|
|
|
|
fprintf (file, "(%s %s)\n", prop_spec->name, cstr ? cstr : str);
|
|
|
|
g_free (str);
|
|
|
|
}
|
2001-11-27 03:52:11 +00:00
|
|
|
|
|
|
|
g_value_unset (&value);
|
|
|
|
}
|
|
|
|
}
|