noctua/src/app/update.rs
wfx 823dfe9fa2 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"
2026-01-10 11:46:07 +01:00

167 lines
5.4 KiB
Rust

// SPDX-License-Identifier: GPL-3.0-or-later
// src/app/update.rs
//
// Application update loop: applies messages to the global model state.
use super::document;
use super::message::AppMessage;
use super::model::{AppModel, ToolMode, ViewMode, PAN_STEP};
/// Central update function applying messages to the model.
///
/// This is the single place where application state is mutated.
pub fn update(model: &mut AppModel, msg: AppMessage) {
println!("update(): received message: {:?}", msg);
match msg {
// ===== File / navigation ==========================================================
AppMessage::OpenPath(path) => {
document::file::open_single_file(model, &path);
// Refresh metadata if panel is visible.
if model.show_right_panel {
refresh_metadata(model);
}
}
AppMessage::NextDocument => {
document::file::navigate_next(model);
// Refresh metadata if panel is visible.
if model.show_right_panel {
refresh_metadata(model);
}
}
AppMessage::PrevDocument => {
document::file::navigate_prev(model);
// Refresh metadata if panel is visible.
if model.show_right_panel {
refresh_metadata(model);
}
}
// ===== Panels =====================================================================
AppMessage::ToggleLeftPanel => {
model.show_left_panel = !model.show_left_panel;
}
AppMessage::ToggleRightPanel => {
model.show_right_panel = !model.show_right_panel;
// Load metadata lazily when panel becomes visible.
if model.show_right_panel && model.metadata.is_none() {
refresh_metadata(model);
}
}
// ===== View / zoom ===============================================================
AppMessage::ZoomIn => zoom_in(model),
AppMessage::ZoomOut => zoom_out(model),
AppMessage::ZoomReset => {
model.view_mode = ViewMode::ActualSize;
model.reset_pan();
}
AppMessage::ZoomFit => {
model.view_mode = ViewMode::Fit;
model.reset_pan();
}
// ===== Pan control (Ctrl + arrow keys) ===========================================
AppMessage::PanLeft => {
model.pan_x -= PAN_STEP;
}
AppMessage::PanRight => {
model.pan_x += PAN_STEP;
}
AppMessage::PanUp => {
model.pan_y -= PAN_STEP;
}
AppMessage::PanDown => {
model.pan_y += PAN_STEP;
}
AppMessage::PanReset => {
model.reset_pan();
}
// ===== Tools =====================================================================
AppMessage::ToggleCropMode => {
model.tool_mode = if model.tool_mode == ToolMode::Crop {
ToolMode::None
} else {
ToolMode::Crop
};
}
AppMessage::ToggleScaleMode => {
model.tool_mode = if model.tool_mode == ToolMode::Scale {
ToolMode::None
} else {
ToolMode::Scale
};
}
// ===== Document transformations ==================================================
AppMessage::FlipHorizontal => {
if let Some(doc) = &mut model.document {
document::transform::flip_horizontal(doc);
}
}
AppMessage::FlipVertical => {
if let Some(doc) = &mut model.document {
document::transform::flip_vertical(doc);
}
}
AppMessage::RotateCW => {
if let Some(doc) = &mut model.document {
document::transform::rotate_cw(doc);
}
}
AppMessage::RotateCCW => {
if let Some(doc) = &mut model.document {
document::transform::rotate_ccw(doc);
}
}
// ===== Metadata ==================================================================
AppMessage::RefreshMetadata => {
refresh_metadata(model);
}
// ===== Error handling ============================================================
AppMessage::ShowError(msg) => {
model.set_error(msg);
}
AppMessage::ClearError => {
model.clear_error();
}
AppMessage::NoOp => {
// Intentionally do nothing.
}
}
}
/// Increment zoom level by 10%.
fn zoom_in(model: &mut AppModel) {
let current = current_zoom(model);
let new_zoom = (current * 1.1).clamp(0.05, 20.0);
model.view_mode = ViewMode::Custom(new_zoom);
}
/// Decrement zoom level by ~9% (inverse of 1.1).
fn zoom_out(model: &mut AppModel) {
let current = current_zoom(model);
let new_zoom = (current / 1.1).clamp(0.05, 20.0);
model.view_mode = ViewMode::Custom(new_zoom);
}
/// Extract the current effective zoom factor from the view mode.
/// For `Fit` mode, we assume 1.0 as starting point when switching to custom zoom.
fn current_zoom(model: &AppModel) -> f32 {
match model.view_mode {
ViewMode::Fit => 1.0,
ViewMode::ActualSize => 1.0,
ViewMode::Custom(z) => z,
}
}
/// Refresh metadata from the current document.
fn refresh_metadata(model: &mut AppModel) {
model.metadata = model.document.as_ref().map(|doc| doc.extract_meta());
}