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., 59 Temple Place - Suite 330,
20
Boston, MA 02111-1307, 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>
30
#include <libgnomeui/gnome-dialog.h>
31
#include <libgnomeui/gnome-dialog-util.h>
33
#include "eel-gconf-extensions.h"
34
#include "rb-dialog.h"
36
static GConfClient *global_gconf_client = NULL;
39
global_client_free (void)
41
if (global_gconf_client == NULL) {
45
g_object_unref (G_OBJECT (global_gconf_client));
46
global_gconf_client = NULL;
51
eel_gconf_client_get_global (void)
53
if (global_gconf_client == NULL) {
54
global_gconf_client = gconf_client_get_default ();
55
g_atexit (global_client_free);
58
return global_gconf_client;
62
eel_gconf_handle_error (GError **error)
64
g_return_val_if_fail (error != NULL, FALSE);
67
rb_error_dialog (NULL,
68
_("Configuration system error"),
70
g_error_free (*error);
80
eel_gconf_set_boolean (const char *key,
81
gboolean boolean_value)
86
g_return_if_fail (key != NULL);
88
client = eel_gconf_client_get_global ();
89
g_return_if_fail (client != NULL);
91
gconf_client_set_bool (client, key, boolean_value, &error);
92
eel_gconf_handle_error (&error);
96
eel_gconf_get_boolean (const char *key)
100
GError *error = NULL;
102
g_return_val_if_fail (key != NULL, FALSE);
104
client = eel_gconf_client_get_global ();
105
g_return_val_if_fail (client != NULL, FALSE);
107
result = gconf_client_get_bool (client, key, &error);
109
if (eel_gconf_handle_error (&error)) {
117
eel_gconf_set_integer (const char *key,
121
GError *error = NULL;
123
g_return_if_fail (key != NULL);
125
client = eel_gconf_client_get_global ();
126
g_return_if_fail (client != NULL);
128
gconf_client_set_int (client, key, int_value, &error);
129
eel_gconf_handle_error (&error);
133
eel_gconf_get_integer (const char *key)
137
GError *error = NULL;
139
g_return_val_if_fail (key != NULL, 0);
141
client = eel_gconf_client_get_global ();
142
g_return_val_if_fail (client != NULL, 0);
144
result = gconf_client_get_int (client, key, &error);
146
if (eel_gconf_handle_error (&error)) {
154
eel_gconf_set_float (const char *key,
158
GError *error = NULL;
160
g_return_if_fail (key != NULL);
162
client = eel_gconf_client_get_global ();
163
g_return_if_fail (client != NULL);
165
gconf_client_set_float (client, key, float_value, &error);
166
eel_gconf_handle_error (&error);
170
eel_gconf_get_float (const char *key)
174
GError *error = NULL;
176
g_return_val_if_fail (key != NULL, 0);
178
client = eel_gconf_client_get_global ();
179
g_return_val_if_fail (client != NULL, 0);
181
result = gconf_client_get_float (client, key, &error);
183
if (eel_gconf_handle_error (&error)) {
191
eel_gconf_set_string (const char *key,
192
const char *string_value)
195
GError *error = NULL;
197
g_return_if_fail (key != NULL);
198
g_return_if_fail (string_value != NULL);
200
client = eel_gconf_client_get_global ();
201
g_return_if_fail (client != NULL);
203
gconf_client_set_string (client, key, string_value, &error);
204
eel_gconf_handle_error (&error);
208
eel_gconf_get_string (const char *key)
212
GError *error = NULL;
214
g_return_val_if_fail (key != NULL, NULL);
216
client = eel_gconf_client_get_global ();
217
g_return_val_if_fail (client != NULL, NULL);
219
result = gconf_client_get_string (client, key, &error);
221
if (eel_gconf_handle_error (&error)) {
222
result = g_strdup ("");
229
eel_gconf_set_string_list (const char *key,
235
g_return_if_fail (key != NULL);
237
client = eel_gconf_client_get_global ();
238
g_return_if_fail (client != NULL);
241
gconf_client_set_list (client, key, GCONF_VALUE_STRING,
242
/* Need cast cause of GConf api bug */
245
eel_gconf_handle_error (&error);
249
eel_gconf_get_string_list (const char *key)
255
g_return_val_if_fail (key != NULL, NULL);
257
client = eel_gconf_client_get_global ();
258
g_return_val_if_fail (client != NULL, NULL);
261
slist = gconf_client_get_list (client, key, GCONF_VALUE_STRING, &error);
262
if (eel_gconf_handle_error (&error)) {
269
/* This code wasn't part of the original eel-gconf-extensions.c */
271
eel_gconf_set_integer_list (const char *key,
277
g_return_if_fail (key != NULL);
279
client = eel_gconf_client_get_global ();
280
g_return_if_fail (client != NULL);
283
gconf_client_set_list (client, key, GCONF_VALUE_INT,
284
/* Need cast cause of GConf api bug */
287
eel_gconf_handle_error (&error);
291
eel_gconf_get_integer_list (const char *key)
297
g_return_val_if_fail (key != NULL, NULL);
299
client = eel_gconf_client_get_global ();
300
g_return_val_if_fail (client != NULL, NULL);
303
slist = gconf_client_get_list (client, key, GCONF_VALUE_INT, &error);
304
if (eel_gconf_handle_error (&error)) {
310
/* End of added code */
313
eel_gconf_is_default (const char *key)
317
GError *error = NULL;
319
g_return_val_if_fail (key != NULL, FALSE);
321
value = gconf_client_get_without_default (eel_gconf_client_get_global (), key, &error);
323
if (eel_gconf_handle_error (&error)) {
325
gconf_value_free (value);
330
result = (value == NULL);
333
gconf_value_free (value);
341
eel_gconf_unset (const char *key)
344
GError *error = NULL;
346
g_return_if_fail (key != NULL);
348
client = eel_gconf_client_get_global ();
349
g_return_if_fail (client != NULL);
351
gconf_client_unset (client, key, &error);
352
eel_gconf_handle_error (&error);
356
eel_gconf_monitor_add (const char *directory)
358
GError *error = NULL;
361
g_return_val_if_fail (directory != NULL, FALSE);
363
client = eel_gconf_client_get_global ();
364
g_return_val_if_fail (client != NULL, FALSE);
366
gconf_client_add_dir (client,
368
GCONF_CLIENT_PRELOAD_NONE,
371
if (eel_gconf_handle_error (&error)) {
379
eel_gconf_monitor_remove (const char *directory)
381
GError *error = NULL;
384
if (directory == NULL) {
388
client = eel_gconf_client_get_global ();
389
g_return_val_if_fail (client != NULL, FALSE);
391
gconf_client_remove_dir (client,
395
if (eel_gconf_handle_error (&error)) {
403
eel_gconf_suggest_sync (void)
406
GError *error = NULL;
408
client = eel_gconf_client_get_global ();
409
g_return_if_fail (client != NULL);
411
gconf_client_suggest_sync (client, &error);
412
eel_gconf_handle_error (&error);
416
eel_gconf_get_value (const char *key)
418
GConfValue *value = NULL;
420
GError *error = NULL;
422
g_return_val_if_fail (key != NULL, NULL);
424
client = eel_gconf_client_get_global ();
425
g_return_val_if_fail (client != NULL, NULL);
427
value = gconf_client_get (client, key, &error);
429
if (eel_gconf_handle_error (&error)) {
431
gconf_value_free (value);
440
eel_gconf_set_value (const char *key, GConfValue *value)
443
GError *error = NULL;
445
g_return_if_fail (key != NULL);
447
client = eel_gconf_client_get_global ();
448
g_return_if_fail (client != NULL);
450
gconf_client_set (client, key, value, &error);
452
if (eel_gconf_handle_error (&error)) {
458
eel_gconf_value_free (GConfValue *value)
464
gconf_value_free (value);
468
eel_gconf_notification_add (const char *key,
469
GConfClientNotifyFunc notification_callback,
470
gpointer callback_data)
472
guint notification_id;
474
GError *error = NULL;
476
g_return_val_if_fail (key != NULL, EEL_GCONF_UNDEFINED_CONNECTION);
477
g_return_val_if_fail (notification_callback != NULL, EEL_GCONF_UNDEFINED_CONNECTION);
479
client = eel_gconf_client_get_global ();
480
g_return_val_if_fail (client != NULL, EEL_GCONF_UNDEFINED_CONNECTION);
482
notification_id = gconf_client_notify_add (client,
484
notification_callback,
489
if (eel_gconf_handle_error (&error)) {
490
if (notification_id != EEL_GCONF_UNDEFINED_CONNECTION) {
491
gconf_client_notify_remove (client, notification_id);
492
notification_id = EEL_GCONF_UNDEFINED_CONNECTION;
496
return notification_id;
500
eel_gconf_notification_remove (guint notification_id)
504
if (notification_id == EEL_GCONF_UNDEFINED_CONNECTION) {
508
client = eel_gconf_client_get_global ();
509
g_return_if_fail (client != NULL);
511
gconf_client_notify_remove (client, notification_id);