hammond-gtk::utils: change the signature of get_pixbug_from_path and rename it
Requires a gtk::Image as argument now, it sets the pixbuf to the img directly instead of returning it. New name is set_image_from_path. This is ground work so we can later keep the image reference, and use it to set the image with a callback.
This commit is contained in:
parent
89ee174ded
commit
daa8f15ce9
@ -1,8 +1,11 @@
|
|||||||
#![cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
|
#![cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
|
||||||
|
|
||||||
use failure::Error;
|
|
||||||
use gdk_pixbuf::Pixbuf;
|
use gdk_pixbuf::Pixbuf;
|
||||||
use gio::{Settings, SettingsExt};
|
use gio::{Settings, SettingsExt};
|
||||||
|
use gtk;
|
||||||
|
use gtk::prelude::*;
|
||||||
|
|
||||||
|
use failure::Error;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use reqwest;
|
use reqwest;
|
||||||
use send_cell::SendCell;
|
use send_cell::SendCell;
|
||||||
@ -137,7 +140,11 @@ lazy_static! {
|
|||||||
// GObjects do not implement Send trait, so SendCell is a way around that.
|
// GObjects do not implement Send trait, so SendCell is a way around that.
|
||||||
// Also lazy_static requires Sync trait, so that's what the mutexes are.
|
// Also lazy_static requires Sync trait, so that's what the mutexes are.
|
||||||
// TODO: maybe use something that would just scale to requested size?
|
// TODO: maybe use something that would just scale to requested size?
|
||||||
pub fn get_pixbuf_from_path(pd: &PodcastCoverQuery, size: u32) -> Result<Pixbuf, Error> {
|
pub fn set_image_from_path(
|
||||||
|
image: >k::Image,
|
||||||
|
pd: &PodcastCoverQuery,
|
||||||
|
size: u32,
|
||||||
|
) -> Result<(), Error> {
|
||||||
{
|
{
|
||||||
let hashmap = CACHED_PIXBUFS
|
let hashmap = CACHED_PIXBUFS
|
||||||
.read()
|
.read()
|
||||||
@ -145,7 +152,9 @@ pub fn get_pixbuf_from_path(pd: &PodcastCoverQuery, size: u32) -> Result<Pixbuf,
|
|||||||
if let Some(px) = hashmap.get(&(pd.id(), size)) {
|
if let Some(px) = hashmap.get(&(pd.id(), size)) {
|
||||||
let m = px.lock()
|
let m = px.lock()
|
||||||
.map_err(|_| format_err!("Failed to lock pixbuf mutex."))?;
|
.map_err(|_| format_err!("Failed to lock pixbuf mutex."))?;
|
||||||
return Ok(m.clone().into_inner());
|
let px = m.clone().into_inner();
|
||||||
|
image.set_from_pixbuf(&px);
|
||||||
|
return Ok(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,7 +164,8 @@ pub fn get_pixbuf_from_path(pd: &PodcastCoverQuery, size: u32) -> Result<Pixbuf,
|
|||||||
.write()
|
.write()
|
||||||
.map_err(|_| format_err!("Failed to lock pixbuf mutex."))?;
|
.map_err(|_| format_err!("Failed to lock pixbuf mutex."))?;
|
||||||
hashmap.insert((pd.id(), size), Mutex::new(SendCell::new(px.clone())));
|
hashmap.insert((pd.id(), size), Mutex::new(SendCell::new(px.clone())));
|
||||||
Ok(px)
|
image.set_from_pixbuf(&px);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|||||||
@ -7,7 +7,7 @@ use hammond_data::EpisodeWidgetQuery;
|
|||||||
use hammond_data::dbqueries;
|
use hammond_data::dbqueries;
|
||||||
|
|
||||||
use app::Action;
|
use app::Action;
|
||||||
use utils::{get_ignored_shows, get_pixbuf_from_path};
|
use utils::{get_ignored_shows, set_image_from_path};
|
||||||
use widgets::EpisodeWidget;
|
use widgets::EpisodeWidget;
|
||||||
|
|
||||||
use std::sync::mpsc::Sender;
|
use std::sync::mpsc::Sender;
|
||||||
@ -228,8 +228,6 @@ impl EpisodesViewWidget {
|
|||||||
|
|
||||||
fn set_cover(&self, podcast_id: i32) -> Result<(), Error> {
|
fn set_cover(&self, podcast_id: i32) -> Result<(), Error> {
|
||||||
let pd = dbqueries::get_podcast_cover_from_id(podcast_id)?;
|
let pd = dbqueries::get_podcast_cover_from_id(podcast_id)?;
|
||||||
let img = get_pixbuf_from_path(&pd, 64)?;
|
set_image_from_path(&self.image, &pd, 64)
|
||||||
self.image.set_from_pixbuf(&img);
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@ use hammond_data::Podcast;
|
|||||||
use hammond_data::dbqueries;
|
use hammond_data::dbqueries;
|
||||||
|
|
||||||
use app::Action;
|
use app::Action;
|
||||||
use utils::{get_ignored_shows, get_pixbuf_from_path};
|
use utils::{get_ignored_shows, set_image_from_path};
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::sync::mpsc::Sender;
|
use std::sync::mpsc::Sender;
|
||||||
@ -133,8 +133,6 @@ impl ShowsChild {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn set_cover(&self, pd: Arc<Podcast>) -> Result<(), Error> {
|
fn set_cover(&self, pd: Arc<Podcast>) -> Result<(), Error> {
|
||||||
let image = get_pixbuf_from_path(&pd.clone().into(), 256)?;
|
set_image_from_path(&self.cover, &pd.clone().into(), 256)
|
||||||
self.cover.set_from_pixbuf(&image);
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,7 +10,7 @@ use hammond_data::dbqueries;
|
|||||||
use hammond_data::utils::replace_extra_spaces;
|
use hammond_data::utils::replace_extra_spaces;
|
||||||
|
|
||||||
use app::Action;
|
use app::Action;
|
||||||
use utils::get_pixbuf_from_path;
|
use utils::set_image_from_path;
|
||||||
use widgets::episode::episodes_listbox;
|
use widgets::episode::episodes_listbox;
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@ -113,9 +113,7 @@ impl ShowWidget {
|
|||||||
|
|
||||||
/// Set the show cover.
|
/// Set the show cover.
|
||||||
fn set_cover(&self, pd: Arc<Podcast>) -> Result<(), Error> {
|
fn set_cover(&self, pd: Arc<Podcast>) -> Result<(), Error> {
|
||||||
let image = get_pixbuf_from_path(&pd.into(), 128)?;
|
set_image_from_path(&self.cover, &pd.into(), 128)
|
||||||
self.cover.set_from_pixbuf(&image);
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the descripton text.
|
/// Set the descripton text.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user