mirror of https://github.com/GNOME/gimp.git
app/config/gimpconfig-serialize.[ch] app/config/gimpconfig.h added new
2001-12-28 Sven Neumann <sven@gimp.org> * app/config/gimpconfig-serialize.[ch] * app/config/gimpconfig.h * app/config/gimprc.[ch]: added new function to only write changes to the personal gimprc. * app/config/test-config.c: test the new functionality. * tools/pdbgen/pdb/procedural_db.pdb: the change I did yesterday wasn't overly clever; here's a better one. * app/pdb/procedural_db_cmds.c: regenerated.
This commit is contained in:
parent
9782493033
commit
d2990f2f1e
14
ChangeLog
14
ChangeLog
|
@ -1,3 +1,17 @@
|
|||
2001-12-28 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* app/config/gimpconfig-serialize.[ch]
|
||||
* app/config/gimpconfig.h
|
||||
* app/config/gimprc.[ch]: added new function to only write changes to
|
||||
the personal gimprc.
|
||||
|
||||
* app/config/test-config.c: test the new functionality.
|
||||
|
||||
* tools/pdbgen/pdb/procedural_db.pdb: the change I did yesterday
|
||||
wasn't overly clever; here's a better one.
|
||||
|
||||
* app/pdb/procedural_db_cmds.c: regenerated.
|
||||
|
||||
2001-12-28 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* app/plug-in/Makefile.am
|
||||
|
|
|
@ -32,14 +32,6 @@
|
|||
#include "gimpconfig-types.h"
|
||||
|
||||
|
||||
static gboolean gimpconfig_serialize_value (const GValue *value,
|
||||
GString *str);
|
||||
|
||||
static void serialize_unknown_token (const gchar *key,
|
||||
const gchar *value,
|
||||
gpointer data);
|
||||
|
||||
|
||||
void
|
||||
gimp_config_serialize_properties (GObject *object,
|
||||
gint fd)
|
||||
|
@ -77,7 +69,7 @@ gimp_config_serialize_properties (GObject *object,
|
|||
g_string_assign (str, "(");
|
||||
g_string_append (str, prop_spec->name);
|
||||
|
||||
if (gimpconfig_serialize_value (&value, str))
|
||||
if (gimp_config_serialize_value (&value, str))
|
||||
{
|
||||
g_string_append (str, ")\n");
|
||||
write (fd, str->str, str->len);
|
||||
|
@ -97,9 +89,9 @@ gimp_config_serialize_properties (GObject *object,
|
|||
g_string_free (str, TRUE);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gimpconfig_serialize_value (const GValue *value,
|
||||
GString *str)
|
||||
gboolean
|
||||
gimp_config_serialize_value (const GValue *value,
|
||||
GString *str)
|
||||
{
|
||||
if (G_VALUE_HOLDS_BOOLEAN (value))
|
||||
{
|
||||
|
@ -165,6 +157,11 @@ gimpconfig_serialize_value (const GValue *value,
|
|||
}
|
||||
|
||||
|
||||
static void serialize_unknown_token (const gchar *key,
|
||||
const gchar *value,
|
||||
gpointer data);
|
||||
|
||||
|
||||
void
|
||||
gimp_config_serialize_unknown_tokens (GObject *object,
|
||||
gint fd)
|
||||
|
|
|
@ -23,10 +23,12 @@
|
|||
#define __GIMP_CONFIG_SERIALIZE_H__
|
||||
|
||||
|
||||
void gimp_config_serialize_properties (GObject *object,
|
||||
gint fd);
|
||||
void gimp_config_serialize_unknown_tokens (GObject *object,
|
||||
gint fd);
|
||||
void gimp_config_serialize_properties (GObject *object,
|
||||
gint fd);
|
||||
void gimp_config_serialize_unknown_tokens (GObject *object,
|
||||
gint fd);
|
||||
gboolean gimp_config_serialize_value (const GValue *value,
|
||||
GString *str);
|
||||
|
||||
|
||||
#endif /* __GIMP_CONFIG_SERIALIZE_H__ */
|
||||
|
|
|
@ -38,9 +38,9 @@ struct _GimpConfigInterface
|
|||
GScanner *scanner);
|
||||
};
|
||||
|
||||
typedef void (*GimpConfigForeachFunc) (const gchar *key,
|
||||
const gchar *value,
|
||||
gpointer user_data);
|
||||
typedef void (* GimpConfigForeachFunc) (const gchar *key,
|
||||
const gchar *value,
|
||||
gpointer user_data);
|
||||
|
||||
|
||||
GType gimp_config_interface_get_type (void) G_GNUC_CONST;
|
||||
|
|
|
@ -21,6 +21,12 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include "libgimpbase/gimpbase.h"
|
||||
|
@ -30,13 +36,21 @@
|
|||
#include "gimpconfig-deserialize.h"
|
||||
#include "gimprc.h"
|
||||
|
||||
#include "libgimp/gimpintl.h"
|
||||
|
||||
static void gimp_rc_config_iface_init (gpointer iface,
|
||||
gpointer iface_data);
|
||||
static void gimp_rc_serialize (GObject *object,
|
||||
gint fd);
|
||||
static gboolean gimp_rc_deserialize (GObject *object,
|
||||
GScanner *scanner);
|
||||
|
||||
static void gimp_rc_config_iface_init (gpointer iface,
|
||||
gpointer iface_data);
|
||||
|
||||
static void gimp_rc_serialize (GObject *object,
|
||||
gint fd);
|
||||
static gboolean gimp_rc_deserialize (GObject *object,
|
||||
GScanner *scanner);
|
||||
static void gimp_rc_serialize_changed_properties (GimpRc *new,
|
||||
GimpRc *old,
|
||||
gint fd);
|
||||
static gboolean gimp_values_equal (const GValue *a,
|
||||
const GValue *b);
|
||||
|
||||
|
||||
GType
|
||||
|
@ -105,9 +119,134 @@ gimp_rc_deserialize (GObject *object,
|
|||
GimpRc *
|
||||
gimp_rc_new (void)
|
||||
{
|
||||
GimpRc *gimprc;
|
||||
|
||||
gimprc = GIMP_RC (g_object_new (GIMP_TYPE_RC, NULL));
|
||||
|
||||
return gimprc;
|
||||
return GIMP_RC (g_object_new (GIMP_TYPE_RC, NULL));
|
||||
}
|
||||
|
||||
gboolean
|
||||
gimp_rc_write_changes (GimpRc *new,
|
||||
GimpRc *old,
|
||||
const gchar *filename)
|
||||
{
|
||||
gint fd;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_RC (new), FALSE);
|
||||
g_return_val_if_fail (GIMP_IS_RC (old), FALSE);
|
||||
|
||||
if (filename)
|
||||
fd = open (filename, O_WRONLY | O_CREAT,
|
||||
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
|
||||
else
|
||||
fd = 1; /* stdout */
|
||||
|
||||
if (fd == -1)
|
||||
{
|
||||
g_message (_("Failed to open file '%s': %s"),
|
||||
filename, g_strerror (errno));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gimp_rc_serialize_changed_properties (new, old, fd);
|
||||
gimp_config_serialize_unknown_tokens (G_OBJECT (new), fd);
|
||||
|
||||
if (filename)
|
||||
close (fd);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_rc_serialize_changed_properties (GimpRc *new,
|
||||
GimpRc *old,
|
||||
gint fd)
|
||||
{
|
||||
GObjectClass *klass;
|
||||
GParamSpec **property_specs;
|
||||
guint n_property_specs;
|
||||
guint i;
|
||||
GString *str;
|
||||
|
||||
klass = G_OBJECT_GET_CLASS (new);
|
||||
|
||||
property_specs = g_object_class_list_properties (klass, &n_property_specs);
|
||||
|
||||
if (!property_specs)
|
||||
return;
|
||||
|
||||
str = g_string_new (NULL);
|
||||
|
||||
for (i = 0; i < n_property_specs; i++)
|
||||
{
|
||||
GParamSpec *prop_spec;
|
||||
GValue new_value = { 0, };
|
||||
GValue old_value = { 0, };
|
||||
|
||||
prop_spec = property_specs[i];
|
||||
|
||||
if (! (prop_spec->flags & G_PARAM_READWRITE))
|
||||
continue;
|
||||
|
||||
g_value_init (&new_value, prop_spec->value_type);
|
||||
g_value_init (&old_value, prop_spec->value_type);
|
||||
g_object_get_property (G_OBJECT (new), prop_spec->name, &new_value);
|
||||
g_object_get_property (G_OBJECT (old), prop_spec->name, &old_value);
|
||||
|
||||
if (!gimp_values_equal (&new_value, &old_value))
|
||||
{
|
||||
g_string_assign (str, "(");
|
||||
g_string_append (str, prop_spec->name);
|
||||
|
||||
if (gimp_config_serialize_value (&new_value, str))
|
||||
{
|
||||
g_string_append (str, ")\n");
|
||||
write (fd, str->str, str->len);
|
||||
}
|
||||
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_value_unset (&old_value);
|
||||
}
|
||||
|
||||
g_free (property_specs);
|
||||
g_string_free (str, TRUE);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gimp_values_equal (const GValue *a,
|
||||
const GValue *b)
|
||||
{
|
||||
g_return_val_if_fail (G_VALUE_TYPE (a) == G_VALUE_TYPE (b), FALSE);
|
||||
|
||||
if (g_value_fits_pointer (a))
|
||||
{
|
||||
if (a->data[0].v_pointer == b->data[0].v_pointer)
|
||||
return TRUE;
|
||||
|
||||
if (G_VALUE_HOLDS_STRING (a))
|
||||
{
|
||||
const gchar *a_str = g_value_get_string (a);
|
||||
const gchar *b_str = g_value_get_string (b);
|
||||
|
||||
if (a_str && b_str)
|
||||
return (strcmp (a_str, b_str) == 0);
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_warning ("%s: Can not compare values of type %s.",
|
||||
G_STRLOC, G_VALUE_TYPE_NAME (a));
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return (a->data[0].v_uint64 == b->data[0].v_uint64);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,8 +46,12 @@ struct _GimpRcClass
|
|||
};
|
||||
|
||||
|
||||
GType gimp_rc_get_type (void) G_GNUC_CONST;
|
||||
GimpRc * gimp_rc_new (void);
|
||||
GType gimp_rc_get_type (void) G_GNUC_CONST;
|
||||
GimpRc * gimp_rc_new (void);
|
||||
|
||||
gboolean gimp_rc_write_changes (GimpRc *new,
|
||||
GimpRc *old,
|
||||
const gchar *filename);
|
||||
|
||||
|
||||
#endif /* GIMP_RC_H__ */
|
||||
|
|
|
@ -45,6 +45,7 @@ main (int argc,
|
|||
char *argv[])
|
||||
{
|
||||
GimpRc *gimprc;
|
||||
GimpRc *gimprc2;
|
||||
const gchar *filename = "foorc";
|
||||
gchar *header;
|
||||
gint i;
|
||||
|
@ -83,9 +84,17 @@ main (int argc,
|
|||
gimp_config_foreach_unknown_token (G_OBJECT (gimprc),
|
||||
output_unknown_token, &header);
|
||||
|
||||
g_print ("\n Testing gimp_rc_write_changes() ... ");
|
||||
|
||||
gimprc2 = gimp_rc_new ();
|
||||
g_object_set (G_OBJECT (gimprc2), "show-tips", FALSE, NULL);
|
||||
|
||||
gimp_rc_write_changes (gimprc2, gimprc, NULL);
|
||||
|
||||
g_print ("\n");
|
||||
|
||||
g_object_unref (G_OBJECT (gimprc));
|
||||
g_object_unref (G_OBJECT (gimprc2));
|
||||
|
||||
g_print ("Done.\n\n");
|
||||
|
||||
|
|
|
@ -134,7 +134,7 @@ match_strings (regex_t *preg,
|
|||
gchar *a)
|
||||
{
|
||||
if (!a)
|
||||
return 0;
|
||||
a = "";
|
||||
|
||||
return regexec (preg, a, 0, NULL, 0);
|
||||
}
|
||||
|
|
|
@ -38,9 +38,9 @@ struct _GimpConfigInterface
|
|||
GScanner *scanner);
|
||||
};
|
||||
|
||||
typedef void (*GimpConfigForeachFunc) (const gchar *key,
|
||||
const gchar *value,
|
||||
gpointer user_data);
|
||||
typedef void (* GimpConfigForeachFunc) (const gchar *key,
|
||||
const gchar *value,
|
||||
gpointer user_data);
|
||||
|
||||
|
||||
GType gimp_config_interface_get_type (void) G_GNUC_CONST;
|
||||
|
|
|
@ -32,14 +32,6 @@
|
|||
#include "gimpconfig-types.h"
|
||||
|
||||
|
||||
static gboolean gimpconfig_serialize_value (const GValue *value,
|
||||
GString *str);
|
||||
|
||||
static void serialize_unknown_token (const gchar *key,
|
||||
const gchar *value,
|
||||
gpointer data);
|
||||
|
||||
|
||||
void
|
||||
gimp_config_serialize_properties (GObject *object,
|
||||
gint fd)
|
||||
|
@ -77,7 +69,7 @@ gimp_config_serialize_properties (GObject *object,
|
|||
g_string_assign (str, "(");
|
||||
g_string_append (str, prop_spec->name);
|
||||
|
||||
if (gimpconfig_serialize_value (&value, str))
|
||||
if (gimp_config_serialize_value (&value, str))
|
||||
{
|
||||
g_string_append (str, ")\n");
|
||||
write (fd, str->str, str->len);
|
||||
|
@ -97,9 +89,9 @@ gimp_config_serialize_properties (GObject *object,
|
|||
g_string_free (str, TRUE);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gimpconfig_serialize_value (const GValue *value,
|
||||
GString *str)
|
||||
gboolean
|
||||
gimp_config_serialize_value (const GValue *value,
|
||||
GString *str)
|
||||
{
|
||||
if (G_VALUE_HOLDS_BOOLEAN (value))
|
||||
{
|
||||
|
@ -165,6 +157,11 @@ gimpconfig_serialize_value (const GValue *value,
|
|||
}
|
||||
|
||||
|
||||
static void serialize_unknown_token (const gchar *key,
|
||||
const gchar *value,
|
||||
gpointer data);
|
||||
|
||||
|
||||
void
|
||||
gimp_config_serialize_unknown_tokens (GObject *object,
|
||||
gint fd)
|
||||
|
|
|
@ -23,10 +23,12 @@
|
|||
#define __GIMP_CONFIG_SERIALIZE_H__
|
||||
|
||||
|
||||
void gimp_config_serialize_properties (GObject *object,
|
||||
gint fd);
|
||||
void gimp_config_serialize_unknown_tokens (GObject *object,
|
||||
gint fd);
|
||||
void gimp_config_serialize_properties (GObject *object,
|
||||
gint fd);
|
||||
void gimp_config_serialize_unknown_tokens (GObject *object,
|
||||
gint fd);
|
||||
gboolean gimp_config_serialize_value (const GValue *value,
|
||||
GString *str);
|
||||
|
||||
|
||||
#endif /* __GIMP_CONFIG_SERIALIZE_H__ */
|
||||
|
|
|
@ -450,7 +450,7 @@ match_strings (regex_t *preg,
|
|||
gchar *a)
|
||||
{
|
||||
if (!a)
|
||||
return 0;
|
||||
a = "";
|
||||
|
||||
return regexec (preg, a, 0, NULL, 0);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue