Skip to content

Commit

Permalink
Thumbnails: Do not create one if the file does not exist.
Browse files Browse the repository at this point in the history
  • Loading branch information
huanie committed Aug 12, 2023
1 parent b0622b7 commit 2b6d16e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/file_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,22 @@ impl FileObject {
let obj = Object::builder().property("file", file);
let icon_name = gio::content_type_get_generic_icon_name(&file.mime_type());
// use the default thumbnail
let image = gtk::Image::builder()
let icon = gtk::Image::builder()
.icon_name(icon_name.unwrap_or(glib::GString::format(format_args!("text/default"))))
.pixel_size(ARGS.get().unwrap().icon_size)
.build();
let obj = obj.property("thumbnail", image).build();
let obj = obj.property("thumbnail", icon).build();
let file = file.clone();

// For every image a thumbnail of the image is sent. When it is not an image a None is sent.
// There is no thumbnail for GIFs.
let (sender, receiver) = MainContext::channel(Priority::default());
gio::spawn_blocking(move || {
let print_err = |err| eprintln!("{}", err);
if !file.query_exists(gio::Cancellable::NONE) {
let _ = sender.send(None).map_err(print_err);
}

let mime_type = file.mime_type();
// this only works for images
if !ARGS.get().unwrap().disable_thumbnails
Expand Down

0 comments on commit 2b6d16e

Please sign in to comment.