gio/auto/app_info.rs
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
5use crate::{AppInfoCreateFlags, AppLaunchContext, AsyncResult, Cancellable, File, Icon, ffi};
6use glib::{prelude::*, translate::*};
7use std::{boxed::Box as Box_, pin::Pin};
8
9glib::wrapper! {
10 /// Information about an installed application and methods to launch
11 /// it (with file arguments).
12 ///
13 /// `GAppInfo` and `GAppLaunchContext` are used for describing and launching
14 /// applications installed on the system.
15 ///
16 /// As of GLib 2.20, URIs will always be converted to POSIX paths
17 /// (using [`FileExt::path()`][crate::prelude::FileExt::path()]) when using [`AppInfoExt::launch()`][crate::prelude::AppInfoExt::launch()]
18 /// even if the application requested an URI and not a POSIX path. For example
19 /// for a desktop-file based application with the following Exec key:
20 ///
21 /// ```text
22 /// Exec=totem %U
23 /// ```
24 ///
25 /// and a single URI, `sftp://foo/file.avi`, then
26 /// `/home/user/.gvfs/sftp on foo/file.avi` will be passed. This will only work
27 /// if a set of suitable GIO extensions (such as GVfs 2.26 compiled with FUSE
28 /// support), is available and operational; if this is not the case, the URI
29 /// will be passed unmodified to the application. Some URIs, such as `mailto:`,
30 /// of course cannot be mapped to a POSIX path (in GVfs there’s no FUSE mount
31 /// for it); such URIs will be passed unmodified to the application.
32 ///
33 /// Specifically for GVfs 2.26 and later, the POSIX URI will be mapped
34 /// back to the GIO URI in the [`File`][crate::File] constructors (since GVfs
35 /// implements the GVfs extension point). As such, if the application
36 /// needs to examine the URI, it needs to use [`FileExt::uri()`][crate::prelude::FileExt::uri()]
37 /// or similar on [`File`][crate::File]. In other words, an application cannot
38 /// assume that the URI passed to e.g. [`File::for_commandline_arg()`][crate::File::for_commandline_arg()]
39 /// is equal to the result of [`FileExt::uri()`][crate::prelude::FileExt::uri()]. The following snippet
40 /// illustrates this:
41 ///
42 /// **⚠️ The following code is in c ⚠️**
43 ///
44 /// ```c
45 /// GFile *f;
46 /// char *uri;
47 ///
48 /// file = g_file_new_for_commandline_arg (uri_from_commandline);
49 ///
50 /// uri = g_file_get_uri (file);
51 /// strcmp (uri, uri_from_commandline) == 0;
52 /// g_free (uri);
53 ///
54 /// if (g_file_has_uri_scheme (file, "cdda"))
55 /// {
56 /// // do something special with uri
57 /// }
58 /// g_object_unref (file);
59 /// ```
60 ///
61 /// This code will work when both `cdda://sr0/Track 1.wav` and
62 /// `/home/user/.gvfs/cdda on sr0/Track 1.wav` is passed to the
63 /// application. It should be noted that it’s generally not safe
64 /// for applications to rely on the format of a particular URIs.
65 /// Different launcher applications (e.g. file managers) may have
66 /// different ideas of what a given URI means.
67 ///
68 /// # Implements
69 ///
70 /// [`AppInfoExt`][trait@crate::prelude::AppInfoExt], [`AppInfoExtManual`][trait@crate::prelude::AppInfoExtManual]
71 #[doc(alias = "GAppInfo")]
72 pub struct AppInfo(Interface<ffi::GAppInfo, ffi::GAppInfoIface>);
73
74 match fn {
75 type_ => || ffi::g_app_info_get_type(),
76 }
77}
78
79impl AppInfo {
80 pub const NONE: Option<&'static AppInfo> = None;
81
82 /// Creates a new [`AppInfo`][crate::AppInfo] from the given information.
83 ///
84 /// When constructing @commandline, quote any filenames or potentially-
85 /// untrusted input using `shell_quote()`, and note that the
86 /// quoting rules of the `Exec` key of the
87 /// [freedesktop.org Desktop Entry Specification](http://freedesktop.org/Standards/desktop-entry-spec)
88 /// are applied. For example, if the @commandline contains
89 /// percent-encoded URIs, the percent-character must be doubled in order to prevent it from
90 /// being swallowed by `Exec` key unquoting. See
91 /// [the specification](https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s07.html)
92 /// for exact quoting rules.
93 /// ## `commandline`
94 /// the command line to use
95 /// ## `application_name`
96 /// the application name, or `NULL` to use @commandline
97 /// ## `flags`
98 /// flags that can specify details of the created [`AppInfo`][crate::AppInfo]
99 ///
100 /// # Returns
101 ///
102 /// new [`AppInfo`][crate::AppInfo] for given command.
103 #[doc(alias = "g_app_info_create_from_commandline")]
104 pub fn create_from_commandline(
105 commandline: impl AsRef<std::ffi::OsStr>,
106 application_name: Option<&str>,
107 flags: AppInfoCreateFlags,
108 ) -> Result<AppInfo, glib::Error> {
109 unsafe {
110 let mut error = std::ptr::null_mut();
111 let ret = ffi::g_app_info_create_from_commandline(
112 commandline.as_ref().to_glib_none().0,
113 application_name.to_glib_none().0,
114 flags.into_glib(),
115 &mut error,
116 );
117 if error.is_null() {
118 Ok(from_glib_full(ret))
119 } else {
120 Err(from_glib_full(error))
121 }
122 }
123 }
124
125 /// Gets a list of all of the applications currently registered
126 /// on this system.
127 ///
128 /// For desktop files, this includes applications that have
129 /// [`NoDisplay=true`](https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s06.html#key-nodisplay)
130 /// set or are excluded from display by means of
131 /// [`OnlyShowIn`](https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s06.html#key-onlyshowin)
132 /// or [`NotShowIn`](https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s06.html#key-notshowin).
133 /// See [`AppInfoExt::should_show()`][crate::prelude::AppInfoExt::should_show()].
134 ///
135 /// The returned list does not include applications which have the
136 /// [`Hidden` key](https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s06.html#key-hidden)
137 /// set.
138 ///
139 /// # Returns
140 ///
141 /// a newly allocated
142 /// list of references to [`AppInfo`][crate::AppInfo]s.
143 #[doc(alias = "g_app_info_get_all")]
144 #[doc(alias = "get_all")]
145 pub fn all() -> Vec<AppInfo> {
146 unsafe { FromGlibPtrContainer::from_glib_full(ffi::g_app_info_get_all()) }
147 }
148
149 /// Gets a list of all [`AppInfo`][crate::AppInfo]s for a given content type,
150 /// including the recommended and fallback [`AppInfo`][crate::AppInfo]s. See
151 /// [`recommended_for_type()`][Self::recommended_for_type()] and
152 /// [`fallback_for_type()`][Self::fallback_for_type()].
153 /// ## `content_type`
154 /// the content type to find a [`AppInfo`][crate::AppInfo] for
155 ///
156 /// # Returns
157 ///
158 /// list of
159 /// [`AppInfo`][crate::AppInfo]s for given @content_type.
160 #[doc(alias = "g_app_info_get_all_for_type")]
161 #[doc(alias = "get_all_for_type")]
162 pub fn all_for_type(content_type: &str) -> Vec<AppInfo> {
163 unsafe {
164 FromGlibPtrContainer::from_glib_full(ffi::g_app_info_get_all_for_type(
165 content_type.to_glib_none().0,
166 ))
167 }
168 }
169
170 /// Gets the default [`AppInfo`][crate::AppInfo] for a given content type.
171 /// ## `content_type`
172 /// the content type to find a [`AppInfo`][crate::AppInfo] for
173 /// ## `must_support_uris`
174 /// if `TRUE`, the [`AppInfo`][crate::AppInfo] is expected to
175 /// support URIs
176 ///
177 /// # Returns
178 ///
179 /// [`AppInfo`][crate::AppInfo] for given
180 /// @content_type or `NULL` on error.
181 #[doc(alias = "g_app_info_get_default_for_type")]
182 #[doc(alias = "get_default_for_type")]
183 pub fn default_for_type(content_type: &str, must_support_uris: bool) -> Option<AppInfo> {
184 unsafe {
185 from_glib_full(ffi::g_app_info_get_default_for_type(
186 content_type.to_glib_none().0,
187 must_support_uris.into_glib(),
188 ))
189 }
190 }
191
192 /// Asynchronously gets the default [`AppInfo`][crate::AppInfo] for a given content
193 /// type.
194 /// ## `content_type`
195 /// the content type to find a [`AppInfo`][crate::AppInfo] for
196 /// ## `must_support_uris`
197 /// if `TRUE`, the [`AppInfo`][crate::AppInfo] is expected to
198 /// support URIs
199 /// ## `cancellable`
200 /// a [`Cancellable`][crate::Cancellable]
201 /// ## `callback`
202 /// a [type@Gio.AsyncReadyCallback] to call
203 /// when the request is done
204 #[cfg(feature = "v2_74")]
205 #[cfg_attr(docsrs, doc(cfg(feature = "v2_74")))]
206 #[doc(alias = "g_app_info_get_default_for_type_async")]
207 #[doc(alias = "get_default_for_type_async")]
208 pub fn default_for_type_async<P: FnOnce(Result<AppInfo, glib::Error>) + 'static>(
209 content_type: &str,
210 must_support_uris: bool,
211 cancellable: Option<&impl IsA<Cancellable>>,
212 callback: P,
213 ) {
214 let main_context = glib::MainContext::ref_thread_default();
215 let is_main_context_owner = main_context.is_owner();
216 let has_acquired_main_context = (!is_main_context_owner)
217 .then(|| main_context.acquire().ok())
218 .flatten();
219 assert!(
220 is_main_context_owner || has_acquired_main_context.is_some(),
221 "Async operations only allowed if the thread is owning the MainContext"
222 );
223
224 let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
225 Box_::new(glib::thread_guard::ThreadGuard::new(callback));
226 unsafe extern "C" fn default_for_type_async_trampoline<
227 P: FnOnce(Result<AppInfo, glib::Error>) + 'static,
228 >(
229 _source_object: *mut glib::gobject_ffi::GObject,
230 res: *mut crate::ffi::GAsyncResult,
231 user_data: glib::ffi::gpointer,
232 ) {
233 unsafe {
234 let mut error = std::ptr::null_mut();
235 let ret = ffi::g_app_info_get_default_for_type_finish(res, &mut error);
236 let result = if error.is_null() {
237 Ok(from_glib_full(ret))
238 } else {
239 Err(from_glib_full(error))
240 };
241 let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
242 Box_::from_raw(user_data as *mut _);
243 let callback: P = callback.into_inner();
244 callback(result);
245 }
246 }
247 let callback = default_for_type_async_trampoline::<P>;
248 unsafe {
249 ffi::g_app_info_get_default_for_type_async(
250 content_type.to_glib_none().0,
251 must_support_uris.into_glib(),
252 cancellable.map(|p| p.as_ref()).to_glib_none().0,
253 Some(callback),
254 Box_::into_raw(user_data) as *mut _,
255 );
256 }
257 }
258
259 #[cfg(feature = "v2_74")]
260 #[cfg_attr(docsrs, doc(cfg(feature = "v2_74")))]
261 pub fn default_for_type_future(
262 content_type: &str,
263 must_support_uris: bool,
264 ) -> Pin<Box_<dyn std::future::Future<Output = Result<AppInfo, glib::Error>> + 'static>> {
265 let content_type = String::from(content_type);
266 Box_::pin(crate::GioFuture::new(
267 &(),
268 move |_obj, cancellable, send| {
269 Self::default_for_type_async(
270 &content_type,
271 must_support_uris,
272 Some(cancellable),
273 move |res| {
274 send.resolve(res);
275 },
276 );
277 },
278 ))
279 }
280
281 /// Gets the default application for handling URIs with the given URI scheme.
282 ///
283 /// A URI scheme is the initial part of the URI, up to but not including the `:`.
284 /// For example, `http`, `ftp` or `sip`.
285 /// ## `uri_scheme`
286 /// a string containing a URI scheme.
287 ///
288 /// # Returns
289 ///
290 /// [`AppInfo`][crate::AppInfo] for given
291 /// @uri_scheme or `NULL` on error.
292 #[doc(alias = "g_app_info_get_default_for_uri_scheme")]
293 #[doc(alias = "get_default_for_uri_scheme")]
294 pub fn default_for_uri_scheme(uri_scheme: &str) -> Option<AppInfo> {
295 unsafe {
296 from_glib_full(ffi::g_app_info_get_default_for_uri_scheme(
297 uri_scheme.to_glib_none().0,
298 ))
299 }
300 }
301
302 /// Asynchronously gets the default application for handling URIs with
303 /// the given URI scheme. A URI scheme is the initial part
304 /// of the URI, up to but not including the `:`, e.g. `http`,
305 /// `ftp` or `sip`.
306 /// ## `uri_scheme`
307 /// a string containing a URI scheme.
308 /// ## `cancellable`
309 /// a [`Cancellable`][crate::Cancellable]
310 /// ## `callback`
311 /// a [type@Gio.AsyncReadyCallback] to call
312 /// when the request is done
313 #[cfg(feature = "v2_74")]
314 #[cfg_attr(docsrs, doc(cfg(feature = "v2_74")))]
315 #[doc(alias = "g_app_info_get_default_for_uri_scheme_async")]
316 #[doc(alias = "get_default_for_uri_scheme_async")]
317 pub fn default_for_uri_scheme_async<P: FnOnce(Result<AppInfo, glib::Error>) + 'static>(
318 uri_scheme: &str,
319 cancellable: Option<&impl IsA<Cancellable>>,
320 callback: P,
321 ) {
322 let main_context = glib::MainContext::ref_thread_default();
323 let is_main_context_owner = main_context.is_owner();
324 let has_acquired_main_context = (!is_main_context_owner)
325 .then(|| main_context.acquire().ok())
326 .flatten();
327 assert!(
328 is_main_context_owner || has_acquired_main_context.is_some(),
329 "Async operations only allowed if the thread is owning the MainContext"
330 );
331
332 let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
333 Box_::new(glib::thread_guard::ThreadGuard::new(callback));
334 unsafe extern "C" fn default_for_uri_scheme_async_trampoline<
335 P: FnOnce(Result<AppInfo, glib::Error>) + 'static,
336 >(
337 _source_object: *mut glib::gobject_ffi::GObject,
338 res: *mut crate::ffi::GAsyncResult,
339 user_data: glib::ffi::gpointer,
340 ) {
341 unsafe {
342 let mut error = std::ptr::null_mut();
343 let ret = ffi::g_app_info_get_default_for_uri_scheme_finish(res, &mut error);
344 let result = if error.is_null() {
345 Ok(from_glib_full(ret))
346 } else {
347 Err(from_glib_full(error))
348 };
349 let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
350 Box_::from_raw(user_data as *mut _);
351 let callback: P = callback.into_inner();
352 callback(result);
353 }
354 }
355 let callback = default_for_uri_scheme_async_trampoline::<P>;
356 unsafe {
357 ffi::g_app_info_get_default_for_uri_scheme_async(
358 uri_scheme.to_glib_none().0,
359 cancellable.map(|p| p.as_ref()).to_glib_none().0,
360 Some(callback),
361 Box_::into_raw(user_data) as *mut _,
362 );
363 }
364 }
365
366 #[cfg(feature = "v2_74")]
367 #[cfg_attr(docsrs, doc(cfg(feature = "v2_74")))]
368 pub fn default_for_uri_scheme_future(
369 uri_scheme: &str,
370 ) -> Pin<Box_<dyn std::future::Future<Output = Result<AppInfo, glib::Error>> + 'static>> {
371 let uri_scheme = String::from(uri_scheme);
372 Box_::pin(crate::GioFuture::new(
373 &(),
374 move |_obj, cancellable, send| {
375 Self::default_for_uri_scheme_async(&uri_scheme, Some(cancellable), move |res| {
376 send.resolve(res);
377 });
378 },
379 ))
380 }
381
382 /// Gets a list of fallback [`AppInfo`][crate::AppInfo]s for a given content type, i.e.
383 /// those applications which claim to support the given content type by MIME
384 /// type subclassing and not directly.
385 /// ## `content_type`
386 /// the content type to find a [`AppInfo`][crate::AppInfo] for
387 ///
388 /// # Returns
389 ///
390 /// list of [`AppInfo`][crate::AppInfo]s
391 /// for given @content_type or `NULL` on error.
392 #[doc(alias = "g_app_info_get_fallback_for_type")]
393 #[doc(alias = "get_fallback_for_type")]
394 pub fn fallback_for_type(content_type: &str) -> Vec<AppInfo> {
395 unsafe {
396 FromGlibPtrContainer::from_glib_full(ffi::g_app_info_get_fallback_for_type(
397 content_type.to_glib_none().0,
398 ))
399 }
400 }
401
402 /// Gets a list of recommended [`AppInfo`][crate::AppInfo]s for a given content type,
403 /// i.e. those applications which claim to support the given content type
404 /// exactly, and not by MIME type subclassing.
405 ///
406 /// Note that the first application of the list is the last used one, i.e.
407 /// the last one for which [`AppInfoExt::set_as_last_used_for_type()`][crate::prelude::AppInfoExt::set_as_last_used_for_type()] has
408 /// been called.
409 /// ## `content_type`
410 /// the content type to find a [`AppInfo`][crate::AppInfo] for
411 ///
412 /// # Returns
413 ///
414 /// list of
415 /// [`AppInfo`][crate::AppInfo]s for given @content_type or `NULL` on error.
416 #[doc(alias = "g_app_info_get_recommended_for_type")]
417 #[doc(alias = "get_recommended_for_type")]
418 pub fn recommended_for_type(content_type: &str) -> Vec<AppInfo> {
419 unsafe {
420 FromGlibPtrContainer::from_glib_full(ffi::g_app_info_get_recommended_for_type(
421 content_type.to_glib_none().0,
422 ))
423 }
424 }
425
426 /// Utility function that launches the default application registered to handle
427 /// the specified uri. Synchronous I/O is done on the uri to detect the type of
428 /// the file if required.
429 ///
430 /// The D-Bus–activated applications don’t have to be started if your application
431 /// terminates too soon after this function. To prevent this, use
432 /// [`launch_default_for_uri_async()`][Self::launch_default_for_uri_async()] instead.
433 /// ## `uri`
434 /// the uri to show
435 /// ## `context`
436 /// optional launch context
437 ///
438 /// # Returns
439 ///
440 /// `TRUE` on success, `FALSE` on error.
441 #[doc(alias = "g_app_info_launch_default_for_uri")]
442 pub fn launch_default_for_uri(
443 uri: &str,
444 context: Option<&impl IsA<AppLaunchContext>>,
445 ) -> Result<(), glib::Error> {
446 unsafe {
447 let mut error = std::ptr::null_mut();
448 let is_ok = ffi::g_app_info_launch_default_for_uri(
449 uri.to_glib_none().0,
450 context.map(|p| p.as_ref()).to_glib_none().0,
451 &mut error,
452 );
453 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
454 if error.is_null() {
455 Ok(())
456 } else {
457 Err(from_glib_full(error))
458 }
459 }
460 }
461
462 /// Async version of [`launch_default_for_uri()`][Self::launch_default_for_uri()].
463 ///
464 /// This version is useful if you are interested in receiving error information
465 /// in the case where the application is sandboxed and the portal may present an
466 /// application chooser dialog to the user.
467 ///
468 /// This is also useful if you want to be sure that the D-Bus–activated
469 /// applications are really started before termination and if you are interested
470 /// in receiving error information from their activation.
471 /// ## `uri`
472 /// the uri to show
473 /// ## `context`
474 /// optional launch context
475 /// ## `cancellable`
476 /// a [`Cancellable`][crate::Cancellable]
477 /// ## `callback`
478 /// a [type@Gio.AsyncReadyCallback] to call
479 /// when the request is done
480 #[doc(alias = "g_app_info_launch_default_for_uri_async")]
481 pub fn launch_default_for_uri_async<P: FnOnce(Result<(), glib::Error>) + 'static>(
482 uri: &str,
483 context: Option<&impl IsA<AppLaunchContext>>,
484 cancellable: Option<&impl IsA<Cancellable>>,
485 callback: P,
486 ) {
487 let main_context = glib::MainContext::ref_thread_default();
488 let is_main_context_owner = main_context.is_owner();
489 let has_acquired_main_context = (!is_main_context_owner)
490 .then(|| main_context.acquire().ok())
491 .flatten();
492 assert!(
493 is_main_context_owner || has_acquired_main_context.is_some(),
494 "Async operations only allowed if the thread is owning the MainContext"
495 );
496
497 let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
498 Box_::new(glib::thread_guard::ThreadGuard::new(callback));
499 unsafe extern "C" fn launch_default_for_uri_async_trampoline<
500 P: FnOnce(Result<(), glib::Error>) + 'static,
501 >(
502 _source_object: *mut glib::gobject_ffi::GObject,
503 res: *mut crate::ffi::GAsyncResult,
504 user_data: glib::ffi::gpointer,
505 ) {
506 unsafe {
507 let mut error = std::ptr::null_mut();
508 ffi::g_app_info_launch_default_for_uri_finish(res, &mut error);
509 let result = if error.is_null() {
510 Ok(())
511 } else {
512 Err(from_glib_full(error))
513 };
514 let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
515 Box_::from_raw(user_data as *mut _);
516 let callback: P = callback.into_inner();
517 callback(result);
518 }
519 }
520 let callback = launch_default_for_uri_async_trampoline::<P>;
521 unsafe {
522 ffi::g_app_info_launch_default_for_uri_async(
523 uri.to_glib_none().0,
524 context.map(|p| p.as_ref()).to_glib_none().0,
525 cancellable.map(|p| p.as_ref()).to_glib_none().0,
526 Some(callback),
527 Box_::into_raw(user_data) as *mut _,
528 );
529 }
530 }
531
532 pub fn launch_default_for_uri_future(
533 uri: &str,
534 context: Option<&(impl IsA<AppLaunchContext> + Clone + 'static)>,
535 ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
536 let uri = String::from(uri);
537 let context = context.map(ToOwned::to_owned);
538 Box_::pin(crate::GioFuture::new(
539 &(),
540 move |_obj, cancellable, send| {
541 Self::launch_default_for_uri_async(
542 &uri,
543 context.as_ref().map(::std::borrow::Borrow::borrow),
544 Some(cancellable),
545 move |res| {
546 send.resolve(res);
547 },
548 );
549 },
550 ))
551 }
552
553 /// Removes all changes to the type associations done by
554 /// [`AppInfoExt::set_as_default_for_type()`][crate::prelude::AppInfoExt::set_as_default_for_type()],
555 /// [`AppInfoExt::set_as_default_for_extension()`][crate::prelude::AppInfoExt::set_as_default_for_extension()],
556 /// [`AppInfoExt::add_supports_type()`][crate::prelude::AppInfoExt::add_supports_type()] or
557 /// [`AppInfoExt::remove_supports_type()`][crate::prelude::AppInfoExt::remove_supports_type()].
558 /// ## `content_type`
559 /// a content type
560 #[doc(alias = "g_app_info_reset_type_associations")]
561 pub fn reset_type_associations(content_type: &str) {
562 unsafe {
563 ffi::g_app_info_reset_type_associations(content_type.to_glib_none().0);
564 }
565 }
566}
567
568/// Trait containing all [`struct@AppInfo`] methods.
569///
570/// # Implementors
571///
572/// [`AppInfo`][struct@crate::AppInfo]
573pub trait AppInfoExt: IsA<AppInfo> + 'static {
574 /// Adds a content type to the application information to indicate the
575 /// application is capable of opening files with the given content type.
576 /// ## `content_type`
577 /// a string.
578 ///
579 /// # Returns
580 ///
581 /// `TRUE` on success, `FALSE` on error.
582 #[doc(alias = "g_app_info_add_supports_type")]
583 fn add_supports_type(&self, content_type: &str) -> Result<(), glib::Error> {
584 unsafe {
585 let mut error = std::ptr::null_mut();
586 let is_ok = ffi::g_app_info_add_supports_type(
587 self.as_ref().to_glib_none().0,
588 content_type.to_glib_none().0,
589 &mut error,
590 );
591 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
592 if error.is_null() {
593 Ok(())
594 } else {
595 Err(from_glib_full(error))
596 }
597 }
598 }
599
600 /// Obtains the information whether the [`AppInfo`][crate::AppInfo] can be deleted.
601 /// See [`delete()`][Self::delete()].
602 ///
603 /// # Returns
604 ///
605 /// `TRUE` if @self can be deleted
606 #[doc(alias = "g_app_info_can_delete")]
607 fn can_delete(&self) -> bool {
608 unsafe { from_glib(ffi::g_app_info_can_delete(self.as_ref().to_glib_none().0)) }
609 }
610
611 /// Checks if a supported content type can be removed from an application.
612 ///
613 /// # Returns
614 ///
615 /// `TRUE` if it is possible to remove supported content types from a
616 /// given @self, `FALSE` if not.
617 #[doc(alias = "g_app_info_can_remove_supports_type")]
618 fn can_remove_supports_type(&self) -> bool {
619 unsafe {
620 from_glib(ffi::g_app_info_can_remove_supports_type(
621 self.as_ref().to_glib_none().0,
622 ))
623 }
624 }
625
626 /// Tries to delete a [`AppInfo`][crate::AppInfo].
627 ///
628 /// On some platforms, there may be a difference between user-defined
629 /// [`AppInfo`][crate::AppInfo]s which can be deleted, and system-wide ones which cannot.
630 /// See [`can_delete()`][Self::can_delete()].
631 ///
632 /// # Returns
633 ///
634 /// `TRUE` if @self has been deleted
635 #[doc(alias = "g_app_info_delete")]
636 fn delete(&self) -> bool {
637 unsafe { from_glib(ffi::g_app_info_delete(self.as_ref().to_glib_none().0)) }
638 }
639
640 /// Creates a duplicate of a [`AppInfo`][crate::AppInfo].
641 ///
642 /// # Returns
643 ///
644 /// a duplicate of @self.
645 #[doc(alias = "g_app_info_dup")]
646 #[must_use]
647 fn dup(&self) -> AppInfo {
648 unsafe { from_glib_full(ffi::g_app_info_dup(self.as_ref().to_glib_none().0)) }
649 }
650
651 #[doc(alias = "g_app_info_equal")]
652 fn equal(&self, appinfo2: &impl IsA<AppInfo>) -> bool {
653 unsafe {
654 from_glib(ffi::g_app_info_equal(
655 self.as_ref().to_glib_none().0,
656 appinfo2.as_ref().to_glib_none().0,
657 ))
658 }
659 }
660
661 /// Gets the commandline with which the application will be
662 /// started.
663 ///
664 /// # Returns
665 ///
666 /// a string containing the @self’s
667 /// commandline, or `NULL` if this information is not available
668 #[doc(alias = "g_app_info_get_commandline")]
669 #[doc(alias = "get_commandline")]
670 fn commandline(&self) -> Option<std::path::PathBuf> {
671 unsafe {
672 from_glib_none(ffi::g_app_info_get_commandline(
673 self.as_ref().to_glib_none().0,
674 ))
675 }
676 }
677
678 /// Gets a human-readable description of an installed application.
679 ///
680 /// # Returns
681 ///
682 /// a string containing a description of the
683 /// application @self, or `NULL` if none.
684 #[doc(alias = "g_app_info_get_description")]
685 #[doc(alias = "get_description")]
686 fn description(&self) -> Option<glib::GString> {
687 unsafe {
688 from_glib_none(ffi::g_app_info_get_description(
689 self.as_ref().to_glib_none().0,
690 ))
691 }
692 }
693
694 /// Gets the display name of the application. The display name is often more
695 /// descriptive to the user than the name itself.
696 ///
697 /// # Returns
698 ///
699 /// the display name of the application for @self, or the name if
700 /// no display name is available.
701 #[doc(alias = "g_app_info_get_display_name")]
702 #[doc(alias = "get_display_name")]
703 fn display_name(&self) -> glib::GString {
704 unsafe {
705 from_glib_none(ffi::g_app_info_get_display_name(
706 self.as_ref().to_glib_none().0,
707 ))
708 }
709 }
710
711 /// Gets the executable’s name for the installed application.
712 ///
713 /// This is intended to be used for debugging or labelling what program is going
714 /// to be run. To launch the executable, use [`launch()`][Self::launch()] and related
715 /// functions, rather than spawning the return value from this function.
716 ///
717 /// # Returns
718 ///
719 /// a string containing the @self’s application
720 /// binaries name
721 #[doc(alias = "g_app_info_get_executable")]
722 #[doc(alias = "get_executable")]
723 fn executable(&self) -> std::path::PathBuf {
724 unsafe {
725 from_glib_none(ffi::g_app_info_get_executable(
726 self.as_ref().to_glib_none().0,
727 ))
728 }
729 }
730
731 /// Gets the icon for the application.
732 ///
733 /// # Returns
734 ///
735 /// the default [`Icon`][crate::Icon] for
736 /// @self or `NULL` if there is no default icon.
737 #[doc(alias = "g_app_info_get_icon")]
738 #[doc(alias = "get_icon")]
739 fn icon(&self) -> Option<Icon> {
740 unsafe { from_glib_none(ffi::g_app_info_get_icon(self.as_ref().to_glib_none().0)) }
741 }
742
743 /// Gets the ID of an application. An id is a string that identifies the
744 /// application. The exact format of the id is platform dependent. For instance,
745 /// on Unix this is the desktop file id from the xdg menu specification.
746 ///
747 /// Note that the returned ID may be `NULL`, depending on how the @self has
748 /// been constructed.
749 ///
750 /// # Returns
751 ///
752 /// a string containing the application’s ID.
753 #[doc(alias = "g_app_info_get_id")]
754 #[doc(alias = "get_id")]
755 fn id(&self) -> Option<glib::GString> {
756 unsafe { from_glib_none(ffi::g_app_info_get_id(self.as_ref().to_glib_none().0)) }
757 }
758
759 /// Gets the installed name of the application.
760 ///
761 /// # Returns
762 ///
763 /// the name of the application for @self.
764 #[doc(alias = "g_app_info_get_name")]
765 #[doc(alias = "get_name")]
766 fn name(&self) -> glib::GString {
767 unsafe { from_glib_none(ffi::g_app_info_get_name(self.as_ref().to_glib_none().0)) }
768 }
769
770 /// Retrieves the list of content types that @app_info claims to support.
771 /// If this information is not provided by the environment, this function
772 /// will return `NULL`.
773 ///
774 /// This function does not take in consideration associations added with
775 /// [`add_supports_type()`][Self::add_supports_type()], but only those exported directly by
776 /// the application.
777 ///
778 /// # Returns
779 ///
780 ///
781 /// a list of content types.
782 #[doc(alias = "g_app_info_get_supported_types")]
783 #[doc(alias = "get_supported_types")]
784 fn supported_types(&self) -> Vec<glib::GString> {
785 unsafe {
786 FromGlibPtrContainer::from_glib_none(ffi::g_app_info_get_supported_types(
787 self.as_ref().to_glib_none().0,
788 ))
789 }
790 }
791
792 /// Launches the application. Passes @files to the launched application
793 /// as arguments, using the optional @context to get information
794 /// about the details of the launcher (like what screen it is on).
795 /// On error, @error will be set accordingly.
796 ///
797 /// To launch the application without arguments pass a `NULL` @files list.
798 ///
799 /// Note that even if the launch is successful the application launched
800 /// can fail to start if it runs into problems during startup. There is
801 /// no way to detect this.
802 ///
803 /// Some URIs can be changed when passed through a GFile (for instance
804 /// unsupported URIs with strange formats like mailto:), so if you have
805 /// a textual URI you want to pass in as argument, consider using
806 /// [`launch_uris()`][Self::launch_uris()] instead.
807 ///
808 /// The launched application inherits the environment of the launching
809 /// process, but it can be modified with [`AppLaunchContextExt::setenv()`][crate::prelude::AppLaunchContextExt::setenv()]
810 /// and [`AppLaunchContextExt::unsetenv()`][crate::prelude::AppLaunchContextExt::unsetenv()].
811 ///
812 /// On UNIX, this function sets the `GIO_LAUNCHED_DESKTOP_FILE`
813 /// environment variable with the path of the launched desktop file and
814 /// `GIO_LAUNCHED_DESKTOP_FILE_PID` to the process id of the launched
815 /// process. This can be used to ignore `GIO_LAUNCHED_DESKTOP_FILE`,
816 /// should it be inherited by further processes. The `DISPLAY`,
817 /// `XDG_ACTIVATION_TOKEN` and `DESKTOP_STARTUP_ID` environment
818 /// variables are also set, based on information provided in @context.
819 /// ## `files`
820 /// a list of [`File`][crate::File] objects
821 /// ## `context`
822 /// the launch context
823 ///
824 /// # Returns
825 ///
826 /// `TRUE` on successful launch, `FALSE` otherwise.
827 #[doc(alias = "g_app_info_launch")]
828 fn launch(
829 &self,
830 files: &[File],
831 context: Option<&impl IsA<AppLaunchContext>>,
832 ) -> Result<(), glib::Error> {
833 unsafe {
834 let mut error = std::ptr::null_mut();
835 let is_ok = ffi::g_app_info_launch(
836 self.as_ref().to_glib_none().0,
837 files.to_glib_none().0,
838 context.map(|p| p.as_ref()).to_glib_none().0,
839 &mut error,
840 );
841 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
842 if error.is_null() {
843 Ok(())
844 } else {
845 Err(from_glib_full(error))
846 }
847 }
848 }
849
850 /// Launches the application. This passes the @uris to the launched application
851 /// as arguments, using the optional @context to get information
852 /// about the details of the launcher (like what screen it is on).
853 /// On error, @error will be set accordingly. If the application only supports
854 /// one URI per invocation as part of their command-line, multiple instances
855 /// of the application will be spawned.
856 ///
857 /// To launch the application without arguments pass a `NULL` @uris list.
858 ///
859 /// Note that even if the launch is successful the application launched
860 /// can fail to start if it runs into problems during startup. There is
861 /// no way to detect this.
862 /// ## `uris`
863 /// a list of URIs to launch.
864 /// ## `context`
865 /// the launch context
866 ///
867 /// # Returns
868 ///
869 /// `TRUE` on successful launch, `FALSE` otherwise.
870 #[doc(alias = "g_app_info_launch_uris")]
871 fn launch_uris(
872 &self,
873 uris: &[&str],
874 context: Option<&impl IsA<AppLaunchContext>>,
875 ) -> Result<(), glib::Error> {
876 unsafe {
877 let mut error = std::ptr::null_mut();
878 let is_ok = ffi::g_app_info_launch_uris(
879 self.as_ref().to_glib_none().0,
880 uris.to_glib_none().0,
881 context.map(|p| p.as_ref()).to_glib_none().0,
882 &mut error,
883 );
884 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
885 if error.is_null() {
886 Ok(())
887 } else {
888 Err(from_glib_full(error))
889 }
890 }
891 }
892
893 /// Removes a supported type from an application, if possible.
894 /// ## `content_type`
895 /// a string.
896 ///
897 /// # Returns
898 ///
899 /// `TRUE` on success, `FALSE` on error.
900 #[doc(alias = "g_app_info_remove_supports_type")]
901 fn remove_supports_type(&self, content_type: &str) -> Result<(), glib::Error> {
902 unsafe {
903 let mut error = std::ptr::null_mut();
904 let is_ok = ffi::g_app_info_remove_supports_type(
905 self.as_ref().to_glib_none().0,
906 content_type.to_glib_none().0,
907 &mut error,
908 );
909 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
910 if error.is_null() {
911 Ok(())
912 } else {
913 Err(from_glib_full(error))
914 }
915 }
916 }
917
918 /// Sets the application as the default handler for the given file extension.
919 /// ## `extension`
920 /// a string containing the file extension (without
921 /// the dot).
922 ///
923 /// # Returns
924 ///
925 /// `TRUE` on success, `FALSE` on error.
926 #[doc(alias = "g_app_info_set_as_default_for_extension")]
927 fn set_as_default_for_extension(
928 &self,
929 extension: impl AsRef<std::path::Path>,
930 ) -> Result<(), glib::Error> {
931 unsafe {
932 let mut error = std::ptr::null_mut();
933 let is_ok = ffi::g_app_info_set_as_default_for_extension(
934 self.as_ref().to_glib_none().0,
935 extension.as_ref().to_glib_none().0,
936 &mut error,
937 );
938 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
939 if error.is_null() {
940 Ok(())
941 } else {
942 Err(from_glib_full(error))
943 }
944 }
945 }
946
947 /// Sets the application as the default handler for a given type.
948 /// ## `content_type`
949 /// the content type.
950 ///
951 /// # Returns
952 ///
953 /// `TRUE` on success, `FALSE` on error.
954 #[doc(alias = "g_app_info_set_as_default_for_type")]
955 fn set_as_default_for_type(&self, content_type: &str) -> Result<(), glib::Error> {
956 unsafe {
957 let mut error = std::ptr::null_mut();
958 let is_ok = ffi::g_app_info_set_as_default_for_type(
959 self.as_ref().to_glib_none().0,
960 content_type.to_glib_none().0,
961 &mut error,
962 );
963 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
964 if error.is_null() {
965 Ok(())
966 } else {
967 Err(from_glib_full(error))
968 }
969 }
970 }
971
972 /// Sets the application as the last used application for a given type. This
973 /// will make the application appear as first in the list returned by
974 /// [`AppInfo::recommended_for_type()`][crate::AppInfo::recommended_for_type()], regardless of the default
975 /// application for that content type.
976 /// ## `content_type`
977 /// the content type.
978 ///
979 /// # Returns
980 ///
981 /// `TRUE` on success, `FALSE` on error.
982 #[doc(alias = "g_app_info_set_as_last_used_for_type")]
983 fn set_as_last_used_for_type(&self, content_type: &str) -> Result<(), glib::Error> {
984 unsafe {
985 let mut error = std::ptr::null_mut();
986 let is_ok = ffi::g_app_info_set_as_last_used_for_type(
987 self.as_ref().to_glib_none().0,
988 content_type.to_glib_none().0,
989 &mut error,
990 );
991 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
992 if error.is_null() {
993 Ok(())
994 } else {
995 Err(from_glib_full(error))
996 }
997 }
998 }
999
1000 /// Checks if the application info should be shown in menus that
1001 /// list available applications.
1002 ///
1003 /// # Returns
1004 ///
1005 /// `TRUE` if the @self should be shown, `FALSE` otherwise.
1006 #[doc(alias = "g_app_info_should_show")]
1007 fn should_show(&self) -> bool {
1008 unsafe { from_glib(ffi::g_app_info_should_show(self.as_ref().to_glib_none().0)) }
1009 }
1010
1011 /// Checks if the application accepts files as arguments.
1012 ///
1013 /// # Returns
1014 ///
1015 /// `TRUE` if the @self supports files.
1016 #[doc(alias = "g_app_info_supports_files")]
1017 fn supports_files(&self) -> bool {
1018 unsafe {
1019 from_glib(ffi::g_app_info_supports_files(
1020 self.as_ref().to_glib_none().0,
1021 ))
1022 }
1023 }
1024
1025 /// Checks if the application supports reading files and directories from URIs.
1026 ///
1027 /// # Returns
1028 ///
1029 /// `TRUE` if the @self supports URIs.
1030 #[doc(alias = "g_app_info_supports_uris")]
1031 fn supports_uris(&self) -> bool {
1032 unsafe {
1033 from_glib(ffi::g_app_info_supports_uris(
1034 self.as_ref().to_glib_none().0,
1035 ))
1036 }
1037 }
1038}
1039
1040impl<O: IsA<AppInfo>> AppInfoExt for O {}