h-gtk/utils: More refactor to improve formatting.
This commit is contained in:
parent
f21398357b
commit
7086afe73d
@ -151,15 +151,12 @@ pub fn set_image_from_path(
|
|||||||
pd: Arc<PodcastCoverQuery>,
|
pd: Arc<PodcastCoverQuery>,
|
||||||
size: u32,
|
size: u32,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
{
|
// Check if there's an active download about this show cover.
|
||||||
// Check if there's an active download about this show cover.
|
// If there is, a callback will be set so this function will be called again.
|
||||||
// If there is, a callback will be set so this function will be called again.
|
// If the download succedes, there should be a quick return from the pixbuf cache_image
|
||||||
// If the download succedes, there should be a quick return from the pixbuf cache_image
|
// If it fails another download will be scheduled.
|
||||||
// If it fails another download will be scheduled.
|
if let Ok(guard) = COVER_DL_REGISTRY.read() {
|
||||||
let reg_guard = COVER_DL_REGISTRY
|
if guard.contains(&pd.id()) {
|
||||||
.read()
|
|
||||||
.map_err(|err| format_err!("Cover Registry: {}.", err))?;
|
|
||||||
if reg_guard.contains(&pd.id()) {
|
|
||||||
let callback = clone!(image, pd => move || {
|
let callback = clone!(image, pd => move || {
|
||||||
let _ = set_image_from_path(&image, pd.clone(), size);
|
let _ = set_image_from_path(&image, pd.clone(), size);
|
||||||
glib::Continue(false)
|
glib::Continue(false)
|
||||||
@ -169,10 +166,9 @@ pub fn set_image_from_path(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
if let Ok(hashmap) = CACHED_PIXBUFS.read() {
|
||||||
let hashmap = CACHED_PIXBUFS
|
// Check if the requested (cover + size) is already in the chache
|
||||||
.read()
|
// and if so do an early return after that.
|
||||||
.map_err(|err| format_err!("Pixbuf HashMap: {}", err))?;
|
|
||||||
if let Some(guard) = hashmap.get(&(pd.id(), size)) {
|
if let Some(guard) = hashmap.get(&(pd.id(), size)) {
|
||||||
guard
|
guard
|
||||||
.lock()
|
.lock()
|
||||||
@ -181,10 +177,9 @@ pub fn set_image_from_path(
|
|||||||
sendcell
|
sendcell
|
||||||
.try_get()
|
.try_get()
|
||||||
.map(|px| image.set_from_pixbuf(px))
|
.map(|px| image.set_from_pixbuf(px))
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| format_err!("Pixbuf was accessed from a different thread"))
|
||||||
format_err!("Pixbuf was accessed from a different thread than created")
|
|
||||||
})
|
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user