imageMetadata: Implement debug
This commit is contained in:
parent
db69cbe64e
commit
0f7115fe8b
2 changed files with 33 additions and 17 deletions
|
|
@ -8,18 +8,20 @@ pub enum ImageMetadata {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ImageMetadata {
|
impl ImageMetadata {
|
||||||
// TODO: error handling
|
|
||||||
pub fn load(file: &gio::File) -> Self {
|
pub fn load(file: &gio::File) -> Self {
|
||||||
let file = std::fs::File::open(file.path().unwrap()).unwrap();
|
if let Some(path) = file.path() {
|
||||||
|
if let Ok(file) = std::fs::File::open(path) {
|
||||||
let mut bufreader = std::io::BufReader::new(&file);
|
let mut bufreader = std::io::BufReader::new(&file);
|
||||||
let exifreader = exif::Reader::new();
|
let exifreader = exif::Reader::new();
|
||||||
|
|
||||||
if let Ok(exif) = exifreader.read_from_container(&mut bufreader) {
|
if let Ok(exif) = exifreader.read_from_container(&mut bufreader) {
|
||||||
Self::Exif(exif)
|
return Self::Exif(exif);
|
||||||
} else {
|
|
||||||
Self::None
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Self::None
|
||||||
|
}
|
||||||
|
|
||||||
pub fn orientation(&self) -> Orientation {
|
pub fn orientation(&self) -> Orientation {
|
||||||
match self {
|
match self {
|
||||||
|
|
@ -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 {
|
impl std::fmt::Debug for ImageMetadata {
|
||||||
fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
|
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
|
||||||
Ok(())
|
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 {
|
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) {
|
pub fn set_texture_with_file(&self, texture: gdk::Texture, source_file: &gio::File) {
|
||||||
let imp = self.imp();
|
let imp = self.imp();
|
||||||
|
|
||||||
|
|
@ -216,6 +210,12 @@ impl LpImage {
|
||||||
self.queue_draw();
|
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> {
|
pub fn texture(&self) -> Option<gdk::Texture> {
|
||||||
let imp = self.imp();
|
let imp = self.imp();
|
||||||
imp.texture.borrow().clone()
|
imp.texture.borrow().clone()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue