1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT
use crate::AppInfo;
use crate::AppLaunchContext;
use glib::object::IsA;
use glib::translate::*;
use std::boxed::Box as Box_;
use std::fmt;
#[cfg(any(feature = "v2_60", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_60")))]
use std::mem;
use std::ptr;
glib::wrapper! {
/// [`DesktopAppInfo`][crate::DesktopAppInfo] is an implementation of [`AppInfo`][crate::AppInfo] based on
/// desktop files.
///
/// Note that `<gio/gdesktopappinfo.h>` belongs to the UNIX-specific
/// GIO interfaces, thus you have to use the `gio-unix-2.0.pc` pkg-config
/// file when using it.
///
/// # Implements
///
/// [`trait@glib::ObjectExt`], [`AppInfoExt`][trait@crate::prelude::AppInfoExt], [`AppInfoExtManual`][trait@crate::prelude::AppInfoExtManual]
#[doc(alias = "GDesktopAppInfo")]
pub struct DesktopAppInfo(Object<ffi::GDesktopAppInfo, ffi::GDesktopAppInfoClass>) @implements AppInfo;
match fn {
type_ => || ffi::g_desktop_app_info_get_type(),
}
}
impl DesktopAppInfo {
/// Creates a new [`DesktopAppInfo`][crate::DesktopAppInfo] based on a desktop file id.
///
/// A desktop file id is the basename of the desktop file, including the
/// .desktop extension. GIO is looking for a desktop file with this name
/// in the `applications` subdirectories of the XDG
/// data directories (i.e. the directories specified in the `XDG_DATA_HOME`
/// and `XDG_DATA_DIRS` environment variables). GIO also supports the
/// prefix-to-subdirectory mapping that is described in the
/// [Menu Spec](http://standards.freedesktop.org/menu-spec/latest/)
/// (i.e. a desktop id of kde-foo.desktop will match
/// `/usr/share/applications/kde/foo.desktop`).
/// ## `desktop_id`
/// the desktop file id
///
/// # Returns
///
/// a new [`DesktopAppInfo`][crate::DesktopAppInfo], or [`None`] if no desktop
/// file with that id exists.
#[doc(alias = "g_desktop_app_info_new")]
pub fn new(desktop_id: &str) -> Option<DesktopAppInfo> {
unsafe { from_glib_full(ffi::g_desktop_app_info_new(desktop_id.to_glib_none().0)) }
}
/// Creates a new [`DesktopAppInfo`][crate::DesktopAppInfo].
/// ## `filename`
/// the path of a desktop file, in the GLib
/// filename encoding
///
/// # Returns
///
/// a new [`DesktopAppInfo`][crate::DesktopAppInfo] or [`None`] on error.
#[doc(alias = "g_desktop_app_info_new_from_filename")]
#[doc(alias = "new_from_filename")]
pub fn from_filename(filename: impl AsRef<std::path::Path>) -> Option<DesktopAppInfo> {
unsafe {
from_glib_full(ffi::g_desktop_app_info_new_from_filename(
filename.as_ref().to_glib_none().0,
))
}
}
/// Creates a new [`DesktopAppInfo`][crate::DesktopAppInfo].
/// ## `key_file`
/// an opened [`glib::KeyFile`][crate::glib::KeyFile]
///
/// # Returns
///
/// a new [`DesktopAppInfo`][crate::DesktopAppInfo] or [`None`] on error.
#[doc(alias = "g_desktop_app_info_new_from_keyfile")]
#[doc(alias = "new_from_keyfile")]
pub fn from_keyfile(key_file: &glib::KeyFile) -> Option<DesktopAppInfo> {
unsafe {
from_glib_full(ffi::g_desktop_app_info_new_from_keyfile(
key_file.to_glib_none().0,
))
}
}
/// Gets the user-visible display name of the "additional application
/// action" specified by `action_name`.
///
/// This corresponds to the "Name" key within the keyfile group for the
/// action.
/// ## `action_name`
/// the name of the action as from
/// [`list_actions()`][Self::list_actions()]
///
/// # Returns
///
/// the locale-specific action name
#[doc(alias = "g_desktop_app_info_get_action_name")]
#[doc(alias = "get_action_name")]
pub fn action_name(&self, action_name: &str) -> glib::GString {
unsafe {
from_glib_full(ffi::g_desktop_app_info_get_action_name(
self.to_glib_none().0,
action_name.to_glib_none().0,
))
}
}
/// Looks up a boolean value in the keyfile backing `self`.
///
/// The `key` is looked up in the "Desktop Entry" group.
/// ## `key`
/// the key to look up
///
/// # Returns
///
/// the boolean value, or [`false`] if the key
/// is not found
#[doc(alias = "g_desktop_app_info_get_boolean")]
#[doc(alias = "get_boolean")]
pub fn boolean(&self, key: &str) -> bool {
unsafe {
from_glib(ffi::g_desktop_app_info_get_boolean(
self.to_glib_none().0,
key.to_glib_none().0,
))
}
}
/// Gets the categories from the desktop file.
///
/// # Returns
///
/// The unparsed Categories key from the desktop file;
/// i.e. no attempt is made to split it by ';' or validate it.
#[doc(alias = "g_desktop_app_info_get_categories")]
#[doc(alias = "get_categories")]
pub fn categories(&self) -> Option<glib::GString> {
unsafe {
from_glib_none(ffi::g_desktop_app_info_get_categories(
self.to_glib_none().0,
))
}
}
/// When `self` was created from a known filename, return it. In some
/// situations such as the [`DesktopAppInfo`][crate::DesktopAppInfo] returned from
/// [`from_keyfile()`][Self::from_keyfile()], this function will return [`None`].
///
/// # Returns
///
/// The full path to the file for `self`,
/// or [`None`] if not known.
#[doc(alias = "g_desktop_app_info_get_filename")]
#[doc(alias = "get_filename")]
pub fn filename(&self) -> Option<std::path::PathBuf> {
unsafe { from_glib_none(ffi::g_desktop_app_info_get_filename(self.to_glib_none().0)) }
}
/// Gets the generic name from the desktop file.
///
/// # Returns
///
/// The value of the GenericName key
#[doc(alias = "g_desktop_app_info_get_generic_name")]
#[doc(alias = "get_generic_name")]
pub fn generic_name(&self) -> Option<glib::GString> {
unsafe {
from_glib_none(ffi::g_desktop_app_info_get_generic_name(
self.to_glib_none().0,
))
}
}
/// A desktop file is hidden if the Hidden key in it is
/// set to True.
///
/// # Returns
///
/// [`true`] if hidden, [`false`] otherwise.
#[doc(alias = "g_desktop_app_info_get_is_hidden")]
#[doc(alias = "get_is_hidden")]
pub fn is_hidden(&self) -> bool {
unsafe { from_glib(ffi::g_desktop_app_info_get_is_hidden(self.to_glib_none().0)) }
}
/// Gets the keywords from the desktop file.
///
/// # Returns
///
/// The value of the Keywords key
#[doc(alias = "g_desktop_app_info_get_keywords")]
#[doc(alias = "get_keywords")]
pub fn keywords(&self) -> Vec<glib::GString> {
unsafe {
FromGlibPtrContainer::from_glib_none(ffi::g_desktop_app_info_get_keywords(
self.to_glib_none().0,
))
}
}
/// Looks up a localized string value in the keyfile backing `self`
/// translated to the current locale.
///
/// The `key` is looked up in the "Desktop Entry" group.
/// ## `key`
/// the key to look up
///
/// # Returns
///
/// a newly allocated string, or [`None`] if the key
/// is not found
#[cfg(any(feature = "v2_56", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_56")))]
#[doc(alias = "g_desktop_app_info_get_locale_string")]
#[doc(alias = "get_locale_string")]
pub fn locale_string(&self, key: &str) -> Option<glib::GString> {
unsafe {
from_glib_full(ffi::g_desktop_app_info_get_locale_string(
self.to_glib_none().0,
key.to_glib_none().0,
))
}
}
/// Gets the value of the NoDisplay key, which helps determine if the
/// application info should be shown in menus. See
/// `G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY` and [`AppInfoExt::should_show()`][crate::prelude::AppInfoExt::should_show()].
///
/// # Returns
///
/// The value of the NoDisplay key
#[doc(alias = "g_desktop_app_info_get_nodisplay")]
#[doc(alias = "get_nodisplay")]
pub fn is_nodisplay(&self) -> bool {
unsafe { from_glib(ffi::g_desktop_app_info_get_nodisplay(self.to_glib_none().0)) }
}
/// Checks if the application info should be shown in menus that list available
/// applications for a specific name of the desktop, based on the
/// `OnlyShowIn` and `NotShowIn` keys.
///
/// `desktop_env` should typically be given as [`None`], in which case the
/// `XDG_CURRENT_DESKTOP` environment variable is consulted. If you want
/// to override the default mechanism then you may specify `desktop_env`,
/// but this is not recommended.
///
/// Note that [`AppInfoExt::should_show()`][crate::prelude::AppInfoExt::should_show()] for `self` will include this check (with
/// [`None`] for `desktop_env`) as well as additional checks.
/// ## `desktop_env`
/// a string specifying a desktop name
///
/// # Returns
///
/// [`true`] if the `self` should be shown in `desktop_env` according to the
/// `OnlyShowIn` and `NotShowIn` keys, [`false`]
/// otherwise.
#[doc(alias = "g_desktop_app_info_get_show_in")]
#[doc(alias = "get_show_in")]
pub fn shows_in(&self, desktop_env: Option<&str>) -> bool {
unsafe {
from_glib(ffi::g_desktop_app_info_get_show_in(
self.to_glib_none().0,
desktop_env.to_glib_none().0,
))
}
}
/// Retrieves the StartupWMClass field from `self`. This represents the
/// WM_CLASS property of the main window of the application, if launched
/// through `self`.
///
/// # Returns
///
/// the startup WM class, or [`None`] if none is set
/// in the desktop file.
#[doc(alias = "g_desktop_app_info_get_startup_wm_class")]
#[doc(alias = "get_startup_wm_class")]
pub fn startup_wm_class(&self) -> Option<glib::GString> {
unsafe {
from_glib_none(ffi::g_desktop_app_info_get_startup_wm_class(
self.to_glib_none().0,
))
}
}
/// Looks up a string value in the keyfile backing `self`.
///
/// The `key` is looked up in the "Desktop Entry" group.
/// ## `key`
/// the key to look up
///
/// # Returns
///
/// a newly allocated string, or [`None`] if the key
/// is not found
#[doc(alias = "g_desktop_app_info_get_string")]
#[doc(alias = "get_string")]
pub fn string(&self, key: &str) -> Option<glib::GString> {
unsafe {
from_glib_full(ffi::g_desktop_app_info_get_string(
self.to_glib_none().0,
key.to_glib_none().0,
))
}
}
/// Looks up a string list value in the keyfile backing `self`.
///
/// The `key` is looked up in the "Desktop Entry" group.
/// ## `key`
/// the key to look up
///
/// # Returns
///
///
/// a [`None`]-terminated string array or [`None`] if the specified
/// key cannot be found. The array should be freed with `g_strfreev()`.
#[cfg(any(feature = "v2_60", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_60")))]
#[doc(alias = "g_desktop_app_info_get_string_list")]
#[doc(alias = "get_string_list")]
pub fn string_list(&self, key: &str) -> Vec<glib::GString> {
unsafe {
let mut length = mem::MaybeUninit::uninit();
let ret = FromGlibContainer::from_glib_full_num(
ffi::g_desktop_app_info_get_string_list(
self.to_glib_none().0,
key.to_glib_none().0,
length.as_mut_ptr(),
),
length.assume_init() as usize,
);
ret
}
}
/// Returns whether `key` exists in the "Desktop Entry" group
/// of the keyfile backing `self`.
/// ## `key`
/// the key to look up
///
/// # Returns
///
/// [`true`] if the `key` exists
#[doc(alias = "g_desktop_app_info_has_key")]
pub fn has_key(&self, key: &str) -> bool {
unsafe {
from_glib(ffi::g_desktop_app_info_has_key(
self.to_glib_none().0,
key.to_glib_none().0,
))
}
}
/// Activates the named application action.
///
/// You may only call this function on action names that were
/// returned from [`list_actions()`][Self::list_actions()].
///
/// Note that if the main entry of the desktop file indicates that the
/// application supports startup notification, and `launch_context` is
/// non-[`None`], then startup notification will be used when activating the
/// action (and as such, invocation of the action on the receiving side
/// must signal the end of startup notification when it is completed).
/// This is the expected behaviour of applications declaring additional
/// actions, as per the desktop file specification.
///
/// As with [`AppInfoExt::launch()`][crate::prelude::AppInfoExt::launch()] there is no way to detect failures that
/// occur while using this function.
/// ## `action_name`
/// the name of the action as from
/// [`list_actions()`][Self::list_actions()]
/// ## `launch_context`
/// a [`AppLaunchContext`][crate::AppLaunchContext]
#[doc(alias = "g_desktop_app_info_launch_action")]
pub fn launch_action(
&self,
action_name: &str,
launch_context: Option<&impl IsA<AppLaunchContext>>,
) {
unsafe {
ffi::g_desktop_app_info_launch_action(
self.to_glib_none().0,
action_name.to_glib_none().0,
launch_context.map(|p| p.as_ref()).to_glib_none().0,
);
}
}
/// This function performs the equivalent of [`AppInfoExt::launch_uris()`][crate::prelude::AppInfoExt::launch_uris()],
/// but is intended primarily for operating system components that
/// launch applications. Ordinary applications should use
/// [`AppInfoExt::launch_uris()`][crate::prelude::AppInfoExt::launch_uris()].
///
/// If the application is launched via GSpawn, then `spawn_flags`, `user_setup`
/// and `user_setup_data` are used for the call to `g_spawn_async()`.
/// Additionally, `pid_callback` (with `pid_callback_data`) will be called to
/// inform about the PID of the created process. See `g_spawn_async_with_pipes()`
/// for information on certain parameter conditions that can enable an
/// optimized `posix_spawn()` codepath to be used.
///
/// If application launching occurs via some other mechanism (eg: D-Bus
/// activation) then `spawn_flags`, `user_setup`, `user_setup_data`,
/// `pid_callback` and `pid_callback_data` are ignored.
/// ## `uris`
/// List of URIs
/// ## `launch_context`
/// a [`AppLaunchContext`][crate::AppLaunchContext]
/// ## `spawn_flags`
/// [`glib::SpawnFlags`][crate::glib::SpawnFlags], used for each process
/// ## `user_setup`
/// a `GSpawnChildSetupFunc`, used once
/// for each process.
/// ## `user_setup_data`
/// User data for `user_setup`
/// ## `pid_callback`
/// Callback for child processes
/// ## `pid_callback_data`
/// User data for `callback`
///
/// # Returns
///
/// [`true`] on successful launch, [`false`] otherwise.
#[doc(alias = "g_desktop_app_info_launch_uris_as_manager")]
pub fn launch_uris_as_manager(
&self,
uris: &[&str],
launch_context: Option<&impl IsA<AppLaunchContext>>,
spawn_flags: glib::SpawnFlags,
user_setup: Option<Box_<dyn FnOnce() + 'static>>,
pid_callback: Option<&mut dyn (FnMut(&DesktopAppInfo, glib::Pid))>,
) -> Result<(), glib::Error> {
let user_setup_data: Box_<Option<Box_<dyn FnOnce() + 'static>>> = Box_::new(user_setup);
unsafe extern "C" fn user_setup_func(user_data: glib::ffi::gpointer) {
let callback: Box_<Option<Box_<dyn FnOnce() + 'static>>> =
Box_::from_raw(user_data as *mut _);
let callback = (*callback).expect("cannot get closure...");
callback()
}
let user_setup = if user_setup_data.is_some() {
Some(user_setup_func as _)
} else {
None
};
let pid_callback_data: Option<&mut dyn (FnMut(&DesktopAppInfo, glib::Pid))> = pid_callback;
unsafe extern "C" fn pid_callback_func(
appinfo: *mut ffi::GDesktopAppInfo,
pid: glib::ffi::GPid,
user_data: glib::ffi::gpointer,
) {
let appinfo = from_glib_borrow(appinfo);
let pid = from_glib(pid);
let callback: *mut Option<&mut dyn (FnMut(&DesktopAppInfo, glib::Pid))> =
user_data as *const _ as usize
as *mut Option<&mut dyn (FnMut(&DesktopAppInfo, glib::Pid))>;
if let Some(ref mut callback) = *callback {
callback(&appinfo, pid)
} else {
panic!("cannot get closure...")
};
}
let pid_callback = if pid_callback_data.is_some() {
Some(pid_callback_func as _)
} else {
None
};
let super_callback0: Box_<Option<Box_<dyn FnOnce() + 'static>>> = user_setup_data;
let super_callback1: &Option<&mut dyn (FnMut(&DesktopAppInfo, glib::Pid))> =
&pid_callback_data;
unsafe {
let mut error = ptr::null_mut();
let is_ok = ffi::g_desktop_app_info_launch_uris_as_manager(
self.to_glib_none().0,
uris.to_glib_none().0,
launch_context.map(|p| p.as_ref()).to_glib_none().0,
spawn_flags.into_glib(),
user_setup,
Box_::into_raw(super_callback0) as *mut _,
pid_callback,
super_callback1 as *const _ as usize as *mut _,
&mut error,
);
assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
if error.is_null() {
Ok(())
} else {
Err(from_glib_full(error))
}
}
}
/// Returns the list of "additional application actions" supported on the
/// desktop file, as per the desktop file specification.
///
/// As per the specification, this is the list of actions that are
/// explicitly listed in the "Actions" key of the [Desktop Entry] group.
///
/// # Returns
///
/// a list of strings, always non-[`None`]
#[doc(alias = "g_desktop_app_info_list_actions")]
pub fn list_actions(&self) -> Vec<glib::GString> {
unsafe {
FromGlibPtrContainer::from_glib_none(ffi::g_desktop_app_info_list_actions(
self.to_glib_none().0,
))
}
}
/// Gets all applications that implement `interface`.
///
/// An application implements an interface if that interface is listed in
/// the Implements= line of the desktop file of the application.
/// ## `interface`
/// the name of the interface
///
/// # Returns
///
/// a list of [`DesktopAppInfo`][crate::DesktopAppInfo]
/// objects.
#[doc(alias = "g_desktop_app_info_get_implementations")]
#[doc(alias = "get_implementations")]
pub fn implementations(interface: &str) -> Vec<DesktopAppInfo> {
unsafe {
FromGlibPtrContainer::from_glib_full(ffi::g_desktop_app_info_get_implementations(
interface.to_glib_none().0,
))
}
}
}
impl fmt::Display for DesktopAppInfo {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("DesktopAppInfo")
}
}