[+] Find thumbnailer with mime

This commit is contained in:
Azalea Gui
2023-02-23 13:53:50 -05:00
parent b92e835d1a
commit ac4fe214d2
+19 -8
View File
@@ -38,14 +38,6 @@ impl Thumbnailer {
Ok(t)
}
/// Load all thumbanilers available in the system
pub fn load_all() -> Result<Vec<Thumbnailer>> {
Ok(fs::read_dir("/usr/share/thumbnailers")?
.filter_map(|f| f.ok())
.filter_map(|f| Thumbnailer::load(&*f.path()).ok())
.collect())
}
/// Check if this thumbnailer should run on a specific mime type
pub fn check(&self, mime: &str) -> bool {
self.mime_type.contains(mime)
@@ -69,3 +61,22 @@ impl Thumbnailer {
Ok(())
}
}
pub struct Thumbnailers {
list: Vec<Thumbnailer>
}
impl Thumbnailers {
/// Load all thumbanilers available in the system
pub fn load_all() -> Result<Thumbnailers> {
Ok(Thumbnailers { list: fs::read_dir("/usr/share/thumbnailers")?
.filter_map(|f| f.ok())
.filter_map(|f| Thumbnailer::load(&*f.path()).ok())
.collect() })
}
/// Find a thumbnailer for a mime type
pub fn find(&self, mime: &str) -> Option<&Thumbnailer> {
self.list.iter().find(|x| x.check(mime))
}
}