~ubuntu-branches/ubuntu/maverick/ekiga/maverick

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Eugen Dedu, Eugen Dedu, Loic Minier
  • Date: 2008-09-27 10:00:00 UTC
  • mfrom: (1.1.8 upstream)
  • mto: (1.4.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 38.
  • Revision ID: james.westby@ubuntu.com-20080927100000-l5k5werb6czr5b3h
Tags: 3.0.1-1
[ Eugen Dedu ]
* New version.  (Closes: #500089).
* Add our own changelog file in /usr/share/doc.
* Remove gnomemeeting transitional package.
* Discover new interfaces.  (Closes: #488199).
* Compile with dbus support.  (Closes: #467212).
* Numeric keypad inserts digits at correct position.  (Closes: #440159).
* Use libnotify upon call.  (Closes: #412604).
* Symlink identical GNOME help files, to reduce size.  (Closes: #505536).
* Explicitely build-depends on a few dev packages, even if they were
  pulled out anyway by the other dependencies.

[ Loic Minier ]
* Use clean:: instead of clean: in rules.
* Don't disable Uploaders: generation for control.in -> control generation
  in rules.
* Fix some tabs which were size 4 anyway.
* Generate a PO template during build by calling intltool-update -p in
  install; thanks Ubuntu and Martin Pitt; closes: #505535.
* Also let the -dbg depend on ${misc:Depends}.
* Cleanup rules; in particular, use dpkg-parsechangelog and honor
  distclean/clean failures, remove old clean rules, commented out stuff,
  gtk-only stuff.
* Pass -s to dh_* in binary-arch.
* Use debian/*.links and debian/*.manpages instead of symlink manually or
  passing files to dh_installman.
* Use ftp.gnome.org in copyright.
* Switch to quilt and fix target deps in the process; build-dep on quilt
  instead of dpatch; rename news.dpatch to 00_news.patch and refresh;
  replace 00list with series.
* Install autotools-dev config.guess and .sub after patching.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 
28
28
 
29
29
/*
30
 
 *                         gmconf-glib.c  -  description 
 
30
 *                         gmconf-glib.c  -  description
31
31
 *                         ------------------------------------------
32
32
 *   begin                : Mar 2004
33
33
 *   copyright            : (C) 2004 by Julien Puydt
37
37
 
38
38
#include <glib.h>
39
39
#include <stdio.h>
 
40
#include <stdlib.h>
 
41
#include <string.h>
40
42
#include <sys/stat.h>
41
43
 
42
44
#include "toolbox/toolbox.h"
43
 
#include "gmconf.h" 
 
45
#include "gmconf.h"
44
46
 
45
47
#ifdef WIN32
46
 
#include "../winpaths.h"
 
48
#include "platform/winpaths.h"
47
49
#endif
48
50
 
49
51
 
62
64
 * - the implementation of gmconf.h's api.
63
65
 */
64
66
 
 
67
#define check_entry_type_return(entry,_type,val) G_STMT_START{ \
 
68
  if (G_LIKELY(entry != NULL && entry->type == _type)) \
 
69
    {} \
 
70
  else { \
 
71
    gchar *msg = NULL; \
 
72
    msg = g_strdup_printf ("gmconf key %s is of type " #_type, entry->key); \
 
73
    g_return_if_fail_warning (G_LOG_DOMAIN, __PRETTY_FUNCTION__, msg); \
 
74
    g_free (msg); \
 
75
    return val; \
 
76
  } \
 
77
}G_STMT_END
 
78
 
 
79
#define check_entry_for_key_return(entry,key,val) G_STMT_START{ \
 
80
  if (G_LIKELY(entry != NULL)) \
 
81
    {} \
 
82
  else { \
 
83
    gchar *msg = NULL; \
 
84
    msg = g_strdup_printf ("key %s has no corresponding entry! ", key); \
 
85
    g_return_if_fail_warning (G_LOG_DOMAIN, __PRETTY_FUNCTION__, msg); \
 
86
    g_free (msg); \
 
87
    return val; \
 
88
  } \
 
89
}G_STMT_END
 
90
 
65
91
 
66
92
/* the data types used in this file */
67
93
 
81
107
typedef struct _Notifier
82
108
{
83
109
  GmConfNotifier func;
84
 
  gpointer data;  
 
110
  gpointer data;
85
111
} Notifier;
86
112
 
87
113
/* that implementation uses the GM_CONF_OTHER type of entry (the one that is
88
114
 * free to use for the specific implementation) to store "redirections", which
89
115
 * is the scheme that is used to make notifications propagate to parents in the
90
 
 * namespace 
 
116
 * namespace
91
117
 */
92
118
struct _GmConfEntry
93
119
{
134
160
/* this little structure is needed to get enough data through the
135
161
 * iterator when destroying a full namespace
136
162
 */
137
 
typedef struct _NamespcWrapper 
 
163
typedef struct _NamespcWrapper
138
164
{
139
165
  GData **datalist;
140
166
  const gchar *namespc;
158
184
 
159
185
/* notifier functions */
160
186
static Notifier *notifier_new (const GmConfNotifier, const gpointer);
161
 
static void notifier_destroy (Notifier *); 
 
187
static void notifier_destroy (Notifier *);
162
188
static void notifier_destroy_in_list (gpointer elt, gpointer unused);
163
189
static void notifier_call_on_entry (Notifier *, GmConfEntry *);
164
190
 
169
195
static const gchar *entry_get_key (const GmConfEntry *);
170
196
static void entry_set_key (GmConfEntry *, const gchar *);
171
197
 
172
 
static const GmConfEntryType entry_get_type (const GmConfEntry *);
 
198
static GmConfEntryType entry_get_type (const GmConfEntry *);
173
199
static void entry_set_type (GmConfEntry *, const GmConfEntryType);
174
200
 
175
201
static gboolean entry_get_bool (const GmConfEntry *);
210
236
                                     GError **error);
211
237
static void sch_parser_characters (GMarkupParseContext *context,
212
238
                                   const gchar *text,
213
 
                                   gsize text_len,  
 
239
                                   gsize text_len,
214
240
                                   gpointer data,
215
241
                                   GError **error);
216
242
 
232
258
                                                   gpointer user_data);
233
259
static void database_remove_namespace (DataBase *, const gchar *);
234
260
static GmConfEntry *database_get_entry_for_key (DataBase *, const gchar *);
235
 
static GmConfEntry *database_get_entry_for_key_create (DataBase *, 
 
261
static GmConfEntry *database_get_entry_for_key_create (DataBase *,
236
262
                                                       const gchar *);
237
263
 
238
264
static void database_set_watched (DataBase *, const gboolean);
258
284
  return result;
259
285
}
260
286
 
261
 
static void 
 
287
static void
262
288
string_list_deep_destroy (GSList *list)
263
289
{
264
290
  GSList *ptr = NULL;
438
464
    item = NULL;
439
465
  }
440
466
 
441
 
    
 
467
 
442
468
  return result;
443
469
}
444
470
 
445
471
/* implementation of notifier functions */
446
472
static Notifier *
447
 
notifier_new (const GmConfNotifier func, const gpointer data)
 
473
notifier_new (const GmConfNotifier func,
 
474
              const gpointer data)
448
475
{
449
476
  Notifier *notifier = NULL;
450
 
  
 
477
 
451
478
  g_return_val_if_fail (func != NULL, NULL);
452
479
 
453
480
  notifier = g_new (Notifier, 1);
463
490
}
464
491
 
465
492
static void
466
 
notifier_destroy_in_list (gpointer elt, gpointer unused)
 
493
notifier_destroy_in_list (gpointer elt,
 
494
                          G_GNUC_UNUSED gpointer unused)
467
495
{
468
496
  notifier_destroy ((Notifier *)elt);
469
497
}
470
498
 
471
499
static void
472
 
notifier_call_on_entry (Notifier *notifier, GmConfEntry *entry)
 
500
notifier_call_on_entry (Notifier *notifier,
 
501
                        GmConfEntry *entry)
473
502
{
474
503
  g_return_if_fail (notifier != NULL);
475
504
  g_return_if_fail (entry != NULL);
519
548
  case GM_CONF_LIST:
520
549
    string_list_deep_destroy (entry->value.list);
521
550
    break;
 
551
  default:
 
552
    break;
522
553
  }
523
554
 
524
555
  g_slist_foreach (entry->notifiers, notifier_destroy_in_list, NULL);
530
561
entry_get_key (const GmConfEntry *entry)
531
562
{
532
563
  g_return_val_if_fail (entry != NULL, NULL);
533
 
  
 
564
 
534
565
  return entry->key;
535
566
}
536
567
 
537
568
static void
538
 
entry_set_key (GmConfEntry *entry, const gchar *key)
 
569
entry_set_key (GmConfEntry *entry,
 
570
               const gchar *key)
539
571
{
540
572
  g_return_if_fail (entry != NULL);
541
573
  g_return_if_fail (key != NULL);
542
574
 
 
575
  if (entry->key)
 
576
    g_free (entry->key);
543
577
  entry->key = g_strdup (key);
544
578
}
545
579
 
546
 
static const GmConfEntryType
 
580
static GmConfEntryType
547
581
entry_get_type (const GmConfEntry *entry)
548
582
{
549
583
  g_return_val_if_fail (entry != NULL, GM_CONF_OTHER);
552
586
}
553
587
 
554
588
static void
555
 
entry_set_type (GmConfEntry *entry, const GmConfEntryType type)
 
589
entry_set_type (GmConfEntry *entry,
 
590
                const GmConfEntryType type)
556
591
{
557
592
  g_return_if_fail (entry != NULL);
558
593
 
562
597
static gboolean
563
598
entry_get_bool (const GmConfEntry *entry)
564
599
{
565
 
  g_return_val_if_fail (entry != NULL, FALSE);
566
 
  g_return_val_if_fail (entry->type == GM_CONF_BOOL, FALSE);
 
600
  check_entry_type_return (entry, GM_CONF_BOOL, FALSE);
567
601
 
568
602
  return entry->value.boolean;
569
603
}
570
604
 
571
605
static void
572
 
entry_set_bool (GmConfEntry *entry, const gboolean val)
 
606
entry_set_bool (GmConfEntry *entry,
 
607
                const gboolean val)
573
608
{
574
609
  g_return_if_fail (entry != NULL);
575
610
 
580
615
static gint
581
616
entry_get_int (const GmConfEntry *entry)
582
617
{
583
 
  g_return_val_if_fail (entry != NULL, 0);
584
 
  g_return_val_if_fail (entry->type == GM_CONF_INT, 0);
 
618
  check_entry_type_return (entry, GM_CONF_INT, 0);
585
619
 
586
620
  return entry->value.integer;
587
621
}
588
622
 
589
 
static void entry_set_int (GmConfEntry *entry, const gint val)
 
623
static void
 
624
entry_set_int (GmConfEntry *entry,
 
625
               const gint val)
590
626
{
591
627
  g_return_if_fail (entry != NULL);
592
628
 
597
633
static gfloat
598
634
entry_get_float (const GmConfEntry *entry)
599
635
{
600
 
  g_return_val_if_fail (entry != NULL, 0);
601
 
  g_return_val_if_fail (entry->type == GM_CONF_FLOAT, 0);
 
636
  check_entry_type_return (entry, GM_CONF_FLOAT, 0);
602
637
 
603
638
  return entry->value.floa;
604
639
}
605
640
 
606
641
static void
607
 
entry_set_float (GmConfEntry *entry, const gfloat val)
 
642
entry_set_float (GmConfEntry *entry,
 
643
                 const gfloat val)
608
644
{
609
645
  g_return_if_fail (entry != NULL);
610
646
 
615
651
static const gchar *
616
652
entry_get_string (const GmConfEntry *entry)
617
653
{
618
 
  g_return_val_if_fail (entry != NULL, 0);
619
 
  g_return_val_if_fail (entry->type == GM_CONF_STRING, 0);
 
654
  check_entry_type_return (entry, GM_CONF_STRING, NULL);
620
655
 
621
656
  return entry->value.string;
622
657
}
633
668
static GSList *
634
669
entry_get_list (const GmConfEntry *entry)
635
670
{
636
 
  g_return_val_if_fail (entry != NULL, 0);
637
 
  g_return_val_if_fail (entry->type == GM_CONF_LIST, 0);
 
671
  check_entry_type_return (entry, GM_CONF_LIST, NULL);
638
672
 
639
673
  return entry->value.list;
640
674
}
641
675
 
642
676
static void
643
 
entry_set_list (GmConfEntry *entry, GSList *val)
 
677
entry_set_list (GmConfEntry *entry,
 
678
                GSList *val)
644
679
{
645
680
  g_return_if_fail (entry != NULL);
646
681
 
648
683
  entry->value.list = string_list_deep_copy (val);
649
684
}
650
685
 
651
 
static void 
652
 
entry_set_redirect (GmConfEntry *entry, GmConfEntry *redirect)
 
686
static void
 
687
entry_set_redirect (GmConfEntry *entry,
 
688
                    GmConfEntry *redirect)
653
689
{
654
690
  g_return_if_fail (entry != NULL);
655
691
 
669
705
  entry = (GmConfEntry *)data;
670
706
  for (ptr = entry->notifiers; ptr != NULL; ptr = ptr->next) {
671
707
    notif = (Notifier *)ptr->data;
672
 
    if (entry->type == GM_CONF_OTHER)
 
708
    if (entry->type == GM_CONF_OTHER && entry->value.redirect != NULL)
673
709
      notifier_call_on_entry (notif, entry->value.redirect);
674
710
    else
675
711
      notifier_call_on_entry (notif, entry);
677
713
  return FALSE;
678
714
}
679
715
 
680
 
static void 
 
716
static void
681
717
entry_call_notifiers (const GmConfEntry *entry)
682
718
{
683
719
  g_return_if_fail (entry != NULL);
687
723
}
688
724
 
689
725
static gpointer
690
 
entry_add_notifier (GmConfEntry *entry, GmConfNotifier func, gpointer data)
 
726
entry_add_notifier (GmConfEntry *entry,
 
727
                    GmConfNotifier func,
 
728
                    gpointer data)
691
729
{
692
730
  Notifier *notif = NULL;
693
731
 
701
739
 
702
740
 
703
741
static void
704
 
entry_remove_notifier (GmConfEntry *entry, gpointer identifier)
 
742
entry_remove_notifier (GmConfEntry *entry,
 
743
                       gpointer identifier)
705
744
{
706
 
  /* no check, since the only function calling here is 
 
745
  /* no check, since the only function calling here is
707
746
     entry_remove_notifier_in_list */
708
747
 
709
748
  entry->notifiers = g_slist_remove (entry->notifiers, identifier);
710
749
}
711
750
 
712
 
static void 
713
 
entry_remove_notifier_in_list (GQuark unused,
 
751
static void
 
752
entry_remove_notifier_in_list (G_GNUC_UNUSED GQuark unused,
714
753
                               gpointer entry,
715
754
                               gpointer identifier)
716
755
{
733
772
  return db;
734
773
}
735
774
 
 
775
static void
 
776
database_destroy (DataBase *db)
 
777
{
 
778
  g_datalist_clear (&db->entries);
 
779
  g_free (db);
 
780
}
 
781
 
736
782
static DataBase *
737
783
database_get_default ()
738
784
{
742
788
  return db;
743
789
}
744
790
 
745
 
static void 
746
 
sch_parser_start_element (GMarkupParseContext *context,
 
791
static void
 
792
sch_parser_start_element (G_GNUC_UNUSED GMarkupParseContext *context,
747
793
                          const gchar *element_name,
748
 
                          const gchar **attribute_names,
749
 
                          const gchar **attribute_values,
 
794
                          G_GNUC_UNUSED const gchar **attribute_names,
 
795
                          G_GNUC_UNUSED const gchar **attribute_values,
750
796
                          gpointer data,
751
 
                          GError **error)
 
797
                          G_GNUC_UNUSED GError **error)
752
798
{
753
799
  SchParser *parser = NULL;
754
800
 
766
812
    parser->state = VALUE;
767
813
}
768
814
 
769
 
static void  
770
 
sch_parser_end_element (GMarkupParseContext *context,
 
815
static void
 
816
sch_parser_end_element (G_GNUC_UNUSED GMarkupParseContext *context,
771
817
                        const gchar *element_name,
772
818
                        gpointer data,
773
 
                        GError **error)
 
819
                        G_GNUC_UNUSED GError **error)
774
820
{
775
821
  SchParser *parser = NULL;
776
822
 
787
833
  parser->state = START;
788
834
}
789
835
 
790
 
static void 
791
 
sch_parser_characters (GMarkupParseContext *context,
 
836
static void
 
837
sch_parser_characters (G_GNUC_UNUSED GMarkupParseContext *context,
792
838
                       const gchar *text,
793
 
                       gsize text_len,  
 
839
                       G_GNUC_UNUSED gsize text_len,
794
840
                       gpointer data,
795
 
                       GError **error)
 
841
                       G_GNUC_UNUSED GError **error)
796
842
{
797
843
  SchParser *parser = NULL;
798
844
 
801
847
  parser = (SchParser *)data;
802
848
 
803
849
  switch (parser->state) {
 
850
 
804
851
  case  START:
805
852
    /* we're not interested in that data: just eat it! */
806
853
    break;
817
864
    else if (strcmp (text, "string") == 0)
818
865
      entry_set_type (parser->entry, GM_CONF_STRING);
819
866
    else if (strcmp (text, "list") == 0)
820
 
      entry_set_type (parser->entry, GM_CONF_LIST);   
 
867
      entry_set_type (parser->entry, GM_CONF_LIST);
821
868
    else
822
869
      entry_set_type (parser->entry, GM_CONF_OTHER);
823
870
    break;
838
885
    case GM_CONF_LIST:
839
886
      entry_set_list (parser->entry, list_from_string (text));
840
887
      break;
 
888
    case GM_CONF_OTHER: /* shouldn't happen */
 
889
      break;
841
890
    default:
842
891
      break;
843
892
    }
 
893
 
 
894
  default:
 
895
    ;/* nothing */
844
896
  }
845
897
}
846
898
 
847
899
static gboolean
848
 
database_load_file (DataBase *db, const gchar *filename)
 
900
database_load_file (DataBase *db,
 
901
                    const gchar *filename)
849
902
{
850
903
  SchParser *parser = NULL;
851
904
  GMarkupParseContext *context = NULL;
858
911
  g_return_val_if_fail (filename != NULL, FALSE);
859
912
 
860
913
  io = g_io_channel_new_file (filename, "r", NULL);
861
 
  if (!io) 
 
914
  if (!io)
862
915
    return FALSE;
863
916
  parser = g_new (SchParser, 1);
864
917
  parser->state = START;
881
934
          return g_markup_parse_context_end_parse (context, NULL);
882
935
        case G_IO_STATUS_NORMAL:
883
936
        case G_IO_STATUS_AGAIN:
 
937
        default:
884
938
          break;
885
939
        }
886
940
      if (!g_markup_parse_context_parse (context, buffer, len, NULL))
894
948
  return TRUE;
895
949
}
896
950
 
897
 
static void 
898
 
database_save_entry (GQuark quark, gpointer data,
 
951
static void
 
952
database_save_entry (G_GNUC_UNUSED GQuark quark,
 
953
                     gpointer data,
899
954
                     gpointer user_data)
900
955
{
901
956
  GmConfEntry *entry = NULL;
902
 
  GSList *ptr;
903
957
  GIOChannel *io = NULL;
904
958
  gchar *value = NULL;
 
959
  const gchar *txt = NULL;
905
960
 
906
961
  g_return_if_fail (data != NULL);
907
962
  g_return_if_fail (user_data != NULL);
955
1010
    value = string_from_float (entry_get_float (entry));
956
1011
    break;
957
1012
  case GM_CONF_STRING:
958
 
    value = g_strdup (entry_get_string (entry));
 
1013
    txt = entry_get_string (entry);
 
1014
    if (txt != NULL)
 
1015
      value = g_markup_escape_text (txt, -1);
 
1016
    else
 
1017
      value = g_strdup ("");
959
1018
    break;
960
1019
  case GM_CONF_LIST:
961
1020
    value = string_from_list (entry_get_list (entry));
972
1031
  g_io_channel_write_chars (io, "</schema>\n", -1, NULL, NULL);
973
1032
}
974
1033
 
975
 
static gboolean 
976
 
database_save_file (DataBase *db, const gchar *filename)
 
1034
static gboolean
 
1035
database_save_file (DataBase *db,
 
1036
                    const gchar *filename)
977
1037
{
978
1038
  GIOChannel *io = NULL;
979
1039
  gchar *dirname = NULL;
980
1040
 
981
 
  g_return_if_fail (db != NULL);
982
 
  g_return_if_fail (filename != NULL);
 
1041
  g_return_val_if_fail (db != NULL, FALSE);
 
1042
  g_return_val_if_fail (filename != NULL, FALSE);
983
1043
 
984
1044
  dirname = g_path_get_dirname (filename);
985
1045
  if (!g_file_test (dirname, G_FILE_TEST_IS_DIR)) {
986
 
    if (!gm_mkdir_with_parents (dirname, S_IRWXU))
 
1046
    if (!g_mkdir_with_parents (dirname, S_IRWXU))
987
1047
      g_warning ("Unable to create directory %s\n", dirname);
988
1048
  }
989
1049
  g_free (dirname);
1001
1061
  return TRUE;
1002
1062
}
1003
1063
 
1004
 
static void 
1005
 
database_add_entry (DataBase *db, GmConfEntry *entry)
 
1064
static void
 
1065
database_add_entry (DataBase *db,
 
1066
                    GmConfEntry *entry)
1006
1067
{
1007
1068
  g_return_if_fail (db != NULL);
1008
1069
  g_return_if_fail (entry != NULL);
1011
1072
                            entry, entry_destroy);
1012
1073
}
1013
1074
 
1014
 
static void 
1015
 
database_remove_namespace_in_datalist (GQuark key_id,
 
1075
static void
 
1076
database_remove_namespace_in_datalist (G_GNUC_UNUSED GQuark key_id,
1016
1077
                                       gpointer data,
1017
1078
                                       gpointer user_data)
1018
1079
{
1019
1080
  GmConfEntry *entry = NULL;
1020
1081
  NamespcWrapper *wrapper = NULL;
1021
1082
  const gchar *key = NULL;
1022
 
  
 
1083
 
1023
1084
  g_return_if_fail (data != NULL);
1024
1085
  g_return_if_fail (user_data != NULL);
1025
1086
 
1032
1093
 
1033
1094
}
1034
1095
 
1035
 
static void 
1036
 
database_remove_namespace (DataBase *db, const gchar *namespc)
 
1096
static void
 
1097
database_remove_namespace (DataBase *db,
 
1098
                           const gchar *namespc)
1037
1099
{
1038
1100
  NamespcWrapper *wrapper = NULL;
1039
 
  
 
1101
 
1040
1102
  g_return_if_fail (db != NULL);
1041
1103
  g_return_if_fail (namespc != NULL);
1042
1104
 
1043
1105
  wrapper = g_new (NamespcWrapper, 1);
1044
1106
  wrapper->datalist = &db->entries;
1045
1107
  wrapper->namespc = namespc;
1046
 
  g_datalist_foreach (&db->entries, 
 
1108
  g_datalist_foreach (&db->entries,
1047
1109
                      database_remove_namespace_in_datalist, wrapper);
1048
1110
  g_free (wrapper);
1049
1111
}
1050
1112
 
1051
1113
static GmConfEntry *
1052
 
database_get_entry_for_key (DataBase *db, const gchar *key)
 
1114
database_get_entry_for_key (DataBase *db,
 
1115
                            const gchar *key)
1053
1116
{
1054
1117
  GmConfEntry *entry = NULL;
1055
1118
 
1057
1120
  g_return_val_if_fail (key != NULL, NULL);
1058
1121
 
1059
1122
  entry = g_datalist_get_data (&db->entries, key);
 
1123
 
1060
1124
  return entry;
1061
1125
}
1062
1126
 
1063
1127
static GmConfEntry *
1064
 
database_get_entry_for_key_create (DataBase *db, const gchar *key)
 
1128
database_get_entry_for_key_create (DataBase *db,
 
1129
                                   const gchar *key)
1065
1130
{
1066
1131
  GmConfEntry *entry = NULL;
1067
1132
 
1077
1142
  return entry;
1078
1143
}
1079
1144
 
1080
 
static void 
1081
 
database_set_watched (DataBase *db, const gboolean bool)
 
1145
static void
 
1146
database_set_watched (DataBase *db,
 
1147
                      const gboolean bool)
1082
1148
{
1083
1149
  g_return_if_fail (db != NULL);
1084
1150
 
1085
1151
  db->is_watched = bool;
1086
1152
}
1087
1153
 
1088
 
static void 
1089
 
database_notify_on_namespace (DataBase *db, const gchar *namespac)
 
1154
static void
 
1155
database_notify_on_namespace (DataBase *db,
 
1156
                              const gchar *namespac)
1090
1157
{
1091
1158
  GmConfEntry *parent_entry = NULL, *entry = NULL;
1092
1159
  gchar *key = NULL;
1093
 
  
 
1160
 
1094
1161
 
1095
1162
  g_return_if_fail (db != NULL);
1096
1163
  g_return_if_fail (namespac != NULL);
1097
1164
  g_return_if_fail (namespac[0] == '/'); /* that makes the loop work! */
1098
1165
 
1099
1166
  entry = database_get_entry_for_key (db, namespac);
1100
 
  
1101
 
  g_return_if_fail (entry != NULL);  
1102
 
  
 
1167
 
 
1168
  g_return_if_fail (entry != NULL);
 
1169
 
1103
1170
  if (db->is_watched == FALSE)
1104
1171
    return;
1105
1172
 
1106
1173
  for (key = g_strdup (namespac);
1107
 
       key[0] != 0; 
 
1174
       key[0] != 0;
1108
1175
       g_strrstr (key, "/")[0] = 0) {
1109
1176
    parent_entry = database_get_entry_for_key (db, key);
1110
1177
    if (parent_entry != NULL) {
1111
1178
      if (entry_get_type (parent_entry) == GM_CONF_OTHER)
1112
1179
        entry_set_redirect (parent_entry, entry);
1113
 
      entry_call_notifiers (parent_entry);      
 
1180
      entry_call_notifiers (parent_entry);
1114
1181
      if (entry_get_type (entry) == GM_CONF_OTHER)
1115
1182
        entry_set_redirect (parent_entry, NULL);
1116
1183
    }
1139
1206
  filename = gm_conf_get_user_conf_filename ();
1140
1207
  result = database_load_file (db, filename);
1141
1208
 
 
1209
  if (G_LIKELY (result))
 
1210
    {}
 
1211
  else
 
1212
    g_log (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
 
1213
           "couldn't read the user configuration in %s", filename);
 
1214
 
1142
1215
  g_free (filename);
1143
1216
 
1144
1217
  return result;
1156
1229
  filename = g_build_filename (SYSCONFDIR, "ekiga",
1157
1230
                               "ekiga.schemas", NULL);
1158
1231
  result = database_load_file (db, filename);
 
1232
 
 
1233
  if (G_LIKELY (result))
 
1234
    {}
 
1235
  else
 
1236
    g_log (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
 
1237
           "couldn't read the system configuration in %s", filename);
1159
1238
  g_free (filename);
1160
1239
 
1161
1240
  return result;
1164
1243
 
1165
1244
/* last but not least, the implementation of the gmconf.h api */
1166
1245
static gboolean
1167
 
saveconf_timer_callback (gpointer unused)
 
1246
saveconf_timer_callback (G_GNUC_UNUSED gpointer unused)
1168
1247
{
1169
1248
  DataBase *db = database_get_default ();
1170
1249
  gchar *user_conf = NULL;
1173
1252
  database_save_file (db, user_conf);
1174
1253
 
1175
1254
  g_free (user_conf);
1176
 
  
 
1255
 
1177
1256
  return TRUE;
1178
1257
}
1179
1258
 
1180
 
void 
1181
 
gm_conf_init (int argc, char **argv)
 
1259
void
 
1260
gm_conf_init ()
1182
1261
{
1183
1262
  gboolean result = FALSE;
1184
1263
  DataBase *db = database_get_default ();
1185
 
 
 
1264
 
1186
1265
  result = gm_conf_load_sys_conf (db);
1187
1266
  result = (gm_conf_load_user_conf (db) || result);
1188
1267
  if (!result)
1196
1275
 
1197
1276
}
1198
1277
 
1199
 
void 
 
1278
 
 
1279
void
 
1280
gm_conf_shutdown ()
 
1281
{
 
1282
  /* a crash is sure to happen if anyone uses gmconf after this... */
 
1283
  DataBase *db = database_get_default ();
 
1284
  database_destroy (db);
 
1285
}
 
1286
 
 
1287
 
 
1288
void
1200
1289
gm_conf_save ()
1201
1290
{
1202
1291
  DataBase *db = database_get_default ();
1209
1298
  g_free (user_conf);
1210
1299
}
1211
1300
 
1212
 
void 
 
1301
void
1213
1302
gm_conf_watch ()
1214
1303
{
1215
1304
  DataBase *db = database_get_default ();
1217
1306
  database_set_watched (db, TRUE);
1218
1307
}
1219
1308
 
1220
 
void 
 
1309
void
1221
1310
gm_conf_unwatch ()
1222
1311
{
1223
1312
  DataBase *db = database_get_default ();
1225
1314
  database_set_watched (db, FALSE);
1226
1315
}
1227
1316
 
1228
 
gpointer 
1229
 
gm_conf_notifier_add (const gchar *namespac, 
 
1317
gpointer
 
1318
gm_conf_notifier_add (const gchar *namespac,
1230
1319
                      GmConfNotifier func,
1231
1320
                      gpointer user_data)
1232
1321
{
1233
1322
  DataBase *db = database_get_default ();
1234
1323
  GmConfEntry *entry = NULL;
1235
 
  
 
1324
 
1236
1325
  g_return_val_if_fail (namespac != NULL, NULL);
1237
1326
  g_return_val_if_fail (func != NULL, NULL);
1238
 
  
 
1327
 
1239
1328
  entry = database_get_entry_for_key_create (db, namespac);
1240
1329
 
1241
1330
  return entry_add_notifier (entry, func, user_data);
1242
1331
}
1243
1332
 
1244
 
void 
 
1333
void
1245
1334
gm_conf_notifier_remove (gpointer identifier)
1246
1335
{
1247
1336
  DataBase *db = database_get_default ();
1263
1352
  database_notify_on_namespace (db, namespac);
1264
1353
}
1265
1354
 
1266
 
GmConfEntryType 
 
1355
GmConfEntryType
1267
1356
gm_conf_entry_get_type (GmConfEntry *entry)
1268
1357
{
1269
1358
  g_return_val_if_fail (entry != NULL, GM_CONF_OTHER);
1279
1368
  return entry_get_key (entry);
1280
1369
}
1281
1370
 
1282
 
gboolean 
 
1371
gboolean
1283
1372
gm_conf_entry_get_bool (GmConfEntry *entry)
1284
1373
{
1285
1374
  g_return_val_if_fail (entry != NULL, FALSE);
1287
1376
  return entry_get_bool (entry);
1288
1377
}
1289
1378
 
1290
 
gint 
 
1379
gint
1291
1380
gm_conf_entry_get_int (GmConfEntry *entry)
1292
1381
{
1293
1382
  g_return_val_if_fail (entry != NULL, 0);
1303
1392
  return entry_get_string (entry);
1304
1393
}
1305
1394
 
1306
 
const GSList *
 
1395
GSList *
1307
1396
gm_conf_entry_get_list (GmConfEntry *entry)
1308
1397
{
1309
1398
  g_return_val_if_fail (entry != NULL, NULL);
1310
1399
 
1311
 
  return entry_get_list (entry);
 
1400
  return string_list_deep_copy (entry_get_list (entry));
1312
1401
}
1313
1402
 
1314
 
void 
1315
 
gm_conf_set_bool (const gchar *key, const gboolean val)
 
1403
void
 
1404
gm_conf_set_bool (const gchar *key,
 
1405
                  const gboolean val)
1316
1406
{
1317
1407
  DataBase *db = database_get_default ();
1318
1408
  GmConfEntry *entry = NULL;
1327
1417
  database_notify_on_namespace (db, entry_get_key (entry));
1328
1418
}
1329
1419
 
1330
 
gboolean 
 
1420
gboolean
1331
1421
gm_conf_get_bool (const gchar *key)
1332
1422
{
1333
1423
  DataBase *db = database_get_default ();
1334
1424
  GmConfEntry *entry = NULL;
1335
1425
 
1336
 
  g_return_if_fail (key != NULL);
 
1426
  g_return_val_if_fail (key != NULL, FALSE);
1337
1427
 
1338
1428
  entry = database_get_entry_for_key (db, key);
1339
 
  if (entry == NULL)
1340
 
    return FALSE;
 
1429
 
 
1430
  check_entry_for_key_return (entry, key, FALSE);
 
1431
 
1341
1432
  return entry_get_bool (entry);
1342
1433
}
1343
1434
 
1344
 
void 
1345
 
gm_conf_set_int (const gchar *key, const int val)
 
1435
void
 
1436
gm_conf_set_int (const gchar *key,
 
1437
                 const int val)
1346
1438
{
1347
1439
  DataBase *db = database_get_default ();
1348
1440
  GmConfEntry *entry = NULL;
1357
1449
  database_notify_on_namespace (db, entry_get_key (entry));
1358
1450
}
1359
1451
 
1360
 
int 
 
1452
int
1361
1453
gm_conf_get_int (const gchar *key)
1362
1454
{
1363
1455
  DataBase *db = database_get_default ();
1364
1456
  GmConfEntry *entry = NULL;
1365
1457
 
1366
 
  g_return_if_fail (key != NULL);
 
1458
  g_return_val_if_fail (key != NULL, 0);
1367
1459
 
1368
1460
  entry = database_get_entry_for_key (db, key);
1369
 
  if (entry == NULL)
1370
 
    return 0;
 
1461
 
 
1462
  check_entry_for_key_return (entry, key, 0);
 
1463
 
1371
1464
  return entry_get_int (entry);
1372
1465
}
1373
1466
 
1374
 
void 
1375
 
gm_conf_set_float (const gchar *key, const float val)
 
1467
void
 
1468
gm_conf_set_float (const gchar *key,
 
1469
                   const float val)
1376
1470
{
1377
1471
  DataBase *db = database_get_default ();
1378
1472
  GmConfEntry *entry = NULL;
1387
1481
  database_notify_on_namespace (db, entry_get_key (entry));
1388
1482
}
1389
1483
 
1390
 
gfloat 
 
1484
gfloat
1391
1485
gm_conf_get_float (const gchar *key)
1392
1486
{
1393
1487
  DataBase *db = database_get_default ();
1394
1488
  GmConfEntry *entry = NULL;
1395
1489
 
1396
 
  g_return_if_fail (key != NULL);
 
1490
  g_return_val_if_fail (key != NULL, 0);
1397
1491
 
1398
1492
  entry = database_get_entry_for_key (db, key);
1399
 
  if (entry == NULL)
1400
 
    return 0;
 
1493
 
 
1494
  check_entry_for_key_return (entry, key, 0);
1401
1495
 
1402
1496
  return entry_get_float (entry);
1403
1497
}
1404
1498
 
1405
 
void 
1406
 
gm_conf_set_string (const gchar *key, const gchar *val)
 
1499
void
 
1500
gm_conf_set_string (const gchar *key,
 
1501
                    const gchar *val)
1407
1502
{
1408
1503
  DataBase *db = database_get_default ();
1409
1504
  GmConfEntry *entry = NULL;
1424
1519
  DataBase *db = database_get_default ();
1425
1520
  GmConfEntry *entry = NULL;
1426
1521
 
1427
 
  g_return_if_fail (key != NULL);
 
1522
  g_return_val_if_fail (key != NULL, NULL);
1428
1523
 
1429
1524
  entry = database_get_entry_for_key (db, key);
1430
 
  if (entry == NULL)
1431
 
    return NULL;
 
1525
 
 
1526
  check_entry_for_key_return (entry, key, NULL);
 
1527
 
1432
1528
  return g_strdup (entry_get_string (entry));
1433
1529
}
1434
1530
 
1435
 
void 
1436
 
gm_conf_set_string_list (const gchar *key, GSList *val)
 
1531
void
 
1532
gm_conf_set_string_list (const gchar *key,
 
1533
                         GSList *val)
1437
1534
{
1438
1535
  DataBase *db = database_get_default ();
1439
1536
  GmConfEntry *entry = NULL;
1454
1551
  DataBase *db = database_get_default ();
1455
1552
  GmConfEntry *entry = NULL;
1456
1553
 
1457
 
  g_return_if_fail (key != NULL);
 
1554
  g_return_val_if_fail (key != NULL, NULL);
1458
1555
 
1459
1556
  entry = database_get_entry_for_key (db, key);
1460
 
  if (entry == NULL)
1461
 
    return NULL;
 
1557
 
 
1558
  check_entry_for_key_return (entry, key, NULL);
 
1559
 
1462
1560
  return string_list_deep_copy (entry_get_list (entry));
1463
1561
}
1464
1562
 
1465
 
void 
 
1563
void
1466
1564
gm_conf_destroy (const gchar *namespac)
1467
1565
{
1468
1566
  DataBase *db = database_get_default ();
1472
1570
  database_remove_namespace (db, namespac);
1473
1571
}
1474
1572
 
1475
 
gboolean 
 
1573
gboolean
1476
1574
gm_conf_is_key_writable (const gchar *key)
1477
1575
{
1478
1576
  g_return_val_if_fail (key != NULL, FALSE);
1481
1579
}
1482
1580
 
1483
1581
gchar *
1484
 
gm_conf_escape_key (const gchar *key, gint len)
 
1582
gm_conf_escape_key (const gchar *key,
 
1583
                    G_GNUC_UNUSED gint len)
1485
1584
{
1486
1585
  return g_strescape (key, NULL); /* we don't honor len */
1487
1586
}
1488
1587
 
1489
1588
gchar *
1490
 
gm_conf_unescape_key (const gchar *key, gint len)
 
1589
gm_conf_unescape_key (const gchar *key,
 
1590
                      G_GNUC_UNUSED gint len)
1491
1591
{
1492
1592
  return g_strcompress (key); /* we don't honor len */
1493
1593
}