Improve Images, Compress, Output, Workflow steps
- Images step: folder drag-and-drop with recursive image scanning, per-file list with format and size info, total file size in header, supported formats label in empty state - Compress step: per-format quality controls moved into AdwExpanderRow, improved quality level descriptions - Output step: dynamic image count with total size from loaded_files, initial overwrite behavior from config - Workflow step: properly handle MetadataConfig::Custom in preset import, mapping all custom metadata fields to JobConfig
This commit is contained in:
@@ -10,7 +10,7 @@ pub fn build_images_page(state: &AppState) -> adw::NavigationPage {
|
||||
let empty_state = build_empty_state();
|
||||
stack.add_named(&empty_state, Some("empty"));
|
||||
|
||||
// Loaded state - thumbnail grid
|
||||
// Loaded state - file list
|
||||
let loaded_state = build_loaded_state(state);
|
||||
stack.add_named(&loaded_state, Some("loaded"));
|
||||
|
||||
@@ -24,19 +24,27 @@ pub fn build_images_page(state: &AppState) -> adw::NavigationPage {
|
||||
let loaded_files = state.loaded_files.clone();
|
||||
let stack_ref = stack.clone();
|
||||
drop_target.connect_drop(move |_target, value, _x, _y| {
|
||||
// Try single file
|
||||
if let Ok(file) = value.get::<gtk::gio::File>()
|
||||
&& let Some(path) = file.path()
|
||||
&& is_image_file(&path)
|
||||
{
|
||||
let mut files = loaded_files.borrow_mut();
|
||||
if !files.contains(&path) {
|
||||
files.push(path);
|
||||
if path.is_dir() {
|
||||
// Recursively add images from directory
|
||||
let mut files = loaded_files.borrow_mut();
|
||||
add_images_from_dir(&path, &mut files);
|
||||
let count = files.len();
|
||||
drop(files);
|
||||
update_loaded_ui(&stack_ref, &loaded_files, count);
|
||||
return true;
|
||||
} else if is_image_file(&path) {
|
||||
let mut files = loaded_files.borrow_mut();
|
||||
if !files.contains(&path) {
|
||||
files.push(path);
|
||||
}
|
||||
let count = files.len();
|
||||
drop(files);
|
||||
update_loaded_ui(&stack_ref, &loaded_files, count);
|
||||
return true;
|
||||
}
|
||||
let count = files.len();
|
||||
drop(files);
|
||||
update_loaded_ui(&stack_ref, count);
|
||||
return true;
|
||||
}
|
||||
false
|
||||
});
|
||||
@@ -58,28 +66,100 @@ fn is_image_file(path: &std::path::Path) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
fn update_loaded_ui(stack: >k::Stack, count: usize) {
|
||||
if count > 0 {
|
||||
stack.set_visible_child_name("loaded");
|
||||
}
|
||||
if let Some(loaded_box) = stack.child_by_name("loaded") {
|
||||
update_count_label(&loaded_box, count);
|
||||
fn add_images_from_dir(dir: &std::path::Path, files: &mut Vec<std::path::PathBuf>) {
|
||||
if let Ok(entries) = std::fs::read_dir(dir) {
|
||||
for entry in entries.flatten() {
|
||||
let path = entry.path();
|
||||
if path.is_dir() {
|
||||
add_images_from_dir(&path, files);
|
||||
} else if is_image_file(&path) && !files.contains(&path) {
|
||||
files.push(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn update_count_label(widget: >k::Widget, count: usize) {
|
||||
fn update_loaded_ui(
|
||||
stack: >k::Stack,
|
||||
loaded_files: &std::rc::Rc<std::cell::RefCell<Vec<std::path::PathBuf>>>,
|
||||
count: usize,
|
||||
) {
|
||||
if count > 0 {
|
||||
stack.set_visible_child_name("loaded");
|
||||
} else {
|
||||
stack.set_visible_child_name("empty");
|
||||
}
|
||||
if let Some(loaded_widget) = stack.child_by_name("loaded") {
|
||||
update_count_and_list(&loaded_widget, loaded_files);
|
||||
}
|
||||
}
|
||||
|
||||
fn update_count_and_list(
|
||||
widget: >k::Widget,
|
||||
loaded_files: &std::rc::Rc<std::cell::RefCell<Vec<std::path::PathBuf>>>,
|
||||
) {
|
||||
let files = loaded_files.borrow();
|
||||
let count = files.len();
|
||||
let total_size: u64 = files.iter()
|
||||
.filter_map(|p| std::fs::metadata(p).ok())
|
||||
.map(|m| m.len())
|
||||
.sum();
|
||||
let size_str = format_size(total_size);
|
||||
|
||||
// Walk widget tree to find and update components
|
||||
walk_loaded_widgets(widget, count, &size_str, &files);
|
||||
}
|
||||
|
||||
fn walk_loaded_widgets(widget: >k::Widget, count: usize, size_str: &str, files: &[std::path::PathBuf]) {
|
||||
if let Some(label) = widget.downcast_ref::<gtk::Label>()
|
||||
&& label.css_classes().iter().any(|c| c == "heading")
|
||||
{
|
||||
label.set_label(&format!("{} images loaded", count));
|
||||
return;
|
||||
label.set_label(&format!("{} images ({})", count, size_str));
|
||||
}
|
||||
if let Some(bx) = widget.downcast_ref::<gtk::Box>() {
|
||||
let mut child = bx.first_child();
|
||||
while let Some(c) = child {
|
||||
update_count_label(&c, count);
|
||||
child = c.next_sibling();
|
||||
if let Some(list_box) = widget.downcast_ref::<gtk::ListBox>()
|
||||
&& list_box.css_classes().iter().any(|c| c == "boxed-list")
|
||||
{
|
||||
// Clear existing rows
|
||||
while let Some(row) = list_box.first_child() {
|
||||
list_box.remove(&row);
|
||||
}
|
||||
// Add rows for each file
|
||||
for path in files {
|
||||
let name = path.file_name()
|
||||
.and_then(|n| n.to_str())
|
||||
.unwrap_or("unknown");
|
||||
let size = std::fs::metadata(path)
|
||||
.map(|m| format_size(m.len()))
|
||||
.unwrap_or_default();
|
||||
let ext = path.extension()
|
||||
.and_then(|e| e.to_str())
|
||||
.unwrap_or("")
|
||||
.to_uppercase();
|
||||
let row = adw::ActionRow::builder()
|
||||
.title(name)
|
||||
.subtitle(format!("{} - {}", ext, size))
|
||||
.build();
|
||||
row.add_prefix(>k::Image::from_icon_name("image-x-generic-symbolic"));
|
||||
list_box.append(&row);
|
||||
}
|
||||
}
|
||||
// Recurse
|
||||
let mut child = widget.first_child();
|
||||
while let Some(c) = child {
|
||||
walk_loaded_widgets(&c, count, size_str, files);
|
||||
child = c.next_sibling();
|
||||
}
|
||||
}
|
||||
|
||||
fn format_size(bytes: u64) -> String {
|
||||
if bytes < 1024 {
|
||||
format!("{} B", bytes)
|
||||
} else if bytes < 1024 * 1024 {
|
||||
format!("{:.1} KB", bytes as f64 / 1024.0)
|
||||
} else if bytes < 1024 * 1024 * 1024 {
|
||||
format!("{:.1} MB", bytes as f64 / (1024.0 * 1024.0))
|
||||
} else {
|
||||
format!("{:.1} GB", bytes as f64 / (1024.0 * 1024.0 * 1024.0))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,8 +205,17 @@ fn build_empty_state() -> gtk::Box {
|
||||
.build();
|
||||
|
||||
let subtitle = gtk::Label::builder()
|
||||
.label("or click Browse to select files")
|
||||
.label("or click Browse to select files.\nYou can also drop folders.")
|
||||
.css_classes(["dim-label"])
|
||||
.halign(gtk::Align::Center)
|
||||
.justify(gtk::Justification::Center)
|
||||
.build();
|
||||
|
||||
let formats_label = gtk::Label::builder()
|
||||
.label("Supported: JPEG, PNG, WebP, AVIF, GIF, TIFF, BMP")
|
||||
.css_classes(["dim-label", "caption"])
|
||||
.halign(gtk::Align::Center)
|
||||
.margin_top(8)
|
||||
.build();
|
||||
|
||||
let browse_button = gtk::Button::builder()
|
||||
@@ -141,6 +230,7 @@ fn build_empty_state() -> gtk::Box {
|
||||
inner.append(&icon);
|
||||
inner.append(&title);
|
||||
inner.append(&subtitle);
|
||||
inner.append(&formats_label);
|
||||
inner.append(&browse_button);
|
||||
drop_zone.append(&inner);
|
||||
|
||||
@@ -165,7 +255,7 @@ fn build_loaded_state(state: &AppState) -> gtk::Box {
|
||||
.build();
|
||||
|
||||
let count_label = gtk::Label::builder()
|
||||
.label("0 images loaded")
|
||||
.label("0 images")
|
||||
.hexpand(true)
|
||||
.halign(gtk::Align::Start)
|
||||
.css_classes(["heading"])
|
||||
@@ -173,7 +263,7 @@ fn build_loaded_state(state: &AppState) -> gtk::Box {
|
||||
|
||||
let add_button = gtk::Button::builder()
|
||||
.icon_name("list-add-symbolic")
|
||||
.tooltip_text("Add more images")
|
||||
.tooltip_text("Add more images (Ctrl+O)")
|
||||
.action_name("win.add-files")
|
||||
.build();
|
||||
add_button.add_css_class("flat");
|
||||
@@ -190,8 +280,7 @@ fn build_loaded_state(state: &AppState) -> gtk::Box {
|
||||
let count_label_c = count_label.clone();
|
||||
clear_button.connect_clicked(move |btn| {
|
||||
files.borrow_mut().clear();
|
||||
count_label_c.set_label("0 images loaded");
|
||||
// Navigate back to empty state by finding parent stack
|
||||
count_label_c.set_label("0 images");
|
||||
if let Some(parent) = btn.ancestor(gtk::Stack::static_type())
|
||||
&& let Some(stack) = parent.downcast_ref::<gtk::Stack>()
|
||||
{
|
||||
@@ -206,7 +295,7 @@ fn build_loaded_state(state: &AppState) -> gtk::Box {
|
||||
|
||||
let separator = gtk::Separator::new(gtk::Orientation::Horizontal);
|
||||
|
||||
// File list showing loaded images
|
||||
// File list
|
||||
let list_scrolled = gtk::ScrolledWindow::builder()
|
||||
.hscrollbar_policy(gtk::PolicyType::Never)
|
||||
.vexpand(true)
|
||||
|
||||
Reference in New Issue
Block a user