This repository has been archived by the owner on Nov 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gsettings.c
3110 lines (2743 loc) · 95.6 KB
/
gsettings.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright © 2009, 2010 Codethink Limited
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the licence, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Author: Ryan Lortie <desrt@desrt.ca>
*/
/* Prelude {{{1 */
#include "config.h"
#include <glib.h>
#include <glibintl.h>
#include "gsettings.h"
#include "gdelayedsettingsbackend.h"
#include "gsettingsbackendinternal.h"
#include "gsettings-mapping.h"
#include "gsettingsschema-internal.h"
#include "gaction.h"
#include "strinfo.c"
/**
* SECTION:gsettings
* @short_description: High-level API for application settings
*
* The #GSettings class provides a convenient API for storing and retrieving
* application settings.
*
* Reads and writes can be considered to be non-blocking. Reading
* settings with #GSettings is typically extremely fast: on
* approximately the same order of magnitude (but slower than) a
* #GHashTable lookup. Writing settings is also extremely fast in terms
* of time to return to your application, but can be extremely expensive
* for other threads and other processes. Many settings backends
* (including dconf) have lazy initialisation which means in the common
* case of the user using their computer without modifying any settings
* a lot of work can be avoided. For dconf, the D-Bus service doesn't
* even need to be started in this case. For this reason, you should
* only ever modify #GSettings keys in response to explicit user action.
* Particular care should be paid to ensure that modifications are not
* made during startup -- for example, when setting the initial value
* of preferences widgets. The built-in g_settings_bind() functionality
* is careful not to write settings in response to notify signals as a
* result of modifications that it makes to widgets.
*
* When creating a GSettings instance, you have to specify a schema
* that describes the keys in your settings and their types and default
* values, as well as some other information.
*
* Normally, a schema has as fixed path that determines where the settings
* are stored in the conceptual global tree of settings. However, schemas
* can also be 'relocatable', i.e. not equipped with a fixed path. This is
* useful e.g. when the schema describes an 'account', and you want to be
* able to store a arbitrary number of accounts.
*
* Unlike other configuration systems (like GConf), GSettings does not
* restrict keys to basic types like strings and numbers. GSettings stores
* values as #GVariant, and allows any #GVariantType for keys. Key names
* are restricted to lowercase characters, numbers and '-'. Furthermore,
* the names must begin with a lowercase character, must not end
* with a '-', and must not contain consecutive dashes.
*
* Similar to GConf, the default values in GSettings schemas can be
* localized, but the localized values are stored in gettext catalogs
* and looked up with the domain that is specified in the
* <tag class="attribute">gettext-domain</tag> attribute of the
* <tag class="starttag">schemalist</tag> or <tag class="starttag">schema</tag>
* elements and the category that is specified in the l10n attribute of the
* <tag class="starttag">key</tag> element.
*
* GSettings uses schemas in a compact binary form that is created
* by the <link linkend="glib-compile-schemas">glib-compile-schemas</link>
* utility. The input is a schema description in an XML format that can be
* described by the following DTD:
* |[<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../gio/gschema.dtd"><xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback></xi:include>]|
*
* glib-compile-schemas expects schema files to have the extension <filename>.gschema.xml</filename>
*
* At runtime, schemas are identified by their id (as specified
* in the <tag class="attribute">id</tag> attribute of the
* <tag class="starttag">schema</tag> element). The
* convention for schema ids is to use a dotted name, similar in
* style to a D-Bus bus name, e.g. "org.gnome.SessionManager". In particular,
* if the settings are for a specific service that owns a D-Bus bus name,
* the D-Bus bus name and schema id should match. For schemas which deal
* with settings not associated with one named application, the id should
* not use StudlyCaps, e.g. "org.gnome.font-rendering".
*
* In addition to #GVariant types, keys can have types that have enumerated
* types. These can be described by a <tag class="starttag">choice</tag>,
* <tag class="starttag">enum</tag> or <tag class="starttag">flags</tag> element, see
* <xref linkend="schema-enumerated"/>. The underlying type of
* such a key is string, but you can use g_settings_get_enum(),
* g_settings_set_enum(), g_settings_get_flags(), g_settings_set_flags()
* access the numeric values corresponding to the string value of enum
* and flags keys.
*
* <example id="schema-default-values"><title>Default values</title>
* <programlisting><![CDATA[
* <schemalist>
* <schema id="org.gtk.Test" path="/tests/" gettext-domain="test">
*
* <key name="greeting" type="s">
* <default l10n="messages">"Hello, earthlings"</default>
* <summary>A greeting</summary>
* <description>
* Greeting of the invading martians
* </description>
* </key>
*
* <key name="box" type="(ii)">
* <default>(20,30)</default>
* </key>
*
* </schema>
* </schemalist>
* ]]></programlisting></example>
*
* <example id="schema-enumerated"><title>Ranges, choices and enumerated types</title>
* <programlisting><![CDATA[
* <schemalist>
*
* <enum id="org.gtk.Test.myenum">
* <value nick="first" value="1"/>
* <value nick="second" value="2"/>
* </enum>
*
* <flags id="org.gtk.Test.myflags">
* <value nick="flag1" value="1"/>
* <value nick="flag2" value="2"/>
* <value nick="flag3" value="4"/>
* </flags>
*
* <schema id="org.gtk.Test">
*
* <key name="key-with-range" type="i">
* <range min="1" max="100"/>
* <default>10</default>
* </key>
*
* <key name="key-with-choices" type="s">
* <choices>
* <choice value='Elisabeth'/>
* <choice value='Annabeth'/>
* <choice value='Joe'/>
* </choices>
* <aliases>
* <alias value='Anna' target='Annabeth'/>
* <alias value='Beth' target='Elisabeth'/>
* </aliases>
* <default>'Joe'</default>
* </key>
*
* <key name='enumerated-key' enum='org.gtk.Test.myenum'>
* <default>'first'</default>
* </key>
*
* <key name='flags-key' flags='org.gtk.Test.myflags'>
* <default>["flag1",flag2"]</default>
* </key>
* </schema>
* </schemalist>
* ]]></programlisting></example>
*
* <refsect2>
* <title>Vendor overrides</title>
* <para>
* Default values are defined in the schemas that get installed by
* an application. Sometimes, it is necessary for a vendor or distributor
* to adjust these defaults. Since patching the XML source for the schema
* is inconvenient and error-prone,
* <link linkend="glib-compile-schemas">glib-compile-schemas</link> reads
* so-called 'vendor override' files. These are keyfiles in the same
* directory as the XML schema sources which can override default values.
* The schema id serves as the group name in the key file, and the values
* are expected in serialized GVariant form, as in the following example:
* <informalexample><programlisting>
* [org.gtk.Example]
* key1='string'
* key2=1.5
* </programlisting></informalexample>
* </para>
* <para>
* glib-compile-schemas expects schema files to have the extension
* <filename>.gschema.override</filename>
* </para>
* </refsect2>
*
* <refsect2>
* <title>Binding</title>
* <para>
* A very convenient feature of GSettings lets you bind #GObject properties
* directly to settings, using g_settings_bind(). Once a GObject property
* has been bound to a setting, changes on either side are automatically
* propagated to the other side. GSettings handles details like
* mapping between GObject and GVariant types, and preventing infinite
* cycles.
* </para>
* <para>
* This makes it very easy to hook up a preferences dialog to the
* underlying settings. To make this even more convenient, GSettings
* looks for a boolean property with the name "sensitivity" and
* automatically binds it to the writability of the bound setting.
* If this 'magic' gets in the way, it can be suppressed with the
* #G_SETTINGS_BIND_NO_SENSITIVITY flag.
* </para>
* </refsect2>
**/
struct _GSettingsPrivate
{
/* where the signals go... */
GMainContext *main_context;
GSettingsBackend *backend;
GSettingsSchema *schema;
gchar *path;
GDelayedSettingsBackend *delayed;
};
enum
{
PROP_0,
PROP_SCHEMA,
PROP_SCHEMA_ID,
PROP_BACKEND,
PROP_PATH,
PROP_HAS_UNAPPLIED,
PROP_DELAY_APPLY
};
enum
{
SIGNAL_WRITABLE_CHANGE_EVENT,
SIGNAL_WRITABLE_CHANGED,
SIGNAL_CHANGE_EVENT,
SIGNAL_CHANGED,
N_SIGNALS
};
static guint g_settings_signals[N_SIGNALS];
G_DEFINE_TYPE (GSettings, g_settings, G_TYPE_OBJECT)
/* Signals {{{1 */
static gboolean
g_settings_real_change_event (GSettings *settings,
const GQuark *keys,
gint n_keys)
{
gint i;
if (keys == NULL)
keys = g_settings_schema_list (settings->priv->schema, &n_keys);
for (i = 0; i < n_keys; i++)
g_signal_emit (settings, g_settings_signals[SIGNAL_CHANGED],
keys[i], g_quark_to_string (keys[i]));
return FALSE;
}
static gboolean
g_settings_real_writable_change_event (GSettings *settings,
GQuark key)
{
const GQuark *keys = &key;
gint n_keys = 1;
gint i;
if (key == 0)
keys = g_settings_schema_list (settings->priv->schema, &n_keys);
for (i = 0; i < n_keys; i++)
g_signal_emit (settings, g_settings_signals[SIGNAL_WRITABLE_CHANGED],
keys[i], g_quark_to_string (keys[i]));
return FALSE;
}
static void
settings_backend_changed (GObject *target,
GSettingsBackend *backend,
const gchar *key,
gpointer origin_tag)
{
GSettings *settings = G_SETTINGS (target);
gboolean ignore_this;
gint i;
/* We used to assert here:
*
* settings->priv->backend == backend
*
* but it could be the case that a notification is queued for delivery
* while someone calls g_settings_delay() (which changes the backend).
*
* Since the delay backend would just pass that straight through
* anyway, it doesn't make sense to try to detect this case.
* Therefore, we just accept it.
*/
for (i = 0; key[i] == settings->priv->path[i]; i++);
if (settings->priv->path[i] == '\0' &&
g_settings_schema_has_key (settings->priv->schema, key + i))
{
GQuark quark;
quark = g_quark_from_string (key + i);
g_signal_emit (settings, g_settings_signals[SIGNAL_CHANGE_EVENT],
0, &quark, 1, &ignore_this);
}
}
static void
settings_backend_path_changed (GObject *target,
GSettingsBackend *backend,
const gchar *path,
gpointer origin_tag)
{
GSettings *settings = G_SETTINGS (target);
gboolean ignore_this;
if (g_str_has_prefix (settings->priv->path, path))
g_signal_emit (settings, g_settings_signals[SIGNAL_CHANGE_EVENT],
0, NULL, 0, &ignore_this);
}
static void
settings_backend_keys_changed (GObject *target,
GSettingsBackend *backend,
const gchar *path,
const gchar * const *items,
gpointer origin_tag)
{
GSettings *settings = G_SETTINGS (target);
gboolean ignore_this;
gint i;
for (i = 0; settings->priv->path[i] &&
settings->priv->path[i] == path[i]; i++);
if (path[i] == '\0')
{
GQuark quarks[256];
gint j, l = 0;
for (j = 0; items[j]; j++)
{
const gchar *item = items[j];
gint k;
for (k = 0; item[k] == settings->priv->path[i + k]; k++);
if (settings->priv->path[i + k] == '\0' &&
g_settings_schema_has_key (settings->priv->schema, item + k))
quarks[l++] = g_quark_from_string (item + k);
/* "256 quarks ought to be enough for anybody!"
* If this bites you, I'm sorry. Please file a bug.
*/
g_assert (l < 256);
}
if (l > 0)
g_signal_emit (settings, g_settings_signals[SIGNAL_CHANGE_EVENT],
0, quarks, l, &ignore_this);
}
}
static void
settings_backend_writable_changed (GObject *target,
GSettingsBackend *backend,
const gchar *key)
{
GSettings *settings = G_SETTINGS (target);
gboolean ignore_this;
gint i;
for (i = 0; key[i] == settings->priv->path[i]; i++);
if (settings->priv->path[i] == '\0' &&
g_settings_schema_has_key (settings->priv->schema, key + i))
g_signal_emit (settings, g_settings_signals[SIGNAL_WRITABLE_CHANGE_EVENT],
0, g_quark_from_string (key + i), &ignore_this);
}
static void
settings_backend_path_writable_changed (GObject *target,
GSettingsBackend *backend,
const gchar *path)
{
GSettings *settings = G_SETTINGS (target);
gboolean ignore_this;
if (g_str_has_prefix (settings->priv->path, path))
g_signal_emit (settings, g_settings_signals[SIGNAL_WRITABLE_CHANGE_EVENT],
0, (GQuark) 0, &ignore_this);
}
/* Properties, Construction, Destruction {{{1 */
static void
g_settings_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GSettings *settings = G_SETTINGS (object);
switch (prop_id)
{
case PROP_SCHEMA:
{
GSettingsSchema *schema;
schema = g_value_dup_boxed (value);
/* we receive a set_property() call for "settings-schema" even
* if it was not specified (ie: with NULL value). ->schema
* could already be set at this point (ie: via "schema-id").
* check for NULL to avoid clobbering the existing value.
*/
if (schema != NULL)
{
g_assert (settings->priv->schema == NULL);
settings->priv->schema = schema;
}
}
break;
case PROP_SCHEMA_ID:
{
const gchar *schema_id;
schema_id = g_value_get_string (value);
/* we receive a set_property() call for both "schema" and
* "schema-id", even if they are not set. Hopefully only one of
* them is non-NULL.
*/
if (schema_id != NULL)
{
GSettingsSchemaSource *default_source;
g_assert (settings->priv->schema == NULL);
default_source = g_settings_schema_source_get_default ();
if (default_source == NULL)
g_error ("No GSettings schemas are installed on the system");
settings->priv->schema = g_settings_schema_source_lookup (default_source, schema_id, TRUE);
if (settings->priv->schema == NULL)
g_error ("Settings schema '%s' is not installed\n", schema_id);
}
}
break;
case PROP_PATH:
settings->priv->path = g_value_dup_string (value);
break;
case PROP_BACKEND:
settings->priv->backend = g_value_dup_object (value);
break;
default:
g_assert_not_reached ();
}
}
static void
g_settings_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GSettings *settings = G_SETTINGS (object);
switch (prop_id)
{
case PROP_SCHEMA:
g_value_set_boxed (value, settings->priv->schema);
break;
case PROP_SCHEMA_ID:
g_value_set_string (value, g_settings_schema_get_id (settings->priv->schema));
break;
case PROP_BACKEND:
g_value_set_object (value, settings->priv->backend);
break;
case PROP_PATH:
g_value_set_string (value, settings->priv->path);
break;
case PROP_HAS_UNAPPLIED:
g_value_set_boolean (value, g_settings_get_has_unapplied (settings));
break;
case PROP_DELAY_APPLY:
g_value_set_boolean (value, settings->priv->delayed != NULL);
break;
default:
g_assert_not_reached ();
}
}
static const GSettingsListenerVTable listener_vtable = {
settings_backend_changed,
settings_backend_path_changed,
settings_backend_keys_changed,
settings_backend_writable_changed,
settings_backend_path_writable_changed
};
static void
g_settings_constructed (GObject *object)
{
GSettings *settings = G_SETTINGS (object);
const gchar *schema_path;
schema_path = g_settings_schema_get_path (settings->priv->schema);
if (settings->priv->path && schema_path && strcmp (settings->priv->path, schema_path) != 0)
g_error ("settings object created with schema '%s' and path '%s', but path '%s' is specified by schema",
g_settings_schema_get_id (settings->priv->schema), settings->priv->path, schema_path);
if (settings->priv->path == NULL)
{
if (schema_path == NULL)
g_error ("attempting to create schema '%s' without a path",
g_settings_schema_get_id (settings->priv->schema));
settings->priv->path = g_strdup (schema_path);
}
if (settings->priv->backend == NULL)
settings->priv->backend = g_settings_backend_get_default ();
g_settings_backend_watch (settings->priv->backend,
&listener_vtable, G_OBJECT (settings),
settings->priv->main_context);
g_settings_backend_subscribe (settings->priv->backend,
settings->priv->path);
}
static void
g_settings_finalize (GObject *object)
{
GSettings *settings = G_SETTINGS (object);
g_settings_backend_unsubscribe (settings->priv->backend,
settings->priv->path);
g_main_context_unref (settings->priv->main_context);
g_object_unref (settings->priv->backend);
g_settings_schema_unref (settings->priv->schema);
g_free (settings->priv->path);
G_OBJECT_CLASS (g_settings_parent_class)->finalize (object);
}
static void
g_settings_init (GSettings *settings)
{
settings->priv = G_TYPE_INSTANCE_GET_PRIVATE (settings,
G_TYPE_SETTINGS,
GSettingsPrivate);
settings->priv->main_context = g_main_context_ref_thread_default ();
}
static void
g_settings_class_init (GSettingsClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
class->writable_change_event = g_settings_real_writable_change_event;
class->change_event = g_settings_real_change_event;
object_class->set_property = g_settings_set_property;
object_class->get_property = g_settings_get_property;
object_class->constructed = g_settings_constructed;
object_class->finalize = g_settings_finalize;
g_type_class_add_private (object_class, sizeof (GSettingsPrivate));
/**
* GSettings::changed:
* @settings: the object on which the signal was emitted
* @key: the name of the key that changed
*
* The "changed" signal is emitted when a key has potentially changed.
* You should call one of the g_settings_get() calls to check the new
* value.
*
* This signal supports detailed connections. You can connect to the
* detailed signal "changed::x" in order to only receive callbacks
* when key "x" changes.
*/
g_settings_signals[SIGNAL_CHANGED] =
g_signal_new ("changed", G_TYPE_SETTINGS,
G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
G_STRUCT_OFFSET (GSettingsClass, changed),
NULL, NULL, g_cclosure_marshal_VOID__STRING, G_TYPE_NONE,
1, G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE);
/**
* GSettings::change-event:
* @settings: the object on which the signal was emitted
* @keys: (array length=n_keys) (element-type GQuark) (allow-none):
* an array of #GQuark<!-- -->s for the changed keys, or %NULL
* @n_keys: the length of the @keys array, or 0
*
* The "change-event" signal is emitted once per change event that
* affects this settings object. You should connect to this signal
* only if you are interested in viewing groups of changes before they
* are split out into multiple emissions of the "changed" signal.
* For most use cases it is more appropriate to use the "changed" signal.
*
* In the event that the change event applies to one or more specified
* keys, @keys will be an array of #GQuark of length @n_keys. In the
* event that the change event applies to the #GSettings object as a
* whole (ie: potentially every key has been changed) then @keys will
* be %NULL and @n_keys will be 0.
*
* The default handler for this signal invokes the "changed" signal
* for each affected key. If any other connected handler returns
* %TRUE then this default functionality will be suppressed.
*
* Returns: %TRUE to stop other handlers from being invoked for the
* event. FALSE to propagate the event further.
*/
g_settings_signals[SIGNAL_CHANGE_EVENT] =
g_signal_new ("change-event", G_TYPE_SETTINGS,
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GSettingsClass, change_event),
g_signal_accumulator_true_handled, NULL,
NULL,
G_TYPE_BOOLEAN, 2, G_TYPE_POINTER, G_TYPE_INT);
/**
* GSettings::writable-changed:
* @settings: the object on which the signal was emitted
* @key: the key
*
* The "writable-changed" signal is emitted when the writability of a
* key has potentially changed. You should call
* g_settings_is_writable() in order to determine the new status.
*
* This signal supports detailed connections. You can connect to the
* detailed signal "writable-changed::x" in order to only receive
* callbacks when the writability of "x" changes.
*/
g_settings_signals[SIGNAL_WRITABLE_CHANGED] =
g_signal_new ("writable-changed", G_TYPE_SETTINGS,
G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
G_STRUCT_OFFSET (GSettingsClass, writable_changed),
NULL, NULL, g_cclosure_marshal_VOID__STRING, G_TYPE_NONE,
1, G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE);
/**
* GSettings::writable-change-event:
* @settings: the object on which the signal was emitted
* @key: the quark of the key, or 0
*
* The "writable-change-event" signal is emitted once per writability
* change event that affects this settings object. You should connect
* to this signal if you are interested in viewing groups of changes
* before they are split out into multiple emissions of the
* "writable-changed" signal. For most use cases it is more
* appropriate to use the "writable-changed" signal.
*
* In the event that the writability change applies only to a single
* key, @key will be set to the #GQuark for that key. In the event
* that the writability change affects the entire settings object,
* @key will be 0.
*
* The default handler for this signal invokes the "writable-changed"
* and "changed" signals for each affected key. This is done because
* changes in writability might also imply changes in value (if for
* example, a new mandatory setting is introduced). If any other
* connected handler returns %TRUE then this default functionality
* will be suppressed.
*
* Returns: %TRUE to stop other handlers from being invoked for the
* event. FALSE to propagate the event further.
*/
g_settings_signals[SIGNAL_WRITABLE_CHANGE_EVENT] =
g_signal_new ("writable-change-event", G_TYPE_SETTINGS,
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GSettingsClass, writable_change_event),
g_signal_accumulator_true_handled, NULL,
NULL, G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
/**
* GSettings:context:
*
* The name of the context that the settings are stored in.
*/
g_object_class_install_property (object_class, PROP_BACKEND,
g_param_spec_object ("backend",
P_("GSettingsBackend"),
P_("The GSettingsBackend for this settings object"),
G_TYPE_SETTINGS_BACKEND, G_PARAM_CONSTRUCT_ONLY |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GSettings:settings-schema:
*
* The #GSettingsSchema describing the types of keys for this
* #GSettings object.
*
* Ideally, this property would be called 'schema'. #GSettingsSchema
* has only existed since version 2.32, however, and before then the
* 'schema' property was used to refer to the ID of the schema rather
* than the schema itself. Take care.
*/
g_object_class_install_property (object_class, PROP_SCHEMA,
g_param_spec_boxed ("settings-schema",
P_("schema"),
P_("The GSettingsSchema for this settings object"),
G_TYPE_SETTINGS_SCHEMA,
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GSettings:schema:
*
* The name of the schema that describes the types of keys
* for this #GSettings object.
*
* The type of this property is *not* #GSettingsSchema.
* #GSettingsSchema has only existed since version 2.32 and
* unfortunately this name was used in previous versions to refer to
* the schema ID rather than the schema itself. Take care to use the
* 'settings-schema' property if you wish to pass in a
* #GSettingsSchema.
*
* Deprecated:2.32:Use the 'schema-id' property instead. In a future
* version, this property may instead refer to a #GSettingsSchema.
*/
g_object_class_install_property (object_class, PROP_SCHEMA_ID,
g_param_spec_string ("schema",
P_("Schema name"),
P_("The name of the schema for this settings object"),
NULL,
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_DEPRECATED | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GSettings:schema-id:
*
* The name of the schema that describes the types of keys
* for this #GSettings object.
*/
g_object_class_install_property (object_class, PROP_SCHEMA_ID,
g_param_spec_string ("schema-id",
P_("Schema name"),
P_("The name of the schema for this settings object"),
NULL,
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GSettings:path:
*
* The path within the backend where the settings are stored.
*/
g_object_class_install_property (object_class, PROP_PATH,
g_param_spec_string ("path",
P_("Base path"),
P_("The path within the backend where the settings are"),
NULL,
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GSettings:has-unapplied:
*
* If this property is %TRUE, the #GSettings object has outstanding
* changes that will be applied when g_settings_apply() is called.
*/
g_object_class_install_property (object_class, PROP_HAS_UNAPPLIED,
g_param_spec_boolean ("has-unapplied",
P_("Has unapplied changes"),
P_("TRUE if there are outstanding changes to apply()"),
FALSE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
/**
* GSettings:delay-apply:
*
* Whether the #GSettings object is in 'delay-apply' mode. See
* g_settings_delay() for details.
*
* Since: 2.28
*/
g_object_class_install_property (object_class, PROP_DELAY_APPLY,
g_param_spec_boolean ("delay-apply",
P_("Delay-apply mode"),
P_("Whether this settings object is in 'delay-apply' mode"),
FALSE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
}
/* Construction (new, new_with_path, etc.) {{{1 */
/**
* g_settings_new:
* @schema_id: the id of the schema
*
* Creates a new #GSettings object with the schema specified by
* @schema_id.
*
* Signals on the newly created #GSettings object will be dispatched
* via the thread-default #GMainContext in effect at the time of the
* call to g_settings_new(). The new #GSettings will hold a reference
* on the context. See g_main_context_push_thread_default().
*
* Returns: a new #GSettings object
*
* Since: 2.26
*/
GSettings *
g_settings_new (const gchar *schema_id)
{
g_return_val_if_fail (schema_id != NULL, NULL);
return g_object_new (G_TYPE_SETTINGS,
"schema-id", schema_id,
NULL);
}
/**
* g_settings_new_with_path:
* @schema_id: the id of the schema
* @path: the path to use
*
* Creates a new #GSettings object with the relocatable schema specified
* by @schema_id and a given path.
*
* You only need to do this if you want to directly create a settings
* object with a schema that doesn't have a specified path of its own.
* That's quite rare.
*
* It is a programmer error to call this function for a schema that
* has an explicitly specified path.
*
* Returns: a new #GSettings object
*
* Since: 2.26
*/
GSettings *
g_settings_new_with_path (const gchar *schema_id,
const gchar *path)
{
g_return_val_if_fail (schema_id != NULL, NULL);
g_return_val_if_fail (path != NULL, NULL);
return g_object_new (G_TYPE_SETTINGS,
"schema-id", schema_id,
"path", path,
NULL);
}
/**
* g_settings_new_with_backend:
* @schema_id: the id of the schema
* @backend: the #GSettingsBackend to use
*
* Creates a new #GSettings object with the schema specified by
* @schema_id and a given #GSettingsBackend.
*
* Creating a #GSettings object with a different backend allows accessing
* settings from a database other than the usual one. For example, it may make
* sense to pass a backend corresponding to the "defaults" settings database on
* the system to get a settings object that modifies the system default
* settings instead of the settings for this user.
*
* Returns: a new #GSettings object
*
* Since: 2.26
*/
GSettings *
g_settings_new_with_backend (const gchar *schema_id,
GSettingsBackend *backend)
{
g_return_val_if_fail (schema_id != NULL, NULL);
g_return_val_if_fail (G_IS_SETTINGS_BACKEND (backend), NULL);
return g_object_new (G_TYPE_SETTINGS,
"schema-id", schema_id,
"backend", backend,
NULL);
}
/**
* g_settings_new_with_backend_and_path:
* @schema_id: the id of the schema
* @backend: the #GSettingsBackend to use
* @path: the path to use
*
* Creates a new #GSettings object with the schema specified by
* @schema_id and a given #GSettingsBackend and path.
*
* This is a mix of g_settings_new_with_backend() and
* g_settings_new_with_path().
*
* Returns: a new #GSettings object
*
* Since: 2.26
*/
GSettings *
g_settings_new_with_backend_and_path (const gchar *schema_id,
GSettingsBackend *backend,
const gchar *path)
{
g_return_val_if_fail (schema_id != NULL, NULL);
g_return_val_if_fail (G_IS_SETTINGS_BACKEND (backend), NULL);
g_return_val_if_fail (path != NULL, NULL);
return g_object_new (G_TYPE_SETTINGS,
"schema-id", schema_id,
"backend", backend,
"path", path,
NULL);
}
/**
* g_settings_new_full:
* @schema: a #GSettingsSchema
* @backend: (allow-none): a #GSettingsBackend
* @path: (allow-none): the path to use
*
* Creates a new #GSettings object with a given schema, backend and
* path.
*
* It should be extremely rare that you ever want to use this function.
* It is made available for advanced use-cases (such as plugin systems
* that want to provide access to schemas loaded from custom locations,
* etc).
*
* At the most basic level, a #GSettings object is a pure composition of
* 4 things: a #GSettingsSchema, a #GSettingsBackend, a path within that
* backend, and a #GMainContext to which signals are dispatched.
*
* This constructor therefore gives you full control over constructing
* #GSettings instances. The first 4 parameters are given directly as
* @schema, @backend and @path, and the main context is taken from the
* thread-default (as per g_settings_new()).
*
* If @backend is %NULL then the default backend is used.
*
* If @path is %NULL then the path from the schema is used. It is an
* error f @path is %NULL and the schema has no path of its own or if
* @path is non-%NULL and not equal to the path that the schema does
* have.
*
* Returns: a new #GSettings object
*
* Since: 2.32
*/
GSettings *
g_settings_new_full (GSettingsSchema *schema,
GSettingsBackend *backend,
const gchar *path)
{
return g_object_new (G_TYPE_SETTINGS,
"settings-schema", schema,
"backend", backend,
"path", path,
NULL);
}
/* Internal read/write utilities {{{1 */
static gboolean
g_settings_write_to_backend (GSettings *settings,
GSettingsSchemaKey *key,
GVariant *value)
{