nm_rs/auto/
vpn_editor_plugin.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir
3// from gtk-girs (https://github.com/gtk-rs/gir-files)
4// DO NOT EDIT
5
6use 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    ///
19    ///
20    /// ## Properties
21    ///
22    ///
23    /// #### `description`
24    ///  Longer description of the VPN plugin.
25    ///
26    /// Readable
27    ///
28    ///
29    /// #### `name`
30    ///  Short display name of the VPN plugin.
31    ///
32    /// Readable
33    ///
34    ///
35    /// #### `service`
36    ///  D-Bus service name of the plugin's VPN service.
37    ///
38    /// Readable
39    ///
40    /// # Implements
41    ///
42    /// [`VpnEditorPluginExt`][trait@crate::prelude::VpnEditorPluginExt]
43    #[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    /// Load the shared library @plugin_name and create a new
55    /// #NMVpnEditorPlugin instance via the #NMVpnEditorPluginFactory
56    /// function.
57    ///
58    /// This is similar to nm_vpn_editor_plugin_load_from_file(), but
59    /// it does no validation of the plugin name, instead passes it directly
60    /// to dlopen(). If you have the full path to a plugin file,
61    /// nm_vpn_editor_plugin_load_from_file() is preferred.
62    /// ## `plugin_name`
63    /// The name of the shared library to load.
64    ///  This path will be directly passed to dlopen() without
65    ///  further checks.
66    /// ## `check_service`
67    /// if not-null, check that the loaded plugin advertises
68    ///  the given service.
69    ///
70    /// # Returns
71    ///
72    /// a new plugin instance or [`None`] on error.
73    #[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    //#[cfg(feature = "v1_2")]
94    //#[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
95    //#[doc(alias = "nm_vpn_editor_plugin_load_from_file")]
96    //pub fn load_from_file(plugin_name: &str, check_service: &str, check_owner: i32, check_file: /*Unimplemented*/FnMut(&str, /*Unimplemented*/Option<Basic: Pointer>, Option<&glib::Error>) -> bool, user_data: /*Unimplemented*/Option<Basic: Pointer>) -> Result<VpnEditorPlugin, glib::Error> {
97    //    unsafe { TODO: call ffi:nm_vpn_editor_plugin_load_from_file() }
98    //}
99}
100
101/// Trait containing all [`struct@VpnEditorPlugin`] methods.
102///
103/// # Implementors
104///
105/// [`VpnEditorPlugin`][struct@crate::VpnEditorPlugin]
106pub 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    /// ## `connection`
137    /// the #NMConnection to be edited
138    ///
139    /// # Returns
140    ///
141    /// a new #NMVpnEditor or [`None`] on error
142    #[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    ///
161    /// # Returns
162    ///
163    /// if set, return the #NMVpnPluginInfo instance.
164    #[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    /// Returns an opaque VT function table for the plugin to extend
188    /// functionality. The actual meaning of NMVpnEditorPluginVT is not
189    /// defined in public API of libnm, instead it must be agreed by
190    /// both the plugin and the caller. See the header-only file
191    /// 'nm-vpn-editor-plugin-call.h' which defines the meaning.
192    /// ## `vt_size`
193    /// the size of the buffer. Can be 0 to only query the
194    ///   size of plugin's VT.
195    ///
196    /// # Returns
197    ///
198    /// the actual size of the @self's virtual function table.
199    ///
200    /// ## `vt`
201    /// buffer to be filled with the VT table of the plugin
202    #[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    /// ## `path`
219    /// full path to the file to attempt to read into a new #NMConnection
220    ///
221    /// # Returns
222    ///
223    /// a new #NMConnection imported from @path, or [`None`]
224    /// on error or if the file at @path was not recognized by this plugin
225    #[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    /// Set or clear the plugin-info instance.
243    /// This takes a weak reference on @plugin_info, to avoid circular
244    /// reference as the plugin-info might also reference the editor-plugin.
245    /// ## `plugin_info`
246    /// a #NMVpnPluginInfo instance or [`None`]
247    #[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    /// Longer description of the VPN plugin.
260    fn description(&self) -> Option<glib::GString> {
261        ObjectExt::property(self.as_ref(), "description")
262    }
263
264    /// Short display name of the VPN plugin.
265    fn name(&self) -> Option<glib::GString> {
266        ObjectExt::property(self.as_ref(), "name")
267    }
268
269    /// D-Bus service name of the plugin's VPN service.
270    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 {}