GConf Utilities
[GLib]


Detailed Description

The API in this file is designed to make it easy to use the GConf system from within Gnucash. GConf is a shared key/value storage system.

The main benefits of these routines are that they

  1. maintain a GConfClient object,
  2. convert gnucash internal section names into full gconf pathnames, and
  3. optionally take care of error checking on return values.


Files

file  gnc-gconf-utils.h
 GConf helper routines.

GConf Miscellaneous Functions

const gchar * gnc_enum_to_nick (GType type, gint value)
gint gnc_enum_from_nick (GType type, const gchar *name, gint default_value)
char * gnc_gconf_section_name (const char *name)
char * gnc_gconf_schema_section_name (const char *name)
void gnc_gconf_suggest_sync (void)

GConf "General" Section Convenience Functions

void gnc_gconf_general_register_cb (const gchar *key, GncGconfGeneralCb func, gpointer user_data)
void gnc_gconf_general_remove_cb (const gchar *key, GncGconfGeneralCb func, gpointer user_data)
void gnc_gconf_general_register_any_cb (GncGconfGeneralAnyCb func, gpointer user_data)
void gnc_gconf_general_remove_any_cb (GncGconfGeneralAnyCb func, gpointer user_data)

GConf Get Functions

gboolean gnc_gconf_get_bool (const gchar *section, const gchar *name, GError **error)
gboolean gnc_gconf_get_bool_no_error (const gchar *section, const gchar *name)
gint gnc_gconf_get_int (const gchar *section, const gchar *name, GError **error)
gdouble gnc_gconf_get_float (const gchar *section, const gchar *name, GError **error)
char * gnc_gconf_get_string (const gchar *section, const gchar *name, GError **error)
GSList * gnc_gconf_get_list (const gchar *section, const gchar *name, GConfValueType list_type, GError **error)
GConfSchema * gnc_gconf_get_schema (const gchar *section, const gchar *name, GError **caller_error)

GConf Set/Unset Functions

void gnc_gconf_set_bool (const gchar *section, const gchar *name, const gboolean value, GError **error)
void gnc_gconf_set_int (const gchar *section, const gchar *name, const gint value, GError **error)
void gnc_gconf_set_float (const gchar *section, const gchar *name, const gdouble value, GError **error)
void gnc_gconf_set_string (const gchar *section, const gchar *name, const gchar *value, GError **error)
void gnc_gconf_set_list (const gchar *section, const gchar *name, GConfValueType list_type, GSList *value, GError **error)
void gnc_gconf_unset (const gchar *section, const gchar *name, GError **error)
void gnc_gconf_unset_dir (const gchar *section, GError **error)

GConf Notification Functions

void gnc_gconf_add_notification (GObject *object, const gchar *section, GConfClientNotifyFunc callback, const gchar *whoami)
guint gnc_gconf_add_anon_notification (const gchar *section, GConfClientNotifyFunc callback, gpointer data)
void gnc_gconf_remove_notification (GObject *object, const gchar *section, const gchar *whoami)
void gnc_gconf_remove_anon_notification (const gchar *section, guint cnxn_id)
GSList * gnc_gconf_client_all_entries (const gchar *section)
gboolean gnc_gconf_schemas_found (void)

GConf One Liners

#define DESTKOP_TEAROFF_MENUS   "/desktop/gnome/interface/menus_have_tearoff"
#define DESTKOP_MENUBAR_DETACHABLE   "/desktop/gnome/interface/menubar_detachable"
#define DESTKOP_TOOLBAR_DETACHABLE   "/desktop/gnome/interface/toolbar_detachable"

Defines

#define GCONF_GENERAL   "general"
#define GCONF_GENERAL_REGISTER   "general/register"
#define GCONF_GENERAL_REPORT   "general/report"
#define GCONF_WARNINGS   "general/warnings"
#define GCONF_WARNINGS_TEMP   "general/warnings/temporary"
#define GCONF_WARNINGS_PERM   "general/warnings/permanent"
#define DESKTOP_GNOME_INTERFACE   "/desktop/gnome/interface"
#define KEY_TOOLBAR_STYLE   "toolbar_style"
#define KEY_SAVE_GEOMETRY   "save_window_geometry"
#define KEY_LAST_PATH   "last_path"
#define KEY_USE_NEW   "use_new_window"
#define KEY_ACCOUNTING_LABELS   "use_accounting_labels"
#define KEY_ACCOUNT_SEPARATOR   "account_separator"
#define KEY_NEGATIVE_IN_RED   "negative_in_red"
#define KEY_NUMBER_OF_ROWS   "number_of_rows"
#define KEY_ENABLE_EURO   "enable_euro"
#define KEY_DATE_FORMAT   "date_format"
#define KEY_SHOW_LEAF_ACCOUNT_NAMES   "show_leaf_account_names"

Typedefs

typedef void(*) GncGconfGeneralCb (GConfEntry *entry, gpointer user_data)
typedef void(*) GncGconfGeneralAnyCb (gpointer user_data)


Function Documentation

gint gnc_enum_from_nick ( GType  type,
const gchar *  name,
gint  default_value 
)

This function takes an enum nickname and returns its value.

Parameters:
type The value defining the enum class. For example, GTK_TYPE_SORT_TYPE or GTK_TYPE_ARROW_TYPE.
name The textual name for one of the items in the enum. For example, "ascending".
default_value A value contained in the enum. This value will be returned if the supplied nickname is invalid. For example, GTK_SORT_ASCENDING.
Returns:
A pointer to the textual "nickname" for this enum.

Definition at line 65 of file gnc-gconf-utils.c.

00068 {
00069   GEnumClass   *enum_class;
00070   GEnumValue   *enum_value;
00071   gchar        *alt_name, *ptr;
00072 
00073   if (name == NULL)
00074     return default_value;
00075 
00076   /* Lookup the enum class in the glib type system */
00077   enum_class = g_type_class_ref (type);
00078   if (!enum_class) {
00079     /* g_type_class_ref has already printed a warning. */
00080     return default_value;
00081   }
00082 
00083   /* Lookup the specified enum in the class */
00084   enum_value = g_enum_get_value_by_nick(enum_class, name);
00085   if (enum_value)
00086     return enum_value->value;
00087 
00088   /* Flip '-' and '_' and try again */
00089   alt_name = g_strdup(name);
00090   if ((ptr = strchr(alt_name, '-')) != NULL) {
00091     do {
00092       *ptr++ = '_';
00093     } while ((ptr = strchr(ptr, '-')) != NULL);
00094   } else  if ((ptr = strchr(alt_name, '_')) != NULL) {
00095     do {
00096       *ptr++ = '-';
00097     } while ((ptr = strchr(ptr, '_')) != NULL);
00098   } else {
00099     g_free(alt_name);
00100     return default_value;
00101   }
00102 
00103   /* Lookup the specified enum in the class */
00104   enum_value = g_enum_get_value_by_nick(enum_class, alt_name);
00105   g_free(alt_name);
00106   if (enum_value)
00107     return enum_value->value;
00108   return default_value;
00109 }

const gchar* gnc_enum_to_nick ( GType  type,
gint  value 
)

This function takes an enum value and returns its nickname.

Parameters:
type The value defining the enum class. For example, GTK_TYPE_SORT_TYPE.
value A value contained in the enum. For example, GTK_SORT_ASCENDING.
Returns:
A pointer to the textual "nickname" for this enum. Tor example, "ascending".

Definition at line 43 of file gnc-gconf-utils.c.

00045 {
00046   GEnumClass        *enum_class;
00047   GEnumValue        *enum_value;
00048 
00049   /* Lookup the enum in the glib type system */
00050   enum_class = g_type_class_ref (type);
00051   if (!enum_class) {
00052     /* g_type_class_ref has already printed a warning. */
00053     return NULL;
00054   }
00055 
00056   enum_value = g_enum_get_value (enum_class, value);
00057   if (!enum_value) {
00058     /* Use the first item in the enum */
00059     enum_value = g_enum_get_value (enum_class, 0);
00060   }
00061   return enum_value->value_nick;
00062 }

guint gnc_gconf_add_anon_notification ( const gchar *  section,
GConfClientNotifyFunc  callback,
gpointer  data 
)

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.

Parameters:
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.
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.
data This pointer will be provided to the callback function when it is invoked.
Returns:
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.

Definition at line 801 of file gnc-gconf-utils.c.

00804 {
00805         GConfClient *client;
00806         GError *error = NULL;
00807         gchar *path;
00808         guint id;
00809 
00810         g_return_val_if_fail(callback != NULL, 0);
00811 
00812         client = gconf_client_get_default();
00813         path = gnc_gconf_section_name(section);
00814 
00815 
00816         /*
00817          * First we have to add the directory...
00818          */
00819         gconf_client_add_dir(client, path, GCONF_CLIENT_PRELOAD_ONELEVEL, &error);
00820         if (error != NULL) {
00821             printf("Failed to add history section to watched directories in gconf: %s", error->message);
00822             g_error_free(error);
00823             g_object_unref(client);
00824             g_free(path);
00825             return 0;
00826         }
00827 
00828         /*
00829          * Then we can add the notification callback.
00830          */
00831         id = gconf_client_notify_add(client, path, callback,
00832                                      data, NULL, &error);
00833         if (error != NULL) {
00834               printf("Failed to set gconf notify for history section: %s", error->message);
00835               gconf_client_remove_dir(client, path, NULL);
00836               g_error_free(error);
00837               g_object_unref(client);
00838               g_free(path);
00839               return 0;
00840         }
00841         g_free(path);
00842         return id;
00843 }

void gnc_gconf_add_notification ( GObject *  object,
const gchar *  section,
GConfClientNotifyFunc  callback,
const gchar *  whoami 
)

Add 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.

Parameters:
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.
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.
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.
whoami A magic value that must match up this call to the corresponding call to gnc_gconf_remove_notification(). The pair of section and whoami should be unique across all callers.

Definition at line 744 of file gnc-gconf-utils.c.

00748 {
00749         GConfClient *client;
00750         GError *error = NULL;
00751         gchar *path, *client_tag, *notify_tag;
00752         guint id;
00753 
00754         g_return_if_fail(G_IS_OBJECT(object));
00755         g_return_if_fail(callback != NULL);
00756         g_return_if_fail(whoami != NULL);
00757 
00758         client = gconf_client_get_default();
00759         path = gnc_gconf_section_name(section);
00760 
00761         /*
00762          * First we have to add the directory...
00763          */
00764         gconf_client_add_dir(client, path, GCONF_CLIENT_PRELOAD_ONELEVEL, &error);
00765         if (error != NULL) {
00766             printf("Failed to add history section to watched directories in gconf: %s", error->message);
00767             g_error_free(error);
00768             g_object_unref(client);
00769             g_free(path);
00770             return;
00771         }
00772 
00773         /*
00774          * Then we can add the notification callback.
00775          */
00776         id = gconf_client_notify_add(client, path, callback,
00777                                      object, NULL, &error);
00778         if (error != NULL) {
00779               printf("Failed to set gconf notify for history section: %s", error->message);
00780               gconf_client_remove_dir(client, path, NULL);
00781               g_error_free(error);
00782               g_object_unref(client);
00783               g_free(path);
00784               return;
00785         }
00786         
00787         /*
00788          * Save the values needed to undo this later.
00789          */
00790         client_tag = g_strdup_printf(CLIENT_TAG, section ? section:"", whoami);
00791         notify_tag = g_strdup_printf(NOTIFY_TAG, section ? section:"", whoami);
00792         g_object_set_data(object, client_tag, client);
00793         g_object_set_data(object, notify_tag, GUINT_TO_POINTER(id));
00794         g_free(notify_tag);
00795         g_free(client_tag);
00796         g_free(path);
00797 }

GSList* gnc_gconf_client_all_entries ( 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.

Parameters:
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.
Returns:
This function returns a list of all key/value pairs stored 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.

Definition at line 640 of file gnc-gconf-utils.c.

00641 {
00642   GError *error = NULL;
00643   GSList *value;
00644   gchar *section;
00645 
00646   if (our_client == NULL)
00647     our_client = gconf_client_get_default();
00648 
00649   section = gnc_gconf_section_name(name);
00650   value = gconf_client_all_entries(our_client, section, &error);
00651   if (error != NULL) {
00652     printf("Failed to get list of all gconf keys: %s", error->message);
00653     g_error_free(error);
00654   }
00655 
00656   return value;
00657 }

void gnc_gconf_general_register_any_cb ( GncGconfGeneralAnyCb  func,
gpointer  user_data 
)

Register a callback for when any key in the general section of Gnucash's gconf data is changed. Any time the value of a key in this section chagnes, the routine will be invoked and will be passed the specified user data.

Parameters:
func This is a pointer to the function to call when the key changes.
user_data This pointer will be passed to the callback function.

Definition at line 217 of file gnc-gconf-utils.c.

00219 {
00220   GHook *hook;
00221 
00222   g_once(&gcb_init_once, gcb_init, NULL);
00223   hook = g_hook_find_func_data(gcb_final_hook_list, TRUE, func, user_data);
00224   if (hook != NULL)
00225     return;
00226 
00227   hook = g_hook_alloc(gcb_final_hook_list);
00228   hook->func = func;
00229   hook->data = user_data;
00230   g_hook_append(gcb_final_hook_list, hook);
00231 }

void gnc_gconf_general_register_cb ( const gchar *  key,
GncGconfGeneralCb  func,
gpointer  user_data 
)

Register a callback for when a specific key in the general section of Gnucash's gconf data is changed. Any time the key's value changes, the routine will be invoked and will be passed both the changes gconf entry and the user data passed to this function.

Parameters:
key This value contains the name of the key within the "general" section to watch.
func This is a pointer to the function to call when the key changes.
user_data This pointer will be passed to the callback function.

Definition at line 165 of file gnc-gconf-utils.c.

00168 {
00169   GHookList *hook_list;
00170   GHook *hook;
00171 
00172   g_once(&gcb_init_once, gcb_init, NULL);
00173   hook_list = g_hash_table_lookup(gcb_callback_hash, key);
00174   if (hook_list == NULL) {
00175     hook_list = g_malloc(sizeof(GHookList));
00176     g_hook_list_init(hook_list, sizeof(GHook));
00177     g_hash_table_insert(gcb_callback_hash, (gpointer)key, hook_list);
00178   }
00179 
00180   hook = g_hook_find_func_data(hook_list, TRUE, func, user_data);
00181   if (hook != NULL) {
00182     return;
00183   }
00184 
00185   hook = g_hook_alloc(hook_list);
00186   hook->func = func;
00187   hook->data = user_data;
00188   g_hook_append(hook_list, hook);
00189 }

void gnc_gconf_general_remove_any_cb ( GncGconfGeneralAnyCb  func,
gpointer  user_data 
)

Remove a function that was registered for a callback when any key in the general section of Gnucash's gconf data changed. Both the func and user_data arguments are used to match up the callback to remove.

Parameters:
func This is a pointer to the function to call when a key changes.
user_data This pointer will be passed to the callback function.

Definition at line 235 of file gnc-gconf-utils.c.

00237 {
00238   GHook *hook;
00239 
00240   g_once(&gcb_init_once, gcb_init, NULL);
00241   hook = g_hook_find_func_data(gcb_final_hook_list, TRUE, func, user_data);
00242   if (hook == NULL)
00243     return;
00244 
00245   g_hook_unref(gcb_final_hook_list, hook);
00246 }

void gnc_gconf_general_remove_cb ( const gchar *  key,
GncGconfGeneralCb  func,
gpointer  user_data 
)

Remove a function that was registered for a callback when a specific key in the general section of Gnucash's gconf data changed. Both the func and user_data arguments are used to match up the callback to remove.

Parameters:
key This value contains the name of the key within the "general" section to watch.
func This is a pointer to the function to call when the key changes.
user_data This pointer will be passed to the callback function.

Definition at line 193 of file gnc-gconf-utils.c.

00196 {
00197   GHookList *hook_list;
00198   GHook *hook;
00199 
00200   g_once(&gcb_init_once, gcb_init, NULL);
00201   hook_list = g_hash_table_lookup(gcb_callback_hash, key);
00202   if (hook_list == NULL)
00203     return;
00204   hook = g_hook_find_func_data(hook_list, TRUE, func, user_data);
00205   if (hook == NULL)
00206     return;
00207 
00208   g_hook_destroy_link(hook_list, hook);
00209   if (hook_list->hooks == NULL) {
00210     g_hash_table_remove(gcb_callback_hash, key);
00211     g_free(hook_list);
00212   }
00213 }

gboolean gnc_gconf_get_bool ( const gchar *  section,
const gchar *  name,
GError **  error 
)

Get a boolean value from GConf.

Retrieve a TRUE/FALSE 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.

Parameters:
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.
name This string is the name of the particular key within the named section of gconf.
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.
Returns:
This function returns the TRUE or FALSE value stored at the requested key in the gconf database. If the key has never been set, this function passes on the default value returned by GConf as specified in the schema for this key. If there is an error in processing, this function passed on the value of FALSE as returned by GConf.

Definition at line 402 of file gnc-gconf-utils.c.

00405 {
00406   GError *error = NULL;
00407   gboolean value;
00408   gchar *key;
00409 
00410   if (our_client == NULL)
00411     our_client = gconf_client_get_default();
00412 
00413   key = gnc_gconf_make_key(section, name);
00414   value = gconf_client_get_bool(our_client, key, &error);
00415   if (error) {
00416     gnc_gconf_load_error(key, caller_error, error);
00417   }
00418   g_free(key);
00419   return value;
00420 }

gboolean gnc_gconf_get_bool_no_error ( const gchar *  section,
const gchar *  name 
)

Get a boolean value from GConf with no error argument.

Retrieve a TRUE/FALSE 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.

Parameters:
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.
name This string is the name of the particular key within the named section of gconf.
Returns:
This function returns the TRUE or FALSE value stored at the requested key in the gconf database. If the key has never been set, this function passes on the default value returned by GConf as specified in the schema for this key. If there is an error in processing, this function passed on the value of FALSE as returned by GConf.
Note:
This function was intended for use only by the guile wrapper functions. It should not be called from C code.

Definition at line 423 of file gnc-gconf-utils.c.

00425 {
00426   return gnc_gconf_get_bool(section, name, NULL);
00427 }

gdouble gnc_gconf_get_float ( const gchar *  section,
const gchar *  name,
GError **  error 
)

Get an float value from GConf.

Retrieve an float 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.

Parameters:
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.
name This string is the name of the particular key within the named section of gconf.
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.
Returns:
This function returns the integer value stored at the requested key in the gconf database. If the key has never been set, this function passes on the default value returned by GConf as specified in the schema for this key. If there is an error in processing, this function passed on the value of zero as returned by GConf.

Definition at line 491 of file gnc-gconf-utils.c.

00494 {
00495   GError *error = NULL;
00496   gint value;
00497   gchar *key;
00498 
00499   if (our_client == NULL)
00500     our_client = gconf_client_get_default();
00501 
00502   key = gnc_gconf_make_key(section, name);
00503   value = gconf_client_get_float(our_client, key, &error);
00504   if (error) {
00505     gnc_gconf_load_error(key, caller_error, error);
00506   }
00507   g_free(key);
00508   return value;
00509 }

gint gnc_gconf_get_int ( const gchar *  section,
const gchar *  name,
GError **  error 
)

Get an integer value from GConf.

Retrieve an integer 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.

Parameters:
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.
name This string is the name of the particular key within the named section of gconf.
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.
Returns:
This function returns the float value stored at the requested key in the gconf database. If the key has never been set, this function passes on the default value returned by GConf as specified in the schema for this key. If there is an error in processing, this function passed on the value of zero as returned by GConf.

Definition at line 450 of file gnc-gconf-utils.c.

00453 {
00454   GError *error = NULL;
00455   gint value;
00456   gchar *key;
00457 
00458   if (our_client == NULL)
00459     our_client = gconf_client_get_default();
00460 
00461   key = gnc_gconf_make_key(section, name);
00462   value = gconf_client_get_int(our_client, key, &error);
00463   if (error) {
00464     gnc_gconf_load_error(key, caller_error, error);
00465   }
00466   g_free(key);
00467   return value;
00468 }

GSList* gnc_gconf_get_list ( const gchar *  section,
const gchar *  name,
GConfValueType  list_type,
GError **  error 
)

Get a list of values from GConf.

Retrieve a list of values from GConf. This list may be of any 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) 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.

Parameters:
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.
name This string is the name of the particular key within the named section of gconf.
list_type This enum indicates the type of each item in the returned list. This type must match the type off the stored items.
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.
Returns:
This function returns a list of value stored at the requested key in the gconf database. If the key has never been set, this function passes on the default value returned by GConf as specified in the schema for this key. 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 memory returned by this function. This include the list itself, and any list data that are string values.

Definition at line 577 of file gnc-gconf-utils.c.

00581 {
00582   GError *error = NULL;
00583   GSList *value;
00584   gchar *key;
00585 
00586   if (our_client == NULL)
00587     our_client = gconf_client_get_default();
00588 
00589   key = gnc_gconf_make_key(section, name);
00590   value = gconf_client_get_list(our_client, key, list_type, &error);
00591   if (error) {
00592     gnc_gconf_load_error(key, caller_error, error);
00593   }
00594   g_free(key);
00595   return value;
00596 }

GConfSchema* gnc_gconf_get_schema ( const gchar *  section,
const gchar *  name,
GError **  caller_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.

Parameters:
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.
name This string is the name of the particular key within the named section of gconf.
caller_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.
Returns:
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.

Definition at line 619 of file gnc-gconf-utils.c.

00622 {
00623   GError *error = NULL;
00624   GConfSchema *value;
00625   gchar *key;
00626 
00627   if (our_client == NULL)
00628     our_client = gconf_client_get_default();
00629 
00630   key = gnc_gconf_make_key(section, name);
00631   value = gconf_client_get_schema(our_client, key, &error);
00632   if (error) {
00633     gnc_gconf_load_error(key, caller_error, error);
00634   }
00635   g_free(key);
00636   return value;
00637 }

char* gnc_gconf_get_string ( const gchar *  section,
const gchar *  name,
GError **  error 
)

Get a string value from GConf.

Retrieve an string 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.

Parameters:
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.
name This string is the name of the particular key within the named section of gconf.
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.
Returns:
This function returns the string value stored at the requested key in the gconf database. If the key has never been set, this function passes on the default value returned by GConf as specified in the schema for this key. 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 string returned by this function.

Definition at line 532 of file gnc-gconf-utils.c.

00535 {
00536   GError *error = NULL;
00537   gchar *value;
00538   gchar *key;
00539 
00540   if (our_client == NULL)
00541     our_client = gconf_client_get_default();
00542 
00543   key = gnc_gconf_make_key(section, name);
00544   value = gconf_client_get_string(our_client, key, &error);
00545   if (error) {
00546     gnc_gconf_load_error(key, caller_error, error);
00547   }
00548   g_free(key);
00549 
00550   if (value && strlen(value) == 0) {
00551     g_free(value);
00552     return NULL;
00553   }
00554   return value;
00555 }

void gnc_gconf_remove_anon_notification ( const gchar *  section,
guint  cnxn_id 
)

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.

Parameters:
section This string is used to find the correct notification function to remove from GConf.
cnxn_id An identification number returned by the gnc_gconf_add_anon_notification() function.

Definition at line 878 of file gnc-gconf-utils.c.

00880 {
00881         GConfClient *client;
00882         gchar *path;
00883 
00884         /*
00885          * Remove any gconf notifications
00886          */
00887         path = gnc_gconf_section_name(section);
00888         client = gconf_client_get_default();
00889         if (client) {
00890           gconf_client_notify_remove(client, cnxn_id);
00891           gconf_client_remove_dir(client, path, NULL);
00892           g_object_unref(client);
00893         }
00894         g_free(path);
00895 }

void gnc_gconf_remove_notification ( GObject *  object,
const gchar *  section,
const gchar *  whoami 
)

Remove a callback from GConf.

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.

Parameters:
object This is a pointer to a GObject derivative. This must be the same object originally passed to the gnc_gconf_add_notification() function, as that function attached several values to the object that are needed by this function.
section This string is used to find the correct notification function to remove from GConf.
whoami A magic value that must match up this call to the corresponding call to gnc_gconf_add_notification(). The pair of section and whoami should be unique across all callers.

Definition at line 847 of file gnc-gconf-utils.c.

00850 {
00851         GConfClient *client;
00852         gchar *path, *client_tag, *notify_tag;
00853         guint id;
00854 
00855         g_return_if_fail(G_IS_OBJECT(object));
00856         g_return_if_fail(whoami != NULL);
00857 
00858         /*
00859          * Remove any gconf notifications
00860          */
00861         client_tag = g_strdup_printf(CLIENT_TAG, section ? section:"", whoami);
00862         client = g_object_get_data(object, client_tag);
00863         path = gnc_gconf_section_name(section);
00864         if (client) {
00865           notify_tag = g_strdup_printf(NOTIFY_TAG, section ? section:"", whoami);
00866           id = GPOINTER_TO_UINT(g_object_get_data(object, notify_tag));
00867           gconf_client_notify_remove(client, id);
00868           gconf_client_remove_dir(client, path, NULL);
00869           g_object_unref(client);
00870           g_free(notify_tag);
00871         }
00872         g_free(path);
00873         g_free(client_tag);
00874 }

char* gnc_gconf_schema_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.

Parameters:
name 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.
Returns:
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.

Definition at line 275 of file gnc-gconf-utils.c.

00276 {
00277   if (strncmp(name, "/schemas", sizeof("/schemas")) == 0) {
00278     /* Need to return a newly allocated string */
00279     return g_strdup(name);
00280   }
00281 
00282   /* This could (should?) be accomplished with a call to
00283    * gnome_gconf_get_app_settings_relative(), but that would introduce
00284    * a new library dependancy, even though its not a gui library.  In
00285    * order to keep this file completely "gnome-free" this approach was
00286    * used.
00287    */
00288   return g_strconcat("/schemas", gnc_get_gconf_path(), "/", name, NULL);
00289 }

gboolean gnc_gconf_schemas_found ( void   ) 

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.

Returns:
This function returns TRUE if it was able to find a schema.

Definition at line 900 of file gnc-gconf-utils.c.

00901 {
00902   GConfSchema* schema;
00903   GError *err = NULL;
00904   gchar *key;
00905 
00906   if (our_client == NULL)
00907     our_client = gconf_client_get_default();
00908 
00909   key = gnc_gconf_make_schema_key(GCONF_GENERAL_REGISTER, "use_theme_colors");
00910   schema = gconf_client_get_schema(our_client, key, &err);
00911   g_free(key);
00912   if (schema == NULL) {
00913     return FALSE;
00914   }
00915   gconf_schema_free(schema);
00916 
00917   /* Set up convenience callback for general section */
00918   
00919   gconf_general_cb_id =
00920     gnc_gconf_add_anon_notification(GCONF_GENERAL, gnc_gconf_general_changed,
00921                                     NULL);
00922     return TRUE;
00923 }

char* gnc_gconf_section_name ( const char *  name  ) 

Convert a local key name to a full gconf path name.

This function takes a gconf key name and converts it into a fully qualified gconf path name. It does this by prepending the standard path for all gnucash keys. It the key is already fully qualified (i.e. begins with a '/' character), this routine does not change the key.

Parameters:
name A partial gconf key or section name. This name is added to the standard prefix to produce a fully qualified key name.
Returns:
This function returns a string pointer to the fully qualified path name of the gconf key. It is the caller's responsibility to free this string.

Definition at line 254 of file gnc-gconf-utils.c.

00255 {
00256   if (name == NULL) {
00257     /* Need to return a newly allocated string */
00258     return g_strdup(gnc_get_gconf_path());
00259   }
00260   if (*name == '/') {
00261     /* Need to return a newly allocated string */
00262     return g_strdup(name);
00263   }
00264 
00265   /* This could (should?) be accomplished with a call to
00266    * gnome_gconf_get_app_settings_relative(), but that would introduce
00267    * a new library dependancy, even though its not a gui library.  In
00268    * order to keep this file completely "gnome-free" this approach was
00269    * used.
00270    */
00271   return g_strjoin("/", gnc_get_gconf_path(), name, NULL);
00272 }

void gnc_gconf_set_bool ( const gchar *  section,
const gchar *  name,
const gboolean  value,
GError **  error 
)

Store a boolean value into GConf.

Store a boolean value into 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.

Parameters:
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.
name This string is the name of the particular key within the named section of gconf.
value The TRUE/FALSE value to be stored.
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.

Definition at line 430 of file gnc-gconf-utils.c.

00434 {
00435   GError *error = NULL;
00436   gchar *key;
00437 
00438   if (our_client == NULL)
00439     our_client = gconf_client_get_default();
00440 
00441   /* Remember whether the column width */
00442   key = gnc_gconf_make_key(section, name);
00443   if (!gconf_client_set_bool(our_client, key, value, &error)) {
00444     gnc_gconf_save_error(key, caller_error, error);
00445   }
00446   g_free(key);
00447 }

void gnc_gconf_set_float ( const gchar *  section,
const gchar *  name,
const gdouble  value,
GError **  error 
)

Store an float value into GConf.

Store an float into 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.

Parameters:
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.
name This string is the name of the particular key within the named section of gconf.
value The number to be stored.
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.

Definition at line 512 of file gnc-gconf-utils.c.

00516 {
00517   GError *error = NULL;
00518   gchar *key;
00519 
00520   if (our_client == NULL)
00521     our_client = gconf_client_get_default();
00522 
00523   /* Remember whether the column width */
00524   key = gnc_gconf_make_key(section, name);
00525   if (!gconf_client_set_float(our_client, key, value, &error)) {
00526     gnc_gconf_save_error(key, caller_error, error);
00527   }
00528   g_free(key);
00529 }

void gnc_gconf_set_int ( const gchar *  section,
const gchar *  name,
const gint  value,
GError **  error 
)

Store an integer value into GConf.

Store an integer into 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.

Parameters:
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.
name This string is the name of the particular key within the named section of gconf.
value The number to be stored.
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.

Definition at line 471 of file gnc-gconf-utils.c.

00475 {
00476   GError *error = NULL;
00477   gchar *key;
00478 
00479   if (our_client == NULL)
00480     our_client = gconf_client_get_default();
00481 
00482   /* Remember whether the column width */
00483   key = gnc_gconf_make_key(section, name);
00484   if (!gconf_client_set_int(our_client, key, value, &error)) {
00485     gnc_gconf_save_error(key, caller_error, error);
00486   }
00487   g_free(key);
00488 }

void gnc_gconf_set_list ( const gchar *  section,
const gchar *  name,
GConfValueType  list_type,
GSList *  value,
GError **  error 
)

Store a list of values into GConf.

Store a list of values into GConf. This list may be of any kind 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 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.

Parameters:
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.
name This string is the name of the particular key within the named section of gconf.
list_type This enum indicates the type of each item in the list to be stored.
value The list of items to be stored. Each item in the list must be of the type specified. E.G. If the list_type is GCONF_VALUE_STRING, then the data field of each element in the list must be a string pointer.
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.

Definition at line 599 of file gnc-gconf-utils.c.

00604 {
00605   GError *error = NULL;
00606   gchar *key;
00607 
00608   if (our_client == NULL)
00609     our_client = gconf_client_get_default();
00610 
00611   key = gnc_gconf_make_key(section, name);
00612   if (!gconf_client_set_list(our_client, key, list_type, value, &error)) {
00613     gnc_gconf_save_error(key, caller_error, error);
00614   }
00615   g_free(key);
00616 }

void gnc_gconf_set_string ( const gchar *  section,
const gchar *  name,
const gchar *  value,
GError **  error 
)

Store a string into GConf.

Store a single string into 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.

Parameters:
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.
name This string is the name of the particular key within the named section of gconf.
value The string to be stored. GConf will make a copy of this string, so it is the callers responsibility to free the space used by this string (if necessary).
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.

Definition at line 558 of file gnc-gconf-utils.c.

00562 {
00563   GError *error = NULL;
00564   gchar *key;
00565 
00566   if (our_client == NULL)
00567     our_client = gconf_client_get_default();
00568 
00569   key = gnc_gconf_make_key(section, name);
00570   if (!gconf_client_set_string(our_client, key, value, &error)) {
00571     gnc_gconf_save_error(key, caller_error, error);
00572   }
00573   g_free(key);
00574 }

void gnc_gconf_suggest_sync ( void   ) 

Tell GConf to propagate changes.

This function tells gconf that changes have been made and that is should propagate its internal state to permanent storage and any other clients. This function is a suggestion to gconf, not a directive, and is therefore should be considered optional. Doesn't hurt to call it though if you've made numerous changes to gconf in a short period of time.

Definition at line 728 of file gnc-gconf-utils.c.

00729 {
00730   GError *error = NULL;
00731 
00732   if (our_client == NULL)
00733     our_client = gconf_client_get_default();
00734 
00735   gconf_client_suggest_sync(our_client, &error);
00736   if (error != NULL) {
00737     printf("Failed to sync gconf: %s", error->message);
00738     g_error_free(error);
00739   }
00740 }

void gnc_gconf_unset ( const gchar *  section,
const gchar *  name,
GError **  error 
)

Delete a value from GConf.

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 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.

Parameters:
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.
name This string is the name of the particular key within the named section of gconf.
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.

Definition at line 660 of file gnc-gconf-utils.c.

00663 {
00664   GError *error = NULL;
00665   gchar *key;
00666 
00667   if (our_client == NULL)
00668     our_client = gconf_client_get_default();
00669 
00670   key = gnc_gconf_make_key(section, name);
00671   if (!gconf_client_unset(our_client, key, &error)) {
00672     if (caller_error) {
00673       g_propagate_error(caller_error, error);
00674     } else {
00675       printf("Failed to unset key %s: %s", key, error->message);
00676       g_error_free(error);
00677     }
00678   }
00679   g_free(key);
00680 }