1use crate::{Connection, VpnEditor, VpnEditorPluginCapability, ffi};
7#[cfg(feature = "v1_4")]
8#[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
9use crate::{VpnEditorPluginVT, VpnPluginInfo};
10use glib::{
11 prelude::*,
12 signal::{SignalHandlerId, connect_raw},
13 translate::*,
14};
15use std::boxed::Box as Box_;
16
17glib::wrapper! {
18 #[doc(alias = "NMVpnEditorPlugin")]
44 pub struct VpnEditorPlugin(Interface<ffi::NMVpnEditorPlugin, ffi::NMVpnEditorPluginInterface>);
45
46 match fn {
47 type_ => || ffi::nm_vpn_editor_plugin_get_type(),
48 }
49}
50
51impl VpnEditorPlugin {
52 pub const NONE: Option<&'static VpnEditorPlugin> = None;
53
54 #[cfg(feature = "v1_4")]
74 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
75 #[doc(alias = "nm_vpn_editor_plugin_load")]
76 pub fn load(plugin_name: &str, check_service: &str) -> Result<VpnEditorPlugin, glib::Error> {
77 assert_initialized_main_thread!();
78 unsafe {
79 let mut error = std::ptr::null_mut();
80 let ret = ffi::nm_vpn_editor_plugin_load(
81 plugin_name.to_glib_none().0,
82 check_service.to_glib_none().0,
83 &mut error,
84 );
85 if error.is_null() {
86 Ok(from_glib_full(ret))
87 } else {
88 Err(from_glib_full(error))
89 }
90 }
91 }
92
93 }
100
101pub trait VpnEditorPluginExt: IsA<VpnEditorPlugin> + 'static {
107 #[doc(alias = "nm_vpn_editor_plugin_export")]
108 fn export(&self, path: &str, connection: &impl IsA<Connection>) -> Result<(), glib::Error> {
109 unsafe {
110 let mut error = std::ptr::null_mut();
111 let is_ok = ffi::nm_vpn_editor_plugin_export(
112 self.as_ref().to_glib_none().0,
113 path.to_glib_none().0,
114 connection.as_ref().to_glib_none().0,
115 &mut error,
116 );
117 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
118 if error.is_null() {
119 Ok(())
120 } else {
121 Err(from_glib_full(error))
122 }
123 }
124 }
125
126 #[doc(alias = "nm_vpn_editor_plugin_get_capabilities")]
127 #[doc(alias = "get_capabilities")]
128 fn capabilities(&self) -> VpnEditorPluginCapability {
129 unsafe {
130 from_glib(ffi::nm_vpn_editor_plugin_get_capabilities(
131 self.as_ref().to_glib_none().0,
132 ))
133 }
134 }
135
136 #[doc(alias = "nm_vpn_editor_plugin_get_editor")]
143 #[doc(alias = "get_editor")]
144 fn editor(&self, connection: &impl IsA<Connection>) -> Result<VpnEditor, glib::Error> {
145 unsafe {
146 let mut error = std::ptr::null_mut();
147 let ret = ffi::nm_vpn_editor_plugin_get_editor(
148 self.as_ref().to_glib_none().0,
149 connection.as_ref().to_glib_none().0,
150 &mut error,
151 );
152 if error.is_null() {
153 Ok(from_glib_full(ret))
154 } else {
155 Err(from_glib_full(error))
156 }
157 }
158 }
159
160 #[cfg(feature = "v1_4")]
165 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
166 #[doc(alias = "nm_vpn_editor_plugin_get_plugin_info")]
167 #[doc(alias = "get_plugin_info")]
168 fn plugin_info(&self) -> VpnPluginInfo {
169 unsafe {
170 from_glib_none(ffi::nm_vpn_editor_plugin_get_plugin_info(
171 self.as_ref().to_glib_none().0,
172 ))
173 }
174 }
175
176 #[doc(alias = "nm_vpn_editor_plugin_get_suggested_filename")]
177 #[doc(alias = "get_suggested_filename")]
178 fn suggested_filename(&self, connection: &impl IsA<Connection>) -> glib::GString {
179 unsafe {
180 from_glib_full(ffi::nm_vpn_editor_plugin_get_suggested_filename(
181 self.as_ref().to_glib_none().0,
182 connection.as_ref().to_glib_none().0,
183 ))
184 }
185 }
186
187 #[cfg(feature = "v1_4")]
203 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
204 #[doc(alias = "nm_vpn_editor_plugin_get_vt")]
205 #[doc(alias = "get_vt")]
206 fn vt(&self, vt_size: usize) -> (usize, VpnEditorPluginVT) {
207 unsafe {
208 let mut vt = VpnEditorPluginVT::uninitialized();
209 let ret = ffi::nm_vpn_editor_plugin_get_vt(
210 self.as_ref().to_glib_none().0,
211 &mut vt.to_glib_none_mut().0,
212 vt_size,
213 );
214 (ret, vt)
215 }
216 }
217
218 #[doc(alias = "nm_vpn_editor_plugin_import")]
226 fn import(&self, path: &str) -> Result<Connection, glib::Error> {
227 unsafe {
228 let mut error = std::ptr::null_mut();
229 let ret = ffi::nm_vpn_editor_plugin_import(
230 self.as_ref().to_glib_none().0,
231 path.to_glib_none().0,
232 &mut error,
233 );
234 if error.is_null() {
235 Ok(from_glib_full(ret))
236 } else {
237 Err(from_glib_full(error))
238 }
239 }
240 }
241
242 #[cfg(feature = "v1_4")]
248 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
249 #[doc(alias = "nm_vpn_editor_plugin_set_plugin_info")]
250 fn set_plugin_info(&self, plugin_info: Option<&VpnPluginInfo>) {
251 unsafe {
252 ffi::nm_vpn_editor_plugin_set_plugin_info(
253 self.as_ref().to_glib_none().0,
254 plugin_info.to_glib_none().0,
255 );
256 }
257 }
258
259 fn description(&self) -> Option<glib::GString> {
261 ObjectExt::property(self.as_ref(), "description")
262 }
263
264 fn name(&self) -> Option<glib::GString> {
266 ObjectExt::property(self.as_ref(), "name")
267 }
268
269 fn service(&self) -> Option<glib::GString> {
271 ObjectExt::property(self.as_ref(), "service")
272 }
273
274 #[doc(alias = "description")]
275 fn connect_description_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
276 unsafe extern "C" fn notify_description_trampoline<
277 P: IsA<VpnEditorPlugin>,
278 F: Fn(&P) + 'static,
279 >(
280 this: *mut ffi::NMVpnEditorPlugin,
281 _param_spec: glib::ffi::gpointer,
282 f: glib::ffi::gpointer,
283 ) {
284 let f: &F = &*(f as *const F);
285 f(VpnEditorPlugin::from_glib_borrow(this).unsafe_cast_ref())
286 }
287 unsafe {
288 let f: Box_<F> = Box_::new(f);
289 connect_raw(
290 self.as_ptr() as *mut _,
291 c"notify::description".as_ptr() as *const _,
292 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
293 notify_description_trampoline::<Self, F> as *const (),
294 )),
295 Box_::into_raw(f),
296 )
297 }
298 }
299
300 #[doc(alias = "name")]
301 fn connect_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
302 unsafe extern "C" fn notify_name_trampoline<
303 P: IsA<VpnEditorPlugin>,
304 F: Fn(&P) + 'static,
305 >(
306 this: *mut ffi::NMVpnEditorPlugin,
307 _param_spec: glib::ffi::gpointer,
308 f: glib::ffi::gpointer,
309 ) {
310 let f: &F = &*(f as *const F);
311 f(VpnEditorPlugin::from_glib_borrow(this).unsafe_cast_ref())
312 }
313 unsafe {
314 let f: Box_<F> = Box_::new(f);
315 connect_raw(
316 self.as_ptr() as *mut _,
317 c"notify::name".as_ptr() as *const _,
318 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
319 notify_name_trampoline::<Self, F> as *const (),
320 )),
321 Box_::into_raw(f),
322 )
323 }
324 }
325
326 #[doc(alias = "service")]
327 fn connect_service_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
328 unsafe extern "C" fn notify_service_trampoline<
329 P: IsA<VpnEditorPlugin>,
330 F: Fn(&P) + 'static,
331 >(
332 this: *mut ffi::NMVpnEditorPlugin,
333 _param_spec: glib::ffi::gpointer,
334 f: glib::ffi::gpointer,
335 ) {
336 let f: &F = &*(f as *const F);
337 f(VpnEditorPlugin::from_glib_borrow(this).unsafe_cast_ref())
338 }
339 unsafe {
340 let f: Box_<F> = Box_::new(f);
341 connect_raw(
342 self.as_ptr() as *mut _,
343 c"notify::service".as_ptr() as *const _,
344 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
345 notify_service_trampoline::<Self, F> as *const (),
346 )),
347 Box_::into_raw(f),
348 )
349 }
350 }
351}
352
353impl<O: IsA<VpnEditorPlugin>> VpnEditorPluginExt for O {}