1use crate::{User, ffi};
6use glib::{
7 object::ObjectType as _,
8 prelude::*,
9 signal::{SignalHandlerId, connect_raw},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 #[doc(alias = "LightDMUserList")]
52 pub struct UserList(Object<ffi::LightDMUserList, ffi::LightDMUserListClass>);
53
54 match fn {
55 type_ => || ffi::lightdm_user_list_get_type(),
56 }
57}
58
59impl UserList {
60 pub const NONE: Option<&'static UserList> = None;
61
62 #[doc(alias = "lightdm_user_list_get_instance")]
68 #[doc(alias = "get_instance")]
69 pub fn instance() -> Option<UserList> {
70 assert_initialized_main_thread!();
71 unsafe { from_glib_none(ffi::lightdm_user_list_get_instance()) }
72 }
73}
74
75pub trait UserListExt: IsA<UserList> + 'static {
81 #[doc(alias = "lightdm_user_list_get_length")]
86 #[doc(alias = "get_length")]
87 fn length(&self) -> i32 {
88 unsafe { ffi::lightdm_user_list_get_length(self.as_ref().to_glib_none().0) }
89 }
90
91 #[doc(alias = "lightdm_user_list_get_user_by_name")]
99 #[doc(alias = "get_user_by_name")]
100 fn user_by_name(&self, username: &str) -> Option<User> {
101 unsafe {
102 from_glib_none(ffi::lightdm_user_list_get_user_by_name(
103 self.as_ref().to_glib_none().0,
104 username.to_glib_none().0,
105 ))
106 }
107 }
108
109 #[doc(alias = "lightdm_user_list_get_users")]
116 #[doc(alias = "get_users")]
117 fn users(&self) -> Vec<User> {
118 unsafe {
119 FromGlibPtrContainer::from_glib_none(ffi::lightdm_user_list_get_users(
120 self.as_ref().to_glib_none().0,
121 ))
122 }
123 }
124
125 #[doc(alias = "num-users")]
126 fn num_users(&self) -> i32 {
127 ObjectExt::property(self.as_ref(), "num-users")
128 }
129
130 #[doc(alias = "user-added")]
134 fn connect_user_added<F: Fn(&Self, &User) + 'static>(&self, f: F) -> SignalHandlerId {
135 unsafe extern "C" fn user_added_trampoline<P: IsA<UserList>, F: Fn(&P, &User) + 'static>(
136 this: *mut ffi::LightDMUserList,
137 user: *mut ffi::LightDMUser,
138 f: glib::ffi::gpointer,
139 ) {
140 unsafe {
141 let f: &F = &*(f as *const F);
142 f(
143 UserList::from_glib_borrow(this).unsafe_cast_ref(),
144 &from_glib_borrow(user),
145 )
146 }
147 }
148 unsafe {
149 let f: Box_<F> = Box_::new(f);
150 connect_raw(
151 self.as_ptr() as *mut _,
152 c"user-added".as_ptr(),
153 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
154 user_added_trampoline::<Self, F> as *const (),
155 )),
156 Box_::into_raw(f),
157 )
158 }
159 }
160
161 #[doc(alias = "user-changed")]
165 fn connect_user_changed<F: Fn(&Self, &User) + 'static>(&self, f: F) -> SignalHandlerId {
166 unsafe extern "C" fn user_changed_trampoline<
167 P: IsA<UserList>,
168 F: Fn(&P, &User) + 'static,
169 >(
170 this: *mut ffi::LightDMUserList,
171 user: *mut ffi::LightDMUser,
172 f: glib::ffi::gpointer,
173 ) {
174 unsafe {
175 let f: &F = &*(f as *const F);
176 f(
177 UserList::from_glib_borrow(this).unsafe_cast_ref(),
178 &from_glib_borrow(user),
179 )
180 }
181 }
182 unsafe {
183 let f: Box_<F> = Box_::new(f);
184 connect_raw(
185 self.as_ptr() as *mut _,
186 c"user-changed".as_ptr(),
187 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
188 user_changed_trampoline::<Self, F> as *const (),
189 )),
190 Box_::into_raw(f),
191 )
192 }
193 }
194
195 #[doc(alias = "user-removed")]
199 fn connect_user_removed<F: Fn(&Self, &User) + 'static>(&self, f: F) -> SignalHandlerId {
200 unsafe extern "C" fn user_removed_trampoline<
201 P: IsA<UserList>,
202 F: Fn(&P, &User) + 'static,
203 >(
204 this: *mut ffi::LightDMUserList,
205 user: *mut ffi::LightDMUser,
206 f: glib::ffi::gpointer,
207 ) {
208 unsafe {
209 let f: &F = &*(f as *const F);
210 f(
211 UserList::from_glib_borrow(this).unsafe_cast_ref(),
212 &from_glib_borrow(user),
213 )
214 }
215 }
216 unsafe {
217 let f: Box_<F> = Box_::new(f);
218 connect_raw(
219 self.as_ptr() as *mut _,
220 c"user-removed".as_ptr(),
221 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
222 user_removed_trampoline::<Self, F> as *const (),
223 )),
224 Box_::into_raw(f),
225 )
226 }
227 }
228
229 #[doc(alias = "length")]
230 fn connect_length_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
231 unsafe extern "C" fn notify_length_trampoline<P: IsA<UserList>, F: Fn(&P) + 'static>(
232 this: *mut ffi::LightDMUserList,
233 _param_spec: glib::ffi::gpointer,
234 f: glib::ffi::gpointer,
235 ) {
236 unsafe {
237 let f: &F = &*(f as *const F);
238 f(UserList::from_glib_borrow(this).unsafe_cast_ref())
239 }
240 }
241 unsafe {
242 let f: Box_<F> = Box_::new(f);
243 connect_raw(
244 self.as_ptr() as *mut _,
245 c"notify::length".as_ptr(),
246 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
247 notify_length_trampoline::<Self, F> as *const (),
248 )),
249 Box_::into_raw(f),
250 )
251 }
252 }
253
254 #[doc(alias = "num-users")]
255 fn connect_num_users_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
256 unsafe extern "C" fn notify_num_users_trampoline<P: IsA<UserList>, F: Fn(&P) + 'static>(
257 this: *mut ffi::LightDMUserList,
258 _param_spec: glib::ffi::gpointer,
259 f: glib::ffi::gpointer,
260 ) {
261 unsafe {
262 let f: &F = &*(f as *const F);
263 f(UserList::from_glib_borrow(this).unsafe_cast_ref())
264 }
265 }
266 unsafe {
267 let f: Box_<F> = Box_::new(f);
268 connect_raw(
269 self.as_ptr() as *mut _,
270 c"notify::num-users".as_ptr(),
271 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
272 notify_num_users_trampoline::<Self, F> as *const (),
273 )),
274 Box_::into_raw(f),
275 )
276 }
277 }
278}
279
280impl<O: IsA<UserList>> UserListExt for O {}