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