imageMetadata: Implement debug
This commit is contained in:
parent
db69cbe64e
commit
0f7115fe8b
2 changed files with 33 additions and 17 deletions
|
|
@ -8,17 +8,19 @@ pub enum ImageMetadata {
|
|||
}
|
||||
|
||||
impl ImageMetadata {
|
||||
// TODO: error handling
|
||||
pub fn load(file: &gio::File) -> Self {
|
||||
let file = std::fs::File::open(file.path().unwrap()).unwrap();
|
||||
let mut bufreader = std::io::BufReader::new(&file);
|
||||
let exifreader = exif::Reader::new();
|
||||
if let Some(path) = file.path() {
|
||||
if let Ok(file) = std::fs::File::open(path) {
|
||||
let mut bufreader = std::io::BufReader::new(&file);
|
||||
let exifreader = exif::Reader::new();
|
||||
|
||||
if let Ok(exif) = exifreader.read_from_container(&mut bufreader) {
|
||||
Self::Exif(exif)
|
||||
} else {
|
||||
Self::None
|
||||
if let Ok(exif) = exifreader.read_from_container(&mut bufreader) {
|
||||
return Self::Exif(exif);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Self::None
|
||||
}
|
||||
|
||||
pub fn orientation(&self) -> Orientation {
|
||||
|
|
@ -38,10 +40,24 @@ impl ImageMetadata {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: implement something (that does not fill the complete screen with binary data)
|
||||
impl std::fmt::Debug for ImageMetadata {
|
||||
fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
|
||||
Ok(())
|
||||
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
|
||||
match self {
|
||||
Self::Exif(exif) => {
|
||||
let list = exif.fields().into_iter().map(|f| {
|
||||
let mut value = f.display_value().to_string();
|
||||
// Remove long values
|
||||
if value.len() > 100 {
|
||||
value = String::from("…");
|
||||
}
|
||||
|
||||
(f.ifd_num.to_string(), f.tag.to_string(), value)
|
||||
});
|
||||
fmt.write_str("Exif")?;
|
||||
fmt.debug_list().entries(list).finish()
|
||||
}
|
||||
Self::None => fmt.write_str("None"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -192,12 +192,6 @@ glib::wrapper! {
|
|||
}
|
||||
|
||||
impl LpImage {
|
||||
pub fn file(&self) -> Option<gio::File> {
|
||||
let imp = self.imp();
|
||||
|
||||
imp.file.borrow().clone()
|
||||
}
|
||||
|
||||
pub fn set_texture_with_file(&self, texture: gdk::Texture, source_file: &gio::File) {
|
||||
let imp = self.imp();
|
||||
|
||||
|
|
@ -216,6 +210,12 @@ impl LpImage {
|
|||
self.queue_draw();
|
||||
}
|
||||
|
||||
pub fn file(&self) -> Option<gio::File> {
|
||||
let imp = self.imp();
|
||||
|
||||
imp.file.borrow().clone()
|
||||
}
|
||||
|
||||
pub fn texture(&self) -> Option<gdk::Texture> {
|
||||
let imp = self.imp();
|
||||
imp.texture.borrow().clone()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue