gio/auto/settings.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5#[cfg(feature = "v2_82")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v2_82")))]
7use crate::SettingsBindFlags;
8use crate::{Action, SettingsBackend, SettingsSchema, ffi};
9use glib::{
10 object::ObjectType as _,
11 prelude::*,
12 signal::{SignalHandlerId, connect_raw},
13 translate::*,
14};
15use std::boxed::Box as Box_;
16
17glib::wrapper! {
18 /// ` elements which have a
19 /// `l10n` attribute set.
20 ///
21 /// Translations **must not** be included in the `.gschema.xml` file by the build
22 /// system, for example by using a rule to generate the XML file from a template.
23 ///
24 /// ## Properties
25 ///
26 ///
27 /// #### `backend`
28 /// The name of the context that the settings are stored in.
29 ///
30 /// Readable | Writable | Construct Only
31 ///
32 ///
33 /// #### `delay-apply`
34 /// mode](class.Settings.html#delay-apply-mode).
35 ///
36 /// Readable
37 ///
38 ///
39 /// #### `has-unapplied`
40 /// Whether the [`Settings`][crate::Settings] object has outstanding changes.
41 ///
42 /// These changes will be applied when [`SettingsExt::apply()`][crate::prelude::SettingsExt::apply()] is called.
43 ///
44 /// Readable
45 ///
46 ///
47 /// #### `path`
48 /// The path within the backend where the settings are stored.
49 ///
50 /// Readable | Writable | Construct Only
51 ///
52 ///
53 /// #### `schema`
54 /// The name of the schema that describes the types of keys
55 /// for this [`Settings`][crate::Settings] object.
56 ///
57 /// The type of this property is *not* [`SettingsSchema`][crate::SettingsSchema].
58 /// [`SettingsSchema`][crate::SettingsSchema] has only existed since version 2.32 and
59 /// unfortunately this name was used in previous versions to refer to
60 /// the schema ID rather than the schema itself. Take care to use the
61 /// [`settings-schema`][struct@crate::Settings#settings-schema] property if you wish to pass in a
62 /// [`SettingsSchema`][crate::SettingsSchema].
63 ///
64 /// Readable | Writable | Construct Only
65 ///
66 ///
67 /// #### `schema-id`
68 /// The name of the schema that describes the types of keys
69 /// for this [`Settings`][crate::Settings] object.
70 ///
71 /// Readable | Writable | Construct Only
72 ///
73 ///
74 /// #### `settings-schema`
75 /// The [`SettingsSchema`][crate::SettingsSchema] describing the types of keys for this
76 /// [`Settings`][crate::Settings] object.
77 ///
78 /// Ideally, this property would be called [`schema`][struct@crate::Settings#schema].
79 /// [`SettingsSchema`][crate::SettingsSchema]
80 /// has only existed since version 2.32, however, and before then the
81 /// [`schema`][struct@crate::Settings#schema] property was used to refer to the ID of the schema rather
82 /// than the schema itself. Take care.
83 ///
84 /// Readable | Writable | Construct Only
85 ///
86 /// ## Signals
87 ///
88 ///
89 /// #### `change-event`
90 /// Emitted once per change event that affects this settings object.
91 ///
92 /// You should connect to this signal
93 /// only if you are interested in viewing groups of changes before they
94 /// are split out into multiple emissions of the [`changed`][struct@crate::Settings#changed] signal.
95 /// For most use cases it is more appropriate to use the [`changed`][struct@crate::Settings#changed] signal.
96 ///
97 /// In the event that the change event applies to one or more specified
98 /// keys, @keys will be an array of `alias::GLib.Quark`s of length @n_keys. In the
99 /// event that the change event applies to the [`Settings`][crate::Settings] object as a
100 /// whole (ie: potentially every key has been changed) then @keys will
101 /// be `NULL` and @n_keys will be `0`.
102 ///
103 /// The default handler for this signal invokes the [`changed`][struct@crate::Settings#changed] signal
104 /// for each affected key. If any other connected handler returns
105 /// true then this default functionality will be suppressed.
106 ///
107 ///
108 ///
109 ///
110 /// #### `changed`
111 /// Emitted when a key has potentially changed.
112 ///
113 /// You should call one of the `Gio::Settings::get()` calls to check the new
114 /// value.
115 ///
116 /// This signal supports detailed connections. You can connect to the
117 /// detailed signal `changed::x` in order to only receive callbacks
118 /// when key `x` changes.
119 ///
120 /// Note that @settings only emits this signal if you have read @key at
121 /// least once while a signal handler was already connected for @key.
122 ///
123 /// Detailed
124 ///
125 ///
126 /// #### `writable-change-event`
127 /// Emitted once per writability change event that affects this settings object.
128 ///
129 /// You should connect
130 /// to this signal if you are interested in viewing groups of changes
131 /// before they are split out into multiple emissions of the
132 /// [`writable-changed`][struct@crate::Settings#writable-changed] signal. For most use cases it is more
133 /// appropriate to use the [`writable-changed`][struct@crate::Settings#writable-changed] signal.
134 ///
135 /// In the event that the writability change applies only to a single
136 /// key, @key will be set to the `alias::GLib.Quark` for that key. In the event
137 /// that the writability change affects the entire settings object,
138 /// @key will be `0`.
139 ///
140 /// The default handler for this signal invokes the [`writable-changed`][struct@crate::Settings#writable-changed]
141 /// and [`changed`][struct@crate::Settings#changed] signals for each affected key. This is done because
142 /// changes in writability might also imply changes in value (if for
143 /// example, a new mandatory setting is introduced). If any other
144 /// connected handler returns true then this default functionality
145 /// will be suppressed.
146 ///
147 ///
148 ///
149 ///
150 /// #### `writable-changed`
151 /// Emitted when the writability of a key has potentially changed.
152 ///
153 /// You should call [`SettingsExt::is_writable()`][crate::prelude::SettingsExt::is_writable()] in order to determine the
154 /// new status.
155 ///
156 /// This signal supports detailed connections. You can connect to the
157 /// detailed signal `writable-changed::x` in order to only receive
158 /// callbacks when the writability of `x` changes.
159 ///
160 /// Detailed
161 ///
162 /// # Implements
163 ///
164 /// [`SettingsExt`][trait@crate::prelude::SettingsExt], [`trait@glib::ObjectExt`], [`SettingsExtManual`][trait@crate::prelude::SettingsExtManual]
165 #[doc(alias = "GSettings")]
166 pub struct Settings(Object<ffi::GSettings, ffi::GSettingsClass>);
167
168 match fn {
169 type_ => || ffi::g_settings_get_type(),
170 }
171}
172
173impl Settings {
174 pub const NONE: Option<&'static Settings> = None;
175
176 /// Creates a new [`Settings`][crate::Settings] object with the schema specified by
177 /// @schema_id.
178 ///
179 /// It is an error for the schema to not exist: schemas are an
180 /// essential part of a program, as they provide type information.
181 /// If schemas need to be dynamically loaded (for example, from an
182 /// optional runtime dependency), [`SettingsSchemaSource::lookup()`][crate::SettingsSchemaSource::lookup()]
183 /// can be used to test for their existence before loading them.
184 ///
185 /// Signals on the newly created [`Settings`][crate::Settings] object will be dispatched
186 /// via the thread-default [`glib::MainContext`][crate::glib::MainContext] in effect at the time of the
187 /// call to [`new()`][Self::new()]. The new [`Settings`][crate::Settings] will hold a reference
188 /// on the context. See [`glib::MainContext::push_thread_default()`][crate::glib::MainContext::push_thread_default()].
189 /// ## `schema_id`
190 /// the ID of the schema
191 ///
192 /// # Returns
193 ///
194 /// a new [`Settings`][crate::Settings] object
195 #[doc(alias = "g_settings_new")]
196 pub fn new(schema_id: &str) -> Settings {
197 unsafe { from_glib_full(ffi::g_settings_new(schema_id.to_glib_none().0)) }
198 }
199
200 /// Creates a new [`Settings`][crate::Settings] object with a given schema, backend and
201 /// path.
202 ///
203 /// It should be extremely rare that you ever want to use this function.
204 /// It is made available for advanced use-cases (such as plugin systems
205 /// that want to provide access to schemas loaded from custom locations,
206 /// etc).
207 ///
208 /// At the most basic level, a [`Settings`][crate::Settings] object is a pure composition of
209 /// four things: a [`SettingsSchema`][crate::SettingsSchema], a [`SettingsBackend`][crate::SettingsBackend], a path within that
210 /// backend, and a [`glib::MainContext`][crate::glib::MainContext] to which signals are dispatched.
211 ///
212 /// This constructor therefore gives you full control over constructing
213 /// [`Settings`][crate::Settings] instances. The first 3 parameters are given directly as
214 /// @schema, @backend and @path, and the main context is taken from the
215 /// thread-default (as per [`new()`][Self::new()]).
216 ///
217 /// If @backend is `NULL` then the default backend is used.
218 ///
219 /// If @path is `NULL` then the path from the schema is used. It is an
220 /// error if @path is `NULL` and the schema has no path of its own or if
221 /// @path is non-`NULL` and not equal to the path that the schema does
222 /// have.
223 /// ## `schema`
224 /// the schema describing the settings
225 /// ## `backend`
226 /// the settings backend to use
227 /// ## `path`
228 /// the path to use
229 ///
230 /// # Returns
231 ///
232 /// a new [`Settings`][crate::Settings] object
233 #[doc(alias = "g_settings_new_full")]
234 pub fn new_full(
235 schema: &SettingsSchema,
236 backend: Option<&impl IsA<SettingsBackend>>,
237 path: Option<&str>,
238 ) -> Settings {
239 unsafe {
240 from_glib_full(ffi::g_settings_new_full(
241 schema.to_glib_none().0,
242 backend.map(|p| p.as_ref()).to_glib_none().0,
243 path.to_glib_none().0,
244 ))
245 }
246 }
247
248 /// settings database on
249 /// the system to get a settings object that modifies the system default
250 /// settings instead of the settings for this user.
251 /// ## `schema_id`
252 /// the ID of the schema
253 /// ## `backend`
254 /// the settings backend to use
255 ///
256 /// # Returns
257 ///
258 /// a new [`Settings`][crate::Settings] object
259 #[doc(alias = "g_settings_new_with_backend")]
260 #[doc(alias = "new_with_backend")]
261 pub fn with_backend(schema_id: &str, backend: &impl IsA<SettingsBackend>) -> Settings {
262 unsafe {
263 from_glib_full(ffi::g_settings_new_with_backend(
264 schema_id.to_glib_none().0,
265 backend.as_ref().to_glib_none().0,
266 ))
267 }
268 }
269
270 /// Creates a new [`Settings`][crate::Settings] object with the schema specified by
271 /// @schema_id and a given [`SettingsBackend`][crate::SettingsBackend] and path.
272 ///
273 /// This is a mix of [`with_backend()`][Self::with_backend()] and
274 /// [`with_path()`][Self::with_path()].
275 /// ## `schema_id`
276 /// the ID of the schema
277 /// ## `backend`
278 /// the settings backend to use
279 /// ## `path`
280 /// the path to use
281 ///
282 /// # Returns
283 ///
284 /// a new [`Settings`][crate::Settings] object
285 #[doc(alias = "g_settings_new_with_backend_and_path")]
286 #[doc(alias = "new_with_backend_and_path")]
287 pub fn with_backend_and_path(
288 schema_id: &str,
289 backend: &impl IsA<SettingsBackend>,
290 path: &str,
291 ) -> Settings {
292 unsafe {
293 from_glib_full(ffi::g_settings_new_with_backend_and_path(
294 schema_id.to_glib_none().0,
295 backend.as_ref().to_glib_none().0,
296 path.to_glib_none().0,
297 ))
298 }
299 }
300
301 /// s quite rare.
302 ///
303 /// It is a programmer error to call this function for a schema that
304 /// has an explicitly specified path.
305 ///
306 /// It is a programmer error if @path is not a valid path. A valid path
307 /// begins and ends with `/` and does not contain two consecutive `/`
308 /// characters.
309 /// ## `schema_id`
310 /// the ID of the schema
311 /// ## `path`
312 /// the path to use
313 ///
314 /// # Returns
315 ///
316 /// a new [`Settings`][crate::Settings] object
317 #[doc(alias = "g_settings_new_with_path")]
318 #[doc(alias = "new_with_path")]
319 pub fn with_path(schema_id: &str, path: &str) -> Settings {
320 unsafe {
321 from_glib_full(ffi::g_settings_new_with_path(
322 schema_id.to_glib_none().0,
323 path.to_glib_none().0,
324 ))
325 }
326 }
327
328 /// Ensures that all pending operations are complete for the default backend.
329 ///
330 /// Writes made to a [`Settings`][crate::Settings] are handled asynchronously. For this
331 /// reason, it is very unlikely that the changes have it to disk by the
332 /// time `Gio::Settings::set()` returns.
333 ///
334 /// This call will block until all of the writes have made it to the
335 /// backend. Since the main loop is not running, no change notifications
336 /// will be dispatched during this call (but some may be queued by the
337 /// time the call is done).
338 #[doc(alias = "g_settings_sync")]
339 pub fn sync() {
340 unsafe {
341 ffi::g_settings_sync();
342 }
343 }
344
345 /// Removes an existing binding for @property on @object.
346 ///
347 /// Note that bindings are automatically removed when the
348 /// object is finalized, so it is rarely necessary to call this
349 /// function.
350 /// ## `object`
351 /// the object with property to unbind
352 /// ## `property`
353 /// the property whose binding is removed
354 #[doc(alias = "g_settings_unbind")]
355 pub fn unbind(object: &impl IsA<glib::Object>, property: &str) {
356 unsafe {
357 ffi::g_settings_unbind(object.as_ref().to_glib_none().0, property.to_glib_none().0);
358 }
359 }
360}
361
362/// Trait containing all [`struct@Settings`] methods.
363///
364/// # Implementors
365///
366/// [`Settings`][struct@crate::Settings]
367pub trait SettingsExt: IsA<Settings> + 'static {
368 /// mode](class.Settings.html#delay-apply-mode). In the normal
369 /// case settings are always applied immediately.
370 #[doc(alias = "g_settings_apply")]
371 fn apply(&self) {
372 unsafe {
373 ffi::g_settings_apply(self.as_ref().to_glib_none().0);
374 }
375 }
376
377 /// Version of [`SettingsExtManual::bind_with_mapping()`][crate::prelude::SettingsExtManual::bind_with_mapping()] using closures instead of
378 /// callbacks for easier binding in other languages.
379 /// ## `key`
380 /// the key to bind
381 /// ## `object`
382 /// the object with property to bind
383 /// ## `property`
384 /// the name of the property to bind
385 /// ## `flags`
386 /// flags for the binding
387 /// ## `get_mapping`
388 /// a function that gets called to convert values
389 /// from @self to @object, or `NULL` to use the default GIO mapping
390 /// ## `set_mapping`
391 /// a function that gets called to convert values
392 /// from @object to @self, or `NULL` to use the default GIO mapping
393 #[cfg(feature = "v2_82")]
394 #[cfg_attr(docsrs, doc(cfg(feature = "v2_82")))]
395 #[doc(alias = "g_settings_bind_with_mapping_closures")]
396 fn bind_with_mapping_closures(
397 &self,
398 key: &str,
399 object: &impl IsA<glib::Object>,
400 property: &str,
401 flags: SettingsBindFlags,
402 get_mapping: Option<&glib::Closure>,
403 set_mapping: Option<&glib::Closure>,
404 ) {
405 unsafe {
406 ffi::g_settings_bind_with_mapping_closures(
407 self.as_ref().to_glib_none().0,
408 key.to_glib_none().0,
409 object.as_ref().to_glib_none().0,
410 property.to_glib_none().0,
411 flags.into_glib(),
412 get_mapping.to_glib_none().0,
413 set_mapping.to_glib_none().0,
414 );
415 }
416 }
417
418 /// Create a binding between the writability of @key in the
419 /// @self object and the property @property of @object.
420 ///
421 /// The property must be boolean; `sensitive` or `visible`
422 /// properties of widgets are the most likely candidates.
423 ///
424 /// Writable bindings are always uni-directional; changes of the
425 /// writability of the setting will be propagated to the object
426 /// property, not the other way.
427 ///
428 /// When the @inverted argument is true, the binding inverts the
429 /// value as it passes from the setting to the object, i.e. @property
430 /// will be set to true if the key is not writable.
431 ///
432 /// Note that the lifecycle of the binding is tied to @object,
433 /// and that you can have only one binding per object property.
434 /// If you bind the same property twice on the same object, the second
435 /// binding overrides the first one.
436 /// ## `key`
437 /// the key to bind
438 /// ## `object`
439 /// the object with property to bind
440 /// ## `property`
441 /// the name of a boolean property to bind
442 /// ## `inverted`
443 /// the value
444 #[doc(alias = "g_settings_bind_writable")]
445 fn bind_writable(
446 &self,
447 key: &str,
448 object: &impl IsA<glib::Object>,
449 property: &str,
450 inverted: bool,
451 ) {
452 unsafe {
453 ffi::g_settings_bind_writable(
454 self.as_ref().to_glib_none().0,
455 key.to_glib_none().0,
456 object.as_ref().to_glib_none().0,
457 property.to_glib_none().0,
458 inverted.into_glib(),
459 );
460 }
461 }
462
463 /// Creates a [`Action`][crate::Action] corresponding to a given [`Settings`][crate::Settings] key.
464 ///
465 /// The action has the same name as the key.
466 ///
467 /// The value of the key becomes the state of the action and the action
468 /// is enabled when the key is writable. Changing the state of the
469 /// action results in the key being written to. Changes to the value or
470 /// writability of the key cause appropriate change notifications to be
471 /// emitted for the action.
472 ///
473 /// For boolean-valued keys, action activations take no parameter and
474 /// result in the toggling of the value. For all other types,
475 /// activations take the new value for the key (which must have the
476 /// correct type).
477 /// ## `key`
478 /// the name of a key in @self
479 ///
480 /// # Returns
481 ///
482 /// a new [`Action`][crate::Action]
483 #[doc(alias = "g_settings_create_action")]
484 fn create_action(&self, key: &str) -> Action {
485 unsafe {
486 from_glib_full(ffi::g_settings_create_action(
487 self.as_ref().to_glib_none().0,
488 key.to_glib_none().0,
489 ))
490 }
491 }
492
493 /// mode](class.Settings.html#delay-apply-mode).
494 ///
495 /// In this
496 /// mode, changes to @self are not immediately propagated to the
497 /// backend, but kept locally until [`apply()`][Self::apply()] is called.
498 #[doc(alias = "g_settings_delay")]
499 fn delay(&self) {
500 unsafe {
501 ffi::g_settings_delay(self.as_ref().to_glib_none().0);
502 }
503 }
504
505 //#[doc(alias = "g_settings_get")]
506 //fn get(&self, key: &str, format: &str, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) {
507 // unsafe { TODO: call ffi:g_settings_get() }
508 //}
509
510 /// t specified as
511 /// having a `b` type in the schema for @self (see [`glib::VariantType`][crate::glib::VariantType]).
512 /// ## `key`
513 /// the key to get the value for
514 ///
515 /// # Returns
516 ///
517 /// a boolean
518 #[doc(alias = "g_settings_get_boolean")]
519 #[doc(alias = "get_boolean")]
520 fn boolean(&self, key: &str) -> bool {
521 unsafe {
522 from_glib(ffi::g_settings_get_boolean(
523 self.as_ref().to_glib_none().0,
524 key.to_glib_none().0,
525 ))
526 }
527 }
528
529 /// ` element.
530 ///
531 /// The created child settings object will inherit the
532 /// [`delay-apply`][struct@crate::Settings#delay-apply] mode from @self.
533 /// ## `name`
534 /// the name of the child schema
535 ///
536 /// # Returns
537 ///
538 /// settings object
539 #[doc(alias = "g_settings_get_child")]
540 #[doc(alias = "get_child")]
541 #[must_use]
542 fn child(&self, name: &str) -> Settings {
543 unsafe {
544 from_glib_full(ffi::g_settings_get_child(
545 self.as_ref().to_glib_none().0,
546 name.to_glib_none().0,
547 ))
548 }
549 }
550
551 /// t contained in the
552 /// schema for @self.
553 /// ## `key`
554 /// the key to get the default value for
555 ///
556 /// # Returns
557 ///
558 /// the default value
559 #[doc(alias = "g_settings_get_default_value")]
560 #[doc(alias = "get_default_value")]
561 fn default_value(&self, key: &str) -> Option<glib::Variant> {
562 unsafe {
563 from_glib_full(ffi::g_settings_get_default_value(
564 self.as_ref().to_glib_none().0,
565 key.to_glib_none().0,
566 ))
567 }
568 }
569
570 /// t specified as
571 /// having a `d` type in the schema for @self (see [`glib::VariantType`][crate::glib::VariantType]).
572 /// ## `key`
573 /// the key to get the value for
574 ///
575 /// # Returns
576 ///
577 /// a double
578 #[doc(alias = "g_settings_get_double")]
579 #[doc(alias = "get_double")]
580 fn double(&self, key: &str) -> f64 {
581 unsafe { ffi::g_settings_get_double(self.as_ref().to_glib_none().0, key.to_glib_none().0) }
582 }
583
584 /// t contained in the
585 /// schema for @self or is not marked as an enumerated type.
586 ///
587 /// If the value stored in the configuration database is not a valid
588 /// value for the enumerated type then this function will return the
589 /// default value.
590 /// ## `key`
591 /// the key to get the value for
592 ///
593 /// # Returns
594 ///
595 /// the enum value
596 #[doc(alias = "g_settings_get_enum")]
597 #[doc(alias = "get_enum")]
598 fn enum_(&self, key: &str) -> i32 {
599 unsafe { ffi::g_settings_get_enum(self.as_ref().to_glib_none().0, key.to_glib_none().0) }
600 }
601
602 /// t contained in the
603 /// schema for @self or is not marked as a flags type.
604 ///
605 /// If the value stored in the configuration database is not a valid
606 /// value for the flags type then this function will return the default
607 /// value.
608 /// ## `key`
609 /// the key to get the value for
610 ///
611 /// # Returns
612 ///
613 /// the flags value
614 #[doc(alias = "g_settings_get_flags")]
615 #[doc(alias = "get_flags")]
616 fn flags(&self, key: &str) -> u32 {
617 unsafe { ffi::g_settings_get_flags(self.as_ref().to_glib_none().0, key.to_glib_none().0) }
618 }
619
620 /// mode](class.Settings.html#delay-apply-mode).
621 ///
622 /// # Returns
623 ///
624 /// true if @self has unapplied changes, false otherwise
625 #[doc(alias = "g_settings_get_has_unapplied")]
626 #[doc(alias = "get_has_unapplied")]
627 #[doc(alias = "has-unapplied")]
628 fn has_unapplied(&self) -> bool {
629 unsafe {
630 from_glib(ffi::g_settings_get_has_unapplied(
631 self.as_ref().to_glib_none().0,
632 ))
633 }
634 }
635
636 /// t specified as
637 /// having an `i` type in the schema for @self (see [`glib::VariantType`][crate::glib::VariantType]).
638 /// ## `key`
639 /// the key to get the value for
640 ///
641 /// # Returns
642 ///
643 /// an integer
644 #[doc(alias = "g_settings_get_int")]
645 #[doc(alias = "get_int")]
646 fn int(&self, key: &str) -> i32 {
647 unsafe { ffi::g_settings_get_int(self.as_ref().to_glib_none().0, key.to_glib_none().0) }
648 }
649
650 /// t specified as
651 /// having an `x` type in the schema for @self (see [`glib::VariantType`][crate::glib::VariantType]).
652 /// ## `key`
653 /// the key to get the value for
654 ///
655 /// # Returns
656 ///
657 /// a 64-bit integer
658 #[doc(alias = "g_settings_get_int64")]
659 #[doc(alias = "get_int64")]
660 fn int64(&self, key: &str) -> i64 {
661 unsafe { ffi::g_settings_get_int64(self.as_ref().to_glib_none().0, key.to_glib_none().0) }
662 }
663
664 //#[doc(alias = "g_settings_get_mapped")]
665 //#[doc(alias = "get_mapped")]
666 //fn mapped(&self, key: &str, mapping: /*Unimplemented*/FnMut(Option<&glib::Variant>, /*Unimplemented*/Option<Basic: Pointer>) -> bool, user_data: /*Unimplemented*/Option<Basic: Pointer>) -> /*Unimplemented*/Option<Basic: Pointer> {
667 // unsafe { TODO: call ffi:g_settings_get_mapped() }
668 //}
669
670 /// t specified as
671 /// having an `s` type in the schema for @self (see [`glib::VariantType`][crate::glib::VariantType]).
672 /// ## `key`
673 /// the key to get the value for
674 ///
675 /// # Returns
676 ///
677 /// a newly-allocated string
678 #[doc(alias = "g_settings_get_string")]
679 #[doc(alias = "get_string")]
680 fn string(&self, key: &str) -> glib::GString {
681 unsafe {
682 from_glib_full(ffi::g_settings_get_string(
683 self.as_ref().to_glib_none().0,
684 key.to_glib_none().0,
685 ))
686 }
687 }
688
689 /// t specified as
690 /// having a `u` type in the schema for @self (see [`glib::VariantType`][crate::glib::VariantType]).
691 /// ## `key`
692 /// the key to get the value for
693 ///
694 /// # Returns
695 ///
696 /// an unsigned integer
697 #[doc(alias = "g_settings_get_uint")]
698 #[doc(alias = "get_uint")]
699 fn uint(&self, key: &str) -> u32 {
700 unsafe { ffi::g_settings_get_uint(self.as_ref().to_glib_none().0, key.to_glib_none().0) }
701 }
702
703 /// t specified as
704 /// having a `t` type in the schema for @self (see [`glib::VariantType`][crate::glib::VariantType]).
705 /// ## `key`
706 /// the key to get the value for
707 ///
708 /// # Returns
709 ///
710 /// a 64-bit unsigned integer
711 #[doc(alias = "g_settings_get_uint64")]
712 #[doc(alias = "get_uint64")]
713 fn uint64(&self, key: &str) -> u64 {
714 unsafe { ffi::g_settings_get_uint64(self.as_ref().to_glib_none().0, key.to_glib_none().0) }
715 }
716
717 /// t contained in the
718 /// schema for @self.
719 /// ## `key`
720 /// the key to get the user value for
721 ///
722 /// # Returns
723 ///
724 /// s value, if set
725 #[doc(alias = "g_settings_get_user_value")]
726 #[doc(alias = "get_user_value")]
727 fn user_value(&self, key: &str) -> Option<glib::Variant> {
728 unsafe {
729 from_glib_full(ffi::g_settings_get_user_value(
730 self.as_ref().to_glib_none().0,
731 key.to_glib_none().0,
732 ))
733 }
734 }
735
736 /// t contained in the
737 /// schema for @self.
738 /// ## `key`
739 /// the key to get the value for
740 ///
741 /// # Returns
742 ///
743 /// a new [`glib::Variant`][struct@crate::glib::Variant]
744 #[doc(alias = "g_settings_get_value")]
745 #[doc(alias = "get_value")]
746 fn value(&self, key: &str) -> glib::Variant {
747 unsafe {
748 from_glib_full(ffi::g_settings_get_value(
749 self.as_ref().to_glib_none().0,
750 key.to_glib_none().0,
751 ))
752 }
753 }
754
755 /// Finds out if a key can be written.
756 /// ## `name`
757 /// the name of a key
758 ///
759 /// # Returns
760 ///
761 /// true if the key @name is writable, false otherwise
762 #[doc(alias = "g_settings_is_writable")]
763 fn is_writable(&self, name: &str) -> bool {
764 unsafe {
765 from_glib(ffi::g_settings_is_writable(
766 self.as_ref().to_glib_none().0,
767 name.to_glib_none().0,
768 ))
769 }
770 }
771
772 /// code, since
773 /// you should already know what children are in your schema. This function
774 /// may still be useful there for introspection reasons, however.
775 ///
776 /// You should free the return value with `strfreev()` when you are done
777 /// with it.
778 ///
779 /// # Returns
780 ///
781 /// a list of the children
782 /// on @self, in no defined order
783 #[doc(alias = "g_settings_list_children")]
784 fn list_children(&self) -> Vec<glib::GString> {
785 unsafe {
786 FromGlibPtrContainer::from_glib_full(ffi::g_settings_list_children(
787 self.as_ref().to_glib_none().0,
788 ))
789 }
790 }
791
792 /// Resets @key to its default value.
793 ///
794 /// This call resets the key, as much as possible, to its default value.
795 /// That might be the value specified in the schema or the one set by the
796 /// administrator.
797 /// ## `key`
798 /// the name of a key
799 #[doc(alias = "g_settings_reset")]
800 fn reset(&self, key: &str) {
801 unsafe {
802 ffi::g_settings_reset(self.as_ref().to_glib_none().0, key.to_glib_none().0);
803 }
804 }
805
806 /// mode](class.Settings.html#delay-apply-mode). In the normal
807 /// case settings are always applied immediately.
808 ///
809 /// Change notifications will be emitted for affected keys.
810 #[doc(alias = "g_settings_revert")]
811 fn revert(&self) {
812 unsafe {
813 ffi::g_settings_revert(self.as_ref().to_glib_none().0);
814 }
815 }
816
817 //#[doc(alias = "g_settings_set")]
818 //fn set(&self, key: &str, format: &str, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) -> bool {
819 // unsafe { TODO: call ffi:g_settings_set() }
820 //}
821
822 /// t specified as
823 /// having a `b` type in the schema for @self (see [`glib::VariantType`][crate::glib::VariantType]).
824 /// ## `key`
825 /// the key to set the value for
826 /// ## `value`
827 /// the value to set it to
828 ///
829 /// # Returns
830 ///
831 /// true if setting the key succeeded,
832 /// false if the key was not writable
833 #[doc(alias = "g_settings_set_boolean")]
834 fn set_boolean(&self, key: &str, value: bool) -> Result<(), glib::error::BoolError> {
835 unsafe {
836 glib::result_from_gboolean!(
837 ffi::g_settings_set_boolean(
838 self.as_ref().to_glib_none().0,
839 key.to_glib_none().0,
840 value.into_glib()
841 ),
842 "Can't set readonly key"
843 )
844 }
845 }
846
847 /// t specified as
848 /// having a `d` type in the schema for @self (see [`glib::VariantType`][crate::glib::VariantType]).
849 /// ## `key`
850 /// the key to set the value for
851 /// ## `value`
852 /// the value to set it to
853 ///
854 /// # Returns
855 ///
856 /// true if setting the key succeeded,
857 /// false if the key was not writable
858 #[doc(alias = "g_settings_set_double")]
859 fn set_double(&self, key: &str, value: f64) -> Result<(), glib::error::BoolError> {
860 unsafe {
861 glib::result_from_gboolean!(
862 ffi::g_settings_set_double(
863 self.as_ref().to_glib_none().0,
864 key.to_glib_none().0,
865 value
866 ),
867 "Can't set readonly key"
868 )
869 }
870 }
871
872 /// associated with
873 /// @value.
874 /// ## `key`
875 /// the key to set the value for
876 /// ## `value`
877 /// an enumerated value
878 ///
879 /// # Returns
880 ///
881 /// true if the set succeeds, false otherwise
882 #[doc(alias = "g_settings_set_enum")]
883 fn set_enum(&self, key: &str, value: i32) -> Result<(), glib::error::BoolError> {
884 unsafe {
885 glib::result_from_gboolean!(
886 ffi::g_settings_set_enum(
887 self.as_ref().to_glib_none().0,
888 key.to_glib_none().0,
889 value
890 ),
891 "Can't set readonly key"
892 )
893 }
894 }
895
896 /// ; one for each
897 /// bit in @value.
898 /// ## `key`
899 /// the key to set the value for
900 /// ## `value`
901 /// a flags value
902 ///
903 /// # Returns
904 ///
905 /// true if the set succeeds, false otherwise
906 #[doc(alias = "g_settings_set_flags")]
907 fn set_flags(&self, key: &str, value: u32) -> Result<(), glib::error::BoolError> {
908 unsafe {
909 glib::result_from_gboolean!(
910 ffi::g_settings_set_flags(
911 self.as_ref().to_glib_none().0,
912 key.to_glib_none().0,
913 value
914 ),
915 "Can't set readonly key"
916 )
917 }
918 }
919
920 /// t specified as
921 /// having an `i` type in the schema for @self (see [`glib::VariantType`][crate::glib::VariantType]).
922 /// ## `key`
923 /// the key to set the value for
924 /// ## `value`
925 /// the value to set it to
926 ///
927 /// # Returns
928 ///
929 /// true if setting the key succeeded,
930 /// false if the key was not writable
931 #[doc(alias = "g_settings_set_int")]
932 fn set_int(&self, key: &str, value: i32) -> Result<(), glib::error::BoolError> {
933 unsafe {
934 glib::result_from_gboolean!(
935 ffi::g_settings_set_int(
936 self.as_ref().to_glib_none().0,
937 key.to_glib_none().0,
938 value
939 ),
940 "Can't set readonly key"
941 )
942 }
943 }
944
945 /// t specified as
946 /// having an `x` type in the schema for @self (see [`glib::VariantType`][crate::glib::VariantType]).
947 /// ## `key`
948 /// the key to set the value for
949 /// ## `value`
950 /// the value to set it to
951 ///
952 /// # Returns
953 ///
954 /// true if setting the key succeeded,
955 /// false if the key was not writable
956 #[doc(alias = "g_settings_set_int64")]
957 fn set_int64(&self, key: &str, value: i64) -> Result<(), glib::error::BoolError> {
958 unsafe {
959 glib::result_from_gboolean!(
960 ffi::g_settings_set_int64(
961 self.as_ref().to_glib_none().0,
962 key.to_glib_none().0,
963 value
964 ),
965 "Can't set readonly key"
966 )
967 }
968 }
969
970 /// t specified as
971 /// having an `s` type in the schema for @self (see [`glib::VariantType`][crate::glib::VariantType]).
972 /// ## `key`
973 /// the key to set the value for
974 /// ## `value`
975 /// the value to set it to
976 ///
977 /// # Returns
978 ///
979 /// true if setting the key succeeded,
980 /// false if the key was not writable
981 #[doc(alias = "g_settings_set_string")]
982 fn set_string(&self, key: &str, value: &str) -> Result<(), glib::error::BoolError> {
983 unsafe {
984 glib::result_from_gboolean!(
985 ffi::g_settings_set_string(
986 self.as_ref().to_glib_none().0,
987 key.to_glib_none().0,
988 value.to_glib_none().0
989 ),
990 "Can't set readonly key"
991 )
992 }
993 }
994
995 /// t specified as
996 /// having a `u` type in the schema for @self (see [`glib::VariantType`][crate::glib::VariantType]).
997 /// ## `key`
998 /// the key to set the value for
999 /// ## `value`
1000 /// the value to set it to
1001 ///
1002 /// # Returns
1003 ///
1004 /// true if setting the key succeeded,
1005 /// false if the key was not writable
1006 #[doc(alias = "g_settings_set_uint")]
1007 fn set_uint(&self, key: &str, value: u32) -> Result<(), glib::error::BoolError> {
1008 unsafe {
1009 glib::result_from_gboolean!(
1010 ffi::g_settings_set_uint(
1011 self.as_ref().to_glib_none().0,
1012 key.to_glib_none().0,
1013 value
1014 ),
1015 "Can't set readonly key"
1016 )
1017 }
1018 }
1019
1020 /// t specified as
1021 /// having a `t` type in the schema for @self (see [`glib::VariantType`][crate::glib::VariantType]).
1022 /// ## `key`
1023 /// the key to set the value for
1024 /// ## `value`
1025 /// the value to set it to
1026 ///
1027 /// # Returns
1028 ///
1029 /// true if setting the key succeeded,
1030 /// false if the key was not writable
1031 #[doc(alias = "g_settings_set_uint64")]
1032 fn set_uint64(&self, key: &str, value: u64) -> Result<(), glib::error::BoolError> {
1033 unsafe {
1034 glib::result_from_gboolean!(
1035 ffi::g_settings_set_uint64(
1036 self.as_ref().to_glib_none().0,
1037 key.to_glib_none().0,
1038 value
1039 ),
1040 "Can't set readonly key"
1041 )
1042 }
1043 }
1044
1045 /// t contained in the
1046 /// schema for @self or for @value to have the incorrect type, per
1047 /// the schema.
1048 ///
1049 /// If @value is floating then this function consumes the reference.
1050 /// ## `key`
1051 /// the key to set the value for
1052 /// ## `value`
1053 /// a [`glib::Variant`][struct@crate::glib::Variant] of the correct type
1054 ///
1055 /// # Returns
1056 ///
1057 /// true if setting the key succeeded,
1058 /// false if the key was not writable
1059 #[doc(alias = "g_settings_set_value")]
1060 fn set_value(&self, key: &str, value: &glib::Variant) -> Result<(), glib::error::BoolError> {
1061 unsafe {
1062 glib::result_from_gboolean!(
1063 ffi::g_settings_set_value(
1064 self.as_ref().to_glib_none().0,
1065 key.to_glib_none().0,
1066 value.to_glib_none().0
1067 ),
1068 "Can't set readonly key"
1069 )
1070 }
1071 }
1072
1073 /// The name of the context that the settings are stored in.
1074 fn backend(&self) -> Option<SettingsBackend> {
1075 ObjectExt::property(self.as_ref(), "backend")
1076 }
1077
1078 /// mode](class.Settings.html#delay-apply-mode).
1079 #[doc(alias = "delay-apply")]
1080 fn is_delay_apply(&self) -> bool {
1081 ObjectExt::property(self.as_ref(), "delay-apply")
1082 }
1083
1084 /// The path within the backend where the settings are stored.
1085 fn path(&self) -> Option<glib::GString> {
1086 ObjectExt::property(self.as_ref(), "path")
1087 }
1088
1089 /// The name of the schema that describes the types of keys
1090 /// for this [`Settings`][crate::Settings] object.
1091 #[doc(alias = "schema-id")]
1092 fn schema_id(&self) -> Option<glib::GString> {
1093 ObjectExt::property(self.as_ref(), "schema-id")
1094 }
1095
1096 /// The [`SettingsSchema`][crate::SettingsSchema] describing the types of keys for this
1097 /// [`Settings`][crate::Settings] object.
1098 ///
1099 /// Ideally, this property would be called [`schema`][struct@crate::Settings#schema].
1100 /// [`SettingsSchema`][crate::SettingsSchema]
1101 /// has only existed since version 2.32, however, and before then the
1102 /// [`schema`][struct@crate::Settings#schema] property was used to refer to the ID of the schema rather
1103 /// than the schema itself. Take care.
1104 #[doc(alias = "settings-schema")]
1105 fn settings_schema(&self) -> Option<SettingsSchema> {
1106 ObjectExt::property(self.as_ref(), "settings-schema")
1107 }
1108
1109 //#[doc(alias = "change-event")]
1110 //fn connect_change_event<Unsupported or ignored types>(&self, f: F) -> SignalHandlerId {
1111 // Unimplemented keys: *.CArray TypeId { ns_id: 3, id: 13 }
1112 //}
1113
1114 /// Emitted when a key has potentially changed.
1115 ///
1116 /// You should call one of the `Gio::Settings::get()` calls to check the new
1117 /// value.
1118 ///
1119 /// This signal supports detailed connections. You can connect to the
1120 /// detailed signal `changed::x` in order to only receive callbacks
1121 /// when key `x` changes.
1122 ///
1123 /// Note that @settings only emits this signal if you have read @key at
1124 /// least once while a signal handler was already connected for @key.
1125 /// ## `key`
1126 /// the name of the key that changed
1127 #[doc(alias = "changed")]
1128 fn connect_changed<F: Fn(&Self, &str) + 'static>(
1129 &self,
1130 detail: Option<&str>,
1131 f: F,
1132 ) -> SignalHandlerId {
1133 unsafe extern "C" fn changed_trampoline<P: IsA<Settings>, F: Fn(&P, &str) + 'static>(
1134 this: *mut ffi::GSettings,
1135 key: *mut std::ffi::c_char,
1136 f: glib::ffi::gpointer,
1137 ) {
1138 unsafe {
1139 let f: &F = &*(f as *const F);
1140 f(
1141 Settings::from_glib_borrow(this).unsafe_cast_ref(),
1142 &glib::GString::from_glib_borrow(key),
1143 )
1144 }
1145 }
1146 unsafe {
1147 let f: Box_<F> = Box_::new(f);
1148 let detailed_signal_name = detail.map(|name| format!("changed::{name}\0"));
1149 let signal_name = detailed_signal_name.as_ref().map_or(c"changed", |n| {
1150 std::ffi::CStr::from_bytes_with_nul_unchecked(n.as_bytes())
1151 });
1152 connect_raw(
1153 self.as_ptr() as *mut _,
1154 signal_name.as_ptr(),
1155 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1156 changed_trampoline::<Self, F> as *const (),
1157 )),
1158 Box_::into_raw(f),
1159 )
1160 }
1161 }
1162
1163 /// Emitted once per writability change event that affects this settings object.
1164 ///
1165 /// You should connect
1166 /// to this signal if you are interested in viewing groups of changes
1167 /// before they are split out into multiple emissions of the
1168 /// [`writable-changed`][struct@crate::Settings#writable-changed] signal. For most use cases it is more
1169 /// appropriate to use the [`writable-changed`][struct@crate::Settings#writable-changed] signal.
1170 ///
1171 /// In the event that the writability change applies only to a single
1172 /// key, @key will be set to the `alias::GLib.Quark` for that key. In the event
1173 /// that the writability change affects the entire settings object,
1174 /// @key will be `0`.
1175 ///
1176 /// The default handler for this signal invokes the [`writable-changed`][struct@crate::Settings#writable-changed]
1177 /// and [`changed`][struct@crate::Settings#changed] signals for each affected key. This is done because
1178 /// changes in writability might also imply changes in value (if for
1179 /// example, a new mandatory setting is introduced). If any other
1180 /// connected handler returns true then this default functionality
1181 /// will be suppressed.
1182 /// ## `key`
1183 /// the quark of the key, or `0`
1184 ///
1185 /// # Returns
1186 ///
1187 /// true to stop other handlers from being invoked for the
1188 /// event, false to propagate the event further
1189 #[doc(alias = "writable-change-event")]
1190 fn connect_writable_change_event<F: Fn(&Self, u32) -> glib::Propagation + 'static>(
1191 &self,
1192 f: F,
1193 ) -> SignalHandlerId {
1194 unsafe extern "C" fn writable_change_event_trampoline<
1195 P: IsA<Settings>,
1196 F: Fn(&P, u32) -> glib::Propagation + 'static,
1197 >(
1198 this: *mut ffi::GSettings,
1199 key: std::ffi::c_uint,
1200 f: glib::ffi::gpointer,
1201 ) -> glib::ffi::gboolean {
1202 unsafe {
1203 let f: &F = &*(f as *const F);
1204 f(Settings::from_glib_borrow(this).unsafe_cast_ref(), key).into_glib()
1205 }
1206 }
1207 unsafe {
1208 let f: Box_<F> = Box_::new(f);
1209 connect_raw(
1210 self.as_ptr() as *mut _,
1211 c"writable-change-event".as_ptr(),
1212 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1213 writable_change_event_trampoline::<Self, F> as *const (),
1214 )),
1215 Box_::into_raw(f),
1216 )
1217 }
1218 }
1219
1220 /// Emitted when the writability of a key has potentially changed.
1221 ///
1222 /// You should call [`is_writable()`][Self::is_writable()] in order to determine the
1223 /// new status.
1224 ///
1225 /// This signal supports detailed connections. You can connect to the
1226 /// detailed signal `writable-changed::x` in order to only receive
1227 /// callbacks when the writability of `x` changes.
1228 /// ## `key`
1229 /// the key
1230 #[doc(alias = "writable-changed")]
1231 fn connect_writable_changed<F: Fn(&Self, &str) + 'static>(
1232 &self,
1233 detail: Option<&str>,
1234 f: F,
1235 ) -> SignalHandlerId {
1236 unsafe extern "C" fn writable_changed_trampoline<
1237 P: IsA<Settings>,
1238 F: Fn(&P, &str) + 'static,
1239 >(
1240 this: *mut ffi::GSettings,
1241 key: *mut std::ffi::c_char,
1242 f: glib::ffi::gpointer,
1243 ) {
1244 unsafe {
1245 let f: &F = &*(f as *const F);
1246 f(
1247 Settings::from_glib_borrow(this).unsafe_cast_ref(),
1248 &glib::GString::from_glib_borrow(key),
1249 )
1250 }
1251 }
1252 unsafe {
1253 let f: Box_<F> = Box_::new(f);
1254 let detailed_signal_name = detail.map(|name| format!("writable-changed::{name}\0"));
1255 let signal_name = detailed_signal_name
1256 .as_ref()
1257 .map_or(c"writable-changed", |n| {
1258 std::ffi::CStr::from_bytes_with_nul_unchecked(n.as_bytes())
1259 });
1260 connect_raw(
1261 self.as_ptr() as *mut _,
1262 signal_name.as_ptr(),
1263 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1264 writable_changed_trampoline::<Self, F> as *const (),
1265 )),
1266 Box_::into_raw(f),
1267 )
1268 }
1269 }
1270
1271 #[doc(alias = "delay-apply")]
1272 fn connect_delay_apply_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1273 unsafe extern "C" fn notify_delay_apply_trampoline<
1274 P: IsA<Settings>,
1275 F: Fn(&P) + 'static,
1276 >(
1277 this: *mut ffi::GSettings,
1278 _param_spec: glib::ffi::gpointer,
1279 f: glib::ffi::gpointer,
1280 ) {
1281 unsafe {
1282 let f: &F = &*(f as *const F);
1283 f(Settings::from_glib_borrow(this).unsafe_cast_ref())
1284 }
1285 }
1286 unsafe {
1287 let f: Box_<F> = Box_::new(f);
1288 connect_raw(
1289 self.as_ptr() as *mut _,
1290 c"notify::delay-apply".as_ptr(),
1291 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1292 notify_delay_apply_trampoline::<Self, F> as *const (),
1293 )),
1294 Box_::into_raw(f),
1295 )
1296 }
1297 }
1298
1299 #[doc(alias = "has-unapplied")]
1300 fn connect_has_unapplied_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1301 unsafe extern "C" fn notify_has_unapplied_trampoline<
1302 P: IsA<Settings>,
1303 F: Fn(&P) + 'static,
1304 >(
1305 this: *mut ffi::GSettings,
1306 _param_spec: glib::ffi::gpointer,
1307 f: glib::ffi::gpointer,
1308 ) {
1309 unsafe {
1310 let f: &F = &*(f as *const F);
1311 f(Settings::from_glib_borrow(this).unsafe_cast_ref())
1312 }
1313 }
1314 unsafe {
1315 let f: Box_<F> = Box_::new(f);
1316 connect_raw(
1317 self.as_ptr() as *mut _,
1318 c"notify::has-unapplied".as_ptr(),
1319 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1320 notify_has_unapplied_trampoline::<Self, F> as *const (),
1321 )),
1322 Box_::into_raw(f),
1323 )
1324 }
1325 }
1326}
1327
1328impl<O: IsA<Settings>> SettingsExt for O {}