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 (_("GConf error:\n %s"), (*error)->message);
68
g_error_free (*error);
78
eel_gconf_set_boolean (const char *key,
79
gboolean boolean_value)
84
g_return_if_fail (key != NULL);
86
client = eel_gconf_client_get_global ();
87
g_return_if_fail (client != NULL);
89
gconf_client_set_bool (client, key, boolean_value, &error);
90
eel_gconf_handle_error (&error);
94
eel_gconf_get_boolean (const char *key)
100
g_return_val_if_fail (key != NULL, FALSE);
102
client = eel_gconf_client_get_global ();
103
g_return_val_if_fail (client != NULL, FALSE);
105
result = gconf_client_get_bool (client, key, &error);
107
if (eel_gconf_handle_error (&error)) {
115
eel_gconf_set_integer (const char *key,
119
GError *error = NULL;
121
g_return_if_fail (key != NULL);
123
client = eel_gconf_client_get_global ();
124
g_return_if_fail (client != NULL);
126
gconf_client_set_int (client, key, int_value, &error);
127
eel_gconf_handle_error (&error);
131
eel_gconf_get_integer (const char *key)
135
GError *error = NULL;
137
g_return_val_if_fail (key != NULL, 0);
139
client = eel_gconf_client_get_global ();
140
g_return_val_if_fail (client != NULL, 0);
142
result = gconf_client_get_int (client, key, &error);
144
if (eel_gconf_handle_error (&error)) {
152
eel_gconf_set_float (const char *key,
156
GError *error = NULL;
158
g_return_if_fail (key != NULL);
160
client = eel_gconf_client_get_global ();
161
g_return_if_fail (client != NULL);
163
gconf_client_set_float (client, key, float_value, &error);
164
eel_gconf_handle_error (&error);
168
eel_gconf_get_float (const char *key)
172
GError *error = NULL;
174
g_return_val_if_fail (key != NULL, 0);
176
client = eel_gconf_client_get_global ();
177
g_return_val_if_fail (client != NULL, 0);
179
result = gconf_client_get_float (client, key, &error);
181
if (eel_gconf_handle_error (&error)) {
189
eel_gconf_set_string (const char *key,
190
const char *string_value)
193
GError *error = NULL;
195
g_return_if_fail (key != NULL);
196
g_return_if_fail (string_value != NULL);
198
client = eel_gconf_client_get_global ();
199
g_return_if_fail (client != NULL);
201
gconf_client_set_string (client, key, string_value, &error);
202
eel_gconf_handle_error (&error);
206
eel_gconf_get_string (const char *key)
210
GError *error = NULL;
212
g_return_val_if_fail (key != NULL, NULL);
214
client = eel_gconf_client_get_global ();
215
g_return_val_if_fail (client != NULL, NULL);
217
result = gconf_client_get_string (client, key, &error);
219
if (eel_gconf_handle_error (&error)) {
220
result = g_strdup ("");
227
eel_gconf_set_string_list (const char *key,
233
g_return_if_fail (key != NULL);
235
client = eel_gconf_client_get_global ();
236
g_return_if_fail (client != NULL);
239
gconf_client_set_list (client, key, GCONF_VALUE_STRING,
240
/* Need cast cause of GConf api bug */
243
eel_gconf_handle_error (&error);
247
eel_gconf_get_string_list (const char *key)
253
g_return_val_if_fail (key != NULL, NULL);
255
client = eel_gconf_client_get_global ();
256
g_return_val_if_fail (client != NULL, NULL);
259
slist = gconf_client_get_list (client, key, GCONF_VALUE_STRING, &error);
260
if (eel_gconf_handle_error (&error)) {
267
/* This code wasn't part of the original eel-gconf-extensions.c */
269
eel_gconf_set_integer_list (const char *key,
275
g_return_if_fail (key != NULL);
277
client = eel_gconf_client_get_global ();
278
g_return_if_fail (client != NULL);
281
gconf_client_set_list (client, key, GCONF_VALUE_INT,
282
/* Need cast cause of GConf api bug */
285
eel_gconf_handle_error (&error);
289
eel_gconf_get_integer_list (const char *key)
295
g_return_val_if_fail (key != NULL, NULL);
297
client = eel_gconf_client_get_global ();
298
g_return_val_if_fail (client != NULL, NULL);
301
slist = gconf_client_get_list (client, key, GCONF_VALUE_INT, &error);
302
if (eel_gconf_handle_error (&error)) {
308
/* End of added code */
311
eel_gconf_is_default (const char *key)
315
GError *error = NULL;
317
g_return_val_if_fail (key != NULL, FALSE);
319
value = gconf_client_get_without_default (eel_gconf_client_get_global (), key, &error);
321
if (eel_gconf_handle_error (&error)) {
323
gconf_value_free (value);
328
result = (value == NULL);
331
gconf_value_free (value);
339
eel_gconf_unset (const char *key)
342
GError *error = NULL;
344
g_return_if_fail (key != NULL);
346
client = eel_gconf_client_get_global ();
347
g_return_if_fail (client != NULL);
349
gconf_client_unset (client, key, &error);
350
eel_gconf_handle_error (&error);
354
eel_gconf_monitor_add (const char *directory)
356
GError *error = NULL;
359
g_return_val_if_fail (directory != NULL, FALSE);
361
client = eel_gconf_client_get_global ();
362
g_return_val_if_fail (client != NULL, FALSE);
364
gconf_client_add_dir (client,
366
GCONF_CLIENT_PRELOAD_NONE,
369
if (eel_gconf_handle_error (&error)) {
377
eel_gconf_monitor_remove (const char *directory)
379
GError *error = NULL;
382
if (directory == NULL) {
386
client = eel_gconf_client_get_global ();
387
g_return_val_if_fail (client != NULL, FALSE);
389
gconf_client_remove_dir (client,
393
if (eel_gconf_handle_error (&error)) {
401
eel_gconf_suggest_sync (void)
404
GError *error = NULL;
406
client = eel_gconf_client_get_global ();
407
g_return_if_fail (client != NULL);
409
gconf_client_suggest_sync (client, &error);
410
eel_gconf_handle_error (&error);
414
eel_gconf_get_value (const char *key)
416
GConfValue *value = NULL;
418
GError *error = NULL;
420
g_return_val_if_fail (key != NULL, NULL);
422
client = eel_gconf_client_get_global ();
423
g_return_val_if_fail (client != NULL, NULL);
425
value = gconf_client_get (client, key, &error);
427
if (eel_gconf_handle_error (&error)) {
429
gconf_value_free (value);
438
eel_gconf_set_value (const char *key, GConfValue *value)
441
GError *error = NULL;
443
g_return_if_fail (key != NULL);
445
client = eel_gconf_client_get_global ();
446
g_return_if_fail (client != NULL);
448
gconf_client_set (client, key, value, &error);
450
if (eel_gconf_handle_error (&error)) {
456
eel_gconf_value_free (GConfValue *value)
462
gconf_value_free (value);
466
eel_gconf_notification_add (const char *key,
467
GConfClientNotifyFunc notification_callback,
468
gpointer callback_data)
470
guint notification_id;
472
GError *error = NULL;
474
g_return_val_if_fail (key != NULL, EEL_GCONF_UNDEFINED_CONNECTION);
475
g_return_val_if_fail (notification_callback != NULL, EEL_GCONF_UNDEFINED_CONNECTION);
477
client = eel_gconf_client_get_global ();
478
g_return_val_if_fail (client != NULL, EEL_GCONF_UNDEFINED_CONNECTION);
480
notification_id = gconf_client_notify_add (client,
482
notification_callback,
487
if (eel_gconf_handle_error (&error)) {
488
if (notification_id != EEL_GCONF_UNDEFINED_CONNECTION) {
489
gconf_client_notify_remove (client, notification_id);
490
notification_id = EEL_GCONF_UNDEFINED_CONNECTION;
494
return notification_id;
498
eel_gconf_notification_remove (guint notification_id)
502
if (notification_id == EEL_GCONF_UNDEFINED_CONNECTION) {
506
client = eel_gconf_client_get_global ();
507
g_return_if_fail (client != NULL);
509
gconf_client_notify_remove (client, notification_id);