From 7647db537bb0e8e6ceede2d4fca59954aecc1d21 Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Wed, 6 Apr 2005 21:37:40 +0000 Subject: [PATCH] added new function to reset a single property to its default value. 2005-04-06 Sven Neumann * libgimpconfig/gimpconfig-utils.[ch]: added new function to reset a single property to its default value. * libgimpconfig/gimpconfig.def: updated. * app/config/gimpbaseconfig.[ch]: reverted last change. * app/base/base.c: use gimp_config_reset_property() instead. --- ChangeLog | 11 ++++ app/base/base.c | 36 +++++----- app/config/gimpbaseconfig.c | 9 +-- app/config/gimpbaseconfig.h | 4 -- .../libgimpconfig/libgimpconfig-sections.txt | 1 + .../libgimpconfig/tmpl/gimpconfig-utils.sgml | 9 +++ libgimpconfig/gimpconfig-utils.c | 65 ++++++++++++++++++- libgimpconfig/gimpconfig-utils.h | 2 + libgimpconfig/gimpconfig.def | 1 + 9 files changed, 106 insertions(+), 32 deletions(-) diff --git a/ChangeLog b/ChangeLog index 497f10ada1..88d7cb5aac 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2005-04-06 Sven Neumann + + * libgimpconfig/gimpconfig-utils.[ch]: added new function to reset + a single property to its default value. + + * libgimpconfig/gimpconfig.def: updated. + + * app/config/gimpbaseconfig.[ch]: reverted last change. + + * app/base/base.c: use gimp_config_reset_property() instead. + 2005-04-06 Sven Neumann * app/Makefile.am: don't use -mwindows when linking gimp-console. diff --git a/app/base/base.c b/app/base/base.c index 1e4e2270ee..3a05756415 100644 --- a/app/base/base.c +++ b/app/base/base.c @@ -55,13 +55,14 @@ GimpBaseConfig *base_config = NULL; -static void base_toast_old_temp_files (GimpBaseConfig *config); -static void base_tile_cache_size_notify (GObject *config, - GParamSpec *param_spec, - gpointer data); -static void base_num_processors_notify (GObject *config, - GParamSpec *param_spec, - gpointer data); +static void base_toast_old_swap_files (const gchar *swap_path); + +static void base_tile_cache_size_notify (GObject *config, + GParamSpec *param_spec, + gpointer data); +static void base_num_processors_notify (GObject *config, + GParamSpec *param_spec, + gpointer data); /* public functions */ @@ -84,23 +85,18 @@ base_init (GimpBaseConfig *config, G_CALLBACK (base_tile_cache_size_notify), NULL); - base_toast_old_temp_files (config); + if (! config->swap_path || ! *config->swap_path) + gimp_config_reset_property (GIMP_CONFIG (config), "swap-path"); - /* Add the swap file */ - if (! config->swap_path) - g_object_set (config, - "swap-path", gimp_base_config_default_swap_path, - NULL); + base_toast_old_swap_files (config->swap_path); tile_swap_init (config->swap_path); swap_is_ok = tile_swap_test (); /* create the temp directory if it doesn't exist */ - if (! config->temp_path) - g_object_set (config, - "temp-path", gimp_base_config_default_temp_path, - NULL); + if (! config->temp_path || ! *config->temp_path) + gimp_config_reset_property (GIMP_CONFIG (config), "temp-path"); temp_dir = gimp_config_path_expand (config->temp_path, TRUE, NULL); @@ -147,16 +143,16 @@ base_exit (void) /* private functions */ static void -base_toast_old_temp_files (GimpBaseConfig *config) +base_toast_old_swap_files (const gchar *swap_path) { GDir *dir = NULL; gchar *dirname; const char *entry; - if (!config->swap_path) + if (! swap_path) return; - dirname = gimp_config_path_expand (config->swap_path, TRUE, NULL); + dirname = gimp_config_path_expand (swap_path, TRUE, NULL); if (!dirname) return; diff --git a/app/config/gimpbaseconfig.c b/app/config/gimpbaseconfig.c index eadc15fdca..2cf7927f1f 100644 --- a/app/config/gimpbaseconfig.c +++ b/app/config/gimpbaseconfig.c @@ -36,11 +36,6 @@ #include "gimp-intl.h" -const gchar *gimp_base_config_default_swap_path = "${gimp_dir}"; -const gchar *gimp_base_config_default_temp_path = - "${gimp_dir}" G_DIR_SEPARATOR_S "tmp"; - - static void gimp_base_config_class_init (GimpBaseConfigClass *klass); static void gimp_base_config_finalize (GObject *object); static void gimp_base_config_set_property (GObject *object, @@ -110,12 +105,12 @@ gimp_base_config_class_init (GimpBaseConfigClass *klass) GIMP_CONFIG_INSTALL_PROP_PATH (object_class, PROP_TEMP_PATH, "temp-path", TEMP_PATH_BLURB, GIMP_CONFIG_PATH_DIR, - gimp_base_config_default_temp_path, + "${gimp_dir}" G_DIR_SEPARATOR_S "tmp", GIMP_CONFIG_PARAM_RESTART); GIMP_CONFIG_INSTALL_PROP_PATH (object_class, PROP_SWAP_PATH, "swap-path", SWAP_PATH_BLURB, GIMP_CONFIG_PATH_DIR, - gimp_base_config_default_swap_path, + "${gimp_dir}", GIMP_CONFIG_PARAM_RESTART); GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_STINGY_MEMORY_USE, "stingy-memory-use", diff --git a/app/config/gimpbaseconfig.h b/app/config/gimpbaseconfig.h index 20266f058f..2f48769ae6 100644 --- a/app/config/gimpbaseconfig.h +++ b/app/config/gimpbaseconfig.h @@ -51,10 +51,6 @@ struct _GimpBaseConfigClass }; -extern const gchar *gimp_base_config_default_swap_path; -extern const gchar *gimp_base_config_default_temp_path; - - GType gimp_base_config_get_type (void) G_GNUC_CONST; diff --git a/devel-docs/libgimpconfig/libgimpconfig-sections.txt b/devel-docs/libgimpconfig/libgimpconfig-sections.txt index eb8610a7fd..698341739e 100644 --- a/devel-docs/libgimpconfig/libgimpconfig-sections.txt +++ b/devel-docs/libgimpconfig/libgimpconfig-sections.txt @@ -90,6 +90,7 @@ gimp_config_serialize_value gimp_config_diff gimp_config_sync gimp_config_reset_properties +gimp_config_reset_property gimp_config_string_append_escaped diff --git a/devel-docs/libgimpconfig/tmpl/gimpconfig-utils.sgml b/devel-docs/libgimpconfig/tmpl/gimpconfig-utils.sgml index 7b13723ea2..a882d21f0b 100644 --- a/devel-docs/libgimpconfig/tmpl/gimpconfig-utils.sgml +++ b/devel-docs/libgimpconfig/tmpl/gimpconfig-utils.sgml @@ -45,6 +45,15 @@ Miscellaneous utility functions for libgimpconfig. @config: + + + + + +@config: +@property_name: + + diff --git a/libgimpconfig/gimpconfig-utils.c b/libgimpconfig/gimpconfig-utils.c index 819de18e37..29538bc898 100644 --- a/libgimpconfig/gimpconfig-utils.c +++ b/libgimpconfig/gimpconfig-utils.c @@ -240,7 +240,7 @@ gimp_config_sync (GimpConfig *src, /** * gimp_config_reset_properties: - * @config: a #GimpConfig + * @config: a #GimpConfig object * * Resets all writable properties of @object to the default values as * defined in their #GParamSpec. Properties marked as "construct-only" @@ -314,6 +314,69 @@ gimp_config_reset_properties (GimpConfig *config) } +/** + * gimp_config_reset_property: + * @config: a #GimpConfig object + * @property_name: name of the property to reset + * + * Resets the property named @property_name to its default value. + * Nothing happens if the property is not writable or marked as + * "construct-only". + * + * Since: GIMP 2.4 + **/ +void +gimp_config_reset_property (GimpConfig *config, + const gchar *property_name) +{ + GObjectClass *klass; + GParamSpec *prop_spec; + + g_return_if_fail (GIMP_IS_CONFIG (config)); + g_return_if_fail (property_name != NULL); + + klass = G_OBJECT_GET_CLASS (config); + + prop_spec = g_object_class_find_property (klass, property_name); + + if (!prop_spec) + return; + + if ((prop_spec->flags & G_PARAM_WRITABLE) && + ! (prop_spec->flags & G_PARAM_CONSTRUCT_ONLY)) + { + GObject *object = G_OBJECT (config); + GValue value = { 0, }; + + if (G_IS_PARAM_SPEC_OBJECT (prop_spec)) + { + if ((prop_spec->flags & GIMP_CONFIG_PARAM_SERIALIZE) && + (prop_spec->flags & GIMP_CONFIG_PARAM_AGGREGATE) && + g_type_interface_peek (g_type_class_peek (prop_spec->value_type), + GIMP_TYPE_CONFIG)) + { + g_value_init (&value, prop_spec->value_type); + + g_object_get_property (object, prop_spec->name, &value); + + gimp_config_reset (GIMP_CONFIG (g_value_get_object (&value))); + + g_value_unset (&value); + } + } + else + { + g_value_init (&value, prop_spec->value_type); + g_param_value_set_default (prop_spec, &value); + + g_object_set_property (object, prop_spec->name, &value); + + g_value_unset (&value); + } + } +} + + /* * GimpConfig string utilities */ diff --git a/libgimpconfig/gimpconfig-utils.h b/libgimpconfig/gimpconfig-utils.h index 7baf188dde..c249ec4db0 100644 --- a/libgimpconfig/gimpconfig-utils.h +++ b/libgimpconfig/gimpconfig-utils.h @@ -32,6 +32,8 @@ gboolean gimp_config_sync (GimpConfig *src, GParamFlags flags); void gimp_config_reset_properties (GimpConfig *config); +void gimp_config_reset_property (GimpConfig *config, + const gchar *property_name); void gimp_config_string_append_escaped (GString *string, const gchar *val); diff --git a/libgimpconfig/gimpconfig.def b/libgimpconfig/gimpconfig.def index 96228cac13..84c1be253d 100644 --- a/libgimpconfig/gimpconfig.def +++ b/libgimpconfig/gimpconfig.def @@ -21,6 +21,7 @@ EXPORTS gimp_config_path_get_type gimp_config_reset gimp_config_reset_properties + gimp_config_reset_property gimp_config_serialize_changed_properties gimp_config_serialize_properties gimp_config_serialize_property