From 34bc2207874b1d737e684993154bf183759d01d7 Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Fri, 8 Feb 2002 14:05:10 +0000 Subject: [PATCH] added gimp_rc_duplicate() and started to add inline documentation. 2002-02-08 Sven Neumann * app/config/gimprc.[ch]: added gimp_rc_duplicate() and started to add inline documentation. * app/config/test-config.c: test the new functionality. --- ChangeLog | 7 +++ app/config/gimprc.c | 92 ++++++++++++++++++++++++++++++++++------ app/config/gimprc.h | 5 ++- app/config/test-config.c | 11 +++-- 4 files changed, 98 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index bb7271f15e..391558996f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2002-02-08 Sven Neumann + + * app/config/gimprc.[ch]: added gimp_rc_duplicate() and started to + add inline documentation. + + * app/config/test-config.c: test the new functionality. + 2002-02-08 Sven Neumann * app/config/gimpbaseconfig.c diff --git a/app/config/gimprc.c b/app/config/gimprc.c index 4ab7cec6d0..838f7a7f3a 100644 --- a/app/config/gimprc.c +++ b/app/config/gimprc.c @@ -118,21 +118,89 @@ gimp_rc_deserialize (GObject *object, return gimp_config_deserialize_properties (object, scanner, TRUE); } +/** + * gimp_rc_new: + * + * Creates a new #GimpRc object with default configuration values. + * + * Return value: the newly generated #GimpRc object. + **/ GimpRc * gimp_rc_new (void) { return GIMP_RC (g_object_new (GIMP_TYPE_RC, NULL)); } +/** + * gimp_rc_duplicate: + * @rc: a #GimpRc object to duplicate. + * + * Creates a new @GimpRc object with all configuration values copied + * from @rc. + * + * Return value: the duplicated #GimpRc object. + **/ +GimpRc * +gimp_rc_duplicate (GimpRc *rc) +{ + GObject *dup; + GObjectClass *klass; + GParamSpec **property_specs; + guint n_property_specs; + guint i; + + g_return_val_if_fail (GIMP_IS_RC (rc), NULL); + + dup = g_object_new (GIMP_TYPE_RC, NULL); + + klass = G_OBJECT_GET_CLASS (rc); + + property_specs = g_object_class_list_properties (klass, &n_property_specs); + + if (!property_specs) + return GIMP_RC (dup); + + for (i = 0; i < n_property_specs; i++) + { + GParamSpec *prop_spec; + GValue value = { 0, }; + + prop_spec = property_specs[i]; + + if (! (prop_spec->flags & G_PARAM_READWRITE)) + continue; + + g_value_init (&value, prop_spec->value_type); + + g_object_get_property (G_OBJECT (rc), prop_spec->name, &value); + g_object_set_property (G_OBJECT (dup), prop_spec->name, &value); + } + + return GIMP_RC (dup); +} + +/** + * gimp_rc_write_changes: + * @new_rc: a #GimpRc object. + * @old_rc: another #GimpRc object. + * @filename: the name of the rc file to generate. If it is %NULL, stdout + * will be used. + * + * Writes all configuration values of @new_rc that differ from the values + * set in @old_rc to the file specified by @filename. If the file already + * exists, it is overwritten. + * + * Return value: TRUE on success, FALSE otherwise. + **/ gboolean -gimp_rc_write_changes (GimpRc *new, - GimpRc *old, +gimp_rc_write_changes (GimpRc *new_rc, + GimpRc *old_rc, 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); + g_return_val_if_fail (GIMP_IS_RC (new_rc), FALSE); + g_return_val_if_fail (GIMP_IS_RC (old_rc), FALSE); if (filename) fd = open (filename, O_WRONLY | O_CREAT, @@ -148,8 +216,8 @@ gimp_rc_write_changes (GimpRc *new, } gimp_rc_write_header (fd); - gimp_rc_serialize_changed_properties (new, old, fd); - gimp_config_serialize_unknown_tokens (G_OBJECT (new), fd); + gimp_rc_serialize_changed_properties (new_rc, old_rc, fd); + gimp_config_serialize_unknown_tokens (G_OBJECT (new_rc), fd); if (filename) close (fd); @@ -158,8 +226,8 @@ gimp_rc_write_changes (GimpRc *new, } static void -gimp_rc_serialize_changed_properties (GimpRc *new, - GimpRc *old, +gimp_rc_serialize_changed_properties (GimpRc *new_rc, + GimpRc *old_rc, gint fd) { GObjectClass *klass; @@ -168,7 +236,7 @@ gimp_rc_serialize_changed_properties (GimpRc *new, guint i; GString *str; - klass = G_OBJECT_GET_CLASS (new); + klass = G_OBJECT_GET_CLASS (new_rc); property_specs = g_object_class_list_properties (klass, &n_property_specs); @@ -190,8 +258,8 @@ gimp_rc_serialize_changed_properties (GimpRc *new, 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); + g_object_get_property (G_OBJECT (new_rc), prop_spec->name, &new_value); + g_object_get_property (G_OBJECT (old_rc), prop_spec->name, &old_value); if (!gimp_values_equal (&new_value, &old_value)) { @@ -206,7 +274,7 @@ gimp_rc_serialize_changed_properties (GimpRc *new, 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)), + g_type_name (G_TYPE_FROM_INSTANCE (new_rc)), prop_spec->name, g_type_name (prop_spec->value_type)); } diff --git a/app/config/gimprc.h b/app/config/gimprc.h index 56cc3e8844..cb7395abe9 100644 --- a/app/config/gimprc.h +++ b/app/config/gimprc.h @@ -48,9 +48,10 @@ struct _GimpRcClass GType gimp_rc_get_type (void) G_GNUC_CONST; GimpRc * gimp_rc_new (void); +GimpRc * gimp_rc_duplicate (GimpRc *rc); -gboolean gimp_rc_write_changes (GimpRc *new, - GimpRc *old, +gboolean gimp_rc_write_changes (GimpRc *new_rc, + GimpRc *old_rc, const gchar *filename); diff --git a/app/config/test-config.c b/app/config/test-config.c index 06e440a81b..dd069f409d 100644 --- a/app/config/test-config.c +++ b/app/config/test-config.c @@ -84,11 +84,16 @@ main (int argc, gimp_config_foreach_unknown_token (G_OBJECT (gimprc), output_unknown_token, &header); - g_print ("\n\nTesting gimp_rc_write_changes() ... \n\n"); + g_print ("\n\nChanging a property ... "); + g_object_set (G_OBJECT (gimprc), "use-help", FALSE, NULL); + + g_print ("\nTesting gimp_rc_duplicate() ... "); + gimprc2 = gimp_rc_duplicate (gimprc); + g_print ("done.\n"); + + g_print ("\nTesting gimp_rc_write_changes() ... \n\n"); - gimprc2 = gimp_rc_new (); g_object_set (G_OBJECT (gimprc2), "show-tips", FALSE, NULL); - gimp_rc_write_changes (gimprc2, gimprc, NULL); g_print ("\n");