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 * Conversion parameters: 26 * inFile = GSettings.html 27 * outPack = gio 28 * outFile = Settings 29 * strct = GSettings 30 * realStrct= 31 * ctorStrct= 32 * clss = Settings 33 * interf = 34 * class Code: No 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - g_settings_ 41 * omit structs: 42 * omit prefixes: 43 * omit code: 44 * omit signals: 45 * imports: 46 * - glib.Str 47 * - glib.Variant 48 * - glib.VariantType 49 * - gobject.Value 50 * - gio.Action 51 * - gio.ActionIF 52 * - gio.SettingsBackend 53 * - gio.SettingsSchema 54 * structWrap: 55 * - GAction* -> ActionIF 56 * - GSettings* -> Settings 57 * - GSettingsBackend* -> SettingsBackend 58 * - GSettingsSchema* -> SettingsSchema 59 * - GValue* -> Value 60 * - GVariant* -> Variant 61 * - GVariantType* -> VariantType 62 * module aliases: 63 * local aliases: 64 * overrides: 65 */ 66 67 module gio.Settings; 68 69 public import gtkc.giotypes; 70 71 private import gtkc.gio; 72 private import glib.ConstructionException; 73 private import gobject.ObjectG; 74 75 private import gobject.Signals; 76 public import gtkc.gdktypes; 77 private import glib.Str; 78 private import glib.Variant; 79 private import glib.VariantType; 80 private import gobject.Value; 81 private import gio.Action; 82 private import gio.ActionIF; 83 private import gio.SettingsBackend; 84 private import gio.SettingsSchema; 85 86 87 private import gobject.ObjectG; 88 89 /** 90 * The GSettings class provides a convenient API for storing and retrieving 91 * application settings. 92 * 93 * Reads and writes can be considered to be non-blocking. Reading 94 * settings with GSettings is typically extremely fast: on 95 * approximately the same order of magnitude (but slower than) a 96 * GHashTable lookup. Writing settings is also extremely fast in terms 97 * of time to return to your application, but can be extremely expensive 98 * for other threads and other processes. Many settings backends 99 * (including dconf) have lazy initialisation which means in the common 100 * case of the user using their computer without modifying any settings 101 * a lot of work can be avoided. For dconf, the D-Bus service doesn't 102 * even need to be started in this case. For this reason, you should 103 * only ever modify GSettings keys in response to explicit user action. 104 * Particular care should be paid to ensure that modifications are not 105 * made during startup -- for example, when setting the initial value 106 * of preferences widgets. The built-in g_settings_bind() functionality 107 * is careful not to write settings in response to notify signals as a 108 * result of modifications that it makes to widgets. 109 * 110 * When creating a GSettings instance, you have to specify a schema 111 * that describes the keys in your settings and their types and default 112 * values, as well as some other information. 113 * 114 * Normally, a schema has as fixed path that determines where the settings 115 * are stored in the conceptual global tree of settings. However, schemas 116 * can also be 'relocatable', i.e. not equipped with a fixed path. This is 117 * useful e.g. when the schema describes an 'account', and you want to be 118 * able to store a arbitrary number of accounts. 119 * 120 * Paths must start with and end with a forward slash character ('/') 121 * and must not contain two sequential slash characters. Paths should 122 * be chosen based on a domain name associated with the program or 123 * library to which the settings belong. Examples of paths are 124 * "/org/gtk/settings/file-chooser/" and "/ca/desrt/dconf-editor/". 125 * Paths should not start with "/apps/", "/desktop/" or "/system/" as 126 * they often did in GConf. 127 * 128 * Unlike other configuration systems (like GConf), GSettings does not 129 * restrict keys to basic types like strings and numbers. GSettings stores 130 * values as GVariant, and allows any GVariantType for keys. Key names 131 * are restricted to lowercase characters, numbers and '-'. Furthermore, 132 * the names must begin with a lowercase character, must not end 133 * with a '-', and must not contain consecutive dashes. 134 * 135 * Similar to GConf, the default values in GSettings schemas can be 136 * localized, but the localized values are stored in gettext catalogs 137 * and looked up with the domain that is specified in the 138 * gettext-domain attribute of the 139 * <schemalist> or <schema> 140 * elements and the category that is specified in the l10n attribute of the 141 * <key> element. 142 * 143 * GSettings uses schemas in a compact binary form that is created 144 * by the glib-compile-schemas 145 * utility. The input is a schema description in an XML format that can be 146 * described by the following DTD: 147 * 148 * $(DDOC_COMMENT example) 149 * 150 * glib-compile-schemas expects schema files to have the extension .gschema.xml 151 * 152 * At runtime, schemas are identified by their id (as specified 153 * in the id attribute of the 154 * <schema> element). The 155 * convention for schema ids is to use a dotted name, similar in 156 * style to a D-Bus bus name, e.g. "org.gnome.SessionManager". In particular, 157 * if the settings are for a specific service that owns a D-Bus bus name, 158 * the D-Bus bus name and schema id should match. For schemas which deal 159 * with settings not associated with one named application, the id should 160 * not use StudlyCaps, e.g. "org.gnome.font-rendering". 161 * 162 * In addition to GVariant types, keys can have types that have enumerated 163 * types. These can be described by a <choice>, 164 * <enum> or <flags> element, see 165 * Example 16, “Ranges, choices and enumerated types”. The underlying type of 166 * such a key is string, but you can use g_settings_get_enum(), 167 * g_settings_set_enum(), g_settings_get_flags(), g_settings_set_flags() 168 * access the numeric values corresponding to the string value of enum 169 * and flags keys. 170 * 171 * $(DDOC_COMMENT example) 172 * 173 * $(DDOC_COMMENT example) 174 * 175 * Vendor overrides 176 * 177 * Default values are defined in the schemas that get installed by 178 * an application. Sometimes, it is necessary for a vendor or distributor 179 * to adjust these defaults. Since patching the XML source for the schema 180 * is inconvenient and error-prone, 181 * glib-compile-schemas reads 182 * so-called 'vendor override' files. These are keyfiles in the same 183 * directory as the XML schema sources which can override default values. 184 * The schema id serves as the group name in the key file, and the values 185 * are expected in serialized GVariant form, as in the following example: 186 * 187 * $(DDOC_COMMENT example) 188 * 189 * glib-compile-schemas expects schema files to have the extension 190 * .gschema.override 191 * 192 * Binding 193 * 194 * A very convenient feature of GSettings lets you bind GObject properties 195 * directly to settings, using g_settings_bind(). Once a GObject property 196 * has been bound to a setting, changes on either side are automatically 197 * propagated to the other side. GSettings handles details like 198 * mapping between GObject and GVariant types, and preventing infinite 199 * cycles. 200 * 201 * This makes it very easy to hook up a preferences dialog to the 202 * underlying settings. To make this even more convenient, GSettings 203 * looks for a boolean property with the name "sensitivity" and 204 * automatically binds it to the writability of the bound setting. 205 * If this 'magic' gets in the way, it can be suppressed with the 206 * G_SETTINGS_BIND_NO_SENSITIVITY flag. 207 */ 208 public class Settings : ObjectG 209 { 210 211 /** the main Gtk struct */ 212 protected GSettings* gSettings; 213 214 215 /** Get the main Gtk struct */ 216 public GSettings* getSettingsStruct() 217 { 218 return gSettings; 219 } 220 221 222 /** the main Gtk struct as a void* */ 223 protected override void* getStruct() 224 { 225 return cast(void*)gSettings; 226 } 227 228 /** 229 * Sets our main struct and passes it to the parent class 230 */ 231 public this (GSettings* gSettings) 232 { 233 super(cast(GObject*)gSettings); 234 this.gSettings = gSettings; 235 } 236 237 protected override void setStruct(GObject* obj) 238 { 239 super.setStruct(obj); 240 gSettings = cast(GSettings*)obj; 241 } 242 243 /** 244 */ 245 int[string] connectedSignals; 246 247 bool delegate(void*, gint, Settings)[] onChangeListeners; 248 /** 249 * The "change-event" signal is emitted once per change event that 250 * affects this settings object. You should connect to this signal 251 * only if you are interested in viewing groups of changes before they 252 * are split out into multiple emissions of the "changed" signal. 253 * For most use cases it is more appropriate to use the "changed" signal. 254 * In the event that the change event applies to one or more specified 255 * keys, keys will be an array of GQuark of length n_keys. In the 256 * event that the change event applies to the GSettings object as a 257 * whole (ie: potentially every key has been changed) then keys will 258 * be NULL and n_keys will be 0. 259 * The default handler for this signal invokes the "changed" signal 260 * for each affected key. If any other connected handler returns 261 * TRUE then this default functionality will be suppressed. 262 * TRUE to stop other handlers from being invoked for the 263 * event. FALSE to propagate the event further. 264 */ 265 void addOnChange(bool delegate(void*, gint, Settings) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 266 { 267 if ( !("change-event" in connectedSignals) ) 268 { 269 Signals.connectData( 270 getStruct(), 271 "change-event", 272 cast(GCallback)&callBackChange, 273 cast(void*)this, 274 null, 275 connectFlags); 276 connectedSignals["change-event"] = 1; 277 } 278 onChangeListeners ~= dlg; 279 } 280 extern(C) static gboolean callBackChange(GSettings* settingsStruct, void* keys, gint nKeys, Settings _settings) 281 { 282 foreach ( bool delegate(void*, gint, Settings) dlg ; _settings.onChangeListeners ) 283 { 284 if ( dlg(keys, nKeys, _settings) ) 285 { 286 return 1; 287 } 288 } 289 290 return 0; 291 } 292 293 void delegate(string, Settings)[] onChangedListeners; 294 /** 295 * The "changed" signal is emitted when a key has potentially changed. 296 * You should call one of the g_settings_get() calls to check the new 297 * value. 298 * This signal supports detailed connections. You can connect to the 299 * detailed signal "changed::x" in order to only receive callbacks 300 * when key "x" changes. 301 */ 302 void addOnChanged(void delegate(string, Settings) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 303 { 304 if ( !("changed" in connectedSignals) ) 305 { 306 Signals.connectData( 307 getStruct(), 308 "changed", 309 cast(GCallback)&callBackChanged, 310 cast(void*)this, 311 null, 312 connectFlags); 313 connectedSignals["changed"] = 1; 314 } 315 onChangedListeners ~= dlg; 316 } 317 extern(C) static void callBackChanged(GSettings* settingsStruct, gchar* key, Settings _settings) 318 { 319 foreach ( void delegate(string, Settings) dlg ; _settings.onChangedListeners ) 320 { 321 dlg(Str.toString(key), _settings); 322 } 323 } 324 325 bool delegate(guint, Settings)[] onWritableChangeListeners; 326 /** 327 * The "writable-change-event" signal is emitted once per writability 328 * change event that affects this settings object. You should connect 329 * to this signal if you are interested in viewing groups of changes 330 * before they are split out into multiple emissions of the 331 * "writable-changed" signal. For most use cases it is more 332 * appropriate to use the "writable-changed" signal. 333 * In the event that the writability change applies only to a single 334 * key, key will be set to the GQuark for that key. In the event 335 * that the writability change affects the entire settings object, 336 * key will be 0. 337 * The default handler for this signal invokes the "writable-changed" 338 * and "changed" signals for each affected key. This is done because 339 * changes in writability might also imply changes in value (if for 340 * example, a new mandatory setting is introduced). If any other 341 * connected handler returns TRUE then this default functionality 342 * will be suppressed. 343 * TRUE to stop other handlers from being invoked for the 344 * event. FALSE to propagate the event further. 345 */ 346 void addOnWritableChange(bool delegate(guint, Settings) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 347 { 348 if ( !("writable-change-event" in connectedSignals) ) 349 { 350 Signals.connectData( 351 getStruct(), 352 "writable-change-event", 353 cast(GCallback)&callBackWritableChange, 354 cast(void*)this, 355 null, 356 connectFlags); 357 connectedSignals["writable-change-event"] = 1; 358 } 359 onWritableChangeListeners ~= dlg; 360 } 361 extern(C) static gboolean callBackWritableChange(GSettings* settingsStruct, guint key, Settings _settings) 362 { 363 foreach ( bool delegate(guint, Settings) dlg ; _settings.onWritableChangeListeners ) 364 { 365 if ( dlg(key, _settings) ) 366 { 367 return 1; 368 } 369 } 370 371 return 0; 372 } 373 374 void delegate(string, Settings)[] onWritableChangedListeners; 375 /** 376 * The "writable-changed" signal is emitted when the writability of a 377 * key has potentially changed. You should call 378 * g_settings_is_writable() in order to determine the new status. 379 * This signal supports detailed connections. You can connect to the 380 * detailed signal "writable-changed::x" in order to only receive 381 * callbacks when the writability of "x" changes. 382 */ 383 void addOnWritableChanged(void delegate(string, Settings) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 384 { 385 if ( !("writable-changed" in connectedSignals) ) 386 { 387 Signals.connectData( 388 getStruct(), 389 "writable-changed", 390 cast(GCallback)&callBackWritableChanged, 391 cast(void*)this, 392 null, 393 connectFlags); 394 connectedSignals["writable-changed"] = 1; 395 } 396 onWritableChangedListeners ~= dlg; 397 } 398 extern(C) static void callBackWritableChanged(GSettings* settingsStruct, gchar* key, Settings _settings) 399 { 400 foreach ( void delegate(string, Settings) dlg ; _settings.onWritableChangedListeners ) 401 { 402 dlg(Str.toString(key), _settings); 403 } 404 } 405 406 407 /** 408 * Creates a new GSettings object with the schema specified by 409 * schema_id. 410 * Signals on the newly created GSettings object will be dispatched 411 * via the thread-default GMainContext in effect at the time of the 412 * call to g_settings_new(). The new GSettings will hold a reference 413 * on the context. See g_main_context_push_thread_default(). 414 * Since 2.26 415 * Params: 416 * schemaId = the id of the schema 417 * Throws: ConstructionException GTK+ fails to create the object. 418 */ 419 public this (string schemaId) 420 { 421 // GSettings * g_settings_new (const gchar *schema_id); 422 auto p = g_settings_new(Str.toStringz(schemaId)); 423 if(p is null) 424 { 425 throw new ConstructionException("null returned by g_settings_new(Str.toStringz(schemaId))"); 426 } 427 this(cast(GSettings*) p); 428 } 429 430 /** 431 * Creates a new GSettings object with the relocatable schema specified 432 * by schema_id and a given path. 433 * You only need to do this if you want to directly create a settings 434 * object with a schema that doesn't have a specified path of its own. 435 * That's quite rare. 436 * It is a programmer error to call this function for a schema that 437 * has an explicitly specified path. 438 * Since 2.26 439 * Params: 440 * schemaId = the id of the schema 441 * path = the path to use 442 * Throws: ConstructionException GTK+ fails to create the object. 443 */ 444 public this (string schemaId, string path) 445 { 446 // GSettings * g_settings_new_with_path (const gchar *schema_id, const gchar *path); 447 auto p = g_settings_new_with_path(Str.toStringz(schemaId), Str.toStringz(path)); 448 if(p is null) 449 { 450 throw new ConstructionException("null returned by g_settings_new_with_path(Str.toStringz(schemaId), Str.toStringz(path))"); 451 } 452 this(cast(GSettings*) p); 453 } 454 455 /** 456 * Creates a new GSettings object with the schema specified by 457 * schema_id and a given GSettingsBackend. 458 * Creating a GSettings object with a different backend allows accessing 459 * settings from a database other than the usual one. For example, it may make 460 * sense to pass a backend corresponding to the "defaults" settings database on 461 * the system to get a settings object that modifies the system default 462 * settings instead of the settings for this user. 463 * Since 2.26 464 * Params: 465 * schemaId = the id of the schema 466 * backend = the GSettingsBackend to use 467 * Throws: ConstructionException GTK+ fails to create the object. 468 */ 469 public this (string schemaId, SettingsBackend backend) 470 { 471 // GSettings * g_settings_new_with_backend (const gchar *schema_id, GSettingsBackend *backend); 472 auto p = g_settings_new_with_backend(Str.toStringz(schemaId), (backend is null) ? null : backend.getSettingsBackendStruct()); 473 if(p is null) 474 { 475 throw new ConstructionException("null returned by g_settings_new_with_backend(Str.toStringz(schemaId), (backend is null) ? null : backend.getSettingsBackendStruct())"); 476 } 477 this(cast(GSettings*) p); 478 } 479 480 /** 481 * Creates a new GSettings object with the schema specified by 482 * schema_id and a given GSettingsBackend and path. 483 * This is a mix of g_settings_new_with_backend() and 484 * g_settings_new_with_path(). 485 * Since 2.26 486 * Params: 487 * schemaId = the id of the schema 488 * backend = the GSettingsBackend to use 489 * path = the path to use 490 * Throws: ConstructionException GTK+ fails to create the object. 491 */ 492 public this (string schemaId, SettingsBackend backend, string path) 493 { 494 // GSettings * g_settings_new_with_backend_and_path (const gchar *schema_id, GSettingsBackend *backend, const gchar *path); 495 auto p = g_settings_new_with_backend_and_path(Str.toStringz(schemaId), (backend is null) ? null : backend.getSettingsBackendStruct(), Str.toStringz(path)); 496 if(p is null) 497 { 498 throw new ConstructionException("null returned by g_settings_new_with_backend_and_path(Str.toStringz(schemaId), (backend is null) ? null : backend.getSettingsBackendStruct(), Str.toStringz(path))"); 499 } 500 this(cast(GSettings*) p); 501 } 502 503 /** 504 * Creates a new GSettings object with a given schema, backend and 505 * path. 506 * It should be extremely rare that you ever want to use this function. 507 * It is made available for advanced use-cases (such as plugin systems 508 * that want to provide access to schemas loaded from custom locations, 509 * etc). 510 * At the most basic level, a GSettings object is a pure composition of 511 * 4 things: a GSettingsSchema, a GSettingsBackend, a path within that 512 * backend, and a GMainContext to which signals are dispatched. 513 * This constructor therefore gives you full control over constructing 514 * GSettings instances. The first 4 parameters are given directly as 515 * schema, backend and path, and the main context is taken from the 516 * thread-default (as per g_settings_new()). 517 * If backend is NULL then the default backend is used. 518 * If path is NULL then the path from the schema is used. It is an 519 * error f path is NULL and the schema has no path of its own or if 520 * path is non-NULL and not equal to the path that the schema does 521 * have. 522 * Since 2.32 523 * Params: 524 * schema = a GSettingsSchema 525 * backend = a GSettingsBackend. [allow-none] 526 * path = the path to use. [allow-none] 527 * Throws: ConstructionException GTK+ fails to create the object. 528 */ 529 public this (SettingsSchema schema, SettingsBackend backend, string path) 530 { 531 // GSettings * g_settings_new_full (GSettingsSchema *schema, GSettingsBackend *backend, const gchar *path); 532 auto p = g_settings_new_full((schema is null) ? null : schema.getSettingsSchemaStruct(), (backend is null) ? null : backend.getSettingsBackendStruct(), Str.toStringz(path)); 533 if(p is null) 534 { 535 throw new ConstructionException("null returned by g_settings_new_full((schema is null) ? null : schema.getSettingsSchemaStruct(), (backend is null) ? null : backend.getSettingsBackendStruct(), Str.toStringz(path))"); 536 } 537 this(cast(GSettings*) p); 538 } 539 540 /** 541 * Ensures that all pending operations for the given are complete for 542 * the default backend. 543 * Writes made to a GSettings are handled asynchronously. For this 544 * reason, it is very unlikely that the changes have it to disk by the 545 * time g_settings_set() returns. 546 * This call will block until all of the writes have made it to the 547 * backend. Since the mainloop is not running, no change notifications 548 * will be dispatched during this call (but some may be queued by the 549 * time the call is done). 550 */ 551 public static void sync() 552 { 553 // void g_settings_sync (void); 554 g_settings_sync(); 555 } 556 557 /** 558 * Gets the value that is stored in settings for key. 559 * It is a programmer error to give a key that isn't contained in the 560 * schema for settings. 561 * Since 2.26 562 * Params: 563 * key = the key to get the value for 564 * Returns: a new GVariant 565 */ 566 public Variant getValue(string key) 567 { 568 // GVariant * g_settings_get_value (GSettings *settings, const gchar *key); 569 auto p = g_settings_get_value(gSettings, Str.toStringz(key)); 570 571 if(p is null) 572 { 573 return null; 574 } 575 576 return ObjectG.getDObject!(Variant)(cast(GVariant*) p); 577 } 578 579 /** 580 * Sets key in settings to value. 581 * It is a programmer error to give a key that isn't contained in the 582 * schema for settings or for value to have the incorrect type, per 583 * the schema. 584 * If value is floating then this function consumes the reference. 585 * Since 2.26 586 * Params: 587 * key = the name of the key to set 588 * value = a GVariant of the correct type 589 * Returns: TRUE if setting the key succeeded, FALSE if the key was not writable 590 */ 591 public int setValue(string key, Variant value) 592 { 593 // gboolean g_settings_set_value (GSettings *settings, const gchar *key, GVariant *value); 594 return g_settings_set_value(gSettings, Str.toStringz(key), (value is null) ? null : value.getVariantStruct()); 595 } 596 597 /** 598 * Finds out if a key can be written or not 599 * Since 2.26 600 * Params: 601 * name = the name of a key 602 * Returns: TRUE if the key name is writable 603 */ 604 public int isWritable(string name) 605 { 606 // gboolean g_settings_is_writable (GSettings *settings, const gchar *name); 607 return g_settings_is_writable(gSettings, Str.toStringz(name)); 608 } 609 610 /** 611 * Changes the GSettings object into 'delay-apply' mode. In this 612 * mode, changes to settings are not immediately propagated to the 613 * backend, but kept locally until g_settings_apply() is called. 614 * Since 2.26 615 */ 616 public void delay() 617 { 618 // void g_settings_delay (GSettings *settings); 619 g_settings_delay(gSettings); 620 } 621 622 /** 623 * Applies any changes that have been made to the settings. This 624 * function does nothing unless settings is in 'delay-apply' mode; 625 * see g_settings_delay(). In the normal case settings are always 626 * applied immediately. 627 */ 628 public void apply() 629 { 630 // void g_settings_apply (GSettings *settings); 631 g_settings_apply(gSettings); 632 } 633 634 /** 635 * Reverts all non-applied changes to the settings. This function 636 * does nothing unless settings is in 'delay-apply' mode; see 637 * g_settings_delay(). In the normal case settings are always applied 638 * immediately. 639 * Change notifications will be emitted for affected keys. 640 */ 641 public void revert() 642 { 643 // void g_settings_revert (GSettings *settings); 644 g_settings_revert(gSettings); 645 } 646 647 /** 648 * Returns whether the GSettings object has any unapplied 649 * changes. This can only be the case if it is in 'delayed-apply' mode. 650 * Since 2.26 651 * Returns: TRUE if settings has unapplied changes 652 */ 653 public int getHasUnapplied() 654 { 655 // gboolean g_settings_get_has_unapplied (GSettings *settings); 656 return g_settings_get_has_unapplied(gSettings); 657 } 658 659 /** 660 * Creates a 'child' settings object which has a base path of 661 * base-path/name, where 662 * base-path is the base path of settings. 663 * The schema for the child settings object must have been declared 664 * in the schema of settings using a <child> element. 665 * Since 2.26 666 * Params: 667 * name = the name of the 'child' schema 668 * Returns: a 'child' settings object. [transfer full] 669 */ 670 public Settings getChild(string name) 671 { 672 // GSettings * g_settings_get_child (GSettings *settings, const gchar *name); 673 auto p = g_settings_get_child(gSettings, Str.toStringz(name)); 674 675 if(p is null) 676 { 677 return null; 678 } 679 680 return ObjectG.getDObject!(Settings)(cast(GSettings*) p); 681 } 682 683 /** 684 * Resets key to its default value. 685 * This call resets the key, as much as possible, to its default value. 686 * That might the value specified in the schema or the one set by the 687 * administrator. 688 * Params: 689 * key = the name of a key 690 */ 691 public void reset(string key) 692 { 693 // void g_settings_reset (GSettings *settings, const gchar *key); 694 g_settings_reset(gSettings, Str.toStringz(key)); 695 } 696 697 /** 698 * Gets a list of the GSettings schemas installed on the system. The 699 * returned list is exactly the list of schemas for which you may call 700 * g_settings_new() without adverse effects. 701 * This function does not list the schemas that do not provide their own 702 * paths (ie: schemas for which you must use 703 * g_settings_new_with_path()). See 704 * g_settings_list_relocatable_schemas() for that. 705 * Since 2.26 706 * Returns: a list of GSettings schemas that are available. The list must not be modified or freed. [element-type utf8][transfer none] 707 */ 708 public static string[] listSchemas() 709 { 710 // const gchar * const * g_settings_list_schemas (void); 711 return Str.toStringArray(g_settings_list_schemas()); 712 } 713 714 /** 715 * Gets a list of the relocatable GSettings schemas installed on the 716 * system. These are schemas that do not provide their own path. It is 717 * usual to instantiate these schemas directly, but if you want to you 718 * can use g_settings_new_with_path() to specify the path. 719 * The output of this function, taken together with the output of 720 * g_settings_list_schemas() represents the complete list of all 721 * installed schemas. 722 * Since 2.28 723 * Returns: a list of relocatable GSettings schemas that are available. The list must not be modified or freed. [element-type utf8][transfer none] 724 */ 725 public static string[] listRelocatableSchemas() 726 { 727 // const gchar * const * g_settings_list_relocatable_schemas (void); 728 return Str.toStringArray(g_settings_list_relocatable_schemas()); 729 } 730 731 /** 732 * Introspects the list of keys on settings. 733 * You should probably not be calling this function from "normal" code 734 * (since you should already know what keys are in your schema). This 735 * function is intended for introspection reasons. 736 * You should free the return value with g_strfreev() when you are done 737 * with it. 738 * Returns: a list of the keys on settings. [transfer full][element-type utf8] 739 */ 740 public string[] listKeys() 741 { 742 // gchar ** g_settings_list_keys (GSettings *settings); 743 return Str.toStringArray(g_settings_list_keys(gSettings)); 744 } 745 746 /** 747 * Gets the list of children on settings. 748 * The list is exactly the list of strings for which it is not an error 749 * to call g_settings_get_child(). 750 * For GSettings objects that are lists, this value can change at any 751 * time and you should connect to the "children-changed" signal to watch 752 * for those changes. Note that there is a race condition here: you may 753 * request a child after listing it only for it to have been destroyed 754 * in the meantime. For this reason, g_settings_get_child() may return 755 * NULL even for a child that was listed by this function. 756 * For GSettings objects that are not lists, you should probably not be 757 * calling this function from "normal" code (since you should already 758 * know what children are in your schema). This function may still be 759 * useful there for introspection reasons, however. 760 * You should free the return value with g_strfreev() when you are done 761 * with it. 762 * Returns: a list of the children on settings. [transfer full][element-type utf8] 763 */ 764 public string[] listChildren() 765 { 766 // gchar ** g_settings_list_children (GSettings *settings); 767 return Str.toStringArray(g_settings_list_children(gSettings)); 768 } 769 770 /** 771 * Queries the range of a key. 772 * This function will return a GVariant that fully describes the range 773 * of values that are valid for key. 774 * The type of GVariant returned is (sv). The 775 * string describes the type of range restriction in effect. The type 776 * and meaning of the value contained in the variant depends on the 777 * string. 778 * If the string is 'type' then the variant contains 779 * an empty array. The element type of that empty array is the expected 780 * type of value and all values of that type are valid. 781 * If the string is 'enum' then the variant contains 782 * an array enumerating the possible values. Each item in the array is 783 * a possible valid value and no other values are valid. 784 * If the string is 'flags' then the variant contains 785 * an array. Each item in the array is a value that may appear zero or 786 * one times in an array to be used as the value for this key. For 787 * example, if the variant contained the array ['x', 788 * 'y'] then the valid values for the key would be 789 * [], ['x'], 790 * ['y'], ['x', 'y'] and 791 * ['y', 'x']. 792 * Finally, if the string is 'range' then the variant 793 * contains a pair of like-typed values -- the minimum and maximum 794 * permissible values for this key. 795 * This information should not be used by normal programs. It is 796 * considered to be a hint for introspection purposes. Normal programs 797 * should already know what is permitted by their own schema. The 798 * format may change in any way in the future -- but particularly, new 799 * forms may be added to the possibilities described above. 800 * It is a programmer error to give a key that isn't contained in the 801 * schema for settings. 802 * You should free the returned value with g_variant_unref() when it is 803 * no longer needed. 804 * Since 2.28 805 * Params: 806 * key = the key to query the range of 807 * Returns: a GVariant describing the range 808 */ 809 public Variant getRange(string key) 810 { 811 // GVariant * g_settings_get_range (GSettings *settings, const gchar *key); 812 auto p = g_settings_get_range(gSettings, Str.toStringz(key)); 813 814 if(p is null) 815 { 816 return null; 817 } 818 819 return ObjectG.getDObject!(Variant)(cast(GVariant*) p); 820 } 821 822 /** 823 * Checks if the given value is of the correct type and within the 824 * permitted range for key. 825 * This API is not intended to be used by normal programs -- they should 826 * already know what is permitted by their own schemas. This API is 827 * meant to be used by programs such as editors or commandline tools. 828 * It is a programmer error to give a key that isn't contained in the 829 * schema for settings. 830 * Since 2.28 831 * Params: 832 * key = the key to check 833 * value = the value to check 834 * Returns: TRUE if value is valid for key 835 */ 836 public int rangeCheck(string key, Variant value) 837 { 838 // gboolean g_settings_range_check (GSettings *settings, const gchar *key, GVariant *value); 839 return g_settings_range_check(gSettings, Str.toStringz(key), (value is null) ? null : value.getVariantStruct()); 840 } 841 842 /** 843 * Gets the value that is stored at key in settings. 844 * A convenience variant of g_settings_get() for booleans. 845 * It is a programmer error to give a key that isn't specified as 846 * having a boolean type in the schema for settings. 847 * Since 2.26 848 * Params: 849 * key = the key to get the value for 850 * Returns: a boolean 851 */ 852 public int getBoolean(string key) 853 { 854 // gboolean g_settings_get_boolean (GSettings *settings, const gchar *key); 855 return g_settings_get_boolean(gSettings, Str.toStringz(key)); 856 } 857 858 /** 859 * Sets key in settings to value. 860 * A convenience variant of g_settings_set() for booleans. 861 * It is a programmer error to give a key that isn't specified as 862 * having a boolean type in the schema for settings. 863 * Since 2.26 864 * Params: 865 * key = the name of the key to set 866 * value = the value to set it to 867 * Returns: TRUE if setting the key succeeded, FALSE if the key was not writable 868 */ 869 public int setBoolean(string key, int value) 870 { 871 // gboolean g_settings_set_boolean (GSettings *settings, const gchar *key, gboolean value); 872 return g_settings_set_boolean(gSettings, Str.toStringz(key), value); 873 } 874 875 /** 876 * Gets the value that is stored at key in settings. 877 * A convenience variant of g_settings_get() for 32-bit integers. 878 * It is a programmer error to give a key that isn't specified as 879 * having a int32 type in the schema for settings. 880 * Since 2.26 881 * Params: 882 * key = the key to get the value for 883 * Returns: an integer 884 */ 885 public int getInt(string key) 886 { 887 // gint g_settings_get_int (GSettings *settings, const gchar *key); 888 return g_settings_get_int(gSettings, Str.toStringz(key)); 889 } 890 891 /** 892 * Sets key in settings to value. 893 * A convenience variant of g_settings_set() for 32-bit integers. 894 * It is a programmer error to give a key that isn't specified as 895 * having a int32 type in the schema for settings. 896 * Since 2.26 897 * Params: 898 * key = the name of the key to set 899 * value = the value to set it to 900 * Returns: TRUE if setting the key succeeded, FALSE if the key was not writable 901 */ 902 public int setInt(string key, int value) 903 { 904 // gboolean g_settings_set_int (GSettings *settings, const gchar *key, gint value); 905 return g_settings_set_int(gSettings, Str.toStringz(key), value); 906 } 907 908 /** 909 * Gets the value that is stored at key in settings. 910 * A convenience variant of g_settings_get() for 32-bit unsigned 911 * integers. 912 * It is a programmer error to give a key that isn't specified as 913 * having a uint32 type in the schema for settings. 914 * Since 2.30 915 * Params: 916 * key = the key to get the value for 917 * Returns: an unsigned integer 918 */ 919 public uint getUint(string key) 920 { 921 // guint g_settings_get_uint (GSettings *settings, const gchar *key); 922 return g_settings_get_uint(gSettings, Str.toStringz(key)); 923 } 924 925 /** 926 * Sets key in settings to value. 927 * A convenience variant of g_settings_set() for 32-bit unsigned 928 * integers. 929 * It is a programmer error to give a key that isn't specified as 930 * having a uint32 type in the schema for settings. 931 * Since 2.30 932 * Params: 933 * key = the name of the key to set 934 * value = the value to set it to 935 * Returns: TRUE if setting the key succeeded, FALSE if the key was not writable 936 */ 937 public int setUint(string key, uint value) 938 { 939 // gboolean g_settings_set_uint (GSettings *settings, const gchar *key, guint value); 940 return g_settings_set_uint(gSettings, Str.toStringz(key), value); 941 } 942 943 /** 944 * Gets the value that is stored at key in settings. 945 * A convenience variant of g_settings_get() for doubles. 946 * It is a programmer error to give a key that isn't specified as 947 * having a 'double' type in the schema for settings. 948 * Since 2.26 949 * Params: 950 * key = the key to get the value for 951 * Returns: a double 952 */ 953 public double getDouble(string key) 954 { 955 // gdouble g_settings_get_double (GSettings *settings, const gchar *key); 956 return g_settings_get_double(gSettings, Str.toStringz(key)); 957 } 958 959 /** 960 * Sets key in settings to value. 961 * A convenience variant of g_settings_set() for doubles. 962 * It is a programmer error to give a key that isn't specified as 963 * having a 'double' type in the schema for settings. 964 * Since 2.26 965 * Params: 966 * key = the name of the key to set 967 * value = the value to set it to 968 * Returns: TRUE if setting the key succeeded, FALSE if the key was not writable 969 */ 970 public int setDouble(string key, double value) 971 { 972 // gboolean g_settings_set_double (GSettings *settings, const gchar *key, gdouble value); 973 return g_settings_set_double(gSettings, Str.toStringz(key), value); 974 } 975 976 /** 977 * Gets the value that is stored at key in settings. 978 * A convenience variant of g_settings_get() for strings. 979 * It is a programmer error to give a key that isn't specified as 980 * having a string type in the schema for settings. 981 * Since 2.26 982 * Params: 983 * key = the key to get the value for 984 * Returns: a newly-allocated string 985 */ 986 public string getString(string key) 987 { 988 // gchar * g_settings_get_string (GSettings *settings, const gchar *key); 989 return Str.toString(g_settings_get_string(gSettings, Str.toStringz(key))); 990 } 991 992 /** 993 * Sets key in settings to value. 994 * A convenience variant of g_settings_set() for strings. 995 * It is a programmer error to give a key that isn't specified as 996 * having a string type in the schema for settings. 997 * Since 2.26 998 * Params: 999 * key = the name of the key to set 1000 * value = the value to set it to 1001 * Returns: TRUE if setting the key succeeded, FALSE if the key was not writable 1002 */ 1003 public int setString(string key, string value) 1004 { 1005 // gboolean g_settings_set_string (GSettings *settings, const gchar *key, const gchar *value); 1006 return g_settings_set_string(gSettings, Str.toStringz(key), Str.toStringz(value)); 1007 } 1008 1009 /** 1010 * A convenience variant of g_settings_get() for string arrays. 1011 * It is a programmer error to give a key that isn't specified as 1012 * having an array of strings type in the schema for settings. 1013 * Since 2.26 1014 * Params: 1015 * key = the key to get the value for 1016 * Returns: a newly-allocated, NULL-terminated array of strings, the value that is stored at key in settings. [array zero-terminated=1][transfer full] 1017 */ 1018 public string[] getStrv(string key) 1019 { 1020 // gchar ** g_settings_get_strv (GSettings *settings, const gchar *key); 1021 return Str.toStringArray(g_settings_get_strv(gSettings, Str.toStringz(key))); 1022 } 1023 1024 /** 1025 * Sets key in settings to value. 1026 * A convenience variant of g_settings_set() for string arrays. If 1027 * value is NULL, then key is set to be the empty array. 1028 * It is a programmer error to give a key that isn't specified as 1029 * having an array of strings type in the schema for settings. 1030 * Since 2.26 1031 * Params: 1032 * key = the name of the key to set 1033 * value = the value to set it to, or NULL. [allow-none][array zero-terminated=1] 1034 * Returns: TRUE if setting the key succeeded, FALSE if the key was not writable 1035 */ 1036 public int setStrv(string key, string[] value) 1037 { 1038 // gboolean g_settings_set_strv (GSettings *settings, const gchar *key, const gchar *const *value); 1039 return g_settings_set_strv(gSettings, Str.toStringz(key), Str.toStringzArray(value)); 1040 } 1041 1042 /** 1043 * Gets the value that is stored in settings for key and converts it 1044 * to the enum value that it represents. 1045 * In order to use this function the type of the value must be a string 1046 * and it must be marked in the schema file as an enumerated type. 1047 * It is a programmer error to give a key that isn't contained in the 1048 * schema for settings or is not marked as an enumerated type. 1049 * If the value stored in the configuration database is not a valid 1050 * value for the enumerated type then this function will return the 1051 * default value. 1052 * Since 2.26 1053 * Params: 1054 * key = the key to get the value for 1055 * Returns: the enum value 1056 */ 1057 public int getEnum(string key) 1058 { 1059 // gint g_settings_get_enum (GSettings *settings, const gchar *key); 1060 return g_settings_get_enum(gSettings, Str.toStringz(key)); 1061 } 1062 1063 /** 1064 * Looks up the enumerated type nick for value and writes it to key, 1065 * within settings. 1066 * It is a programmer error to give a key that isn't contained in the 1067 * schema for settings or is not marked as an enumerated type, or for 1068 * value not to be a valid value for the named type. 1069 * After performing the write, accessing key directly with 1070 * g_settings_get_string() will return the 'nick' associated with 1071 * value. 1072 * Params: 1073 * key = a key, within settings 1074 * value = an enumerated value 1075 * Returns: TRUE, if the set succeeds 1076 */ 1077 public int setEnum(string key, int value) 1078 { 1079 // gboolean g_settings_set_enum (GSettings *settings, const gchar *key, gint value); 1080 return g_settings_set_enum(gSettings, Str.toStringz(key), value); 1081 } 1082 1083 /** 1084 * Gets the value that is stored in settings for key and converts it 1085 * to the flags value that it represents. 1086 * In order to use this function the type of the value must be an array 1087 * of strings and it must be marked in the schema file as an flags type. 1088 * It is a programmer error to give a key that isn't contained in the 1089 * schema for settings or is not marked as a flags type. 1090 * If the value stored in the configuration database is not a valid 1091 * value for the flags type then this function will return the default 1092 * value. 1093 * Since 2.26 1094 * Params: 1095 * key = the key to get the value for 1096 * Returns: the flags value 1097 */ 1098 public uint getFlags(string key) 1099 { 1100 // guint g_settings_get_flags (GSettings *settings, const gchar *key); 1101 return g_settings_get_flags(gSettings, Str.toStringz(key)); 1102 } 1103 1104 /** 1105 * Looks up the flags type nicks for the bits specified by value, puts 1106 * them in an array of strings and writes the array to key, within 1107 * settings. 1108 * It is a programmer error to give a key that isn't contained in the 1109 * schema for settings or is not marked as a flags type, or for value 1110 * to contain any bits that are not value for the named type. 1111 * After performing the write, accessing key directly with 1112 * g_settings_get_strv() will return an array of 'nicks'; one for each 1113 * bit in value. 1114 * Params: 1115 * key = a key, within settings 1116 * value = a flags value 1117 * Returns: TRUE, if the set succeeds 1118 */ 1119 public int setFlags(string key, uint value) 1120 { 1121 // gboolean g_settings_set_flags (GSettings *settings, const gchar *key, guint value); 1122 return g_settings_set_flags(gSettings, Str.toStringz(key), value); 1123 } 1124 1125 /** 1126 * Gets the value that is stored at key in settings, subject to 1127 * application-level validation/mapping. 1128 * You should use this function when the application needs to perform 1129 * some processing on the value of the key (for example, parsing). The 1130 * mapping function performs that processing. If the function 1131 * indicates that the processing was unsuccessful (due to a parse error, 1132 * for example) then the mapping is tried again with another value. 1133 * This allows a robust 'fall back to defaults' behaviour to be 1134 * implemented somewhat automatically. 1135 * The first value that is tried is the user's setting for the key. If 1136 * the mapping function fails to map this value, other values may be 1137 * tried in an unspecified order (system or site defaults, translated 1138 * schema default values, untranslated schema default values, etc). 1139 * If the mapping function fails for all possible values, one additional 1140 * attempt is made: the mapping function is called with a NULL value. 1141 * If the mapping function still indicates failure at this point then 1142 * the application will be aborted. 1143 * The result parameter for the mapping function is pointed to a 1144 * gpointer which is initially set to NULL. The same pointer is given 1145 * to each invocation of mapping. The final value of that gpointer is 1146 * what is returned by this function. NULL is valid; it is returned 1147 * just as any other value would be. 1148 * Params: 1149 * key = the key to get the value for 1150 * mapping = the function to map the value in the 1151 * settings database to the value used by the application. [scope call] 1152 * userData = user data for mapping 1153 * Returns: the result, which may be NULL. [transfer full] 1154 */ 1155 public void* getMapped(string key, GSettingsGetMapping mapping, void* userData) 1156 { 1157 // gpointer g_settings_get_mapped (GSettings *settings, const gchar *key, GSettingsGetMapping mapping, gpointer user_data); 1158 return g_settings_get_mapped(gSettings, Str.toStringz(key), mapping, userData); 1159 } 1160 1161 /** 1162 * Create a binding between the key in the settings object 1163 * and the property property of object. 1164 * The binding uses the default GIO mapping functions to map 1165 * between the settings and property values. These functions 1166 * handle booleans, numeric types and string types in a 1167 * straightforward way. Use g_settings_bind_with_mapping() if 1168 * you need a custom mapping, or map between types that are not 1169 * supported by the default mapping functions. 1170 * Unless the flags include G_SETTINGS_BIND_NO_SENSITIVITY, this 1171 * function also establishes a binding between the writability of 1172 * key and the "sensitive" property of object (if object has 1173 * a boolean property by that name). See g_settings_bind_writable() 1174 * for more details about writable bindings. 1175 * Note that the lifecycle of the binding is tied to the object, 1176 * and that you can have only one binding per object property. 1177 * If you bind the same property twice on the same object, the second 1178 * binding overrides the first one. 1179 * Since 2.26 1180 * Params: 1181 * key = the key to bind 1182 * object = a GObject. [type GObject.Object] 1183 * property = the name of the property to bind 1184 * flags = flags for the binding 1185 */ 1186 public void bind(string key, void* object, string property, GSettingsBindFlags flags) 1187 { 1188 // void g_settings_bind (GSettings *settings, const gchar *key, gpointer object, const gchar *property, GSettingsBindFlags flags); 1189 g_settings_bind(gSettings, Str.toStringz(key), object, Str.toStringz(property), flags); 1190 } 1191 1192 /** 1193 * Create a binding between the key in the settings object 1194 * and the property property of object. 1195 * The binding uses the provided mapping functions to map between 1196 * settings and property values. 1197 * Note that the lifecycle of the binding is tied to the object, 1198 * and that you can have only one binding per object property. 1199 * If you bind the same property twice on the same object, the second 1200 * binding overrides the first one. 1201 * Since 2.26 1202 * Params: 1203 * key = the key to bind 1204 * object = a GObject. [type GObject.Object] 1205 * property = the name of the property to bind 1206 * flags = flags for the binding 1207 * getMapping = a function that gets called to convert values 1208 * from settings to object, or NULL to use the default GIO mapping 1209 * setMapping = a function that gets called to convert values 1210 * from object to settings, or NULL to use the default GIO mapping 1211 * userData = data that gets passed to get_mapping and set_mapping 1212 * destroy = GDestroyNotify function for user_data 1213 */ 1214 public void bindWithMapping(string key, void* object, string property, GSettingsBindFlags flags, GSettingsBindGetMapping getMapping, GSettingsBindSetMapping setMapping, void* userData, GDestroyNotify destroy) 1215 { 1216 // void g_settings_bind_with_mapping (GSettings *settings, const gchar *key, gpointer object, const gchar *property, GSettingsBindFlags flags, GSettingsBindGetMapping get_mapping, GSettingsBindSetMapping set_mapping, gpointer user_data, GDestroyNotify destroy); 1217 g_settings_bind_with_mapping(gSettings, Str.toStringz(key), object, Str.toStringz(property), flags, getMapping, setMapping, userData, destroy); 1218 } 1219 1220 /** 1221 * Create a binding between the writability of key in the 1222 * settings object and the property property of object. 1223 * The property must be boolean; "sensitive" or "visible" 1224 * properties of widgets are the most likely candidates. 1225 * Writable bindings are always uni-directional; changes of the 1226 * writability of the setting will be propagated to the object 1227 * property, not the other way. 1228 * When the inverted argument is TRUE, the binding inverts the 1229 * value as it passes from the setting to the object, i.e. property 1230 * will be set to TRUE if the key is not 1231 * writable. 1232 * Note that the lifecycle of the binding is tied to the object, 1233 * and that you can have only one binding per object property. 1234 * If you bind the same property twice on the same object, the second 1235 * binding overrides the first one. 1236 * Since 2.26 1237 * Params: 1238 * key = the key to bind 1239 * object = a GObject. [type GObject.Object] 1240 * property = the name of a boolean property to bind 1241 * inverted = whether to 'invert' the value 1242 */ 1243 public void bindWritable(string key, void* object, string property, int inverted) 1244 { 1245 // void g_settings_bind_writable (GSettings *settings, const gchar *key, gpointer object, const gchar *property, gboolean inverted); 1246 g_settings_bind_writable(gSettings, Str.toStringz(key), object, Str.toStringz(property), inverted); 1247 } 1248 1249 /** 1250 * Removes an existing binding for property on object. 1251 * Note that bindings are automatically removed when the 1252 * object is finalized, so it is rarely necessary to call this 1253 * function. 1254 * Since 2.26 1255 * Params: 1256 * object = the object 1257 * property = the property whose binding is removed 1258 */ 1259 public static void unbind(void* object, string property) 1260 { 1261 // void g_settings_unbind (gpointer object, const gchar *property); 1262 g_settings_unbind(object, Str.toStringz(property)); 1263 } 1264 1265 /** 1266 * Creates a GAction corresponding to a given GSettings key. 1267 * The action has the same name as the key. 1268 * The value of the key becomes the state of the action and the action 1269 * is enabled when the key is writable. Changing the state of the 1270 * action results in the key being written to. Changes to the value or 1271 * writability of the key cause appropriate change notifications to be 1272 * emitted for the action. 1273 * For boolean-valued keys, action activations take no parameter and 1274 * result in the toggling of the value. For all other types, 1275 * activations take the new value for the key (which must have the 1276 * correct type). 1277 * Since 2.32 1278 * Params: 1279 * key = the name of a key in settings 1280 * Returns: a new GAction. [transfer full] 1281 */ 1282 public ActionIF createAction(string key) 1283 { 1284 // GAction * g_settings_create_action (GSettings *settings, const gchar *key); 1285 auto p = g_settings_create_action(gSettings, Str.toStringz(key)); 1286 1287 if(p is null) 1288 { 1289 return null; 1290 } 1291 1292 return ObjectG.getDObject!(Action, ActionIF)(cast(GAction*) p); 1293 } 1294 }