From daa8f15ce956ada22326cb23a3c922c29278a0d2 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Wed, 28 Mar 2018 21:47:10 +0300 Subject: [PATCH] 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. --- hammond-gtk/src/utils.rs | 18 ++++++++++++++---- hammond-gtk/src/views/episodes.rs | 6 ++---- hammond-gtk/src/views/shows.rs | 6 ++---- hammond-gtk/src/widgets/show.rs | 6 ++---- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/hammond-gtk/src/utils.rs b/hammond-gtk/src/utils.rs index f8a6bcb..65a24d3 100644 --- a/hammond-gtk/src/utils.rs +++ b/hammond-gtk/src/utils.rs @@ -1,8 +1,11 @@ #![cfg_attr(feature = "cargo-clippy", allow(type_complexity))] -use failure::Error; use gdk_pixbuf::Pixbuf; use gio::{Settings, SettingsExt}; +use gtk; +use gtk::prelude::*; + +use failure::Error; use regex::Regex; use reqwest; use send_cell::SendCell; @@ -137,7 +140,11 @@ lazy_static! { // 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. // TODO: maybe use something that would just scale to requested size? -pub fn get_pixbuf_from_path(pd: &PodcastCoverQuery, size: u32) -> Result { +pub fn set_image_from_path( + image: >k::Image, + pd: &PodcastCoverQuery, + size: u32, +) -> Result<(), Error> { { let hashmap = CACHED_PIXBUFS .read() @@ -145,7 +152,9 @@ pub fn get_pixbuf_from_path(pd: &PodcastCoverQuery, size: u32) -> Result Result Result<(), Error> { let pd = dbqueries::get_podcast_cover_from_id(podcast_id)?; - let img = get_pixbuf_from_path(&pd, 64)?; - self.image.set_from_pixbuf(&img); - Ok(()) + set_image_from_path(&self.image, &pd, 64) } } diff --git a/hammond-gtk/src/views/shows.rs b/hammond-gtk/src/views/shows.rs index 2a59984..1abf4c8 100644 --- a/hammond-gtk/src/views/shows.rs +++ b/hammond-gtk/src/views/shows.rs @@ -6,7 +6,7 @@ use hammond_data::Podcast; use hammond_data::dbqueries; 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::mpsc::Sender; @@ -133,8 +133,6 @@ impl ShowsChild { } fn set_cover(&self, pd: Arc) -> Result<(), Error> { - let image = get_pixbuf_from_path(&pd.clone().into(), 256)?; - self.cover.set_from_pixbuf(&image); - Ok(()) + set_image_from_path(&self.cover, &pd.clone().into(), 256) } } diff --git a/hammond-gtk/src/widgets/show.rs b/hammond-gtk/src/widgets/show.rs index 5a304fe..c6b458f 100644 --- a/hammond-gtk/src/widgets/show.rs +++ b/hammond-gtk/src/widgets/show.rs @@ -10,7 +10,7 @@ use hammond_data::dbqueries; use hammond_data::utils::replace_extra_spaces; use app::Action; -use utils::get_pixbuf_from_path; +use utils::set_image_from_path; use widgets::episode::episodes_listbox; use std::sync::Arc; @@ -113,9 +113,7 @@ impl ShowWidget { /// Set the show cover. fn set_cover(&self, pd: Arc) -> Result<(), Error> { - let image = get_pixbuf_from_path(&pd.into(), 128)?; - self.cover.set_from_pixbuf(&image); - Ok(()) + set_image_from_path(&self.cover, &pd.into(), 128) } /// Set the descripton text.