imageView: Skip unsupported formats when sliding
If an image with unsupported format is opened directly, the error is shown. Closes #92 Part-of: <https://gitlab.gnome.org/Incubator/loupe/-/merge_requests/212>
This commit is contained in:
parent
8f55668cd6
commit
6db58463bf
5 changed files with 83 additions and 25 deletions
|
|
@ -109,6 +109,7 @@ mod imp {
|
|||
pub struct LpImage {
|
||||
pub(super) file: RefCell<Option<gio::File>>,
|
||||
pub(super) is_deleted: Cell<bool>,
|
||||
pub(super) is_unsupported: Cell<bool>,
|
||||
/// Track changes to this image
|
||||
pub(super) file_monitor: RefCell<Option<gio::FileMonitor>>,
|
||||
pub(super) frame_buffer: Arc<ArcSwap<tiling::FrameBuffer>>,
|
||||
|
|
@ -200,6 +201,9 @@ mod imp {
|
|||
glib::ParamSpecBoolean::builder("is-loaded")
|
||||
.read_only()
|
||||
.build(),
|
||||
glib::ParamSpecBoolean::builder("is-unsupported")
|
||||
.read_only()
|
||||
.build(),
|
||||
glib::ParamSpecString::builder("error").read_only().build(),
|
||||
glib::ParamSpecObject::builder::<LpImageMetadata>("metadata")
|
||||
.read_only()
|
||||
|
|
@ -241,6 +245,7 @@ mod imp {
|
|||
"file" => obj.file().to_value(),
|
||||
"is-deleted" => obj.is_deleted().to_value(),
|
||||
"is-loaded" => obj.is_loaded().to_value(),
|
||||
"is-unsupported" => obj.is_unsupported().to_value(),
|
||||
"error" => obj.error().to_value(),
|
||||
"metadata" => obj.metadata().to_value(),
|
||||
"format-name" => obj.format_name().to_value(),
|
||||
|
|
@ -759,13 +764,7 @@ impl LpImage {
|
|||
// Reset background color for reloads
|
||||
self.set_background_color(None);
|
||||
|
||||
let (decoder, mut decoder_update) = match Decoder::new(file.clone(), tiles.clone()).await {
|
||||
Ok(x) => x,
|
||||
Err(err) => {
|
||||
self.set_error(err);
|
||||
return;
|
||||
}
|
||||
};
|
||||
let (decoder_res, mut decoder_update) = Decoder::new(file.clone(), tiles.clone()).await;
|
||||
|
||||
let weak_obj = self.downgrade();
|
||||
spawn(async move {
|
||||
|
|
@ -777,8 +776,10 @@ impl LpImage {
|
|||
log::debug!("Stopped listening to decoder since sender is gone");
|
||||
});
|
||||
|
||||
let decoder = Arc::new(decoder);
|
||||
self.imp().decoder.replace(Some(decoder));
|
||||
if let Ok(decoder) = decoder_res {
|
||||
let decoder = Arc::new(decoder);
|
||||
self.imp().decoder.replace(Some(decoder));
|
||||
}
|
||||
}
|
||||
|
||||
/// Called when decoder sends update
|
||||
|
|
@ -837,6 +838,12 @@ impl LpImage {
|
|||
imp.tick_callback.replace(Some(callback_id));
|
||||
}
|
||||
}
|
||||
DecoderUpdate::UnsupportedFormat => {
|
||||
if !self.is_unsupported() {
|
||||
imp.is_unsupported.set(true);
|
||||
self.notify("is-unsupported");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -874,6 +881,10 @@ impl LpImage {
|
|||
self.imp().is_deleted.get()
|
||||
}
|
||||
|
||||
pub fn is_unsupported(&self) -> bool {
|
||||
self.imp().is_unsupported.get()
|
||||
}
|
||||
|
||||
/// Zoom level that makes the image fit in widget
|
||||
///
|
||||
/// During image rotation the image does not actually fit into widget.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue