2001-11-27 11:52:11 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2001-12-08 00:10:53 +08:00
|
|
|
* Config file serialization and deserialization interface
|
2002-03-24 01:58:57 +08:00
|
|
|
* Copyright (C) 2001-2002 Sven Neumann <sven@gimp.org>
|
2003-07-11 20:22:42 +08:00
|
|
|
*
|
2001-11-27 11:52:11 +08:00
|
|
|
* 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"
|
|
|
|
|
2001-12-13 09:55:37 +08:00
|
|
|
#include <string.h>
|
2001-11-27 11:52:11 +08:00
|
|
|
|
|
|
|
#include <glib-object.h>
|
|
|
|
|
2003-07-08 00:22:45 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2002-05-31 21:58:18 +08:00
|
|
|
|
2003-03-06 04:21:50 +08:00
|
|
|
#include "config-types.h"
|
|
|
|
|
2001-11-27 11:52:11 +08:00
|
|
|
#include "gimpconfig.h"
|
2001-12-08 00:10:53 +08:00
|
|
|
#include "gimpconfig-deserialize.h"
|
2003-10-15 07:00:16 +08:00
|
|
|
#include "gimpconfig-serialize.h"
|
|
|
|
#include "gimpconfig-params.h"
|
2002-05-04 07:48:03 +08:00
|
|
|
#include "gimpconfig-utils.h"
|
2003-03-06 04:21:50 +08:00
|
|
|
#include "gimpconfigwriter.h"
|
2002-05-31 21:58:18 +08:00
|
|
|
#include "gimpscanner.h"
|
2001-11-27 11:52:11 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2001-12-13 09:55:37 +08:00
|
|
|
|
2001-12-09 11:00:32 +08:00
|
|
|
|
2003-07-11 20:22:42 +08:00
|
|
|
/*
|
2001-12-10 00:18:15 +08:00
|
|
|
* The GimpConfig serialization and deserialization interface.
|
|
|
|
*/
|
2001-11-27 11:52:11 +08:00
|
|
|
|
2003-10-16 04:05:23 +08:00
|
|
|
static void gimp_config_iface_base_init (GimpConfigInterface *config_iface);
|
2001-11-27 11:52:11 +08:00
|
|
|
|
2003-10-11 22:30:18 +08:00
|
|
|
static gboolean gimp_config_iface_serialize (GimpConfig *config,
|
|
|
|
GimpConfigWriter *writer,
|
|
|
|
gpointer data);
|
|
|
|
static gboolean gimp_config_iface_deserialize (GimpConfig *config,
|
|
|
|
GScanner *scanner,
|
|
|
|
gint nest_level,
|
|
|
|
gpointer data);
|
|
|
|
static GimpConfig * gimp_config_iface_duplicate (GimpConfig *config);
|
|
|
|
static gboolean gimp_config_iface_equal (GimpConfig *a,
|
|
|
|
GimpConfig *b);
|
|
|
|
static void gimp_config_iface_reset (GimpConfig *config);
|
2001-11-27 11:52:11 +08:00
|
|
|
|
|
|
|
|
|
|
|
GType
|
2001-12-08 00:10:53 +08:00
|
|
|
gimp_config_interface_get_type (void)
|
2001-11-27 11:52:11 +08:00
|
|
|
{
|
2001-12-08 00:10:53 +08:00
|
|
|
static GType config_iface_type = 0;
|
2001-11-27 11:52:11 +08:00
|
|
|
|
2001-12-08 00:10:53 +08:00
|
|
|
if (!config_iface_type)
|
2001-11-27 11:52:11 +08:00
|
|
|
{
|
2001-12-08 00:10:53 +08:00
|
|
|
static const GTypeInfo config_iface_info =
|
2001-11-27 11:52:11 +08:00
|
|
|
{
|
2001-12-08 00:10:53 +08:00
|
|
|
sizeof (GimpConfigInterface),
|
2003-10-16 04:05:23 +08:00
|
|
|
(GBaseInitFunc) gimp_config_iface_base_init,
|
2001-11-27 11:52:11 +08:00
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
};
|
|
|
|
|
2003-07-11 20:22:42 +08:00
|
|
|
config_iface_type = g_type_register_static (G_TYPE_INTERFACE,
|
|
|
|
"GimpConfigInterface",
|
|
|
|
&config_iface_info,
|
2001-12-08 00:10:53 +08:00
|
|
|
0);
|
2001-11-27 11:52:11 +08:00
|
|
|
|
2002-12-30 02:58:24 +08:00
|
|
|
g_type_interface_add_prerequisite (config_iface_type, G_TYPE_OBJECT);
|
2001-12-08 00:10:53 +08:00
|
|
|
}
|
2003-07-11 20:22:42 +08:00
|
|
|
|
2001-12-08 00:10:53 +08:00
|
|
|
return config_iface_type;
|
2001-11-27 11:52:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-10-16 04:05:23 +08:00
|
|
|
gimp_config_iface_base_init (GimpConfigInterface *config_iface)
|
2001-11-27 11:52:11 +08:00
|
|
|
{
|
2003-10-16 04:05:23 +08:00
|
|
|
if (! config_iface->serialize)
|
|
|
|
{
|
|
|
|
config_iface->serialize = gimp_config_iface_serialize;
|
|
|
|
config_iface->deserialize = gimp_config_iface_deserialize;
|
|
|
|
config_iface->duplicate = gimp_config_iface_duplicate;
|
|
|
|
config_iface->equal = gimp_config_iface_equal;
|
|
|
|
config_iface->reset = gimp_config_iface_reset;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* always set these to NULL since we don't want to inherit them
|
|
|
|
* from parent classes
|
|
|
|
*/
|
|
|
|
config_iface->serialize_property = NULL;
|
|
|
|
config_iface->deserialize_property = NULL;
|
2001-11-27 11:52:11 +08:00
|
|
|
}
|
|
|
|
|
2002-05-15 19:05:32 +08:00
|
|
|
static gboolean
|
2003-10-11 22:30:18 +08:00
|
|
|
gimp_config_iface_serialize (GimpConfig *config,
|
2003-03-06 04:21:50 +08:00
|
|
|
GimpConfigWriter *writer,
|
|
|
|
gpointer data)
|
2001-11-27 11:52:11 +08:00
|
|
|
{
|
2003-10-11 22:30:18 +08:00
|
|
|
return gimp_config_serialize_properties (config, writer);
|
2001-12-08 00:10:53 +08:00
|
|
|
}
|
2001-11-27 11:52:11 +08:00
|
|
|
|
2001-12-08 00:10:53 +08:00
|
|
|
static gboolean
|
2003-10-11 22:30:18 +08:00
|
|
|
gimp_config_iface_deserialize (GimpConfig *config,
|
|
|
|
GScanner *scanner,
|
|
|
|
gint nest_level,
|
|
|
|
gpointer data)
|
2001-12-08 00:10:53 +08:00
|
|
|
{
|
2003-10-11 22:30:18 +08:00
|
|
|
return gimp_config_deserialize_properties (config,
|
2002-12-30 02:58:24 +08:00
|
|
|
scanner, nest_level, FALSE);
|
2001-11-27 11:52:11 +08:00
|
|
|
}
|
|
|
|
|
2003-10-11 22:30:18 +08:00
|
|
|
static GimpConfig *
|
|
|
|
gimp_config_iface_duplicate (GimpConfig *config)
|
2002-05-04 07:48:03 +08:00
|
|
|
{
|
2003-09-30 02:29:11 +08:00
|
|
|
GObjectClass *klass;
|
|
|
|
GParamSpec **property_specs;
|
|
|
|
guint n_property_specs;
|
|
|
|
GParameter *construct_params = NULL;
|
|
|
|
gint n_construct_params = 0;
|
|
|
|
guint i;
|
2003-10-11 22:30:18 +08:00
|
|
|
GimpConfig *dup;
|
2003-09-30 02:29:11 +08:00
|
|
|
|
2003-10-11 22:30:18 +08:00
|
|
|
klass = G_OBJECT_GET_CLASS (config);
|
2003-09-30 02:29:11 +08:00
|
|
|
|
|
|
|
property_specs = g_object_class_list_properties (klass, &n_property_specs);
|
|
|
|
|
|
|
|
construct_params = g_new0 (GParameter, n_property_specs);
|
|
|
|
|
|
|
|
for (i = 0; i < n_property_specs; i++)
|
|
|
|
{
|
|
|
|
GParamSpec *prop_spec = property_specs[i];
|
|
|
|
|
|
|
|
if ((prop_spec->flags & G_PARAM_READABLE) &&
|
|
|
|
(prop_spec->flags & G_PARAM_WRITABLE) &&
|
|
|
|
(prop_spec->flags & G_PARAM_CONSTRUCT_ONLY))
|
|
|
|
{
|
|
|
|
GParameter *construct_param;
|
|
|
|
|
|
|
|
construct_param = &construct_params[n_construct_params++];
|
|
|
|
|
2004-08-31 21:16:08 +08:00
|
|
|
construct_param->name = prop_spec->name;
|
2003-09-30 02:29:11 +08:00
|
|
|
|
2004-08-31 21:16:08 +08:00
|
|
|
g_value_init (&construct_param->value, prop_spec->value_type);
|
2003-10-11 22:30:18 +08:00
|
|
|
g_object_get_property (G_OBJECT (config), prop_spec->name,
|
2003-09-30 02:29:11 +08:00
|
|
|
&construct_param->value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (property_specs);
|
|
|
|
|
2003-10-11 22:30:18 +08:00
|
|
|
dup = g_object_newv (G_TYPE_FROM_INSTANCE (config),
|
2003-09-30 02:29:11 +08:00
|
|
|
n_construct_params, construct_params);
|
|
|
|
|
|
|
|
for (i = 0; i < n_construct_params; i++)
|
|
|
|
g_value_unset (&construct_params[i].value);
|
|
|
|
|
|
|
|
g_free (construct_params);
|
2002-05-04 07:48:03 +08:00
|
|
|
|
2003-10-14 23:20:59 +08:00
|
|
|
gimp_config_sync (config, dup, 0);
|
2002-05-04 07:48:03 +08:00
|
|
|
|
|
|
|
return dup;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2003-10-11 22:30:18 +08:00
|
|
|
gimp_config_iface_equal (GimpConfig *a,
|
|
|
|
GimpConfig *b)
|
2002-05-04 07:48:03 +08:00
|
|
|
{
|
|
|
|
GObjectClass *klass;
|
|
|
|
GParamSpec **property_specs;
|
|
|
|
guint n_property_specs;
|
|
|
|
guint i;
|
|
|
|
gboolean equal = TRUE;
|
|
|
|
|
|
|
|
klass = G_OBJECT_GET_CLASS (a);
|
|
|
|
|
|
|
|
property_specs = g_object_class_list_properties (klass, &n_property_specs);
|
2003-07-11 20:22:42 +08:00
|
|
|
|
2002-05-04 07:48:03 +08:00
|
|
|
for (i = 0; equal && i < n_property_specs; i++)
|
|
|
|
{
|
|
|
|
GParamSpec *prop_spec;
|
|
|
|
GValue a_value = { 0, };
|
|
|
|
GValue b_value = { 0, };
|
|
|
|
|
|
|
|
prop_spec = property_specs[i];
|
|
|
|
|
|
|
|
if (! (prop_spec->flags & G_PARAM_READABLE))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
g_value_init (&a_value, prop_spec->value_type);
|
|
|
|
g_value_init (&b_value, prop_spec->value_type);
|
2003-10-11 22:30:18 +08:00
|
|
|
g_object_get_property (G_OBJECT (a), prop_spec->name, &a_value);
|
|
|
|
g_object_get_property (G_OBJECT (b), prop_spec->name, &b_value);
|
2002-05-04 07:48:03 +08:00
|
|
|
|
2003-10-15 07:00:16 +08:00
|
|
|
if (g_param_values_cmp (prop_spec, &a_value, &b_value))
|
|
|
|
{
|
|
|
|
if ((prop_spec->flags & GIMP_PARAM_AGGREGATE) &&
|
|
|
|
G_IS_PARAM_SPEC_OBJECT (prop_spec) &&
|
|
|
|
g_type_interface_peek (g_type_class_peek (prop_spec->value_type),
|
|
|
|
GIMP_TYPE_CONFIG))
|
|
|
|
{
|
|
|
|
if (! gimp_config_is_equal_to (g_value_get_object (&a_value),
|
|
|
|
g_value_get_object (&b_value)))
|
|
|
|
{
|
|
|
|
equal = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
equal = FALSE;
|
|
|
|
}
|
|
|
|
}
|
2002-05-04 07:48:03 +08:00
|
|
|
|
|
|
|
g_value_unset (&a_value);
|
|
|
|
g_value_unset (&b_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (property_specs);
|
|
|
|
|
|
|
|
return equal;
|
|
|
|
}
|
|
|
|
|
2003-02-02 05:50:21 +08:00
|
|
|
static void
|
2003-10-11 22:30:18 +08:00
|
|
|
gimp_config_iface_reset (GimpConfig *config)
|
2003-02-02 05:50:21 +08:00
|
|
|
{
|
2003-10-11 22:30:18 +08:00
|
|
|
gimp_config_reset_properties (config);
|
2003-02-02 05:50:21 +08:00
|
|
|
}
|
|
|
|
|
2002-03-24 01:58:57 +08:00
|
|
|
/**
|
2003-06-24 06:02:56 +08:00
|
|
|
* gimp_config_serialize_to_file:
|
2003-10-11 22:30:18 +08:00
|
|
|
* @config: a #GObject that implements the #GimpConfigInterface.
|
2002-03-24 01:58:57 +08:00
|
|
|
* @filename: the name of the file to write the configuration to.
|
2003-03-06 04:21:50 +08:00
|
|
|
* @header: optional file header (must be ASCII only)
|
|
|
|
* @footer: optional file footer (must be ASCII only)
|
2002-05-15 19:59:51 +08:00
|
|
|
* @data: user data passed to the serialize implementation.
|
2002-03-24 01:58:57 +08:00
|
|
|
* @error:
|
2003-07-11 20:22:42 +08:00
|
|
|
*
|
2003-10-11 22:30:18 +08:00
|
|
|
* Serializes the object properties of @config to the file specified
|
2003-07-11 20:22:42 +08:00
|
|
|
* by @filename. If a file with that name already exists, it is
|
2002-03-24 01:58:57 +08:00
|
|
|
* overwritten. Basically this function opens @filename for you and
|
2003-10-11 22:30:18 +08:00
|
|
|
* calls the serialize function of the @config's #GimpConfigInterface.
|
2002-03-24 01:58:57 +08:00
|
|
|
*
|
|
|
|
* Return value: %TRUE if serialization succeeded, %FALSE otherwise.
|
|
|
|
**/
|
2001-12-08 00:10:53 +08:00
|
|
|
gboolean
|
2003-10-11 22:30:18 +08:00
|
|
|
gimp_config_serialize_to_file (GimpConfig *config,
|
2003-06-24 06:02:56 +08:00
|
|
|
const gchar *filename,
|
|
|
|
const gchar *header,
|
|
|
|
const gchar *footer,
|
|
|
|
gpointer data,
|
|
|
|
GError **error)
|
2001-11-27 11:52:11 +08:00
|
|
|
{
|
2003-10-11 22:30:18 +08:00
|
|
|
GimpConfigWriter *writer;
|
2001-11-27 11:52:11 +08:00
|
|
|
|
2003-10-11 22:30:18 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_CONFIG (config), FALSE);
|
2001-12-08 00:10:53 +08:00
|
|
|
g_return_val_if_fail (filename != NULL, FALSE);
|
2002-03-24 01:58:57 +08:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
2001-11-27 11:52:11 +08:00
|
|
|
|
2003-06-24 06:02:56 +08:00
|
|
|
writer = gimp_config_writer_new_file (filename, TRUE, header, error);
|
2003-03-06 04:21:50 +08:00
|
|
|
if (!writer)
|
|
|
|
return FALSE;
|
2002-12-20 20:27:05 +08:00
|
|
|
|
2003-10-11 22:30:18 +08:00
|
|
|
GIMP_CONFIG_GET_INTERFACE (config)->serialize (config, writer, data);
|
2002-05-14 05:39:59 +08:00
|
|
|
|
2003-03-06 04:21:50 +08:00
|
|
|
return gimp_config_writer_finish (writer, footer, error);
|
2001-11-27 11:52:11 +08:00
|
|
|
}
|
|
|
|
|
2003-06-25 03:45:55 +08:00
|
|
|
gboolean
|
2003-10-11 22:30:18 +08:00
|
|
|
gimp_config_serialize_to_fd (GimpConfig *config,
|
|
|
|
gint fd,
|
|
|
|
gpointer data)
|
2003-06-25 03:45:55 +08:00
|
|
|
{
|
2003-10-11 22:30:18 +08:00
|
|
|
GimpConfigWriter *writer;
|
2003-06-25 03:45:55 +08:00
|
|
|
|
2003-10-11 22:30:18 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_CONFIG (config), FALSE);
|
2003-06-25 03:45:55 +08:00
|
|
|
g_return_val_if_fail (fd > 0, FALSE);
|
|
|
|
|
|
|
|
writer = gimp_config_writer_new_fd (fd);
|
|
|
|
if (!writer)
|
|
|
|
return FALSE;
|
|
|
|
|
2003-10-11 22:30:18 +08:00
|
|
|
GIMP_CONFIG_GET_INTERFACE (config)->serialize (config, writer, data);
|
2003-06-25 03:45:55 +08:00
|
|
|
|
|
|
|
return gimp_config_writer_finish (writer, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2003-06-24 06:02:56 +08:00
|
|
|
/**
|
|
|
|
* gimp_config_serialize_to_string:
|
2003-10-11 22:30:18 +08:00
|
|
|
* @config: a #GObject that implements the #GimpConfigInterface.
|
2003-06-24 06:02:56 +08:00
|
|
|
* @data: user data passed to the serialize implementation.
|
2003-07-11 20:22:42 +08:00
|
|
|
*
|
2003-10-11 22:30:18 +08:00
|
|
|
* Serializes the object properties of @config to a string.
|
2003-06-24 06:02:56 +08:00
|
|
|
*
|
|
|
|
* Return value: a newly allocated %NUL-terminated string.
|
|
|
|
**/
|
|
|
|
gchar *
|
2003-10-11 22:30:18 +08:00
|
|
|
gimp_config_serialize_to_string (GimpConfig *config,
|
|
|
|
gpointer data)
|
2003-06-24 06:02:56 +08:00
|
|
|
{
|
2003-10-11 22:30:18 +08:00
|
|
|
GimpConfigWriter *writer;
|
|
|
|
GString *str;
|
2003-06-24 06:02:56 +08:00
|
|
|
|
2003-10-11 22:30:18 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_CONFIG (config), NULL);
|
2003-06-24 06:02:56 +08:00
|
|
|
|
|
|
|
str = g_string_new (NULL);
|
|
|
|
writer = gimp_config_writer_new_string (str);
|
|
|
|
|
2003-10-11 22:30:18 +08:00
|
|
|
GIMP_CONFIG_GET_INTERFACE (config)->serialize (config, writer, data);
|
2003-06-24 06:02:56 +08:00
|
|
|
|
|
|
|
gimp_config_writer_finish (writer, NULL, NULL);
|
|
|
|
|
|
|
|
return g_string_free (str, FALSE);
|
|
|
|
}
|
|
|
|
|
2002-03-24 01:58:57 +08:00
|
|
|
/**
|
|
|
|
* gimp_config_deserialize:
|
2003-10-11 22:30:18 +08:00
|
|
|
* @config: a #GObject that implements the #GimpConfigInterface.
|
2002-03-24 01:58:57 +08:00
|
|
|
* @filename: the name of the file to read configuration from.
|
2002-05-16 02:23:17 +08:00
|
|
|
* @data: user data passed to the deserialize implementation.
|
2003-07-11 20:22:42 +08:00
|
|
|
* @error:
|
|
|
|
*
|
2002-03-24 01:58:57 +08:00
|
|
|
* Opens the file specified by @filename, reads configuration data
|
2003-10-11 22:30:18 +08:00
|
|
|
* from it and configures @config accordingly. Basically this function
|
2002-03-24 01:58:57 +08:00
|
|
|
* creates a properly configured #GScanner for you and calls the
|
2003-10-11 22:30:18 +08:00
|
|
|
* deserialize function of the @config's #GimpConfigInterface.
|
2003-07-11 20:22:42 +08:00
|
|
|
*
|
|
|
|
* Return value: %TRUE if deserialization succeeded, %FALSE otherwise.
|
2002-03-24 01:58:57 +08:00
|
|
|
**/
|
2001-11-27 11:52:11 +08:00
|
|
|
gboolean
|
2003-10-11 22:30:18 +08:00
|
|
|
gimp_config_deserialize_file (GimpConfig *config,
|
2003-06-24 06:02:56 +08:00
|
|
|
const gchar *filename,
|
|
|
|
gpointer data,
|
|
|
|
GError **error)
|
2001-11-27 11:52:11 +08:00
|
|
|
{
|
2003-10-11 22:30:18 +08:00
|
|
|
GScanner *scanner;
|
|
|
|
gboolean success;
|
2001-11-27 11:52:11 +08:00
|
|
|
|
2003-10-11 22:30:18 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_CONFIG (config), FALSE);
|
2001-12-08 00:10:53 +08:00
|
|
|
g_return_val_if_fail (filename != NULL, FALSE);
|
2002-03-24 01:58:57 +08:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
2003-07-11 20:22:42 +08:00
|
|
|
|
2003-06-24 06:02:56 +08:00
|
|
|
scanner = gimp_scanner_new_file (filename, error);
|
2002-05-31 21:58:18 +08:00
|
|
|
if (! scanner)
|
|
|
|
return FALSE;
|
2001-11-27 11:52:11 +08:00
|
|
|
|
2003-10-11 22:30:18 +08:00
|
|
|
success = GIMP_CONFIG_GET_INTERFACE (config)->deserialize (config,
|
|
|
|
scanner, 0, data);
|
2001-11-27 11:52:11 +08:00
|
|
|
|
2002-05-31 21:58:18 +08:00
|
|
|
gimp_scanner_destroy (scanner);
|
2001-11-27 11:52:11 +08:00
|
|
|
|
2002-05-22 21:19:19 +08:00
|
|
|
if (! success)
|
|
|
|
g_assert (error == NULL || *error != NULL);
|
|
|
|
|
2001-11-27 11:52:11 +08:00
|
|
|
return success;
|
|
|
|
}
|
2001-12-08 23:56:40 +08:00
|
|
|
|
2003-06-24 06:02:56 +08:00
|
|
|
/**
|
|
|
|
* gimp_config_deserialize_string:
|
2003-10-11 22:30:18 +08:00
|
|
|
* @config: a #GObject that implements the #GimpConfigInterface.
|
2003-06-24 06:02:56 +08:00
|
|
|
* @text: string to deserialize (in UTF-8 encoding)
|
|
|
|
* @text_len: length of @text in bytes or -1
|
2003-08-09 03:30:23 +08:00
|
|
|
* @data:
|
2003-07-11 20:22:42 +08:00
|
|
|
* @error:
|
|
|
|
*
|
2003-10-11 22:30:18 +08:00
|
|
|
* Configures @config from @text. Basically this function creates a
|
2003-06-24 06:02:56 +08:00
|
|
|
* properly configured #GScanner for you and calls the deserialize
|
2003-10-11 22:30:18 +08:00
|
|
|
* function of the @config's #GimpConfigInterface.
|
2003-07-11 20:22:42 +08:00
|
|
|
*
|
2003-08-09 03:30:23 +08:00
|
|
|
* Returns: %TRUE if deserialization succeeded, %FALSE otherwise.
|
2003-06-24 06:02:56 +08:00
|
|
|
**/
|
|
|
|
gboolean
|
2003-10-11 22:30:18 +08:00
|
|
|
gimp_config_deserialize_string (GimpConfig *config,
|
2003-06-24 06:02:56 +08:00
|
|
|
const gchar *text,
|
|
|
|
gint text_len,
|
|
|
|
gpointer data,
|
|
|
|
GError **error)
|
|
|
|
{
|
2003-10-11 22:30:18 +08:00
|
|
|
GScanner *scanner;
|
|
|
|
gboolean success;
|
2003-06-24 06:02:56 +08:00
|
|
|
|
2003-10-11 22:30:18 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_CONFIG (config), FALSE);
|
2003-06-24 06:02:56 +08:00
|
|
|
g_return_val_if_fail (text != NULL || text_len == 0, FALSE);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
|
|
|
|
|
|
scanner = gimp_scanner_new_string (text, text_len, error);
|
|
|
|
|
2003-10-11 22:30:18 +08:00
|
|
|
success = GIMP_CONFIG_GET_INTERFACE (config)->deserialize (config,
|
|
|
|
scanner, 0, data);
|
2003-06-24 06:02:56 +08:00
|
|
|
|
|
|
|
gimp_scanner_destroy (scanner);
|
|
|
|
|
|
|
|
if (! success)
|
|
|
|
g_assert (error == NULL || *error != NULL);
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2002-05-27 22:04:21 +08:00
|
|
|
gboolean
|
|
|
|
gimp_config_deserialize_return (GScanner *scanner,
|
|
|
|
GTokenType expected_token,
|
2002-06-18 03:36:33 +08:00
|
|
|
gint nest_level)
|
2002-05-27 22:04:21 +08:00
|
|
|
{
|
|
|
|
GTokenType next_token;
|
|
|
|
|
|
|
|
g_return_val_if_fail (scanner != NULL, FALSE);
|
|
|
|
|
|
|
|
next_token = g_scanner_peek_next_token (scanner);
|
|
|
|
|
|
|
|
if (expected_token != G_TOKEN_LEFT_PAREN)
|
|
|
|
{
|
|
|
|
g_scanner_get_next_token (scanner);
|
2002-06-18 03:36:33 +08:00
|
|
|
g_scanner_unexp_token (scanner, expected_token, NULL, NULL, NULL,
|
2002-05-27 22:04:21 +08:00
|
|
|
_("fatal parse error"), TRUE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (nest_level > 0 && next_token == G_TOKEN_RIGHT_PAREN)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else if (next_token != G_TOKEN_EOF)
|
|
|
|
{
|
|
|
|
g_scanner_get_next_token (scanner);
|
2002-06-18 03:36:33 +08:00
|
|
|
g_scanner_unexp_token (scanner, expected_token, NULL, NULL, NULL,
|
2002-05-27 22:04:21 +08:00
|
|
|
_("fatal parse error"), TRUE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2002-05-24 10:53:20 +08:00
|
|
|
|
2002-05-04 07:48:03 +08:00
|
|
|
/**
|
|
|
|
* gimp_config_duplicate:
|
2003-10-11 22:30:18 +08:00
|
|
|
* @config: a #GObject that implements the #GimpConfigInterface.
|
2003-07-11 20:22:42 +08:00
|
|
|
*
|
2002-05-04 07:48:03 +08:00
|
|
|
* Creates a copy of the passed object by copying all object
|
|
|
|
* properties. The default implementation of the #GimpConfigInterface
|
|
|
|
* only works for objects that are completely defined by their
|
|
|
|
* properties.
|
2003-07-11 20:22:42 +08:00
|
|
|
*
|
2003-10-14 23:20:59 +08:00
|
|
|
* Return value: the duplicated #GimpConfig object
|
2002-05-04 07:48:03 +08:00
|
|
|
**/
|
2003-10-14 23:20:59 +08:00
|
|
|
gpointer
|
2003-10-11 22:30:18 +08:00
|
|
|
gimp_config_duplicate (GimpConfig *config)
|
2002-05-04 07:48:03 +08:00
|
|
|
{
|
2003-10-11 22:30:18 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_CONFIG (config), NULL);
|
2002-05-04 07:48:03 +08:00
|
|
|
|
2003-10-11 22:30:18 +08:00
|
|
|
return GIMP_CONFIG_GET_INTERFACE (config)->duplicate (config);
|
2002-05-04 07:48:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_config_is_equal_to:
|
|
|
|
* @a: a #GObject that implements the #GimpConfigInterface.
|
|
|
|
* @b: another #GObject of the same type as @a.
|
2003-07-11 20:22:42 +08:00
|
|
|
*
|
2002-05-04 07:48:03 +08:00
|
|
|
* Compares the two objects. The default implementation of the
|
|
|
|
* #GimpConfigInterface compares the object properties and thus only
|
|
|
|
* works for objects that are completely defined by their
|
|
|
|
* properties.
|
2003-07-11 20:22:42 +08:00
|
|
|
*
|
2002-05-04 07:48:03 +08:00
|
|
|
* Return value: %TRUE if the two objects are equal.
|
|
|
|
**/
|
|
|
|
gboolean
|
2003-10-11 22:30:18 +08:00
|
|
|
gimp_config_is_equal_to (GimpConfig *a,
|
|
|
|
GimpConfig *b)
|
2002-05-04 07:48:03 +08:00
|
|
|
{
|
2003-10-11 22:30:18 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_CONFIG (a), FALSE);
|
|
|
|
g_return_val_if_fail (GIMP_IS_CONFIG (b), FALSE);
|
2002-05-06 06:11:34 +08:00
|
|
|
g_return_val_if_fail (G_TYPE_FROM_INSTANCE (a) == G_TYPE_FROM_INSTANCE (b),
|
2002-05-04 07:48:03 +08:00
|
|
|
FALSE);
|
|
|
|
|
2003-10-11 22:30:18 +08:00
|
|
|
return GIMP_CONFIG_GET_INTERFACE (a)->equal (a, b);
|
2002-05-04 07:48:03 +08:00
|
|
|
}
|
|
|
|
|
2003-02-02 05:50:21 +08:00
|
|
|
/**
|
|
|
|
* gimp_config_reset:
|
2003-10-11 22:30:18 +08:00
|
|
|
* @config: a #GObject that implements the #GimpConfigInterface.
|
2003-07-11 20:22:42 +08:00
|
|
|
*
|
2003-02-02 05:50:21 +08:00
|
|
|
* Resets the object to its default state. The default implementation of the
|
|
|
|
* #GimpConfigInterface only works for objects that are completely defined by
|
|
|
|
* their properties.
|
|
|
|
**/
|
|
|
|
void
|
2003-10-11 22:30:18 +08:00
|
|
|
gimp_config_reset (GimpConfig *config)
|
2003-02-02 05:50:21 +08:00
|
|
|
{
|
2003-10-11 22:30:18 +08:00
|
|
|
g_return_if_fail (GIMP_IS_CONFIG (config));
|
2003-02-02 05:50:21 +08:00
|
|
|
|
2003-10-11 22:30:18 +08:00
|
|
|
GIMP_CONFIG_GET_INTERFACE (config)->reset (config);
|
2003-02-02 05:50:21 +08:00
|
|
|
}
|