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::AppInfoCreateFlags; 6 use crate::AppLaunchContext; 7 #[cfg(any(feature = "v2_50", feature = "dox"))] 8 #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_50")))] 9 use crate::AsyncResult; 10 #[cfg(any(feature = "v2_50", feature = "dox"))] 11 #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_50")))] 12 use crate::Cancellable; 13 use crate::File; 14 use crate::Icon; 15 use glib::object::IsA; 16 use glib::translate::*; 17 #[cfg(any(feature = "v2_50", feature = "dox"))] 18 #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_50")))] 19 use std::boxed::Box as Box_; 20 use std::fmt; 21 #[cfg(any(feature = "v2_50", feature = "dox"))] 22 #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_50")))] 23 use std::pin::Pin; 24 use std::ptr; 25 26 glib::wrapper! { 27 #[doc(alias = "GAppInfo")] 28 pub struct AppInfo(Interface<ffi::GAppInfo, ffi::GAppInfoIface>); 29 30 match fn { 31 type_ => || ffi::g_app_info_get_type(), 32 } 33 } 34 35 impl AppInfo { 36 #[doc(alias = "g_app_info_create_from_commandline")] create_from_commandline<P: AsRef<std::ffi::OsStr>>( commandline: P, application_name: Option<&str>, flags: AppInfoCreateFlags, ) -> Result<AppInfo, glib::Error>37 pub fn create_from_commandline<P: AsRef<std::ffi::OsStr>>( 38 commandline: P, 39 application_name: Option<&str>, 40 flags: AppInfoCreateFlags, 41 ) -> Result<AppInfo, glib::Error> { 42 unsafe { 43 let mut error = ptr::null_mut(); 44 let ret = ffi::g_app_info_create_from_commandline( 45 commandline.as_ref().to_glib_none().0, 46 application_name.to_glib_none().0, 47 flags.into_glib(), 48 &mut error, 49 ); 50 if error.is_null() { 51 Ok(from_glib_full(ret)) 52 } else { 53 Err(from_glib_full(error)) 54 } 55 } 56 } 57 58 #[doc(alias = "g_app_info_get_all")] 59 #[doc(alias = "get_all")] all() -> Vec<AppInfo>60 pub fn all() -> Vec<AppInfo> { 61 unsafe { FromGlibPtrContainer::from_glib_full(ffi::g_app_info_get_all()) } 62 } 63 64 #[doc(alias = "g_app_info_get_all_for_type")] 65 #[doc(alias = "get_all_for_type")] all_for_type(content_type: &str) -> Vec<AppInfo>66 pub fn all_for_type(content_type: &str) -> Vec<AppInfo> { 67 unsafe { 68 FromGlibPtrContainer::from_glib_full(ffi::g_app_info_get_all_for_type( 69 content_type.to_glib_none().0, 70 )) 71 } 72 } 73 74 #[doc(alias = "g_app_info_get_default_for_type")] 75 #[doc(alias = "get_default_for_type")] default_for_type(content_type: &str, must_support_uris: bool) -> Option<AppInfo>76 pub fn default_for_type(content_type: &str, must_support_uris: bool) -> Option<AppInfo> { 77 unsafe { 78 from_glib_full(ffi::g_app_info_get_default_for_type( 79 content_type.to_glib_none().0, 80 must_support_uris.into_glib(), 81 )) 82 } 83 } 84 85 #[doc(alias = "g_app_info_get_default_for_uri_scheme")] 86 #[doc(alias = "get_default_for_uri_scheme")] default_for_uri_scheme(uri_scheme: &str) -> Option<AppInfo>87 pub fn default_for_uri_scheme(uri_scheme: &str) -> Option<AppInfo> { 88 unsafe { 89 from_glib_full(ffi::g_app_info_get_default_for_uri_scheme( 90 uri_scheme.to_glib_none().0, 91 )) 92 } 93 } 94 95 #[doc(alias = "g_app_info_get_fallback_for_type")] 96 #[doc(alias = "get_fallback_for_type")] fallback_for_type(content_type: &str) -> Vec<AppInfo>97 pub fn fallback_for_type(content_type: &str) -> Vec<AppInfo> { 98 unsafe { 99 FromGlibPtrContainer::from_glib_full(ffi::g_app_info_get_fallback_for_type( 100 content_type.to_glib_none().0, 101 )) 102 } 103 } 104 105 #[doc(alias = "g_app_info_get_recommended_for_type")] 106 #[doc(alias = "get_recommended_for_type")] recommended_for_type(content_type: &str) -> Vec<AppInfo>107 pub fn recommended_for_type(content_type: &str) -> Vec<AppInfo> { 108 unsafe { 109 FromGlibPtrContainer::from_glib_full(ffi::g_app_info_get_recommended_for_type( 110 content_type.to_glib_none().0, 111 )) 112 } 113 } 114 115 #[doc(alias = "g_app_info_launch_default_for_uri")] launch_default_for_uri<P: IsA<AppLaunchContext>>( uri: &str, context: Option<&P>, ) -> Result<(), glib::Error>116 pub fn launch_default_for_uri<P: IsA<AppLaunchContext>>( 117 uri: &str, 118 context: Option<&P>, 119 ) -> Result<(), glib::Error> { 120 unsafe { 121 let mut error = ptr::null_mut(); 122 let _ = ffi::g_app_info_launch_default_for_uri( 123 uri.to_glib_none().0, 124 context.map(|p| p.as_ref()).to_glib_none().0, 125 &mut error, 126 ); 127 if error.is_null() { 128 Ok(()) 129 } else { 130 Err(from_glib_full(error)) 131 } 132 } 133 } 134 135 #[cfg(any(feature = "v2_50", feature = "dox"))] 136 #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_50")))] 137 #[doc(alias = "g_app_info_launch_default_for_uri_async")] launch_default_for_uri_async< P: IsA<AppLaunchContext>, Q: IsA<Cancellable>, R: FnOnce(Result<(), glib::Error>) + Send + 'static, >( uri: &str, context: Option<&P>, cancellable: Option<&Q>, callback: R, )138 pub fn launch_default_for_uri_async< 139 P: IsA<AppLaunchContext>, 140 Q: IsA<Cancellable>, 141 R: FnOnce(Result<(), glib::Error>) + Send + 'static, 142 >( 143 uri: &str, 144 context: Option<&P>, 145 cancellable: Option<&Q>, 146 callback: R, 147 ) { 148 let user_data: Box_<R> = Box_::new(callback); 149 unsafe extern "C" fn launch_default_for_uri_async_trampoline< 150 R: FnOnce(Result<(), glib::Error>) + Send + 'static, 151 >( 152 _source_object: *mut glib::gobject_ffi::GObject, 153 res: *mut crate::ffi::GAsyncResult, 154 user_data: glib::ffi::gpointer, 155 ) { 156 let mut error = ptr::null_mut(); 157 let _ = ffi::g_app_info_launch_default_for_uri_finish(res, &mut error); 158 let result = if error.is_null() { 159 Ok(()) 160 } else { 161 Err(from_glib_full(error)) 162 }; 163 let callback: Box_<R> = Box_::from_raw(user_data as *mut _); 164 callback(result); 165 } 166 let callback = launch_default_for_uri_async_trampoline::<R>; 167 unsafe { 168 ffi::g_app_info_launch_default_for_uri_async( 169 uri.to_glib_none().0, 170 context.map(|p| p.as_ref()).to_glib_none().0, 171 cancellable.map(|p| p.as_ref()).to_glib_none().0, 172 Some(callback), 173 Box_::into_raw(user_data) as *mut _, 174 ); 175 } 176 } 177 178 #[cfg(any(feature = "v2_50", feature = "dox"))] 179 #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_50")))] launch_default_for_uri_async_future<P: IsA<AppLaunchContext> + Clone + 'static>( uri: &str, context: Option<&P>, ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>>180 pub fn launch_default_for_uri_async_future<P: IsA<AppLaunchContext> + Clone + 'static>( 181 uri: &str, 182 context: Option<&P>, 183 ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> { 184 let uri = String::from(uri); 185 let context = context.map(ToOwned::to_owned); 186 Box_::pin(crate::GioFuture::new( 187 &(), 188 move |_obj, cancellable, send| { 189 Self::launch_default_for_uri_async( 190 &uri, 191 context.as_ref().map(::std::borrow::Borrow::borrow), 192 Some(cancellable), 193 move |res| { 194 send.resolve(res); 195 }, 196 ); 197 }, 198 )) 199 } 200 201 #[doc(alias = "g_app_info_reset_type_associations")] reset_type_associations(content_type: &str)202 pub fn reset_type_associations(content_type: &str) { 203 unsafe { 204 ffi::g_app_info_reset_type_associations(content_type.to_glib_none().0); 205 } 206 } 207 } 208 209 pub const NONE_APP_INFO: Option<&AppInfo> = None; 210 211 pub trait AppInfoExt: 'static { 212 #[doc(alias = "g_app_info_add_supports_type")] add_supports_type(&self, content_type: &str) -> Result<(), glib::Error>213 fn add_supports_type(&self, content_type: &str) -> Result<(), glib::Error>; 214 215 #[doc(alias = "g_app_info_can_delete")] can_delete(&self) -> bool216 fn can_delete(&self) -> bool; 217 218 #[doc(alias = "g_app_info_can_remove_supports_type")] can_remove_supports_type(&self) -> bool219 fn can_remove_supports_type(&self) -> bool; 220 221 #[doc(alias = "g_app_info_delete")] delete(&self) -> bool222 fn delete(&self) -> bool; 223 224 #[doc(alias = "g_app_info_dup")] dup(&self) -> AppInfo225 fn dup(&self) -> AppInfo; 226 227 #[doc(alias = "g_app_info_equal")] equal<P: IsA<AppInfo>>(&self, appinfo2: &P) -> bool228 fn equal<P: IsA<AppInfo>>(&self, appinfo2: &P) -> bool; 229 230 #[doc(alias = "g_app_info_get_commandline")] 231 #[doc(alias = "get_commandline")] commandline(&self) -> Option<std::path::PathBuf>232 fn commandline(&self) -> Option<std::path::PathBuf>; 233 234 #[doc(alias = "g_app_info_get_description")] 235 #[doc(alias = "get_description")] description(&self) -> Option<glib::GString>236 fn description(&self) -> Option<glib::GString>; 237 238 #[doc(alias = "g_app_info_get_display_name")] 239 #[doc(alias = "get_display_name")] display_name(&self) -> glib::GString240 fn display_name(&self) -> glib::GString; 241 242 #[doc(alias = "g_app_info_get_executable")] 243 #[doc(alias = "get_executable")] executable(&self) -> std::path::PathBuf244 fn executable(&self) -> std::path::PathBuf; 245 246 #[doc(alias = "g_app_info_get_icon")] 247 #[doc(alias = "get_icon")] icon(&self) -> Option<Icon>248 fn icon(&self) -> Option<Icon>; 249 250 #[doc(alias = "g_app_info_get_id")] 251 #[doc(alias = "get_id")] id(&self) -> Option<glib::GString>252 fn id(&self) -> Option<glib::GString>; 253 254 #[doc(alias = "g_app_info_get_name")] 255 #[doc(alias = "get_name")] name(&self) -> glib::GString256 fn name(&self) -> glib::GString; 257 258 #[doc(alias = "g_app_info_get_supported_types")] 259 #[doc(alias = "get_supported_types")] supported_types(&self) -> Vec<glib::GString>260 fn supported_types(&self) -> Vec<glib::GString>; 261 262 #[doc(alias = "g_app_info_launch")] launch<P: IsA<AppLaunchContext>>( &self, files: &[File], context: Option<&P>, ) -> Result<(), glib::Error>263 fn launch<P: IsA<AppLaunchContext>>( 264 &self, 265 files: &[File], 266 context: Option<&P>, 267 ) -> Result<(), glib::Error>; 268 269 #[doc(alias = "g_app_info_launch_uris")] launch_uris<P: IsA<AppLaunchContext>>( &self, uris: &[&str], context: Option<&P>, ) -> Result<(), glib::Error>270 fn launch_uris<P: IsA<AppLaunchContext>>( 271 &self, 272 uris: &[&str], 273 context: Option<&P>, 274 ) -> Result<(), glib::Error>; 275 276 #[doc(alias = "g_app_info_remove_supports_type")] remove_supports_type(&self, content_type: &str) -> Result<(), glib::Error>277 fn remove_supports_type(&self, content_type: &str) -> Result<(), glib::Error>; 278 279 #[doc(alias = "g_app_info_set_as_default_for_extension")] set_as_default_for_extension<P: AsRef<std::path::Path>>( &self, extension: P, ) -> Result<(), glib::Error>280 fn set_as_default_for_extension<P: AsRef<std::path::Path>>( 281 &self, 282 extension: P, 283 ) -> Result<(), glib::Error>; 284 285 #[doc(alias = "g_app_info_set_as_default_for_type")] set_as_default_for_type(&self, content_type: &str) -> Result<(), glib::Error>286 fn set_as_default_for_type(&self, content_type: &str) -> Result<(), glib::Error>; 287 288 #[doc(alias = "g_app_info_set_as_last_used_for_type")] set_as_last_used_for_type(&self, content_type: &str) -> Result<(), glib::Error>289 fn set_as_last_used_for_type(&self, content_type: &str) -> Result<(), glib::Error>; 290 291 #[doc(alias = "g_app_info_should_show")] should_show(&self) -> bool292 fn should_show(&self) -> bool; 293 294 #[doc(alias = "g_app_info_supports_files")] supports_files(&self) -> bool295 fn supports_files(&self) -> bool; 296 297 #[doc(alias = "g_app_info_supports_uris")] supports_uris(&self) -> bool298 fn supports_uris(&self) -> bool; 299 } 300 301 impl<O: IsA<AppInfo>> AppInfoExt for O { add_supports_type(&self, content_type: &str) -> Result<(), glib::Error>302 fn add_supports_type(&self, content_type: &str) -> Result<(), glib::Error> { 303 unsafe { 304 let mut error = ptr::null_mut(); 305 let _ = ffi::g_app_info_add_supports_type( 306 self.as_ref().to_glib_none().0, 307 content_type.to_glib_none().0, 308 &mut error, 309 ); 310 if error.is_null() { 311 Ok(()) 312 } else { 313 Err(from_glib_full(error)) 314 } 315 } 316 } 317 can_delete(&self) -> bool318 fn can_delete(&self) -> bool { 319 unsafe { from_glib(ffi::g_app_info_can_delete(self.as_ref().to_glib_none().0)) } 320 } 321 can_remove_supports_type(&self) -> bool322 fn can_remove_supports_type(&self) -> bool { 323 unsafe { 324 from_glib(ffi::g_app_info_can_remove_supports_type( 325 self.as_ref().to_glib_none().0, 326 )) 327 } 328 } 329 delete(&self) -> bool330 fn delete(&self) -> bool { 331 unsafe { from_glib(ffi::g_app_info_delete(self.as_ref().to_glib_none().0)) } 332 } 333 dup(&self) -> AppInfo334 fn dup(&self) -> AppInfo { 335 unsafe { from_glib_full(ffi::g_app_info_dup(self.as_ref().to_glib_none().0)) } 336 } 337 equal<P: IsA<AppInfo>>(&self, appinfo2: &P) -> bool338 fn equal<P: IsA<AppInfo>>(&self, appinfo2: &P) -> bool { 339 unsafe { 340 from_glib(ffi::g_app_info_equal( 341 self.as_ref().to_glib_none().0, 342 appinfo2.as_ref().to_glib_none().0, 343 )) 344 } 345 } 346 commandline(&self) -> Option<std::path::PathBuf>347 fn commandline(&self) -> Option<std::path::PathBuf> { 348 unsafe { 349 from_glib_none(ffi::g_app_info_get_commandline( 350 self.as_ref().to_glib_none().0, 351 )) 352 } 353 } 354 description(&self) -> Option<glib::GString>355 fn description(&self) -> Option<glib::GString> { 356 unsafe { 357 from_glib_none(ffi::g_app_info_get_description( 358 self.as_ref().to_glib_none().0, 359 )) 360 } 361 } 362 display_name(&self) -> glib::GString363 fn display_name(&self) -> glib::GString { 364 unsafe { 365 from_glib_none(ffi::g_app_info_get_display_name( 366 self.as_ref().to_glib_none().0, 367 )) 368 } 369 } 370 executable(&self) -> std::path::PathBuf371 fn executable(&self) -> std::path::PathBuf { 372 unsafe { 373 from_glib_none(ffi::g_app_info_get_executable( 374 self.as_ref().to_glib_none().0, 375 )) 376 } 377 } 378 icon(&self) -> Option<Icon>379 fn icon(&self) -> Option<Icon> { 380 unsafe { from_glib_none(ffi::g_app_info_get_icon(self.as_ref().to_glib_none().0)) } 381 } 382 id(&self) -> Option<glib::GString>383 fn id(&self) -> Option<glib::GString> { 384 unsafe { from_glib_none(ffi::g_app_info_get_id(self.as_ref().to_glib_none().0)) } 385 } 386 name(&self) -> glib::GString387 fn name(&self) -> glib::GString { 388 unsafe { from_glib_none(ffi::g_app_info_get_name(self.as_ref().to_glib_none().0)) } 389 } 390 supported_types(&self) -> Vec<glib::GString>391 fn supported_types(&self) -> Vec<glib::GString> { 392 unsafe { 393 FromGlibPtrContainer::from_glib_none(ffi::g_app_info_get_supported_types( 394 self.as_ref().to_glib_none().0, 395 )) 396 } 397 } 398 launch<P: IsA<AppLaunchContext>>( &self, files: &[File], context: Option<&P>, ) -> Result<(), glib::Error>399 fn launch<P: IsA<AppLaunchContext>>( 400 &self, 401 files: &[File], 402 context: Option<&P>, 403 ) -> Result<(), glib::Error> { 404 unsafe { 405 let mut error = ptr::null_mut(); 406 let _ = ffi::g_app_info_launch( 407 self.as_ref().to_glib_none().0, 408 files.to_glib_none().0, 409 context.map(|p| p.as_ref()).to_glib_none().0, 410 &mut error, 411 ); 412 if error.is_null() { 413 Ok(()) 414 } else { 415 Err(from_glib_full(error)) 416 } 417 } 418 } 419 launch_uris<P: IsA<AppLaunchContext>>( &self, uris: &[&str], context: Option<&P>, ) -> Result<(), glib::Error>420 fn launch_uris<P: IsA<AppLaunchContext>>( 421 &self, 422 uris: &[&str], 423 context: Option<&P>, 424 ) -> Result<(), glib::Error> { 425 unsafe { 426 let mut error = ptr::null_mut(); 427 let _ = ffi::g_app_info_launch_uris( 428 self.as_ref().to_glib_none().0, 429 uris.to_glib_none().0, 430 context.map(|p| p.as_ref()).to_glib_none().0, 431 &mut error, 432 ); 433 if error.is_null() { 434 Ok(()) 435 } else { 436 Err(from_glib_full(error)) 437 } 438 } 439 } 440 remove_supports_type(&self, content_type: &str) -> Result<(), glib::Error>441 fn remove_supports_type(&self, content_type: &str) -> Result<(), glib::Error> { 442 unsafe { 443 let mut error = ptr::null_mut(); 444 let _ = ffi::g_app_info_remove_supports_type( 445 self.as_ref().to_glib_none().0, 446 content_type.to_glib_none().0, 447 &mut error, 448 ); 449 if error.is_null() { 450 Ok(()) 451 } else { 452 Err(from_glib_full(error)) 453 } 454 } 455 } 456 set_as_default_for_extension<P: AsRef<std::path::Path>>( &self, extension: P, ) -> Result<(), glib::Error>457 fn set_as_default_for_extension<P: AsRef<std::path::Path>>( 458 &self, 459 extension: P, 460 ) -> Result<(), glib::Error> { 461 unsafe { 462 let mut error = ptr::null_mut(); 463 let _ = ffi::g_app_info_set_as_default_for_extension( 464 self.as_ref().to_glib_none().0, 465 extension.as_ref().to_glib_none().0, 466 &mut error, 467 ); 468 if error.is_null() { 469 Ok(()) 470 } else { 471 Err(from_glib_full(error)) 472 } 473 } 474 } 475 set_as_default_for_type(&self, content_type: &str) -> Result<(), glib::Error>476 fn set_as_default_for_type(&self, content_type: &str) -> Result<(), glib::Error> { 477 unsafe { 478 let mut error = ptr::null_mut(); 479 let _ = ffi::g_app_info_set_as_default_for_type( 480 self.as_ref().to_glib_none().0, 481 content_type.to_glib_none().0, 482 &mut error, 483 ); 484 if error.is_null() { 485 Ok(()) 486 } else { 487 Err(from_glib_full(error)) 488 } 489 } 490 } 491 set_as_last_used_for_type(&self, content_type: &str) -> Result<(), glib::Error>492 fn set_as_last_used_for_type(&self, content_type: &str) -> Result<(), glib::Error> { 493 unsafe { 494 let mut error = ptr::null_mut(); 495 let _ = ffi::g_app_info_set_as_last_used_for_type( 496 self.as_ref().to_glib_none().0, 497 content_type.to_glib_none().0, 498 &mut error, 499 ); 500 if error.is_null() { 501 Ok(()) 502 } else { 503 Err(from_glib_full(error)) 504 } 505 } 506 } 507 should_show(&self) -> bool508 fn should_show(&self) -> bool { 509 unsafe { from_glib(ffi::g_app_info_should_show(self.as_ref().to_glib_none().0)) } 510 } 511 supports_files(&self) -> bool512 fn supports_files(&self) -> bool { 513 unsafe { 514 from_glib(ffi::g_app_info_supports_files( 515 self.as_ref().to_glib_none().0, 516 )) 517 } 518 } 519 supports_uris(&self) -> bool520 fn supports_uris(&self) -> bool { 521 unsafe { 522 from_glib(ffi::g_app_info_supports_uris( 523 self.as_ref().to_glib_none().0, 524 )) 525 } 526 } 527 } 528 529 impl fmt::Display for AppInfo { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result530 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 531 f.write_str("AppInfo") 532 } 533 } 534