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