1#[cfg(feature = "v1_2")]
7#[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
8use crate::VpnEditorPlugin;
9use crate::ffi;
10use glib::prelude::*;
11#[cfg(feature = "v1_2")]
12#[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
13use glib::{
14 signal::{SignalHandlerId, connect_raw},
15 translate::*,
16};
17#[cfg(feature = "v1_2")]
18#[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
19use std::boxed::Box as Box_;
20
21#[cfg(feature = "gio_v2_22")]
22#[cfg_attr(docsrs, doc(cfg(feature = "gio_v2_22")))]
23glib::wrapper! {
24 #[doc(alias = "NMVpnPluginInfo")]
55 pub struct VpnPluginInfo(Object<ffi::NMVpnPluginInfo, ffi::NMVpnPluginInfoClass>) @implements gio::Initable;
56
57 match fn {
58 type_ => || ffi::nm_vpn_plugin_info_get_type(),
59 }
60}
61
62#[cfg(not(any(feature = "gio_v2_22")))]
63glib::wrapper! {
64 #[doc(alias = "NMVpnPluginInfo")]
65 pub struct VpnPluginInfo(Object<ffi::NMVpnPluginInfo, ffi::NMVpnPluginInfoClass>);
66
67 match fn {
68 type_ => || ffi::nm_vpn_plugin_info_get_type(),
69 }
70}
71
72impl VpnPluginInfo {
73 #[cfg(feature = "v1_2")]
84 #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
85 #[doc(alias = "nm_vpn_plugin_info_new_from_file")]
86 #[doc(alias = "new_from_file")]
87 pub fn from_file(filename: &str) -> Result<VpnPluginInfo, glib::Error> {
88 assert_initialized_main_thread!();
89 unsafe {
90 let mut error = std::ptr::null_mut();
91 let ret = ffi::nm_vpn_plugin_info_new_from_file(filename.to_glib_none().0, &mut error);
92 if error.is_null() {
93 Ok(from_glib_full(ret))
94 } else {
95 Err(from_glib_full(error))
96 }
97 }
98 }
99
100 #[cfg(feature = "v1_4")]
115 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
116 #[doc(alias = "nm_vpn_plugin_info_new_search_file")]
117 pub fn new_search_file(name: Option<&str>, service: Option<&str>) -> Option<VpnPluginInfo> {
118 assert_initialized_main_thread!();
119 unsafe {
120 from_glib_full(ffi::nm_vpn_plugin_info_new_search_file(
121 name.to_glib_none().0,
122 service.to_glib_none().0,
123 ))
124 }
125 }
126
127 pub fn builder() -> VpnPluginInfoBuilder {
140 VpnPluginInfoBuilder::new()
141 }
142
143 #[cfg(feature = "v1_4")]
149 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
150 #[doc(alias = "nm_vpn_plugin_info_get_aliases")]
151 #[doc(alias = "get_aliases")]
152 pub fn aliases(&self) -> Vec<glib::GString> {
153 unsafe {
154 FromGlibPtrContainer::from_glib_none(ffi::nm_vpn_plugin_info_get_aliases(
155 self.to_glib_none().0,
156 ))
157 }
158 }
159
160 #[cfg(feature = "v1_4")]
165 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
166 #[doc(alias = "nm_vpn_plugin_info_get_auth_dialog")]
167 #[doc(alias = "get_auth_dialog")]
168 pub fn auth_dialog(&self) -> glib::GString {
169 unsafe {
170 from_glib_none(ffi::nm_vpn_plugin_info_get_auth_dialog(
171 self.to_glib_none().0,
172 ))
173 }
174 }
175
176 #[cfg(feature = "v1_2")]
181 #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
182 #[doc(alias = "nm_vpn_plugin_info_get_editor_plugin")]
183 #[doc(alias = "get_editor_plugin")]
184 pub fn editor_plugin(&self) -> VpnEditorPlugin {
185 unsafe {
186 from_glib_none(ffi::nm_vpn_plugin_info_get_editor_plugin(
187 self.to_glib_none().0,
188 ))
189 }
190 }
191
192 #[cfg(feature = "v1_2")]
197 #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
198 #[doc(alias = "nm_vpn_plugin_info_get_filename")]
199 #[doc(alias = "get_filename")]
200 pub fn filename(&self) -> glib::GString {
201 unsafe { from_glib_none(ffi::nm_vpn_plugin_info_get_filename(self.to_glib_none().0)) }
202 }
203
204 #[cfg(feature = "v1_2")]
209 #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
210 #[doc(alias = "nm_vpn_plugin_info_get_name")]
211 #[doc(alias = "get_name")]
212 pub fn name(&self) -> glib::GString {
213 unsafe { from_glib_none(ffi::nm_vpn_plugin_info_get_name(self.to_glib_none().0)) }
214 }
215
216 #[cfg(feature = "v1_2")]
221 #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
222 #[doc(alias = "nm_vpn_plugin_info_get_plugin")]
223 #[doc(alias = "get_plugin")]
224 pub fn plugin(&self) -> glib::GString {
225 unsafe { from_glib_none(ffi::nm_vpn_plugin_info_get_plugin(self.to_glib_none().0)) }
226 }
227
228 #[cfg(feature = "v1_2")]
233 #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
234 #[doc(alias = "nm_vpn_plugin_info_get_program")]
235 #[doc(alias = "get_program")]
236 pub fn program(&self) -> glib::GString {
237 unsafe { from_glib_none(ffi::nm_vpn_plugin_info_get_program(self.to_glib_none().0)) }
238 }
239
240 #[cfg(feature = "v1_4")]
245 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
246 #[doc(alias = "nm_vpn_plugin_info_get_service")]
247 #[doc(alias = "get_service")]
248 pub fn service(&self) -> glib::GString {
249 unsafe { from_glib_none(ffi::nm_vpn_plugin_info_get_service(self.to_glib_none().0)) }
250 }
251
252 #[cfg(feature = "v1_2")]
261 #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
262 #[doc(alias = "nm_vpn_plugin_info_load_editor_plugin")]
263 pub fn load_editor_plugin(&self) -> Result<VpnEditorPlugin, glib::Error> {
264 unsafe {
265 let mut error = std::ptr::null_mut();
266 let ret = ffi::nm_vpn_plugin_info_load_editor_plugin(self.to_glib_none().0, &mut error);
267 if error.is_null() {
268 Ok(from_glib_none(ret))
269 } else {
270 Err(from_glib_full(error))
271 }
272 }
273 }
274
275 #[cfg(feature = "v1_2")]
285 #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
286 #[doc(alias = "nm_vpn_plugin_info_lookup_property")]
287 pub fn lookup_property(&self, group: &str, key: &str) -> glib::GString {
288 unsafe {
289 from_glib_none(ffi::nm_vpn_plugin_info_lookup_property(
290 self.to_glib_none().0,
291 group.to_glib_none().0,
292 key.to_glib_none().0,
293 ))
294 }
295 }
296
297 #[cfg(feature = "v1_2")]
301 #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
302 #[doc(alias = "nm_vpn_plugin_info_set_editor_plugin")]
303 pub fn set_editor_plugin(&self, plugin: Option<&impl IsA<VpnEditorPlugin>>) {
304 unsafe {
305 ffi::nm_vpn_plugin_info_set_editor_plugin(
306 self.to_glib_none().0,
307 plugin.map(|p| p.as_ref()).to_glib_none().0,
308 );
309 }
310 }
311
312 #[cfg(feature = "v1_4")]
317 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
318 #[doc(alias = "nm_vpn_plugin_info_supports_hints")]
319 pub fn supports_hints(&self) -> bool {
320 unsafe {
321 from_glib(ffi::nm_vpn_plugin_info_supports_hints(
322 self.to_glib_none().0,
323 ))
324 }
325 }
326
327 #[cfg(feature = "v1_42")]
332 #[cfg_attr(docsrs, doc(cfg(feature = "v1_42")))]
333 #[doc(alias = "nm_vpn_plugin_info_supports_multiple")]
334 pub fn supports_multiple(&self) -> bool {
335 unsafe {
336 from_glib(ffi::nm_vpn_plugin_info_supports_multiple(
337 self.to_glib_none().0,
338 ))
339 }
340 }
341
342 #[cfg(feature = "v1_2")]
352 #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
353 #[doc(alias = "nm_vpn_plugin_info_list_add")]
354 pub fn list_add(
355 list: &[VpnPluginInfo],
356 plugin_info: &VpnPluginInfo,
357 ) -> Result<(), glib::Error> {
358 skip_assert_initialized!();
359 unsafe {
360 let mut error = std::ptr::null_mut();
361 let is_ok = ffi::nm_vpn_plugin_info_list_add(
362 &mut list
363 .into_iter()
364 .cloned()
365 .collect::<glib::SList<VpnPluginInfo>>()
366 .to_glib_none()
367 .0,
368 plugin_info.to_glib_none().0,
369 &mut error,
370 );
371 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
372 if error.is_null() {
373 Ok(())
374 } else {
375 Err(from_glib_full(error))
376 }
377 }
378 }
379
380 #[cfg(feature = "v1_2")]
389 #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
390 #[doc(alias = "nm_vpn_plugin_info_list_find_by_filename")]
391 pub fn list_find_by_filename(list: &[VpnPluginInfo], filename: &str) -> VpnPluginInfo {
392 assert_initialized_main_thread!();
393 unsafe {
394 from_glib_none(ffi::nm_vpn_plugin_info_list_find_by_filename(
395 list.into_iter()
396 .cloned()
397 .collect::<glib::SList<_>>()
398 .to_glib_none()
399 .0,
400 filename.to_glib_none().0,
401 ))
402 }
403 }
404
405 #[cfg(feature = "v1_2")]
414 #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
415 #[doc(alias = "nm_vpn_plugin_info_list_find_by_name")]
416 pub fn list_find_by_name(list: &[VpnPluginInfo], name: &str) -> VpnPluginInfo {
417 assert_initialized_main_thread!();
418 unsafe {
419 from_glib_none(ffi::nm_vpn_plugin_info_list_find_by_name(
420 list.into_iter()
421 .cloned()
422 .collect::<glib::SList<_>>()
423 .to_glib_none()
424 .0,
425 name.to_glib_none().0,
426 ))
427 }
428 }
429
430 #[cfg(feature = "v1_2")]
440 #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
441 #[doc(alias = "nm_vpn_plugin_info_list_find_by_service")]
442 pub fn list_find_by_service(list: &[VpnPluginInfo], service: &str) -> VpnPluginInfo {
443 assert_initialized_main_thread!();
444 unsafe {
445 from_glib_none(ffi::nm_vpn_plugin_info_list_find_by_service(
446 list.into_iter()
447 .cloned()
448 .collect::<glib::SList<_>>()
449 .to_glib_none()
450 .0,
451 service.to_glib_none().0,
452 ))
453 }
454 }
455
456 #[cfg(feature = "v1_4")]
476 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
477 #[doc(alias = "nm_vpn_plugin_info_list_find_service_type")]
478 pub fn list_find_service_type(list: &[VpnPluginInfo], name: &str) -> glib::GString {
479 assert_initialized_main_thread!();
480 unsafe {
481 from_glib_full(ffi::nm_vpn_plugin_info_list_find_service_type(
482 list.into_iter()
483 .cloned()
484 .collect::<glib::SList<_>>()
485 .to_glib_none()
486 .0,
487 name.to_glib_none().0,
488 ))
489 }
490 }
491
492 #[cfg(feature = "v1_4")]
508 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
509 #[doc(alias = "nm_vpn_plugin_info_list_get_service_types")]
510 pub fn list_get_service_types(
511 list: &[VpnPluginInfo],
512 only_existing: bool,
513 with_abbreviations: bool,
514 ) -> Vec<glib::GString> {
515 assert_initialized_main_thread!();
516 unsafe {
517 FromGlibPtrContainer::from_glib_full(ffi::nm_vpn_plugin_info_list_get_service_types(
518 list.into_iter()
519 .cloned()
520 .collect::<glib::SList<_>>()
521 .to_glib_none()
522 .0,
523 only_existing.into_glib(),
524 with_abbreviations.into_glib(),
525 ))
526 }
527 }
528
529 #[cfg(feature = "v1_2")]
535 #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
536 #[doc(alias = "nm_vpn_plugin_info_list_load")]
537 pub fn list_load() -> Vec<VpnPluginInfo> {
538 assert_initialized_main_thread!();
539 unsafe { FromGlibPtrContainer::from_glib_full(ffi::nm_vpn_plugin_info_list_load()) }
540 }
541
542 #[cfg(feature = "v1_2")]
552 #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
553 #[doc(alias = "nm_vpn_plugin_info_list_remove")]
554 pub fn list_remove(list: &[VpnPluginInfo], plugin_info: &VpnPluginInfo) -> bool {
555 skip_assert_initialized!();
556 unsafe {
557 from_glib(ffi::nm_vpn_plugin_info_list_remove(
558 &mut list
559 .into_iter()
560 .cloned()
561 .collect::<glib::SList<_>>()
562 .to_glib_none()
563 .0,
564 plugin_info.to_glib_none().0,
565 ))
566 }
567 }
568
569 #[cfg(feature = "v1_2")]
575 #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
576 #[doc(alias = "nm_vpn_plugin_info_validate_filename")]
577 pub fn validate_filename(filename: &str) -> bool {
578 assert_initialized_main_thread!();
579 unsafe {
580 from_glib(ffi::nm_vpn_plugin_info_validate_filename(
581 filename.to_glib_none().0,
582 ))
583 }
584 }
585
586 #[cfg(feature = "v1_2")]
587 #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
588 #[doc(alias = "name")]
589 pub fn connect_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
590 unsafe extern "C" fn notify_name_trampoline<F: Fn(&VpnPluginInfo) + 'static>(
591 this: *mut ffi::NMVpnPluginInfo,
592 _param_spec: glib::ffi::gpointer,
593 f: glib::ffi::gpointer,
594 ) {
595 let f: &F = &*(f as *const F);
596 f(&from_glib_borrow(this))
597 }
598 unsafe {
599 let f: Box_<F> = Box_::new(f);
600 connect_raw(
601 self.as_ptr() as *mut _,
602 c"notify::name".as_ptr() as *const _,
603 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
604 notify_name_trampoline::<F> as *const (),
605 )),
606 Box_::into_raw(f),
607 )
608 }
609 }
610}
611
612#[cfg(feature = "v1_2")]
613#[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
614impl std::fmt::Display for VpnPluginInfo {
615 #[inline]
616 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
617 f.write_str(&self.name())
618 }
619}
620
621#[must_use = "The builder must be built to be used"]
626pub struct VpnPluginInfoBuilder {
627 builder: glib::object::ObjectBuilder<'static, VpnPluginInfo>,
628}
629
630impl VpnPluginInfoBuilder {
631 fn new() -> Self {
632 Self {
633 builder: glib::object::Object::builder(),
634 }
635 }
636
637 #[cfg(feature = "v1_2")]
642 #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
643 pub fn filename(self, filename: impl Into<glib::GString>) -> Self {
644 Self {
645 builder: self.builder.property("filename", filename.into()),
646 }
647 }
648
649 #[cfg(feature = "v1_2")]
653 #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
654 pub fn keyfile(self, keyfile: &glib::KeyFile) -> Self {
655 Self {
656 builder: self.builder.property("keyfile", keyfile),
657 }
658 }
659
660 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
663 pub fn build(self) -> VpnPluginInfo {
664 assert_initialized_main_thread!();
665 self.builder.build()
666 }
667}