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