Use xdg_mime::SharedMimeInfo to find icon names for mime types
This commit is contained in:
parent
983e85ab89
commit
ed8fd870a9
3 changed files with 97 additions and 13 deletions
|
|
@ -3,11 +3,22 @@ use std::path::Path;
|
|||
|
||||
pub const FALLBACK_MIME_ICON: &str = "text-x-generic";
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref SHARED_MIME_INFO: xdg_mime::SharedMimeInfo = xdg_mime::SharedMimeInfo::new();
|
||||
}
|
||||
|
||||
pub fn mime_icon<P: AsRef<Path>>(path: P, size: u16) -> icon::Icon {
|
||||
let path = path.as_ref();
|
||||
for mime in mime_guess::from_path(path).iter() {
|
||||
//TODO: correct some common issues (like application/x-sh not being found)
|
||||
let icon_name = mime.essence_str().replace("/", "-");
|
||||
//TODO: SHARED_MIME_INFO.get_mime_types_from_file_name(path)
|
||||
for mime_type in mime_guess::from_path(path) {
|
||||
for icon_name in SHARED_MIME_INFO.lookup_icon_names(&mime_type) {
|
||||
let named = icon::from_name(icon_name).size(size);
|
||||
if named.clone().path().is_some() {
|
||||
return named.icon();
|
||||
}
|
||||
}
|
||||
|
||||
let icon_name = mime_type.essence_str().replace("/", "-");
|
||||
let named = icon::from_name(icon_name).size(size);
|
||||
if named.clone().path().is_some() {
|
||||
return named.icon();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue