~ubuntu-branches/ubuntu/precise/sflphone/precise

« back to all changes in this revision

Viewing changes to .pc/05_glib_includes.patch/gnome/src/eel-gconf-extensions.c

  • Committer: Package Import Robot
  • Author(s): Whoopie
  • Date: 2012-03-22 10:29:10 UTC
  • mfrom: (4.1.12 sid)
  • Revision ID: package-import@ubuntu.com-20120322102910-tb8hugi2su1tguwh
Tags: 1.0.2-1ubuntu1
* Apply some upstream patches to fix FTBFS (LP: #913018):
  - debian/patches/05_glib_includes.patch: fix glib includes.
  - debian/patches/06_use_XkbKeycodeToKeysym.patch: use 
    XkbKeycodeToKeysym instead of (deprecated) XKeycodeToKeysym.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
 
2
 
 
3
/* eel-gconf-extensions.c - Stuff to make GConf easier to use.
 
4
 
 
5
   Copyright (C) 2000, 2001 Eazel, Inc.
 
6
 
 
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.
 
11
 
 
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.
 
16
 
 
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.
 
21
 
 
22
   Authors: Ramiro Estrugo <ramiro@eazel.com>
 
23
*/
 
24
 
 
25
#include <stdlib.h>
 
26
#include "config.h"
 
27
#include "eel-gconf-extensions.h"
 
28
 
 
29
#include <gconf/gconf-client.h>
 
30
#include <gconf/gconf.h>
 
31
#include <gtk/gtk.h>
 
32
#include <glib/gi18n.h>
 
33
 
 
34
static GConfClient *global_gconf_client = NULL;
 
35
 
 
36
static void
 
37
global_client_free(void)
 
38
{
 
39
    if (global_gconf_client == NULL) {
 
40
        return;
 
41
    }
 
42
 
 
43
    g_object_unref(G_OBJECT(global_gconf_client));
 
44
    global_gconf_client = NULL;
 
45
}
 
46
 
 
47
/* Public */
 
48
GConfClient *
 
49
eel_gconf_client_get_global(void)
 
50
{
 
51
    /* Initialize gconf if needed */
 
52
    if (!gconf_is_initialized()) {
 
53
        char *argv[] = { "eel-preferences", NULL };
 
54
        GError *error = NULL;
 
55
        char *teststr;
 
56
 
 
57
        if (!gconf_init(1, argv, &error)) {
 
58
            if (eel_gconf_handle_error(&error)) {
 
59
                return NULL;
 
60
            }
 
61
        }
 
62
 
 
63
        /* check if gconf schemas are working */
 
64
        teststr = gconf_client_get_string(eel_gconf_client_get_global(),
 
65
                                          "/apps/gpdf/gconf_test", NULL);
 
66
 
 
67
        if (!teststr) {
 
68
            GtkWidget *dialog;
 
69
            dialog = gtk_message_dialog_new(NULL,
 
70
                                            GTK_DIALOG_MODAL,
 
71
                                            GTK_MESSAGE_ERROR,
 
72
                                            GTK_BUTTONS_OK,
 
73
                                            _("Cannot find a schema for gpdf preferences. \n"
 
74
                                              "Check your gconf setup, look at gpdf FAQ for \n"
 
75
                                              "more info"));
 
76
            gtk_dialog_run(GTK_DIALOG(dialog));
 
77
            exit(0);
 
78
        } else {
 
79
            g_free(teststr);
 
80
        }
 
81
 
 
82
    }
 
83
 
 
84
    if (global_gconf_client == NULL) {
 
85
        global_gconf_client = gconf_client_get_default();
 
86
        g_atexit(global_client_free);
 
87
    }
 
88
 
 
89
    return global_gconf_client;
 
90
}
 
91
 
 
92
gboolean
 
93
eel_gconf_handle_error(GError **error)
 
94
{
 
95
    g_return_val_if_fail(error != NULL, FALSE);
 
96
 
 
97
    if (*error != NULL) {
 
98
        g_warning("GConf error: %s\n", (*error)->message);
 
99
        g_error_free(*error);
 
100
        *error = NULL;
 
101
 
 
102
        return TRUE;
 
103
    }
 
104
 
 
105
    return FALSE;
 
106
}
 
107
 
 
108
void
 
109
eel_gconf_set_boolean(const char *key,
 
110
                      gboolean boolean_value)
 
111
{
 
112
    GConfClient *client;
 
113
    GError *error = NULL;
 
114
 
 
115
    g_return_if_fail(key != NULL);
 
116
 
 
117
    client = eel_gconf_client_get_global();
 
118
    g_return_if_fail(client != NULL);
 
119
 
 
120
    gconf_client_set_bool(client, key, boolean_value, &error);
 
121
    eel_gconf_handle_error(&error);
 
122
}
 
123
 
 
124
gboolean
 
125
eel_gconf_get_boolean(const char *key)
 
126
{
 
127
    gboolean result;
 
128
    GConfClient *client;
 
129
    GError *error = NULL;
 
130
 
 
131
    g_return_val_if_fail(key != NULL, FALSE);
 
132
 
 
133
    client = eel_gconf_client_get_global();
 
134
    g_return_val_if_fail(client != NULL, FALSE);
 
135
 
 
136
    result = gconf_client_get_bool(client, key, &error);
 
137
 
 
138
    if (eel_gconf_handle_error(&error)) {
 
139
        result = FALSE;
 
140
    }
 
141
 
 
142
    return result;
 
143
}
 
144
 
 
145
void
 
146
eel_gconf_set_integer(const char *key,
 
147
                      int int_value)
 
148
{
 
149
    GConfClient *client;
 
150
    GError *error = NULL;
 
151
 
 
152
    g_return_if_fail(key != NULL);
 
153
 
 
154
    client = eel_gconf_client_get_global();
 
155
    g_return_if_fail(client != NULL);
 
156
 
 
157
    gconf_client_set_int(client, key, int_value, &error);
 
158
    eel_gconf_handle_error(&error);
 
159
}
 
160
 
 
161
int
 
162
eel_gconf_get_integer(const char *key)
 
163
{
 
164
    int result;
 
165
    GConfClient *client;
 
166
    GError *error = NULL;
 
167
 
 
168
    g_return_val_if_fail(key != NULL, 0);
 
169
 
 
170
    client = eel_gconf_client_get_global();
 
171
    g_return_val_if_fail(client != NULL, 0);
 
172
 
 
173
    result = gconf_client_get_int(client, key, &error);
 
174
 
 
175
    if (eel_gconf_handle_error(&error)) {
 
176
        result = 0;
 
177
    }
 
178
 
 
179
    return result;
 
180
}
 
181
 
 
182
void
 
183
eel_gconf_set_float(const char *key,
 
184
                    gfloat float_value)
 
185
{
 
186
    GConfClient *client;
 
187
    GError *error = NULL;
 
188
 
 
189
    g_return_if_fail(key != NULL);
 
190
 
 
191
    client = eel_gconf_client_get_global();
 
192
    g_return_if_fail(client != NULL);
 
193
 
 
194
    gconf_client_set_float(client, key, float_value, &error);
 
195
    eel_gconf_handle_error(&error);
 
196
}
 
197
 
 
198
gfloat
 
199
eel_gconf_get_float(const char *key)
 
200
{
 
201
    gfloat result;
 
202
    GConfClient *client;
 
203
    GError *error = NULL;
 
204
 
 
205
    g_return_val_if_fail(key != NULL, 0);
 
206
 
 
207
    client = eel_gconf_client_get_global();
 
208
    g_return_val_if_fail(client != NULL, 0);
 
209
 
 
210
    result = gconf_client_get_float(client, key, &error);
 
211
 
 
212
    if (eel_gconf_handle_error(&error)) {
 
213
        result = 0;
 
214
    }
 
215
 
 
216
    return result;
 
217
}
 
218
 
 
219
void
 
220
eel_gconf_set_string(const char *key,
 
221
                     const char *string_value)
 
222
{
 
223
    GConfClient *client;
 
224
    GError *error = NULL;
 
225
 
 
226
    g_return_if_fail(key != NULL);
 
227
    g_return_if_fail(string_value != NULL);
 
228
 
 
229
    client = eel_gconf_client_get_global();
 
230
    g_return_if_fail(client != NULL);
 
231
 
 
232
    gconf_client_set_string(client, key, string_value, &error);
 
233
    eel_gconf_handle_error(&error);
 
234
}
 
235
 
 
236
void
 
237
eel_gconf_unset(const char *key)
 
238
{
 
239
    GConfClient *client;
 
240
    GError *error = NULL;
 
241
 
 
242
    g_return_if_fail(key != NULL);
 
243
 
 
244
    client = eel_gconf_client_get_global();
 
245
    g_return_if_fail(client != NULL);
 
246
 
 
247
    gconf_client_unset(client, key, &error);
 
248
    eel_gconf_handle_error(&error);
 
249
}
 
250
 
 
251
char *
 
252
eel_gconf_get_string(const char *key)
 
253
{
 
254
    char *result;
 
255
    GConfClient *client;
 
256
    GError *error = NULL;
 
257
 
 
258
    g_return_val_if_fail(key != NULL, NULL);
 
259
 
 
260
    client = eel_gconf_client_get_global();
 
261
    g_return_val_if_fail(client != NULL, NULL);
 
262
 
 
263
    result = gconf_client_get_string(client, key, &error);
 
264
 
 
265
    if (eel_gconf_handle_error(&error)) {
 
266
        result = g_strdup("");
 
267
    }
 
268
 
 
269
    return result;
 
270
}
 
271
 
 
272
void
 
273
eel_gconf_set_string_list(const char *key,
 
274
                          const GSList *slist)
 
275
{
 
276
    GConfClient *client;
 
277
    GError *error;
 
278
 
 
279
    g_return_if_fail(key != NULL);
 
280
 
 
281
    client = eel_gconf_client_get_global();
 
282
    g_return_if_fail(client != NULL);
 
283
 
 
284
    error = NULL;
 
285
    gconf_client_set_list(client, key, GCONF_VALUE_STRING,
 
286
                          /* Need cast cause of GConf api bug */
 
287
                          (GSList *) slist,
 
288
                          &error);
 
289
    eel_gconf_handle_error(&error);
 
290
}
 
291
 
 
292
GSList *
 
293
eel_gconf_get_string_list(const char *key)
 
294
{
 
295
    GSList *slist;
 
296
    GConfClient *client;
 
297
    GError *error;
 
298
 
 
299
    g_return_val_if_fail(key != NULL, NULL);
 
300
 
 
301
    client = eel_gconf_client_get_global();
 
302
    g_return_val_if_fail(client != NULL, NULL);
 
303
 
 
304
    error = NULL;
 
305
    slist = gconf_client_get_list(client, key, GCONF_VALUE_STRING, &error);
 
306
 
 
307
    if (eel_gconf_handle_error(&error)) {
 
308
        slist = NULL;
 
309
    }
 
310
 
 
311
    return slist;
 
312
}
 
313
 
 
314
/* This code wasn't part of the original eel-gconf-extensions.c */
 
315
void
 
316
eel_gconf_set_integer_list(const char *key,
 
317
                           const GSList *slist)
 
318
{
 
319
    GConfClient *client;
 
320
    GError *error;
 
321
 
 
322
    g_return_if_fail(key != NULL);
 
323
 
 
324
    client = eel_gconf_client_get_global();
 
325
    g_return_if_fail(client != NULL);
 
326
 
 
327
    error = NULL;
 
328
    gconf_client_set_list(client, key, GCONF_VALUE_INT,
 
329
                          /* Need cast cause of GConf api bug */
 
330
                          (GSList *) slist,
 
331
                          &error);
 
332
    eel_gconf_handle_error(&error);
 
333
}
 
334
 
 
335
GSList *
 
336
eel_gconf_get_integer_list(const char *key)
 
337
{
 
338
    GSList *slist;
 
339
    GConfClient *client;
 
340
    GError *error;
 
341
 
 
342
    g_return_val_if_fail(key != NULL, NULL);
 
343
 
 
344
    client = eel_gconf_client_get_global();
 
345
    g_return_val_if_fail(client != NULL, NULL);
 
346
 
 
347
    error = NULL;
 
348
    slist = gconf_client_get_list(client, key, GCONF_VALUE_INT, &error);
 
349
 
 
350
    if (eel_gconf_handle_error(&error)) {
 
351
        slist = NULL;
 
352
    }
 
353
 
 
354
    return slist;
 
355
}
 
356
/* End of added code */
 
357
 
 
358
gboolean
 
359
eel_gconf_is_default(const char *key)
 
360
{
 
361
    gboolean result;
 
362
    GConfValue *value;
 
363
    GError *error = NULL;
 
364
 
 
365
    g_return_val_if_fail(key != NULL, FALSE);
 
366
 
 
367
    value = gconf_client_get_without_default(eel_gconf_client_get_global(), key, &error);
 
368
 
 
369
    if (eel_gconf_handle_error(&error)) {
 
370
        if (value != NULL) {
 
371
            gconf_value_free(value);
 
372
        }
 
373
 
 
374
        return FALSE;
 
375
    }
 
376
 
 
377
    result = (value == NULL);
 
378
 
 
379
    if (value != NULL) {
 
380
        gconf_value_free(value);
 
381
    }
 
382
 
 
383
 
 
384
    return result;
 
385
}
 
386
 
 
387
gboolean
 
388
eel_gconf_monitor_add(const char *directory)
 
389
{
 
390
    GError *error = NULL;
 
391
    GConfClient *client;
 
392
 
 
393
    g_return_val_if_fail(directory != NULL, FALSE);
 
394
 
 
395
    client = eel_gconf_client_get_global();
 
396
    g_return_val_if_fail(client != NULL, FALSE);
 
397
 
 
398
    gconf_client_add_dir(client,
 
399
                         directory,
 
400
                         GCONF_CLIENT_PRELOAD_NONE,
 
401
                         &error);
 
402
 
 
403
    if (eel_gconf_handle_error(&error)) {
 
404
        return FALSE;
 
405
    }
 
406
 
 
407
    return TRUE;
 
408
}
 
409
 
 
410
gboolean
 
411
eel_gconf_monitor_remove(const char *directory)
 
412
{
 
413
    GError *error = NULL;
 
414
    GConfClient *client;
 
415
 
 
416
    if (directory == NULL) {
 
417
        return FALSE;
 
418
    }
 
419
 
 
420
    client = eel_gconf_client_get_global();
 
421
    g_return_val_if_fail(client != NULL, FALSE);
 
422
 
 
423
    gconf_client_remove_dir(client,
 
424
                            directory,
 
425
                            &error);
 
426
 
 
427
    if (eel_gconf_handle_error(&error)) {
 
428
        return FALSE;
 
429
    }
 
430
 
 
431
    return TRUE;
 
432
}
 
433
 
 
434
void
 
435
eel_gconf_suggest_sync(void)
 
436
{
 
437
    GConfClient *client;
 
438
    GError *error = NULL;
 
439
 
 
440
    client = eel_gconf_client_get_global();
 
441
    g_return_if_fail(client != NULL);
 
442
 
 
443
    gconf_client_suggest_sync(client, &error);
 
444
    eel_gconf_handle_error(&error);
 
445
}
 
446
 
 
447
GConfValue*
 
448
eel_gconf_get_value(const char *key)
 
449
{
 
450
    GConfValue *value = NULL;
 
451
    GConfClient *client;
 
452
    GError *error = NULL;
 
453
 
 
454
    g_return_val_if_fail(key != NULL, NULL);
 
455
 
 
456
    client = eel_gconf_client_get_global();
 
457
    g_return_val_if_fail(client != NULL, NULL);
 
458
 
 
459
    value = gconf_client_get(client, key, &error);
 
460
 
 
461
    if (eel_gconf_handle_error(&error)) {
 
462
        if (value != NULL) {
 
463
            gconf_value_free(value);
 
464
            value = NULL;
 
465
        }
 
466
    }
 
467
 
 
468
    return value;
 
469
}
 
470
 
 
471
void
 
472
eel_gconf_set_value(const char *key, const GConfValue *value)
 
473
{
 
474
    GConfClient *client;
 
475
    GError *error = NULL;
 
476
 
 
477
    g_return_if_fail(key != NULL);
 
478
 
 
479
    client = eel_gconf_client_get_global();
 
480
    g_return_if_fail(client != NULL);
 
481
 
 
482
    gconf_client_set(client, key, value, &error);
 
483
 
 
484
    if (eel_gconf_handle_error(&error)) {
 
485
        return;
 
486
    }
 
487
}
 
488
 
 
489
gboolean
 
490
eel_gconf_key_exists(const char *key)
 
491
{
 
492
    GConfValue *value = NULL;
 
493
    GConfClient *client;
 
494
    GError *error = NULL;
 
495
    gboolean error_occurred;
 
496
    gboolean value_found;
 
497
 
 
498
    g_return_val_if_fail(key != NULL, FALSE);
 
499
 
 
500
    client = eel_gconf_client_get_global();
 
501
    g_return_val_if_fail(client != NULL, FALSE);
 
502
 
 
503
    value = gconf_client_get(client, key, &error);
 
504
 
 
505
    value_found = (value != NULL);
 
506
    error_occurred = (error != NULL);
 
507
 
 
508
    eel_gconf_value_free(value);
 
509
 
 
510
    if (error != NULL) {
 
511
        g_error_free(error);
 
512
    }
 
513
 
 
514
    return (!error_occurred && value_found);
 
515
}
 
516
 
 
517
void
 
518
eel_gconf_value_free(GConfValue *value)
 
519
{
 
520
    if (value == NULL) {
 
521
        return;
 
522
    }
 
523
 
 
524
    gconf_value_free(value);
 
525
}
 
526
 
 
527
guint
 
528
eel_gconf_notification_add(const char *key,
 
529
                           GConfClientNotifyFunc notification_callback,
 
530
                           gpointer callback_data)
 
531
{
 
532
    guint notification_id;
 
533
    GConfClient *client;
 
534
    GError *error = NULL;
 
535
 
 
536
    g_return_val_if_fail(key != NULL, EEL_GCONF_UNDEFINED_CONNECTION);
 
537
    g_return_val_if_fail(notification_callback != NULL, EEL_GCONF_UNDEFINED_CONNECTION);
 
538
 
 
539
    client = eel_gconf_client_get_global();
 
540
    g_return_val_if_fail(client != NULL, EEL_GCONF_UNDEFINED_CONNECTION);
 
541
 
 
542
    notification_id = gconf_client_notify_add(client,
 
543
                      key,
 
544
                      notification_callback,
 
545
                      callback_data,
 
546
                      NULL,
 
547
                      &error);
 
548
 
 
549
    if (eel_gconf_handle_error(&error)) {
 
550
        if (notification_id != EEL_GCONF_UNDEFINED_CONNECTION) {
 
551
            gconf_client_notify_remove(client, notification_id);
 
552
            notification_id = EEL_GCONF_UNDEFINED_CONNECTION;
 
553
        }
 
554
    }
 
555
 
 
556
    return notification_id;
 
557
}
 
558
 
 
559
void
 
560
eel_gconf_notification_remove(guint notification_id)
 
561
{
 
562
    GConfClient *client;
 
563
 
 
564
    if (notification_id == EEL_GCONF_UNDEFINED_CONNECTION) {
 
565
        return;
 
566
    }
 
567
 
 
568
    client = eel_gconf_client_get_global();
 
569
    g_return_if_fail(client != NULL);
 
570
 
 
571
    gconf_client_notify_remove(client, notification_id);
 
572
}
 
573
 
 
574
/* Simple wrapper for eel_gconf_notifier_add which
 
575
 * adds the notifier id to the GList given as argument
 
576
 * so that a call to gpdf_notification_free can remove the notifiers
 
577
 */
 
578
void
 
579
gpdf_notification_add(const char *key,
 
580
                      GConfClientNotifyFunc notification_callback,
 
581
                      gpointer callback_data,
 
582
                      GList **notifiers)
 
583
{
 
584
    guint id = 0;
 
585
 
 
586
    id = eel_gconf_notification_add(key,
 
587
                                    notification_callback,
 
588
                                    callback_data);
 
589
 
 
590
    if (notifiers != NULL) {
 
591
        *notifiers = g_list_append(*notifiers,
 
592
                                   GINT_TO_POINTER(id));
 
593
    }
 
594
}
 
595
 
 
596
/* Removes all the notifiers listed in notifiers */
 
597
/* Frees the notifiers list */
 
598
void
 
599
gpdf_notification_remove(GList **notifiers)
 
600
{
 
601
    g_list_foreach(*notifiers,
 
602
                   (GFunc) eel_gconf_notification_remove,
 
603
                   NULL);
 
604
    g_list_free(*notifiers);
 
605
    *notifiers = NULL;
 
606
}
 
607
 
 
608