[Gnucash-changes] New function to check existence of gconf keys.

David Hampton hampton at cvs.gnucash.org
Sat Jul 16 00:00:52 EDT 2005


Log Message:
-----------
New function to check existence of gconf keys.  New functions to
add/remove gconf notifications for use by code that doesn't have a
GObject available.

Tags:
----
gnucash-gnome2-dev

Modified Files:
--------------
    gnucash/src/core-utils:
        gnc-gconf-utils.c
        gnc-gconf-utils.h

Revision Data
-------------
Index: gnc-gconf-utils.h
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/core-utils/Attic/gnc-gconf-utils.h,v
retrieving revision 1.1.2.5
retrieving revision 1.1.2.6
diff -Lsrc/core-utils/gnc-gconf-utils.h -Lsrc/core-utils/gnc-gconf-utils.h -u -r1.1.2.5 -r1.1.2.6
--- src/core-utils/gnc-gconf-utils.h
+++ src/core-utils/gnc-gconf-utils.h
@@ -47,6 +47,11 @@
 
 #include <gconf/gconf-client.h>
 
+/* Section names used across multiple modules */
+#define GCONF_GENERAL		"general"
+#define GCONF_GENERAL_REGISTER	"general/register"
+#define GCONF_WARNINGS		"general/warnings"
+
 /* Keys used across multiple modules */
 #define KEY_LAST_PATH "last_path"
 
@@ -501,6 +506,11 @@
  *  without the standard gnucash prefix.  This allows the object to
  *  respond to keys like standard desktop settings.
  *
+ *  @param object This is a pointer to a GObject derivative.  This
+ *  object will be provided to the callback function when it is
+ *  invoked.  Several values will also be attached to this object that
+ *  are used by the gnc_gconf_remove_notification() function.
+ *
  *  @param section This string provides a grouping of keys within the
  *  GnuCash section of the gconf database.  It can be a simple string
  *  as in "history" for settings that are common to many areas of
@@ -517,6 +527,42 @@
 				 const gchar *section,
 				 GConfClientNotifyFunc callback);
 
+
+/** An alternative function for adding a notification callback to
+ *  GConf.
+ *
+ *  Add a function that will be called whenever a value within the
+ *  specified section of the GConf tree changes.  The section name
+ *  provided as an argument is combined with the standard gnucash key
+ *  prefix to produce a fully qualified key name.  This name may be a
+ *  fully qualified key path name, in which case it is used as is,
+ *  without the standard gnucash prefix.  This allows the object to
+ *  respond to keys like standard desktop settings.
+ *
+ *  @param section This string provides a grouping of keys within the
+ *  GnuCash section of the gconf database.  It can be a simple string
+ *  as in "history" for settings that are common to many areas of
+ *  gnucash, or it can be a partial path name as in
+ *  "dialogs/business/invoice" for setting that only apply to one
+ *  specific area of the program.  Any key changes within this section
+ *  will invoke the notification function.
+ *
+ *  @param callback The function to call when a value changes.  This
+ *  function will receive the key/value pair as one argument, and the
+ *  'object' argument to this function as another of its arguments.
+ *
+ *  @param data This pointer will be provided to the callback function
+ *  when it is invoked.
+ *
+ *  @return This function returns an identification number that must
+ *  be passed to the gnc_gconf_remove_anon_notification() function to
+ *  reverse the actions of this function.
+ */
+guint gnc_gconf_add_anon_notification (const gchar *section,
+				       GConfClientNotifyFunc callback,
+				       gpointer data);
+
+
 /** Remove a callback from GConf.
  *
  *  Remove a GConf callback function previously added with the
@@ -531,6 +577,25 @@
 				    const gchar *section);
 
 
+
+/** An alternative method for remove a callback from GConf; paired
+ *  with gnc_gconf_add_anon_notification().
+ *
+ *  Remove a GConf callback function previously added with the
+ *  gnc_gconf_add_notification function.  The section name must be the
+ *  same string provided when the callback function was added.  This
+ *  name is used to find/remove the callback.
+ *
+ *  @param section This string is used to find the correct
+ *  notification function to remove from GConf.
+ *
+ *  @param cnxn_id An identification number returned by the
+ *  gnc_gconf_add_anon_notification() function.
+ */
+void gnc_gconf_remove_anon_notification (const gchar *section,
+					 guint cnxn_id);
+
+
 /** Retrieve a list of all key/value pairs in the specified GConf
  *  section.  The section name provided as an argument is combined
  *  with the standard gnucash key prefix to produce a fully qualified
@@ -559,6 +624,16 @@
 GSList *gnc_gconf_client_all_entries (GObject *object,
 				      const gchar *section);
 
+
+/** Check gconf to see if the schema for one of the gnucash keys can
+ *  be found.  This function is called to determine whether or not to
+ *  launch a druid to help the user properly set up GConf for Gnucash.
+ *
+ *  @return This function returns TRUE if it was able to find a
+ *  schema.
+ */
+gboolean gnc_gconf_schemas_found (void);
+
 /** @} */
 
 /** @name GConf One Liners 
Index: gnc-gconf-utils.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/core-utils/Attic/gnc-gconf-utils.c,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -Lsrc/core-utils/gnc-gconf-utils.c -Lsrc/core-utils/gnc-gconf-utils.c -u -r1.1.2.4 -r1.1.2.5
--- src/core-utils/gnc-gconf-utils.c
+++ src/core-utils/gnc-gconf-utils.c
@@ -153,6 +153,20 @@
 }
 
 
+static gchar *
+gnc_gconf_make_schema_key (const gchar *section, const gchar *name)
+{
+  gchar *intermediate, *key;
+
+  g_assert ((section != NULL) || (name != NULL));
+
+  intermediate = gnc_gconf_make_key(section, name);
+  key = g_strconcat("/schemas", intermediate, NULL);
+  g_free(intermediate);
+  return key;
+}
+
+
 gboolean
 gnc_gconf_get_bool (const gchar *section,
 		    const gchar *name,
@@ -442,7 +456,6 @@
 	client = gconf_client_get_default();
 	path = gnc_gconf_section_name(section);
 
-
 	/*
 	 * First we have to add the directory...
 	 */
@@ -451,6 +464,7 @@
 	    printf("Failed to add history section to watched directories in gconf: %s", error->message);
 	    g_error_free(error);
 	    g_object_unref(client);
+	    g_free(path);
 	    return;
 	}
 
@@ -464,6 +478,7 @@
 	      gconf_client_remove_dir(client, path, NULL);
 	      g_error_free(error);
 	      g_object_unref(client);
+	      g_free(path);
 	      return;
 	}
 	
@@ -476,6 +491,54 @@
 	g_object_set_data(object, notify_tag, GUINT_TO_POINTER(id));
 	g_free(notify_tag);
 	g_free(client_tag);
+	g_free(path);
+}
+
+
+guint
+gnc_gconf_add_anon_notification (const gchar *section,
+				 GConfClientNotifyFunc callback,
+				 gpointer data)
+{
+	GConfClient *client;
+	GError *error = NULL;
+	gchar *path;
+	guint id;
+
+	g_return_val_if_fail(section != NULL, 0);
+	g_return_val_if_fail(callback != NULL, 0);
+
+	client = gconf_client_get_default();
+	path = gnc_gconf_section_name(section);
+
+
+	/*
+	 * First we have to add the directory...
+	 */
+	gconf_client_add_dir(client, path, GCONF_CLIENT_PRELOAD_ONELEVEL, &error);
+	if (error != NULL) {
+	    printf("Failed to add history section to watched directories in gconf: %s", error->message);
+	    g_error_free(error);
+	    g_object_unref(client);
+	    g_free(path);
+	    return 0;
+	}
+
+	/*
+	 * Then we can add the notification callback.
+	 */
+	id = gconf_client_notify_add(client, path, callback,
+				     data, NULL, &error);
+	if (error != NULL) {
+	      printf("Failed to set gconf notify for history section: %s", error->message);
+	      gconf_client_remove_dir(client, path, NULL);
+	      g_error_free(error);
+	      g_object_unref(client);
+	      g_free(path);
+	      return 0;
+	}
+	g_free(path);
+	return id;
 }
 
 
@@ -507,3 +570,47 @@
 	g_free(path);
 	g_free(client_tag);
 }
+
+
+void
+gnc_gconf_remove_anon_notification (const gchar *section,
+				    guint cnxn_id)
+{
+	GConfClient *client;
+	gchar *path;
+
+	g_return_if_fail(section != NULL);
+
+	/*
+	 * Remove any gconf notifications
+	 */
+	path = gnc_gconf_section_name(section);
+	client = gconf_client_get_default();
+	if (client) {
+	  gconf_client_notify_remove(client, cnxn_id);
+	  gconf_client_remove_dir(client, path, NULL);
+	  g_object_unref(client);
+	}
+	g_free(path);
+}
+
+gboolean
+gnc_gconf_schemas_found (void)
+{
+  GConfSchema* schema;
+  GError *err = NULL;
+  gboolean found = FALSE;
+  gchar *key;
+
+  if (our_client == NULL)
+    our_client = gconf_client_get_default();
+
+  key = gnc_gconf_make_schema_key(GCONF_GENERAL_REGISTER, "use_theme_colors");
+  schema = gconf_client_get_schema(our_client, key, &err);
+  if (schema != NULL) {
+    gconf_schema_free(schema);
+    found = TRUE;
+  }
+  g_free(key);
+  return found;
+}


More information about the gnucash-changes mailing list