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