Struct DesktopEntry

Source
pub struct DesktopEntry {
    pub appid: String,
    pub groups: Groups,
    pub path: PathBuf,
    pub ubuntu_gettext_domain: Option<String>,
}

Fields§

§appid: String§groups: Groups§path: PathBuf§ubuntu_gettext_domain: Option<String>

Implementations§

Source§

impl DesktopEntry

Source

pub fn from_str<L>( path: impl Into<PathBuf>, input: &str, locales_filter: Option<&[L]>, ) -> Result<DesktopEntry, DecodeError>
where L: AsRef<str>,

Examples found in repository?
examples/bench.rs (line 27)
16fn bench(it: u32) {
17    let mut total_time = Duration::ZERO;
18
19    for _ in 0..it {
20        let locale = get_languages_from_env();
21        let paths = Iter::new(default_paths());
22
23        let now = Instant::now();
24
25        for path in paths {
26            if let Ok(bytes) = fs::read_to_string(&path) {
27                if let Ok(_entry) = DesktopEntry::from_str(&path, &bytes, Some(&locale)) {}
28            }
29        }
30
31        total_time += now.elapsed();
32    }
33
34    println!("time to parse all .desktop files: {:.2?}", total_time / it);
35}
Source

pub fn from_path<L>( path: impl Into<PathBuf>, locales_filter: Option<&[L]>, ) -> Result<DesktopEntry, DecodeError>
where L: AsRef<str>,

Return an owned DesktopEntry

Examples found in repository?
examples/specific_file.rs (line 15)
5fn main() {
6    let path = Path::new("tests_entries/org.mozilla.firefox.desktop");
7    let locales = &["fr_FR", "en", "it"];
8
9    // if let Ok(bytes) = fs::read_to_string(path) {
10    //     if let Ok(entry) = DesktopEntry::decode_from_str(path, &bytes, locales) {
11    //         println!("{}\n---\n{}", path.display(), entry);
12    //     }
13    // }
14
15    if let Ok(entry) = DesktopEntry::from_path(path.to_path_buf(), Some(locales)) {
16        println!("{}\n---\n{}", path.display(), entry);
17    }
18}
Source§

impl DesktopEntry

Source

pub fn parse_exec(&self) -> Result<Vec<String>, ExecError>

Source

pub fn parse_exec_with_uris<L>( &self, uris: &[&str], locales: &[L], ) -> Result<Vec<String>, ExecError>
where L: AsRef<str>,

Macros like %f (cf .desktop spec) will be subtitued using the uris parameter.

Source

pub fn parse_exec_action( &self, action_name: &str, ) -> Result<Vec<String>, ExecError>

Source

pub fn parse_exec_action_with_uris<L>( &self, action_name: &str, uris: &[&str], locales: &[L], ) -> Result<Vec<String>, ExecError>
where L: AsRef<str>,

Source§

impl DesktopEntry

Source

pub fn from_appid(appid: String) -> DesktopEntry

Construct a new DesktopEntry from an appid. The name field will be set to that appid.

Source

pub fn matches_wm_class(&self, id: Ascii<&str>) -> bool

Entries with a matching StartupWMClass should be preferred over those that do not.

Source

pub fn matches_id(&self, id: Ascii<&str>) -> bool

Match entry by desktop entry file name

Source

pub fn matches_name(&self, name: Ascii<&str>) -> bool

Source§

impl DesktopEntry

Source

pub fn id(&self) -> &str

Source

pub fn desktop_entry(&self, key: &str) -> Option<&str>

A desktop entry field if any field under the [Desktop Entry] section.

Source

pub fn desktop_entry_localized<'a, L: AsRef<str>>( &'a self, key: &str, locales: &[L], ) -> Option<Cow<'a, str>>

Source

pub fn add_desktop_entry(&mut self, key: String, value: String)

Insert a new field to this DesktopEntry, in the [Desktop Entry] section, removing the previous value and locales in any.

Source

pub fn name<L: AsRef<str>>(&self, locales: &[L]) -> Option<Cow<'_, str>>

Source

pub fn generic_name<L: AsRef<str>>(&self, locales: &[L]) -> Option<Cow<'_, str>>

Source

pub fn full_name<L: AsRef<str>>(&self, locales: &[L]) -> Option<Cow<'_, str>>

Get the full name of an application, and fall back to the name if that fails.

Source

pub fn icon(&self) -> Option<&str>

Examples found in repository?
examples/find_appid.rs (line 13)
3fn main() {
4    let locales = fde::get_languages_from_env();
5    let desktop_entries = fde::desktop_entries(&locales);
6
7    for arg in std::env::args().skip(1) {
8        let arg = fde::unicase::Ascii::new(arg.as_str());
9
10        let desktop_entry =
11            fde::find_app_by_id(&desktop_entries, arg).expect("could not find appid");
12
13        let icon_source = fde::IconSource::from_unknown(desktop_entry.icon().unwrap_or_default());
14
15        println!("{arg}: {desktop_entry:#?} with icon {icon_source:?}");
16    }
17}
Source

pub fn comment<L: AsRef<str>>(&self, locales: &[L]) -> Option<Cow<'_, str>>

This is an human readable description of the desktop file.

Source

pub fn exec(&self) -> Option<&str>

Source

pub fn categories(&self) -> Option<Vec<&str>>

Return categories

Source

pub fn keywords<L: AsRef<str>>( &self, locales: &[L], ) -> Option<Vec<Cow<'_, str>>>

Return keywords

Source

pub fn mime_type(&self) -> Option<Vec<&str>>

Return mime types

Source

pub fn no_display(&self) -> bool

Source

pub fn only_show_in(&self) -> Option<Vec<&str>>

Source

pub fn not_show_in(&self) -> Option<Vec<&str>>

Source

pub fn flatpak(&self) -> Option<&str>

Source

pub fn prefers_non_default_gpu(&self) -> bool

Source

pub fn startup_notify(&self) -> bool

Source

pub fn startup_wm_class(&self) -> Option<&str>

Source

pub fn terminal(&self) -> bool

Source

pub fn type_(&self) -> Option<&str>

Source

pub fn actions(&self) -> Option<Vec<&str>>

Source

pub fn action_entry(&self, action: &str, key: &str) -> Option<&str>

An action is defined as [Desktop Action actions-name] where action-name is defined in the Actions field of [Desktop Entry]. Example: to get the Name field of this new-window action

[Desktop Action new-window]
Name=Open a New Window

you will need to call

entry.action_entry("new-window", "Name")
Source

pub fn action_entry_localized<L: AsRef<str>>( &self, action: &str, key: &str, locales: &[L], ) -> Option<Cow<'_, str>>

Source

pub fn action_name<L: AsRef<str>>( &self, action: &str, locales: &[L], ) -> Option<Cow<'_, str>>

Source

pub fn action_exec(&self, action: &str) -> Option<&str>

Source

pub fn localized_entry_splitted<'a, L: AsRef<str>>( &'a self, group: Option<&'a Group>, key: &str, locales: &[L], ) -> Option<Vec<Cow<'a, str>>>

Trait Implementations§

Source§

impl Clone for DesktopEntry

Source§

fn clone(&self) -> DesktopEntry

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DesktopEntry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for DesktopEntry

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for DesktopEntry

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for DesktopEntry

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for DesktopEntry

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for DesktopEntry

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for DesktopEntry

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.