[Gnucash-changes] Add some schema related functions.

David Hampton hampton at cvs.gnucash.org
Sun Jul 17 20:12:31 EDT 2005


Log Message:
-----------
Add some schema related functions.  Remove extraneous argument from
gnc_gconf_client_all_entries().  Doxygen updates.

Tags:
----
gnucash-gnome2-dev

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

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.6
retrieving revision 1.1.2.7
diff -Lsrc/core-utils/gnc-gconf-utils.h -Lsrc/core-utils/gnc-gconf-utils.h -u -r1.1.2.6 -r1.1.2.7
--- src/core-utils/gnc-gconf-utils.h
+++ src/core-utils/gnc-gconf-utils.h
@@ -51,6 +51,8 @@
 #define GCONF_GENERAL		"general"
 #define GCONF_GENERAL_REGISTER	"general/register"
 #define GCONF_WARNINGS		"general/warnings"
+#define GCONF_WARNINGS_TEMP	"general/warnings/temporary"
+#define GCONF_WARNINGS_PERM	"general/warnings/permanent"
 
 /* Keys used across multiple modules */
 #define KEY_LAST_PATH "last_path"
@@ -108,6 +110,26 @@
  */
 char *gnc_gconf_section_name (const char *name);
 
+
+/** Convert a local schema key name to a full gconf schemapath name.
+ *
+ *  This function takes a gconf schema key name and converts it into a
+ *  fully qualified gconf schema path name.  It does this by
+ *  prepending the standard path for all gnucash schema keys.  It the
+ *  key is already fully qualified (i.e. begins with the string
+ *  "/schemas), this routine does not change the key.
+ *
+ *  @param A partial gconf schema key or section name.  This name is
+ *  added to the standard schema prefix to produce a fully qualified
+ *  schema key name.
+ *
+ *  @return This function returns a string pointer to the fully
+ *  qualified path name of the gconf schema key.  It is the caller's
+ *  responsibility to free this string.
+ */
+char *gnc_gconf_schema_section_name (const char *name);
+
+
 /** Tell GConf to propagate changes.
  *
  *  This function tells gconf that changes have been made and that is
@@ -313,6 +335,43 @@
 			    const gchar *name,
 			    GConfValueType list_type,
 			    GError **error);
+
+
+/** Get a schema value from GConf.
+ *
+ *  Retrieve a schema value from GConf.  The section and key names
+ *  provided as arguments are combined with the standard gnucash key
+ *  prefix to produce a fully qualified key name.  Either name (but
+ *  not both) may be a fully qualified key path name, in which case it
+ *  is used as is, without the standard gnucash prefix.  This allows
+ *  the program to access keys like standard desktop settings.  Either
+ *  name (but not both) may be NULL.
+ *
+ *  @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.
+ *
+ *  @param name This string is the name of the particular key within
+ *  the named section of gconf.
+ *
+ *  @param error An optional pointer to a GError structure.  If NULL,
+ *  this function will check for any errors returned by GConf and will
+ *  display an error message via stdout.  If present, this function
+ *  will pass any error back to the calling function for it to handle.
+ *
+ *  @return This function returns the schema stored at the requested
+ *  key in the gconf database.  If there is an error in processing,
+ *  this function passed on the NULL value as returned by GConf.  It
+ *  is the callers responsibility to free any returned schema by
+ *  calling the gconf_schema_free() function.
+ */
+GConfSchema *gnc_gconf_get_schema (const gchar *section,
+				    const gchar *name,
+				   GError **caller_error);
+
 /** @} */
 
 /** @name GConf Set/Unset Functions 
@@ -461,7 +520,7 @@
 
 /** Delete a value from GConf.
  *
- *  Complete remove a value from GConf.  The next attempt to read this
+ *  Completely remove a value from GConf.  The next attempt to read this
  *  value will return the default as specified in the GConf schema for
  *  this key.  The section and key names provided as arguments are
  *  combined with the standard gnucash key prefix to produce a fully
@@ -490,6 +549,30 @@
 		      const gchar *name,
 		      GError **error);
 
+
+/** Delete a directory of values from GConf.
+ *
+ *  Completely remove a directory of values from GConf.  The next
+ *  attempt to read any of these values will return the default as
+ *  specified in the GConf schema for the key.  The section names
+ *  provided as an arguments is combined with the standard gnucash key
+ *  prefix to produce a fully qualified directory name.
+ *
+ *  @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.
+ *
+ *  @param error An optional pointer to a GError structure.  If NULL,
+ *  this function will check for any errors returned by GConf and will
+ *  display an error message via stdout.  If present, this function
+ *  will pass any error back to the calling function for it to handle.
+ */
+void gnc_gconf_unset_dir (const gchar *section,
+			  GError **error);
+
 /** @} */
 
 /** @name GConf Notification Functions 
@@ -608,21 +691,14 @@
  *  "dialogs/business/invoice" for setting that only apply to one
  *  specific area of the program.
  *
- *  @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.
- *
  *  @return This function returns a list of all key/value pairs stored
- *  in this section of the gconf database.  It is the callers
- *  responsibility to free any memory returned by this function.  This
- *  include the list itself, and any entries contained in the list.
- *  See gconf_client_all_entries in the gconf documentation.
+ *  in this section of the gconf database.  These are GConfEntry
+ *  objects.  It is the callers responsibility to free any memory
+ *  returned by this function.  This include the list itself, and any
+ *  entries contained in the list.  See gconf_client_all_entries in
+ *  the gconf documentation.
  */
-GSList *gnc_gconf_client_all_entries (GObject *object,
-				      const gchar *section);
+GSList *gnc_gconf_client_all_entries (const gchar *section);
 
 
 /** Check gconf to see if the schema for one of the gnucash keys can
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.5
retrieving revision 1.1.2.6
diff -Lsrc/core-utils/gnc-gconf-utils.c -Lsrc/core-utils/gnc-gconf-utils.c -u -r1.1.2.5 -r1.1.2.6
--- src/core-utils/gnc-gconf-utils.c
+++ src/core-utils/gnc-gconf-utils.c
@@ -25,7 +25,7 @@
 #include "config.h"
 
 #include <stdio.h>
-#include <strings.h>
+#include <string.h>
 #include "gnc-gconf-utils.h"
 
 #define APP_GNUCASH "/apps/gnucash/%s"
@@ -125,6 +125,23 @@
   return g_strdup_printf(APP_GNUCASH, name);
 }
 
+char *
+gnc_gconf_schema_section_name (const char *name)
+{
+  if (strncmp(name, "/schemas", sizeof("/schemas")) == 0) {
+    /* Need to return a newly allocated string */
+    return g_strdup(name);
+  }
+
+  /* This could (should?) be accomplished with a call to
+   * gnome_gconf_get_app_settings_relative(), but that would introduce
+   * a new library dependancy, even though its not a gui library.  In
+   * order to keep this file completely "gnome-free" this approach was
+   * used.
+   */
+  return g_strdup_printf("/schemas" APP_GNUCASH, name);
+}
+
 static gchar *
 gnc_gconf_make_key (const gchar *section, const gchar *name)
 {
@@ -378,9 +395,34 @@
   g_free(key);
 }
 
+GConfSchema *
+gnc_gconf_get_schema (const gchar *section,
+		      const gchar *name,
+		      GError **caller_error)
+{
+  GError *error = NULL;
+  GConfSchema *value;
+  gchar *key;
+
+  if (our_client == NULL)
+    our_client = gconf_client_get_default();
+
+  key = gnc_gconf_make_key(section, name);
+  value = gconf_client_get_schema(our_client, key, &error);
+  if (error) {
+    if (caller_error) {
+      g_propagate_error(caller_error, error);
+    } else {
+      printf("Failed to load key %s: %s", key, error->message);
+      g_error_free(error);
+    }
+  }
+  g_free(key);
+  return value;
+}
+
 GSList *
-gnc_gconf_client_all_entries (GObject *object,
-			      const gchar *name)
+gnc_gconf_client_all_entries (const gchar *name)
 {
   GError *error = NULL;
   GSList *value;
@@ -415,7 +457,7 @@
     if (caller_error) {
       g_propagate_error(caller_error, error);
     } else {
-      printf("Failed to save key %s: %s", key, error->message);
+      printf("Failed to unset key %s: %s", key, error->message);
       g_error_free(error);
     }
   }
@@ -424,6 +466,50 @@
 
 
 void
+gnc_gconf_unset_dir (const gchar *section,
+		     GError **caller_error)
+{
+  GError *error = NULL;
+  GSList *entries, *tmp;
+  const gchar *key;
+  gchar *dir_key;
+
+  if (our_client == NULL)
+    our_client = gconf_client_get_default();
+
+  dir_key = gnc_gconf_make_key(section, NULL);
+  entries = gconf_client_all_entries(our_client, dir_key, &error);
+  g_free(dir_key);
+  if (error) {
+    if (caller_error) {
+      g_propagate_error(caller_error, error);
+    } else {
+      printf("Failed to get directory entries for key %s: %s",
+	     dir_key, error->message);
+      g_error_free(error);
+    }
+    return;
+  }
+
+  for (tmp = entries; tmp; tmp = g_slist_next(tmp)) {
+    key = gconf_entry_get_key(tmp->data);
+    if (!gconf_client_unset(our_client, key, &error)) {
+      if (caller_error) {
+	g_propagate_error(caller_error, error);
+      } else {
+	printf("Failed to unset key %s: %s", key, error->message);
+	g_error_free(error);
+      }
+      break;
+    }
+  }
+
+  g_slist_foreach(entries, (GFunc)gconf_entry_free, NULL);
+  g_slist_free(entries);
+}
+
+
+void
 gnc_gconf_suggest_sync (void)
 {
   GError *error = NULL;
Index: gnc-tree-view.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/gnome-utils/Attic/gnc-tree-view.c,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -Lsrc/gnome-utils/gnc-tree-view.c -Lsrc/gnome-utils/gnc-tree-view.c -u -r1.1.2.2 -r1.1.2.3
--- src/gnome-utils/gnc-tree-view.c
+++ src/gnome-utils/gnc-tree-view.c
@@ -1087,8 +1087,7 @@
   GList *columns;
 
   ENTER("view %p", view);
-  all_entries = gnc_gconf_client_all_entries(G_OBJECT(view),
-					     view->priv->gconf_section);
+  all_entries = gnc_gconf_client_all_entries(view->priv->gconf_section);
 
   /* Set a flag indicating that the gconf data section may be empty.
    * It will be checked later on and appropriate action taken if its


More information about the gnucash-changes mailing list