1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD 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 Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gio.Settings; 26 27 private import gio.Action; 28 private import gio.ActionIF; 29 private import gio.SettingsBackend; 30 private import gio.SettingsSchema; 31 private import glib.ConstructionException; 32 private import glib.Str; 33 private import glib.Variant; 34 private import gobject.ObjectG; 35 private import gobject.Signals; 36 public import gtkc.gdktypes; 37 private import gtkc.gio; 38 public import gtkc.giotypes; 39 private import std.algorithm; 40 41 42 /** 43 * The #GSettings class provides a convenient API for storing and retrieving 44 * application settings. 45 * 46 * Reads and writes can be considered to be non-blocking. Reading 47 * settings with #GSettings is typically extremely fast: on 48 * approximately the same order of magnitude (but slower than) a 49 * #GHashTable lookup. Writing settings is also extremely fast in terms 50 * of time to return to your application, but can be extremely expensive 51 * for other threads and other processes. Many settings backends 52 * (including dconf) have lazy initialisation which means in the common 53 * case of the user using their computer without modifying any settings 54 * a lot of work can be avoided. For dconf, the D-Bus service doesn't 55 * even need to be started in this case. For this reason, you should 56 * only ever modify #GSettings keys in response to explicit user action. 57 * Particular care should be paid to ensure that modifications are not 58 * made during startup -- for example, when setting the initial value 59 * of preferences widgets. The built-in g_settings_bind() functionality 60 * is careful not to write settings in response to notify signals as a 61 * result of modifications that it makes to widgets. 62 * 63 * When creating a GSettings instance, you have to specify a schema 64 * that describes the keys in your settings and their types and default 65 * values, as well as some other information. 66 * 67 * Normally, a schema has as fixed path that determines where the settings 68 * are stored in the conceptual global tree of settings. However, schemas 69 * can also be '[relocatable][gsettings-relocatable]', i.e. not equipped with 70 * a fixed path. This is 71 * useful e.g. when the schema describes an 'account', and you want to be 72 * able to store a arbitrary number of accounts. 73 * 74 * Paths must start with and end with a forward slash character ('/') 75 * and must not contain two sequential slash characters. Paths should 76 * be chosen based on a domain name associated with the program or 77 * library to which the settings belong. Examples of paths are 78 * "/org/gtk/settings/file-chooser/" and "/ca/desrt/dconf-editor/". 79 * Paths should not start with "/apps/", "/desktop/" or "/system/" as 80 * they often did in GConf. 81 * 82 * Unlike other configuration systems (like GConf), GSettings does not 83 * restrict keys to basic types like strings and numbers. GSettings stores 84 * values as #GVariant, and allows any #GVariantType for keys. Key names 85 * are restricted to lowercase characters, numbers and '-'. Furthermore, 86 * the names must begin with a lowercase character, must not end 87 * with a '-', and must not contain consecutive dashes. 88 * 89 * Similar to GConf, the default values in GSettings schemas can be 90 * localized, but the localized values are stored in gettext catalogs 91 * and looked up with the domain that is specified in the 92 * `gettext-domain` attribute of the <schemalist> or <schema> 93 * elements and the category that is specified in the `l10n` attribute of 94 * the <default> element. The string which is translated includes all text in 95 * the <default> element, including any surrounding quotation marks. 96 * 97 * The `l10n` attribute must be set to `messages` or `time`, and sets the 98 * [locale category for 99 * translation](https://www.gnu.org/software/gettext/manual/html_node/Aspects.html#index-locale-categories-1). 100 * The `messages` category should be used by default; use `time` for 101 * translatable date or time formats. A translation comment can be added as an 102 * XML comment immediately above the <default> element — it is recommended to 103 * add these comments to aid translators understand the meaning and 104 * implications of the default value. An optional translation `context` 105 * attribute can be set on the <default> element to disambiguate multiple 106 * defaults which use the same string. 107 * 108 * For example: 109 * |[ 110 * <!-- Translators: A list of words which are not allowed to be typed, in 111 * GVariant serialization syntax. 112 * See: https://developer.gnome.org/glib/stable/gvariant-text.html --> 113 * <default l10n='messages' context='Banned words'>['bad', 'words']</default> 114 * ]| 115 * 116 * Translations of default values must remain syntactically valid serialized 117 * #GVariants (e.g. retaining any surrounding quotation marks) or runtime 118 * errors will occur. 119 * 120 * GSettings uses schemas in a compact binary form that is created 121 * by the [glib-compile-schemas][glib-compile-schemas] 122 * utility. The input is a schema description in an XML format. 123 * 124 * A DTD for the gschema XML format can be found here: 125 * [gschema.dtd](https://git.gnome.org/browse/glib/tree/gio/gschema.dtd) 126 * 127 * The [glib-compile-schemas][glib-compile-schemas] tool expects schema 128 * files to have the extension `.gschema.xml`. 129 * 130 * At runtime, schemas are identified by their id (as specified in the 131 * id attribute of the <schema> element). The convention for schema 132 * ids is to use a dotted name, similar in style to a D-Bus bus name, 133 * e.g. "org.gnome.SessionManager". In particular, if the settings are 134 * for a specific service that owns a D-Bus bus name, the D-Bus bus name 135 * and schema id should match. For schemas which deal with settings not 136 * associated with one named application, the id should not use 137 * StudlyCaps, e.g. "org.gnome.font-rendering". 138 * 139 * In addition to #GVariant types, keys can have types that have 140 * enumerated types. These can be described by a <choice>, 141 * <enum> or <flags> element, as seen in the 142 * [example][schema-enumerated]. The underlying type of such a key 143 * is string, but you can use g_settings_get_enum(), g_settings_set_enum(), 144 * g_settings_get_flags(), g_settings_set_flags() access the numeric values 145 * corresponding to the string value of enum and flags keys. 146 * 147 * An example for default value: 148 * |[ 149 * <schemalist> 150 * <schema id="org.gtk.Test" path="/org/gtk/Test/" gettext-domain="test"> 151 * 152 * <key name="greeting" type="s"> 153 * <default l10n="messages">"Hello, earthlings"</default> 154 * <summary>A greeting</summary> 155 * <description> 156 * Greeting of the invading martians 157 * </description> 158 * </key> 159 * 160 * <key name="box" type="(ii)"> 161 * <default>(20,30)</default> 162 * </key> 163 * 164 * </schema> 165 * </schemalist> 166 * ]| 167 * 168 * An example for ranges, choices and enumerated types: 169 * |[ 170 * <schemalist> 171 * 172 * <enum id="org.gtk.Test.myenum"> 173 * <value nick="first" value="1"/> 174 * <value nick="second" value="2"/> 175 * </enum> 176 * 177 * <flags id="org.gtk.Test.myflags"> 178 * <value nick="flag1" value="1"/> 179 * <value nick="flag2" value="2"/> 180 * <value nick="flag3" value="4"/> 181 * </flags> 182 * 183 * <schema id="org.gtk.Test"> 184 * 185 * <key name="key-with-range" type="i"> 186 * <range min="1" max="100"/> 187 * <default>10</default> 188 * </key> 189 * 190 * <key name="key-with-choices" type="s"> 191 * <choices> 192 * <choice value='Elisabeth'/> 193 * <choice value='Annabeth'/> 194 * <choice value='Joe'/> 195 * </choices> 196 * <aliases> 197 * <alias value='Anna' target='Annabeth'/> 198 * <alias value='Beth' target='Elisabeth'/> 199 * </aliases> 200 * <default>'Joe'</default> 201 * </key> 202 * 203 * <key name='enumerated-key' enum='org.gtk.Test.myenum'> 204 * <default>'first'</default> 205 * </key> 206 * 207 * <key name='flags-key' flags='org.gtk.Test.myflags'> 208 * <default>["flag1","flag2"]</default> 209 * </key> 210 * </schema> 211 * </schemalist> 212 * ]| 213 * 214 * ## Vendor overrides 215 * 216 * Default values are defined in the schemas that get installed by 217 * an application. Sometimes, it is necessary for a vendor or distributor 218 * to adjust these defaults. Since patching the XML source for the schema 219 * is inconvenient and error-prone, 220 * [glib-compile-schemas][glib-compile-schemas] reads so-called vendor 221 * override' files. These are keyfiles in the same directory as the XML 222 * schema sources which can override default values. The schema id serves 223 * as the group name in the key file, and the values are expected in 224 * serialized GVariant form, as in the following example: 225 * |[ 226 * [org.gtk.Example] 227 * key1='string' 228 * key2=1.5 229 * ]| 230 * 231 * glib-compile-schemas expects schema files to have the extension 232 * `.gschema.override`. 233 * 234 * ## Binding 235 * 236 * A very convenient feature of GSettings lets you bind #GObject properties 237 * directly to settings, using g_settings_bind(). Once a GObject property 238 * has been bound to a setting, changes on either side are automatically 239 * propagated to the other side. GSettings handles details like mapping 240 * between GObject and GVariant types, and preventing infinite cycles. 241 * 242 * This makes it very easy to hook up a preferences dialog to the 243 * underlying settings. To make this even more convenient, GSettings 244 * looks for a boolean property with the name "sensitivity" and 245 * automatically binds it to the writability of the bound setting. 246 * If this 'magic' gets in the way, it can be suppressed with the 247 * #G_SETTINGS_BIND_NO_SENSITIVITY flag. 248 * 249 * ## Relocatable schemas # {#gsettings-relocatable} 250 * 251 * A relocatable schema is one with no `path` attribute specified on its 252 * <schema> element. By using g_settings_new_with_path(), a #GSettings object 253 * can be instantiated for a relocatable schema, assigning a path to the 254 * instance. Paths passed to g_settings_new_with_path() will typically be 255 * constructed dynamically from a constant prefix plus some form of instance 256 * identifier; but they must still be valid GSettings paths. Paths could also 257 * be constant and used with a globally installed schema originating from a 258 * dependency library. 259 * 260 * For example, a relocatable schema could be used to store geometry information 261 * for different windows in an application. If the schema ID was 262 * `org.foo.MyApp.Window`, it could be instantiated for paths 263 * `/org/foo/MyApp/main/`, `/org/foo/MyApp/document-1/`, 264 * `/org/foo/MyApp/document-2/`, etc. If any of the paths are well-known 265 * they can be specified as <child> elements in the parent schema, e.g.: 266 * |[ 267 * <schema id="org.foo.MyApp" path="/org/foo/MyApp/"> 268 * <child name="main" schema="org.foo.MyApp.Window"/> 269 * </schema> 270 * ]| 271 * 272 * ## Build system integration # {#gsettings-build-system} 273 * 274 * GSettings comes with autotools integration to simplify compiling and 275 * installing schemas. To add GSettings support to an application, add the 276 * following to your `configure.ac`: 277 * |[ 278 * GLIB_GSETTINGS 279 * ]| 280 * 281 * In the appropriate `Makefile.am`, use the following snippet to compile and 282 * install the named schema: 283 * |[ 284 * gsettings_SCHEMAS = org.foo.MyApp.gschema.xml 285 * EXTRA_DIST = $(gsettings_SCHEMAS) 286 * 287 * @GSETTINGS_RULES@ 288 * ]| 289 * 290 * No changes are needed to the build system to mark a schema XML file for 291 * translation. Assuming it sets the `gettext-domain` attribute, a schema may 292 * be marked for translation by adding it to `POTFILES.in`, assuming gettext 293 * 0.19 is in use (the preferred method for translation): 294 * |[ 295 * data/org.foo.MyApp.gschema.xml 296 * ]| 297 * 298 * Alternatively, if intltool 0.50.1 is in use: 299 * |[ 300 * [type: gettext/gsettings]data/org.foo.MyApp.gschema.xml 301 * ]| 302 * 303 * GSettings will use gettext to look up translations for the <summary> and 304 * <description> elements, and also any <default> elements which have a `l10n` 305 * attribute set. Translations must not be included in the `.gschema.xml` file 306 * by the build system, for example by using intltool XML rules with a 307 * `.gschema.xml.in` template. 308 * 309 * If an enumerated type defined in a C header file is to be used in a GSettings 310 * schema, it can either be defined manually using an <enum> element in the 311 * schema XML, or it can be extracted automatically from the C header. This 312 * approach is preferred, as it ensures the two representations are always 313 * synchronised. To do so, add the following to the relevant `Makefile.am`: 314 * |[ 315 * gsettings_ENUM_NAMESPACE = org.foo.MyApp 316 * gsettings_ENUM_FILES = my-app-enums.h my-app-misc.h 317 * ]| 318 * 319 * `gsettings_ENUM_NAMESPACE` specifies the schema namespace for the enum files, 320 * which are specified in `gsettings_ENUM_FILES`. This will generate a 321 * `org.foo.MyApp.enums.xml` file containing the extracted enums, which will be 322 * automatically included in the schema compilation, install and uninstall 323 * rules. It should not be committed to version control or included in 324 * `EXTRA_DIST`. 325 */ 326 public class Settings : ObjectG 327 { 328 /** the main Gtk struct */ 329 protected GSettings* gSettings; 330 331 /** Get the main Gtk struct */ 332 public GSettings* getSettingsStruct() 333 { 334 return gSettings; 335 } 336 337 /** the main Gtk struct as a void* */ 338 protected override void* getStruct() 339 { 340 return cast(void*)gSettings; 341 } 342 343 protected override void setStruct(GObject* obj) 344 { 345 gSettings = cast(GSettings*)obj; 346 super.setStruct(obj); 347 } 348 349 /** 350 * Sets our main struct and passes it to the parent class. 351 */ 352 public this (GSettings* gSettings, bool ownedRef = false) 353 { 354 this.gSettings = gSettings; 355 super(cast(GObject*)gSettings, ownedRef); 356 } 357 358 359 /** */ 360 public static GType getType() 361 { 362 return g_settings_get_type(); 363 } 364 365 /** 366 * Creates a new #GSettings object with the schema specified by 367 * @schema_id. 368 * 369 * Signals on the newly created #GSettings object will be dispatched 370 * via the thread-default #GMainContext in effect at the time of the 371 * call to g_settings_new(). The new #GSettings will hold a reference 372 * on the context. See g_main_context_push_thread_default(). 373 * 374 * Params: 375 * schemaId = the id of the schema 376 * 377 * Return: a new #GSettings object 378 * 379 * Since: 2.26 380 * 381 * Throws: ConstructionException GTK+ fails to create the object. 382 */ 383 public this(string schemaId) 384 { 385 auto p = g_settings_new(Str.toStringz(schemaId)); 386 387 if(p is null) 388 { 389 throw new ConstructionException("null returned by new"); 390 } 391 392 this(cast(GSettings*) p, true); 393 } 394 395 /** 396 * Creates a new #GSettings object with a given schema, backend and 397 * path. 398 * 399 * It should be extremely rare that you ever want to use this function. 400 * It is made available for advanced use-cases (such as plugin systems 401 * that want to provide access to schemas loaded from custom locations, 402 * etc). 403 * 404 * At the most basic level, a #GSettings object is a pure composition of 405 * 4 things: a #GSettingsSchema, a #GSettingsBackend, a path within that 406 * backend, and a #GMainContext to which signals are dispatched. 407 * 408 * This constructor therefore gives you full control over constructing 409 * #GSettings instances. The first 3 parameters are given directly as 410 * @schema, @backend and @path, and the main context is taken from the 411 * thread-default (as per g_settings_new()). 412 * 413 * If @backend is %NULL then the default backend is used. 414 * 415 * If @path is %NULL then the path from the schema is used. It is an 416 * error if @path is %NULL and the schema has no path of its own or if 417 * @path is non-%NULL and not equal to the path that the schema does 418 * have. 419 * 420 * Params: 421 * schema = a #GSettingsSchema 422 * backend = a #GSettingsBackend 423 * path = the path to use 424 * 425 * Return: a new #GSettings object 426 * 427 * Since: 2.32 428 * 429 * Throws: ConstructionException GTK+ fails to create the object. 430 */ 431 public this(SettingsSchema schema, SettingsBackend backend, string path) 432 { 433 auto p = g_settings_new_full((schema is null) ? null : schema.getSettingsSchemaStruct(), (backend is null) ? null : backend.getSettingsBackendStruct(), Str.toStringz(path)); 434 435 if(p is null) 436 { 437 throw new ConstructionException("null returned by new_full"); 438 } 439 440 this(cast(GSettings*) p, true); 441 } 442 443 /** 444 * Creates a new #GSettings object with the schema specified by 445 * @schema_id and a given #GSettingsBackend. 446 * 447 * Creating a #GSettings object with a different backend allows accessing 448 * settings from a database other than the usual one. For example, it may make 449 * sense to pass a backend corresponding to the "defaults" settings database on 450 * the system to get a settings object that modifies the system default 451 * settings instead of the settings for this user. 452 * 453 * Params: 454 * schemaId = the id of the schema 455 * backend = the #GSettingsBackend to use 456 * 457 * Return: a new #GSettings object 458 * 459 * Since: 2.26 460 * 461 * Throws: ConstructionException GTK+ fails to create the object. 462 */ 463 public this(string schemaId, SettingsBackend backend) 464 { 465 auto p = g_settings_new_with_backend(Str.toStringz(schemaId), (backend is null) ? null : backend.getSettingsBackendStruct()); 466 467 if(p is null) 468 { 469 throw new ConstructionException("null returned by new_with_backend"); 470 } 471 472 this(cast(GSettings*) p, true); 473 } 474 475 /** 476 * Creates a new #GSettings object with the schema specified by 477 * @schema_id and a given #GSettingsBackend and path. 478 * 479 * This is a mix of g_settings_new_with_backend() and 480 * g_settings_new_with_path(). 481 * 482 * Params: 483 * schemaId = the id of the schema 484 * backend = the #GSettingsBackend to use 485 * path = the path to use 486 * 487 * Return: a new #GSettings object 488 * 489 * Since: 2.26 490 * 491 * Throws: ConstructionException GTK+ fails to create the object. 492 */ 493 public this(string schemaId, SettingsBackend backend, string path) 494 { 495 auto p = g_settings_new_with_backend_and_path(Str.toStringz(schemaId), (backend is null) ? null : backend.getSettingsBackendStruct(), Str.toStringz(path)); 496 497 if(p is null) 498 { 499 throw new ConstructionException("null returned by new_with_backend_and_path"); 500 } 501 502 this(cast(GSettings*) p, true); 503 } 504 505 /** 506 * Creates a new #GSettings object with the relocatable schema specified 507 * by @schema_id and a given path. 508 * 509 * You only need to do this if you want to directly create a settings 510 * object with a schema that doesn't have a specified path of its own. 511 * That's quite rare. 512 * 513 * It is a programmer error to call this function for a schema that 514 * has an explicitly specified path. 515 * 516 * It is a programmer error if @path is not a valid path. A valid path 517 * begins and ends with '/' and does not contain two consecutive '/' 518 * characters. 519 * 520 * Params: 521 * schemaId = the id of the schema 522 * path = the path to use 523 * 524 * Return: a new #GSettings object 525 * 526 * Since: 2.26 527 * 528 * Throws: ConstructionException GTK+ fails to create the object. 529 */ 530 public this(string schemaId, string path) 531 { 532 auto p = g_settings_new_with_path(Str.toStringz(schemaId), Str.toStringz(path)); 533 534 if(p is null) 535 { 536 throw new ConstructionException("null returned by new_with_path"); 537 } 538 539 this(cast(GSettings*) p, true); 540 } 541 542 /** 543 * <!-- --> 544 * 545 * Deprecated: Use g_settings_schema_source_list_schemas() instead 546 * 547 * Return: a list of relocatable 548 * #GSettings schemas that are available. The list must not be 549 * modified or freed. 550 * 551 * Since: 2.28 552 */ 553 public static string[] listRelocatableSchemas() 554 { 555 return Str.toStringArray(g_settings_list_relocatable_schemas()); 556 } 557 558 /** 559 * <!-- --> 560 * 561 * Deprecated: Use g_settings_schema_source_list_schemas() instead. 562 * If you used g_settings_list_schemas() to check for the presence of 563 * a particular schema, use g_settings_schema_source_lookup() instead 564 * of your whole loop. 565 * 566 * Return: a list of #GSettings 567 * schemas that are available. The list must not be modified or 568 * freed. 569 * 570 * Since: 2.26 571 */ 572 public static string[] listSchemas() 573 { 574 return Str.toStringArray(g_settings_list_schemas()); 575 } 576 577 /** 578 * Ensures that all pending operations for the given are complete for 579 * the default backend. 580 * 581 * Writes made to a #GSettings are handled asynchronously. For this 582 * reason, it is very unlikely that the changes have it to disk by the 583 * time g_settings_set() returns. 584 * 585 * This call will block until all of the writes have made it to the 586 * backend. Since the mainloop is not running, no change notifications 587 * will be dispatched during this call (but some may be queued by the 588 * time the call is done). 589 */ 590 public static void sync() 591 { 592 g_settings_sync(); 593 } 594 595 /** 596 * Removes an existing binding for @property on @object. 597 * 598 * Note that bindings are automatically removed when the 599 * object is finalized, so it is rarely necessary to call this 600 * function. 601 * 602 * Params: 603 * object = the object 604 * property = the property whose binding is removed 605 * 606 * Since: 2.26 607 */ 608 public static void unbind(ObjectG object, string property) 609 { 610 g_settings_unbind((object is null) ? null : object.getObjectGStruct(), Str.toStringz(property)); 611 } 612 613 /** 614 * Applies any changes that have been made to the settings. This 615 * function does nothing unless @settings is in 'delay-apply' mode; 616 * see g_settings_delay(). In the normal case settings are always 617 * applied immediately. 618 */ 619 public void apply() 620 { 621 g_settings_apply(gSettings); 622 } 623 624 /** 625 * Create a binding between the @key in the @settings object 626 * and the property @property of @object. 627 * 628 * The binding uses the default GIO mapping functions to map 629 * between the settings and property values. These functions 630 * handle booleans, numeric types and string types in a 631 * straightforward way. Use g_settings_bind_with_mapping() if 632 * you need a custom mapping, or map between types that are not 633 * supported by the default mapping functions. 634 * 635 * Unless the @flags include %G_SETTINGS_BIND_NO_SENSITIVITY, this 636 * function also establishes a binding between the writability of 637 * @key and the "sensitive" property of @object (if @object has 638 * a boolean property by that name). See g_settings_bind_writable() 639 * for more details about writable bindings. 640 * 641 * Note that the lifecycle of the binding is tied to the object, 642 * and that you can have only one binding per object property. 643 * If you bind the same property twice on the same object, the second 644 * binding overrides the first one. 645 * 646 * Params: 647 * key = the key to bind 648 * object = a #GObject 649 * property = the name of the property to bind 650 * flags = flags for the binding 651 * 652 * Since: 2.26 653 */ 654 public void bind(string key, ObjectG object, string property, GSettingsBindFlags flags) 655 { 656 g_settings_bind(gSettings, Str.toStringz(key), (object is null) ? null : object.getObjectGStruct(), Str.toStringz(property), flags); 657 } 658 659 /** 660 * Create a binding between the @key in the @settings object 661 * and the property @property of @object. 662 * 663 * The binding uses the provided mapping functions to map between 664 * settings and property values. 665 * 666 * Note that the lifecycle of the binding is tied to the object, 667 * and that you can have only one binding per object property. 668 * If you bind the same property twice on the same object, the second 669 * binding overrides the first one. 670 * 671 * Params: 672 * key = the key to bind 673 * object = a #GObject 674 * property = the name of the property to bind 675 * flags = flags for the binding 676 * getMapping = a function that gets called to convert values 677 * from @settings to @object, or %NULL to use the default GIO mapping 678 * setMapping = a function that gets called to convert values 679 * from @object to @settings, or %NULL to use the default GIO mapping 680 * userData = data that gets passed to @get_mapping and @set_mapping 681 * destroy = #GDestroyNotify function for @user_data 682 * 683 * Since: 2.26 684 */ 685 public void bindWithMapping(string key, ObjectG object, string property, GSettingsBindFlags flags, GSettingsBindGetMapping getMapping, GSettingsBindSetMapping setMapping, void* userData, GDestroyNotify destroy) 686 { 687 g_settings_bind_with_mapping(gSettings, Str.toStringz(key), (object is null) ? null : object.getObjectGStruct(), Str.toStringz(property), flags, getMapping, setMapping, userData, destroy); 688 } 689 690 /** 691 * Create a binding between the writability of @key in the 692 * @settings object and the property @property of @object. 693 * The property must be boolean; "sensitive" or "visible" 694 * properties of widgets are the most likely candidates. 695 * 696 * Writable bindings are always uni-directional; changes of the 697 * writability of the setting will be propagated to the object 698 * property, not the other way. 699 * 700 * When the @inverted argument is %TRUE, the binding inverts the 701 * value as it passes from the setting to the object, i.e. @property 702 * will be set to %TRUE if the key is not writable. 703 * 704 * Note that the lifecycle of the binding is tied to the object, 705 * and that you can have only one binding per object property. 706 * If you bind the same property twice on the same object, the second 707 * binding overrides the first one. 708 * 709 * Params: 710 * key = the key to bind 711 * object = a #GObject 712 * property = the name of a boolean property to bind 713 * inverted = whether to 'invert' the value 714 * 715 * Since: 2.26 716 */ 717 public void bindWritable(string key, ObjectG object, string property, bool inverted) 718 { 719 g_settings_bind_writable(gSettings, Str.toStringz(key), (object is null) ? null : object.getObjectGStruct(), Str.toStringz(property), inverted); 720 } 721 722 /** 723 * Creates a #GAction corresponding to a given #GSettings key. 724 * 725 * The action has the same name as the key. 726 * 727 * The value of the key becomes the state of the action and the action 728 * is enabled when the key is writable. Changing the state of the 729 * action results in the key being written to. Changes to the value or 730 * writability of the key cause appropriate change notifications to be 731 * emitted for the action. 732 * 733 * For boolean-valued keys, action activations take no parameter and 734 * result in the toggling of the value. For all other types, 735 * activations take the new value for the key (which must have the 736 * correct type). 737 * 738 * Params: 739 * key = the name of a key in @settings 740 * 741 * Return: a new #GAction 742 * 743 * Since: 2.32 744 */ 745 public ActionIF createAction(string key) 746 { 747 auto p = g_settings_create_action(gSettings, Str.toStringz(key)); 748 749 if(p is null) 750 { 751 return null; 752 } 753 754 return ObjectG.getDObject!(Action, ActionIF)(cast(GAction*) p, true); 755 } 756 757 /** 758 * Changes the #GSettings object into 'delay-apply' mode. In this 759 * mode, changes to @settings are not immediately propagated to the 760 * backend, but kept locally until g_settings_apply() is called. 761 * 762 * Since: 2.26 763 */ 764 public void delay() 765 { 766 g_settings_delay(gSettings); 767 } 768 769 /** 770 * Gets the value that is stored at @key in @settings. 771 * 772 * A convenience variant of g_settings_get() for booleans. 773 * 774 * It is a programmer error to give a @key that isn't specified as 775 * having a boolean type in the schema for @settings. 776 * 777 * Params: 778 * key = the key to get the value for 779 * 780 * Return: a boolean 781 * 782 * Since: 2.26 783 */ 784 public bool getBoolean(string key) 785 { 786 return g_settings_get_boolean(gSettings, Str.toStringz(key)) != 0; 787 } 788 789 /** 790 * Creates a child settings object which has a base path of 791 * `base-path/@name`, where `base-path` is the base path of 792 * @settings. 793 * 794 * The schema for the child settings object must have been declared 795 * in the schema of @settings using a <child> element. 796 * 797 * Params: 798 * name = the name of the child schema 799 * 800 * Return: a 'child' settings object 801 * 802 * Since: 2.26 803 */ 804 public Settings getChild(string name) 805 { 806 auto p = g_settings_get_child(gSettings, Str.toStringz(name)); 807 808 if(p is null) 809 { 810 return null; 811 } 812 813 return ObjectG.getDObject!(Settings)(cast(GSettings*) p, true); 814 } 815 816 /** 817 * Gets the "default value" of a key. 818 * 819 * This is the value that would be read if g_settings_reset() were to be 820 * called on the key. 821 * 822 * Note that this may be a different value than returned by 823 * g_settings_schema_key_get_default_value() if the system administrator 824 * has provided a default value. 825 * 826 * Comparing the return values of g_settings_get_default_value() and 827 * g_settings_get_value() is not sufficient for determining if a value 828 * has been set because the user may have explicitly set the value to 829 * something that happens to be equal to the default. The difference 830 * here is that if the default changes in the future, the user's key 831 * will still be set. 832 * 833 * This function may be useful for adding an indication to a UI of what 834 * the default value was before the user set it. 835 * 836 * It is a programmer error to give a @key that isn't contained in the 837 * schema for @settings. 838 * 839 * Params: 840 * key = the key to get the default value for 841 * 842 * Return: the default value 843 * 844 * Since: 2.40 845 */ 846 public Variant getDefaultValue(string key) 847 { 848 auto p = g_settings_get_default_value(gSettings, Str.toStringz(key)); 849 850 if(p is null) 851 { 852 return null; 853 } 854 855 return new Variant(cast(GVariant*) p, true); 856 } 857 858 /** 859 * Gets the value that is stored at @key in @settings. 860 * 861 * A convenience variant of g_settings_get() for doubles. 862 * 863 * It is a programmer error to give a @key that isn't specified as 864 * having a 'double' type in the schema for @settings. 865 * 866 * Params: 867 * key = the key to get the value for 868 * 869 * Return: a double 870 * 871 * Since: 2.26 872 */ 873 public double getDouble(string key) 874 { 875 return g_settings_get_double(gSettings, Str.toStringz(key)); 876 } 877 878 /** 879 * Gets the value that is stored in @settings for @key and converts it 880 * to the enum value that it represents. 881 * 882 * In order to use this function the type of the value must be a string 883 * and it must be marked in the schema file as an enumerated type. 884 * 885 * It is a programmer error to give a @key that isn't contained in the 886 * schema for @settings or is not marked as an enumerated type. 887 * 888 * If the value stored in the configuration database is not a valid 889 * value for the enumerated type then this function will return the 890 * default value. 891 * 892 * Params: 893 * key = the key to get the value for 894 * 895 * Return: the enum value 896 * 897 * Since: 2.26 898 */ 899 public int getEnum(string key) 900 { 901 return g_settings_get_enum(gSettings, Str.toStringz(key)); 902 } 903 904 /** 905 * Gets the value that is stored in @settings for @key and converts it 906 * to the flags value that it represents. 907 * 908 * In order to use this function the type of the value must be an array 909 * of strings and it must be marked in the schema file as an flags type. 910 * 911 * It is a programmer error to give a @key that isn't contained in the 912 * schema for @settings or is not marked as a flags type. 913 * 914 * If the value stored in the configuration database is not a valid 915 * value for the flags type then this function will return the default 916 * value. 917 * 918 * Params: 919 * key = the key to get the value for 920 * 921 * Return: the flags value 922 * 923 * Since: 2.26 924 */ 925 public uint getFlags(string key) 926 { 927 return g_settings_get_flags(gSettings, Str.toStringz(key)); 928 } 929 930 /** 931 * Returns whether the #GSettings object has any unapplied 932 * changes. This can only be the case if it is in 'delayed-apply' mode. 933 * 934 * Return: %TRUE if @settings has unapplied changes 935 * 936 * Since: 2.26 937 */ 938 public bool getHasUnapplied() 939 { 940 return g_settings_get_has_unapplied(gSettings) != 0; 941 } 942 943 /** 944 * Gets the value that is stored at @key in @settings. 945 * 946 * A convenience variant of g_settings_get() for 32-bit integers. 947 * 948 * It is a programmer error to give a @key that isn't specified as 949 * having a int32 type in the schema for @settings. 950 * 951 * Params: 952 * key = the key to get the value for 953 * 954 * Return: an integer 955 * 956 * Since: 2.26 957 */ 958 public int getInt(string key) 959 { 960 return g_settings_get_int(gSettings, Str.toStringz(key)); 961 } 962 963 /** 964 * Gets the value that is stored at @key in @settings. 965 * 966 * A convenience variant of g_settings_get() for 64-bit integers. 967 * 968 * It is a programmer error to give a @key that isn't specified as 969 * having a int64 type in the schema for @settings. 970 * 971 * Params: 972 * key = the key to get the value for 973 * 974 * Return: a 64-bit integer 975 * 976 * Since: 2.50 977 */ 978 public long getInt64(string key) 979 { 980 return g_settings_get_int64(gSettings, Str.toStringz(key)); 981 } 982 983 /** 984 * Gets the value that is stored at @key in @settings, subject to 985 * application-level validation/mapping. 986 * 987 * You should use this function when the application needs to perform 988 * some processing on the value of the key (for example, parsing). The 989 * @mapping function performs that processing. If the function 990 * indicates that the processing was unsuccessful (due to a parse error, 991 * for example) then the mapping is tried again with another value. 992 * 993 * This allows a robust 'fall back to defaults' behaviour to be 994 * implemented somewhat automatically. 995 * 996 * The first value that is tried is the user's setting for the key. If 997 * the mapping function fails to map this value, other values may be 998 * tried in an unspecified order (system or site defaults, translated 999 * schema default values, untranslated schema default values, etc). 1000 * 1001 * If the mapping function fails for all possible values, one additional 1002 * attempt is made: the mapping function is called with a %NULL value. 1003 * If the mapping function still indicates failure at this point then 1004 * the application will be aborted. 1005 * 1006 * The result parameter for the @mapping function is pointed to a 1007 * #gpointer which is initially set to %NULL. The same pointer is given 1008 * to each invocation of @mapping. The final value of that #gpointer is 1009 * what is returned by this function. %NULL is valid; it is returned 1010 * just as any other value would be. 1011 * 1012 * Params: 1013 * key = the key to get the value for 1014 * mapping = the function to map the value in the 1015 * settings database to the value used by the application 1016 * userData = user data for @mapping 1017 * 1018 * Return: the result, which may be %NULL 1019 */ 1020 public void* getMapped(string key, GSettingsGetMapping mapping, void* userData) 1021 { 1022 return g_settings_get_mapped(gSettings, Str.toStringz(key), mapping, userData); 1023 } 1024 1025 /** 1026 * Queries the range of a key. 1027 * 1028 * Deprecated: Use g_settings_schema_key_get_range() instead. 1029 * 1030 * Params: 1031 * key = the key to query the range of 1032 * 1033 * Since: 2.28 1034 */ 1035 public Variant getRange(string key) 1036 { 1037 auto p = g_settings_get_range(gSettings, Str.toStringz(key)); 1038 1039 if(p is null) 1040 { 1041 return null; 1042 } 1043 1044 return new Variant(cast(GVariant*) p, true); 1045 } 1046 1047 /** 1048 * Gets the value that is stored at @key in @settings. 1049 * 1050 * A convenience variant of g_settings_get() for strings. 1051 * 1052 * It is a programmer error to give a @key that isn't specified as 1053 * having a string type in the schema for @settings. 1054 * 1055 * Params: 1056 * key = the key to get the value for 1057 * 1058 * Return: a newly-allocated string 1059 * 1060 * Since: 2.26 1061 */ 1062 public string getString(string key) 1063 { 1064 auto retStr = g_settings_get_string(gSettings, Str.toStringz(key)); 1065 1066 scope(exit) Str.freeString(retStr); 1067 return Str.toString(retStr); 1068 } 1069 1070 /** 1071 * A convenience variant of g_settings_get() for string arrays. 1072 * 1073 * It is a programmer error to give a @key that isn't specified as 1074 * having an array of strings type in the schema for @settings. 1075 * 1076 * Params: 1077 * key = the key to get the value for 1078 * 1079 * Return: a 1080 * newly-allocated, %NULL-terminated array of strings, the value that 1081 * is stored at @key in @settings. 1082 * 1083 * Since: 2.26 1084 */ 1085 public string[] getStrv(string key) 1086 { 1087 auto retStr = g_settings_get_strv(gSettings, Str.toStringz(key)); 1088 1089 scope(exit) Str.freeStringArray(retStr); 1090 return Str.toStringArray(retStr); 1091 } 1092 1093 /** 1094 * Gets the value that is stored at @key in @settings. 1095 * 1096 * A convenience variant of g_settings_get() for 32-bit unsigned 1097 * integers. 1098 * 1099 * It is a programmer error to give a @key that isn't specified as 1100 * having a uint32 type in the schema for @settings. 1101 * 1102 * Params: 1103 * key = the key to get the value for 1104 * 1105 * Return: an unsigned integer 1106 * 1107 * Since: 2.30 1108 */ 1109 public uint getUint(string key) 1110 { 1111 return g_settings_get_uint(gSettings, Str.toStringz(key)); 1112 } 1113 1114 /** 1115 * Gets the value that is stored at @key in @settings. 1116 * 1117 * A convenience variant of g_settings_get() for 64-bit unsigned 1118 * integers. 1119 * 1120 * It is a programmer error to give a @key that isn't specified as 1121 * having a uint64 type in the schema for @settings. 1122 * 1123 * Params: 1124 * key = the key to get the value for 1125 * 1126 * Return: a 64-bit unsigned integer 1127 * 1128 * Since: 2.50 1129 */ 1130 public ulong getUint64(string key) 1131 { 1132 return g_settings_get_uint64(gSettings, Str.toStringz(key)); 1133 } 1134 1135 /** 1136 * Checks the "user value" of a key, if there is one. 1137 * 1138 * The user value of a key is the last value that was set by the user. 1139 * 1140 * After calling g_settings_reset() this function should always return 1141 * %NULL (assuming something is not wrong with the system 1142 * configuration). 1143 * 1144 * It is possible that g_settings_get_value() will return a different 1145 * value than this function. This can happen in the case that the user 1146 * set a value for a key that was subsequently locked down by the system 1147 * administrator -- this function will return the user's old value. 1148 * 1149 * This function may be useful for adding a "reset" option to a UI or 1150 * for providing indication that a particular value has been changed. 1151 * 1152 * It is a programmer error to give a @key that isn't contained in the 1153 * schema for @settings. 1154 * 1155 * Params: 1156 * key = the key to get the user value for 1157 * 1158 * Return: the user's value, if set 1159 * 1160 * Since: 2.40 1161 */ 1162 public Variant getUserValue(string key) 1163 { 1164 auto p = g_settings_get_user_value(gSettings, Str.toStringz(key)); 1165 1166 if(p is null) 1167 { 1168 return null; 1169 } 1170 1171 return new Variant(cast(GVariant*) p, true); 1172 } 1173 1174 /** 1175 * Gets the value that is stored in @settings for @key. 1176 * 1177 * It is a programmer error to give a @key that isn't contained in the 1178 * schema for @settings. 1179 * 1180 * Params: 1181 * key = the key to get the value for 1182 * 1183 * Return: a new #GVariant 1184 * 1185 * Since: 2.26 1186 */ 1187 public Variant getValue(string key) 1188 { 1189 auto p = g_settings_get_value(gSettings, Str.toStringz(key)); 1190 1191 if(p is null) 1192 { 1193 return null; 1194 } 1195 1196 return new Variant(cast(GVariant*) p, true); 1197 } 1198 1199 /** 1200 * Finds out if a key can be written or not 1201 * 1202 * Params: 1203 * name = the name of a key 1204 * 1205 * Return: %TRUE if the key @name is writable 1206 * 1207 * Since: 2.26 1208 */ 1209 public bool isWritable(string name) 1210 { 1211 return g_settings_is_writable(gSettings, Str.toStringz(name)) != 0; 1212 } 1213 1214 /** 1215 * Gets the list of children on @settings. 1216 * 1217 * The list is exactly the list of strings for which it is not an error 1218 * to call g_settings_get_child(). 1219 * 1220 * For GSettings objects that are lists, this value can change at any 1221 * time and you should connect to the "children-changed" signal to watch 1222 * for those changes. Note that there is a race condition here: you may 1223 * request a child after listing it only for it to have been destroyed 1224 * in the meantime. For this reason, g_settings_get_child() may return 1225 * %NULL even for a child that was listed by this function. 1226 * 1227 * For GSettings objects that are not lists, you should probably not be 1228 * calling this function from "normal" code (since you should already 1229 * know what children are in your schema). This function may still be 1230 * useful there for introspection reasons, however. 1231 * 1232 * You should free the return value with g_strfreev() when you are done 1233 * with it. 1234 * 1235 * Return: a list of the children on @settings 1236 */ 1237 public string[] listChildren() 1238 { 1239 auto retStr = g_settings_list_children(gSettings); 1240 1241 scope(exit) Str.freeStringArray(retStr); 1242 return Str.toStringArray(retStr); 1243 } 1244 1245 /** 1246 * Introspects the list of keys on @settings. 1247 * 1248 * You should probably not be calling this function from "normal" code 1249 * (since you should already know what keys are in your schema). This 1250 * function is intended for introspection reasons. 1251 * 1252 * You should free the return value with g_strfreev() when you are done 1253 * with it. 1254 * 1255 * Return: a list of the keys on @settings 1256 */ 1257 public string[] listKeys() 1258 { 1259 auto retStr = g_settings_list_keys(gSettings); 1260 1261 scope(exit) Str.freeStringArray(retStr); 1262 return Str.toStringArray(retStr); 1263 } 1264 1265 /** 1266 * Checks if the given @value is of the correct type and within the 1267 * permitted range for @key. 1268 * 1269 * Deprecated: Use g_settings_schema_key_range_check() instead. 1270 * 1271 * Params: 1272 * key = the key to check 1273 * value = the value to check 1274 * 1275 * Return: %TRUE if @value is valid for @key 1276 * 1277 * Since: 2.28 1278 */ 1279 public bool rangeCheck(string key, Variant value) 1280 { 1281 return g_settings_range_check(gSettings, Str.toStringz(key), (value is null) ? null : value.getVariantStruct()) != 0; 1282 } 1283 1284 /** 1285 * Resets @key to its default value. 1286 * 1287 * This call resets the key, as much as possible, to its default value. 1288 * That might the value specified in the schema or the one set by the 1289 * administrator. 1290 * 1291 * Params: 1292 * key = the name of a key 1293 */ 1294 public void reset(string key) 1295 { 1296 g_settings_reset(gSettings, Str.toStringz(key)); 1297 } 1298 1299 /** 1300 * Reverts all non-applied changes to the settings. This function 1301 * does nothing unless @settings is in 'delay-apply' mode; see 1302 * g_settings_delay(). In the normal case settings are always applied 1303 * immediately. 1304 * 1305 * Change notifications will be emitted for affected keys. 1306 */ 1307 public void revert() 1308 { 1309 g_settings_revert(gSettings); 1310 } 1311 1312 /** 1313 * Sets @key in @settings to @value. 1314 * 1315 * A convenience variant of g_settings_set() for booleans. 1316 * 1317 * It is a programmer error to give a @key that isn't specified as 1318 * having a boolean type in the schema for @settings. 1319 * 1320 * Params: 1321 * key = the name of the key to set 1322 * value = the value to set it to 1323 * 1324 * Return: %TRUE if setting the key succeeded, 1325 * %FALSE if the key was not writable 1326 * 1327 * Since: 2.26 1328 */ 1329 public bool setBoolean(string key, bool value) 1330 { 1331 return g_settings_set_boolean(gSettings, Str.toStringz(key), value) != 0; 1332 } 1333 1334 /** 1335 * Sets @key in @settings to @value. 1336 * 1337 * A convenience variant of g_settings_set() for doubles. 1338 * 1339 * It is a programmer error to give a @key that isn't specified as 1340 * having a 'double' type in the schema for @settings. 1341 * 1342 * Params: 1343 * key = the name of the key to set 1344 * value = the value to set it to 1345 * 1346 * Return: %TRUE if setting the key succeeded, 1347 * %FALSE if the key was not writable 1348 * 1349 * Since: 2.26 1350 */ 1351 public bool setDouble(string key, double value) 1352 { 1353 return g_settings_set_double(gSettings, Str.toStringz(key), value) != 0; 1354 } 1355 1356 /** 1357 * Looks up the enumerated type nick for @value and writes it to @key, 1358 * within @settings. 1359 * 1360 * It is a programmer error to give a @key that isn't contained in the 1361 * schema for @settings or is not marked as an enumerated type, or for 1362 * @value not to be a valid value for the named type. 1363 * 1364 * After performing the write, accessing @key directly with 1365 * g_settings_get_string() will return the 'nick' associated with 1366 * @value. 1367 * 1368 * Params: 1369 * key = a key, within @settings 1370 * value = an enumerated value 1371 * 1372 * Return: %TRUE, if the set succeeds 1373 */ 1374 public bool setEnum(string key, int value) 1375 { 1376 return g_settings_set_enum(gSettings, Str.toStringz(key), value) != 0; 1377 } 1378 1379 /** 1380 * Looks up the flags type nicks for the bits specified by @value, puts 1381 * them in an array of strings and writes the array to @key, within 1382 * @settings. 1383 * 1384 * It is a programmer error to give a @key that isn't contained in the 1385 * schema for @settings or is not marked as a flags type, or for @value 1386 * to contain any bits that are not value for the named type. 1387 * 1388 * After performing the write, accessing @key directly with 1389 * g_settings_get_strv() will return an array of 'nicks'; one for each 1390 * bit in @value. 1391 * 1392 * Params: 1393 * key = a key, within @settings 1394 * value = a flags value 1395 * 1396 * Return: %TRUE, if the set succeeds 1397 */ 1398 public bool setFlags(string key, uint value) 1399 { 1400 return g_settings_set_flags(gSettings, Str.toStringz(key), value) != 0; 1401 } 1402 1403 /** 1404 * Sets @key in @settings to @value. 1405 * 1406 * A convenience variant of g_settings_set() for 32-bit integers. 1407 * 1408 * It is a programmer error to give a @key that isn't specified as 1409 * having a int32 type in the schema for @settings. 1410 * 1411 * Params: 1412 * key = the name of the key to set 1413 * value = the value to set it to 1414 * 1415 * Return: %TRUE if setting the key succeeded, 1416 * %FALSE if the key was not writable 1417 * 1418 * Since: 2.26 1419 */ 1420 public bool setInt(string key, int value) 1421 { 1422 return g_settings_set_int(gSettings, Str.toStringz(key), value) != 0; 1423 } 1424 1425 /** 1426 * Sets @key in @settings to @value. 1427 * 1428 * A convenience variant of g_settings_set() for 64-bit integers. 1429 * 1430 * It is a programmer error to give a @key that isn't specified as 1431 * having a int64 type in the schema for @settings. 1432 * 1433 * Params: 1434 * key = the name of the key to set 1435 * value = the value to set it to 1436 * 1437 * Return: %TRUE if setting the key succeeded, 1438 * %FALSE if the key was not writable 1439 * 1440 * Since: 2.50 1441 */ 1442 public bool setInt64(string key, long value) 1443 { 1444 return g_settings_set_int64(gSettings, Str.toStringz(key), value) != 0; 1445 } 1446 1447 /** 1448 * Sets @key in @settings to @value. 1449 * 1450 * A convenience variant of g_settings_set() for strings. 1451 * 1452 * It is a programmer error to give a @key that isn't specified as 1453 * having a string type in the schema for @settings. 1454 * 1455 * Params: 1456 * key = the name of the key to set 1457 * value = the value to set it to 1458 * 1459 * Return: %TRUE if setting the key succeeded, 1460 * %FALSE if the key was not writable 1461 * 1462 * Since: 2.26 1463 */ 1464 public bool setString(string key, string value) 1465 { 1466 return g_settings_set_string(gSettings, Str.toStringz(key), Str.toStringz(value)) != 0; 1467 } 1468 1469 /** 1470 * Sets @key in @settings to @value. 1471 * 1472 * A convenience variant of g_settings_set() for string arrays. If 1473 * @value is %NULL, then @key is set to be the empty array. 1474 * 1475 * It is a programmer error to give a @key that isn't specified as 1476 * having an array of strings type in the schema for @settings. 1477 * 1478 * Params: 1479 * key = the name of the key to set 1480 * value = the value to set it to, or %NULL 1481 * 1482 * Return: %TRUE if setting the key succeeded, 1483 * %FALSE if the key was not writable 1484 * 1485 * Since: 2.26 1486 */ 1487 public bool setStrv(string key, string[] value) 1488 { 1489 return g_settings_set_strv(gSettings, Str.toStringz(key), Str.toStringzArray(value)) != 0; 1490 } 1491 1492 /** 1493 * Sets @key in @settings to @value. 1494 * 1495 * A convenience variant of g_settings_set() for 32-bit unsigned 1496 * integers. 1497 * 1498 * It is a programmer error to give a @key that isn't specified as 1499 * having a uint32 type in the schema for @settings. 1500 * 1501 * Params: 1502 * key = the name of the key to set 1503 * value = the value to set it to 1504 * 1505 * Return: %TRUE if setting the key succeeded, 1506 * %FALSE if the key was not writable 1507 * 1508 * Since: 2.30 1509 */ 1510 public bool setUint(string key, uint value) 1511 { 1512 return g_settings_set_uint(gSettings, Str.toStringz(key), value) != 0; 1513 } 1514 1515 /** 1516 * Sets @key in @settings to @value. 1517 * 1518 * A convenience variant of g_settings_set() for 64-bit unsigned 1519 * integers. 1520 * 1521 * It is a programmer error to give a @key that isn't specified as 1522 * having a uint64 type in the schema for @settings. 1523 * 1524 * Params: 1525 * key = the name of the key to set 1526 * value = the value to set it to 1527 * 1528 * Return: %TRUE if setting the key succeeded, 1529 * %FALSE if the key was not writable 1530 * 1531 * Since: 2.50 1532 */ 1533 public bool setUint64(string key, ulong value) 1534 { 1535 return g_settings_set_uint64(gSettings, Str.toStringz(key), value) != 0; 1536 } 1537 1538 /** 1539 * Sets @key in @settings to @value. 1540 * 1541 * It is a programmer error to give a @key that isn't contained in the 1542 * schema for @settings or for @value to have the incorrect type, per 1543 * the schema. 1544 * 1545 * If @value is floating then this function consumes the reference. 1546 * 1547 * Params: 1548 * key = the name of the key to set 1549 * value = a #GVariant of the correct type 1550 * 1551 * Return: %TRUE if setting the key succeeded, 1552 * %FALSE if the key was not writable 1553 * 1554 * Since: 2.26 1555 */ 1556 public bool setValue(string key, Variant value) 1557 { 1558 return g_settings_set_value(gSettings, Str.toStringz(key), (value is null) ? null : value.getVariantStruct()) != 0; 1559 } 1560 1561 protected class OnChangeDelegateWrapper 1562 { 1563 bool delegate(void*, int, Settings) dlg; 1564 gulong handlerId; 1565 ConnectFlags flags; 1566 this(bool delegate(void*, int, Settings) dlg, gulong handlerId, ConnectFlags flags) 1567 { 1568 this.dlg = dlg; 1569 this.handlerId = handlerId; 1570 this.flags = flags; 1571 } 1572 } 1573 protected OnChangeDelegateWrapper[] onChangeListeners; 1574 1575 /** 1576 * The "change-event" signal is emitted once per change event that 1577 * affects this settings object. You should connect to this signal 1578 * only if you are interested in viewing groups of changes before they 1579 * are split out into multiple emissions of the "changed" signal. 1580 * For most use cases it is more appropriate to use the "changed" signal. 1581 * 1582 * In the event that the change event applies to one or more specified 1583 * keys, @keys will be an array of #GQuark of length @n_keys. In the 1584 * event that the change event applies to the #GSettings object as a 1585 * whole (ie: potentially every key has been changed) then @keys will 1586 * be %NULL and @n_keys will be 0. 1587 * 1588 * The default handler for this signal invokes the "changed" signal 1589 * for each affected key. If any other connected handler returns 1590 * %TRUE then this default functionality will be suppressed. 1591 * 1592 * Params: 1593 * keys = an array of #GQuarks for the changed keys, or %NULL 1594 * nKeys = the length of the @keys array, or 0 1595 * 1596 * Return: %TRUE to stop other handlers from being invoked for the 1597 * event. FALSE to propagate the event further. 1598 */ 1599 gulong addOnChange(bool delegate(void*, int, Settings) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1600 { 1601 onChangeListeners ~= new OnChangeDelegateWrapper(dlg, 0, connectFlags); 1602 onChangeListeners[onChangeListeners.length - 1].handlerId = Signals.connectData( 1603 this, 1604 "change-event", 1605 cast(GCallback)&callBackChange, 1606 cast(void*)onChangeListeners[onChangeListeners.length - 1], 1607 cast(GClosureNotify)&callBackChangeDestroy, 1608 connectFlags); 1609 return onChangeListeners[onChangeListeners.length - 1].handlerId; 1610 } 1611 1612 extern(C) static int callBackChange(GSettings* settingsStruct, void* keys, int nKeys,OnChangeDelegateWrapper wrapper) 1613 { 1614 return wrapper.dlg(keys, nKeys, wrapper.outer); 1615 } 1616 1617 extern(C) static void callBackChangeDestroy(OnChangeDelegateWrapper wrapper, GClosure* closure) 1618 { 1619 wrapper.outer.internalRemoveOnChange(wrapper); 1620 } 1621 1622 protected void internalRemoveOnChange(OnChangeDelegateWrapper source) 1623 { 1624 foreach(index, wrapper; onChangeListeners) 1625 { 1626 if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId) 1627 { 1628 onChangeListeners[index] = null; 1629 onChangeListeners = std.algorithm.remove(onChangeListeners, index); 1630 break; 1631 } 1632 } 1633 } 1634 1635 1636 protected class OnChangedDelegateWrapper 1637 { 1638 void delegate(string, Settings) dlg; 1639 gulong handlerId; 1640 ConnectFlags flags; 1641 this(void delegate(string, Settings) dlg, gulong handlerId, ConnectFlags flags) 1642 { 1643 this.dlg = dlg; 1644 this.handlerId = handlerId; 1645 this.flags = flags; 1646 } 1647 } 1648 protected OnChangedDelegateWrapper[] onChangedListeners; 1649 1650 /** 1651 * The "changed" signal is emitted when a key has potentially changed. 1652 * You should call one of the g_settings_get() calls to check the new 1653 * value. 1654 * 1655 * This signal supports detailed connections. You can connect to the 1656 * detailed signal "changed::x" in order to only receive callbacks 1657 * when key "x" changes. 1658 * 1659 * Note that @settings only emits this signal if you have read @key at 1660 * least once while a signal handler was already connected for @key. 1661 * 1662 * Params: 1663 * key = the name of the key that changed 1664 */ 1665 gulong addOnChanged(void delegate(string, Settings) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1666 { 1667 onChangedListeners ~= new OnChangedDelegateWrapper(dlg, 0, connectFlags); 1668 onChangedListeners[onChangedListeners.length - 1].handlerId = Signals.connectData( 1669 this, 1670 "changed", 1671 cast(GCallback)&callBackChanged, 1672 cast(void*)onChangedListeners[onChangedListeners.length - 1], 1673 cast(GClosureNotify)&callBackChangedDestroy, 1674 connectFlags); 1675 return onChangedListeners[onChangedListeners.length - 1].handlerId; 1676 } 1677 1678 extern(C) static void callBackChanged(GSettings* settingsStruct, char* key,OnChangedDelegateWrapper wrapper) 1679 { 1680 wrapper.dlg(Str.toString(key), wrapper.outer); 1681 } 1682 1683 extern(C) static void callBackChangedDestroy(OnChangedDelegateWrapper wrapper, GClosure* closure) 1684 { 1685 wrapper.outer.internalRemoveOnChanged(wrapper); 1686 } 1687 1688 protected void internalRemoveOnChanged(OnChangedDelegateWrapper source) 1689 { 1690 foreach(index, wrapper; onChangedListeners) 1691 { 1692 if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId) 1693 { 1694 onChangedListeners[index] = null; 1695 onChangedListeners = std.algorithm.remove(onChangedListeners, index); 1696 break; 1697 } 1698 } 1699 } 1700 1701 1702 protected class OnWritableChangeDelegateWrapper 1703 { 1704 bool delegate(uint, Settings) dlg; 1705 gulong handlerId; 1706 ConnectFlags flags; 1707 this(bool delegate(uint, Settings) dlg, gulong handlerId, ConnectFlags flags) 1708 { 1709 this.dlg = dlg; 1710 this.handlerId = handlerId; 1711 this.flags = flags; 1712 } 1713 } 1714 protected OnWritableChangeDelegateWrapper[] onWritableChangeListeners; 1715 1716 /** 1717 * The "writable-change-event" signal is emitted once per writability 1718 * change event that affects this settings object. You should connect 1719 * to this signal if you are interested in viewing groups of changes 1720 * before they are split out into multiple emissions of the 1721 * "writable-changed" signal. For most use cases it is more 1722 * appropriate to use the "writable-changed" signal. 1723 * 1724 * In the event that the writability change applies only to a single 1725 * key, @key will be set to the #GQuark for that key. In the event 1726 * that the writability change affects the entire settings object, 1727 * @key will be 0. 1728 * 1729 * The default handler for this signal invokes the "writable-changed" 1730 * and "changed" signals for each affected key. This is done because 1731 * changes in writability might also imply changes in value (if for 1732 * example, a new mandatory setting is introduced). If any other 1733 * connected handler returns %TRUE then this default functionality 1734 * will be suppressed. 1735 * 1736 * Params: 1737 * key = the quark of the key, or 0 1738 * 1739 * Return: %TRUE to stop other handlers from being invoked for the 1740 * event. FALSE to propagate the event further. 1741 */ 1742 gulong addOnWritableChange(bool delegate(uint, Settings) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1743 { 1744 onWritableChangeListeners ~= new OnWritableChangeDelegateWrapper(dlg, 0, connectFlags); 1745 onWritableChangeListeners[onWritableChangeListeners.length - 1].handlerId = Signals.connectData( 1746 this, 1747 "writable-change-event", 1748 cast(GCallback)&callBackWritableChange, 1749 cast(void*)onWritableChangeListeners[onWritableChangeListeners.length - 1], 1750 cast(GClosureNotify)&callBackWritableChangeDestroy, 1751 connectFlags); 1752 return onWritableChangeListeners[onWritableChangeListeners.length - 1].handlerId; 1753 } 1754 1755 extern(C) static int callBackWritableChange(GSettings* settingsStruct, uint key,OnWritableChangeDelegateWrapper wrapper) 1756 { 1757 return wrapper.dlg(key, wrapper.outer); 1758 } 1759 1760 extern(C) static void callBackWritableChangeDestroy(OnWritableChangeDelegateWrapper wrapper, GClosure* closure) 1761 { 1762 wrapper.outer.internalRemoveOnWritableChange(wrapper); 1763 } 1764 1765 protected void internalRemoveOnWritableChange(OnWritableChangeDelegateWrapper source) 1766 { 1767 foreach(index, wrapper; onWritableChangeListeners) 1768 { 1769 if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId) 1770 { 1771 onWritableChangeListeners[index] = null; 1772 onWritableChangeListeners = std.algorithm.remove(onWritableChangeListeners, index); 1773 break; 1774 } 1775 } 1776 } 1777 1778 1779 protected class OnWritableChangedDelegateWrapper 1780 { 1781 void delegate(string, Settings) dlg; 1782 gulong handlerId; 1783 ConnectFlags flags; 1784 this(void delegate(string, Settings) dlg, gulong handlerId, ConnectFlags flags) 1785 { 1786 this.dlg = dlg; 1787 this.handlerId = handlerId; 1788 this.flags = flags; 1789 } 1790 } 1791 protected OnWritableChangedDelegateWrapper[] onWritableChangedListeners; 1792 1793 /** 1794 * The "writable-changed" signal is emitted when the writability of a 1795 * key has potentially changed. You should call 1796 * g_settings_is_writable() in order to determine the new status. 1797 * 1798 * This signal supports detailed connections. You can connect to the 1799 * detailed signal "writable-changed::x" in order to only receive 1800 * callbacks when the writability of "x" changes. 1801 * 1802 * Params: 1803 * key = the key 1804 */ 1805 gulong addOnWritableChanged(void delegate(string, Settings) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1806 { 1807 onWritableChangedListeners ~= new OnWritableChangedDelegateWrapper(dlg, 0, connectFlags); 1808 onWritableChangedListeners[onWritableChangedListeners.length - 1].handlerId = Signals.connectData( 1809 this, 1810 "writable-changed", 1811 cast(GCallback)&callBackWritableChanged, 1812 cast(void*)onWritableChangedListeners[onWritableChangedListeners.length - 1], 1813 cast(GClosureNotify)&callBackWritableChangedDestroy, 1814 connectFlags); 1815 return onWritableChangedListeners[onWritableChangedListeners.length - 1].handlerId; 1816 } 1817 1818 extern(C) static void callBackWritableChanged(GSettings* settingsStruct, char* key,OnWritableChangedDelegateWrapper wrapper) 1819 { 1820 wrapper.dlg(Str.toString(key), wrapper.outer); 1821 } 1822 1823 extern(C) static void callBackWritableChangedDestroy(OnWritableChangedDelegateWrapper wrapper, GClosure* closure) 1824 { 1825 wrapper.outer.internalRemoveOnWritableChanged(wrapper); 1826 } 1827 1828 protected void internalRemoveOnWritableChanged(OnWritableChangedDelegateWrapper source) 1829 { 1830 foreach(index, wrapper; onWritableChangedListeners) 1831 { 1832 if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId) 1833 { 1834 onWritableChangedListeners[index] = null; 1835 onWritableChangedListeners = std.algorithm.remove(onWritableChangedListeners, index); 1836 break; 1837 } 1838 } 1839 } 1840 1841 }