Commit 7647db53 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann
Browse files

added new function to reset a single property to its default value.

2005-04-06  Sven Neumann  <sven@gimp.org>

	* 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.
parent d4645e25
2005-04-06 Sven Neumann <sven@gimp.org>
* 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 <sven@gimp.org>
* app/Makefile.am: don't use -mwindows when linking gimp-console.
......
......@@ -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;
......
......@@ -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",
......
......@@ -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;
......
......@@ -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
</SECTION>
......
......@@ -45,6 +45,15 @@ Miscellaneous utility functions for libgimpconfig.
@config:
<!-- ##### FUNCTION gimp_config_reset_property ##### -->
<para>
</para>
@config:
@property_name:
<!-- ##### FUNCTION gimp_config_string_append_escaped ##### -->
<para>
......
......@@ -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
*/
......
......@@ -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);
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment