[goffice] Conf: fix configuration monitoring.



commit 56c45ddd2fdb006bb6f6b3ac9dcad5873fc3e693
Author: Morten Welinder <terra gnome org>
Date:   Wed Jul 1 13:11:18 2009 -0400

    Conf: fix configuration monitoring.

 ChangeLog                     |    4 ++++
 goffice/app/go-conf-gconf.c   |   30 +++++++++++++++++++-----------
 goffice/app/go-conf-keyfile.c |    2 +-
 goffice/app/go-conf-win32.c   |    2 +-
 4 files changed, 25 insertions(+), 13 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index ab3fdc8..4202e4b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,10 @@
 
 	* goffice/app/go-conf-gconf.c (go_conf_add_monitor): Don't use
 	reserved identifier.
+	(get_schema): Use go_conf_get_real_key to avoid problems with
+	NULL.
+	(cb_key_changed): Actually call the monitor with a node as
+	advertised!
 
 2009-06-30  Emmanuel Pacaud <emmanuel pacaud lapp in2p3 fr>
 
diff --git a/goffice/app/go-conf-gconf.c b/goffice/app/go-conf-gconf.c
index b981d8b..2651106 100644
--- a/goffice/app/go-conf-gconf.c
+++ b/goffice/app/go-conf-gconf.c
@@ -28,8 +28,11 @@ go_conf_shutdown (void)
 static gchar *
 go_conf_get_real_key (GOConfNode const *key, gchar const *subkey)
 {
-	return key ? (subkey ? g_strconcat ((key)->path, "/", subkey, NULL): g_strdup (key->path)) :
-		     g_strdup (subkey);
+	return key
+		? (subkey
+		   ? g_strconcat (key->path, "/", subkey, NULL)
+		   : g_strdup (key->path))
+		: g_strdup (subkey);
 }
 
 GOConfNode *
@@ -38,15 +41,13 @@ go_conf_get_node (GOConfNode *parent, gchar const *key)
 	GOConfNode *node;
 
 	node = g_new (GOConfNode, 1);
-	gconf_client = gconf_client;
 	node->root = !parent;
 	if (node->root) {
 		node->path = g_strconcat ("/apps/", key, NULL);
 		gconf_client_add_dir (gconf_client, node->path,
 				      GCONF_CLIENT_PRELOAD_RECURSIVE,
 				      NULL);
-	}
-	else
+	} else
 		node->path = go_conf_get_real_key (parent, key);
 
 	return node;
@@ -241,11 +242,12 @@ go_conf_load_str_list (GOConfNode *node, gchar const *key)
 static GConfSchema *
 get_schema (GOConfNode *node, gchar const *key)
 {
-	gchar *schema_key = g_strconcat (
-		"/schemas", node->path, "/", key, NULL);
-	GConfSchema *schema = gconf_client_get_schema (
-		gconf_client, schema_key, NULL);
+	gchar *real_key = go_conf_get_real_key (node, key);
+	gchar *schema_key = g_strconcat ("/schemas", real_key, NULL);
+	GConfSchema *schema = gconf_client_get_schema
+		(gconf_client, schema_key, NULL);
 	g_free (schema_key);
+	g_free (real_key);
 	return schema;
 }
 
@@ -435,6 +437,7 @@ go_conf_remove_monitor (guint monitor_id)
 
 typedef struct {
 	GOConfMonitorFunc monitor;
+	GOConfNode *node;
 	gpointer data;
 } GOConfClosure;
 
@@ -442,7 +445,7 @@ static void
 cb_key_changed (GConfClient *client, guint cnxn_id,
 		GConfEntry *entry, GOConfClosure *cls)
 {
-	cls->monitor (NULL, gconf_entry_get_key (entry), cls->data);
+	cls->monitor (cls->node, gconf_entry_get_key (entry), cls->data);
 }
 
 guint
@@ -450,10 +453,15 @@ go_conf_add_monitor (GOConfNode *node, gchar const *key,
 		     GOConfMonitorFunc monitor, gpointer data)
 {
 	guint ret;
-	GOConfClosure *cls = g_new0 (GOConfClosure, 1);
+	GOConfClosure *cls;
 	gchar *real_key;
 
+	g_return_val_if_fail (node || key, 0);
+	g_return_val_if_fail (monitor != NULL, 0);
+
+	cls = g_new (GOConfClosure, 1);
 	cls->monitor = monitor;
+	cls->node = node;
 	cls->data = data;
 	real_key = go_conf_get_real_key (node, key);
 	ret = gconf_client_notify_add
diff --git a/goffice/app/go-conf-keyfile.c b/goffice/app/go-conf-keyfile.c
index 5675ca3..1e025b3 100644
--- a/goffice/app/go-conf-keyfile.c
+++ b/goffice/app/go-conf-keyfile.c
@@ -59,7 +59,7 @@ go_conf_get_real_key (GOConfNode const *key, gchar const *subkey)
 }
 
 void
-go_conf_init ()
+go_conf_init (void)
 {
 	key_files = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_key_file_free);
 }
diff --git a/goffice/app/go-conf-win32.c b/goffice/app/go-conf-win32.c
index 3ff5da6..5b08ebb 100644
--- a/goffice/app/go-conf-win32.c
+++ b/goffice/app/go-conf-win32.c
@@ -13,7 +13,7 @@ struct _GOConfNode {
 };
 
 void
-go_conf_init ()
+go_conf_init (void)
 {
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]