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