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            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
560/// Trait containing all [`struct@AppInfo`] methods.
561///
562/// # Implementors
563///
564/// [`AppInfo`][struct@crate::AppInfo], [`DesktopAppInfo`][struct@crate::DesktopAppInfo]
565pub trait AppInfoExt: IsA<AppInfo> + 'static {
566    /// Adds a content type to the application information to indicate the
567    /// application is capable of opening files with the given content type.
568    /// ## `content_type`
569    /// a string.
570    ///
571    /// # Returns
572    ///
573    /// `TRUE` on success, `FALSE` on error.
574    #[doc(alias = "g_app_info_add_supports_type")]
575    fn add_supports_type(&self, content_type: &str) -> Result<(), glib::Error> {
576        unsafe {
577            let mut error = std::ptr::null_mut();
578            let is_ok = ffi::g_app_info_add_supports_type(
579                self.as_ref().to_glib_none().0,
580                content_type.to_glib_none().0,
581                &mut error,
582            );
583            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
584            if error.is_null() {
585                Ok(())
586            } else {
587                Err(from_glib_full(error))
588            }
589        }
590    }
591
592    /// Obtains the information whether the [`AppInfo`][crate::AppInfo] can be deleted.
593    /// See [`delete()`][Self::delete()].
594    ///
595    /// # Returns
596    ///
597    /// `TRUE` if @self can be deleted
598    #[doc(alias = "g_app_info_can_delete")]
599    fn can_delete(&self) -> bool {
600        unsafe { from_glib(ffi::g_app_info_can_delete(self.as_ref().to_glib_none().0)) }
601    }
602
603    /// Checks if a supported content type can be removed from an application.
604    ///
605    /// # Returns
606    ///
607    /// `TRUE` if it is possible to remove supported content types from a
608    ///   given @self, `FALSE` if not.
609    #[doc(alias = "g_app_info_can_remove_supports_type")]
610    fn can_remove_supports_type(&self) -> bool {
611        unsafe {
612            from_glib(ffi::g_app_info_can_remove_supports_type(
613                self.as_ref().to_glib_none().0,
614            ))
615        }
616    }
617
618    /// Tries to delete a [`AppInfo`][crate::AppInfo].
619    ///
620    /// On some platforms, there may be a difference between user-defined
621    /// [`AppInfo`][crate::AppInfo]s which can be deleted, and system-wide ones which cannot.
622    /// See [`can_delete()`][Self::can_delete()].
623    ///
624    /// # Returns
625    ///
626    /// `TRUE` if @self has been deleted
627    #[doc(alias = "g_app_info_delete")]
628    fn delete(&self) -> bool {
629        unsafe { from_glib(ffi::g_app_info_delete(self.as_ref().to_glib_none().0)) }
630    }
631
632    /// Creates a duplicate of a [`AppInfo`][crate::AppInfo].
633    ///
634    /// # Returns
635    ///
636    /// a duplicate of @self.
637    #[doc(alias = "g_app_info_dup")]
638    #[must_use]
639    fn dup(&self) -> AppInfo {
640        unsafe { from_glib_full(ffi::g_app_info_dup(self.as_ref().to_glib_none().0)) }
641    }
642
643    #[doc(alias = "g_app_info_equal")]
644    fn equal(&self, appinfo2: &impl IsA<AppInfo>) -> bool {
645        unsafe {
646            from_glib(ffi::g_app_info_equal(
647                self.as_ref().to_glib_none().0,
648                appinfo2.as_ref().to_glib_none().0,
649            ))
650        }
651    }
652
653    /// Gets the commandline with which the application will be
654    /// started.
655    ///
656    /// # Returns
657    ///
658    /// a string containing the @self’s
659    ///   commandline, or `NULL` if this information is not available
660    #[doc(alias = "g_app_info_get_commandline")]
661    #[doc(alias = "get_commandline")]
662    fn commandline(&self) -> Option<std::path::PathBuf> {
663        unsafe {
664            from_glib_none(ffi::g_app_info_get_commandline(
665                self.as_ref().to_glib_none().0,
666            ))
667        }
668    }
669
670    /// Gets a human-readable description of an installed application.
671    ///
672    /// # Returns
673    ///
674    /// a string containing a description of the
675    /// application @self, or `NULL` if none.
676    #[doc(alias = "g_app_info_get_description")]
677    #[doc(alias = "get_description")]
678    fn description(&self) -> Option<glib::GString> {
679        unsafe {
680            from_glib_none(ffi::g_app_info_get_description(
681                self.as_ref().to_glib_none().0,
682            ))
683        }
684    }
685
686    /// Gets the display name of the application. The display name is often more
687    /// descriptive to the user than the name itself.
688    ///
689    /// # Returns
690    ///
691    /// the display name of the application for @self, or the name if
692    /// no display name is available.
693    #[doc(alias = "g_app_info_get_display_name")]
694    #[doc(alias = "get_display_name")]
695    fn display_name(&self) -> glib::GString {
696        unsafe {
697            from_glib_none(ffi::g_app_info_get_display_name(
698                self.as_ref().to_glib_none().0,
699            ))
700        }
701    }
702
703    /// Gets the executable’s name for the installed application.
704    ///
705    /// This is intended to be used for debugging or labelling what program is going
706    /// to be run. To launch the executable, use [`launch()`][Self::launch()] and related
707    /// functions, rather than spawning the return value from this function.
708    ///
709    /// # Returns
710    ///
711    /// a string containing the @self’s application
712    /// binaries name
713    #[doc(alias = "g_app_info_get_executable")]
714    #[doc(alias = "get_executable")]
715    fn executable(&self) -> std::path::PathBuf {
716        unsafe {
717            from_glib_none(ffi::g_app_info_get_executable(
718                self.as_ref().to_glib_none().0,
719            ))
720        }
721    }
722
723    /// Gets the icon for the application.
724    ///
725    /// # Returns
726    ///
727    /// the default [`Icon`][crate::Icon] for
728    ///   @self or `NULL` if there is no default icon.
729    #[doc(alias = "g_app_info_get_icon")]
730    #[doc(alias = "get_icon")]
731    fn icon(&self) -> Option<Icon> {
732        unsafe { from_glib_none(ffi::g_app_info_get_icon(self.as_ref().to_glib_none().0)) }
733    }
734
735    /// Gets the ID of an application. An id is a string that identifies the
736    /// application. The exact format of the id is platform dependent. For instance,
737    /// on Unix this is the desktop file id from the xdg menu specification.
738    ///
739    /// Note that the returned ID may be `NULL`, depending on how the @self has
740    /// been constructed.
741    ///
742    /// # Returns
743    ///
744    /// a string containing the application’s ID.
745    #[doc(alias = "g_app_info_get_id")]
746    #[doc(alias = "get_id")]
747    fn id(&self) -> Option<glib::GString> {
748        unsafe { from_glib_none(ffi::g_app_info_get_id(self.as_ref().to_glib_none().0)) }
749    }
750
751    /// Gets the installed name of the application.
752    ///
753    /// # Returns
754    ///
755    /// the name of the application for @self.
756    #[doc(alias = "g_app_info_get_name")]
757    #[doc(alias = "get_name")]
758    fn name(&self) -> glib::GString {
759        unsafe { from_glib_none(ffi::g_app_info_get_name(self.as_ref().to_glib_none().0)) }
760    }
761
762    /// Retrieves the list of content types that @app_info claims to support.
763    /// If this information is not provided by the environment, this function
764    /// will return `NULL`.
765    ///
766    /// This function does not take in consideration associations added with
767    /// [`add_supports_type()`][Self::add_supports_type()], but only those exported directly by
768    /// the application.
769    ///
770    /// # Returns
771    ///
772    ///
773    ///   a list of content types.
774    #[doc(alias = "g_app_info_get_supported_types")]
775    #[doc(alias = "get_supported_types")]
776    fn supported_types(&self) -> Vec<glib::GString> {
777        unsafe {
778            FromGlibPtrContainer::from_glib_none(ffi::g_app_info_get_supported_types(
779                self.as_ref().to_glib_none().0,
780            ))
781        }
782    }
783
784    /// Launches the application. Passes @files to the launched application
785    /// as arguments, using the optional @context to get information
786    /// about the details of the launcher (like what screen it is on).
787    /// On error, @error will be set accordingly.
788    ///
789    /// To launch the application without arguments pass a `NULL` @files list.
790    ///
791    /// Note that even if the launch is successful the application launched
792    /// can fail to start if it runs into problems during startup. There is
793    /// no way to detect this.
794    ///
795    /// Some URIs can be changed when passed through a GFile (for instance
796    /// unsupported URIs with strange formats like mailto:), so if you have
797    /// a textual URI you want to pass in as argument, consider using
798    /// [`launch_uris()`][Self::launch_uris()] instead.
799    ///
800    /// The launched application inherits the environment of the launching
801    /// process, but it can be modified with [`AppLaunchContextExt::setenv()`][crate::prelude::AppLaunchContextExt::setenv()]
802    /// and [`AppLaunchContextExt::unsetenv()`][crate::prelude::AppLaunchContextExt::unsetenv()].
803    ///
804    /// On UNIX, this function sets the `GIO_LAUNCHED_DESKTOP_FILE`
805    /// environment variable with the path of the launched desktop file and
806    /// `GIO_LAUNCHED_DESKTOP_FILE_PID` to the process id of the launched
807    /// process. This can be used to ignore `GIO_LAUNCHED_DESKTOP_FILE`,
808    /// should it be inherited by further processes. The `DISPLAY`,
809    /// `XDG_ACTIVATION_TOKEN` and `DESKTOP_STARTUP_ID` environment
810    /// variables are also set, based on information provided in @context.
811    /// ## `files`
812    /// a list of [`File`][crate::File] objects
813    /// ## `context`
814    /// the launch context
815    ///
816    /// # Returns
817    ///
818    /// `TRUE` on successful launch, `FALSE` otherwise.
819    #[doc(alias = "g_app_info_launch")]
820    fn launch(
821        &self,
822        files: &[File],
823        context: Option<&impl IsA<AppLaunchContext>>,
824    ) -> Result<(), glib::Error> {
825        unsafe {
826            let mut error = std::ptr::null_mut();
827            let is_ok = ffi::g_app_info_launch(
828                self.as_ref().to_glib_none().0,
829                files.to_glib_none().0,
830                context.map(|p| p.as_ref()).to_glib_none().0,
831                &mut error,
832            );
833            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
834            if error.is_null() {
835                Ok(())
836            } else {
837                Err(from_glib_full(error))
838            }
839        }
840    }
841
842    /// Launches the application. This passes the @uris to the launched application
843    /// as arguments, using the optional @context to get information
844    /// about the details of the launcher (like what screen it is on).
845    /// On error, @error will be set accordingly. If the application only supports
846    /// one URI per invocation as part of their command-line, multiple instances
847    /// of the application will be spawned.
848    ///
849    /// To launch the application without arguments pass a `NULL` @uris list.
850    ///
851    /// Note that even if the launch is successful the application launched
852    /// can fail to start if it runs into problems during startup. There is
853    /// no way to detect this.
854    /// ## `uris`
855    /// a list of URIs to launch.
856    /// ## `context`
857    /// the launch context
858    ///
859    /// # Returns
860    ///
861    /// `TRUE` on successful launch, `FALSE` otherwise.
862    #[doc(alias = "g_app_info_launch_uris")]
863    fn launch_uris(
864        &self,
865        uris: &[&str],
866        context: Option<&impl IsA<AppLaunchContext>>,
867    ) -> Result<(), glib::Error> {
868        unsafe {
869            let mut error = std::ptr::null_mut();
870            let is_ok = ffi::g_app_info_launch_uris(
871                self.as_ref().to_glib_none().0,
872                uris.to_glib_none().0,
873                context.map(|p| p.as_ref()).to_glib_none().0,
874                &mut error,
875            );
876            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
877            if error.is_null() {
878                Ok(())
879            } else {
880                Err(from_glib_full(error))
881            }
882        }
883    }
884
885    /// Removes a supported type from an application, if possible.
886    /// ## `content_type`
887    /// a string.
888    ///
889    /// # Returns
890    ///
891    /// `TRUE` on success, `FALSE` on error.
892    #[doc(alias = "g_app_info_remove_supports_type")]
893    fn remove_supports_type(&self, content_type: &str) -> Result<(), glib::Error> {
894        unsafe {
895            let mut error = std::ptr::null_mut();
896            let is_ok = ffi::g_app_info_remove_supports_type(
897                self.as_ref().to_glib_none().0,
898                content_type.to_glib_none().0,
899                &mut error,
900            );
901            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
902            if error.is_null() {
903                Ok(())
904            } else {
905                Err(from_glib_full(error))
906            }
907        }
908    }
909
910    /// Sets the application as the default handler for the given file extension.
911    /// ## `extension`
912    /// a string containing the file extension (without
913    ///   the dot).
914    ///
915    /// # Returns
916    ///
917    /// `TRUE` on success, `FALSE` on error.
918    #[doc(alias = "g_app_info_set_as_default_for_extension")]
919    fn set_as_default_for_extension(
920        &self,
921        extension: impl AsRef<std::path::Path>,
922    ) -> Result<(), glib::Error> {
923        unsafe {
924            let mut error = std::ptr::null_mut();
925            let is_ok = ffi::g_app_info_set_as_default_for_extension(
926                self.as_ref().to_glib_none().0,
927                extension.as_ref().to_glib_none().0,
928                &mut error,
929            );
930            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
931            if error.is_null() {
932                Ok(())
933            } else {
934                Err(from_glib_full(error))
935            }
936        }
937    }
938
939    /// Sets the application as the default handler for a given type.
940    /// ## `content_type`
941    /// the content type.
942    ///
943    /// # Returns
944    ///
945    /// `TRUE` on success, `FALSE` on error.
946    #[doc(alias = "g_app_info_set_as_default_for_type")]
947    fn set_as_default_for_type(&self, content_type: &str) -> Result<(), glib::Error> {
948        unsafe {
949            let mut error = std::ptr::null_mut();
950            let is_ok = ffi::g_app_info_set_as_default_for_type(
951                self.as_ref().to_glib_none().0,
952                content_type.to_glib_none().0,
953                &mut error,
954            );
955            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
956            if error.is_null() {
957                Ok(())
958            } else {
959                Err(from_glib_full(error))
960            }
961        }
962    }
963
964    /// Sets the application as the last used application for a given type. This
965    /// will make the application appear as first in the list returned by
966    /// [`AppInfo::recommended_for_type()`][crate::AppInfo::recommended_for_type()], regardless of the default
967    /// application for that content type.
968    /// ## `content_type`
969    /// the content type.
970    ///
971    /// # Returns
972    ///
973    /// `TRUE` on success, `FALSE` on error.
974    #[doc(alias = "g_app_info_set_as_last_used_for_type")]
975    fn set_as_last_used_for_type(&self, content_type: &str) -> Result<(), glib::Error> {
976        unsafe {
977            let mut error = std::ptr::null_mut();
978            let is_ok = ffi::g_app_info_set_as_last_used_for_type(
979                self.as_ref().to_glib_none().0,
980                content_type.to_glib_none().0,
981                &mut error,
982            );
983            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
984            if error.is_null() {
985                Ok(())
986            } else {
987                Err(from_glib_full(error))
988            }
989        }
990    }
991
992    /// Checks if the application info should be shown in menus that
993    /// list available applications.
994    ///
995    /// # Returns
996    ///
997    /// `TRUE` if the @self should be shown, `FALSE` otherwise.
998    #[doc(alias = "g_app_info_should_show")]
999    fn should_show(&self) -> bool {
1000        unsafe { from_glib(ffi::g_app_info_should_show(self.as_ref().to_glib_none().0)) }
1001    }
1002
1003    /// Checks if the application accepts files as arguments.
1004    ///
1005    /// # Returns
1006    ///
1007    /// `TRUE` if the @self supports files.
1008    #[doc(alias = "g_app_info_supports_files")]
1009    fn supports_files(&self) -> bool {
1010        unsafe {
1011            from_glib(ffi::g_app_info_supports_files(
1012                self.as_ref().to_glib_none().0,
1013            ))
1014        }
1015    }
1016
1017    /// Checks if the application supports reading files and directories from URIs.
1018    ///
1019    /// # Returns
1020    ///
1021    /// `TRUE` if the @self supports URIs.
1022    #[doc(alias = "g_app_info_supports_uris")]
1023    fn supports_uris(&self) -> bool {
1024        unsafe {
1025            from_glib(ffi::g_app_info_supports_uris(
1026                self.as_ref().to_glib_none().0,
1027            ))
1028        }
1029    }
1030}
1031
1032impl<O: IsA<AppInfo>> AppInfoExt for O {}