Skip to main content

lightdm/auto/
user_list.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::{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    /// #LightDMUserList is an opaque data structure and can only be accessed
16    /// using the provided functions.
17    ///
18    /// ## Properties
19    ///
20    ///
21    /// #### `length`
22    ///  Readable
23    ///
24    ///
25    /// #### `num-users`
26    ///  Readable
27    ///
28    /// ## Signals
29    ///
30    ///
31    /// #### `user-added`
32    ///  The ::user-added signal gets emitted when a user account is created.
33    ///
34    ///
35    ///
36    ///
37    /// #### `user-changed`
38    ///  The ::user-changed signal gets emitted when a user account is modified.
39    ///
40    ///
41    ///
42    ///
43    /// #### `user-removed`
44    ///  The ::user-removed signal gets emitted when a user account is removed.
45    ///
46    ///
47    ///
48    /// # Implements
49    ///
50    /// [`UserListExt`][trait@crate::prelude::UserListExt]
51    #[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    /// Get the user list.
63    ///
64    /// # Returns
65    ///
66    /// the #LightDMUserList
67    #[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
75/// Trait containing all [`struct@UserList`] methods.
76///
77/// # Implementors
78///
79/// [`UserList`][struct@crate::UserList]
80pub trait UserListExt: IsA<UserList> + 'static {
81    ///
82    /// # Returns
83    ///
84    /// The number of users able to log in
85    #[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    /// Get information about a given user or #NULL if this user doesn't exist.
92    /// ## `username`
93    /// Name of user to get.
94    ///
95    /// # Returns
96    ///
97    /// A #LightDMUser entry for the given user.
98    #[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    /// Get a list of users to present to the user.  This list may be a subset of the
110    /// available users and may be empty depending on the server configuration.
111    ///
112    /// # Returns
113    ///
114    /// A list of #LightDMUser that should be presented to the user.
115    #[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    /// The ::user-added signal gets emitted when a user account is created.
131    /// ## `user`
132    /// The #LightDMUser that has been added.
133    #[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    /// The ::user-changed signal gets emitted when a user account is modified.
162    /// ## `user`
163    /// The #LightDMUser that has been changed.
164    #[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    /// The ::user-removed signal gets emitted when a user account is removed.
196    /// ## `user`
197    /// The #LightDMUser that has been removed.
198    #[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 {}