Skip to main content

gio_unix/auto/
desktop_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;
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9    /// ` belongs to the UNIX-specific
10    /// GIO interfaces, thus you have to use the `gio-unix-2.0.pc` pkg-config
11    /// file or the `GioUnix-2.0` GIR namespace when using it.
12    ///
13    /// ## Properties
14    ///
15    ///
16    /// #### `filename`
17    ///  The origin filename of this [`DesktopAppInfo`][crate::DesktopAppInfo]
18    ///
19    /// Readable | Writable | Construct Only
20    ///
21    /// # Implements
22    ///
23    /// [`trait@gio::prelude::AppInfoExt`], [`DesktopAppInfoExtManual`][trait@crate::prelude::DesktopAppInfoExtManual]
24    #[doc(alias = "GDesktopAppInfo")]
25    pub struct DesktopAppInfo(Object<ffi::GDesktopAppInfo, ffi::GDesktopAppInfoClass>) @implements gio::AppInfo;
26
27    match fn {
28        type_ => || ffi::g_desktop_app_info_get_type(),
29    }
30}
31
32impl DesktopAppInfo {
33    /// Creates a new [`DesktopAppInfo`][crate::DesktopAppInfo] based on a desktop file ID.
34    ///
35    /// A desktop file ID is the basename of the desktop file, including the
36    /// `.desktop` extension. GIO is looking for a desktop file with this name
37    /// in the `applications` subdirectories of the XDG
38    /// data directories (i.e. the directories specified in the `XDG_DATA_HOME`
39    /// and `XDG_DATA_DIRS` environment variables). GIO also supports the
40    /// prefix-to-subdirectory mapping that is described in the
41    /// [Menu Spec](http://standards.freedesktop.org/menu-spec/latest/)
42    /// (i.e. a desktop ID of `kde-foo.desktop` will match
43    /// `/usr/share/applications/kde/foo.desktop`).
44    /// ## `desktop_id`
45    /// the desktop file ID
46    ///
47    /// # Returns
48    ///
49    /// a new [`DesktopAppInfo`][crate::DesktopAppInfo], or `NULL` if no
50    ///    desktop file with that ID exists.
51    #[doc(alias = "g_desktop_app_info_new")]
52    pub fn new(desktop_id: &str) -> Option<DesktopAppInfo> {
53        unsafe { from_glib_full(ffi::g_desktop_app_info_new(desktop_id.to_glib_none().0)) }
54    }
55
56    /// Creates a new [`DesktopAppInfo`][crate::DesktopAppInfo].
57    /// ## `filename`
58    /// the path of a desktop file, in the GLib
59    ///      filename encoding
60    ///
61    /// # Returns
62    ///
63    /// a new [`DesktopAppInfo`][crate::DesktopAppInfo] or `NULL` on error.
64    #[doc(alias = "g_desktop_app_info_new_from_filename")]
65    #[doc(alias = "new_from_filename")]
66    pub fn from_filename(filename: impl AsRef<std::path::Path>) -> Option<DesktopAppInfo> {
67        unsafe {
68            from_glib_full(ffi::g_desktop_app_info_new_from_filename(
69                filename.as_ref().to_glib_none().0,
70            ))
71        }
72    }
73
74    /// Creates a new [`DesktopAppInfo`][crate::DesktopAppInfo].
75    /// ## `key_file`
76    /// an opened [type@GLib.KeyFile]
77    ///
78    /// # Returns
79    ///
80    /// a new [`DesktopAppInfo`][crate::DesktopAppInfo] or `NULL` on error.
81    #[doc(alias = "g_desktop_app_info_new_from_keyfile")]
82    #[doc(alias = "new_from_keyfile")]
83    pub fn from_keyfile(key_file: &glib::KeyFile) -> Option<DesktopAppInfo> {
84        unsafe {
85            from_glib_full(ffi::g_desktop_app_info_new_from_keyfile(
86                key_file.to_glib_none().0,
87            ))
88        }
89    }
90
91    /// ](https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s11.html)
92    /// specified by @action_name.
93    ///
94    /// This corresponds to the `Name` key within the keyfile group for the
95    /// action.
96    /// ## `action_name`
97    /// the name of the action as from
98    ///   [`list_actions()`][Self::list_actions()]
99    ///
100    /// # Returns
101    ///
102    /// the locale-specific action name
103    #[doc(alias = "g_desktop_app_info_get_action_name")]
104    #[doc(alias = "get_action_name")]
105    pub fn action_name(&self, action_name: &str) -> glib::GString {
106        unsafe {
107            from_glib_full(ffi::g_desktop_app_info_get_action_name(
108                self.to_glib_none().0,
109                action_name.to_glib_none().0,
110            ))
111        }
112    }
113
114    /// Looks up a boolean value in the keyfile backing @self.
115    ///
116    /// The @key is looked up in the `Desktop Entry` group.
117    /// ## `key`
118    /// the key to look up
119    ///
120    /// # Returns
121    ///
122    /// the boolean value, or `FALSE` if the key is not found
123    #[doc(alias = "g_desktop_app_info_get_boolean")]
124    #[doc(alias = "get_boolean")]
125    pub fn boolean(&self, key: &str) -> bool {
126        unsafe {
127            from_glib(ffi::g_desktop_app_info_get_boolean(
128                self.to_glib_none().0,
129                key.to_glib_none().0,
130            ))
131        }
132    }
133
134    /// Gets the categories from the desktop file.
135    ///
136    /// # Returns
137    ///
138    /// The unparsed
139    ///   [`Categories` key](https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s06.html#key-categories)
140    ///   from the desktop file;
141    ///   i.e. no attempt is made to split it by `;` or validate it.
142    #[doc(alias = "g_desktop_app_info_get_categories")]
143    #[doc(alias = "get_categories")]
144    pub fn categories(&self) -> Option<glib::GString> {
145        unsafe {
146            from_glib_none(ffi::g_desktop_app_info_get_categories(
147                self.to_glib_none().0,
148            ))
149        }
150    }
151
152    /// When @self was created from a known filename, return it.
153    ///
154    /// In some situations such as a [`DesktopAppInfo`][crate::DesktopAppInfo] returned
155    /// from [`from_keyfile()`][Self::from_keyfile()], this function
156    /// will return `NULL`.
157    ///
158    /// # Returns
159    ///
160    /// The full path to the file for @self,
161    ///   or `NULL` if not known.
162    #[doc(alias = "g_desktop_app_info_get_filename")]
163    #[doc(alias = "get_filename")]
164    pub fn filename(&self) -> Option<std::path::PathBuf> {
165        unsafe { from_glib_none(ffi::g_desktop_app_info_get_filename(self.to_glib_none().0)) }
166    }
167
168    /// Gets the generic name from the desktop file.
169    ///
170    /// # Returns
171    ///
172    /// The value of the
173    ///   [`GenericName` key](https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s06.html#key-genericname)
174    #[doc(alias = "g_desktop_app_info_get_generic_name")]
175    #[doc(alias = "get_generic_name")]
176    pub fn generic_name(&self) -> Option<glib::GString> {
177        unsafe {
178            from_glib_none(ffi::g_desktop_app_info_get_generic_name(
179                self.to_glib_none().0,
180            ))
181        }
182    }
183
184    /// A desktop file is hidden if the
185    /// [`Hidden` key](https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s06.html#key-hidden)
186    /// in it is set to `True`.
187    ///
188    /// # Returns
189    ///
190    /// `TRUE` if hidden, `FALSE` otherwise.
191    #[doc(alias = "g_desktop_app_info_get_is_hidden")]
192    #[doc(alias = "get_is_hidden")]
193    pub fn is_hidden(&self) -> bool {
194        unsafe { from_glib(ffi::g_desktop_app_info_get_is_hidden(self.to_glib_none().0)) }
195    }
196
197    /// Gets the keywords from the desktop file.
198    ///
199    /// # Returns
200    ///
201    /// The value of the
202    ///   [`Keywords` key](https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s06.html#key-keywords)
203    #[doc(alias = "g_desktop_app_info_get_keywords")]
204    #[doc(alias = "get_keywords")]
205    pub fn keywords(&self) -> Vec<glib::GString> {
206        unsafe {
207            FromGlibPtrContainer::from_glib_none(ffi::g_desktop_app_info_get_keywords(
208                self.to_glib_none().0,
209            ))
210        }
211    }
212
213    /// Looks up a localized string value in the keyfile backing @self
214    /// translated to the current locale.
215    ///
216    /// The @key is looked up in the `Desktop Entry` group.
217    /// ## `key`
218    /// the key to look up
219    ///
220    /// # Returns
221    ///
222    /// a newly allocated string, or `NULL` if the key is not
223    ///   found
224    #[doc(alias = "g_desktop_app_info_get_locale_string")]
225    #[doc(alias = "get_locale_string")]
226    pub fn locale_string(&self, key: &str) -> Option<glib::GString> {
227        unsafe {
228            from_glib_full(ffi::g_desktop_app_info_get_locale_string(
229                self.to_glib_none().0,
230                key.to_glib_none().0,
231            ))
232        }
233    }
234
235    /// Gets the value of the
236    /// [`NoDisplay` key](https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s06.html#key-nodisplay)
237    ///  which helps determine if the application info should be shown in menus. See
238    /// `G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY` and [`AppInfoExtManual::should_show()`][crate::gio::prelude::AppInfoExtManual::should_show()].
239    ///
240    /// # Returns
241    ///
242    /// The value of the `NoDisplay` key
243    #[doc(alias = "g_desktop_app_info_get_nodisplay")]
244    #[doc(alias = "get_nodisplay")]
245    pub fn is_nodisplay(&self) -> bool {
246        unsafe { from_glib(ffi::g_desktop_app_info_get_nodisplay(self.to_glib_none().0)) }
247    }
248
249    /// Checks if the application info should be shown in menus that list available
250    /// applications for a specific name of the desktop, based on the
251    /// [`OnlyShowIn`](https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s06.html#key-onlyshowin)
252    /// and [`NotShowIn`](https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s06.html#key-notshowin)
253    /// keys.
254    ///
255    /// @desktop_env should typically be given as `NULL`, in which case the
256    /// `XDG_CURRENT_DESKTOP` environment variable is consulted.  If you want
257    /// to override the default mechanism then you may specify @desktop_env,
258    /// but this is not recommended.
259    ///
260    /// Note that [`AppInfoExtManual::should_show()`][crate::gio::prelude::AppInfoExtManual::should_show()] for @self will include this check
261    /// (with `NULL` for @desktop_env) as well as additional checks.
262    /// ## `desktop_env`
263    /// a string specifying a desktop name
264    ///
265    /// # Returns
266    ///
267    /// `TRUE` if the @self should be shown in @desktop_env according to the
268    /// `OnlyShowIn` and `NotShowIn` keys, `FALSE` otherwise.
269    #[doc(alias = "g_desktop_app_info_get_show_in")]
270    #[doc(alias = "get_show_in")]
271    pub fn shows_in(&self, desktop_env: Option<&str>) -> bool {
272        unsafe {
273            from_glib(ffi::g_desktop_app_info_get_show_in(
274                self.to_glib_none().0,
275                desktop_env.to_glib_none().0,
276            ))
277        }
278    }
279
280    /// Retrieves the `StartupWMClass` field from @self. This represents the
281    /// `WM_CLASS` property of the main window of the application, if launched
282    /// through @self.
283    ///
284    /// # Returns
285    ///
286    /// the startup WM class, or `NULL` if none
287    ///   is set in the desktop file.
288    #[doc(alias = "g_desktop_app_info_get_startup_wm_class")]
289    #[doc(alias = "get_startup_wm_class")]
290    pub fn startup_wm_class(&self) -> Option<glib::GString> {
291        unsafe {
292            from_glib_none(ffi::g_desktop_app_info_get_startup_wm_class(
293                self.to_glib_none().0,
294            ))
295        }
296    }
297
298    /// Looks up a string value in the keyfile backing @self.
299    ///
300    /// The @key is looked up in the `Desktop Entry` group.
301    /// ## `key`
302    /// the key to look up
303    ///
304    /// # Returns
305    ///
306    /// a newly allocated string, or `NULL` if the key is not
307    ///   found
308    #[doc(alias = "g_desktop_app_info_get_string")]
309    #[doc(alias = "get_string")]
310    pub fn string(&self, key: &str) -> Option<glib::GString> {
311        unsafe {
312            from_glib_full(ffi::g_desktop_app_info_get_string(
313                self.to_glib_none().0,
314                key.to_glib_none().0,
315            ))
316        }
317    }
318
319    /// Looks up a string list value in the keyfile backing @self.
320    ///
321    /// The @key is looked up in the `Desktop Entry` group.
322    /// ## `key`
323    /// the key to look up
324    ///
325    /// # Returns
326    ///
327    ///
328    ///   a `NULL`-terminated string array or `NULL` if the specified
329    ///   key cannot be found. The array should be freed with `strfreev()`.
330    #[cfg(feature = "v2_60")]
331    #[cfg_attr(docsrs, doc(cfg(feature = "v2_60")))]
332    #[doc(alias = "g_desktop_app_info_get_string_list")]
333    #[doc(alias = "get_string_list")]
334    pub fn string_list(&self, key: &str) -> Vec<glib::GString> {
335        unsafe {
336            let mut length = std::mem::MaybeUninit::uninit();
337            let ret = FromGlibContainer::from_glib_full_num(
338                ffi::g_desktop_app_info_get_string_list(
339                    self.to_glib_none().0,
340                    key.to_glib_none().0,
341                    length.as_mut_ptr(),
342                ),
343                length.assume_init() as _,
344            );
345            ret
346        }
347    }
348
349    /// Returns whether @key exists in the `Desktop Entry` group
350    /// of the keyfile backing @self.
351    /// ## `key`
352    /// the key to look up
353    ///
354    /// # Returns
355    ///
356    /// `TRUE` if the @key exists
357    #[doc(alias = "g_desktop_app_info_has_key")]
358    pub fn has_key(&self, key: &str) -> bool {
359        unsafe {
360            from_glib(ffi::g_desktop_app_info_has_key(
361                self.to_glib_none().0,
362                key.to_glib_none().0,
363            ))
364        }
365    }
366
367    /// Activates the named application action.
368    ///
369    /// You may only call this function on action names that were
370    /// returned from [`list_actions()`][Self::list_actions()].
371    ///
372    /// Note that if the main entry of the desktop file indicates that the
373    /// application supports startup notification, and @launch_context is
374    /// non-`NULL`, then startup notification will be used when activating the
375    /// action (and as such, invocation of the action on the receiving side
376    /// must signal the end of startup notification when it is completed).
377    /// This is the expected behaviour of applications declaring additional
378    /// actions, as per the
379    /// [desktop file specification](https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s11.html).
380    ///
381    /// As with [`AppInfoExtManual::launch()`][crate::gio::prelude::AppInfoExtManual::launch()] there is no way to detect failures that
382    /// occur while using this function.
383    /// ## `action_name`
384    /// the name of the action as from
385    ///   [`list_actions()`][Self::list_actions()]
386    /// ## `launch_context`
387    /// a [`gio::AppLaunchContext`][crate::gio::AppLaunchContext]
388    #[doc(alias = "g_desktop_app_info_launch_action")]
389    pub fn launch_action(
390        &self,
391        action_name: &str,
392        launch_context: Option<&impl IsA<gio::AppLaunchContext>>,
393    ) {
394        unsafe {
395            ffi::g_desktop_app_info_launch_action(
396                self.to_glib_none().0,
397                action_name.to_glib_none().0,
398                launch_context.map(|p| p.as_ref()).to_glib_none().0,
399            );
400        }
401    }
402
403    //#[doc(alias = "g_desktop_app_info_launch_uris_as_manager")]
404    //pub fn launch_uris_as_manager(&self, uris: &[&str], launch_context: Option<&impl IsA<gio::AppLaunchContext>>, spawn_flags: glib::SpawnFlags, user_setup: Option<Box_<dyn FnOnce() + 'static>>, pid_callback: /*Unimplemented*/FnMut(&DesktopAppInfo, /*Ignored*/glib::Pid), pid_callback_data: /*Unimplemented*/Option<Basic: Pointer>) -> Result<(), glib::Error> {
405    //    unsafe { TODO: call ffi:g_desktop_app_info_launch_uris_as_manager() }
406    //}
407
408    /// ](https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s11.html)
409    /// supported on the desktop file, as per the desktop file specification.
410    ///
411    /// As per the specification, this is the list of actions that are
412    /// explicitly listed in the `Actions` key of the `Desktop Entry` group.
413    ///
414    /// # Returns
415    ///
416    /// a
417    ///   list of strings, always non-`NULL`
418    #[doc(alias = "g_desktop_app_info_list_actions")]
419    pub fn list_actions(&self) -> Vec<glib::GString> {
420        unsafe {
421            FromGlibPtrContainer::from_glib_none(ffi::g_desktop_app_info_list_actions(
422                self.to_glib_none().0,
423            ))
424        }
425    }
426
427    /// Gets all applications that implement @interface.
428    ///
429    /// An application implements an interface if that interface is listed in
430    /// the `Implements` line of the desktop file of the application.
431    /// ## `interface`
432    /// the name of the interface
433    ///
434    /// # Returns
435    ///
436    /// a list of
437    ///   [`DesktopAppInfo`][crate::DesktopAppInfo] objects.
438    #[doc(alias = "g_desktop_app_info_get_implementations")]
439    #[doc(alias = "get_implementations")]
440    pub fn implementations(interface: &str) -> Vec<DesktopAppInfo> {
441        unsafe {
442            FromGlibPtrContainer::from_glib_full(ffi::g_desktop_app_info_get_implementations(
443                interface.to_glib_none().0,
444            ))
445        }
446    }
447}