[Gnucash-changes] Add some more utility functions.
David Hampton
hampton at cvs.gnucash.org
Thu May 19 23:30:01 EDT 2005
Log Message:
-----------
Add some more utility functions.
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.4
retrieving revision 1.1.2.5
diff -Lsrc/core-utils/gnc-gconf-utils.h -Lsrc/core-utils/gnc-gconf-utils.h -u -r1.1.2.4 -r1.1.2.5
--- src/core-utils/gnc-gconf-utils.h
+++ src/core-utils/gnc-gconf-utils.h
@@ -22,7 +22,7 @@
* *
\********************************************************************/
-/** @addtogroup GUI
+/** @addtogroup GLib
@{ */
/** @addtogroup GConf
@@ -50,10 +50,42 @@
/* Keys used across multiple modules */
#define KEY_LAST_PATH "last_path"
+
/** @name GConf Miscellaneous Functions
@{
*/
+/** This function takes an enum value and returns its nickname.
+ *
+ * @param type The value defining the enum class. For example,
+ * GTK_TYPE_SORT_TYPE.
+ *
+ * @param value A value contained in the enum. For example,
+ * GTK_SORT_ASCENDING.
+ *
+ * @return A pointer to the textual "nickname" for this enum. Tor
+ * example, "ascending".
+ */
+const gchar * gnc_enum_to_nick(GType type, gint value);
+
+/** This function takes an enum nickname and returns its value.
+ *
+ * @param type The value defining the enum class. For example,
+ * GTK_TYPE_SORT_TYPE or GTK_TYPE_ARROW_TYPE.
+ *
+ * @param name The textual name for one of the items in the enum.
+ * For example, "ascending".
+ *
+ * @param value A value contained in the enum. This value will be
+ * returned if the supplied nickname is invalid. For example,
+ * GTK_SORT_ASCENDING.
+ *
+ * @return A pointer to the textual "nickname" for this enum.
+ */
+gint gnc_enum_from_nick(GType type,
+ const gchar *name,
+ gint default_value);
+
/** Convert a local key name to a full gconf path name.
*
* This function takes a gconf key name and converts it into a fully
@@ -235,7 +267,7 @@
/** Get a list of values from GConf.
*
* Retrieve a list of values from GConf. This list may be of any
- * kind of value understoof by GConf, but all values in the list will
+ * kind of value understood by GConf, but all values in the list will
* be of the same type. 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)
@@ -384,7 +416,7 @@
/** Store a list of values into GConf.
*
* Store a list of values into GConf. This list may be of any kind
- * of value understoof by GConf, but all values in the list must be
+ * of value understood by GConf, but all values in the list must be
* of the same type. 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
@@ -497,6 +529,36 @@
*/
void gnc_gconf_remove_notification (GObject *object,
const gchar *section);
+
+
+/** 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
+ * section 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 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.
+ */
+GSList *gnc_gconf_client_all_entries (GObject *object,
+ const gchar *section);
+
/** @} */
/** @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.2
retrieving revision 1.1.2.3
diff -Lsrc/core-utils/gnc-gconf-utils.c -Lsrc/core-utils/gnc-gconf-utils.c -u -r1.1.2.2 -r1.1.2.3
--- src/core-utils/gnc-gconf-utils.c
+++ src/core-utils/gnc-gconf-utils.c
@@ -33,6 +33,57 @@
static GConfClient *our_client = NULL;
+/************************************************************/
+/* Enum Utilities */
+/************************************************************/
+
+const gchar *
+gnc_enum_to_nick(GType type,
+ gint value)
+{
+ GEnumClass *enum_class;
+ GEnumValue *enum_value;
+
+ /* Lookup the enum in the glib type system */
+ enum_class = g_type_class_ref (type);
+ if (!enum_class) {
+ /* g_type_class_ref has already printed a warning. */
+ return NULL;
+ }
+
+ enum_value = g_enum_get_value (enum_class, value);
+ if (!enum_value) {
+ /* Use the first item in the enum */
+ enum_value = g_enum_get_value (enum_class, 0);
+ }
+ return enum_value->value_nick;
+}
+
+gint
+gnc_enum_from_nick(GType type,
+ const gchar *name,
+ gint default_value)
+{
+ GEnumClass *enum_class;
+ GEnumValue *enum_value;
+
+ /* Lookup the enum class in the glib type system */
+ enum_class = g_type_class_ref (type);
+ if (!enum_class) {
+ /* g_type_class_ref has already printed a warning. */
+ return default_value;
+ }
+
+ /* Lookup the specified enum in the class */
+ enum_value = g_enum_get_value_by_nick(enum_class, name);
+ if (enum_value)
+ return enum_value->value;
+ return default_value;
+}
+
+/************************************************************/
+/* Gconf Utilities */
+/************************************************************/
char *
gnc_gconf_section_name (const char *name)
@@ -290,6 +341,27 @@
g_free(key);
}
+GSList *
+gnc_gconf_client_all_entries (GObject *object,
+ const gchar *name)
+{
+ GError *error = NULL;
+ GSList *value;
+ gchar *section;
+
+ if (our_client == NULL)
+ our_client = gconf_client_get_default();
+
+ section = gnc_gconf_section_name(name);
+ value = gconf_client_all_entries(our_client, section, &error);
+ if (error != NULL) {
+ printf("Failed to get list of all gconf keys: %s", error->message);
+ g_error_free(error);
+ }
+
+ return value;
+}
+
void
gnc_gconf_unset (const gchar *section,
const gchar *name,
@@ -335,7 +407,6 @@
const gchar *section,
GConfClientNotifyFunc callback)
{
-
GConfClient *client;
GError *error = NULL;
gchar *path, *client_tag, *notify_tag;
More information about the gnucash-changes
mailing list