1use crate::ffi;
6use glib::{
7 prelude::*,
8 signal::{SignalHandlerId, connect_raw},
9 translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14 #[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 pub fn builder() -> LanguageBuilder {
50 LanguageBuilder::new()
51 }
52}
53
54#[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 #[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
85pub trait LanguageExt: IsA<Language> + 'static {
91 #[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 #[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 #[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 #[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 {}