1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
3 /* arch-tag: Implementation of stuff to make GConf easier to use.
5 Copyright (C) 2000, 2001 Eazel, Inc.
7 The Gnome Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public License as
9 published by the Free Software Foundation; either version 2 of the
10 License, or (at your option) any later version.
12 The Gnome Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public
18 License along with the Gnome Library; see the file COPYING.LIB. If not,
19 write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 Boston, MA 02110-1301 USA.
22 Authors: Ramiro Estrugo <ramiro@eazel.com>
27 #include <gconf/gconf-client.h>
28 #include <gconf/gconf.h>
29 #include <libgnome/gnome-i18n.h>
31 #include "eel-gconf-extensions.h"
32 #include "rb-dialog.h"
34 static GConfClient
*global_gconf_client
= NULL
;
37 global_client_free (void)
39 if (global_gconf_client
== NULL
) {
43 g_object_unref (G_OBJECT (global_gconf_client
));
44 global_gconf_client
= NULL
;
49 eel_gconf_client_get_global (void)
51 if (global_gconf_client
== NULL
) {
52 global_gconf_client
= gconf_client_get_default ();
53 g_atexit (global_client_free
);
56 return global_gconf_client
;
60 eel_gconf_handle_error (GError
**error
)
62 g_return_val_if_fail (error
!= NULL
, FALSE
);
65 g_warning ((*error
)->message
);
66 g_error_free (*error
);
76 eel_gconf_set_boolean (const char *key
,
77 gboolean boolean_value
)
82 g_return_if_fail (key
!= NULL
);
84 client
= eel_gconf_client_get_global ();
85 g_return_if_fail (client
!= NULL
);
87 gconf_client_set_bool (client
, key
, boolean_value
, &error
);
88 eel_gconf_handle_error (&error
);
92 eel_gconf_get_boolean (const char *key
)
98 g_return_val_if_fail (key
!= NULL
, FALSE
);
100 client
= eel_gconf_client_get_global ();
101 g_return_val_if_fail (client
!= NULL
, FALSE
);
103 result
= gconf_client_get_bool (client
, key
, &error
);
105 if (eel_gconf_handle_error (&error
)) {
113 eel_gconf_set_integer (const char *key
,
117 GError
*error
= NULL
;
119 g_return_if_fail (key
!= NULL
);
121 client
= eel_gconf_client_get_global ();
122 g_return_if_fail (client
!= NULL
);
124 gconf_client_set_int (client
, key
, int_value
, &error
);
125 eel_gconf_handle_error (&error
);
129 eel_gconf_get_integer (const char *key
)
133 GError
*error
= NULL
;
135 g_return_val_if_fail (key
!= NULL
, 0);
137 client
= eel_gconf_client_get_global ();
138 g_return_val_if_fail (client
!= NULL
, 0);
140 result
= gconf_client_get_int (client
, key
, &error
);
142 if (eel_gconf_handle_error (&error
)) {
150 eel_gconf_set_float (const char *key
,
154 GError
*error
= NULL
;
156 g_return_if_fail (key
!= NULL
);
158 client
= eel_gconf_client_get_global ();
159 g_return_if_fail (client
!= NULL
);
161 gconf_client_set_float (client
, key
, float_value
, &error
);
162 eel_gconf_handle_error (&error
);
166 eel_gconf_get_float (const char *key
)
170 GError
*error
= NULL
;
172 g_return_val_if_fail (key
!= NULL
, 0);
174 client
= eel_gconf_client_get_global ();
175 g_return_val_if_fail (client
!= NULL
, 0);
177 result
= gconf_client_get_float (client
, key
, &error
);
179 if (eel_gconf_handle_error (&error
)) {
187 eel_gconf_set_string (const char *key
,
188 const char *string_value
)
191 GError
*error
= NULL
;
193 g_return_if_fail (key
!= NULL
);
194 g_return_if_fail (string_value
!= NULL
);
196 client
= eel_gconf_client_get_global ();
197 g_return_if_fail (client
!= NULL
);
199 gconf_client_set_string (client
, key
, string_value
, &error
);
200 eel_gconf_handle_error (&error
);
204 eel_gconf_get_string (const char *key
)
208 GError
*error
= NULL
;
210 g_return_val_if_fail (key
!= NULL
, NULL
);
212 client
= eel_gconf_client_get_global ();
213 g_return_val_if_fail (client
!= NULL
, NULL
);
215 result
= gconf_client_get_string (client
, key
, &error
);
217 if (eel_gconf_handle_error (&error
)) {
218 result
= g_strdup ("");
225 eel_gconf_set_string_list (const char *key
,
231 g_return_if_fail (key
!= NULL
);
233 client
= eel_gconf_client_get_global ();
234 g_return_if_fail (client
!= NULL
);
237 gconf_client_set_list (client
, key
, GCONF_VALUE_STRING
,
238 /* Need cast cause of GConf api bug */
241 eel_gconf_handle_error (&error
);
245 eel_gconf_get_string_list (const char *key
)
251 g_return_val_if_fail (key
!= NULL
, NULL
);
253 client
= eel_gconf_client_get_global ();
254 g_return_val_if_fail (client
!= NULL
, NULL
);
257 slist
= gconf_client_get_list (client
, key
, GCONF_VALUE_STRING
, &error
);
258 if (eel_gconf_handle_error (&error
)) {
265 /* This code wasn't part of the original eel-gconf-extensions.c */
267 eel_gconf_set_integer_list (const char *key
,
273 g_return_if_fail (key
!= NULL
);
275 client
= eel_gconf_client_get_global ();
276 g_return_if_fail (client
!= NULL
);
279 gconf_client_set_list (client
, key
, GCONF_VALUE_INT
,
280 /* Need cast cause of GConf api bug */
283 eel_gconf_handle_error (&error
);
287 eel_gconf_get_integer_list (const char *key
)
293 g_return_val_if_fail (key
!= NULL
, NULL
);
295 client
= eel_gconf_client_get_global ();
296 g_return_val_if_fail (client
!= NULL
, NULL
);
299 slist
= gconf_client_get_list (client
, key
, GCONF_VALUE_INT
, &error
);
300 if (eel_gconf_handle_error (&error
)) {
306 /* End of added code */
309 eel_gconf_is_default (const char *key
)
313 GError
*error
= NULL
;
315 g_return_val_if_fail (key
!= NULL
, FALSE
);
317 value
= gconf_client_get_without_default (eel_gconf_client_get_global (), key
, &error
);
319 if (eel_gconf_handle_error (&error
)) {
321 gconf_value_free (value
);
326 result
= (value
== NULL
);
329 gconf_value_free (value
);
337 eel_gconf_unset (const char *key
)
340 GError
*error
= NULL
;
342 g_return_if_fail (key
!= NULL
);
344 client
= eel_gconf_client_get_global ();
345 g_return_if_fail (client
!= NULL
);
347 gconf_client_unset (client
, key
, &error
);
348 eel_gconf_handle_error (&error
);
352 eel_gconf_monitor_add (const char *directory
)
354 GError
*error
= NULL
;
357 g_return_val_if_fail (directory
!= NULL
, FALSE
);
359 client
= eel_gconf_client_get_global ();
360 g_return_val_if_fail (client
!= NULL
, FALSE
);
362 gconf_client_add_dir (client
,
364 GCONF_CLIENT_PRELOAD_NONE
,
367 if (eel_gconf_handle_error (&error
)) {
375 eel_gconf_monitor_remove (const char *directory
)
377 GError
*error
= NULL
;
380 if (directory
== NULL
) {
384 client
= eel_gconf_client_get_global ();
385 g_return_val_if_fail (client
!= NULL
, FALSE
);
387 gconf_client_remove_dir (client
,
391 if (eel_gconf_handle_error (&error
)) {
399 eel_gconf_suggest_sync (void)
402 GError
*error
= NULL
;
404 client
= eel_gconf_client_get_global ();
405 g_return_if_fail (client
!= NULL
);
407 gconf_client_suggest_sync (client
, &error
);
408 eel_gconf_handle_error (&error
);
412 eel_gconf_get_value (const char *key
)
414 GConfValue
*value
= NULL
;
416 GError
*error
= NULL
;
418 g_return_val_if_fail (key
!= NULL
, NULL
);
420 client
= eel_gconf_client_get_global ();
421 g_return_val_if_fail (client
!= NULL
, NULL
);
423 value
= gconf_client_get (client
, key
, &error
);
425 if (eel_gconf_handle_error (&error
)) {
427 gconf_value_free (value
);
436 eel_gconf_set_value (const char *key
, GConfValue
*value
)
439 GError
*error
= NULL
;
441 g_return_if_fail (key
!= NULL
);
443 client
= eel_gconf_client_get_global ();
444 g_return_if_fail (client
!= NULL
);
446 gconf_client_set (client
, key
, value
, &error
);
448 if (eel_gconf_handle_error (&error
)) {
454 eel_gconf_value_free (GConfValue
*value
)
460 gconf_value_free (value
);
464 eel_gconf_notification_add (const char *key
,
465 GConfClientNotifyFunc notification_callback
,
466 gpointer callback_data
)
468 guint notification_id
;
470 GError
*error
= NULL
;
472 g_return_val_if_fail (key
!= NULL
, EEL_GCONF_UNDEFINED_CONNECTION
);
473 g_return_val_if_fail (notification_callback
!= NULL
, EEL_GCONF_UNDEFINED_CONNECTION
);
475 client
= eel_gconf_client_get_global ();
476 g_return_val_if_fail (client
!= NULL
, EEL_GCONF_UNDEFINED_CONNECTION
);
478 notification_id
= gconf_client_notify_add (client
,
480 notification_callback
,
485 if (eel_gconf_handle_error (&error
)) {
486 if (notification_id
!= EEL_GCONF_UNDEFINED_CONNECTION
) {
487 gconf_client_notify_remove (client
, notification_id
);
488 notification_id
= EEL_GCONF_UNDEFINED_CONNECTION
;
492 return notification_id
;
496 eel_gconf_notification_remove (guint notification_id
)
500 if (notification_id
== EEL_GCONF_UNDEFINED_CONNECTION
) {
504 client
= eel_gconf_client_get_global ();
505 g_return_if_fail (client
!= NULL
);
507 gconf_client_notify_remove (client
, notification_id
);