~noskcaj/ubuntu/trusty/ekiga/ftbfs

« back to all changes in this revision

Viewing changes to lib/gmconf/gmconf-gconf.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2006-01-28 18:49:20 UTC
  • Revision ID: james.westby@ubuntu.com-20060128184920-v525ihmiv7id40xs
Tags: upstream-1.99.0
ImportĀ upstreamĀ versionĀ 1.99.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/* GnomeMeeting -- A Video-Conferencing application
 
3
 * Copyright (C) 2000-2006 Damien Sandras
 
4
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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.
 
18
 *
 
19
 *
 
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.
 
26
 */
 
27
 
 
28
 
 
29
/*
 
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
 
38
 *
 
39
 */
 
40
 
 
41
 
 
42
#include "../../config.h"
 
43
 
 
44
#include <gtk/gtk.h>
 
45
#include <gconf/gconf-client.h>
 
46
 
 
47
#include <string.h>
 
48
 
 
49
#ifndef DISABLE_GNOME
 
50
#include <gnome.h>
 
51
#endif
 
52
 
 
53
#include "gmconf.h"
 
54
 
 
55
 
 
56
#ifndef _
 
57
#ifdef DISABLE_GNOME
 
58
#include <libintl.h>
 
59
#define _(x) gettext(x)
 
60
#ifdef gettext_noop
 
61
#define N_(String) gettext_noop (String)
 
62
#else
 
63
#define N_(String) (String)
 
64
#endif
 
65
#endif
 
66
#endif
 
67
 
 
68
 
 
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;
 
74
 
 
75
struct _GConfNotifierWrap {  
 
76
  GmConfNotifier real_notifier;
 
77
  gpointer real_user_data;
 
78
};
 
79
 
 
80
static GConfNotifierWrap *gconf_notifier_wrapper_new (GmConfNotifier, 
 
81
                                                      gpointer);
 
82
 
 
83
/* gpointer, because it is a callback */
 
84
static void gconf_notifier_wrapper_destroy (gpointer);
 
85
 
 
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 *,
 
89
                                            guint,
 
90
                                            GConfEntry *,
 
91
                                            gpointer);
 
92
 
 
93
 
 
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 *,
 
97
                                  GError *);
 
98
 
 
99
 
 
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, 
 
104
                            gpointer user_data)
 
105
{
 
106
  GConfNotifierWrap *result = NULL;
 
107
  
 
108
  g_return_val_if_fail (notifier != NULL, NULL);
 
109
 
 
110
  result = g_new (GConfNotifierWrap, 1);
 
111
  result->real_notifier = notifier;
 
112
  result->real_user_data = user_data;
 
113
 
 
114
  return result;
 
115
}
 
116
 
 
117
/* this function is automatically called to free the notifiers' wrappers */
 
118
static void
 
119
gconf_notifier_wrapper_destroy (gpointer wrapper)
 
120
{
 
121
  g_free ((GConfNotifierWrap *) wrapper);
 
122
}
 
123
 
 
124
 
 
125
/* this is the universal gconf notification unwrapper: it
 
126
 * expects a wrapped gm conf notifier in its user_data argument,
 
127
 * and calls it  */
 
128
static void        
 
129
gconf_notifier_wrapper_trigger (GConfClient *client,
 
130
                                guint identifier,
 
131
                                GConfEntry *entry,
 
132
                                gpointer user_data)
 
133
{
 
134
  GConfNotifierWrap *wrapper = NULL;
 
135
 
 
136
  g_return_if_fail (user_data != NULL);
 
137
 
 
138
  wrapper = (GConfNotifierWrap *)user_data;
 
139
  wrapper->real_notifier (GUINT_TO_POINTER (identifier),
 
140
                          (GmConfEntry *)entry,
 
141
                          wrapper->real_user_data);
 
142
}
 
143
 
 
144
 
 
145
/* this is where we take care of error reporting from gconf */
 
146
static void
 
147
gconf_error_callback (GConfClient *client,
 
148
                      GError *err)
 
149
{
 
150
  GtkWidget *dialog = NULL;
 
151
  
 
152
  dialog =
 
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"
 
158
                              " be saved."));
 
159
 
 
160
  gtk_dialog_run (GTK_DIALOG (dialog));
 
161
  gtk_widget_destroy (dialog);
 
162
}
 
163
 
 
164
 
 
165
/* From now on, the rest is just calling the gconf functions,
 
166
 * just checking for the key's validity */
 
167
void
 
168
gm_conf_set_bool (const gchar *key,
 
169
                  const gboolean b)
 
170
{
 
171
  GConfClient *client = NULL;
 
172
 
 
173
  g_return_if_fail (key != NULL);
 
174
 
 
175
  client = gconf_client_get_default ();
 
176
  gconf_client_set_bool (client, key, b, NULL);
 
177
}
 
178
 
 
179
 
 
180
gboolean
 
181
gm_conf_get_bool (const gchar *key)
 
182
{
 
183
  GConfClient *client = NULL;
 
184
 
 
185
  g_return_val_if_fail (key != NULL, FALSE);
 
186
 
 
187
  client = gconf_client_get_default ();
 
188
  return gconf_client_get_bool (client, key, NULL);
 
189
}
 
190
 
 
191
 
 
192
void
 
193
gm_conf_set_string (const gchar *key,
 
194
                    const gchar *v)
 
195
{
 
196
  GConfClient *client = NULL;
 
197
 
 
198
  g_return_if_fail (key != NULL);
 
199
 
 
200
  client = gconf_client_get_default ();
 
201
  gconf_client_set_string (client, key, v, NULL);
 
202
}
 
203
 
 
204
 
 
205
gchar *
 
206
gm_conf_get_string (const gchar *key)
 
207
{
 
208
  GConfClient *client = NULL;
 
209
 
 
210
  g_return_val_if_fail (key != NULL, NULL);
 
211
 
 
212
  client = gconf_client_get_default ();
 
213
  return gconf_client_get_string (client, key, NULL);
 
214
}
 
215
 
 
216
 
 
217
void
 
218
gm_conf_set_int (const gchar *key,
 
219
                 const int v)
 
220
{
 
221
  GConfClient *client = NULL;
 
222
 
 
223
  g_return_if_fail (key != NULL);
 
224
 
 
225
  client = gconf_client_get_default ();
 
226
  gconf_client_set_int (client, key, v, NULL);
 
227
}
 
228
 
 
229
 
 
230
int
 
231
gm_conf_get_int (const gchar *key)
 
232
{
 
233
  GConfClient *client = NULL;
 
234
 
 
235
  g_return_val_if_fail (key != NULL, 0);
 
236
 
 
237
  client = gconf_client_get_default ();
 
238
  return gconf_client_get_int (client, key, NULL);
 
239
}
 
240
 
 
241
 
 
242
void
 
243
gm_conf_set_float (const gchar *key,
 
244
                   const float v)
 
245
{
 
246
  GConfClient *client = NULL;
 
247
 
 
248
  g_return_if_fail (key != NULL);
 
249
 
 
250
  client = gconf_client_get_default ();
 
251
  gconf_client_set_float (client, key, v, NULL);
 
252
}
 
253
 
 
254
 
 
255
gfloat
 
256
gm_conf_get_float (const gchar *key)
 
257
{
 
258
  GConfClient *client = NULL;
 
259
 
 
260
  g_return_val_if_fail (key != NULL, (float)0);
 
261
 
 
262
  client = gconf_client_get_default ();
 
263
  return gconf_client_get_float (client, key, NULL);
 
264
}
 
265
 
 
266
 
 
267
void
 
268
gm_conf_set_string_list (const gchar *key,
 
269
                         GSList *l)
 
270
{
 
271
  GConfClient *client = NULL;
 
272
 
 
273
  g_return_if_fail (key != NULL);
 
274
 
 
275
  client = gconf_client_get_default ();
 
276
  gconf_client_set_list (client, key, GCONF_VALUE_STRING, l, NULL);
 
277
}
 
278
 
 
279
 
 
280
GSList *
 
281
gm_conf_get_string_list (const gchar *key)
 
282
{
 
283
  GConfClient *client = NULL;
 
284
 
 
285
  g_return_val_if_fail (key != NULL, NULL);
 
286
 
 
287
  client = gconf_client_get_default ();
 
288
  return gconf_client_get_list (client, key, GCONF_VALUE_STRING, NULL);
 
289
}
 
290
 
 
291
 
 
292
gchar *
 
293
gm_conf_escape_key (gchar *key, 
 
294
                    gint len)
 
295
{
 
296
  return gconf_escape_key (key, len);
 
297
}
 
298
 
 
299
 
 
300
gchar *
 
301
gm_conf_unescape_key (gchar *key, 
 
302
                      gint len)
 
303
{
 
304
  return gconf_unescape_key (key, len);
 
305
}
 
306
 
 
307
 
 
308
gboolean
 
309
gm_conf_is_key_writable (gchar *key)
 
310
{
 
311
  GConfClient *client = NULL;
 
312
 
 
313
  g_return_val_if_fail (key != NULL, FALSE);
 
314
 
 
315
  client = gconf_client_get_default ();
 
316
  return gconf_client_key_is_writable (client, key, NULL);
 
317
}
 
318
 
 
319
 
 
320
void
 
321
gm_conf_init (int argc, 
 
322
              char **argv)
 
323
{
 
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);
 
328
}
 
329
 
 
330
 
 
331
void
 
332
gm_conf_save ()
 
333
{
 
334
  /* nothing needed */
 
335
}
 
336
 
 
337
 
 
338
GmConfEntryType
 
339
gm_conf_entry_get_type (GmConfEntry *entry)
 
340
{
 
341
  GConfEntry *gconf_entry = NULL;
 
342
 
 
343
  g_return_val_if_fail (entry != NULL, GM_CONF_OTHER);
 
344
 
 
345
  gconf_entry = (GConfEntry *)entry;
 
346
  switch (gconf_entry->value->type)
 
347
    {
 
348
    case GCONF_VALUE_BOOL:
 
349
      return GM_CONF_BOOL;
 
350
    case GCONF_VALUE_INT:
 
351
      return GM_CONF_INT;
 
352
    case GCONF_VALUE_STRING:
 
353
      return GM_CONF_STRING;
 
354
    case GCONF_VALUE_LIST:
 
355
      return GM_CONF_LIST;
 
356
    default:
 
357
      return GM_CONF_OTHER;
 
358
    }
 
359
}
 
360
 
 
361
 
 
362
const gchar *
 
363
gm_conf_entry_get_key (GmConfEntry *entry)
 
364
{
 
365
  GConfEntry *gconf_entry = NULL;
 
366
 
 
367
  g_return_val_if_fail (entry != NULL, NULL);
 
368
 
 
369
  gconf_entry = (GConfEntry *)entry;
 
370
  return gconf_entry_get_key (gconf_entry);
 
371
}
 
372
 
 
373
 
 
374
gboolean
 
375
gm_conf_entry_get_bool (GmConfEntry *entry)
 
376
{
 
377
  GConfEntry *gconf_entry = NULL;
 
378
 
 
379
  g_return_val_if_fail (entry != NULL, FALSE);
 
380
 
 
381
  gconf_entry = (GConfEntry *)entry;
 
382
  return gconf_value_get_bool (gconf_entry->value);
 
383
}
 
384
 
 
385
 
 
386
gint
 
387
gm_conf_entry_get_int (GmConfEntry *entry)
 
388
{
 
389
  GConfEntry *gconf_entry = NULL;
 
390
 
 
391
  g_return_val_if_fail (entry != NULL, 0);
 
392
 
 
393
  gconf_entry = (GConfEntry *)entry;
 
394
  return gconf_value_get_int (gconf_entry->value);
 
395
}
 
396
 
 
397
 
 
398
const gchar *
 
399
gm_conf_entry_get_string (GmConfEntry *entry)
 
400
{
 
401
  GConfEntry *gconf_entry = NULL;
 
402
 
 
403
  g_return_val_if_fail (entry != NULL, NULL);
 
404
 
 
405
  gconf_entry = (GConfEntry *)entry;
 
406
  return gconf_value_get_string (gconf_entry->value);
 
407
}
 
408
 
 
409
 
 
410
const GSList *
 
411
gm_conf_entry_get_list (GmConfEntry *entry)
 
412
{
 
413
  GConfEntry *gconf_entry = NULL;
 
414
 
 
415
  g_return_val_if_fail (entry != NULL, NULL);
 
416
 
 
417
  gconf_entry = (GConfEntry *)entry;
 
418
  return gconf_value_get_list (gconf_entry->value);
 
419
}
 
420
 
 
421
 
 
422
gpointer
 
423
gm_conf_notifier_add (const gchar *namespac, 
 
424
                      GmConfNotifier func,
 
425
                      gpointer user_data)
 
426
{
 
427
  GConfClient *client = NULL;
 
428
  GConfNotifierWrap *wrapper = NULL;
 
429
 
 
430
  g_return_val_if_fail (namespac != NULL, NULL);
 
431
  g_return_val_if_fail (func != NULL, NULL);
 
432
  
 
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,
 
437
                                                   wrapper,
 
438
                                                   gconf_notifier_wrapper_destroy, NULL));
 
439
}
 
440
 
 
441
 
 
442
void 
 
443
gm_conf_notifier_remove (gpointer identifier)
 
444
{
 
445
  GConfClient *client = NULL;
 
446
 
 
447
  g_return_if_fail (identifier != NULL);
 
448
 
 
449
  client = gconf_client_get_default ();  
 
450
  gconf_client_notify_remove (client, GPOINTER_TO_UINT (identifier));
 
451
}
 
452
 
 
453
void
 
454
gm_conf_notifier_trigger (const gchar *namespac)
 
455
{
 
456
  GConfClient *client = NULL;
 
457
 
 
458
  g_return_if_fail (namespac != NULL);
 
459
 
 
460
  client = gconf_client_get_default ();  
 
461
  gconf_client_notify (client, namespac);
 
462
}
 
463
 
 
464
void
 
465
gm_conf_watch ()
 
466
{
 
467
  GConfClient *client = NULL;
 
468
 
 
469
  client = gconf_client_get_default ();  
 
470
  gconf_client_add_dir (client, "/apps/" PACKAGE_NAME,
 
471
                        GCONF_CLIENT_PRELOAD_NONE, NULL);
 
472
}
 
473
 
 
474
 
 
475
void 
 
476
gm_conf_unwatch ()
 
477
{
 
478
  GConfClient *client = NULL;
 
479
 
 
480
  client = gconf_client_get_default ();  
 
481
  gconf_client_remove_dir (client, "/apps/" PACKAGE_NAME, NULL);
 
482
}
 
483
 
 
484
 
 
485
void 
 
486
gm_conf_destroy (const gchar *namespac)
 
487
{
 
488
  GConfClient *client = NULL;
 
489
 
 
490
  g_return_if_fail (namespac != NULL);
 
491
 
 
492
  client = gconf_client_get_default ();  
 
493
  gconf_client_unset (client, namespac, NULL);
 
494
}
 
495