code: Use chained if-let's

This commit is contained in:
Sophie Herold 2026-01-29 19:04:26 +01:00
parent f806bbd484
commit 8972c5efb9
12 changed files with 219 additions and 235 deletions

View file

@ -201,12 +201,12 @@ impl Decoder {
/// Request missing tiles /// Request missing tiles
pub fn request(&self, tile_request: TileRequest) { pub fn request(&self, tile_request: TileRequest) {
if let FormatDecoder::Svg(svg) = &self.decoder { if let FormatDecoder::Svg(svg) = &self.decoder
if let Err(err) = svg.request(tile_request) { && let Err(err) = svg.request(tile_request)
{
tracing::error!("Failed to request new SVG tiles: {err}"); tracing::error!("Failed to request new SVG tiles: {err}");
} }
} }
}
pub fn fill_frame_buffer(&self) { pub fn fill_frame_buffer(&self) {
if let FormatDecoder::Glycin(decoder) = &self.decoder { if let FormatDecoder::Glycin(decoder) = &self.decoder {

View file

@ -369,14 +369,13 @@ impl Metadata {
let location_exact = libgweather::Location::new_detached("", None, lat, lon); let location_exact = libgweather::Location::new_detached("", None, lat, lon);
// do not use city if more than 15 km away // do not use city if more than 15 km away
if nearest_city.distance(&location_exact) < 15. { if nearest_city.distance(&location_exact) < 15.
if let (Some(city), Some(country)) = && let (Some(city), Some(country)) =
(nearest_city.city_name(), nearest_city.country_name()) (nearest_city.city_name(), nearest_city.country_name())
{ {
return Some(format!("{city}, {country}")); return Some(format!("{city}, {country}"));
} }
} }
}
self.gps_location_display() self.gps_location_display()
} else { } else {

View file

@ -63,12 +63,13 @@ pub fn apply_unicode_escapes(s: impl AsRef<str>) -> Option<String> {
while let Some(c) = char_iter.next() { while let Some(c) = char_iter.next() {
match state { match state {
State::None if c == '\\' => { State::None if c == '\\' => {
if let (Some(c1), Some(c2)) = (char_iter.next(), char_iter.next()) { if let (Some(c1), Some(c2)) = (char_iter.next(), char_iter.next())
if c1 == 'u' && c2 == '{' { && c1 == 'u'
&& c2 == '{'
{
state = State::UnicodeHex; state = State::UnicodeHex;
} }
} }
}
State::None => new.push(c), State::None => new.push(c),
State::UnicodeHex => { State::UnicodeHex => {
if c == '}' { if c == '}' {

View file

@ -252,9 +252,9 @@ mod imp {
let obj = self.obj(); let obj = self.obj();
self.save.popdown(); self.save.popdown();
if let Some(original_file) = obj.original_image().file() { if let Some(original_file) = obj.original_image().file()
if let Some(current_path) = original_file.path() { && let Some(current_path) = original_file.path()
if let Some(mut file_stem) = current_path.file_stem().map(|x| x.to_os_string()) && let Some(mut file_stem) = current_path.file_stem().map(|x| x.to_os_string())
{ {
let mut tmp_path = current_path.clone(); let mut tmp_path = current_path.clone();
file_stem.push(".tmp"); file_stem.push(".tmp");
@ -298,11 +298,7 @@ mod imp {
return; return;
} }
tracing::debug!( tracing::debug!("Moving '{}' to '{}'", tmp_file.uri(), original_file.uri());
"Moving '{}' to '{}'",
tmp_file.uri(),
original_file.uri()
);
let move_result = gio::CancellableFuture::new( let move_result = gio::CancellableFuture::new(
tmp_file tmp_file
.move_future( .move_future(
@ -334,8 +330,6 @@ mod imp {
} }
} }
} }
}
}
#[must_use] #[must_use]
/// Saves image with operations applies /// Saves image with operations applies

View file

@ -303,8 +303,9 @@ impl imp::LpImage {
let zoom = imp.zoom_target.get() * scale; let zoom = imp.zoom_target.get() * scale;
// Move image with fingers on touchscreens // Move image with fingers on touchscreens
if gesture.device().map(|x| x.source()) == Some(gdk::InputSource::Touchscreen) { if gesture.device().map(|x| x.source()) == Some(gdk::InputSource::Touchscreen)
if let p1 @ Some((x1, y1)) = gesture.bounding_box_center() { && let p1 @ Some((x1, y1)) = gesture.bounding_box_center()
{
if let Some((x0, y0)) = imp.zoom_gesture_center.get() { if let Some((x0, y0)) = imp.zoom_gesture_center.get() {
imp.set_hadj_value(imp.hadj_value() + x0 - x1); imp.set_hadj_value(imp.hadj_value() + x0 - x1);
imp.set_vadj_value(imp.vadj_value() + y0 - y1); imp.set_vadj_value(imp.vadj_value() + y0 - y1);
@ -314,7 +315,6 @@ impl imp::LpImage {
imp.zoom_gesture_center.set(p1); imp.zoom_gesture_center.set(p1);
} }
}
let zoom_out_threshold = 1. / ZOOM_GESTURE_LOCK_THRESHOLD; let zoom_out_threshold = 1. / ZOOM_GESTURE_LOCK_THRESHOLD;
let zoom_in_threshold = ZOOM_GESTURE_LOCK_THRESHOLD; let zoom_in_threshold = ZOOM_GESTURE_LOCK_THRESHOLD;

View file

@ -186,8 +186,9 @@ impl imp::LpImage {
} }
pub(super) fn request_tiles(&self) { pub(super) fn request_tiles(&self) {
if let Some(decoder) = self.decoder.borrow().as_ref() { if let Some(decoder) = self.decoder.borrow().as_ref()
if self.zoom_animation().state() != adw::AnimationState::Playing { && self.zoom_animation().state() != adw::AnimationState::Playing
{
// Force minimum tile size of 1000x1000 since with smaller // Force minimum tile size of 1000x1000 since with smaller
// tiles the tiled rendering advantage disappears // tiles the tiled rendering advantage disappears
let x_inset = f32::min(-3., (self.viewport().width() - 1000.) / 2.); let x_inset = f32::min(-3., (self.viewport().width() - 1000.) / 2.);
@ -200,7 +201,6 @@ impl imp::LpImage {
}); });
} }
} }
}
/// File changed on drive /// File changed on drive
fn file_changed( fn file_changed(
@ -287,19 +287,16 @@ impl imp::LpImage {
async fn check_editable(&self) { async fn check_editable(&self) {
let obj = self.obj(); let obj = self.obj();
if let Some(mime_type) = obj.metadata().mime_type() { if let Some(mime_type) = obj.metadata().mime_type()
if let Ok(supported_formats) = glycin::config::Config::cached() && let Ok(supported_formats) = glycin::config::Config::cached()
.await .await
.editor(&mime_type.as_str().into()) .editor(&mime_type.as_str().into())
{ && LpEditWindow::REQUIRED_OPERATIONS
if LpEditWindow::REQUIRED_OPERATIONS
.iter() .iter()
.all(|x| supported_formats.operations.contains(x)) .all(|x| supported_formats.operations.contains(x))
{ {
self.editable.set(true); self.editable.set(true);
obj.notify_editable(); obj.notify_editable();
}
}
}; };
} }
} }

View file

@ -158,8 +158,10 @@ impl WidgetImpl for imp::LpImage {
let image_width = image_width_i32 as f64; let image_width = image_width_i32 as f64;
let image_height = image_height_i32 as f64; let image_height = image_height_i32 as f64;
if image_width_i32 > 0 && image_height_i32 > 0 { if image_width_i32 > 0
if let Some((monitor_width, monitor_height)) = self.monitor_size() { && image_height_i32 > 0
&& let Some((monitor_width, monitor_height)) = self.monitor_size()
{
let hidpi_scale = self.scaling(); let hidpi_scale = self.scaling();
tracing::trace!("Physical monitor dimensions: {monitor_width} x {monitor_height}"); tracing::trace!("Physical monitor dimensions: {monitor_width} x {monitor_height}");
@ -169,9 +171,7 @@ impl WidgetImpl for imp::LpImage {
let image_area = image_width * image_height; let image_area = image_width * image_height;
let occupy_area_factor = if logical_monitor_area <= SMALL_SCREEN_AREA { let occupy_area_factor = if logical_monitor_area <= SMALL_SCREEN_AREA {
tracing::trace!( tracing::trace!("Small monitor detected: Using {SMALL_OCCUPY_SCREEN} screen area");
"Small monitor detected: Using {SMALL_OCCUPY_SCREEN} screen area"
);
SMALL_OCCUPY_SCREEN SMALL_OCCUPY_SCREEN
} else { } else {
tracing::trace!( tracing::trace!(
@ -214,7 +214,6 @@ impl WidgetImpl for imp::LpImage {
return (0, size as i32, -1, -1); return (0, size as i32, -1, -1);
} }
}
// fallback if monitor size or image size is not known: // fallback if monitor size or image size is not known:
// use original image size and hope for the best // use original image size and hope for the best
@ -338,9 +337,10 @@ impl imp::LpImage {
pub fn monitor_size(&self) -> Option<(f64, f64)> { pub fn monitor_size(&self) -> Option<(f64, f64)> {
let obj = self.obj(); let obj = self.obj();
if let Some(display) = gdk::Display::default() { if let Some(display) = gdk::Display::default()
if let Some(surface) = obj.native().and_then(|x| x.surface()) { && let Some(surface) = obj.native().and_then(|x| x.surface())
if let Some(monitor) = display.monitor_at_surface(&surface) { && let Some(monitor) = display.monitor_at_surface(&surface)
{
let hidpi_scale = self.scaling(); let hidpi_scale = self.scaling();
let monitor_geometry = monitor.geometry(); let monitor_geometry = monitor.geometry();
@ -349,8 +349,6 @@ impl imp::LpImage {
monitor_geometry.height() as f64 * hidpi_scale, monitor_geometry.height() as f64 * hidpi_scale,
)); ));
} }
}
}
None None
} }

View file

@ -104,8 +104,9 @@ impl LpImage {
zoom_animation.play(); zoom_animation.play();
} }
if let Ok(r) = gufo_common::orientation::Rotation::try_from(angle) { if let Ok(r) = gufo_common::orientation::Rotation::try_from(angle)
if r != gufo_common::orientation::Rotation::_0 { && r != gufo_common::orientation::Rotation::_0
{
tracing::debug!("Editing image to rotate by {r:?}"); tracing::debug!("Editing image to rotate by {r:?}");
let operation = glycin::Operation::Rotate(r); let operation = glycin::Operation::Rotate(r);
let editing_queue = &self.imp().editing_queue; let editing_queue = &self.imp().editing_queue;
@ -114,4 +115,3 @@ impl LpImage {
} }
} }
} }
}

View file

@ -303,12 +303,12 @@ mod imp {
#[weak] #[weak]
obj, obj,
move |_| { move |_| {
if let Some(page) = obj.current_page() { if let Some(page) = obj.current_page()
if let Some(value) = obj.zoom_value_f64() { && let Some(value) = obj.zoom_value_f64()
{
page.image().zoom_to_no_best_fit(value); page.image().zoom_to_no_best_fit(value);
} }
} }
}
)); ));
self.drag_source.set_exclusive(true); self.drag_source.set_exclusive(true);
@ -717,14 +717,14 @@ impl LpImageView {
/// Handle files are added or removed from directory /// Handle files are added or removed from directory
fn model_content_changed_cb(&self, file_event: &FileEvent) { fn model_content_changed_cb(&self, file_event: &FileEvent) {
// Animate to image that was restored from trash // Animate to image that was restored from trash
if let Some(trash_restore) = self.trash_restore() { if let Some(trash_restore) = self.trash_restore()
if self.model().contains_file(&trash_restore) { && self.model().contains_file(&trash_restore)
{
self.set_trash_restore(gio::File::NONE); self.set_trash_restore(gio::File::NONE);
self.update_sliding_view(&trash_restore); self.update_sliding_view(&trash_restore);
self.scroll_sliding_view(&trash_restore, true); self.scroll_sliding_view(&trash_restore, true);
return; return;
} }
}
let Some(current_file) = self.current_file() else { let Some(current_file) = self.current_file() else {
return; return;
@ -742,12 +742,12 @@ impl LpImageView {
page.image().init(&target_file); page.image().init(&target_file);
} }
// File that delayed move is set for is now available // File that delayed move is set for is now available
if let Some(delayed_current_file) = self.delayed_current_file() { if let Some(delayed_current_file) = self.delayed_current_file()
if target_file.equal(&delayed_current_file) { && target_file.equal(&delayed_current_file)
{
self.navigate_to_file(&delayed_current_file); self.navigate_to_file(&delayed_current_file);
} }
} }
}
FileEvent::New(new) => { FileEvent::New(new) => {
// File that delayed move is set for is now available // File that delayed move is set for is now available
if let Some(delayed_current_file) = self.delayed_current_file() { if let Some(delayed_current_file) = self.delayed_current_file() {

View file

@ -575,11 +575,11 @@ impl LpImageWindow {
if let Some(ref file) = imp.image_view.current_file() { if let Some(ref file) = imp.image_view.current_file() {
let launcher = gtk::FileLauncher::new(Some(file)); let launcher = gtk::FileLauncher::new(Some(file));
launcher.set_always_ask(true); launcher.set_always_ask(true);
if let Err(e) = launcher.launch_future(self.try_window().as_ref()).await { if let Err(e) = launcher.launch_future(self.try_window().as_ref()).await
if !e.matches(gtk::DialogError::Dismissed) { && !e.matches(gtk::DialogError::Dismissed)
{
tracing::error!("Could not open image in external program: {}", e); tracing::error!("Could not open image in external program: {}", e);
} }
}
} else { } else {
tracing::error!("Could not load a path for the current image.") tracing::error!("Could not load a path for the current image.")
} }
@ -611,13 +611,12 @@ impl LpImageWindow {
return false; return false;
}; };
if let Some(focus_widget) = GtkWindowExt::focus(&window) { if let Some(focus_widget) = GtkWindowExt::focus(&window)
if focus_widget.is_ancestor(&*self.imp().properties_view) { && focus_widget.is_ancestor(&*self.imp().properties_view)
if let Ok(label) = focus_widget.downcast::<gtk::Label>() { && let Ok(label) = focus_widget.downcast::<gtk::Label>()
{
return label.selection_bounds().is_some(); return label.selection_bounds().is_some();
} }
}
}
false false
} }

View file

@ -388,18 +388,16 @@ mod imp {
.set_value(size_unit.round(obj.original_size().0 * obj.width_unit_factor())); .set_value(size_unit.round(obj.original_size().0 * obj.width_unit_factor()));
// Default to inch for USA and Liberia // Default to inch for USA and Liberia
if let Some(unit_locale) = getlocale(gettextrs::LocaleCategory::LcMeasurement) { if let Some(unit_locale) = getlocale(gettextrs::LocaleCategory::LcMeasurement)
if let Some(locale) = unit_locale && let Some(locale) = unit_locale
.split(|x| *x == b'_') .split(|x| *x == b'_')
.nth(1) .nth(1)
.and_then(|x| x.get(0..2)) .and_then(|x| x.get(0..2))
&& (locale == b"US" || locale == b"LR")
{ {
if locale == b"US" || locale == b"LR" {
imp.margin_unit.set_selected(Unit::Inch as u32); imp.margin_unit.set_selected(Unit::Inch as u32);
imp.size_unit.set_selected(Unit::Inch as u32); imp.size_unit.set_selected(Unit::Inch as u32);
} }
}
}
let orientation = match obj.page_setup().orientation() { let orientation = match obj.page_setup().orientation() {
gtk::PageOrientation::Portrait => "portrait", gtk::PageOrientation::Portrait => "portrait",

View file

@ -246,8 +246,8 @@ mod imp {
if matches!( if matches!(
*self.position_tracking.borrow(), *self.position_tracking.borrow(),
PositionTracking::Position(_) PositionTracking::Position(_)
) { ) && let Some(mut child) = obj.first_child()
if let Some(mut child) = obj.first_child() { {
let mut children = vec![child.clone()]; let mut children = vec![child.clone()];
while let Some(new_child) = child.next_sibling() { while let Some(new_child) = child.next_sibling() {
child = new_child; child = new_child;
@ -255,14 +255,13 @@ mod imp {
} }
for child in children { for child in children {
if let Ok(page) = child.downcast::<LpImagePage>() { if let Ok(page) = child.downcast::<LpImagePage>()
if obj.index_of(&page).is_none() { && obj.index_of(&page).is_none()
{
page.unparent(); page.unparent();
} }
} }
} }
}
}
for (page_index, page) in self.pages.borrow().iter().enumerate() { for (page_index, page) in self.pages.borrow().iter().enumerate() {
match *self.position_tracking.borrow() { match *self.position_tracking.borrow() {
@ -612,8 +611,8 @@ impl LpSlidingView {
/// Move to image with cards animation /// Move to image with cards animation
fn step_to(&self, page: &LpImagePage) { fn step_to(&self, page: &LpImagePage) {
let animation = self.step_animation(); let animation = self.step_animation();
if let Some(prev_page) = self.current_page() { if let Some(prev_page) = self.current_page()
if let (Some(prev_index), Some(new_index)) = && let (Some(prev_index), Some(new_index)) =
(self.index_of(&prev_page), self.index_of(page)) (self.index_of(&prev_page), self.index_of(page))
{ {
let backward = new_index < prev_index; let backward = new_index < prev_index;
@ -625,7 +624,6 @@ impl LpSlidingView {
self.set_current_page(Some(page)); self.set_current_page(Some(page));
animation.play(); animation.play();
} }
}
self.set_current_page(Some(page)); self.set_current_page(Some(page));
} }