Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions crates/engine/src/crs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ const NON_ADJUSTMENT: &[&str] = &[
// the file's as-shot white, recorded next to the edit (ours comes from the file itself)
"crs:AsShotTemperature",
"crs:AsShotTint",
// which Lightroom version may read the edit, and checksums of the profiles it names
"crs:CompatibleVersion",
"crs:CameraProfileDigest",
"crs:LensProfileDigest",
// the lens profile Lightroom picked: ours is the file's own, only `LensProfileEnable` carries over
"crs:LensProfileName",
"crs:LensProfileFilename",
"crs:LensProfileIsEmbedded",
"crs:LensProfileSetup",
// a crop tool option (keep the crop inside the photo), not the crop itself
"crs:CropConstrainToUnitSquare",
];

/// True if the packet carries any `crs:` adjustment (not just bookkeeping fields).
Expand Down Expand Up @@ -492,6 +503,8 @@ pub fn to_partial_report(props: &Props, values: Option<&crate::crs_masks::Values
|| k == "AutoTone"
|| k == "AutoGrayscaleMix"
|| (k == "PointColors" && value_is(k, &empty_points))
// the lens profile's strength, written at its default (100 %) next to every profile
|| (matches!(k, "LensProfileDistortionScale" | "LensProfileVignettingScale") && value_is(k, &|v| v.iter().all(|s| s.trim() == "100")))
};
let mut unmapped: Vec<String> = props
.keys()
Expand Down Expand Up @@ -869,6 +882,21 @@ mod tests {
assert_eq!(got, ["FutureSlider", "PointColors"]);
}

#[test]
fn lightroom_profile_bookkeeping_is_not_reported() {
// what Lightroom Classic writes next to every raw's edit: none of it changes the rendering
let bookkeeping = r#"crs:CompatibleVersion="268435456" crs:CameraProfileDigest="0A1B" crs:LensProfileDigest="2C3D"
crs:LensProfileName="Sony FE 24-70mm" crs:LensProfileFilename="x.lcp" crs:LensProfileIsEmbedded="False"
crs:LensProfileSetup="LensDefaults" crs:LensProfileDistortionScale="100" crs:LensProfileVignettingScale="100"
crs:CropConstrainToUnitSquare="1""#;
let look = r#"<crs:Look rdf:parseType="Resource"><crs:Name>Vivid</crs:Name></crs:Look>"#;
assert_eq!(unmapped(&preset_packet(bookkeeping, "")), Vec::<String>::new());
assert_eq!(unmapped(&preset_packet(bookkeeping, look)), ["Look"], "the Look is a real gap");
// a lens profile's strength away from 100 % is an adjustment we don't carry over
let scaled = preset_packet(r#"crs:LensProfileDistortionScale="60""#, "");
assert_eq!(unmapped(&scaled), ["LensProfileDistortionScale"]);
}

#[test]
fn disabled_lens_profile_switch_keeps_embedded_corrections() {
// Lightroom applies a file's built-in lens corrections regardless of its profile switch,
Expand Down
6 changes: 5 additions & 1 deletion crates/ui-egui/src/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,12 @@ pub fn inspect(app: &LightcraftApp, ctx: &egui::Context) -> Value {
"export": {"running": app.export.as_ref().map(crate::export_task::ExportTask::status), "last": app.last_export_result},
"import": app.import.as_ref().map(crate::import::ImportTask::status),
"tasks": app.tasks.labels(),
// every long-running task in flight, as the activity stack shows them (`activity.list`)
// every long-running task in flight, as the bell's popover shows them (`activity.list`)
"activity": app.session.activity.list(),
// the bell's popover (running tasks and recent notifications) is open, and what the bell lists, newest first
"activityOpen": app.notifications.open,
"notifications": app.notifications.items.iter().map(|n| json!({"id": n.id, "text": n.text, "warning": n.warning, "details": n.report.is_some()})).collect::<Vec<_>>(),
"unread": app.notifications.unread,
// commands waiting on a native file dialog shown off the UI thread (`pick`)
"fileDialogs": app.pending_picks.iter().map(|p| p.command.clone()).collect::<Vec<_>>(),
"memory": memory(app),
Expand Down
3 changes: 2 additions & 1 deletion crates/ui-egui/src/headless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3318,8 +3318,9 @@ mod tests {
assert!(!h.app.scan.as_ref().unwrap().copy, "the running scan keeps its options");
let r = h.request("ui.inspect", json!({}), t);
assert!(r["result"]["scan"].is_object(), "{r}");
// Cancel is the ✕ of the scan's row in the activity stack (shown once it is half a second old)
// Cancel is the ✕ of the scan's row in the bell's popover (shown once it is half a second old)
let id = h.app.session.activity.list().first().map(|t| t.id).expect("a scan row");
crate::panels::activity::set_open(&mut h.app, Some(true));
let cross = format!("activity:cancel:{id}");
assert!(h.step_until(t, |h| h.app.widgets.iter().any(|(w, _)| *w == cross)), "the row shows");
let r = h.request("ui.clickWidget", json!({"id": cross}), t);
Expand Down
122 changes: 69 additions & 53 deletions crates/ui-egui/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -796,59 +796,72 @@ fn commit_batch(app: &mut LightcraftApp, task: &mut ImportTask, prepared: lightc
}
}

fn xmp_warning_text(warning: &ImportWarning) -> String {
let path = &warning.path;
/// What a warning is about, without the photo: the heading of its group in the import report.
fn warning_headings(warning: &ImportWarning) -> Vec<String> {
use crate::i18n::tr;
match warning.code {
ImportWarningCode::CameraProfile => crate::i18n::tr_format!(
"XMP profile \"{profile}\" was not applied for {path}; colors may differ from Lightroom.",
profile = warning.profile.as_deref().unwrap_or_default(),
path = path,
),
ImportWarningCode::UprightGeometry => match warning.mode.unwrap_or(ImportUprightMode::Unknown) {
ImportUprightMode::Off => crate::i18n::tr_format!(
"Lightroom geometry for {path} was not preserved; saved transform is ignored because Upright is Off.",
path = path,
),
ImportUprightMode::Guided => crate::i18n::tr_format!(
"Lightroom geometry for {path} was not preserved; Guided Upright saved transform is unsupported.",
path = path,
),
ImportUprightMode::Auto => crate::i18n::tr_format!(
"Lightroom geometry was not preserved for {path}; {mode} will be recalculated.",
path = path,
mode = crate::i18n::tr("Auto")
),
ImportUprightMode::Level => crate::i18n::tr_format!(
"Lightroom geometry was not preserved for {path}; {mode} will be recalculated.",
path = path,
mode = crate::i18n::tr("Level")
),
ImportUprightMode::Vertical => crate::i18n::tr_format!(
"Lightroom geometry was not preserved for {path}; {mode} will be recalculated.",
path = path,
mode = crate::i18n::tr("Vertical")
),
ImportUprightMode::Full => crate::i18n::tr_format!(
"Lightroom geometry was not preserved for {path}; {mode} will be recalculated.",
path = path,
mode = crate::i18n::tr("Full")
),
ImportUprightMode::Unknown => {
crate::i18n::tr_format!("Lightroom geometry for {path} was not preserved; saved Upright transform is unsupported.", path = path,)
ImportWarningCode::CameraProfile => {
vec![format!("{}: {}", tr("Profile not applied, colors may differ from Lightroom"), warning.profile.as_deref().unwrap_or_default())]
}
ImportWarningCode::UprightGeometry => vec![
tr(match warning.mode.unwrap_or(ImportUprightMode::Unknown) {
ImportUprightMode::Off => "Saved Lightroom geometry ignored: Upright is Off",
ImportUprightMode::Guided => "Guided Upright geometry is not supported",
ImportUprightMode::Auto => "Upright Auto will be recalculated",
ImportUprightMode::Level => "Upright Level will be recalculated",
ImportUprightMode::Vertical => "Upright Vertical will be recalculated",
ImportUprightMode::Full => "Upright Full will be recalculated",
ImportUprightMode::Unknown => "Saved Upright geometry is not supported",
})
.to_string(),
],
ImportWarningCode::UnmappedXmp => warning.fields.iter().map(|field| format!("{}: {field}", tr("Not imported"))).collect(),
}
}

/// How many photos the warnings are about.
fn warned_photos(warnings: &[ImportWarning]) -> usize {
let mut paths: Vec<&str> = warnings.iter().map(|w| w.path.as_str()).collect();
paths.sort_unstable();
paths.dedup();
paths.len()
}

/// The import's warnings as a report: one group per problem (a Lightroom setting not carried over, a profile not
/// applied…) listing the photos it concerns, in the order the problems first came up.
pub(crate) fn warnings_report(warnings: &[ImportWarning]) -> crate::notifications::Report {
let mut groups: Vec<crate::notifications::ReportGroup> = Vec::new();
for w in warnings {
for heading in warning_headings(w) {
let i = match groups.iter().position(|g| g.heading == heading) {
Some(i) => i,
None => {
groups.push(crate::notifications::ReportGroup { heading, items: Vec::new() });
groups.len() - 1
}
};
if let Some(g) = groups.get_mut(i)
&& !g.items.contains(&w.path)
{
g.items.push(w.path.clone());
}
},
ImportWarningCode::UnmappedXmp => {
crate::i18n::tr_format!("XMP adjustments were not imported for {path}: {fields}.", path = path, fields = warning.fields.join(", "),)
}
}
let n = warned_photos(warnings);
crate::notifications::Report {
title: crate::i18n::tr("Import Warnings").to_string(),
summary: format!(
"{}: {n}. {}",
crate::i18n::tr("Photos with Lightroom settings LightCraft didn't apply"),
crate::i18n::tr("Their other edits were imported.")
),
groups,
}
}

fn xmp_warnings_text(warnings: &[ImportWarning]) -> String {
crate::i18n::tr_format!(
"Import warnings ({n}):\n{warnings}",
n = warnings.len(),
warnings = warnings.iter().map(xmp_warning_text).collect::<Vec<_>>().join("\n"),
)
/// The toast's line for the warnings (the report has the rest).
fn warnings_line(warnings: &[ImportWarning]) -> String {
format!("{}: {}", crate::i18n::tr("Lightroom settings not applied"), warned_photos(warnings))
}

/// The import is done (or cancelled): one undo step, show and select the first photo (unless the
Expand All @@ -866,15 +879,18 @@ fn finish(app: &mut LightcraftApp, ctx: &egui::Context, task: ImportTask) {
app.session.merge_undo(steps, &label);
if task.auto {
if !task.warnings.is_empty() {
app.toast_for(ctx, xmp_warnings_text(&task.warnings), 8.0);
let added = crate::i18n::tr_format!("Auto Import: added {} photo{}", task.imported, if task.imported == 1 { "" } else { "s" });
let msg = format!("{added} · {}", warnings_line(&task.warnings));
app.notify(ctx, msg, true, Some(warnings_report(&task.warnings)));
} else if task.imported > 0 {
app.toast(ctx, crate::i18n::tr_format!("Auto Import: added {} photo{}", task.imported, if task.imported == 1 { "" } else { "s" }));
}
return;
}
if task.browse {
if !task.warnings.is_empty() {
app.toast_for(ctx, xmp_warnings_text(&task.warnings), 8.0);
let msg = format!("{} · {}", crate::i18n::tr("Photos added"), warnings_line(&task.warnings));
app.notify(ctx, msg, true, Some(warnings_report(&task.warnings)));
} else if task.failed > 0 {
app.toast(ctx, crate::i18n::tr_format!("{} photo{} not readable", task.failed, if task.failed == 1 { "" } else { "s" }));
}
Expand Down Expand Up @@ -927,11 +943,11 @@ fn finish(app: &mut LightcraftApp, ctx: &egui::Context, task: ImportTask) {
msg.push_str(&crate::i18n::tr_format!(" · {} not readable", task.failed));
}
if task.warnings.is_empty() {
app.toast(ctx, msg);
app.notify(ctx, msg, task.failed > 0, None);
} else {
msg.push_str("\n\n");
msg.push_str(&xmp_warnings_text(&task.warnings));
app.toast_for(ctx, msg, 8.0);
msg.push_str(" · ");
msg.push_str(&warnings_line(&task.warnings));
app.notify(ctx, msg, true, Some(warnings_report(&task.warnings)));
}
}

Expand Down
43 changes: 38 additions & 5 deletions crates/ui-egui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub mod menubar;
pub mod menus;
pub mod merge;
mod model_setup;
pub mod notifications;
pub mod panels;
pub mod pick;
pub mod print_view;
Expand Down Expand Up @@ -476,8 +477,10 @@ pub struct LightcraftApp {
/// The library failed to open at launch: the blocking window, then the temporary-session
/// banner (issue #100). Cleared once a library opens.
pub library_problem: Option<panels::library_problem::LibraryProblem>,
/// The activity stack shows every task, not just the first few ("+N more" was clicked).
pub activity_expanded: bool,
/// Recent outcomes the bell lists, and whether its popover is open.
pub notifications: notifications::Notifications,
/// The toast on show has a Details link: its text, and the notification whose report it opens.
pub toast_link: Option<(String, u64)>,
}

impl LightcraftApp {
Expand Down Expand Up @@ -555,7 +558,8 @@ impl LightcraftApp {
screen_profile: None,
screen_profile_read: None,
library_problem: None,
activity_expanded: false,
notifications: Default::default(),
toast_link: None,
model_setup: Default::default(),
}
}
Expand Down Expand Up @@ -881,10 +885,39 @@ impl LightcraftApp {
}
}

/// A toast for an error the user has to read and act on (stays 6 s).
/// A toast for an error the user has to read and act on (stays 6 s, and in the bell's list).
pub fn toast_error(&mut self, ctx: &egui::Context, text: impl Into<String>) {
let t = ctx.input(|i| i.time);
self.ui.toast = Some((text.into(), t + 6.0, None));
let text = text.into();
self.notifications.push(text.clone(), true, None, t);
self.ui.toast = Some((text, t + 6.0, None));
}

/// Tell how something ended: a toast, kept in the bell's list. With a `report`, the toast stays 8 s and has a
/// Details link that opens it (the toast says what happened in a line; the report lists it all).
pub fn notify(&mut self, ctx: &egui::Context, text: impl Into<String>, warning: bool, report: Option<notifications::Report>) {
let t = ctx.input(|i| i.time);
let text = text.into();
let linked = report.is_some();
let id = self.notifications.push(text.clone(), warning, report, t);
self.toast_link = linked.then(|| (text.clone(), id));
self.ui.toast = Some((text, t + if linked || warning { 8.0 } else { TOAST_SECONDS }, None));
}

/// Open notification `id`'s report (its Details link).
pub fn show_report(&mut self, id: u64) -> bool {
// (never over a dialog in progress: it would lose what was typed there)
if self.ui.dialog.is_some() {
return false;
}
let Some(report) = self.notifications.get(id).and_then(|n| n.report.clone()) else { return false };
self.ui.dialog = Some(state::Dialog::Report { report });
// the toast that led here has done its job (it would sit on the report)
if self.toast_link.as_ref().is_some_and(|(_, linked)| *linked == id) {
self.ui.toast = None;
self.toast_link = None;
}
true
}

fn drain_control(&mut self, ctx: &egui::Context) {
Expand Down
6 changes: 6 additions & 0 deletions crates/ui-egui/src/menus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ pub const UI_COMMANDS: &[UiCommand] = &[
("view.back", "Back to Grid", Some("Escape"), ""),
("tool.done", "Done", Some("Enter"), ""),
("view.filterBar", "Filter Bar", Some("Shift+F"), "View"),
// {open?}: the top bar's bell popover (running tasks, recent notifications); no params toggles
("view.activity", "Activity & Notifications", None, "Window"),
("local.addRoot", "Add Folder to Local", None, ""),
("local.hide", "Remove from Local", None, ""),
("local.restoreHidden", "Show Hidden Local Locations", None, ""),
Expand Down Expand Up @@ -1099,6 +1101,10 @@ pub fn run_ui_command(app: &mut LightcraftApp, id: &str, p: &Value) -> Option<Re
app.ui.set_single_panel(on.unwrap_or(!app.ui.single_panel));
json!({"soloSections": app.ui.single_panel})
}),
"view.activity" => bool_param(id, p, "open").map(|open| {
crate::panels::activity::set_open(app, open);
json!({"open": app.notifications.open})
}),
"view.filterBar" => {
app.ui.filter_bar = !app.ui.filter_bar;
if app.ui.filter_bar && !matches!(app.ui.view, ViewMode::PhotoGrid | ViewMode::SquareGrid) {
Expand Down
Loading
Loading