Use tracing for logging

This commit is contained in:
Sophie Herold 2025-12-18 23:15:46 +01:00
parent f255af9f6a
commit 4d6d771ab4
36 changed files with 260 additions and 223 deletions

10
Cargo.lock generated
View file

@ -1587,9 +1587,9 @@ dependencies = [
"libadwaita", "libadwaita",
"libc", "libc",
"libgweather", "libgweather",
"log",
"strum", "strum",
"thiserror", "thiserror",
"tracing",
"tracing-subscriber", "tracing-subscriber",
"url", "url",
] ]
@ -2331,9 +2331,9 @@ checksum = "df8b2b54733674ad286d16267dcfc7a71ed5c776e4ac7aa3c3e2561f7c637bf2"
[[package]] [[package]]
name = "tracing" name = "tracing"
version = "0.1.43" version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d15d90a0b5c19378952d479dc858407149d7bb45a14de0142f6c534b16fc647" checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100"
dependencies = [ dependencies = [
"pin-project-lite", "pin-project-lite",
"tracing-attributes", "tracing-attributes",
@ -2353,9 +2353,9 @@ dependencies = [
[[package]] [[package]]
name = "tracing-core" name = "tracing-core"
version = "0.1.35" version = "0.1.36"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a04e24fab5c89c6a36eb8558c9656f30d81de51dfa4d3b45f26b21d61fa0a6c" checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a"
dependencies = [ dependencies = [
"once_cell", "once_cell",
"valuable", "valuable",

View file

@ -40,8 +40,8 @@ gvdb-macros = "0.1.6"
indexmap = "2.0.0" indexmap = "2.0.0"
libc = "0.2.158" libc = "0.2.158"
libgweather = "4.4.0" libgweather = "4.4.0"
log = "0.4.17"
strum = { version = "0.27.1", features = ["derive"] } strum = { version = "0.27.1", features = ["derive"] }
thiserror = "2.0.3" thiserror = "2.0.3"
tracing = "0.1.44"
tracing-subscriber = { version = "0.3.18", features = ["fmt", "env-filter"] } tracing-subscriber = { version = "0.3.18", features = ["fmt", "env-filter"] }
url = "2.3.1" url = "2.3.1"

View file

@ -69,7 +69,7 @@ mod imp {
impl ApplicationImpl for LpApplication { impl ApplicationImpl for LpApplication {
fn startup(&self) { fn startup(&self) {
log::trace!("Startup"); tracing::trace!("Startup");
self.parent_startup(); self.parent_startup();
// Force dark theme // Force dark theme
@ -82,7 +82,7 @@ mod imp {
} }
fn activate(&self) { fn activate(&self) {
log::debug!("Showing window via 'activate'"); tracing::debug!("Showing window via 'activate'");
let application = self.obj(); let application = self.obj();
let window = LpWindow::new(&*application); let window = LpWindow::new(&*application);
window.present(); window.present();
@ -90,7 +90,7 @@ mod imp {
// Handles opening files from the command line or other applications // Handles opening files from the command line or other applications
fn open(&self, files: &[gio::File], _hint: &str) { fn open(&self, files: &[gio::File], _hint: &str) {
log::trace!("Open {} file(s)", files.len()); tracing::trace!("Open {} file(s)", files.len());
let application = self.obj(); let application = self.obj();
let win = LpWindow::new(&*application); let win = LpWindow::new(&*application);
win.image_view().set_images_from_files(files.to_vec()); win.image_view().set_images_from_files(files.to_vec());
@ -138,7 +138,7 @@ impl LpApplication {
gio::ActionEntryBuilder::new("new-window") gio::ActionEntryBuilder::new("new-window")
.activate(|app: &Self, _, _| { .activate(|app: &Self, _, _| {
let win = LpWindow::new(app); let win = LpWindow::new(app);
log::debug!("Showing new window"); tracing::debug!("Showing new window");
win.present(); win.present();
}) })
.build(), .build(),
@ -160,7 +160,7 @@ impl LpApplication {
if let Err(e) = if let Err(e) =
gio::AppInfo::launch_default_for_uri_future("help:loupe", context.as_ref()).await gio::AppInfo::launch_default_for_uri_future("help:loupe", context.as_ref()).await
{ {
log::error!("Failed to launch help: {}", e.message()); tracing::error!("Failed to launch help: {}", e.message());
} }
}); });
} }

View file

@ -100,8 +100,8 @@ impl UpdateSender {
let result = self.sender.force_send(update); let result = self.sender.force_send(update);
match result { match result {
Err(err) => log::error!("Failed to send update: {err}"), Err(err) => tracing::error!("Failed to send update: {err}"),
Ok(Some(msg)) => log::error!("Unexpectedly replaced the message {msg:?}"), Ok(Some(msg)) => tracing::error!("Unexpectedly replaced the message {msg:?}"),
_ => {} _ => {}
} }
} }
@ -171,7 +171,7 @@ impl Decoder {
let update_sender = UpdateSender { sender }; let update_sender = UpdateSender { sender };
tiles.set_update_sender(update_sender.clone()); tiles.set_update_sender(update_sender.clone());
log::trace!("Setting up loader"); tracing::trace!("Setting up loader");
let mut loader = glycin::Loader::new(file); let mut loader = glycin::Loader::new(file);
loader.apply_transformations(false); loader.apply_transformations(false);
@ -229,7 +229,7 @@ impl Decoder {
if let FormatDecoder::Glycin(decoder) = &self.decoder { if let FormatDecoder::Glycin(decoder) = &self.decoder {
decoder.fill_frame_buffer(); decoder.fill_frame_buffer();
} else { } else {
log::error!("Trying to fill frame buffer for decoder without animation support"); tracing::error!("Trying to fill frame buffer for decoder without animation support");
} }
} }
} }

View file

@ -20,6 +20,7 @@
use std::sync::Arc; use std::sync::Arc;
use gtk::prelude::*; use gtk::prelude::*;
use tracing::Instrument;
use super::*; use super::*;
use crate::decoder::tiling::{self, SharedFrameBuffer}; use crate::decoder::tiling::{self, SharedFrameBuffer};
@ -47,7 +48,15 @@ impl Glycin {
let (next_frame_send, next_frame_recv) = async_channel::bounded(2); let (next_frame_send, next_frame_recv) = async_channel::bounded(2);
updater.clone().spawn_error_handled(async move { let span = tracing::debug_span!(
"proxy",
image = image
.file()
.and_then(|x| x.basename())
.map(|x| x.display().to_string())
);
updater.clone().spawn_error_handled(
async move {
let mut metadata: Metadata = Metadata::default(); let mut metadata: Metadata = Metadata::default();
metadata.set_image_info(image.details().clone()); metadata.set_image_info(image.details().clone());
metadata.set_mime_type(image.mime_type().to_string()); metadata.set_mime_type(image.mime_type().to_string());
@ -99,7 +108,7 @@ impl Glycin {
} }
} }
} else { } else {
log::debug!("Animation handler gone"); tracing::debug!("Animation handler gone");
return Ok(()); return Ok(());
} }
} }
@ -115,7 +124,9 @@ impl Glycin {
} }
Ok(()) Ok(())
}); }
.instrument(span),
);
Self { Self {
cancellable, cancellable,

View file

@ -87,7 +87,7 @@ impl Svg {
}; };
if cancellable.is_cancelled() { if cancellable.is_cancelled() {
log::debug!("Terminating SVG decoder thread"); tracing::debug!("Terminating SVG decoder thread");
break; break;
} }

View file

@ -104,7 +104,7 @@ impl Tile {
let area_with_bleed = round(&self.area_with_bleed().scale(zoom, zoom)); let area_with_bleed = round(&self.area_with_bleed().scale(zoom, zoom));
if area_with_bleed.width() < 1. || area_with_bleed.height() < 1. { if area_with_bleed.width() < 1. || area_with_bleed.height() < 1. {
log::warn!("Trying to draw image with dimensions smaller than 1"); tracing::warn!("Trying to draw image with dimensions smaller than 1");
return; return;
} }
@ -169,7 +169,7 @@ impl FrameBuffer {
if let Some(tiling) = self.images.front() { if let Some(tiling) = self.images.front() {
tiling.add_to_snapshot(snapshot, zoom, options); tiling.add_to_snapshot(snapshot, zoom, options);
} else { } else {
log::error!("Trying to snapshot empty tiling queue"); tracing::error!("Trying to snapshot empty tiling queue");
} }
} }
@ -227,7 +227,7 @@ impl TiledImage {
.flat_map(|(_, tiles)| tiles) .flat_map(|(_, tiles)| tiles)
.collect(); .collect();
log::trace!("Rendering {} tiles", tiles.len()); tracing::trace!("Rendering {} tiles", tiles.len());
// Scale from application pixels back to physical pixels // Scale from application pixels back to physical pixels
snapshot.scale(1. / options.scaling as f32, 1. / options.scaling as f32); snapshot.scale(1. / options.scaling as f32, 1. / options.scaling as f32);
@ -396,11 +396,13 @@ impl TiledImage {
missing_tiles = next_missing_tiles; missing_tiles = next_missing_tiles;
} else { } else {
log::error!("Images should never have multiple 'Simple' layers: {tile_layer:?}"); tracing::error!(
"Images should never have multiple 'Simple' layers: {tile_layer:?}"
);
} }
} }
log::trace!( tracing::trace!(
"Cleanup kept {} tiles", "Cleanup kept {} tiles",
kept_tiles kept_tiles
.tile_layers .tile_layers

View file

@ -51,7 +51,7 @@ impl Queue {
glib::spawn_future_local(async move { glib::spawn_future_local(async move {
let lock: async_lock::MutexGuard<()> = queue.lock.lock().await; let lock: async_lock::MutexGuard<()> = queue.lock.lock().await;
if let Err(err) = queue.apply(image).await { if let Err(err) = queue.apply(image).await {
log::error!("Err: {err}"); tracing::error!("Err: {err}");
} }
drop(lock); drop(lock);
}); });
@ -72,7 +72,7 @@ impl Queue {
let edit_instruction = editor.apply_sparse(&operations).await?; let edit_instruction = editor.apply_sparse(&operations).await?;
if edit_instruction.apply_to(file).await? == EditOutcome::Unchanged { if edit_instruction.apply_to(file).await? == EditOutcome::Unchanged {
log::warn!("Writing new files is not supported yet"); tracing::warn!("Writing new files is not supported yet");
} }
Ok(()) Ok(())

View file

@ -82,7 +82,10 @@ impl Entry {
} }
Err(err) => { Err(err) => {
log::error!("Failed to obtain information for sorting '{}': {err}", uri); tracing::error!(
"Failed to obtain information for sorting '{}': {err}",
uri
);
break; break;
} }
} }
@ -189,7 +192,7 @@ impl LpFileModel {
self.imp().monitor.set(monitor).unwrap(); self.imp().monitor.set(monitor).unwrap();
} }
Err(err) => { Err(err) => {
log::info!("Cannot monitor directory: {err}"); tracing::info!("Cannot monitor directory: {err}");
} }
} }
@ -216,7 +219,7 @@ impl LpFileModel {
let info = enumerator.next_files_future(1, glib::Priority::LOW).await; let info = enumerator.next_files_future(1, glib::Priority::LOW).await;
match info { match info {
Err(err) => { Err(err) => {
log::warn!("Unreadable entry in directory: {err}"); tracing::warn!("Unreadable entry in directory: {err}");
break; break;
} }
Ok(mut info) => { Ok(mut info) => {
@ -268,7 +271,7 @@ impl LpFileModel {
Self::sort(&mut files); Self::sort(&mut files);
} }
log::debug!( tracing::debug!(
"Completed loading list of files of '{}' after {:#?}", "Completed loading list of files of '{}' after {:#?}",
directory.uri(), directory.uri(),
instant.elapsed(), instant.elapsed(),
@ -318,7 +321,7 @@ impl LpFileModel {
/// Returns `n` elements before and after given file /// Returns `n` elements before and after given file
pub fn files_around(&self, file: &gio::File, n: usize) -> IndexMap<GString, gio::File> { pub fn files_around(&self, file: &gio::File, n: usize) -> IndexMap<GString, gio::File> {
let Some(index) = self.index_of(file) else { let Some(index) = self.index_of(file) else {
log::error!("URI not in model: {}", file.uri()); tracing::error!("URI not in model: {}", file.uri());
return IndexMap::new(); return IndexMap::new();
}; };
@ -374,7 +377,7 @@ impl LpFileModel {
let Ok(info) = let Ok(info) =
util::query_attributes(file, vec![gio::FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE]) util::query_attributes(file, vec![gio::FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE])
else { else {
log::warn!("Could not query file info: {}", file.uri()); tracing::warn!("Could not query file info: {}", file.uri());
return false; return false;
}; };
@ -391,7 +394,7 @@ impl LpFileModel {
{ {
f(&file_event); f(&file_event);
} else { } else {
log::error!("Failed to read arguments from 'changed' signal."); tracing::error!("Failed to read arguments from 'changed' signal.");
} }
None None
@ -432,7 +435,7 @@ impl LpFileModel {
// Changing file content could theoretically make it an image // Changing file content could theoretically make it an image
// by adding a magic byte // by adding a magic byte
log::debug!("File added: {uri_a}"); tracing::debug!("File added: {uri_a}");
glib::spawn_future_local(glib::clone!( glib::spawn_future_local(glib::clone!(
#[strong(rename_to=obj)] #[strong(rename_to=obj)]
@ -450,7 +453,7 @@ impl LpFileModel {
gio::FileMonitorEvent::Deleted gio::FileMonitorEvent::Deleted
| gio::FileMonitorEvent::MovedOut | gio::FileMonitorEvent::MovedOut
| gio::FileMonitorEvent::Unmounted => { | gio::FileMonitorEvent::Unmounted => {
log::debug!("File removed: {}", file_a.uri()); tracing::debug!("File removed: {}", file_a.uri());
let removed = self let removed = self
.imp() .imp()
.files .files
@ -465,7 +468,7 @@ impl LpFileModel {
if let Some(file_b) = file_b { if let Some(file_b) = file_b {
{ {
let uri_b = file_b.uri(); let uri_b = file_b.uri();
log::debug!("File moved from '{uri_a}' to '{uri_b}'"); tracing::debug!("File moved from '{uri_a}' to '{uri_b}'");
let mut changed = let mut changed =
self.imp().files.borrow_mut().shift_remove(&uri_a).is_some(); self.imp().files.borrow_mut().shift_remove(&uri_a).is_some();

View file

@ -95,19 +95,19 @@ pub fn main() -> glib::ExitCode {
.with(tracing_subscriber::fmt::Layer::default().compact()) .with(tracing_subscriber::fmt::Layer::default().compact())
.init(); .init();
log::debug!("Logger initialized"); tracing::debug!("Logger initialized");
setlocale(LocaleCategory::LcAll, ""); setlocale(LocaleCategory::LcAll, "");
bindtextdomain("loupe", config::LOCALEDIR).unwrap(); bindtextdomain("loupe", config::LOCALEDIR).unwrap();
textdomain("loupe").unwrap(); textdomain("loupe").unwrap();
log::trace!("gettext initialized"); tracing::trace!("gettext initialized");
gio::resources_register( gio::resources_register(
&gio::Resource::from_data(&glib::Bytes::from_static(GRESOURCE_BYTES)).unwrap(), &gio::Resource::from_data(&glib::Bytes::from_static(GRESOURCE_BYTES)).unwrap(),
); );
log::trace!("Gio resources registered"); tracing::trace!("Gio resources registered");
LpApplication::new().run() LpApplication::new().run()
} }

View file

@ -48,7 +48,7 @@ impl Metadata {
let result = self.metadata.add_raw_exif(bytes); let result = self.metadata.add_raw_exif(bytes);
if let Err(err) = &result { if let Err(err) = &result {
log::warn!("Failed to decode EXIF bytes: {err}"); tracing::warn!("Failed to decode EXIF bytes: {err}");
} }
} }
@ -56,7 +56,7 @@ impl Metadata {
let result = self.metadata.add_raw_xmp(bytes); let result = self.metadata.add_raw_xmp(bytes);
if let Err(err) = &result { if let Err(err) = &result {
log::warn!("Failed to decode XMP bytes: {err}"); tracing::warn!("Failed to decode XMP bytes: {err}");
} }
} }

View file

@ -46,7 +46,7 @@ pub fn datetime_fmt(datetime: &glib::DateTime) -> Option<String> {
.format(&datetime_format); .format(&datetime_format);
if let Err(err) = &fmt { if let Err(err) = &fmt {
log::error!("Could not format DateTime with '{datetime_format}': {err}"); tracing::error!("Could not format DateTime with '{datetime_format}': {err}");
} }
fmt.ok().map(|x| x.to_string()) fmt.ok().map(|x| x.to_string())

View file

@ -25,7 +25,7 @@ pub trait ParentWindow: WidgetExt {
let result = self.root().and_downcast(); let result = self.root().and_downcast();
if result.is_none() { if result.is_none() {
log::error!( tracing::error!(
"Couldn't find LpWindow for {self:?}. mapped={}. caller={}", "Couldn't find LpWindow for {self:?}. mapped={}. caller={}",
self.is_mapped(), self.is_mapped(),
std::panic::Location::caller(), std::panic::Location::caller(),
@ -40,7 +40,7 @@ pub trait ParentWindow: WidgetExt {
let result = self.root().and_downcast(); let result = self.root().and_downcast();
if result.is_none() { if result.is_none() {
log::error!( tracing::error!(
"Couldn't find LpWindow for {self:?}. mapped={}. caller={}", "Couldn't find LpWindow for {self:?}. mapped={}. caller={}",
self.is_mapped(), self.is_mapped(),
std::panic::Location::caller(), std::panic::Location::caller(),

View file

@ -281,7 +281,7 @@ mod imp {
Some(&LpAspectRatio::default().to_variant()), Some(&LpAspectRatio::default().to_variant()),
); );
if let Err(err) = res { if let Err(err) = res {
log::error!("Failed to call action edit-crop.aspect-ratio: {err}"); tracing::error!("Failed to call action edit-crop.aspect-ratio: {err}");
} }
let (w, h) = self.image.image_size(); let (w, h) = self.image.image_size();
@ -294,7 +294,7 @@ mod imp {
.obj() .obj()
.activate_action("edit-crop.orientation", Some(&orientation.to_variant())); .activate_action("edit-crop.orientation", Some(&orientation.to_variant()));
if let Err(err) = res { if let Err(err) = res {
log::error!("Failed to call action edit-crop.orientation: {err}"); tracing::error!("Failed to call action edit-crop.orientation: {err}");
} }
self.obj().action_set_enabled("edit-crop.reset", false); self.obj().action_set_enabled("edit-crop.reset", false);

View file

@ -846,7 +846,7 @@ mod imp {
/// Set x coordinate of crop selection rectangle origin /// Set x coordinate of crop selection rectangle origin
pub(super) fn set_crop_x(&self, x: f32) { pub(super) fn set_crop_x(&self, x: f32) {
if x < 0. { if x < 0. {
log::error!("Tried to set x coordinate to {x}"); tracing::error!("Tried to set x coordinate to {x}");
return; return;
} }
@ -864,7 +864,7 @@ mod imp {
/// Set y coordinate of crop selection rectangle origin /// Set y coordinate of crop selection rectangle origin
pub(super) fn set_crop_y(&self, y: f32) { pub(super) fn set_crop_y(&self, y: f32) {
if y < 0. { if y < 0. {
log::error!("Tried to set y coordinate to {y}"); tracing::error!("Tried to set y coordinate to {y}");
return; return;
} }
@ -911,7 +911,9 @@ mod imp {
fn update_crop_area_image_coord(&self) { fn update_crop_area_image_coord(&self) {
let crop_area_image_coord = self.crop_area_image_coord(); let crop_area_image_coord = self.crop_area_image_coord();
if self.is_in_user_change() { if self.is_in_user_change() {
log::trace!("Setting crop are in image coordinates to {crop_area_image_coord:?}"); tracing::trace!(
"Setting crop are in image coordinates to {crop_area_image_coord:?}"
);
self.crop_area_image_coord.replace(crop_area_image_coord); self.crop_area_image_coord.replace(crop_area_image_coord);
} }
} }

View file

@ -234,7 +234,7 @@ mod imp {
match file_dialog.save_future(obj.try_window().as_ref()).await { match file_dialog.save_future(obj.try_window().as_ref()).await {
Err(err) => { Err(err) => {
log::error!("{}", err); tracing::error!("{}", err);
} }
Ok(new_file) => { Ok(new_file) => {
if self if self
@ -278,7 +278,7 @@ mod imp {
.await; .await;
if written { if written {
log::debug!("Moving image to trash '{}'", original_file.uri()); tracing::debug!("Moving image to trash '{}'", original_file.uri());
let trash_result = gio::CancellableFuture::new( let trash_result = gio::CancellableFuture::new(
original_file.trash_future(glib::Priority::DEFAULT), original_file.trash_future(glib::Priority::DEFAULT),
cancellable.clone(), cancellable.clone(),
@ -287,7 +287,7 @@ mod imp {
if trash_result.is_err() { if trash_result.is_err() {
// Canceled // Canceled
log::debug!("Trashing image canceled"); tracing::debug!("Trashing image canceled");
return; return;
} else if let Ok(Err(err)) = trash_result { } else if let Ok(Err(err)) = trash_result {
obj.window_show_error( obj.window_show_error(
@ -298,7 +298,11 @@ mod imp {
return; return;
} }
log::debug!("Moving '{}' to '{}'", tmp_file.uri(), original_file.uri()); tracing::debug!(
"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(
@ -313,7 +317,7 @@ mod imp {
if move_result.is_err() { if move_result.is_err() {
// Canceled // Canceled
log::debug!("Moving image canceled"); tracing::debug!("Moving image canceled");
return; return;
} else if let Ok(Err(err)) = move_result { } else if let Ok(Err(err)) = move_result {
obj.window_show_error( obj.window_show_error(
@ -352,17 +356,17 @@ mod imp {
editor.cancellable(cancellable.clone()); editor.cancellable(cancellable.clone());
if let Some(operations) = obj.operations() { if let Some(operations) = obj.operations() {
log::debug!("Computing edited image."); tracing::debug!("Computing edited image.");
let result = match editor.edit().await { let result = match editor.edit().await {
Ok(editable_image) => editable_image.apply_complete(&operations).await, Ok(editable_image) => editable_image.apply_complete(&operations).await,
Err(err) => Err(err), Err(err) => Err(err),
}; };
match result { match result {
Err(err) if matches!(err.error(), glycin::Error::Canceled(_)) => { Err(err) if matches!(err.error(), glycin::Error::Canceled(_)) => {
log::debug!("Computing edited image canceled"); tracing::debug!("Computing edited image canceled");
} }
Err(err) => { Err(err) => {
log::warn!("Failed to edit image: {err}"); tracing::warn!("Failed to edit image: {err}");
obj.window_show_error( obj.window_show_error(
&gettext("Failed to edit image."), &gettext("Failed to edit image."),
&format!("Failed to edit image:\n\n{err}\n\n{operations:#?}"), &format!("Failed to edit image:\n\n{err}\n\n{operations:#?}"),
@ -370,7 +374,7 @@ mod imp {
) )
} }
Ok(edit) => { Ok(edit) => {
log::debug!("Saving edited image to '{}'", new_file.uri()); tracing::debug!("Saving edited image to '{}'", new_file.uri());
match edit.data().get() { match edit.data().get() {
Err(err) => { Err(err) => {
obj.window_show_error( obj.window_show_error(
@ -394,7 +398,7 @@ mod imp {
.await; .await;
if save_result.is_err() { if save_result.is_err() {
log::debug!("Saving image canceled"); tracing::debug!("Saving image canceled");
} else if let Ok(Err(err)) = save_result { } else if let Ok(Err(err)) = save_result {
obj.window_show_error( obj.window_show_error(
&gettext("Failed to Save Image"), &gettext("Failed to Save Image"),
@ -402,7 +406,7 @@ mod imp {
ErrorType::General, ErrorType::General,
); );
} else { } else {
log::debug!("Image saved"); tracing::debug!("Image saved");
return true; return true;
} }
} }

View file

@ -110,7 +110,7 @@ impl LpErrorDetails {
} }
)); ));
log::debug!("Showing error details"); tracing::debug!("Showing error details");
obj.present(Some(root)); obj.present(Some(root));
obj obj
} }

View file

@ -318,7 +318,7 @@ mod imp {
#[weak] #[weak]
obj, obj,
move |_, _| { move |_, _| {
log::debug!("Scale changed signal"); tracing::debug!("Scale changed signal");
obj.queue_resize(); obj.queue_resize();
} }
), ),
@ -358,7 +358,7 @@ mod imp {
} }
fn dispose(&self) { fn dispose(&self) {
log::debug!("Disposing LpImage"); tracing::debug!("Disposing LpImage");
// remove target from zoom animation because it's property of this object // remove target from zoom animation because it's property of this object
self.rotation_animation() self.rotation_animation()

View file

@ -58,7 +58,7 @@ impl imp::LpImage {
pub async fn background_color_guess(&self) -> Option<gdk::RGBA> { pub async fn background_color_guess(&self) -> Option<gdk::RGBA> {
let obj = self.obj(); let obj = self.obj();
log::debug!("Determining background color"); tracing::debug!("Determining background color");
if self.fixed_background_color.borrow().is_some() { if self.fixed_background_color.borrow().is_some() {
return None; return None;
@ -66,7 +66,7 @@ impl imp::LpImage {
// Shortcut for formats that don't support transparency // Shortcut for formats that don't support transparency
if !obj.metadata().is_potentially_transparent() { if !obj.metadata().is_potentially_transparent() {
log::trace!("This format does not support transparency"); tracing::trace!("This format does not support transparency");
return Some(Self::default_background_color()); return Some(Self::default_background_color());
} }
@ -151,7 +151,7 @@ impl imp::LpImage {
} }
if !has_transparency { if !has_transparency {
log::trace!("This image does not have transparency"); tracing::trace!("This image does not have transparency");
return Some(default_color); return Some(default_color);
} }
@ -163,8 +163,8 @@ impl imp::LpImage {
1. 1.
}; };
log::trace!("Total: {n_pixels}, transparent: {completely_transparent}, bad contrast: {bad_contrast}"); tracing::trace!("Total: {n_pixels}, transparent: {completely_transparent}, bad contrast: {bad_contrast}");
log::trace!("Amount bad contrast: {part_bad_contrast}"); tracing::trace!("Amount bad contrast: {part_bad_contrast}");
if part_bad_contrast > BACKGROUND_GUESS_LOW_CONTRAST_TRHESHOLD { if part_bad_contrast > BACKGROUND_GUESS_LOW_CONTRAST_TRHESHOLD {
Some(alternate_color) Some(alternate_color)

View file

@ -76,7 +76,7 @@ impl LpImage {
if let Some(node) = tmp_snapshot.to_node() { if let Some(node) = tmp_snapshot.to_node() {
imp.apply_operations(node, &gtk::Snapshot::new())?; imp.apply_operations(node, &gtk::Snapshot::new())?;
} else { } else {
log::error!("Render node is empty"); tracing::error!("Render node is empty");
} }
imp.configure_best_fit(); imp.configure_best_fit();

View file

@ -109,7 +109,7 @@ impl imp::LpImage {
(f64::exp(-y * f64::ln(ZOOM_FACTOR_SCROLL_SURFACE)), false) (f64::exp(-y * f64::ln(ZOOM_FACTOR_SCROLL_SURFACE)), false)
} }
unknown_unit => { unknown_unit => {
log::warn!("Ignoring unknown scroll unit: {unknown_unit:?}"); tracing::warn!("Ignoring unknown scroll unit: {unknown_unit:?}");
(1., false) (1., false)
} }
}; };
@ -142,12 +142,12 @@ impl imp::LpImage {
move |gesture, n_press, x, y| { move |gesture, n_press, x, y| {
// only handle double clicks // only handle double clicks
if n_press != 2 { if n_press != 2 {
log::trace!("Gesture {n_press} click"); tracing::trace!("Gesture {n_press} click");
gesture.set_state(gtk::EventSequenceState::Denied); gesture.set_state(gtk::EventSequenceState::Denied);
return; return;
} }
log::trace!("Gesture double click"); tracing::trace!("Gesture double click");
gesture.set_state(gtk::EventSequenceState::Claimed); gesture.set_state(gtk::EventSequenceState::Claimed);
if gesture.device().map(|x| x.source()) == Some(gdk::InputSource::Touchscreen) { if gesture.device().map(|x| x.source()) == Some(gdk::InputSource::Touchscreen) {
@ -175,7 +175,7 @@ impl imp::LpImage {
#[weak] #[weak]
obj, obj,
move |gesture, _, _| { move |gesture, _, _| {
log::trace!("Drag gesture begin"); tracing::trace!("Drag gesture begin");
let imp = obj.imp(); let imp = obj.imp();
// Allow only left and middle button // Allow only left and middle button
@ -216,7 +216,7 @@ impl imp::LpImage {
#[weak] #[weak]
obj, obj,
move |_, _, _| { move |_, _, _| {
log::trace!("Drag gesture end"); tracing::trace!("Drag gesture end");
obj.set_cursor(None); obj.set_cursor(None);
obj.imp().last_drag_value.set(None); obj.imp().last_drag_value.set(None);
} }
@ -230,7 +230,7 @@ impl imp::LpImage {
#[weak] #[weak]
obj, obj,
move |_, _| { move |_, _| {
log::trace!("Rotate gesture begin"); tracing::trace!("Rotate gesture begin");
obj.imp().cancel_deceleration(); obj.imp().cancel_deceleration();
} }
)); ));
@ -270,7 +270,7 @@ impl imp::LpImage {
#[weak] #[weak]
obj, obj,
move |_, _| { move |_, _| {
log::debug!("Rotate gesture end"); tracing::debug!("Rotate gesture end");
let angle = (obj.rotation() / 90.).round() * 90. - obj.imp().rotation_target.get(); let angle = (obj.rotation() / 90.).round() * 90. - obj.imp().rotation_target.get();
obj.rotate_by(angle); obj.rotate_by(angle);
@ -286,7 +286,7 @@ impl imp::LpImage {
#[weak] #[weak]
obj, obj,
move |gesture, _| { move |gesture, _| {
log::trace!("Zoom gesture begin"); tracing::trace!("Zoom gesture begin");
let imp = obj.imp(); let imp = obj.imp();
imp.cancel_deceleration(); imp.cancel_deceleration();
@ -309,7 +309,7 @@ impl imp::LpImage {
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);
} else { } else {
log::warn!("Zoom bounding box center: No previous value"); tracing::warn!("Zoom bounding box center: No previous value");
} }
imp.zoom_gesture_center.set(p1); imp.zoom_gesture_center.set(p1);
@ -336,7 +336,7 @@ impl imp::LpImage {
obj, obj,
move |_, _| { move |_, _| {
let imp = obj.imp(); let imp = obj.imp();
log::debug!("Zoom gesture end"); tracing::debug!("Zoom gesture end");
let rotation_target = (obj.rotation() / 90.).round() * 90.; let rotation_target = (obj.rotation() / 90.).round() * 90.;
if obj.zoom() < imp.zoom_level_best_fit_for_rotation(rotation_target) if obj.zoom() < imp.zoom_level_best_fit_for_rotation(rotation_target)
@ -367,7 +367,7 @@ impl imp::LpImage {
scrolled_window.set_kinetic_scrolling(false); scrolled_window.set_kinetic_scrolling(false);
scrolled_window.set_kinetic_scrolling(true); scrolled_window.set_kinetic_scrolling(true);
} else { } else {
log::error!("Could not find GtkScrolledWindow parent to cancel deceleration"); tracing::error!("Could not find GtkScrolledWindow parent to cancel deceleration");
} }
} }
} }

View file

@ -78,9 +78,12 @@ impl imp::LpImage {
pub fn update(&self, update: DecoderUpdate) { pub fn update(&self, update: DecoderUpdate) {
let obj = self.obj(); let obj = self.obj();
let span = tracing::debug_span!("update", image = obj.basename());
let _guard = span.enter();
match update { match update {
DecoderUpdate::Metadata(metadata) => { DecoderUpdate::Metadata(metadata) => {
log::debug!("Received metadata"); tracing::debug!("Received metadata");
self.metadata.borrow_mut().merge(*metadata); self.metadata.borrow_mut().merge(*metadata);
self.emmit_metadata_changed(); self.emmit_metadata_changed();
@ -92,7 +95,7 @@ impl imp::LpImage {
)); ));
} }
DecoderUpdate::Dimensions => { DecoderUpdate::Dimensions => {
log::debug!("Received dimensions: {:?}", self.untransformed_dimensions()); tracing::debug!("Received dimensions: {:?}", self.untransformed_dimensions());
obj.notify_image_size_available(); obj.notify_image_size_available();
self.configure_best_fit(); self.configure_best_fit();
self.request_tiles(); self.request_tiles();
@ -141,14 +144,14 @@ impl imp::LpImage {
} }
DecoderUpdate::SpecificError(err) => { DecoderUpdate::SpecificError(err) => {
if self.obj().is_loaded() { if self.obj().is_loaded() {
log::warn!("Error occured while loading additional data: {err:?}"); tracing::warn!("Error occured while loading additional data: {err:?}");
} else { } else {
self.set_specific_error(err); self.set_specific_error(err);
} }
} }
DecoderUpdate::GenericError(err) => { DecoderUpdate::GenericError(err) => {
if self.obj().is_loaded() { if self.obj().is_loaded() {
log::warn!("Error occured while loading additional data: {err:?}"); tracing::warn!("Error occured while loading additional data: {err:?}");
} else { } else {
self.set_error(Some(err)); self.set_error(Some(err));
} }
@ -218,12 +221,12 @@ impl imp::LpImage {
match event { match event {
gio::FileMonitorEvent::Renamed => { gio::FileMonitorEvent::Renamed => {
if let Some(file) = file_b.cloned() { if let Some(file) = file_b.cloned() {
log::debug!("Moved to {}", file.uri()); tracing::debug!("Moved to {}", file.uri());
// current file got replaced with a new one // current file got replaced with a new one
let file_replace = obj.file().is_some_and(|x| x.equal(&file)); let file_replace = obj.file().is_some_and(|x| x.equal(&file));
if file_replace { if file_replace {
log::debug!("Image got replaced {}", file.uri()); tracing::debug!("Image got replaced {}", file.uri());
glib::spawn_future_local(async move { glib::spawn_future_local(async move {
obj.load(&file).await; obj.load(&file).await;
}); });
@ -243,7 +246,7 @@ impl imp::LpImage {
} }
} }
gio::FileMonitorEvent::MovedIn => { gio::FileMonitorEvent::MovedIn => {
log::debug!("Image got replaced by moving into dir {}", file_a.uri()); tracing::debug!("Image got replaced by moving into dir {}", file_a.uri());
glib::spawn_future_local(glib::clone!( glib::spawn_future_local(glib::clone!(
#[strong] #[strong]
file_a, file_a,
@ -255,7 +258,7 @@ impl imp::LpImage {
gio::FileMonitorEvent::ChangesDoneHint => { gio::FileMonitorEvent::ChangesDoneHint => {
let obj = self.obj().to_owned(); let obj = self.obj().to_owned();
let file = file_a.clone(); let file = file_a.clone();
log::debug!("Image was edited {}", file.uri()); tracing::debug!("Image was edited {}", file.uri());
glib::spawn_future_local(async move { glib::spawn_future_local(async move {
obj.load(&file).await; obj.load(&file).await;
}); });
@ -263,7 +266,7 @@ impl imp::LpImage {
gio::FileMonitorEvent::Deleted gio::FileMonitorEvent::Deleted
| gio::FileMonitorEvent::MovedOut | gio::FileMonitorEvent::MovedOut
| gio::FileMonitorEvent::Unmounted => { | gio::FileMonitorEvent::Unmounted => {
log::debug!("File no longer available: {event:?} {}", file_a.uri()); tracing::debug!("File no longer available: {event:?} {}", file_a.uri());
self.is_deleted.set(true); self.is_deleted.set(true);
self.obj().notify_is_deleted(); self.obj().notify_is_deleted();
} }
@ -272,7 +275,7 @@ impl imp::LpImage {
} }
fn set_error(&self, err: Option<anyhow::Error>) { fn set_error(&self, err: Option<anyhow::Error>) {
log::debug!("Decoding error: {err:?}"); tracing::debug!("Decoding error: {err:?}");
// Keeping first error instead of replacing with new error // Keeping first error instead of replacing with new error
if err.is_some() && self.error.borrow().is_some() { if err.is_some() && self.error.borrow().is_some() {
@ -342,16 +345,16 @@ impl LpImage {
if let Some(file) = self.file() { if let Some(file) = self.file() {
self.load(&file).await; self.load(&file).await;
} else { } else {
log::error!("Trying to reload image without file"); tracing::error!("Trying to reload image without file");
} }
} }
pub async fn load(&self, file: &gio::File) { pub async fn load(&self, file: &gio::File) {
let imp = self.imp(); let imp = self.imp();
log::debug!("Loading file {}", file.uri()); tracing::debug!("Loading file {}", file.uri());
if imp.rotation_animation().state() == adw::AnimationState::Playing { if imp.rotation_animation().state() == adw::AnimationState::Playing {
log::debug!("Queueing image reload due to playing rotate animation."); tracing::debug!("Queueing image reload due to playing rotate animation.");
self.imp().queued_reload.replace(Some(file.clone())); self.imp().queued_reload.replace(Some(file.clone()));
return; return;
} }
@ -380,7 +383,7 @@ impl LpImage {
obj.imp().update(update); obj.imp().update(update);
} }
} }
log::debug!("Stopped listening to decoder since sender is gone"); tracing::debug!("Stopped listening to decoder since sender is gone");
}); });
imp.decoder.replace(Some(Arc::new(decoder))); imp.decoder.replace(Some(Arc::new(decoder)));

View file

@ -85,7 +85,7 @@ impl imp::LpImage {
let file_info = metadata::FileInfo::new(&file).await; let file_info = metadata::FileInfo::new(&file).await;
match file_info { match file_info {
Ok(file_info) => self.metadata.borrow_mut().set_file_info(file_info), Ok(file_info) => self.metadata.borrow_mut().set_file_info(file_info),
Err(err) => log::warn!("Failed to load file information: {err}"), Err(err) => tracing::warn!("Failed to load file information: {err}"),
} }
self.emmit_metadata_changed(); self.emmit_metadata_changed();
} }
@ -101,6 +101,12 @@ impl LpImage {
self.imp().file.borrow().clone() self.imp().file.borrow().clone()
} }
pub fn basename(&self) -> Option<String> {
self.file()
.and_then(|x| x.basename())
.map(|x| x.display().to_string())
}
pub fn metadata(&self) -> impl Deref<Target = Metadata> + '_ { pub fn metadata(&self) -> impl Deref<Target = Metadata> + '_ {
self.imp().metadata.borrow() self.imp().metadata.borrow()
} }
@ -136,7 +142,7 @@ impl LpImage {
match file_info { match file_info {
Err(err) => { Err(err) => {
log::error!( tracing::error!(
"Failed to obtain CAN_TRASH attribute for '{}': {err}", "Failed to obtain CAN_TRASH attribute for '{}': {err}",
file.uri() file.uri()
); );

View file

@ -26,7 +26,7 @@ impl LpImage {
gtk::PanDirection::Left | gtk::PanDirection::Up => -1., gtk::PanDirection::Left | gtk::PanDirection::Up => -1.,
gtk::PanDirection::Right | gtk::PanDirection::Down => 1., gtk::PanDirection::Right | gtk::PanDirection::Down => 1.,
_ => { _ => {
log::error!("Unknown pan direction {direction:?}"); tracing::error!("Unknown pan direction {direction:?}");
return; return;
} }
}; };
@ -39,7 +39,7 @@ impl LpImage {
(self.vadj(), imp.max_vadjustment_value()) (self.vadj(), imp.max_vadjustment_value())
} }
_ => { _ => {
log::error!("Unknown pan direction {direction:?}"); tracing::error!("Unknown pan direction {direction:?}");
return; return;
} }
}; };

View file

@ -70,7 +70,7 @@ impl WidgetImpl for imp::LpImage {
let nth_snapshot = self.nth_snapshot.get() + 1; let nth_snapshot = self.nth_snapshot.get() + 1;
if nth_snapshot < 3 { if nth_snapshot < 3 {
self.nth_snapshot.set(nth_snapshot); self.nth_snapshot.set(nth_snapshot);
log::trace!("Creating snapshot #{nth_snapshot}"); tracing::trace!("Creating snapshot #{nth_snapshot}");
} }
let scaling_filter = if obj.metadata().is_svg() { let scaling_filter = if obj.metadata().is_svg() {
@ -124,10 +124,10 @@ impl WidgetImpl for imp::LpImage {
frame_buffer.add_to_snapshot(&tmp_snapshot, applicable_zoom, &render_options); frame_buffer.add_to_snapshot(&tmp_snapshot, applicable_zoom, &render_options);
if let Some(node) = tmp_snapshot.to_node() { if let Some(node) = tmp_snapshot.to_node() {
if let Err(err) = self.apply_operations(node, snapshot) { if let Err(err) = self.apply_operations(node, snapshot) {
log::error!("Failed to apply operations to node: {err}"); tracing::error!("Failed to apply operations to node: {err}");
} }
} else { } else {
log::error!("Render node is empty"); tracing::error!("Render node is empty");
} }
} else { } else {
// Apply rotation and mirroring // Apply rotation and mirroring
@ -144,12 +144,16 @@ impl WidgetImpl for imp::LpImage {
snapshot.restore(); snapshot.restore();
if nth_snapshot < 3 { if nth_snapshot < 3 {
log::trace!("Snapshot #{nth_snapshot} created"); tracing::trace!("Snapshot #{nth_snapshot} created");
} }
} }
fn measure(&self, orientation: gtk::Orientation, _for_size: i32) -> (i32, i32, i32, i32) { fn measure(&self, orientation: gtk::Orientation, _for_size: i32) -> (i32, i32, i32, i32) {
let obj = self.obj(); let obj = self.obj();
let span = tracing::debug_span!("measure", image = obj.basename());
let _guard = span.enter();
let (image_width_i32, image_height_i32) = obj.image_size(); let (image_width_i32, image_height_i32) = obj.image_size();
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;
@ -157,7 +161,7 @@ impl WidgetImpl for imp::LpImage {
if image_width_i32 > 0 && image_height_i32 > 0 { if image_width_i32 > 0 && image_height_i32 > 0 {
if let Some((monitor_width, monitor_height)) = self.monitor_size() { if let Some((monitor_width, monitor_height)) = self.monitor_size() {
let hidpi_scale = self.scaling(); let hidpi_scale = self.scaling();
log::trace!("Physical monitor dimensions: {monitor_width} x {monitor_height}"); tracing::trace!("Physical monitor dimensions: {monitor_width} x {monitor_height}");
// areas // areas
let monitor_area = monitor_width * monitor_height; let monitor_area = monitor_width * monitor_height;
@ -165,10 +169,12 @@ 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 {
log::trace!("Small monitor detected: Using {SMALL_OCCUPY_SCREEN} screen area"); tracing::trace!(
"Small monitor detected: Using {SMALL_OCCUPY_SCREEN} screen area"
);
SMALL_OCCUPY_SCREEN SMALL_OCCUPY_SCREEN
} else { } else {
log::trace!( tracing::trace!(
"Sufficiently large monitor detected: Using {DEFAULT_OCCUPY_SCREEN} screen area" "Sufficiently large monitor detected: Using {DEFAULT_OCCUPY_SCREEN} screen area"
); );
DEFAULT_OCCUPY_SCREEN DEFAULT_OCCUPY_SCREEN
@ -218,7 +224,7 @@ impl WidgetImpl for imp::LpImage {
_ => unreachable!(), _ => unreachable!(),
}; };
log::warn!("Not enough information available to calculate fitting window size"); tracing::warn!("Not enough information available to calculate fitting window size");
(0, size, -1, -1) (0, size, -1, -1)
} }

View file

@ -59,7 +59,7 @@ impl imp::LpImage {
let imp = obj.imp(); let imp = obj.imp();
if let Some(new_file) = imp.queued_reload.replace(None) { if let Some(new_file) = imp.queued_reload.replace(None) {
glib::spawn_future_local(async move { glib::spawn_future_local(async move {
log::debug!("Animation finished: Executing delayed reload"); tracing::debug!("Animation finished: Executing delayed reload");
obj.load(&new_file).await; obj.load(&new_file).await;
}); });
} }
@ -74,7 +74,7 @@ impl imp::LpImage {
impl LpImage { impl LpImage {
/// Set rotation and mirroring to the state would have after loading /// Set rotation and mirroring to the state would have after loading
pub fn reset_rotation(&self) { pub fn reset_rotation(&self) {
log::debug!("Resetting rotation"); tracing::debug!("Resetting rotation");
let orientation = self.metadata().orientation(); let orientation = self.metadata().orientation();
self.imp() self.imp()
.rotation_target .rotation_target
@ -86,7 +86,7 @@ impl LpImage {
pub fn rotate_by(&self, angle: f64) { pub fn rotate_by(&self, angle: f64) {
let imp = self.imp(); let imp = self.imp();
log::debug!("Rotate by {} degrees", angle); tracing::debug!("Rotate by {} degrees", angle);
let target = &self.imp().rotation_target; let target = &self.imp().rotation_target;
target.set(target.get() + angle); target.set(target.get() + angle);
@ -106,7 +106,7 @@ impl LpImage {
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 { if r != gufo_common::orientation::Rotation::_0 {
log::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;
editing_queue.push(operation); editing_queue.push(operation);

View file

@ -60,7 +60,7 @@ impl imp::LpImage {
} }
pub fn set_ignore_scroll_policy(&self, scroll_policy: gtk::ScrollablePolicy) { pub fn set_ignore_scroll_policy(&self, scroll_policy: gtk::ScrollablePolicy) {
log::error!("Ignored setting new scroll policy {scroll_policy:?}"); tracing::error!("Ignored setting new scroll policy {scroll_policy:?}");
} }
pub fn scroll_policy(&self) -> gtk::ScrollablePolicy { pub fn scroll_policy(&self) -> gtk::ScrollablePolicy {

View file

@ -70,7 +70,7 @@ impl imp::LpImage {
/// Sets respective output values if best-fit is active /// Sets respective output values if best-fit is active
pub(super) fn configure_best_fit(&self) { pub(super) fn configure_best_fit(&self) {
log::trace!("Configure best fit"); tracing::trace!("Configure best fit");
// calculate new zoom value for best fit // calculate new zoom value for best fit
if self.obj().is_best_fit() { if self.obj().is_best_fit() {
// LpImage can get measured during pinch zoom gesture, when scrollbars appear // LpImage can get measured during pinch zoom gesture, when scrollbars appear
@ -193,7 +193,7 @@ impl imp::LpImage {
} }
pub(super) fn set_zoom_target(&self, zoom_target: f64) { pub(super) fn set_zoom_target(&self, zoom_target: f64) {
log::trace!("Setting zoom target {zoom_target}"); tracing::trace!("Setting zoom target {zoom_target}");
self.zoom_target.set(zoom_target); self.zoom_target.set(zoom_target);
self.obj().notify_zoom_target(); self.obj().notify_zoom_target();
@ -243,13 +243,13 @@ impl imp::LpImage {
obj.set_best_fit(false); obj.set_best_fit(false);
} }
log::trace!("Zoom to {zoom:.3}"); tracing::trace!("Zoom to {zoom:.3}");
self.set_zoom_target(zoom); self.set_zoom_target(zoom);
// abort if already at correct zoom level // abort if already at correct zoom level
if zoom == obj.zoom() { if zoom == obj.zoom() {
log::trace!("Already at correct zoom level"); tracing::trace!("Already at correct zoom level");
return; return;
} }

View file

@ -105,7 +105,7 @@ mod imp {
#[weak] #[weak]
obj, obj,
move |gesture, x, y| { move |gesture, x, y| {
log::debug!("Long press triggered"); tracing::debug!("Long press triggered");
obj.show_popover_at(x, y); obj.show_popover_at(x, y);
gesture.set_state(gtk::EventSequenceState::Claimed); gesture.set_state(gtk::EventSequenceState::Claimed);
} }
@ -128,7 +128,7 @@ mod imp {
obj, obj,
move |_| { move |_| {
if obj.image().is_loaded() { if obj.image().is_loaded() {
log::debug!("Showing image"); tracing::debug!("Showing image");
obj.imp() obj.imp()
.stack .stack
.set_visible_child(&*obj.imp().image_stack_page); .set_visible_child(&*obj.imp().image_stack_page);

View file

@ -257,7 +257,7 @@ mod imp {
} else if row == &*imp.zoom_to_50 { } else if row == &*imp.zoom_to_50 {
0.5 0.5
} else { } else {
log::error!("Activated unknown entry in zoom to popover."); tracing::error!("Activated unknown entry in zoom to popover.");
return; return;
}; };
@ -445,7 +445,7 @@ impl LpImageView {
} }
)); ));
} else { } else {
log::error!("File list was empty"); tracing::error!("File list was empty");
} }
} }
@ -464,7 +464,7 @@ impl LpImageView {
}; };
if is_same_directory { if is_same_directory {
log::debug!("Re-using old model and navigating to the current file"); tracing::debug!("Re-using old model and navigating to the current file");
self.navigate_to_file(&file); self.navigate_to_file(&file);
return; return;
} }
@ -475,14 +475,14 @@ impl LpImageView {
async move { async move {
let model = LpFileModel::from_file(file.clone()).await; let model = LpFileModel::from_file(file.clone()).await;
obj.set_model(model); obj.set_model(model);
log::debug!("New model created"); tracing::debug!("New model created");
obj.update_sliding_view(&file); obj.update_sliding_view(&file);
// List other files in directory // List other files in directory
if let Some(directory) = directory { if let Some(directory) = directory {
if let Err(err) = obj.model().load_directory(directory.clone()).await { if let Err(err) = obj.model().load_directory(directory.clone()).await {
log::warn!("Failed to load directory: {}", err.root_cause()); tracing::warn!("Failed to load directory: {}", err.root_cause());
obj.window_show_toast( obj.window_show_toast(
&format!("{} {}", err, err.root_cause()), &format!("{} {}", err, err.root_cause()),
adw::ToastPriority::High, adw::ToastPriority::High,
@ -534,7 +534,7 @@ impl LpImageView {
} }
let Some(new_index) = self.model().index_of(new_file) else { let Some(new_index) = self.model().index_of(new_file) else {
log::debug!( tracing::debug!(
"Could not navigate to file that's not in model '{}': Delaying insertion", "Could not navigate to file that's not in model '{}': Delaying insertion",
new_file.uri() new_file.uri()
); );
@ -561,7 +561,7 @@ impl LpImageView {
page page
}; };
log::debug!("Scrolling to page for {}", new_file.uri()); tracing::debug!("Scrolling to page for {}", new_file.uri());
self.imp().preserve_content.set(true); self.imp().preserve_content.set(true);
sliding_view.animate_to(&page); sliding_view.animate_to(&page);
@ -570,7 +570,7 @@ impl LpImageView {
/// Ensures the sliding view contains the correct images /// Ensures the sliding view contains the correct images
fn update_sliding_view(&self, current_file: &gio::File) { fn update_sliding_view(&self, current_file: &gio::File) {
log::debug!( tracing::debug!(
"Updating sliding_view neighbors for current path {}", "Updating sliding_view neighbors for current path {}",
current_file.uri() current_file.uri()
); );
@ -603,7 +603,7 @@ impl LpImageView {
fn scroll_sliding_view(&self, file: &gio::File, animated: bool) { fn scroll_sliding_view(&self, file: &gio::File, animated: bool) {
let Some(current_page) = self.sliding_view().pages().swap_remove(&file.uri()) else { let Some(current_page) = self.sliding_view().pages().swap_remove(&file.uri()) else {
log::error!( tracing::error!(
"Current path not available in sliding_view for scrolling: {}", "Current path not available in sliding_view for scrolling: {}",
file.uri() file.uri()
); );
@ -653,14 +653,14 @@ impl LpImageView {
move |image| { move |image| {
if image.specific_error() == DecoderError::UnsupportedFormat { if image.specific_error() == DecoderError::UnsupportedFormat {
if obj.current_image().as_ref() == Some(image) { if obj.current_image().as_ref() == Some(image) {
log::debug!( tracing::debug!(
"Image format unsupported but not removing since current image" "Image format unsupported but not removing since current image"
); );
return; return;
} }
if let Some(file) = image.file() { if let Some(file) = image.file() {
log::debug!("Removing image with unsupported format {:?}", file.uri()); tracing::debug!("Removing image with unsupported format {:?}", file.uri());
obj.model().remove(&file); obj.model().remove(&file);
if let Some(current_file) = obj.current_file() { if let Some(current_file) = obj.current_file() {
obj.update_sliding_view(&current_file); obj.update_sliding_view(&current_file);
@ -772,7 +772,7 @@ impl LpImageView {
self.notify_is_previous_available(); self.notify_is_previous_available();
let Some(new_page) = self.current_page() else { let Some(new_page) = self.current_page() else {
log::debug!("Page changed but no current page"); tracing::debug!("Page changed but no current page");
return; return;
}; };
@ -789,7 +789,7 @@ impl LpImageView {
if let Some(new_page) = &current_page { if let Some(new_page) = &current_page {
self.update_sliding_view(&new_page.file()); self.update_sliding_view(&new_page.file());
} else { } else {
log::error!("No LpImagePage"); tracing::error!("No LpImagePage");
} }
} }

View file

@ -164,7 +164,7 @@ mod imp {
#[weak] #[weak]
obj, obj,
move |gesture, _, _, _| { move |gesture, _, _, _| {
log::trace!("Mouse forward button clicked"); tracing::trace!("Mouse forward button clicked");
gesture.set_state(gtk::EventSequenceState::Claimed); gesture.set_state(gtk::EventSequenceState::Claimed);
obj.image_view().navigate(Direction::Forward, false); obj.image_view().navigate(Direction::Forward, false);
} }
@ -173,7 +173,7 @@ mod imp {
#[weak] #[weak]
obj, obj,
move |gesture, _, _, _| { move |gesture, _, _, _| {
log::trace!("Mouse back button clicked"); tracing::trace!("Mouse back button clicked");
gesture.set_state(gtk::EventSequenceState::Claimed); gesture.set_state(gtk::EventSequenceState::Claimed);
obj.image_view().navigate(Direction::Back, false); obj.image_view().navigate(Direction::Back, false);
} }
@ -186,7 +186,7 @@ mod imp {
// TODO: We can't claim the gesture here, right? Otherwise we suppress the // TODO: We can't claim the gesture here, right? Otherwise we suppress the
// double-click // double-click
if n_press == 1 { if n_press == 1 {
log::trace!("General 1 click event"); tracing::trace!("General 1 click event");
obj.on_click(); obj.on_click();
} }
} }
@ -424,7 +424,7 @@ mod imp {
let files = match value.get::<gdk::FileList>() { let files = match value.get::<gdk::FileList>() {
Ok(list) => list.files(), Ok(list) => list.files(),
Err(err) => { Err(err) => {
log::error!("Issue with drop value: {err}"); tracing::error!("Issue with drop value: {err}");
return false; return false;
} }
}; };
@ -432,12 +432,12 @@ mod imp {
if !files.is_empty() { if !files.is_empty() {
obj.image_view().set_images_from_files(files); obj.image_view().set_images_from_files(files);
} else { } else {
log::error!("Dropped FileList was empty"); tracing::error!("Dropped FileList was empty");
return false; return false;
} }
// Maybe one day this will actually work // Maybe one day this will actually work
log::debug!("Trying to focus window after drag and drop"); tracing::debug!("Trying to focus window after drag and drop");
obj.window_inspect(|w| w.present()); obj.window_inspect(|w| w.present());
true true
@ -553,7 +553,7 @@ impl LpImageWindow {
.collect(); .collect();
self.image_view().set_images_from_files(images); self.image_view().set_images_from_files(images);
} else { } else {
log::debug!("File dialog canceled or file not readable"); tracing::debug!("File dialog canceled or file not readable");
} }
} }
@ -565,11 +565,11 @@ impl LpImageWindow {
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) { if !e.matches(gtk::DialogError::Dismissed) {
log::error!("Could not open image in external program: {}", e); tracing::error!("Could not open image in external program: {}", e);
} }
} }
} else { } else {
log::error!("Could not load a path for the current image.") tracing::error!("Could not load a path for the current image.")
} }
} }
@ -581,7 +581,7 @@ impl LpImageWindow {
let imp = self.imp(); let imp = self.imp();
if let Err(e) = imp.image_view.set_background().await { if let Err(e) = imp.image_view.set_background().await {
log::error!("Failed to set background: {}", e); tracing::error!("Failed to set background: {}", e);
} }
} }
@ -589,7 +589,7 @@ impl LpImageWindow {
let imp = self.imp(); let imp = self.imp();
if let Err(e) = imp.image_view.print() { if let Err(e) = imp.image_view.print() {
log::error!("Failed to print file: {}", e); tracing::error!("Failed to print file: {}", e);
} }
} }
@ -615,7 +615,7 @@ impl LpImageWindow {
let imp = self.imp(); let imp = self.imp();
if let Err(e) = imp.image_view.copy() { if let Err(e) = imp.image_view.copy() {
log::error!("Failed to copy to clipboard: {}", e); tracing::error!("Failed to copy to clipboard: {}", e);
} else { } else {
self.window_show_toast( self.window_show_toast(
&gettext("Image copied to clipboard"), &gettext("Image copied to clipboard"),
@ -630,7 +630,7 @@ impl LpImageWindow {
image_view.current_file(), image_view.current_file(),
image_view.current_file().and_then(|x| x.path()), image_view.current_file().and_then(|x| x.path()),
) else { ) else {
log::error!("No file to trash"); tracing::error!("No file to trash");
return; return;
}; };
@ -653,7 +653,7 @@ impl LpImageWindow {
.set_trash_restore(Some(gio::File::for_path(&path))); .set_trash_restore(Some(gio::File::for_path(&path)));
let result = crate::util::untrash(&path).await; let result = crate::util::untrash(&path).await;
if let Err(err) = result { if let Err(err) = result {
log::error!("Failed to untrash {path:?}: {err}"); tracing::error!("Failed to untrash {path:?}: {err}");
obj.window_show_toast( obj.window_show_toast(
&gettext("Failed to restore image from trash"), &gettext("Failed to restore image from trash"),
adw::ToastPriority::High, adw::ToastPriority::High,
@ -668,7 +668,7 @@ impl LpImageWindow {
if Some(gio::IOErrorEnum::NotSupported) == err.kind::<gio::IOErrorEnum>() { if Some(gio::IOErrorEnum::NotSupported) == err.kind::<gio::IOErrorEnum>() {
self.delete_future(&path).await; self.delete_future(&path).await;
} else { } else {
log::error!("Failed to delete file {path:?}: {err}"); tracing::error!("Failed to delete file {path:?}: {err}");
self.window_show_toast( self.window_show_toast(
&gettext("Failed to move image to trash"), &gettext("Failed to move image to trash"),
adw::ToastPriority::Normal, adw::ToastPriority::Normal,
@ -682,7 +682,7 @@ impl LpImageWindow {
async fn delete(&self) { async fn delete(&self) {
let image_view = self.image_view(); let image_view = self.image_view();
let Some(path) = image_view.current_file().and_then(|x| x.path()) else { let Some(path) = image_view.current_file().and_then(|x| x.path()) else {
log::error!("No file to delete"); tracing::error!("No file to delete");
return; return;
}; };
@ -714,7 +714,7 @@ impl LpImageWindow {
let result = file.delete_future(glib::Priority::default()).await; let result = file.delete_future(glib::Priority::default()).await;
if let Err(err) = result { if let Err(err) = result {
log::error!("Failed to delete file {path:?}: {err}"); tracing::error!("Failed to delete file {path:?}: {err}");
self.window_show_toast( self.window_show_toast(
&gettext("Failed to delete image"), &gettext("Failed to delete image"),
adw::ToastPriority::Normal, adw::ToastPriority::Normal,
@ -873,7 +873,7 @@ impl LpImageWindow {
let settings = LpApplication::default().settings(); let settings = LpApplication::default().settings();
let result = settings.set_boolean("show-properties", imp.properties_button.is_active()); let result = settings.set_boolean("show-properties", imp.properties_button.is_active());
if let Err(err) = result { if let Err(err) = result {
log::warn!("Failed to save show-properties state, {}", err); tracing::warn!("Failed to save show-properties state, {}", err);
} }
} }
@ -901,7 +901,7 @@ impl LpImageWindow {
.map(|page| page.image()); .map(|page| page.image());
if image.is_some_and(|img| img.image_size_available()) { if image.is_some_and(|img| img.image_size_available()) {
log::debug!("Showing window because image size is ready"); tracing::debug!("Showing window because image size is ready");
self.window().present(); self.window().present();
} }
} }
@ -916,7 +916,7 @@ impl LpImageWindow {
let current_page = self.imp().image_view.current_page(); let current_page = self.imp().image_view.current_page();
if current_page.is_some_and(|page| page.image().error().is_some()) { if current_page.is_some_and(|page| page.image().error().is_some()) {
log::debug!("Showing window because loading image failed"); tracing::debug!("Showing window because loading image failed");
self.window_inspect(|w| w.present()); self.window_inspect(|w| w.present());
} }
} }
@ -958,7 +958,7 @@ impl LpImageWindow {
}; };
let Some(application) = window.application() else { let Some(application) = window.application() else {
log::error!("No application for window found"); tracing::error!("No application for window found");
return; return;
}; };

View file

@ -282,7 +282,7 @@ impl Action {
if let Some(current_page) = win.imp().image_view.current_page() { if let Some(current_page) = win.imp().image_view.current_page() {
current_page.image().reload().await; current_page.image().reload().await;
} else { } else {
log::error!("No current image to reload"); tracing::error!("No current image to reload");
} }
}); });
} }

View file

@ -84,7 +84,7 @@ impl From<&str> for PageAlignment {
"left" => (HAlignment::Left, VAlignment::Middle), "left" => (HAlignment::Left, VAlignment::Middle),
"right" => (HAlignment::Right, VAlignment::Middle), "right" => (HAlignment::Right, VAlignment::Middle),
pos => { pos => {
log::error!("Unknown alignment '{pos}'"); tracing::error!("Unknown alignment '{pos}'");
(HAlignment::default(), VAlignment::default()) (HAlignment::default(), VAlignment::default())
} }
}; };
@ -134,7 +134,7 @@ impl<T: AsRef<str>> From<T> for Unit {
"px" => Self::Pixel, "px" => Self::Pixel,
"%" => Self::Percent, "%" => Self::Percent,
unit => { unit => {
log::error!("Unknown unit '{unit}'"); tracing::error!("Unknown unit '{unit}'");
Self::default() Self::default()
} }
} }
@ -408,7 +408,7 @@ mod imp {
obj.set_orientation(orientation); obj.set_orientation(orientation);
drop(ui_updates_disabled); drop(ui_updates_disabled);
log::debug!("Showing print dialog"); tracing::debug!("Showing print dialog");
obj.present(); obj.present();
} }
@ -460,7 +460,7 @@ impl LpPrint {
print_setup: Option<gtk::PrintSetup>, print_setup: Option<gtk::PrintSetup>,
) { ) {
let Some(file) = image.file() else { let Some(file) = image.file() else {
log::error!("Tried to print LpImage without GFile"); tracing::error!("Tried to print LpImage without GFile");
return; return;
}; };
@ -496,7 +496,7 @@ impl LpPrint {
let print_setup = match print_dialog.setup_future(Some(&parent)).await { let print_setup = match print_dialog.setup_future(Some(&parent)).await {
Err(err) => { Err(err) => {
// TODO: show error // TODO: show error
log::warn!("Failed to print: {err}"); tracing::warn!("Failed to print: {err}");
return; return;
} }
Ok(print_setup) => print_setup, Ok(print_setup) => print_setup,
@ -897,21 +897,21 @@ impl LpPrint {
let draw_result = match result { let draw_result = match result {
Err(err) => { Err(err) => {
log::warn!("Print error: {err}"); tracing::warn!("Print error: {err}");
return; return;
} }
Ok(output_stream) => obj.draw_page(output_stream).await, Ok(output_stream) => obj.draw_page(output_stream).await,
}; };
if let Err(err) = draw_result { if let Err(err) = draw_result {
log::warn!("Print error: {err}"); tracing::warn!("Print error: {err}");
} }
}); });
} }
/// Draw PDF for printing /// Draw PDF for printing
async fn draw_page(&self, output_stream: gio::OutputStream) -> anyhow::Result<()> { async fn draw_page(&self, output_stream: gio::OutputStream) -> anyhow::Result<()> {
log::debug!("Drawing image to print"); tracing::debug!("Drawing image to print");
let image = self.image(); let image = self.image();
let (orig_width, orig_height) = self.original_size(); let (orig_width, orig_height) = self.original_size();

View file

@ -311,7 +311,7 @@ mod imp {
let launcher = gtk::FileLauncher::new(self.file().as_ref()); let launcher = gtk::FileLauncher::new(self.file().as_ref());
let win = obj.native().and_downcast::<gtk::Window>(); let win = obj.native().and_downcast::<gtk::Window>();
if let Err(e) = launcher.open_containing_folder_future(win.as_ref()).await { if let Err(e) = launcher.open_containing_folder_future(win.as_ref()).await {
log::error!("Could not open parent directory: {e}"); tracing::error!("Could not open parent directory: {e}");
}; };
} }
@ -344,7 +344,7 @@ mod imp {
gio::Cancellable::NONE, gio::Cancellable::NONE,
|result| { |result| {
if let Err(err) = result { if let Err(err) = result {
log::error!("Failed to show geo URI: {err}") tracing::error!("Failed to show geo URI: {err}")
} }
}, },
); );

View file

@ -30,7 +30,7 @@ use adw::prelude::*;
use adw::subclass::prelude::*; use adw::subclass::prelude::*;
use glib::Properties; use glib::Properties;
use indexmap::IndexMap; use indexmap::IndexMap;
use log::error; use tracing::error;
use crate::deps::*; use crate::deps::*;
use crate::widgets::LpImagePage; use crate::widgets::LpImagePage;
@ -76,7 +76,7 @@ impl PositionTracking {
fn set_progress(&mut self, progress: f64) { fn set_progress(&mut self, progress: f64) {
match self { match self {
Self::Position(_) => { Self::Position(_) => {
log::error!("Trying to set StackedCards progress while not in animation state.") tracing::error!("Trying to set StackedCards progress while not in animation state.")
} }
Self::StackedCards(cards) => cards.progress = progress, Self::StackedCards(cards) => cards.progress = progress,
}; };
@ -471,7 +471,7 @@ impl LpSlidingView {
/// Add page to the specified position /// Add page to the specified position
pub fn insert(&self, page: &LpImagePage, pos: usize) { pub fn insert(&self, page: &LpImagePage, pos: usize) {
if pos > self.n_pages() { if pos > self.n_pages() {
log::error!("Invalid insert position {pos} for {}", page.file().uri()); tracing::error!("Invalid insert position {pos} for {}", page.file().uri());
return; return;
} }
@ -499,7 +499,7 @@ impl LpSlidingView {
} }
self.shift_position(current_index); self.shift_position(current_index);
} else { } else {
log::error!("Page to move not found: {}", page.file().uri()); tracing::error!("Page to move not found: {}", page.file().uri());
} }
} }
@ -523,7 +523,7 @@ impl LpSlidingView {
self.clear(false); self.clear(false);
} }
} else { } else {
log::error!("Trying to remove non-existent page."); tracing::error!("Trying to remove non-existent page.");
} }
} }
@ -589,7 +589,7 @@ impl LpSlidingView {
self.set_current_page(Some(page)); self.set_current_page(Some(page));
self.emit_target_page_reached(); self.emit_target_page_reached();
} else { } else {
log::error!("Page not in LpSlidingView {}", page.file().uri()); tracing::error!("Page not in LpSlidingView {}", page.file().uri());
} }
} }
@ -605,7 +605,7 @@ impl LpSlidingView {
self.scroll_to(page, 0.); self.scroll_to(page, 0.);
} }
} else { } else {
log::error!("Page not in LpSlidingView {}", page.file().uri()); tracing::error!("Page not in LpSlidingView {}", page.file().uri());
} }
} }
@ -640,7 +640,7 @@ impl LpSlidingView {
self.set_current_page(Some(page)); self.set_current_page(Some(page));
animation.play(); animation.play();
} else { } else {
log::error!("Page not in LpSlidingView {}", page.file().uri()); tracing::error!("Page not in LpSlidingView {}", page.file().uri());
} }
} }
@ -691,7 +691,7 @@ impl LpSlidingView {
match &*self.imp().position_tracking.borrow() { match &*self.imp().position_tracking.borrow() {
PositionTracking::Position(position) => *position, PositionTracking::Position(position) => *position,
PositionTracking::StackedCards(_) => { PositionTracking::StackedCards(_) => {
log::error!("Using SlidindView position while in StackedCards animation"); tracing::error!("Using SlidindView position while in StackedCards animation");
0. 0.
} }
} }

View file

@ -122,7 +122,7 @@ mod imp {
#[weak] #[weak]
obj, obj,
move || if !obj.is_visible() { move || if !obj.is_visible() {
log::debug!("Showing window after timeout"); tracing::debug!("Showing window after timeout");
obj.present() obj.present()
} }
), ),
@ -227,7 +227,7 @@ impl LpWindow {
pub async fn show_about(&self) { pub async fn show_about(&self) {
let about = crate::about::dialog().await; let about = crate::about::dialog().await;
log::debug!("Showing about dialog"); tracing::debug!("Showing about dialog");
about.present(Some(self)); about.present(Some(self));
} }
@ -238,7 +238,7 @@ impl LpWindow {
} }
pub fn show_specific_image(&self, file: gio::File) { pub fn show_specific_image(&self, file: gio::File) {
log::debug!("Showing specific image: {}", file.uri()); tracing::debug!("Showing specific image: {}", file.uri());
self.image_view().set_images_from_files(vec![file]); self.image_view().set_images_from_files(vec![file]);
self.show_image(); self.show_image();
} }
@ -251,7 +251,7 @@ impl LpWindow {
self.imp().stack.set_visible_child(edit_child); self.imp().stack.set_visible_child(edit_child);
self.set_fullscreened(false); self.set_fullscreened(false);
} else { } else {
log::error!("Can't open image editor since no current image exists"); tracing::error!("Can't open image editor since no current image exists");
} }
} }