diff options
author | Rodrigo Moya <rodrigo@ximian.com> | 2002-08-27 22:10:42 +0800 |
---|---|---|
committer | Rodrigo Moya <rodrigo@src.gnome.org> | 2002-08-27 22:10:42 +0800 |
commit | 7414b866844f59e09c648863f8daa57d7258cfd0 (patch) | |
tree | c795f3d64e4d4b1972ae40114f01c9ecb879ea0e /e-util | |
parent | 07f076dd90cd0bb4eecb8215b1d53024b19545f3 (diff) | |
download | gsoc2013-evolution-7414b866844f59e09c648863f8daa57d7258cfd0.tar.gz gsoc2013-evolution-7414b866844f59e09c648863f8daa57d7258cfd0.tar.zst gsoc2013-evolution-7414b866844f59e09c648863f8daa57d7258cfd0.zip |
new functions. (property_change_cb, add_key): added support for FLOAT
2002-08-27 Rodrigo Moya <rodrigo@ximian.com>
* e-config-listener.c[ch] (e_config_listener_get_float_with_default,
e_config_listener_set_boolean, e_config_listener_set_float): new
functions.
(property_change_cb, add_key): added support for FLOAT values.
(e_config_listener_set_string): free strings before returning.
svn path=/trunk/; revision=17873
Diffstat (limited to 'e-util')
-rw-r--r-- | e-util/ChangeLog | 8 | ||||
-rw-r--r-- | e-util/e-config-listener.c | 94 | ||||
-rw-r--r-- | e-util/e-config-listener.h | 10 |
3 files changed, 110 insertions, 2 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog index 3d6dd456f8..fcfbb86bcc 100644 --- a/e-util/ChangeLog +++ b/e-util/ChangeLog @@ -1,3 +1,11 @@ +2002-08-27 Rodrigo Moya <rodrigo@ximian.com> + + * e-config-listener.c[ch] (e_config_listener_get_float_with_default, + e_config_listener_set_boolean, e_config_listener_set_float): new + functions. + (property_change_cb, add_key): added support for FLOAT values. + (e_config_listener_set_string): free strings before returning. + 2002-08-26 Peter Williams <peterw@ximian.com> * e-dialog-utils.c (set_transient_for_gdk): If gdk_window_foreign_new diff --git a/e-util/e-config-listener.c b/e-util/e-config-listener.c index 028f5ecc8e..1d4f38ce87 100644 --- a/e-util/e-config-listener.c +++ b/e-util/e-config-listener.c @@ -24,6 +24,7 @@ typedef struct { GtkFundamentalType type; union { gboolean v_bool; + float v_float; long v_long; char *v_str; } value; @@ -191,6 +192,9 @@ property_change_cb (BonoboListener *listener, if (bonobo_arg_type_is_equal (any->_type, BONOBO_ARG_BOOLEAN, NULL)) { kd->type = GTK_TYPE_BOOL; kd->value.v_bool = BONOBO_ARG_GET_BOOLEAN (any); + } else if (bonobo_arg_type_is_equal (any->_type, BONOBO_ARG_FLOAT, NULL)) { + kd->type = GTK_TYPE_FLOAT; + kd->value.v_float = BONOBO_ARG_GET_FLOAT (any); } else if (bonobo_arg_type_is_equal (any->_type, BONOBO_ARG_LONG, NULL)) { kd->type = GTK_TYPE_LONG; kd->value.v_long = BONOBO_ARG_GET_LONG (any); @@ -221,6 +225,9 @@ add_key (EConfigListener *cl, const char *key, GtkFundamentalType type, case GTK_TYPE_BOOL : memcpy (&kd->value.v_bool, value, sizeof (gboolean)); break; + case GTK_TYPE_FLOAT : + memcpy (&kd->value.v_float, value, sizeof (float)); + break; case GTK_TYPE_LONG : memcpy (&kd->value.v_long, value, sizeof (long)); break; @@ -297,6 +304,43 @@ e_config_listener_get_boolean_with_default (EConfigListener *cl, return value; } +float +e_config_listener_get_float_with_default (EConfigListener *cl, + const char *key, + float def, + gboolean *used_default) +{ + float value; + KeyData *kd; + gboolean d; + gpointer orig_key, orig_value; + + g_return_val_if_fail (E_IS_CONFIG_LISTENER (cl), -1); + g_return_val_if_fail (key != NULL, -1); + + /* search for the key in our hash table */ + if (!g_hash_table_lookup_extended (cl->priv->keys, key, &orig_key, &orig_value)) { + /* not found, so retrieve it from the configuration database */ + value = bonobo_config_get_float_with_default (cl->priv->db, key, def, &d); + kd = add_key (cl, key, GTK_TYPE_FLOAT, &value, d); + + if (used_default != NULL) + *used_default = d; + } else { + kd = (KeyData *) orig_value; + g_assert (kd != NULL); + + if (kd->type == GTK_TYPE_FLOAT) { + value = kd->value.v_float; + if (used_default != NULL) + *used_default = kd->used_default; + } else + return -1; + } + + return value; +} + long e_config_listener_get_long_with_default (EConfigListener *cl, const char *key, @@ -375,6 +419,48 @@ e_config_listener_get_string_with_default (EConfigListener *cl, } void +e_config_listener_set_boolean (EConfigListener *cl, const char *key, gboolean value) +{ + CORBA_Environment ev; + + g_return_if_fail (E_IS_CONFIG_LISTENER (cl)); + g_return_if_fail (key != NULL); + + /* check that the value is not the same */ + if (value == e_config_listener_get_boolean_with_default (cl, key, 0, NULL)) + return; + + CORBA_exception_init (&ev); + + bonobo_config_set_boolean (cl->priv->db, key, value, &ev); + if (BONOBO_EX (&ev)) + g_warning ("Cannot save config key %s -- %s", key, BONOBO_EX_ID (&ev)); + + CORBA_exception_free (&ev); +} + +void +e_config_listener_set_float (EConfigListener *cl, const char *key, float value) +{ + CORBA_Environment ev; + + g_return_if_fail (E_IS_CONFIG_LISTENER (cl)); + g_return_if_fail (key != NULL); + + /* check that the value is not the same */ + if (value == e_config_listener_get_float_with_default (cl, key, 0, NULL)) + return; + + CORBA_exception_init (&ev); + + bonobo_config_set_float (cl->priv->db, key, value, &ev); + if (BONOBO_EX (&ev)) + g_warning ("Cannot save config key %s -- %s", key, BONOBO_EX_ID (&ev)); + + CORBA_exception_free (&ev); +} + +void e_config_listener_set_long (EConfigListener *cl, const char *key, long value) { CORBA_Environment ev; @@ -405,10 +491,14 @@ e_config_listener_set_string (EConfigListener *cl, const char *key, const char * g_return_if_fail (key != NULL); /* check that the value is not the same */ - s1 = value; + s1 = (char *) value; s2 = e_config_listener_get_string_with_default (cl, key, NULL, NULL); - if (!strcmp (s1 ? s1 : "", s2 ? s2 : "")) + if (!strcmp (s1 ? s1 : "", s2 ? s2 : "")) { + g_free (s2); return; + } + + g_free (s2); CORBA_exception_init (&ev); diff --git a/e-util/e-config-listener.h b/e-util/e-config-listener.h index 9ac2f522e6..cc526e8735 100644 --- a/e-util/e-config-listener.h +++ b/e-util/e-config-listener.h @@ -43,6 +43,10 @@ gboolean e_config_listener_get_boolean_with_default (EConfigListene const char *key, gboolean def, gboolean *used_default); +float e_config_listener_get_float_with_default (EConfigListener *cl, + const char *key, + float def, + gboolean *used_default); long e_config_listener_get_long_with_default (EConfigListener *cl, const char *key, long def, @@ -51,6 +55,12 @@ char *e_config_listener_get_string_with_default (EConfigListener const char *key, const char *def, gboolean *used_default); +void e_config_listener_set_boolean (EConfigListener *cl, + const char *key, + gboolean value); +void e_config_listener_set_float (EConfigListener *cl, + const char *key, + float value); void e_config_listener_set_long (EConfigListener *cl, const char *key, long value); |