aboutsummaryrefslogtreecommitdiffstats
path: root/e-util
diff options
context:
space:
mode:
authorRodrigo Moya <rodrigo@ximian.com>2002-08-23 18:54:49 +0800
committerRodrigo Moya <rodrigo@src.gnome.org>2002-08-23 18:54:49 +0800
commitc0ffa4248356ef5023f4daa6259d0b088899a21c (patch)
tree377ad6434a94d9cc62bf2ed30e5859c2c166b779 /e-util
parent57eb3a20f5c13c551fabd7bab73cdae4ce67bfb0 (diff)
downloadgsoc2013-evolution-c0ffa4248356ef5023f4daa6259d0b088899a21c.tar
gsoc2013-evolution-c0ffa4248356ef5023f4daa6259d0b088899a21c.tar.gz
gsoc2013-evolution-c0ffa4248356ef5023f4daa6259d0b088899a21c.tar.bz2
gsoc2013-evolution-c0ffa4248356ef5023f4daa6259d0b088899a21c.tar.lz
gsoc2013-evolution-c0ffa4248356ef5023f4daa6259d0b088899a21c.tar.xz
gsoc2013-evolution-c0ffa4248356ef5023f4daa6259d0b088899a21c.tar.zst
gsoc2013-evolution-c0ffa4248356ef5023f4daa6259d0b088899a21c.zip
added "key_changed" signal to class. (property_change_cb): emit
2002-08-22 Rodrigo Moya <rodrigo@ximian.com> * e-config-listener.[ch]: added "key_changed" signal to class. (property_change_cb): emit "key_changed" signal. (e_config_listener_set_long): new function. (e_config_listener_get_long_with_default): new function. svn path=/trunk/; revision=17847
Diffstat (limited to 'e-util')
-rw-r--r--e-util/ChangeLog7
-rw-r--r--e-util/e-config-listener.c163
-rw-r--r--e-util/e-config-listener.h20
3 files changed, 156 insertions, 34 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog
index c1b916be6f..6b7fa1d3ec 100644
--- a/e-util/ChangeLog
+++ b/e-util/ChangeLog
@@ -1,3 +1,10 @@
+2002-08-22 Rodrigo Moya <rodrigo@ximian.com>
+
+ * e-config-listener.[ch]: added "key_changed" signal to class.
+ (property_change_cb): emit "key_changed" signal.
+ (e_config_listener_set_long): new function.
+ (e_config_listener_get_long_with_default): new function.
+
2002-08-22 Dan Winship <danw@ximian.com>
* e-path.c (e_path_rmdir): Remove an e_path directory, and its
diff --git a/e-util/e-config-listener.c b/e-util/e-config-listener.c
index e6fd8dbb9c..df3dfdf27c 100644
--- a/e-util/e-config-listener.c
+++ b/e-util/e-config-listener.c
@@ -8,6 +8,7 @@
* Copyright 2002, Ximian, Inc.
*/
+#include <gtk/gtksignal.h>
#include <gtk/gtktypeutils.h>
#include <bonobo/bonobo-exception.h>
#include <bonobo/bonobo-event-source.h>
@@ -22,8 +23,9 @@ typedef struct {
char *key;
GtkFundamentalType type;
union {
- char *v_str;
gboolean v_bool;
+ long v_long;
+ char *v_str;
} value;
gboolean used_default;
} KeyData;
@@ -39,6 +41,13 @@ static void e_config_listener_destroy (GtkObject *object);
static GtkObjectClass *parent_class = NULL;
+enum {
+ KEY_CHANGED,
+ LAST_SIGNAL
+};
+
+static guint config_listener_signals[LAST_SIGNAL];
+
static void
e_config_listener_class_init (EConfigListenerClass *klass)
{
@@ -47,6 +56,16 @@ e_config_listener_class_init (EConfigListenerClass *klass)
parent_class = gtk_type_class (PARENT_TYPE);
object_class->destroy = e_config_listener_destroy;
+ klass->key_changed = NULL;
+
+ config_listener_signals[KEY_CHANGED] =
+ gtk_signal_new ("key_changed",
+ GTK_RUN_FIRST,
+ object_class->type,
+ GTK_SIGNAL_OFFSET (EConfigListenerClass, key_changed),
+ gtk_marshal_NONE__STRING,
+ GTK_TYPE_NONE, 1, GTK_TYPE_STRING);
+ gtk_object_class_add_signals (object_class, config_listener_signals, LAST_SIGNAL);
}
static void
@@ -172,11 +191,16 @@ 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_LONG, NULL)) {
+ kd->type = GTK_TYPE_LONG;
+ kd->value.v_long = BONOBO_ARG_GET_LONG (any);
} else if (bonobo_arg_type_is_equal (any->_type, BONOBO_ARG_STRING, NULL)) {
kd->type = GTK_TYPE_STRING;
kd->value.v_str = g_strdup (BONOBO_ARG_GET_STRING (any));
} else
return;
+
+ gtk_signal_emit (GTK_OBJECT (kd->cl), config_listener_signals[KEY_CHANGED], kd->key);
}
static KeyData *
@@ -185,6 +209,7 @@ add_key (EConfigListener *cl, const char *key, GtkFundamentalType type,
{
KeyData *kd;
char *event_name;
+ char *ch;
CORBA_Environment ev;
/* add the key to our hash table */
@@ -196,6 +221,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_LONG :
+ memcpy (&kd->value.v_long, value, sizeof (long));
+ break;
case GTK_TYPE_STRING :
kd->value.v_str = (char *) value;
break;
@@ -207,6 +235,9 @@ add_key (EConfigListener *cl, const char *key, GtkFundamentalType type,
/* add the listener for changes */
event_name = g_strdup_printf ("=Bonobo/ConfigDatabase:change%s",
kd->key);
+ ch = strrchr (event_name, '/');
+ if (ch)
+ *ch = ':';
CORBA_exception_init (&ev);
bonobo_event_source_client_add_listener (
@@ -216,6 +247,7 @@ add_key (EConfigListener *cl, const char *key, GtkFundamentalType type,
&ev, kd);
if (BONOBO_EX (&ev)) {
CORBA_exception_free (&ev);
+ g_free (event_name);
free_key_hash (kd->key, kd, NULL);
return NULL;
}
@@ -228,6 +260,80 @@ add_key (EConfigListener *cl, const char *key, GtkFundamentalType type,
return kd;
}
+gboolean
+e_config_listener_get_boolean_with_default (EConfigListener *cl,
+ const char *key,
+ gboolean def,
+ gboolean *used_default)
+{
+ gboolean value;
+ KeyData *kd;
+ gboolean d;
+ gpointer orig_key, orig_value;
+
+ g_return_val_if_fail (E_IS_CONFIG_LISTENER (cl), FALSE);
+ g_return_val_if_fail (key != NULL, FALSE);
+
+ /* 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_boolean_with_default (cl->priv->db, key, def, &d);
+ kd = add_key (cl, key, GTK_TYPE_BOOL, &value, d);
+
+ if (used_default != NULL)
+ *used_default = d;
+ } else {
+ kd = (KeyData *) orig_value;
+ g_assert (kd != NULL);
+
+ if (kd->type == GTK_TYPE_BOOL) {
+ value = kd->value.v_bool;
+ if (used_default != NULL)
+ *used_default = kd->used_default;
+ } else
+ return FALSE;
+ }
+
+ return value;
+}
+
+long
+e_config_listener_get_long_with_default (EConfigListener *cl,
+ const char *key,
+ long def,
+ gboolean *used_default)
+{
+ long 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_long_with_default (cl->priv->db, key, def, &d);
+ kd = add_key (cl, key, GTK_TYPE_LONG, &value, d);
+
+ if (used_default != NULL)
+ *used_default = d;
+ } else {
+ kd = (KeyData *) orig_value;
+ g_assert (kd != NULL);
+
+ if (kd->type == GTK_TYPE_LONG) {
+ value = kd->value.v_long;
+ if (used_default != NULL)
+ *used_default = kd->used_default;
+ } else
+ return -1;
+ }
+
+ return value;
+}
+
char *
e_config_listener_get_string_with_default (EConfigListener *cl,
const char *key,
@@ -268,41 +374,38 @@ e_config_listener_get_string_with_default (EConfigListener *cl,
return str;
}
-gboolean
-e_config_listener_get_boolean_with_default (EConfigListener *cl,
- const char *key,
- gboolean def,
- gboolean *used_default)
+void
+e_config_listener_set_long (EConfigListener *cl, const char *key, long value)
{
- gboolean value;
- KeyData *kd;
- gboolean d;
- gpointer orig_key, orig_value;
+ CORBA_Environment ev;
- g_return_val_if_fail (E_IS_CONFIG_LISTENER (cl), FALSE);
- g_return_val_if_fail (key != NULL, FALSE);
+ g_return_if_fail (E_IS_CONFIG_LISTENER (cl));
+ g_return_if_fail (key != NULL);
- /* 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_boolean_with_default (cl->priv->db, key, def, &d);
- kd = add_key (cl, key, GTK_TYPE_BOOL, &value, d);
+ CORBA_exception_init (&ev);
- if (used_default != NULL)
- *used_default = d;
- } else {
- kd = (KeyData *) orig_value;
- g_assert (kd != NULL);
+ bonobo_config_set_long (cl->priv->db, key, value, &ev);
+ if (BONOBO_EX (&ev))
+ g_warning ("Cannot save config key %s -- %s", key, BONOBO_EX_ID (&ev));
- if (kd->type == GTK_TYPE_BOOL) {
- value = kd->value.v_bool;
- if (used_default != NULL)
- *used_default = kd->used_default;
- } else
- return FALSE;
- }
+ CORBA_exception_free (&ev);
+}
- return value;
+void
+e_config_listener_set_string (EConfigListener *cl, const char *key, const char *value)
+{
+ CORBA_Environment ev;
+
+ g_return_if_fail (E_IS_CONFIG_LISTENER (cl));
+ g_return_if_fail (key != NULL);
+
+ CORBA_exception_init (&ev);
+
+ bonobo_config_set_string (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);
}
Bonobo_ConfigDatabase
diff --git a/e-util/e-config-listener.h b/e-util/e-config-listener.h
index b83565d85f..9ac2f522e6 100644
--- a/e-util/e-config-listener.h
+++ b/e-util/e-config-listener.h
@@ -32,19 +32,31 @@ typedef struct {
typedef struct {
GtkObjectClass parent_class;
+
+ void (* key_changed) (EConfigListener *cl, const char *key);
} EConfigListenerClass;
GtkType e_config_listener_get_type (void);
EConfigListener *e_config_listener_new (void);
-char *e_config_listener_get_string_with_default (EConfigListener *cl,
- const char *key,
- const char *def,
- gboolean *used_default);
gboolean e_config_listener_get_boolean_with_default (EConfigListener *cl,
const char *key,
gboolean def,
gboolean *used_default);
+long e_config_listener_get_long_with_default (EConfigListener *cl,
+ const char *key,
+ long def,
+ gboolean *used_default);
+char *e_config_listener_get_string_with_default (EConfigListener *cl,
+ const char *key,
+ const char *def,
+ gboolean *used_default);
+void e_config_listener_set_long (EConfigListener *cl,
+ const char *key,
+ long value);
+void e_config_listener_set_string (EConfigListener *cl,
+ const char *key,
+ const char *value);
Bonobo_ConfigDatabase e_config_listener_get_db (EConfigListener *cl);