![]() | ![]() | ![]() | GConf Manual | ![]() |
---|
enum GConfClientPreloadType; enum GConfClientErrorHandlingMode; void (*GConfClientNotifyFunc) (GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointer user_data); void (*GConfClientErrorHandlerFunc) (GConfClient *client, GError *error); #define GCONF_CLIENT (obj) GConfClient* gconf_client_get_default (void); GConfClient* gconf_client_get_for_engine (GConfEngine *engine); void gconf_client_add_dir (GConfClient *client, const gchar *dir, GConfClientPreloadType preload, GError **err); void gconf_client_remove_dir (GConfClient *client, const gchar *dir, GError **err); guint gconf_client_notify_add (GConfClient *client, const gchar *namespace_section, GConfClientNotifyFunc func, gpointer user_data, GFreeFunc destroy_notify, GError **err); void gconf_client_notify_remove (GConfClient *client, guint cnxn); void gconf_client_set_error_handling (GConfClient *client, GConfClientErrorHandlingMode mode); void gconf_client_set_global_default_error_handler (GConfClientErrorHandlerFunc func); void gconf_client_clear_cache (GConfClient *client); void gconf_client_preload (GConfClient *client, const gchar *dirname, GConfClientPreloadType type, GError **err); void gconf_client_set (GConfClient *client, const gchar *key, const GConfValue *val, GError **err); GConfValue* gconf_client_get (GConfClient *client, const gchar *key, GError **err); GConfValue* gconf_client_get_without_default (GConfClient *client, const gchar *key, GError **err); GConfEntry* gconf_client_get_entry (GConfClient *client, const gchar *key, const gchar *locale, gboolean use_schema_default, GError **err); GConfValue* gconf_client_get_default_from_schema (GConfClient *client, const gchar *key, GError **err); gboolean gconf_client_unset (GConfClient *client, const gchar *key, GError **err); GSList* gconf_client_all_entries (GConfClient *client, const gchar *dir, GError **err); GSList* gconf_client_all_dirs (GConfClient *client, const gchar *dir, GError **err); void gconf_client_suggest_sync (GConfClient *client, GError **err); gboolean gconf_client_dir_exists (GConfClient *client, const gchar *dir, GError **err); gdouble gconf_client_get_float (GConfClient *client, const gchar *key, GError **err); gint gconf_client_get_int (GConfClient *client, const gchar *key, GError **err); gchar* gconf_client_get_string (GConfClient *client, const gchar *key, GError **err); gboolean gconf_client_get_bool (GConfClient *client, const gchar *key, GError **err); GConfSchema* gconf_client_get_schema (GConfClient *client, const gchar *key, GError **err); GSList* gconf_client_get_list (GConfClient *client, const gchar *key, GConfValueType list_type, GError **err); gboolean gconf_client_get_pair (GConfClient *client, const gchar *key, GConfValueType car_type, GConfValueType cdr_type, gpointer car_retloc, gpointer cdr_retloc, GError **err); gboolean gconf_client_set_float (GConfClient *client, const gchar *key, gdouble val, GError **err); gboolean gconf_client_set_int (GConfClient *client, const gchar *key, gint val, GError **err); gboolean gconf_client_set_string (GConfClient *client, const gchar *key, const gchar *val, GError **err); gboolean gconf_client_set_bool (GConfClient *client, const gchar *key, gboolean val, GError **err); gboolean gconf_client_set_schema (GConfClient *client, const gchar *key, const GConfSchema *val, GError **err); gboolean gconf_client_set_list (GConfClient *client, const gchar *key, GConfValueType list_type, GSList *list, GError **err); gboolean gconf_client_set_pair (GConfClient *client, const gchar *key, GConfValueType car_type, GConfValueType cdr_type, gconstpointer address_of_car, gconstpointer address_of_cdr, GError **err); void gconf_client_error (GConfClient *client, GError *error); void gconf_client_unreturned_error (GConfClient *client, GError *error); void gconf_client_value_changed (GConfClient *client, const gchar *key, GConfValue *value); GConfChangeSet* gconf_client_reverse_change_set (GConfClient *client, GConfChangeSet *cs, GError **err); GConfChangeSet* gconf_client_change_set_from_currentv (GConfClient *client, const gchar **keys, GError **err); GConfChangeSet* gconf_client_change_set_from_current (GConfClient *client, GError **err, const gchar *first_key, ...); gboolean gconf_client_commit_change_set (GConfClient *client, GConfChangeSet *cs, gboolean remove_committed, GError **err);
GConfClient adds the following features to plain GConf:
A client-side cache for a specified list of directories you're interested in. You can "preload" entire directories into the cache, speeding things up even more.
Some automatic error handling, if you request it.
Signals when a value changes or an error occurs.
Warning |
If you use GConfClient, you should not use the underlying GConfEngine directly, or you'll break things. This is why there's no gconf_client_get_engine() function; in fact, if you create the GConfClient with gconf_client_get_default(), there is no (legitimate) way to obtain a pointer to the underlying GConfEngine. If you create a GConfClient from an existing engine, you'll have to be disciplined enough to avoid using that engine directly. [1] |
A GConfClient has a list of directories that it "watches." These directories are optionally pre-loaded into the cache, and monitored in order to emit the value_changed signal. The GConfClient can also be used to access directories not in the list, but those directories won't be preloaded and the "value_changed" signal won't be emitted for them.
There are two error-related signals in GConfClient. The first is plain "error"; it's emitted anytime an error occurs. The second is "unreturned_error"; this signal is emitted if you pass NULL as the GError** to any GConfClient function. The idea is that you can have a global error handler attached to the "unreturned_error" signal; if you want to use this handler, you don't need to use the normal GConf error handling mechanism. However, if you ever need to handle errors for a specific function call, you can override the global handler by passing a non-NULL GError** to the function. If you want an error handler that's always invoked, use the "error" signal.
The "value_changed" signal is emitted whenever the server notifies your client program that a value has changed in the GConf database. There's one problem with this signal: the signal handler has to use strcmp() to determine whether the changed value is the one it was interested in. If you are interested in lots of values, then every time a value changes you'll be making lots of calls to strcmp() and getting O(n) performance. gconf_client_notify_add() is a superior interface in most cases for this reason. Note that calling gconf_client_set() and its relatives will cause "value_changed" to be emitted, but "value_changed" is also emitted if another process changes the value.
Most of the GConfClient interface mirrors the functions you'd use to manipulate a GConfEngine (gconf_engine_get() and gconf_client_get(), for example). These should all work just like the GConfEngine versions, except that they use the cache from GConfClient and emit the GConfClient signals.
As always with GConf, applications based on GConfClient should use a model-controller-view architecture. Typically, this means that areas of your application affected by a setting will monitor the relevant key and update themselves when necessary. The preferences dialog will simply change keys, allowing GConf to notify the rest of the application that changes have occurred. Here the application proper is the "view," GConf is the "model", and the preferences dialog is the "controller." In no case should you do this:
gconf_client_set(client, key, value); application_update_to_reflect_setting();This breaks if a setting is changed outside your application—or even from a different part of your application. The correct way (in pseudo-code) is:
/* At application startup */ gconf_client_notify_add(client, key, application_update_to_reflect_setting, data); /* From preferences dialog */ gconf_client_set(client, key, value);See the example programs that come with GConf for more details.
typedef enum { /*< prefix=GCONF_CLIENT >*/ GCONF_CLIENT_PRELOAD_NONE, /* don't preload anything */ GCONF_CLIENT_PRELOAD_ONELEVEL, /* load entries directly under the directory. */ GCONF_CLIENT_PRELOAD_RECURSIVE /* recurse the directory tree; possibly quite expensive! */ } GConfClientPreloadType;
The GConfClientPreloadType is used to tell GConfClient how to preload one of its directories. As a rule of thumb, if you plan to get the value of almost all the keys in a directory, preloading that directory will probably enhance performance. If you plan to use only half the keys, preloading is likely a bad idea. GCONF_CLIENT_PRELOAD_NONE specifies that no preload occurs, GCONF_CLIENT_PRELOAD_ONELEVEL loads the immediate children of the directory, GCONF_CLIENT_PRELOAD_RECURSIVE loads all children of the directory and its subdirectories, recursively.
GCONF_CLIENT_PRELOAD_NONE | preload nothing. |
GCONF_CLIENT_PRELOAD_ONELEVEL | preload immediate children of the directory. |
GCONF_CLIENT_PRELOAD_RECURSIVE | recursively preload everything in and below the directory. |
typedef enum { /*< prefix=GCONF_CLIENT >*/ GCONF_CLIENT_HANDLE_NONE, GCONF_CLIENT_HANDLE_UNRETURNED, GCONF_CLIENT_HANDLE_ALL } GConfClientErrorHandlingMode;
GConfClientErrorHandlingMode is used to control GConfClient's default error handling. GConfClient can pop up a dialog in the default signal handler for "error" or "unreturned_error." You can specify that no errors are handled, only unreturned errors are handled, or all errors are handled with this enumeration. You can prevent specific errors from being handled automatically by stopping the signal emission before the default signal handler is called (see the GTK+ documentation, gtk_signal_emit_stop_by_name() for example).
GCONF_CLIENT_HANDLE_NONE | never run a default error handler. |
GCONF_CLIENT_HANDLE_UNRETURNED | run a default error handler for unreturned errors ("unreturned_error" signal). |
GCONF_CLIENT_HANDLE_ALL | run a default error handler for all errors ("error" signal). |
void (*GConfClientNotifyFunc) (GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointer user_data);
This is the signature of a user function added with gconf_client_notify_add(). The notify function is invoked when the value of a key changes. The value argument is the new value, or NULL if the key was unset. The value argument should not be modified, and should be copied if you want to keep it around (the GConfClient will destroy it sometime after your notify function is called).
client : | the GConfClient notifying us. |
cnxn_id : | connection ID from gconf_client_notify_add(). |
entry : | |
user_data : | user data from gconf_client_notify_add(). |
void (*GConfClientErrorHandlerFunc) (GConfClient *client, GError *error);
client : | |
error : |
#define GCONF_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GCONF_TYPE_CLIENT, GConfClient))
Casts a pointer to a GConfClient*.
obj : | a GConfClient. |
GConfClient* gconf_client_get_default (void);
Creates a new GConfClient using the default GConfEngine. Normally this is the engine you want. If someone else is already using the default GConfClient, this function returns the same one they're using, but with the reference count incremented. So you have to unref either way.
Returns : | a new GConfClient. g_object_unref() when you're done. |
GConfClient* gconf_client_get_for_engine (GConfEngine *engine);
Creates a new GConfClient with a specific GConfEngine. Only specialized configuration-related programs should need to call this function. The returned GConfClient should be unref'd when you're done with g_object_unref(). Remember to avoid using the GConfEngine directly once you have a GConfClient wrapper.
engine : | the GConfEngine to use. |
Returns : | a new GConfClient. |
void gconf_client_add_dir (GConfClient *client, const gchar *dir, GConfClientPreloadType preload, GError **err);
Add a directory to the list of directories the GConfClient will watch. Any changes to keys below this directory will cause the "value_changed" signal to be emitted. When you add the directory, you can request that the GConfClient preload its contents; see GConfClientPreloadType for details.
Added directories may not overlap. That is, if you add "/foo", you may not add "/foo/bar". However you can add "/foo" and "/bar". You can also add "/foo" multiple times; if you add a directory multiple times, it will not be removed until you call gconf_client_remove_dir() an equal number of times.
client : | a GConfClient. |
dir : | directory to add to the list. |
preload : | degree of preload. |
err : | the return location for an allocated GError, or NULL to ignore errors. |
void gconf_client_remove_dir (GConfClient *client, const gchar *dir, GError **err);
Remove a directory from the list created with gconf_client_add_dir(). If any notifications have been added below this directory with gconf_client_notify_add(), those notifications will be disabled until you re-add the removed directory. Note that if a directory has been added multiple times, you must remove it the same number of times before the remove takes effect.
client : | a GConfClient. |
dir : | directory to remove. |
err : |
|
guint gconf_client_notify_add (GConfClient *client, const gchar *namespace_section, GConfClientNotifyFunc func, gpointer user_data, GFreeFunc destroy_notify, GError **err);
Request notification of changes to namespace_section. This includes the key namespace_section itself, and any keys below it (the behavior is identical to gconf_engine_notify_add(), but while gconf_engine_notify_add() places a notification request on the server for every notify function, GConfClient requests server notification for directories added with gconf_client_add_dir() and keeps the list of GConfClientNotifyFunc on the client side).
For the notification to happen, namespace_section must be equal to or below one of the directories added with gconf_client_add_dir(). You can still call gconf_client_notify_add() for other directories, but no notification will be received until you add a directory above or equal to namespace_section. One implication of this is that gconf_client_remove_dir() temporarily disables notifications that were below the removed directory.
The function returns a connection ID you can use to call gconf_client_notify_remove().
See the description of GConfClientNotifyFunc for details on how the notification function is called.
client : | a GConfClient. |
namespace_section : | where to listen for changes. |
func : | function to call when changes occur. |
user_data : | user data to pass to func. |
destroy_notify : | function to call on user_data when the notify is removed or the GConfClient is destroyed, or NULL for none. |
err : | the return location for an allocated GError, or NULL to ignore errors. |
Returns : | a connection ID for removing the notification. |
void gconf_client_notify_remove (GConfClient *client, guint cnxn);
Remove a notification using the ID returned from gconf_client_notify_add(). Invokes the destroy notify function on the notification's user data, if appropriate.
client : | a GConfClient. |
cnxn : | connection ID. |
void gconf_client_set_error_handling (GConfClient *client, GConfClientErrorHandlingMode mode);
Controls the default error handling for GConfClient. See GConfClientErrorHandlingMode and GConfClientParentWindowFunc for details on this.
client : | a GConfClient. |
mode : | error handling mode. |
void gconf_client_set_global_default_error_handler (GConfClientErrorHandlerFunc func);
func : |
|
void gconf_client_clear_cache (GConfClient *client);
Dumps everything out of the GConfClient client-side cache. If you know you're done using the GConfClient for a while, you can call this function to save some memory.
client : | a GConfClient. |
void gconf_client_preload (GConfClient *client, const gchar *dirname, GConfClientPreloadType type, GError **err);
Preloads a directory. Normally you do this when you call gconf_client_add_dir(), but if you've called gconf_client_clear_cache() there may be a reason to do it again.
client : | a GConfClient. |
dirname : | directory to preload. |
type : | degree of preload. |
err : | the return location for an allocated GError, or NULL to ignore errors. |
void gconf_client_set (GConfClient *client, const gchar *key, const GConfValue *val, GError **err);
Sets the value of a configuration key. Just like gconf_engine_set(), but uses GConfClient caching and error-handling features. The val argument will not be modified.
client : | a GConfClient. |
key : | key to set. |
val : | new value. |
err : | the return location for an allocated GError, or NULL to ignore errors. |
GConfValue* gconf_client_get (GConfClient *client, const gchar *key, GError **err);
client : | |
key : | |
err : | |
Returns : |
|
GConfValue* gconf_client_get_without_default (GConfClient *client, const gchar *key, GError **err);
client : | |
key : | |
err : | |
Returns : |
|
GConfEntry* gconf_client_get_entry (GConfClient *client, const gchar *key, const gchar *locale, gboolean use_schema_default, GError **err);
client : | |
key : | |
locale : | |
use_schema_default : | |
err : | |
Returns : |
|
GConfValue* gconf_client_get_default_from_schema (GConfClient *client, const gchar *key, GError **err);
client : | |
key : | |
err : | |
Returns : |
|
gboolean gconf_client_unset (GConfClient *client, const gchar *key, GError **err);
client : | a GConfClient. |
key : | |
err : | the return location for an allocated GError, or NULL to ignore errors. |
Returns : |
|
GSList* gconf_client_all_entries (GConfClient *client, const gchar *dir, GError **err);
client : | a GConfClient. |
dir : | |
err : | the return location for an allocated GError, or NULL to ignore errors. |
Returns : |
|
GSList* gconf_client_all_dirs (GConfClient *client, const gchar *dir, GError **err);
client : | a GConfClient. |
dir : | |
err : | the return location for an allocated GError, or NULL to ignore errors. |
Returns : |
|
void gconf_client_suggest_sync (GConfClient *client, GError **err);
client : | a GConfClient. |
err : | the return location for an allocated GError, or NULL to ignore errors. |
gboolean gconf_client_dir_exists (GConfClient *client, const gchar *dir, GError **err);
client : | a GConfClient. |
dir : | |
err : | the return location for an allocated GError, or NULL to ignore errors. |
Returns : |
|
gdouble gconf_client_get_float (GConfClient *client, const gchar *key, GError **err);
client : | a GConfClient. |
key : | |
err : | the return location for an allocated GError, or NULL to ignore errors. |
Returns : |
|
gint gconf_client_get_int (GConfClient *client, const gchar *key, GError **err);
client : | a GConfClient. |
key : | |
err : | the return location for an allocated GError, or NULL to ignore errors. |
Returns : |
|
gchar* gconf_client_get_string (GConfClient *client, const gchar *key, GError **err);
client : | a GConfClient. |
key : | |
err : | the return location for an allocated GError, or NULL to ignore errors. |
Returns : |
|
gboolean gconf_client_get_bool (GConfClient *client, const gchar *key, GError **err);
client : | a GConfClient. |
key : | |
err : | the return location for an allocated GError, or NULL to ignore errors. |
Returns : |
|
GConfSchema* gconf_client_get_schema (GConfClient *client, const gchar *key, GError **err);
client : | a GConfClient. |
key : | |
err : | the return location for an allocated GError, or NULL to ignore errors. |
Returns : |
|
GSList* gconf_client_get_list (GConfClient *client, const gchar *key, GConfValueType list_type, GError **err);
client : | a GConfClient. |
key : | |
list_type : | |
err : | the return location for an allocated GError, or NULL to ignore errors. |
Returns : |
|
gboolean gconf_client_get_pair (GConfClient *client, const gchar *key, GConfValueType car_type, GConfValueType cdr_type, gpointer car_retloc, gpointer cdr_retloc, GError **err);
client : | a GConfClient. |
key : | |
car_type : | |
cdr_type : | |
car_retloc : | |
cdr_retloc : | |
err : | the return location for an allocated GError, or NULL to ignore errors. |
Returns : |
|
gboolean gconf_client_set_float (GConfClient *client, const gchar *key, gdouble val, GError **err);
client : | a GConfClient. |
key : | |
val : | |
err : | the return location for an allocated GError, or NULL to ignore errors. |
Returns : |
|
gboolean gconf_client_set_int (GConfClient *client, const gchar *key, gint val, GError **err);
client : | a GConfClient. |
key : | |
val : | |
err : | the return location for an allocated GError, or NULL to ignore errors. |
Returns : |
|
gboolean gconf_client_set_string (GConfClient *client, const gchar *key, const gchar *val, GError **err);
client : | a GConfClient. |
key : | |
val : | |
err : | the return location for an allocated GError, or NULL to ignore errors. |
Returns : |
|
gboolean gconf_client_set_bool (GConfClient *client, const gchar *key, gboolean val, GError **err);
client : | a GConfClient. |
key : | |
val : | |
err : | the return location for an allocated GError, or NULL to ignore errors. |
Returns : |
|
gboolean gconf_client_set_schema (GConfClient *client, const gchar *key, const GConfSchema *val, GError **err);
client : | a GConfClient. |
key : | |
val : | |
err : | the return location for an allocated GError, or NULL to ignore errors. |
Returns : |
|
gboolean gconf_client_set_list (GConfClient *client, const gchar *key, GConfValueType list_type, GSList *list, GError **err);
client : | a GConfClient. |
key : | |
list_type : | |
list : | |
err : | the return location for an allocated GError, or NULL to ignore errors. |
Returns : |
|
gboolean gconf_client_set_pair (GConfClient *client, const gchar *key, GConfValueType car_type, GConfValueType cdr_type, gconstpointer address_of_car, gconstpointer address_of_cdr, GError **err);
client : | a GConfClient. |
key : | |
car_type : | |
cdr_type : | |
address_of_car : | |
address_of_cdr : | |
err : | the return location for an allocated GError, or NULL to ignore errors. |
Returns : |
|
void gconf_client_error (GConfClient *client, GError *error);
Emits the "error" signal. Rarely useful.
client : | a GConfClient. |
error : | error to pass to signal handlers. |
void gconf_client_unreturned_error (GConfClient *client, GError *error);
Emits the "unreturned_error" signal. Rarely useful.
client : | a GConfClient. |
error : | error to pass to signal handlers. |
void gconf_client_value_changed (GConfClient *client, const gchar *key, GConfValue *value);
Emits the "value_changed" signal. Rarely useful.
client : | a GConfClient. |
key : | key to pass to signal handlers. |
value : | value of key to pass to signal handlers. |
GConfChangeSet* gconf_client_reverse_change_set (GConfClient *client, GConfChangeSet *cs, GError **err);
Creates a change set that would reverse cs. That is, for each change in cs, save the current state of that key in the returned change set.
client : | a GConfClient. |
cs : | change set to create the reverse of. |
err : | the return location for an allocated GError, or NULL to ignore errors. |
Returns : | a new change set that would restore the current state of each key in cs. |
GConfChangeSet* gconf_client_change_set_from_currentv (GConfClient *client, const gchar **keys, GError **err);
Creates a change set that will change the keys in NULL-terminated array keys to their current state. Use this to save the current state of a collection of keys; then you can later revert to the current state by committing the returned change set.
client : | a GConfClient. |
keys : | NULL-terminated array of key names. |
err : | the return location for an allocated GError, or NULL to ignore errors. |
Returns : | new change set that changes all the keys to their current state. |
GConfChangeSet* gconf_client_change_set_from_current (GConfClient *client, GError **err, const gchar *first_key, ...);
Convenient varargs version of gconf_client_change_set_from_currentv().
client : | a GConfClient. |
err : | the return location for an allocated GError, or NULL to ignore errors. |
first_key : | first key to save the current state of. |
... : | NULL-terminated list of additional keys. |
Returns : | new change set that changes all the keys to their current state. |
gboolean gconf_client_commit_change_set (GConfClient *client, GConfChangeSet *cs, gboolean remove_committed, GError **err);
client : | |
cs : | |
remove_committed : | |
err : | |
Returns : |
|
[1] | This is all a white lie; some direct GConfEngine operations are safe. But it's complicated to know which, and if an operation isn't safe the resulting bugs will mangle the cache and cause weird bugs at an indeterminate time in the future; you don't want to risk this situation. |
<<< GtkObject Wrapper Reference (GConfClient) | GConf Internal Reference >>> |