polkit_rs/auto/
unix_user.rs

1// Generated by gir (https://github.com/gtk-rs/gir @ b2a1c6f9b362)
2// from ../misc (@ ???)
3// DO NOT EDIT
4
5use crate::{Identity, 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 = "PolkitUnixUser")]
15    pub struct UnixUser(Object<ffi::PolkitUnixUser, ffi::PolkitUnixUserClass>) @implements Identity;
16
17    match fn {
18        type_ => || ffi::polkit_unix_user_get_type(),
19    }
20}
21
22impl UnixUser {
23    #[doc(alias = "polkit_unix_user_get_name")]
24    #[doc(alias = "get_name")]
25    pub fn name(&self) -> Option<glib::GString> {
26        unsafe { from_glib_none(ffi::polkit_unix_user_get_name(self.to_glib_none().0)) }
27    }
28
29    #[doc(alias = "polkit_unix_user_get_uid")]
30    #[doc(alias = "get_uid")]
31    pub fn uid(&self) -> i32 {
32        unsafe { ffi::polkit_unix_user_get_uid(self.to_glib_none().0) }
33    }
34
35    #[doc(alias = "polkit_unix_user_set_uid")]
36    #[doc(alias = "uid")]
37    pub fn set_uid(&self, uid: i32) {
38        unsafe {
39            ffi::polkit_unix_user_set_uid(self.to_glib_none().0, uid);
40        }
41    }
42
43    #[doc(alias = "polkit_unix_user_new")]
44    pub fn new(uid: i32) -> Self {
45        unsafe {
46            let identify: Identity = from_glib_full(ffi::polkit_unix_user_new(uid));
47            identify.unsafe_cast()
48        }
49    }
50
51    #[doc(alias = "polkit_unix_user_new_for_name")]
52    pub fn new_for_name(name: &str) -> Result<Self, glib::Error> {
53        unsafe {
54            let mut error = std::ptr::null_mut();
55            let ret = ffi::polkit_unix_user_new_for_name(name.to_glib_none().0, &mut error);
56            if error.is_null() {
57                let identify: Identity = from_glib_full(ret);
58                let user = identify.unsafe_cast();
59                Ok(user)
60            } else {
61                Err(from_glib_full(error))
62            }
63        }
64    }
65
66    #[doc(alias = "uid")]
67    pub fn connect_uid_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
68        unsafe extern "C" fn notify_uid_trampoline<F: Fn(&UnixUser) + 'static>(
69            this: *mut ffi::PolkitUnixUser,
70            _param_spec: glib::ffi::gpointer,
71            f: glib::ffi::gpointer,
72        ) {
73            unsafe {
74                let f: &F = &*(f as *const F);
75                f(&from_glib_borrow(this))
76            }
77        }
78        unsafe {
79            let f: Box_<F> = Box_::new(f);
80            connect_raw(
81                self.as_ptr() as *mut _,
82                c"notify::uid".as_ptr() as *const _,
83                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
84                    notify_uid_trampoline::<F> as *const (),
85                )),
86                Box_::into_raw(f),
87            )
88        }
89    }
90}