Restore session settings for convert format, quality preset, and metadata mode
- Parse stored format/quality/metadata strings back to enum values on launch - Remove duplicate help button handler - Session now properly round-trips all wizard state between launches
This commit is contained in:
@@ -169,6 +169,39 @@ fn load_css() {
|
||||
);
|
||||
}
|
||||
|
||||
fn parse_image_format(s: &str) -> Option<pixstrip_core::types::ImageFormat> {
|
||||
match s {
|
||||
"Jpeg" => Some(pixstrip_core::types::ImageFormat::Jpeg),
|
||||
"Png" => Some(pixstrip_core::types::ImageFormat::Png),
|
||||
"WebP" => Some(pixstrip_core::types::ImageFormat::WebP),
|
||||
"Avif" => Some(pixstrip_core::types::ImageFormat::Avif),
|
||||
"Gif" => Some(pixstrip_core::types::ImageFormat::Gif),
|
||||
"Tiff" => Some(pixstrip_core::types::ImageFormat::Tiff),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_quality_preset(s: &str) -> Option<pixstrip_core::types::QualityPreset> {
|
||||
match s {
|
||||
"Maximum" => Some(pixstrip_core::types::QualityPreset::Maximum),
|
||||
"High" => Some(pixstrip_core::types::QualityPreset::High),
|
||||
"Medium" => Some(pixstrip_core::types::QualityPreset::Medium),
|
||||
"Low" => Some(pixstrip_core::types::QualityPreset::Low),
|
||||
"WebOptimized" => Some(pixstrip_core::types::QualityPreset::WebOptimized),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_metadata_mode(s: &str) -> Option<MetadataMode> {
|
||||
match s {
|
||||
"StripAll" => Some(MetadataMode::StripAll),
|
||||
"Privacy" => Some(MetadataMode::Privacy),
|
||||
"KeepAll" => Some(MetadataMode::KeepAll),
|
||||
"Custom" => Some(MetadataMode::Custom),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn build_ui(app: &adw::Application) {
|
||||
load_css();
|
||||
|
||||
@@ -202,14 +235,24 @@ fn build_ui(app: &adw::Application) {
|
||||
trim_whitespace: false,
|
||||
canvas_padding: 0,
|
||||
convert_enabled: if remember { sess_state.convert_enabled.unwrap_or(false) } else { false },
|
||||
convert_format: None,
|
||||
convert_format: if remember {
|
||||
sess_state.convert_format.as_deref().and_then(parse_image_format)
|
||||
} else {
|
||||
None
|
||||
},
|
||||
progressive_jpeg: false,
|
||||
format_mapping_jpeg: 0,
|
||||
format_mapping_png: 0,
|
||||
format_mapping_webp: 0,
|
||||
format_mapping_tiff: 0,
|
||||
compress_enabled: if remember { sess_state.compress_enabled.unwrap_or(true) } else { true },
|
||||
quality_preset: pixstrip_core::types::QualityPreset::Medium,
|
||||
quality_preset: if remember {
|
||||
sess_state.quality_preset.as_deref()
|
||||
.and_then(parse_quality_preset)
|
||||
.unwrap_or(pixstrip_core::types::QualityPreset::Medium)
|
||||
} else {
|
||||
pixstrip_core::types::QualityPreset::Medium
|
||||
},
|
||||
jpeg_quality: 85,
|
||||
png_level: 3,
|
||||
webp_quality: 80,
|
||||
@@ -217,7 +260,13 @@ fn build_ui(app: &adw::Application) {
|
||||
webp_effort: 4,
|
||||
avif_speed: 6,
|
||||
metadata_enabled: if remember { sess_state.metadata_enabled.unwrap_or(true) } else { true },
|
||||
metadata_mode: MetadataMode::StripAll,
|
||||
metadata_mode: if remember {
|
||||
sess_state.metadata_mode.as_deref()
|
||||
.and_then(parse_metadata_mode)
|
||||
.unwrap_or(MetadataMode::StripAll)
|
||||
} else {
|
||||
MetadataMode::StripAll
|
||||
},
|
||||
strip_gps: true,
|
||||
strip_camera: true,
|
||||
strip_software: true,
|
||||
@@ -395,16 +444,6 @@ fn build_ui(app: &adw::Application) {
|
||||
});
|
||||
}
|
||||
|
||||
// Wire help button to show contextual help for current step
|
||||
{
|
||||
let wizard = ui.state.wizard.clone();
|
||||
let window_ref = window.clone();
|
||||
help_button.connect_clicked(move |_| {
|
||||
let step = wizard.borrow().current_step;
|
||||
show_step_help(&window_ref, step);
|
||||
});
|
||||
}
|
||||
|
||||
setup_window_actions(&window, &ui);
|
||||
update_nav_buttons(
|
||||
&ui.state.wizard.borrow(),
|
||||
|
||||
Reference in New Issue
Block a user