Skip to main content

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