Skip to main content

lightdm/auto/
functions.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::{Language, Layout, Session, ffi};
6use glib::{prelude::*, translate::*};
7
8/// Checks if is authorized to do a system hibernate.
9///
10/// # Returns
11///
12/// #TRUE if can hibernate the system
13#[doc(alias = "lightdm_get_can_hibernate")]
14#[doc(alias = "get_can_hibernate")]
15pub fn can_hibernate() -> bool {
16    assert_initialized_main_thread!();
17    unsafe { from_glib(ffi::lightdm_get_can_hibernate()) }
18}
19
20/// Checks if is authorized to do a system restart.
21///
22/// # Returns
23///
24/// #TRUE if can restart the system
25#[doc(alias = "lightdm_get_can_restart")]
26#[doc(alias = "get_can_restart")]
27pub fn can_restart() -> bool {
28    assert_initialized_main_thread!();
29    unsafe { from_glib(ffi::lightdm_get_can_restart()) }
30}
31
32/// Checks if is authorized to do a system shutdown.
33///
34/// # Returns
35///
36/// #TRUE if can shutdown the system
37#[doc(alias = "lightdm_get_can_shutdown")]
38#[doc(alias = "get_can_shutdown")]
39pub fn can_shutdown() -> bool {
40    assert_initialized_main_thread!();
41    unsafe { from_glib(ffi::lightdm_get_can_shutdown()) }
42}
43
44/// Checks if authorized to do a system suspend.
45///
46/// # Returns
47///
48/// #TRUE if can suspend the system
49#[doc(alias = "lightdm_get_can_suspend")]
50#[doc(alias = "get_can_suspend")]
51pub fn can_suspend() -> bool {
52    assert_initialized_main_thread!();
53    unsafe { from_glib(ffi::lightdm_get_can_suspend()) }
54}
55
56///
57/// # Returns
58///
59/// The name of the host we are running on.
60#[doc(alias = "lightdm_get_hostname")]
61#[doc(alias = "get_hostname")]
62pub fn hostname() -> Option<glib::GString> {
63    assert_initialized_main_thread!();
64    unsafe { from_glib_none(ffi::lightdm_get_hostname()) }
65}
66
67/// Get the current language.
68///
69/// # Returns
70///
71/// The current language or #NULL if no language.
72#[doc(alias = "lightdm_get_language")]
73#[doc(alias = "get_language")]
74pub fn language() -> Option<Language> {
75    assert_initialized_main_thread!();
76    unsafe { from_glib_none(ffi::lightdm_get_language()) }
77}
78
79/// Get a list of languages to present to the user.
80///
81/// # Returns
82///
83/// A list of #LightDMLanguage that should be presented to the user.
84#[doc(alias = "lightdm_get_languages")]
85#[doc(alias = "get_languages")]
86pub fn languages() -> Vec<Language> {
87    assert_initialized_main_thread!();
88    unsafe { FromGlibPtrContainer::from_glib_none(ffi::lightdm_get_languages()) }
89}
90
91/// Get the current keyboard layout.
92///
93/// # Returns
94///
95/// The currently active layout for this user.
96#[doc(alias = "lightdm_get_layout")]
97#[doc(alias = "get_layout")]
98pub fn layout() -> Option<Layout> {
99    assert_initialized_main_thread!();
100    unsafe { from_glib_none(ffi::lightdm_get_layout()) }
101}
102
103/// Get a list of keyboard layouts to present to the user.
104///
105/// # Returns
106///
107/// A list of #LightDMLayout that should be presented to the user.
108#[doc(alias = "lightdm_get_layouts")]
109#[doc(alias = "get_layouts")]
110pub fn layouts() -> Vec<Layout> {
111    assert_initialized_main_thread!();
112    unsafe { FromGlibPtrContainer::from_glib_none(ffi::lightdm_get_layouts()) }
113}
114
115/// Get a system message that should be presented to the user.
116/// e.g. "Welcome to Yoyodyne"
117///
118/// # Returns
119///
120/// a string (the contents of /etc/motd) or [`None`] if not set.
121#[doc(alias = "lightdm_get_motd")]
122#[doc(alias = "get_motd")]
123pub fn motd() -> Option<glib::GString> {
124    assert_initialized_main_thread!();
125    unsafe { from_glib_full(ffi::lightdm_get_motd()) }
126}
127
128/// Get a word describing the OS, suitable for checking which OS the greeter is running on.
129/// e.g. "ubuntu"
130///
131/// # Returns
132///
133/// a string (ID variable from /etc/os-release) or [`None`] if not set.
134#[doc(alias = "lightdm_get_os_id")]
135#[doc(alias = "get_os_id")]
136pub fn os_id() -> Option<glib::GString> {
137    assert_initialized_main_thread!();
138    unsafe { from_glib_none(ffi::lightdm_get_os_id()) }
139}
140
141/// Get a line of text describing the OS without version information, suitable for presentation to the user.
142/// e.g. "Ubuntu"
143///
144/// # Returns
145///
146/// a string (NAME variable from /etc/os-release) or [`None`] if not set.
147#[doc(alias = "lightdm_get_os_name")]
148#[doc(alias = "get_os_name")]
149pub fn os_name() -> Option<glib::GString> {
150    assert_initialized_main_thread!();
151    unsafe { from_glib_none(ffi::lightdm_get_os_name()) }
152}
153
154/// Get a line of text describing the OS, suitable for presentation to the user.
155/// e.g. "Ubuntu 16.04.1 LTS"
156///
157/// # Returns
158///
159/// a string (PRETTY_NAME variable from /etc/os-release) or [`None`] if not set.
160#[doc(alias = "lightdm_get_os_pretty_name")]
161#[doc(alias = "get_os_pretty_name")]
162pub fn os_pretty_name() -> Option<glib::GString> {
163    assert_initialized_main_thread!();
164    unsafe { from_glib_none(ffi::lightdm_get_os_pretty_name()) }
165}
166
167/// Get a line of text describing the OS version, suitable for presentation to the user.
168/// e.g. "16.04.1 LTS (Xenial Xapus)"
169///
170/// # Returns
171///
172/// a string (VERSION variable from /etc/os-release) or [`None`] if not set.
173#[doc(alias = "lightdm_get_os_version")]
174#[doc(alias = "get_os_version")]
175pub fn os_version() -> Option<glib::GString> {
176    assert_initialized_main_thread!();
177    unsafe { from_glib_none(ffi::lightdm_get_os_version()) }
178}
179
180/// Get a word descibing the OS version, suitable for checking which version of the OS this greeter is running on.
181/// e.g. "16.04"
182///
183/// # Returns
184///
185/// a string (VERSION_ID variable from /etc/os-release) or [`None`] if not set.
186#[doc(alias = "lightdm_get_os_version_id")]
187#[doc(alias = "get_os_version_id")]
188pub fn os_version_id() -> Option<glib::GString> {
189    assert_initialized_main_thread!();
190    unsafe { from_glib_none(ffi::lightdm_get_os_version_id()) }
191}
192
193/// Get the available remote sessions.
194///
195/// # Returns
196///
197/// A list of #LightDMSession
198#[doc(alias = "lightdm_get_remote_sessions")]
199#[doc(alias = "get_remote_sessions")]
200pub fn remote_sessions() -> Vec<Session> {
201    assert_initialized_main_thread!();
202    unsafe { FromGlibPtrContainer::from_glib_none(ffi::lightdm_get_remote_sessions()) }
203}
204
205/// Get the available sessions.
206///
207/// # Returns
208///
209/// A list of #LightDMSession
210#[doc(alias = "lightdm_get_sessions")]
211#[doc(alias = "get_sessions")]
212pub fn sessions() -> Vec<Session> {
213    assert_initialized_main_thread!();
214    unsafe { FromGlibPtrContainer::from_glib_none(ffi::lightdm_get_sessions()) }
215}
216
217/// Triggers a system hibernate.
218///
219/// # Returns
220///
221/// #TRUE if hibernate initiated.
222#[doc(alias = "lightdm_hibernate")]
223pub fn hibernate() -> Result<(), glib::Error> {
224    assert_initialized_main_thread!();
225    unsafe {
226        let mut error = std::ptr::null_mut();
227        let is_ok = ffi::lightdm_hibernate(&mut error);
228        debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
229        if error.is_null() {
230            Ok(())
231        } else {
232            Err(from_glib_full(error))
233        }
234    }
235}
236
237/// Triggers a system restart.
238///
239/// # Returns
240///
241/// #TRUE if restart initiated.
242#[doc(alias = "lightdm_restart")]
243pub fn restart() -> Result<(), glib::Error> {
244    assert_initialized_main_thread!();
245    unsafe {
246        let mut error = std::ptr::null_mut();
247        let is_ok = ffi::lightdm_restart(&mut error);
248        debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
249        if error.is_null() {
250            Ok(())
251        } else {
252            Err(from_glib_full(error))
253        }
254    }
255}
256
257/// Set the layout for this session.
258/// ## `layout`
259/// The layout to use
260#[doc(alias = "lightdm_set_layout")]
261pub fn set_layout(layout: &impl IsA<Layout>) {
262    skip_assert_initialized!();
263    unsafe {
264        ffi::lightdm_set_layout(layout.as_ref().to_glib_none().0);
265    }
266}
267
268/// Triggers a system shutdown.
269///
270/// # Returns
271///
272/// #TRUE if shutdown initiated.
273#[doc(alias = "lightdm_shutdown")]
274pub fn shutdown() -> Result<(), glib::Error> {
275    assert_initialized_main_thread!();
276    unsafe {
277        let mut error = std::ptr::null_mut();
278        let is_ok = ffi::lightdm_shutdown(&mut error);
279        debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
280        if error.is_null() {
281            Ok(())
282        } else {
283            Err(from_glib_full(error))
284        }
285    }
286}
287
288/// Triggers a system suspend.
289///
290/// # Returns
291///
292/// #TRUE if suspend initiated.
293#[doc(alias = "lightdm_suspend")]
294pub fn suspend() -> Result<(), glib::Error> {
295    assert_initialized_main_thread!();
296    unsafe {
297        let mut error = std::ptr::null_mut();
298        let is_ok = ffi::lightdm_suspend(&mut error);
299        debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
300        if error.is_null() {
301            Ok(())
302        } else {
303            Err(from_glib_full(error))
304        }
305    }
306}