Implement comprehensive metadata extraction for raster images with

EXIF support and display in the right panel.

New features:
- Extract basic metadata (filename, format, resolution, file size, color type)
- Parse EXIF data (camera, date, exposure, aperture, ISO, focal length, GPS)
- Display metadata in collapsible right panel (toggle with 'i' key)
- Auto-refresh metadata on document navigation

Changes by file:

Cargo.toml, Cargo.lock:
- Add kamadak-exif dependency for EXIF parsing

i18n/en/noctua.ftl:
- Add translation strings for all metadata labels

src/app/document/meta.rs:
- New module for metadata types (BasicMeta, ExifMeta, DocumentMeta)
- Extraction logic with EXIF parsing via kamadak-exif
- Helper methods for formatted display (resolution, file size, camera, GPS)

src/app/document/mod.rs:
- Re-export meta module

src/app/document/{raster,vector,portable}.rs:
- Add extract_metadata() method stubs (full impl for raster)

src/app/document/file.rs:
- Reset metadata on document change

src/app/message.rs:
- Add ToggleRightPanel and RefreshMetadata messages

src/app/model.rs:
- Add metadata: Option<DocumentMeta> field
- Add show_right_panel: bool field

src/app/update.rs:
- Handle panel toggle and metadata refresh
- Auto-refresh metadata on navigation when panel visible

src/app/view/panels.rs:
- Implement right_panel() with metadata display
- Conditional sections for basic info and EXIF data

src/app/view/canvas.rs:
- Integrate right panel into layout"
This commit is contained in:
wfx 2026-01-10 11:46:07 +01:00
parent 6623a12632
commit 823dfe9fa2
14 changed files with 616 additions and 153 deletions

View file

@ -1,8 +1,8 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// src/app/view/canvas.rs
//
// Center canvas for displaying the current document.
/// Renders the center canvas area with the current document.
//
use cosmic::iced::{Alignment, Length};
use cosmic::widget::{container, image, text, Column, Row};
use cosmic::Element;

View file

@ -12,8 +12,55 @@ use crate::app::model::ViewMode;
use crate::app::{AppMessage, AppModel};
/// Top header bar (global actions, toggles).
pub fn header(_model: &AppModel) -> Element<'_, AppMessage> {
let content = Row::new().spacing(8).align_y(Alignment::Center);
pub fn header(model: &AppModel) -> Element<'_, AppMessage> {
// Left panel toggle button.
let left_toggle = widget::button::icon(widget::icon::from_name(if model.show_left_panel {
"sidebar-show-left-symbolic"
} else {
"sidebar-show-left-symbolic"
}))
.on_press(AppMessage::ToggleLeftPanel);
// Right panel toggle button.
let right_toggle = widget::button::icon(widget::icon::from_name(if model.show_right_panel {
"sidebar-show-right-symbolic"
} else {
"sidebar-show-right-symbolic"
}))
.on_press(AppMessage::ToggleRightPanel);
// File name display (centered).
let file_name = model
.current_path
.as_ref()
.and_then(|p| p.file_name())
.and_then(|n| n.to_str())
.unwrap_or("");
let title = Text::new(file_name);
// Spacer to push title to center and right_toggle to the right.
let left_section = Row::new()
.spacing(8)
.align_y(Alignment::Center)
.push(left_toggle);
let center_section = Container::new(title)
.width(Length::Fill)
.align_x(Alignment::Center);
let right_section = Row::new()
.spacing(8)
.align_y(Alignment::Center)
.push(right_toggle);
let content = Row::new()
.spacing(8)
.align_y(Alignment::Center)
.width(Length::Fill)
.push(left_section)
.push(center_section)
.push(right_section);
Container::new(content)
.width(Length::Fill)
@ -75,18 +122,76 @@ pub fn right_panel(model: &AppModel) -> Option<Element<'_, AppMessage>> {
return None;
}
let meta = Column::new()
.spacing(4)
.push(Text::new("Metadata"))
.push(Text::new(format!(
"Current index: {:?}",
model.current_index
)));
let mut content = Column::new().spacing(8).padding(4);
let panel = Container::new(meta)
.width(Length::Fixed(220.0))
// Section header.
content = content.push(Text::new(fl!("metadata")).size(16).width(Length::Fill));
content = content.push(widget::divider::horizontal::default());
if let Some(meta) = &model.metadata {
// Basic information section.
content = content
.push(meta_row(fl!("file-name"), meta.basic.file_name.clone()))
.push(meta_row(fl!("format"), meta.basic.format.clone()))
.push(meta_row(fl!("resolution"), meta.basic.resolution_display()))
.push(meta_row(fl!("file-size"), meta.basic.file_size_display()))
.push(meta_row(fl!("color-type"), meta.basic.color_type.clone()));
// EXIF section (if available).
if let Some(exif) = &meta.exif {
content = content
.push(widget::vertical_space().height(Length::Fixed(12.0)))
.push(Text::new(fl!("exif-data")).size(14))
.push(widget::divider::horizontal::default());
if let Some(camera) = exif.camera_display() {
content = content.push(meta_row(fl!("camera"), camera));
}
if let Some(date) = &exif.date_time {
content = content.push(meta_row(fl!("date-taken"), date.clone()));
}
if let Some(exp) = &exif.exposure_time {
content = content.push(meta_row(fl!("exposure"), exp.clone()));
}
if let Some(aperture) = &exif.f_number {
content = content.push(meta_row(fl!("aperture"), aperture.clone()));
}
if let Some(iso) = exif.iso {
content = content.push(meta_row(fl!("iso"), iso.to_string()));
}
if let Some(focal) = &exif.focal_length {
content = content.push(meta_row(fl!("focal-length"), focal.clone()));
}
if let Some(gps) = exif.gps_display() {
content = content.push(meta_row(fl!("gps"), gps));
}
}
} else if model.document.is_some() {
// Document exists but metadata not yet loaded.
content = content.push(Text::new(fl!("loading-metadata")));
} else {
// No document loaded.
content = content.push(Text::new(fl!("no-document")));
}
let panel = Container::new(widget::scrollable(content).height(Length::Fill))
.width(Length::Fixed(240.0))
.height(Length::Fill)
.padding(8);
Some(panel.into())
}
/// Helper to create a label-value row for metadata display.
fn meta_row(label: String, value: String) -> Element<'static, AppMessage> {
Row::new()
.spacing(8)
.push(
Text::new(format!("{}:", label))
.size(12)
.width(Length::Fixed(80.0)),
)
.push(Text::new(value).size(12).width(Length::Fill))
.into()
}