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