1
<!-- ##### SECTION Title ##### -->
5
<!-- ##### SECTION Short_Description ##### -->
7
Basic functions to initialize GConf and get/set values
9
<!-- ##### SECTION Long_Description ##### -->
11
These functions initialize GConf, and communicate with the
12
<application>gconfd</application> server via a
13
#GConfEngine object. You can install a notification
14
request on the server, get values, set values, list directories, and associate
15
schema names with keys.
19
Most of this interface is replicated in the #GtkObject wrapper
20
(#GConfClient object); an alternative to the value-setting functions
21
is the #GConfChangeSet interface.
24
<!-- ##### SECTION See_Also ##### -->
29
<!-- ##### FUNCTION gconf_init ##### -->
31
Initializes the GConf library. Creates a connection to a CORBA ORB, and
32
initializes OAF (the object activation framework) if it isn't already
38
@err: the return location for an allocated #GError, or <symbol>NULL</symbol> to ignore errors.
39
@Returns: <symbol>TRUE</symbol> on success, <symbol>FALSE</symbol> otherwise.
42
<!-- ##### FUNCTION gconf_preinit ##### -->
51
<!-- ##### FUNCTION gconf_postinit ##### -->
60
<!-- ##### FUNCTION gconf_is_initialized ##### -->
62
Asks whether the library has been initialized.
65
@Returns: <symbol>TRUE</symbol> if the library has been initialized.
68
<!-- ##### USER_FUNCTION GConfNotifyFunc ##### -->
70
A callback function invoked when a key's value changes. The @cnxn_id parameter
71
will be the connection ID returned from gconf_engine_notify_add(). @key will be the
72
full path of the changed key, @value will be the new value if the key is set.
73
If the key is unset, @value will be the default value if one exists, or
74
<symbol>NULL</symbol> otherwise. @is_default indicates whether a value is a
75
default setting or a user setting. If @value is <symbol>NULL</symbol>,
76
@is_default will be <symbol>TRUE</symbol>. @user_data is the data passed to
77
gconf_engine_notify_add().
80
@conf: the #GConfEngine passed to gconf_engine_notify_add().
81
@cnxn_id: the ID returned from gconf_engine_notify_add().
83
@user_data: the user data passed to gconf_engine_notify_add().
84
<!-- # Unused Parameters # -->
85
@key: the full path of the changed key.
86
@value: the new value, or <symbol>NULL</symbol> if the key was unset.
87
@is_default: if <symbol>TRUE</symbol>, the key is unset but this is the default value for it.
90
<!-- ##### FUNCTION gconf_engine_notify_add ##### -->
92
Registers a notification request with the <application>gconfd</application>
93
server. The server will notify the client when any key at or below
94
@namespace_section is set or unset. Try to watch the smallest possible part of
95
the namespace; otherwise you will slow down the server and your application with
96
unnecessary notifications. Note that you should prefer gconf_client_notify_add()
97
if you're using the #GtkObject wrapper library, because
98
gconf_client_notify_add() does not require a client-server conversation for
99
every callback. gconf_engine_notify_add() requests a different server notification for
100
every callback. The function returns an ID you can use to remove the
101
notification request; 0 is an invalid ID, and is returned if an error occurs.
104
@conf: a #GConfEngine to monitor for changes.
105
@namespace_section: the directory or key to watch; you will be notified of changes at or below this point.
106
@func: the callback to invoke when a notification is received from the server.
107
@user_data: the data to pass to the callback.
108
@err: the return location for an allocated #GError, or <symbol>NULL</symbol> to ignore errors.
109
@Returns: an ID for the notification request, or 0 on error.
112
<!-- ##### FUNCTION gconf_engine_notify_remove ##### -->
114
Removes a notification request.
117
@conf: the #GConfEngine you were monitoring for changes.
118
@cnxn: The ID returned by gconf_engine_notify_add().
121
<!-- ##### FUNCTION gconf_engine_get ##### -->
123
Returns the #GConfValue stored at @key, or <symbol>NULL</symbol> if no value is
124
set. You must call gconf_value_free() to free the returned value. If you know
125
the expected type of the value, you probably want to use the type-specific
126
convenience wrappers (gconf_engine_get_int(), etc.) because they will do the
127
type-checking for you and return the appropriate type. Automatically returns the
128
default value for a key, if the key is unset and a default exists.
131
@conf: a #GConfEngine to get the value from.
132
@key: the key to get.
133
@err: the return location for an allocated #GError, or <symbol>NULL</symbol> to ignore errors.
134
@Returns: newly-allocated #GConfValue, or <symbol>NULL</symbol> if unset and no default exists.
137
<!-- ##### FUNCTION gconf_engine_get_with_locale ##### -->
139
Requests the value appropriate for a particular locale. Right now,
140
only values of type %GCONF_VALUE_SCHEMA are localized; the locale is
141
meaningless for other value types. Also, gconf_engine_get () automatically
142
requests the value in the user's current locale. So this function is
143
only useful if you want a schema for some locale other than the user's
144
current locale. Except for the additional argument, this function is
145
identical to gconf_engine_get () in all respects.
148
@conf: a #GConfEngine to get the value from.
149
@key: the key to get.
150
@locale: preferred locale (as in the locale-related environment variables).
151
@err: the return location for an allocated #GError, or <symbol>NULL</symbol> to ignore errors.
152
@Returns: newly-allocated #GConfValue, or <symbol>NULL</symbol> if unset.
155
<!-- ##### FUNCTION gconf_engine_get_without_default ##### -->
157
Identical to gconf_engine_get (), except that it will return <symbol>NULL</symbol> in
158
place of the default value if the key is unset. Note that gconf_engine_get () can also
159
return <symbol>NULL</symbol> if no default exists or an error occurs.
162
@conf: a #GConfEngine to get the value from.
163
@key: the key to get.
164
@err: the return location for an allocated #GError, or <symbol>NULL</symbol> to ignore errors.
165
@Returns: newly-allocated #GConfValue, or <symbol>NULL</symbol> if unset.
168
<!-- ##### FUNCTION gconf_engine_get_entry ##### -->
170
Obtain the full #GConfEntry for a value.
181
<!-- ##### FUNCTION gconf_engine_get_default_from_schema ##### -->
183
Returns the default value stored in the key's schema, if the key has a schema
184
associated and the schema exists and the schema contains a default value. Note
185
that gconf_engine_get (), gconf_engine_get_string(), and so on already return the default value
186
if no other value is found, so normally you do not need this function. This
187
function is just for convenience; you could also get the #GConfMetaInfo for the
188
key, read the schema name from there, then look up the schema by name and
189
extract the default value.
192
@conf: a #GConfEngine to get the value from.
193
@key: the key to get the default value for.
194
@err: the return location for an allocated #GError, or <symbol>NULL</symbol> to ignore errors.
195
@Returns: newly-allocated #GConfValue, or <symbol>NULL</symbol> if unset.
198
<!-- ##### FUNCTION gconf_engine_set ##### -->
200
Sets the value of @key to @value. Does not modify the passed-in
201
#GConfValue, you must free it yourself. You may prefer a type-specific
202
convenience wrapper, such as gconf_engine_set_int().
206
An error of note is %GCONF_OVERRIDDEN, indicating that the system
207
administrator has "forced" a value for this key. If no writable
208
configuration sources exist, it is not an error, but GConf will just
209
forget all your values; this allows users to have a configuration-free
210
setup without a constant barrage of error messages.
213
@conf: a #GConfEngine to set the value in.
214
@key: the key to set.
215
@value: the new value of @key.
216
@err: the return location for an allocated #GError, or <symbol>NULL</symbol> to ignore errors.
217
@Returns: <symbol>TRUE</symbol> on success, <symbol>FALSE</symbol> on error.
220
<!-- ##### FUNCTION gconf_engine_unset ##### -->
222
Unsets the value of @key; if @key is already unset, has no effect. An
223
error of note is %GCONF_OVERRIDDEN, indicating that the system
224
administrator has "forced" a value for this key.
227
@conf: a #GConfEngine to affect.
228
@key: the key to unset.
229
@err: the return location for an allocated #GError, or <symbol>NULL</symbol> to ignore errors.
230
@Returns: <symbol>TRUE</symbol> on success, <symbol>FALSE</symbol> on error.
233
<!-- ##### FUNCTION gconf_engine_associate_schema ##### -->
235
Directs GConf to find the schema for @key at location
236
@schema_key. That is, the value stored at @schema_key should have type
237
#GCONF_VALUE_SCHEMA, and be descriptive of @key. Normally you don't
238
call this function from C code; you can ship a special file with your
239
application and ask <application>gconftool</application> to install
240
schema associations into the database during "make install."
243
@conf: a #GConfEngine to affect.
244
@key: the key to associate the schema with.
245
@schema_key: the key where the schema will be stored.
246
@err: the return location for an allocated #GError, or <symbol>NULL</symbol> to ignore errors.
247
@Returns: <symbol>TRUE</symbol> on success, <symbol>FALSE</symbol> on error.
250
<!-- ##### FUNCTION gconf_engine_all_entries ##### -->
252
Lists the key-value pairs in @dir. Does not list subdirectories; for
253
that use gconf_engine_all_dirs(). The returned list contains #GConfEntry
254
objects. A #GConfEntry contains a <emphasis>relative</emphasis> key
255
and a value. The list is not recursive, it contains only the immediate
256
children of @dir. To free the returned list, gconf_entry_free()
257
each list element, then g_slist_free() the list itself.
260
@conf: a #GConfEngine.
261
@dir: Directory to list.
262
@err: the return location for an allocated #GError, or <symbol>NULL</symbol> to ignore errors.
263
@Returns: List of #GConfEntry.
266
<!-- ##### FUNCTION gconf_engine_all_dirs ##### -->
268
Lists the subdirectories in @dir. The returned list contains allocated
269
strings; you should g_free() each string in the list, then
270
g_slist_free() the list itself.
273
@conf: a #GConfEngine.
274
@dir: Directory to get subdirectories from.
275
@err: the return location for an allocated #GError, or <symbol>NULL</symbol> to ignore errors.
276
@Returns: List of allocated subdirectory names.
279
<!-- ##### FUNCTION gconf_engine_suggest_sync ##### -->
281
Suggests to <application>gconfd</application> that you've just finished
282
a block of changes, and it would be an optimal time to sync to
283
permanent storage. This is only a suggestion; and
284
<application>gconfd</application> will eventually sync even if you
285
don't call gconf_engine_suggest_sync(). This function is just a "hint"
286
provided to <application>gconfd</application> to maximize efficiency
287
and minimize data loss.
290
@conf: the #GConfEngine to suggest syncing to.
291
@err: the return location for an allocated #GError, or <symbol>NULL</symbol> to ignore errors.
294
<!-- ##### FUNCTION gconf_engine_dir_exists ##### -->
296
Queries whether the directory @dir exists in the GConf
297
database. Returns <symbol>TRUE</symbol> or <symbol>FALSE</symbol>.
300
@conf: a #GConfEngine.
301
@dir: Directory to check for.
302
@err: the return location for an allocated #GError, or <symbol>NULL</symbol> to ignore errors.
303
@Returns: <symbol>TRUE</symbol> or <symbol>FALSE</symbol>.
306
<!-- ##### FUNCTION gconf_valid_key ##### -->
308
Asks whether a key is syntactically correct, that is, it ensures that
309
the key consists of slash-separated strings and contains only legal
310
characters. Normally you shouldn't need to call this function; the
311
GConf functions all check this for you and return an error if the key
312
is invalid. However, it may be useful to validate input to an entry
313
field or the like. If you pass a non-<symbol>NULL</symbol> address as
314
the @why_invalid argument, an allocated string is returned explaining
315
why the key is invalid, if it is. If the key is valid the @why_invalid
320
@why_invalid: return location for an explanation of the problem, if any. g_free() the returned string.
321
@Returns: <symbol>TRUE</symbol> if the key is valid, or <symbol>FALSE</symbol> if not.
324
<!-- ##### FUNCTION gconf_key_is_below ##### -->
326
Asks whether the key @below would be found below the key @above, were
327
they both to exist in the database. For example, <symbol>/foo</symbol>
328
is always found below <symbol>/</symbol> and above
329
<symbol>/foo/bar</symbol>. This probably isn't useful but GConf uses
330
it internally so here it is if you need it.
333
@above: the key on the "left hand side" of the predicate.
334
@below: the key on the "right hand side."
335
@Returns: <symbol>TRUE</symbol> or <symbol>FALSE</symbol>.
338
<!-- ##### FUNCTION gconf_engine_get_float ##### -->
340
Requests the floating point number (%GCONF_VALUE_FLOAT) stored at
341
@key. Automatically performs type-checking, so if a non-float is
342
stored at @key, an error is returned. On error, or if @key is unset,
346
@conf: a #GConfEngine.
347
@key: key you want the value of.
348
@err: the return location for an allocated #GError, or <symbol>NULL</symbol> to ignore errors.
349
@Returns: the value of @key, or 0.0 if no value is obtained.
352
<!-- ##### FUNCTION gconf_engine_get_int ##### -->
354
Requests the integer (%GCONF_VALUE_INT) stored at
355
@key. Automatically performs type-checking, so if a non-integer is
356
stored at @key, an error is returned. On error, or if @key is unset,
360
@conf: a #GConfEngine.
361
@key: key you want the value of.
362
@err: the return location for an allocated #GError, or <symbol>NULL</symbol> to ignore errors.
363
@Returns: the value of @key, or 0 if no value is obtained.
366
<!-- ##### FUNCTION gconf_engine_get_string ##### -->
368
Requests the string (%GCONF_VALUE_STRING) stored at
369
@key. Automatically performs type-checking, so if a non-string is
370
stored at @key, an error is returned. On error, or if @key is unset,
371
<symbol>NULL</symbol> is returned.
374
@conf: a #GConfEngine.
375
@key: key you want the value of.
376
@err: the return location for an allocated #GError, or <symbol>NULL</symbol> to ignore errors.
377
@Returns: allocated string (value of @key), or <symbol>NULL</symbol> if no value is obtained.
380
<!-- ##### FUNCTION gconf_engine_get_bool ##### -->
382
Requests the boolean value (%GCONF_VALUE_BOOL) stored at
383
@key. Automatically performs type-checking, so if a non-bool is
384
stored at @key, an error is returned. On error, or if @key is unset,
385
<symbol>FALSE</symbol> is returned.
388
@conf: a #GConfEngine.
389
@key: key you want the value of.
390
@err: the return location for an allocated #GError, or <symbol>NULL</symbol> to ignore errors.
391
@Returns: the value of @key, or <symbol>FALSE</symbol> if no value is obtained.
394
<!-- ##### FUNCTION gconf_engine_get_schema ##### -->
396
Requests the schema (%GCONF_VALUE_SCHEMA) stored at @key.
397
Automatically performs type-checking, so if a non-schema is stored at
398
@key, an error is returned. If no value is set or an error occurs,
399
<symbol>NULL</symbol> is returned.
402
@conf: a #GConfEngine.
403
@key: key you want the value of.
404
@err: the return location for an allocated #GError, or <symbol>NULL</symbol> to ignore errors.
405
@Returns: the value of @key as an allocated #GConfSchema, or <symbol>NULL</symbol> if no value was obtained.
408
<!-- ##### FUNCTION gconf_engine_get_list ##### -->
410
Requests the list (%GCONF_VALUE_LIST) stored at @key. Automatically
411
performs type-checking, so if a non-list is stored at @key, or the
412
list does not contain elements of type @list_type, an error is
413
returned. If no value is set or an error occurs, <symbol>NULL</symbol>
414
is returned. Note that <symbol>NULL</symbol> is also the empty list,
415
so if you need to distinguish the empty list from an unset value, you
416
must use gconf_engine_get () to obtain a raw #GConfValue.
420
<emphasis>Remember that GConf lists can only store primitive types:
421
%GCONF_VALUE_FLOAT, %GCONF_VALUE_INT, %GCONF_VALUE_BOOL,
422
%GCONF_VALUE_STRING, %GCONF_VALUE_SCHEMA.</emphasis> Also remember
423
that lists must be uniform, you may not mix types in the same list.
427
The type of the list elements depends on @list_type. A #GConfValue
428
with type %GCONF_VALUE_LIST normally stores a list of more #GConfValue
429
objects. gconf_engine_get_list() automatically converts to primitive C
430
types. Thus, the list->data fields in the returned list
433
<informaltable pgwide=1 frame="none">
434
<tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*">
438
<entry>%GCONF_VALUE_INT</entry>
439
<entry>The integer itself, converted with GINT_TO_POINTER()</entry>
443
<entry>%GCONF_VALUE_BOOL</entry>
444
<entry>The bool itself, converted with GINT_TO_POINTER()</entry>
448
<entry>%GCONF_VALUE_FLOAT</entry>
449
<entry>A pointer to #gdouble, which should be freed with g_free()</entry>
453
<entry>%GCONF_VALUE_STRING</entry>
454
<entry>A pointer to #gchar, which should be freed with g_free()</entry>
458
<entry>%GCONF_VALUE_SCHEMA</entry>
459
<entry>A pointer to #GConfSchema, which should be freed with gconf_schema_free()</entry>
462
</tbody></tgroup></informaltable>
464
In the %GCONF_VALUE_FLOAT and %GCONF_VALUE_STRING cases, you must
465
g_free() each list element. In the %GCONF_VALUE_SCHEMA case you must
466
gconf_schema_free() each element. In all cases you must free the
467
list itself with g_slist_free().
470
@conf: a #GConfEngine.
471
@key: key you want the value of.
472
@list_type: type of each list element.
473
@err: the return location for an allocated #GError, or <symbol>NULL</symbol> to ignore errors.
474
@Returns: an allocated list, with elements as described above.
477
<!-- ##### FUNCTION gconf_engine_get_pair ##### -->
479
Requests the pair (%GCONF_VALUE_PAIR) stored at @key. Automatically
480
performs type-checking, so if a non-pair is stored at @key, or the
481
pair does not have the right @car_type and @cdr_type, an error is
482
returned. Remember that the <firstterm>car</firstterm> of a pair is
483
its first value, and the <firstterm>cdr</firstterm> is its second
484
value, in the Lisp tradition.
488
<emphasis>Remember that GConf pairs can only store primitive types:
489
%GCONF_VALUE_FLOAT, %GCONF_VALUE_INT, %GCONF_VALUE_BOOL,
490
%GCONF_VALUE_STRING, %GCONF_VALUE_SCHEMA.</emphasis>
494
gconf_engine_get_pair() stores the two fields of the pair in the locations
495
pointed to by @car_retloc and @cdr_retloc. The type of these pointers
496
depends on the corresponding @car_type and @cdr_type:
498
<informaltable pgwide=1 frame="none">
499
<tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*">
503
<entry>%GCONF_VALUE_INT</entry>
504
<entry>pointer to #gint</entry>
508
<entry>%GCONF_VALUE_BOOL</entry>
509
<entry>pointer to #gboolean</entry>
513
<entry>%GCONF_VALUE_FLOAT</entry>
514
<entry>pointer to #gdouble</entry>
518
<entry>%GCONF_VALUE_STRING</entry>
519
<entry>pointer to #gchar*</entry>
523
<entry>%GCONF_VALUE_SCHEMA</entry>
524
<entry>pointer to #GConfSchema*</entry>
527
</tbody></tgroup></informaltable>
529
In the %GCONF_VALUE_STRING case, you must g_free() the string(s)
530
stored in the return location(s). In the %GCONF_VALUE_SCHEMA case you
531
must gconf_schema_free() the returned schema. If there's an error
532
or the value is unset, @car_retloc and @cdr_retloc are left unchanged.
536
gconf_engine_get_pair() returns <symbol>TRUE</symbol> on success.
540
An example of gconf_engine_get_pair() in action:
544
GError* error = NULL;
546
if (!gconf_engine_get_pair(conf, "/foo",
549
&car, &cdr, &error))
551
/* Note: car/cdr should be untouched, because an error occurred */
552
g_assert(error != NULL);
553
fprintf(stderr, "Error: %s\n", error->message);
559
/* Note: car/cdr may be untouched even though there was no error,
560
if no value was set for "/foo"
562
printf("Found pair (%g,%s)\n", car, cdr);
569
@conf: a #GConfEngine.
570
@key: key you want the value of.
571
@car_type: desired type of the pair's first field (car).
572
@cdr_type: desired type of the pair's second field (cdr).
573
@car_retloc: address of a return location for the car.
574
@cdr_retloc: address of a return location for the cdr.
575
@err: the return location for an allocated #GError, or <symbol>NULL</symbol> to ignore errors.
576
@Returns: <symbol>TRUE</symbol> on success, <symbol>FALSE</symbol> on error.
579
<!-- ##### FUNCTION gconf_engine_set_float ##### -->
584
@conf: a #GConfEngine.
587
@err: the return location for an allocated #GError, or <symbol>NULL</symbol> to ignore errors.
591
<!-- ##### FUNCTION gconf_engine_set_int ##### -->
596
@conf: a #GConfEngine.
599
@err: the return location for an allocated #GError, or <symbol>NULL</symbol> to ignore errors.
603
<!-- ##### FUNCTION gconf_engine_set_string ##### -->
608
@conf: a #GConfEngine.
611
@err: the return location for an allocated #GError, or <symbol>NULL</symbol> to ignore errors.
615
<!-- ##### FUNCTION gconf_engine_set_bool ##### -->
620
@conf: a #GConfEngine.
623
@err: the return location for an allocated #GError, or <symbol>NULL</symbol> to ignore errors.
627
<!-- ##### FUNCTION gconf_engine_set_schema ##### -->
632
@conf: a #GConfEngine.
635
@err: the return location for an allocated #GError, or <symbol>NULL</symbol> to ignore errors.
639
<!-- ##### FUNCTION gconf_engine_set_list ##### -->
644
@conf: a #GConfEngine.
648
@err: the return location for an allocated #GError, or <symbol>NULL</symbol> to ignore errors.
652
<!-- ##### FUNCTION gconf_engine_set_pair ##### -->
657
@conf: a #GConfEngine.
663
@err: the return location for an allocated #GError, or <symbol>NULL</symbol> to ignore errors.
667
<!-- ##### STRUCT GConfEnumStringPair ##### -->
675
<!-- ##### FUNCTION gconf_string_to_enum ##### -->
677
It's best to store enumeration values as strings rather than integers. This is
678
robust against changes in the enumeration, and also human-readable.
679
This function makes it more convenient to store enums as strings.
683
The first argument is a lookup table, typically declared statically as follows:
685
static GConfEnumStringPair foo_enum_lookup_table[] = {
686
{ FOO_BLAH, "Blah" },
691
Note that the last element of the table is <literal>{ 0, NULL }</literal>.
692
Typically the strings you use should be semi-human-readable, for GTK+ and GNOME
693
stripping off the library prefix and converting to StudlyCaps is the recommended
698
The function returns <symbol>TRUE</symbol> if a match for the string is found,
699
and if a match is found the enum value is placed in @enum_value_retloc.
702
@lookup_table: a lookup table mapping enum values to strings.
703
@str: the string to convert to an enum value.
704
@enum_value_retloc: the address of an enum variable.
705
@Returns: <symbol>TRUE</symbol> if a match was found.
708
<!-- ##### FUNCTION gconf_enum_to_string ##### -->
710
See gconf_string_to_enum() for background information on this function.
713
@lookup_table: a lookup table mapping enum values to strings.
714
@enum_value: the enumeration value to convert to a string.
715
@Returns: a pointer to the proper string in the lookup table, or <symbol>NULL</symbol> if no match was found.