Skip to main content

lightdm/auto/
language.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from lightdm-gir-files
3// DO NOT EDIT
4
5use crate::ffi;
6use glib::{
7    prelude::*,
8    signal::{SignalHandlerId, connect_raw},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    /// #LightDMLanguage is an opaque data structure and can only be accessed
15    /// using the provided functions.
16    ///
17    /// ## Properties
18    ///
19    ///
20    /// #### `code`
21    ///  Readable | Writeable | Construct Only
22    ///
23    ///
24    /// #### `name`
25    ///  Readable
26    ///
27    ///
28    /// #### `territory`
29    ///  Readable
30    ///
31    /// # Implements
32    ///
33    /// [`LanguageExt`][trait@crate::prelude::LanguageExt]
34    #[doc(alias = "LightDMLanguage")]
35    pub struct Language(Object<ffi::LightDMLanguage, ffi::LightDMLanguageClass>);
36
37    match fn {
38        type_ => || ffi::lightdm_language_get_type(),
39    }
40}
41
42impl Language {
43    pub const NONE: Option<&'static Language> = None;
44
45    // rustdoc-stripper-ignore-next
46    /// Creates a new builder-pattern struct instance to construct [`Language`] objects.
47    ///
48    /// This method returns an instance of [`LanguageBuilder`](crate::builders::LanguageBuilder) which can be used to create [`Language`] objects.
49    pub fn builder() -> LanguageBuilder {
50        LanguageBuilder::new()
51    }
52}
53
54// rustdoc-stripper-ignore-next
55/// A [builder-pattern] type to construct [`Language`] objects.
56///
57/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
58#[must_use = "The builder must be built to be used"]
59pub struct LanguageBuilder {
60    builder: glib::object::ObjectBuilder<'static, Language>,
61}
62
63impl LanguageBuilder {
64    fn new() -> Self {
65        Self {
66            builder: glib::object::Object::builder(),
67        }
68    }
69
70    pub fn code(self, code: impl Into<glib::GString>) -> Self {
71        Self {
72            builder: self.builder.property("code", code.into()),
73        }
74    }
75
76    // rustdoc-stripper-ignore-next
77    /// Build the [`Language`].
78    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
79    pub fn build(self) -> Language {
80        assert_initialized_main_thread!();
81        self.builder.build()
82    }
83}
84
85/// Trait containing all [`struct@Language`] methods.
86///
87/// # Implementors
88///
89/// [`Language`][struct@crate::Language]
90pub trait LanguageExt: IsA<Language> + 'static {
91    /// Get the code of a language (e.g. "de_DE.UTF-8")
92    ///
93    /// # Returns
94    ///
95    /// The code of the language
96    #[doc(alias = "lightdm_language_get_code")]
97    #[doc(alias = "get_code")]
98    fn code(&self) -> Option<glib::GString> {
99        unsafe {
100            from_glib_none(ffi::lightdm_language_get_code(
101                self.as_ref().to_glib_none().0,
102            ))
103        }
104    }
105
106    /// Get the name of a language.
107    ///
108    /// # Returns
109    ///
110    /// The name of the language
111    #[doc(alias = "lightdm_language_get_name")]
112    #[doc(alias = "get_name")]
113    fn name(&self) -> Option<glib::GString> {
114        unsafe {
115            from_glib_none(ffi::lightdm_language_get_name(
116                self.as_ref().to_glib_none().0,
117            ))
118        }
119    }
120
121    /// Get the territory the language is used in.
122    ///
123    /// # Returns
124    ///
125    /// The territory the language is used in.
126    #[doc(alias = "lightdm_language_get_territory")]
127    #[doc(alias = "get_territory")]
128    fn territory(&self) -> Option<glib::GString> {
129        unsafe {
130            from_glib_none(ffi::lightdm_language_get_territory(
131                self.as_ref().to_glib_none().0,
132            ))
133        }
134    }
135
136    /// Check if a language code matches this language.
137    /// ## `code`
138    /// A language code
139    ///
140    /// # Returns
141    ///
142    /// #TRUE if the code matches this language.
143    #[doc(alias = "lightdm_language_matches")]
144    fn matches(&self, code: &str) -> bool {
145        unsafe {
146            from_glib(ffi::lightdm_language_matches(
147                self.as_ref().to_glib_none().0,
148                code.to_glib_none().0,
149            ))
150        }
151    }
152
153    #[doc(alias = "name")]
154    fn connect_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
155        unsafe extern "C" fn notify_name_trampoline<P: IsA<Language>, F: Fn(&P) + 'static>(
156            this: *mut ffi::LightDMLanguage,
157            _param_spec: glib::ffi::gpointer,
158            f: glib::ffi::gpointer,
159        ) {
160            unsafe {
161                let f: &F = &*(f as *const F);
162                f(Language::from_glib_borrow(this).unsafe_cast_ref())
163            }
164        }
165        unsafe {
166            let f: Box_<F> = Box_::new(f);
167            connect_raw(
168                self.as_ptr() as *mut _,
169                c"notify::name".as_ptr(),
170                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
171                    notify_name_trampoline::<Self, F> as *const (),
172                )),
173                Box_::into_raw(f),
174            )
175        }
176    }
177
178    #[doc(alias = "territory")]
179    fn connect_territory_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
180        unsafe extern "C" fn notify_territory_trampoline<P: IsA<Language>, F: Fn(&P) + 'static>(
181            this: *mut ffi::LightDMLanguage,
182            _param_spec: glib::ffi::gpointer,
183            f: glib::ffi::gpointer,
184        ) {
185            unsafe {
186                let f: &F = &*(f as *const F);
187                f(Language::from_glib_borrow(this).unsafe_cast_ref())
188            }
189        }
190        unsafe {
191            let f: Box_<F> = Box_::new(f);
192            connect_raw(
193                self.as_ptr() as *mut _,
194                c"notify::territory".as_ptr(),
195                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
196                    notify_territory_trampoline::<Self, F> as *const (),
197                )),
198                Box_::into_raw(f),
199            )
200        }
201    }
202}
203
204impl<O: IsA<Language>> LanguageExt for O {}