|
| 1 | +// This file was generated by gir (https://github.com/gtk-rs/gir) |
| 2 | +// from gir-files (https://github.com/gtk-rs/gir-files) |
| 3 | +// DO NOT EDIT |
| 4 | + |
| 5 | +use crate::Window; |
| 6 | +use glib::object::IsA; |
| 7 | +use glib::object::ObjectType as ObjectType_; |
| 8 | +use glib::signal::connect_raw; |
| 9 | +use glib::signal::SignalHandlerId; |
| 10 | +use glib::translate::*; |
| 11 | +use std::boxed::Box as Box_; |
| 12 | +use std::fmt; |
| 13 | +use std::mem::transmute; |
| 14 | +use std::pin::Pin; |
| 15 | +use std::ptr; |
| 16 | + |
| 17 | +glib::wrapper! { |
| 18 | + #[doc(alias = "GtkFileLauncher")] |
| 19 | + pub struct FileLauncher(Object<ffi::GtkFileLauncher, ffi::GtkFileLauncherClass>); |
| 20 | + |
| 21 | + match fn { |
| 22 | + type_ => || ffi::gtk_file_launcher_get_type(), |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +impl FileLauncher { |
| 27 | + #[doc(alias = "gtk_file_launcher_new")] |
| 28 | + pub fn new(file: Option<&impl IsA<gio::File>>) -> FileLauncher { |
| 29 | + assert_initialized_main_thread!(); |
| 30 | + unsafe { |
| 31 | + from_glib_full(ffi::gtk_file_launcher_new( |
| 32 | + file.map(|p| p.as_ref()).to_glib_none().0, |
| 33 | + )) |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + #[doc(alias = "gtk_file_launcher_get_file")] |
| 38 | + #[doc(alias = "get_file")] |
| 39 | + pub fn file(&self) -> Option<gio::File> { |
| 40 | + unsafe { from_glib_none(ffi::gtk_file_launcher_get_file(self.to_glib_none().0)) } |
| 41 | + } |
| 42 | + |
| 43 | + #[doc(alias = "gtk_file_launcher_launch")] |
| 44 | + pub fn launch<P: FnOnce(Result<(), glib::Error>) + 'static>( |
| 45 | + &self, |
| 46 | + parent: Option<&impl IsA<Window>>, |
| 47 | + cancellable: Option<&impl IsA<gio::Cancellable>>, |
| 48 | + callback: P, |
| 49 | + ) { |
| 50 | + let main_context = glib::MainContext::ref_thread_default(); |
| 51 | + let is_main_context_owner = main_context.is_owner(); |
| 52 | + let has_acquired_main_context = (!is_main_context_owner) |
| 53 | + .then(|| main_context.acquire().ok()) |
| 54 | + .flatten(); |
| 55 | + assert!( |
| 56 | + is_main_context_owner || has_acquired_main_context.is_some(), |
| 57 | + "Async operations only allowed if the thread is owning the MainContext" |
| 58 | + ); |
| 59 | + |
| 60 | + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = |
| 61 | + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); |
| 62 | + unsafe extern "C" fn launch_trampoline<P: FnOnce(Result<(), glib::Error>) + 'static>( |
| 63 | + _source_object: *mut glib::gobject_ffi::GObject, |
| 64 | + res: *mut gio::ffi::GAsyncResult, |
| 65 | + user_data: glib::ffi::gpointer, |
| 66 | + ) { |
| 67 | + let mut error = ptr::null_mut(); |
| 68 | + let _ = ffi::gtk_file_launcher_launch_finish(_source_object as *mut _, res, &mut error); |
| 69 | + let result = if error.is_null() { |
| 70 | + Ok(()) |
| 71 | + } else { |
| 72 | + Err(from_glib_full(error)) |
| 73 | + }; |
| 74 | + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = |
| 75 | + Box_::from_raw(user_data as *mut _); |
| 76 | + let callback: P = callback.into_inner(); |
| 77 | + callback(result); |
| 78 | + } |
| 79 | + let callback = launch_trampoline::<P>; |
| 80 | + unsafe { |
| 81 | + ffi::gtk_file_launcher_launch( |
| 82 | + self.to_glib_none().0, |
| 83 | + parent.map(|p| p.as_ref()).to_glib_none().0, |
| 84 | + cancellable.map(|p| p.as_ref()).to_glib_none().0, |
| 85 | + Some(callback), |
| 86 | + Box_::into_raw(user_data) as *mut _, |
| 87 | + ); |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + pub fn launch_future( |
| 92 | + &self, |
| 93 | + parent: Option<&(impl IsA<Window> + Clone + 'static)>, |
| 94 | + ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> { |
| 95 | + let parent = parent.map(ToOwned::to_owned); |
| 96 | + Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { |
| 97 | + obj.launch( |
| 98 | + parent.as_ref().map(::std::borrow::Borrow::borrow), |
| 99 | + Some(cancellable), |
| 100 | + move |res| { |
| 101 | + send.resolve(res); |
| 102 | + }, |
| 103 | + ); |
| 104 | + })) |
| 105 | + } |
| 106 | + |
| 107 | + #[doc(alias = "gtk_file_launcher_open_containing_folder")] |
| 108 | + pub fn open_containing_folder<P: FnOnce(Result<(), glib::Error>) + 'static>( |
| 109 | + &self, |
| 110 | + parent: Option<&impl IsA<Window>>, |
| 111 | + cancellable: Option<&impl IsA<gio::Cancellable>>, |
| 112 | + callback: P, |
| 113 | + ) { |
| 114 | + let main_context = glib::MainContext::ref_thread_default(); |
| 115 | + let is_main_context_owner = main_context.is_owner(); |
| 116 | + let has_acquired_main_context = (!is_main_context_owner) |
| 117 | + .then(|| main_context.acquire().ok()) |
| 118 | + .flatten(); |
| 119 | + assert!( |
| 120 | + is_main_context_owner || has_acquired_main_context.is_some(), |
| 121 | + "Async operations only allowed if the thread is owning the MainContext" |
| 122 | + ); |
| 123 | + |
| 124 | + let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = |
| 125 | + Box_::new(glib::thread_guard::ThreadGuard::new(callback)); |
| 126 | + unsafe extern "C" fn open_containing_folder_trampoline< |
| 127 | + P: FnOnce(Result<(), glib::Error>) + 'static, |
| 128 | + >( |
| 129 | + _source_object: *mut glib::gobject_ffi::GObject, |
| 130 | + res: *mut gio::ffi::GAsyncResult, |
| 131 | + user_data: glib::ffi::gpointer, |
| 132 | + ) { |
| 133 | + let mut error = ptr::null_mut(); |
| 134 | + let _ = ffi::gtk_file_launcher_open_containing_folder_finish( |
| 135 | + _source_object as *mut _, |
| 136 | + res, |
| 137 | + &mut error, |
| 138 | + ); |
| 139 | + let result = if error.is_null() { |
| 140 | + Ok(()) |
| 141 | + } else { |
| 142 | + Err(from_glib_full(error)) |
| 143 | + }; |
| 144 | + let callback: Box_<glib::thread_guard::ThreadGuard<P>> = |
| 145 | + Box_::from_raw(user_data as *mut _); |
| 146 | + let callback: P = callback.into_inner(); |
| 147 | + callback(result); |
| 148 | + } |
| 149 | + let callback = open_containing_folder_trampoline::<P>; |
| 150 | + unsafe { |
| 151 | + ffi::gtk_file_launcher_open_containing_folder( |
| 152 | + self.to_glib_none().0, |
| 153 | + parent.map(|p| p.as_ref()).to_glib_none().0, |
| 154 | + cancellable.map(|p| p.as_ref()).to_glib_none().0, |
| 155 | + Some(callback), |
| 156 | + Box_::into_raw(user_data) as *mut _, |
| 157 | + ); |
| 158 | + } |
| 159 | + } |
| 160 | + |
| 161 | + pub fn open_containing_folder_future( |
| 162 | + &self, |
| 163 | + parent: Option<&(impl IsA<Window> + Clone + 'static)>, |
| 164 | + ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> { |
| 165 | + let parent = parent.map(ToOwned::to_owned); |
| 166 | + Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| { |
| 167 | + obj.open_containing_folder( |
| 168 | + parent.as_ref().map(::std::borrow::Borrow::borrow), |
| 169 | + Some(cancellable), |
| 170 | + move |res| { |
| 171 | + send.resolve(res); |
| 172 | + }, |
| 173 | + ); |
| 174 | + })) |
| 175 | + } |
| 176 | + |
| 177 | + #[doc(alias = "gtk_file_launcher_set_file")] |
| 178 | + pub fn set_file(&self, file: Option<&impl IsA<gio::File>>) { |
| 179 | + unsafe { |
| 180 | + ffi::gtk_file_launcher_set_file( |
| 181 | + self.to_glib_none().0, |
| 182 | + file.map(|p| p.as_ref()).to_glib_none().0, |
| 183 | + ); |
| 184 | + } |
| 185 | + } |
| 186 | + |
| 187 | + #[cfg(any(feature = "v4_10", feature = "dox"))] |
| 188 | + #[cfg_attr(feature = "dox", doc(cfg(feature = "v4_10")))] |
| 189 | + #[doc(alias = "file")] |
| 190 | + pub fn connect_file_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { |
| 191 | + unsafe extern "C" fn notify_file_trampoline<F: Fn(&FileLauncher) + 'static>( |
| 192 | + this: *mut ffi::GtkFileLauncher, |
| 193 | + _param_spec: glib::ffi::gpointer, |
| 194 | + f: glib::ffi::gpointer, |
| 195 | + ) { |
| 196 | + let f: &F = &*(f as *const F); |
| 197 | + f(&from_glib_borrow(this)) |
| 198 | + } |
| 199 | + unsafe { |
| 200 | + let f: Box_<F> = Box_::new(f); |
| 201 | + connect_raw( |
| 202 | + self.as_ptr() as *mut _, |
| 203 | + b"notify::file\0".as_ptr() as *const _, |
| 204 | + Some(transmute::<_, unsafe extern "C" fn()>( |
| 205 | + notify_file_trampoline::<F> as *const (), |
| 206 | + )), |
| 207 | + Box_::into_raw(f), |
| 208 | + ) |
| 209 | + } |
| 210 | + } |
| 211 | +} |
| 212 | + |
| 213 | +impl fmt::Display for FileLauncher { |
| 214 | + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 215 | + f.write_str("FileLauncher") |
| 216 | + } |
| 217 | +} |
0 commit comments