1use 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 #[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 #[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
71pub trait TlsPasswordExt: IsA<TlsPassword> + 'static {
77 #[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 #[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 #[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 #[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 #[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_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 {}