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
impl DesktopEntry
Sourcepub fn from_str<L>(
path: impl Into<PathBuf>,
input: &str,
locales_filter: Option<&[L]>,
) -> Result<DesktopEntry, DecodeError>
pub fn from_str<L>( path: impl Into<PathBuf>, input: &str, locales_filter: Option<&[L]>, ) -> Result<DesktopEntry, DecodeError>
Examples found in repository?
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}Sourcepub fn from_path<L>(
path: impl Into<PathBuf>,
locales_filter: Option<&[L]>,
) -> Result<DesktopEntry, DecodeError>
pub fn from_path<L>( path: impl Into<PathBuf>, locales_filter: Option<&[L]>, ) -> Result<DesktopEntry, DecodeError>
Return an owned DesktopEntry
Examples found in repository?
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
impl DesktopEntry
pub fn parse_exec(&self) -> Result<Vec<String>, ExecError>
Sourcepub fn parse_exec_with_uris<L>(
&self,
uris: &[&str],
locales: &[L],
) -> Result<Vec<String>, ExecError>
pub fn parse_exec_with_uris<L>( &self, uris: &[&str], locales: &[L], ) -> Result<Vec<String>, ExecError>
Macros like %f (cf .desktop spec) will be subtitued using the uris parameter.
pub fn parse_exec_action( &self, action_name: &str, ) -> Result<Vec<String>, ExecError>
pub fn parse_exec_action_with_uris<L>( &self, action_name: &str, uris: &[&str], locales: &[L], ) -> Result<Vec<String>, ExecError>
Source§impl DesktopEntry
impl DesktopEntry
Sourcepub fn match_query<Q, L>(
&self,
query: Q,
locales: &[L],
additional_haystack_values: &[&str],
) -> f64
pub fn match_query<Q, L>( &self, query: Q, locales: &[L], additional_haystack_values: &[&str], ) -> f64
The returned value is between 0.0 and 1.0 (higher value means more similar).
You can use the additional_haystack_values parameter to add relevant string that are not part of the desktop entry.
Source§impl DesktopEntry
impl DesktopEntry
Sourcepub fn from_appid(appid: String) -> DesktopEntry
pub fn from_appid(appid: String) -> DesktopEntry
Construct a new DesktopEntry from an appid. The name field will be
set to that appid.
Source§impl DesktopEntry
impl DesktopEntry
pub fn id(&self) -> &str
Sourcepub fn desktop_entry(&self, key: &str) -> Option<&str>
pub fn desktop_entry(&self, key: &str) -> Option<&str>
A desktop entry field if any field under the [Desktop Entry] section.
pub fn desktop_entry_localized<'a, L: AsRef<str>>( &'a self, key: &str, locales: &[L], ) -> Option<Cow<'a, str>>
Sourcepub fn add_desktop_entry(&mut self, key: String, value: String)
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.
pub fn name<L: AsRef<str>>(&self, locales: &[L]) -> Option<Cow<'_, str>>
pub fn generic_name<L: AsRef<str>>(&self, locales: &[L]) -> Option<Cow<'_, str>>
pub fn icon(&self) -> Option<&str>
Sourcepub fn comment<L: AsRef<str>>(&self, locales: &[L]) -> Option<Cow<'_, str>>
pub fn comment<L: AsRef<str>>(&self, locales: &[L]) -> Option<Cow<'_, str>>
This is an human readable description of the desktop file.
pub fn exec(&self) -> Option<&str>
Sourcepub fn categories(&self) -> Option<Vec<&str>>
pub fn categories(&self) -> Option<Vec<&str>>
Return categories
Sourcepub fn keywords<L: AsRef<str>>(
&self,
locales: &[L],
) -> Option<Vec<Cow<'_, str>>>
pub fn keywords<L: AsRef<str>>( &self, locales: &[L], ) -> Option<Vec<Cow<'_, str>>>
Return keywords
pub fn no_display(&self) -> bool
pub fn only_show_in(&self) -> Option<Vec<&str>>
pub fn not_show_in(&self) -> Option<Vec<&str>>
pub fn flatpak(&self) -> Option<&str>
pub fn prefers_non_default_gpu(&self) -> bool
pub fn startup_notify(&self) -> bool
pub fn startup_wm_class(&self) -> Option<&str>
pub fn terminal(&self) -> bool
pub fn type_(&self) -> Option<&str>
pub fn actions(&self) -> Option<Vec<&str>>
Sourcepub fn action_entry(&self, action: &str, key: &str) -> Option<&str>
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 Windowyou will need to call
entry.action_entry("new-window", "Name")pub fn action_entry_localized<L: AsRef<str>>( &self, action: &str, key: &str, locales: &[L], ) -> Option<Cow<'_, str>>
pub fn action_name<L: AsRef<str>>( &self, action: &str, locales: &[L], ) -> Option<Cow<'_, str>>
pub fn action_exec(&self, action: &str) -> Option<&str>
pub fn localized_entry_splitted<'a, L: AsRef<str>>( &self, group: Option<&'a Group>, key: &str, locales: &[L], ) -> Option<Vec<Cow<'a, str>>>
Trait Implementations§
Source§impl Clone for DesktopEntry
impl Clone for DesktopEntry
Source§fn clone(&self) -> DesktopEntry
fn clone(&self) -> DesktopEntry
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more