[+] Find thumbnailer with mime
This commit is contained in:
@@ -38,14 +38,6 @@ impl Thumbnailer {
|
|||||||
Ok(t)
|
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
|
/// Check if this thumbnailer should run on a specific mime type
|
||||||
pub fn check(&self, mime: &str) -> bool {
|
pub fn check(&self, mime: &str) -> bool {
|
||||||
self.mime_type.contains(mime)
|
self.mime_type.contains(mime)
|
||||||
@@ -69,3 +61,22 @@ impl Thumbnailer {
|
|||||||
Ok(())
|
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))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user