1#![allow(deprecated)]
6
7use crate::{ffi,Connection,Object};
8#[cfg(feature = "v1_12")]
9#[cfg_attr(docsrs, doc(cfg(feature = "v1_12")))]
10use crate::{SettingsConnectionFlags};
11use glib::{prelude::*,signal::{connect_raw, SignalHandlerId},translate::*};
12use std::{boxed::Box as Box_,pin::Pin};
13
14glib::wrapper! {
15 #[doc(alias = "NMRemoteConnection")]
86 pub struct RemoteConnection(Object<ffi::NMRemoteConnection, ffi::NMRemoteConnectionClass>) @extends Object, @implements Connection;
87
88 match fn {
89 type_ => || ffi::nm_remote_connection_get_type(),
90 }
91}
92
93impl RemoteConnection {
94 #[cfg_attr(feature = "v1_22", deprecated = "Since 1.22")]
110 #[allow(deprecated)]
111 #[doc(alias = "nm_remote_connection_commit_changes")]
112 pub fn commit_changes(&self, save_to_disk: bool, cancellable: Option<&impl IsA<gio::Cancellable>>) -> Result<(), glib::Error> {
113 unsafe {
114 let mut error = std::ptr::null_mut();
115 let is_ok = ffi::nm_remote_connection_commit_changes(self.to_glib_none().0, save_to_disk.into_glib(), cancellable.map(|p| p.as_ref()).to_glib_none().0, &mut error);
116 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
117 if error.is_null() { Ok(()) } else { Err(from_glib_full(error)) }
118 }
119 }
120
121 #[doc(alias = "nm_remote_connection_commit_changes_async")]
132 pub fn commit_changes_async<P: FnOnce(Result<(), glib::Error>) + 'static>(&self, save_to_disk: bool, cancellable: Option<&impl IsA<gio::Cancellable>>, callback: P) {
133
134 let main_context = glib::MainContext::ref_thread_default();
135 let is_main_context_owner = main_context.is_owner();
136 let has_acquired_main_context = (!is_main_context_owner)
137 .then(|| main_context.acquire().ok())
138 .flatten();
139 assert!(
140 is_main_context_owner || has_acquired_main_context.is_some(),
141 "Async operations only allowed if the thread is owning the MainContext"
142 );
143
144 let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = Box_::new(glib::thread_guard::ThreadGuard::new(callback));
145 unsafe extern "C" fn commit_changes_async_trampoline<P: FnOnce(Result<(), glib::Error>) + 'static>(_source_object: *mut glib::gobject_ffi::GObject, res: *mut gio::ffi::GAsyncResult, user_data: glib::ffi::gpointer) {
146 let mut error = std::ptr::null_mut();
147 ffi::nm_remote_connection_commit_changes_finish(_source_object as *mut _, res, &mut error);
148 let result = if error.is_null() { Ok(()) } else { Err(from_glib_full(error)) };
149 let callback: Box_<glib::thread_guard::ThreadGuard<P>> = Box_::from_raw(user_data as *mut _);
150 let callback: P = callback.into_inner();
151 callback(result);
152 }
153 let callback = commit_changes_async_trampoline::<P>;
154 unsafe {
155 ffi::nm_remote_connection_commit_changes_async(self.to_glib_none().0, save_to_disk.into_glib(), cancellable.map(|p| p.as_ref()).to_glib_none().0, Some(callback), Box_::into_raw(user_data) as *mut _);
156 }
157 }
158
159
160 pub fn commit_changes_future(&self, save_to_disk: bool) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
161
162 Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
163 obj.commit_changes_async(
164 save_to_disk,
165 Some(cancellable),
166 move |res| {
167 send.resolve(res);
168 },
169 );
170 }))
171 }
172
173 #[cfg_attr(feature = "v1_22", deprecated = "Since 1.22")]
185 #[allow(deprecated)]
186 #[doc(alias = "nm_remote_connection_delete")]
187 pub fn delete(&self, cancellable: Option<&impl IsA<gio::Cancellable>>) -> Result<(), glib::Error> {
188 unsafe {
189 let mut error = std::ptr::null_mut();
190 let is_ok = ffi::nm_remote_connection_delete(self.to_glib_none().0, cancellable.map(|p| p.as_ref()).to_glib_none().0, &mut error);
191 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
192 if error.is_null() { Ok(()) } else { Err(from_glib_full(error)) }
193 }
194 }
195
196 #[doc(alias = "nm_remote_connection_delete_async")]
202 pub fn delete_async<P: FnOnce(Result<(), glib::Error>) + 'static>(&self, cancellable: Option<&impl IsA<gio::Cancellable>>, callback: P) {
203
204 let main_context = glib::MainContext::ref_thread_default();
205 let is_main_context_owner = main_context.is_owner();
206 let has_acquired_main_context = (!is_main_context_owner)
207 .then(|| main_context.acquire().ok())
208 .flatten();
209 assert!(
210 is_main_context_owner || has_acquired_main_context.is_some(),
211 "Async operations only allowed if the thread is owning the MainContext"
212 );
213
214 let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = Box_::new(glib::thread_guard::ThreadGuard::new(callback));
215 unsafe extern "C" fn delete_async_trampoline<P: FnOnce(Result<(), glib::Error>) + 'static>(_source_object: *mut glib::gobject_ffi::GObject, res: *mut gio::ffi::GAsyncResult, user_data: glib::ffi::gpointer) {
216 let mut error = std::ptr::null_mut();
217 ffi::nm_remote_connection_delete_finish(_source_object as *mut _, res, &mut error);
218 let result = if error.is_null() { Ok(()) } else { Err(from_glib_full(error)) };
219 let callback: Box_<glib::thread_guard::ThreadGuard<P>> = Box_::from_raw(user_data as *mut _);
220 let callback: P = callback.into_inner();
221 callback(result);
222 }
223 let callback = delete_async_trampoline::<P>;
224 unsafe {
225 ffi::nm_remote_connection_delete_async(self.to_glib_none().0, cancellable.map(|p| p.as_ref()).to_glib_none().0, Some(callback), Box_::into_raw(user_data) as *mut _);
226 }
227 }
228
229
230 pub fn delete_future(&self) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
231
232 Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
233 obj.delete_async(
234 Some(cancellable),
235 move |res| {
236 send.resolve(res);
237 },
238 );
239 }))
240 }
241
242 #[cfg(feature = "v1_12")]
247 #[cfg_attr(docsrs, doc(cfg(feature = "v1_12")))]
248 #[doc(alias = "nm_remote_connection_get_filename")]
249 #[doc(alias = "get_filename")]
250 pub fn filename(&self) -> glib::GString {
251 unsafe {
252 from_glib_none(ffi::nm_remote_connection_get_filename(self.to_glib_none().0))
253 }
254 }
255
256 #[cfg(feature = "v1_12")]
261 #[cfg_attr(docsrs, doc(cfg(feature = "v1_12")))]
262 #[doc(alias = "nm_remote_connection_get_flags")]
263 #[doc(alias = "get_flags")]
264 pub fn flags(&self) -> SettingsConnectionFlags {
265 unsafe {
266 from_glib(ffi::nm_remote_connection_get_flags(self.to_glib_none().0))
267 }
268 }
269
270 #[doc(alias = "nm_remote_connection_get_unsaved")]
304 #[doc(alias = "get_unsaved")]
305 #[doc(alias = "unsaved")]
306 pub fn is_unsaved(&self) -> bool {
307 unsafe {
308 from_glib(ffi::nm_remote_connection_get_unsaved(self.to_glib_none().0))
309 }
310 }
311
312 #[cfg(feature = "v1_44")]
318 #[cfg_attr(docsrs, doc(cfg(feature = "v1_44")))]
319 #[doc(alias = "nm_remote_connection_get_version_id")]
320 #[doc(alias = "get_version_id")]
321 #[doc(alias = "version-id")]
322 pub fn version_id(&self) -> u64 {
323 unsafe {
324 ffi::nm_remote_connection_get_version_id(self.to_glib_none().0)
325 }
326 }
327
328 #[doc(alias = "nm_remote_connection_get_visible")]
342 #[doc(alias = "get_visible")]
343 #[doc(alias = "visible")]
344 pub fn is_visible(&self) -> bool {
345 unsafe {
346 from_glib(ffi::nm_remote_connection_get_visible(self.to_glib_none().0))
347 }
348 }
349
350 #[cfg_attr(feature = "v1_22", deprecated = "Since 1.22")]
363 #[allow(deprecated)]
364 #[doc(alias = "nm_remote_connection_save")]
365 pub fn save(&self, cancellable: Option<&impl IsA<gio::Cancellable>>) -> Result<(), glib::Error> {
366 unsafe {
367 let mut error = std::ptr::null_mut();
368 let is_ok = ffi::nm_remote_connection_save(self.to_glib_none().0, cancellable.map(|p| p.as_ref()).to_glib_none().0, &mut error);
369 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
370 if error.is_null() { Ok(()) } else { Err(from_glib_full(error)) }
371 }
372 }
373
374 #[doc(alias = "nm_remote_connection_save_async")]
381 pub fn save_async<P: FnOnce(Result<(), glib::Error>) + 'static>(&self, cancellable: Option<&impl IsA<gio::Cancellable>>, callback: P) {
382
383 let main_context = glib::MainContext::ref_thread_default();
384 let is_main_context_owner = main_context.is_owner();
385 let has_acquired_main_context = (!is_main_context_owner)
386 .then(|| main_context.acquire().ok())
387 .flatten();
388 assert!(
389 is_main_context_owner || has_acquired_main_context.is_some(),
390 "Async operations only allowed if the thread is owning the MainContext"
391 );
392
393 let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = Box_::new(glib::thread_guard::ThreadGuard::new(callback));
394 unsafe extern "C" fn save_async_trampoline<P: FnOnce(Result<(), glib::Error>) + 'static>(_source_object: *mut glib::gobject_ffi::GObject, res: *mut gio::ffi::GAsyncResult, user_data: glib::ffi::gpointer) {
395 let mut error = std::ptr::null_mut();
396 ffi::nm_remote_connection_save_finish(_source_object as *mut _, res, &mut error);
397 let result = if error.is_null() { Ok(()) } else { Err(from_glib_full(error)) };
398 let callback: Box_<glib::thread_guard::ThreadGuard<P>> = Box_::from_raw(user_data as *mut _);
399 let callback: P = callback.into_inner();
400 callback(result);
401 }
402 let callback = save_async_trampoline::<P>;
403 unsafe {
404 ffi::nm_remote_connection_save_async(self.to_glib_none().0, cancellable.map(|p| p.as_ref()).to_glib_none().0, Some(callback), Box_::into_raw(user_data) as *mut _);
405 }
406 }
407
408
409 pub fn save_future(&self) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
410
411 Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
412 obj.save_async(
413 Some(cancellable),
414 move |res| {
415 send.resolve(res);
416 },
417 );
418 }))
419 }
420
421 #[cfg(feature = "v1_12")]
449 #[cfg_attr(docsrs, doc(cfg(feature = "v1_12")))]
450 #[doc(alias = "filename")]
451 pub fn connect_filename_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
452 unsafe extern "C" fn notify_filename_trampoline<F: Fn(&RemoteConnection) + 'static>(this: *mut ffi::NMRemoteConnection, _param_spec: glib::ffi::gpointer, f: glib::ffi::gpointer) {
453 let f: &F = &*(f as *const F);
454 f(&from_glib_borrow(this))
455 }
456 unsafe {
457 let f: Box_<F> = Box_::new(f);
458 connect_raw(self.as_ptr() as *mut _, c"notify::filename".as_ptr() as *const _,
459 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(notify_filename_trampoline::<F> as *const ())), Box_::into_raw(f))
460 }
461 }
462
463 #[cfg(feature = "v1_12")]
464 #[cfg_attr(docsrs, doc(cfg(feature = "v1_12")))]
465 #[doc(alias = "flags")]
466 pub fn connect_flags_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
467 unsafe extern "C" fn notify_flags_trampoline<F: Fn(&RemoteConnection) + 'static>(this: *mut ffi::NMRemoteConnection, _param_spec: glib::ffi::gpointer, f: glib::ffi::gpointer) {
468 let f: &F = &*(f as *const F);
469 f(&from_glib_borrow(this))
470 }
471 unsafe {
472 let f: Box_<F> = Box_::new(f);
473 connect_raw(self.as_ptr() as *mut _, c"notify::flags".as_ptr() as *const _,
474 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(notify_flags_trampoline::<F> as *const ())), Box_::into_raw(f))
475 }
476 }
477
478 #[doc(alias = "unsaved")]
479 pub fn connect_unsaved_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
480 unsafe extern "C" fn notify_unsaved_trampoline<F: Fn(&RemoteConnection) + 'static>(this: *mut ffi::NMRemoteConnection, _param_spec: glib::ffi::gpointer, f: glib::ffi::gpointer) {
481 let f: &F = &*(f as *const F);
482 f(&from_glib_borrow(this))
483 }
484 unsafe {
485 let f: Box_<F> = Box_::new(f);
486 connect_raw(self.as_ptr() as *mut _, c"notify::unsaved".as_ptr() as *const _,
487 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(notify_unsaved_trampoline::<F> as *const ())), Box_::into_raw(f))
488 }
489 }
490
491 #[cfg(feature = "v1_44")]
492 #[cfg_attr(docsrs, doc(cfg(feature = "v1_44")))]
493 #[doc(alias = "version-id")]
494 pub fn connect_version_id_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
495 unsafe extern "C" fn notify_version_id_trampoline<F: Fn(&RemoteConnection) + 'static>(this: *mut ffi::NMRemoteConnection, _param_spec: glib::ffi::gpointer, f: glib::ffi::gpointer) {
496 let f: &F = &*(f as *const F);
497 f(&from_glib_borrow(this))
498 }
499 unsafe {
500 let f: Box_<F> = Box_::new(f);
501 connect_raw(self.as_ptr() as *mut _, c"notify::version-id".as_ptr() as *const _,
502 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(notify_version_id_trampoline::<F> as *const ())), Box_::into_raw(f))
503 }
504 }
505
506 #[doc(alias = "visible")]
507 pub fn connect_visible_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
508 unsafe extern "C" fn notify_visible_trampoline<F: Fn(&RemoteConnection) + 'static>(this: *mut ffi::NMRemoteConnection, _param_spec: glib::ffi::gpointer, f: glib::ffi::gpointer) {
509 let f: &F = &*(f as *const F);
510 f(&from_glib_borrow(this))
511 }
512 unsafe {
513 let f: Box_<F> = Box_::new(f);
514 connect_raw(self.as_ptr() as *mut _, c"notify::visible".as_ptr() as *const _,
515 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(notify_visible_trampoline::<F> as *const ())), Box_::into_raw(f))
516 }
517 }
518}