gio/auto/
tls_password.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{TlsPasswordFlags, ffi};
6use glib::{
7    prelude::*,
8    signal::{SignalHandlerId, connect_raw},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    /// An abstract interface representing a password used in TLS. Often used in
15    /// user interaction such as unlocking a key storage token.
16    ///
17    /// ## Properties
18    ///
19    ///
20    /// #### `description`
21    ///  Description of what the password is for.
22    ///
23    /// Readable | Writeable
24    ///
25    ///
26    /// #### `flags`
27    ///  Flags about the password.
28    ///
29    /// Readable | Writeable
30    ///
31    ///
32    /// #### `warning`
33    ///  Warning about the password.
34    ///
35    /// Readable | Writeable
36    ///
37    /// # Implements
38    ///
39    /// [`TlsPasswordExt`][trait@crate::prelude::TlsPasswordExt], [`trait@glib::ObjectExt`]
40    #[doc(alias = "GTlsPassword")]
41    pub struct TlsPassword(Object<ffi::GTlsPassword, ffi::GTlsPasswordClass>);
42
43    match fn {
44        type_ => || ffi::g_tls_password_get_type(),
45    }
46}
47
48impl TlsPassword {
49    pub const NONE: Option<&'static TlsPassword> = None;
50
51    /// Create a new #GTlsPassword object.
52    /// ## `flags`
53    /// the password flags
54    /// ## `description`
55    /// description of what the password is for
56    ///
57    /// # Returns
58    ///
59    /// The newly allocated password object
60    #[doc(alias = "g_tls_password_new")]
61    pub fn new(flags: TlsPasswordFlags, description: &str) -> TlsPassword {
62        unsafe {
63            from_glib_full(ffi::g_tls_password_new(
64                flags.into_glib(),
65                description.to_glib_none().0,
66            ))
67        }
68    }
69}
70
71/// Trait containing all [`struct@TlsPassword`] methods.
72///
73/// # Implementors
74///
75/// [`TlsPassword`][struct@crate::TlsPassword]
76pub trait TlsPasswordExt: IsA<TlsPassword> + 'static {
77    /// Get a description string about what the password will be used for.
78    ///
79    /// # Returns
80    ///
81    /// The description of the password.
82    #[doc(alias = "g_tls_password_get_description")]
83    #[doc(alias = "get_description")]
84    fn description(&self) -> glib::GString {
85        unsafe {
86            from_glib_none(ffi::g_tls_password_get_description(
87                self.as_ref().to_glib_none().0,
88            ))
89        }
90    }
91
92    /// Get flags about the password.
93    ///
94    /// # Returns
95    ///
96    /// The flags about the password.
97    #[doc(alias = "g_tls_password_get_flags")]
98    #[doc(alias = "get_flags")]
99    fn flags(&self) -> TlsPasswordFlags {
100        unsafe {
101            from_glib(ffi::g_tls_password_get_flags(
102                self.as_ref().to_glib_none().0,
103            ))
104        }
105    }
106
107    /// Get a user readable translated warning. Usually this warning is a
108    /// representation of the password flags returned from
109    /// g_tls_password_get_flags().
110    ///
111    /// # Returns
112    ///
113    /// The warning.
114    #[doc(alias = "g_tls_password_get_warning")]
115    #[doc(alias = "get_warning")]
116    fn warning(&self) -> glib::GString {
117        unsafe {
118            from_glib_none(ffi::g_tls_password_get_warning(
119                self.as_ref().to_glib_none().0,
120            ))
121        }
122    }
123
124    /// Set a description string about what the password will be used for.
125    /// ## `description`
126    /// The description of the password
127    #[doc(alias = "g_tls_password_set_description")]
128    #[doc(alias = "description")]
129    fn set_description(&self, description: &str) {
130        unsafe {
131            ffi::g_tls_password_set_description(
132                self.as_ref().to_glib_none().0,
133                description.to_glib_none().0,
134            );
135        }
136    }
137
138    /// Set flags about the password.
139    /// ## `flags`
140    /// The flags about the password
141    #[doc(alias = "g_tls_password_set_flags")]
142    #[doc(alias = "flags")]
143    fn set_flags(&self, flags: TlsPasswordFlags) {
144        unsafe {
145            ffi::g_tls_password_set_flags(self.as_ref().to_glib_none().0, flags.into_glib());
146        }
147    }
148
149    //#[doc(alias = "g_tls_password_set_value_full")]
150    //fn set_value_full(&self, value: &[u8]) {
151    //    unsafe { TODO: call ffi:g_tls_password_set_value_full() }
152    //}
153
154    /// Set a user readable translated warning. Usually this warning is a
155    /// representation of the password flags returned from
156    /// g_tls_password_get_flags().
157    /// ## `warning`
158    /// The user readable warning
159    #[doc(alias = "g_tls_password_set_warning")]
160    #[doc(alias = "warning")]
161    fn set_warning(&self, warning: &str) {
162        unsafe {
163            ffi::g_tls_password_set_warning(
164                self.as_ref().to_glib_none().0,
165                warning.to_glib_none().0,
166            );
167        }
168    }
169
170    #[doc(alias = "description")]
171    fn connect_description_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
172        unsafe extern "C" fn notify_description_trampoline<
173            P: IsA<TlsPassword>,
174            F: Fn(&P) + 'static,
175        >(
176            this: *mut ffi::GTlsPassword,
177            _param_spec: glib::ffi::gpointer,
178            f: glib::ffi::gpointer,
179        ) {
180            unsafe {
181                let f: &F = &*(f as *const F);
182                f(TlsPassword::from_glib_borrow(this).unsafe_cast_ref())
183            }
184        }
185        unsafe {
186            let f: Box_<F> = Box_::new(f);
187            connect_raw(
188                self.as_ptr() as *mut _,
189                c"notify::description".as_ptr() as *const _,
190                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
191                    notify_description_trampoline::<Self, F> as *const (),
192                )),
193                Box_::into_raw(f),
194            )
195        }
196    }
197
198    #[doc(alias = "flags")]
199    fn connect_flags_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
200        unsafe extern "C" fn notify_flags_trampoline<P: IsA<TlsPassword>, F: Fn(&P) + 'static>(
201            this: *mut ffi::GTlsPassword,
202            _param_spec: glib::ffi::gpointer,
203            f: glib::ffi::gpointer,
204        ) {
205            unsafe {
206                let f: &F = &*(f as *const F);
207                f(TlsPassword::from_glib_borrow(this).unsafe_cast_ref())
208            }
209        }
210        unsafe {
211            let f: Box_<F> = Box_::new(f);
212            connect_raw(
213                self.as_ptr() as *mut _,
214                c"notify::flags".as_ptr() as *const _,
215                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
216                    notify_flags_trampoline::<Self, F> as *const (),
217                )),
218                Box_::into_raw(f),
219            )
220        }
221    }
222
223    #[doc(alias = "warning")]
224    fn connect_warning_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
225        unsafe extern "C" fn notify_warning_trampoline<P: IsA<TlsPassword>, F: Fn(&P) + 'static>(
226            this: *mut ffi::GTlsPassword,
227            _param_spec: glib::ffi::gpointer,
228            f: glib::ffi::gpointer,
229        ) {
230            unsafe {
231                let f: &F = &*(f as *const F);
232                f(TlsPassword::from_glib_borrow(this).unsafe_cast_ref())
233            }
234        }
235        unsafe {
236            let f: Box_<F> = Box_::new(f);
237            connect_raw(
238                self.as_ptr() as *mut _,
239                c"notify::warning".as_ptr() as *const _,
240                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
241                    notify_warning_trampoline::<Self, F> as *const (),
242                )),
243                Box_::into_raw(f),
244            )
245        }
246    }
247}
248
249impl<O: IsA<TlsPassword>> TlsPasswordExt for O {}