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 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.
Sourcepub fn matches_wm_class(&self, id: Ascii<&str>) -> bool
pub fn matches_wm_class(&self, id: Ascii<&str>) -> bool
Entries with a matching StartupWMClass should be preferred over those that do not.
Sourcepub fn matches_id(&self, id: Ascii<&str>) -> bool
pub fn matches_id(&self, id: Ascii<&str>) -> bool
Match entry by desktop entry file name
pub fn matches_name(&self, name: Ascii<&str>) -> bool
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>>
Sourcepub fn full_name<L: AsRef<str>>(&self, locales: &[L]) -> Option<Cow<'_, str>>
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.
Sourcepub fn icon(&self) -> Option<&str>
pub fn icon(&self) -> Option<&str>
Examples found in repository?
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}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>>( &'a 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