2
/* GnomeMeeting -- A Video-Conferencing application
3
* Copyright (C) 2000-2006 Damien Sandras
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
* GnomeMeting is licensed under the GPL license and as a special exception,
21
* you have permission to link or otherwise combine this program with the
22
* programs OpenH323 and Pwlib, and distribute the combination, without
23
* applying the requirements of the GNU GPL to the OpenH323 program, as long
24
* as you do follow the requirements of the GNU GPL for all the rest of the
25
* software thus combined.
30
* gmconf-gconf.c - description
31
* ------------------------------------------
32
* begin : Mar 2004, derived from gconf_widgets_extensions.c
33
* started on Fri Oct 17 2003.
34
* copyright : (c) 2000-2006 by Damien sandras,
35
* (c) 2004 by Julien Puydt
36
* description : gconf implementation of gnomemeeting's
37
* configuration system
42
#include "../../config.h"
45
#include <gconf/gconf-client.h>
59
#define _(x) gettext(x)
61
#define N_(String) gettext_noop (String)
63
#define N_(String) (String)
69
/* this is needed in order to really hide gconf: one needs to be able to
70
* call the GmConfNotifier from inside a gconf notifier, so we hide the real
71
* notifier and its associated user data into the user data of a gconf
72
* notifier, that will do the unwrapping, and call the real stuff */
73
typedef struct _GConfNotifierWrap GConfNotifierWrap;
75
struct _GConfNotifierWrap {
76
GmConfNotifier real_notifier;
77
gpointer real_user_data;
80
static GConfNotifierWrap *gconf_notifier_wrapper_new (GmConfNotifier,
83
/* gpointer, because it is a callback */
84
static void gconf_notifier_wrapper_destroy (gpointer);
86
/* this is the universal gconf notifier, that interprets its fourth
87
* argument as a GConfNotifierWrap*, and fires it */
88
static void gconf_notifier_wrapper_trigger (GConfClient *,
94
/* this function is called whenever an error occurs in gconf: it allows
95
* to use NULL as error callback in every other call */
96
static void gconf_error_callback (GConfClient *,
100
/* this functions expects a non-NULL conf notifier, and wraps it for
101
* use by the universal gconf notifier */
102
static GConfNotifierWrap *
103
gconf_notifier_wrapper_new (GmConfNotifier notifier,
106
GConfNotifierWrap *result = NULL;
108
g_return_val_if_fail (notifier != NULL, NULL);
110
result = g_new (GConfNotifierWrap, 1);
111
result->real_notifier = notifier;
112
result->real_user_data = user_data;
117
/* this function is automatically called to free the notifiers' wrappers */
119
gconf_notifier_wrapper_destroy (gpointer wrapper)
121
g_free ((GConfNotifierWrap *) wrapper);
125
/* this is the universal gconf notification unwrapper: it
126
* expects a wrapped gm conf notifier in its user_data argument,
129
gconf_notifier_wrapper_trigger (GConfClient *client,
134
GConfNotifierWrap *wrapper = NULL;
136
g_return_if_fail (user_data != NULL);
138
wrapper = (GConfNotifierWrap *)user_data;
139
wrapper->real_notifier (GUINT_TO_POINTER (identifier),
140
(GmConfEntry *)entry,
141
wrapper->real_user_data);
145
/* this is where we take care of error reporting from gconf */
147
gconf_error_callback (GConfClient *client,
150
GtkWidget *dialog = NULL;
153
gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL,
154
GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
155
_("An error has happened in the"
156
" configuration backend.\n"
157
"Maybe some of your settings won't"
160
gtk_dialog_run (GTK_DIALOG (dialog));
161
gtk_widget_destroy (dialog);
165
/* From now on, the rest is just calling the gconf functions,
166
* just checking for the key's validity */
168
gm_conf_set_bool (const gchar *key,
171
GConfClient *client = NULL;
173
g_return_if_fail (key != NULL);
175
client = gconf_client_get_default ();
176
gconf_client_set_bool (client, key, b, NULL);
181
gm_conf_get_bool (const gchar *key)
183
GConfClient *client = NULL;
185
g_return_val_if_fail (key != NULL, FALSE);
187
client = gconf_client_get_default ();
188
return gconf_client_get_bool (client, key, NULL);
193
gm_conf_set_string (const gchar *key,
196
GConfClient *client = NULL;
198
g_return_if_fail (key != NULL);
200
client = gconf_client_get_default ();
201
gconf_client_set_string (client, key, v, NULL);
206
gm_conf_get_string (const gchar *key)
208
GConfClient *client = NULL;
210
g_return_val_if_fail (key != NULL, NULL);
212
client = gconf_client_get_default ();
213
return gconf_client_get_string (client, key, NULL);
218
gm_conf_set_int (const gchar *key,
221
GConfClient *client = NULL;
223
g_return_if_fail (key != NULL);
225
client = gconf_client_get_default ();
226
gconf_client_set_int (client, key, v, NULL);
231
gm_conf_get_int (const gchar *key)
233
GConfClient *client = NULL;
235
g_return_val_if_fail (key != NULL, 0);
237
client = gconf_client_get_default ();
238
return gconf_client_get_int (client, key, NULL);
243
gm_conf_set_float (const gchar *key,
246
GConfClient *client = NULL;
248
g_return_if_fail (key != NULL);
250
client = gconf_client_get_default ();
251
gconf_client_set_float (client, key, v, NULL);
256
gm_conf_get_float (const gchar *key)
258
GConfClient *client = NULL;
260
g_return_val_if_fail (key != NULL, (float)0);
262
client = gconf_client_get_default ();
263
return gconf_client_get_float (client, key, NULL);
268
gm_conf_set_string_list (const gchar *key,
271
GConfClient *client = NULL;
273
g_return_if_fail (key != NULL);
275
client = gconf_client_get_default ();
276
gconf_client_set_list (client, key, GCONF_VALUE_STRING, l, NULL);
281
gm_conf_get_string_list (const gchar *key)
283
GConfClient *client = NULL;
285
g_return_val_if_fail (key != NULL, NULL);
287
client = gconf_client_get_default ();
288
return gconf_client_get_list (client, key, GCONF_VALUE_STRING, NULL);
293
gm_conf_escape_key (gchar *key,
296
return gconf_escape_key (key, len);
301
gm_conf_unescape_key (gchar *key,
304
return gconf_unescape_key (key, len);
309
gm_conf_is_key_writable (gchar *key)
311
GConfClient *client = NULL;
313
g_return_val_if_fail (key != NULL, FALSE);
315
client = gconf_client_get_default ();
316
return gconf_client_key_is_writable (client, key, NULL);
321
gm_conf_init (int argc,
324
gconf_init (argc, argv, 0);
325
gconf_client_set_error_handling (gconf_client_get_default (),
326
GCONF_CLIENT_HANDLE_UNRETURNED);
327
gconf_client_set_global_default_error_handler (gconf_error_callback);
339
gm_conf_entry_get_type (GmConfEntry *entry)
341
GConfEntry *gconf_entry = NULL;
343
g_return_val_if_fail (entry != NULL, GM_CONF_OTHER);
345
gconf_entry = (GConfEntry *)entry;
346
switch (gconf_entry->value->type)
348
case GCONF_VALUE_BOOL:
350
case GCONF_VALUE_INT:
352
case GCONF_VALUE_STRING:
353
return GM_CONF_STRING;
354
case GCONF_VALUE_LIST:
357
return GM_CONF_OTHER;
363
gm_conf_entry_get_key (GmConfEntry *entry)
365
GConfEntry *gconf_entry = NULL;
367
g_return_val_if_fail (entry != NULL, NULL);
369
gconf_entry = (GConfEntry *)entry;
370
return gconf_entry_get_key (gconf_entry);
375
gm_conf_entry_get_bool (GmConfEntry *entry)
377
GConfEntry *gconf_entry = NULL;
379
g_return_val_if_fail (entry != NULL, FALSE);
381
gconf_entry = (GConfEntry *)entry;
382
return gconf_value_get_bool (gconf_entry->value);
387
gm_conf_entry_get_int (GmConfEntry *entry)
389
GConfEntry *gconf_entry = NULL;
391
g_return_val_if_fail (entry != NULL, 0);
393
gconf_entry = (GConfEntry *)entry;
394
return gconf_value_get_int (gconf_entry->value);
399
gm_conf_entry_get_string (GmConfEntry *entry)
401
GConfEntry *gconf_entry = NULL;
403
g_return_val_if_fail (entry != NULL, NULL);
405
gconf_entry = (GConfEntry *)entry;
406
return gconf_value_get_string (gconf_entry->value);
411
gm_conf_entry_get_list (GmConfEntry *entry)
413
GConfEntry *gconf_entry = NULL;
415
g_return_val_if_fail (entry != NULL, NULL);
417
gconf_entry = (GConfEntry *)entry;
418
return gconf_value_get_list (gconf_entry->value);
423
gm_conf_notifier_add (const gchar *namespac,
427
GConfClient *client = NULL;
428
GConfNotifierWrap *wrapper = NULL;
430
g_return_val_if_fail (namespac != NULL, NULL);
431
g_return_val_if_fail (func != NULL, NULL);
433
client = gconf_client_get_default ();
434
wrapper = gconf_notifier_wrapper_new (func, user_data);
435
return GUINT_TO_POINTER(gconf_client_notify_add (client, namespac,
436
gconf_notifier_wrapper_trigger,
438
gconf_notifier_wrapper_destroy, NULL));
443
gm_conf_notifier_remove (gpointer identifier)
445
GConfClient *client = NULL;
447
g_return_if_fail (identifier != NULL);
449
client = gconf_client_get_default ();
450
gconf_client_notify_remove (client, GPOINTER_TO_UINT (identifier));
454
gm_conf_notifier_trigger (const gchar *namespac)
456
GConfClient *client = NULL;
458
g_return_if_fail (namespac != NULL);
460
client = gconf_client_get_default ();
461
gconf_client_notify (client, namespac);
467
GConfClient *client = NULL;
469
client = gconf_client_get_default ();
470
gconf_client_add_dir (client, "/apps/" PACKAGE_NAME,
471
GCONF_CLIENT_PRELOAD_NONE, NULL);
478
GConfClient *client = NULL;
480
client = gconf_client_get_default ();
481
gconf_client_remove_dir (client, "/apps/" PACKAGE_NAME, NULL);
486
gm_conf_destroy (const gchar *namespac)
488
GConfClient *client = NULL;
490
g_return_if_fail (namespac != NULL);
492
client = gconf_client_get_default ();
493
gconf_client_unset (client, namespac, NULL);