From 895591f628eeab91635161ac7b60841662d02d41 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Tue, 19 Dec 2017 13:19:38 +0200 Subject: [PATCH] EpisodesView: Use show cover image. --- hammond-data/src/lib.rs | 2 +- hammond-data/src/models/queryables.rs | 8 ++++++++ hammond-gtk/src/utils.rs | 7 +++++++ hammond-gtk/src/views/episodes.rs | 22 ++++++++++++++++------ 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/hammond-data/src/lib.rs b/hammond-data/src/lib.rs index 97aec76..711eb0c 100644 --- a/hammond-data/src/lib.rs +++ b/hammond-data/src/lib.rs @@ -61,7 +61,7 @@ pub(crate) mod models; mod parser; mod schema; -pub use models::queryables::{Episode, EpisodeWidgetQuery, Podcast, Source}; +pub use models::queryables::{Episode, EpisodeViewWidgetQuery, EpisodeWidgetQuery, Podcast, Source}; /// [XDG Base Direcotory](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html) Paths. #[allow(missing_debug_implementations)] diff --git a/hammond-data/src/models/queryables.rs b/hammond-data/src/models/queryables.rs index e87d8b6..5120f83 100644 --- a/hammond-data/src/models/queryables.rs +++ b/hammond-data/src/models/queryables.rs @@ -354,9 +354,17 @@ pub struct EpisodeViewWidgetQuery { } impl EpisodeViewWidgetQuery { + /// Get the `image_uri`. + /// + /// Represents the uri(url usually) that the Feed cover image is located at. pub fn image_uri(&self) -> Option<&str> { self.image_uri.as_ref().map(|s| s.as_str()) } + + /// `Podcast` table foreign key. + pub fn podcast_id(&self) -> i32 { + self.podcast_id + } } #[derive(Queryable, Identifiable, AsChangeset, Associations, PartialEq)] diff --git a/hammond-gtk/src/utils.rs b/hammond-gtk/src/utils.rs index c2f484d..66f5b54 100644 --- a/hammond-gtk/src/utils.rs +++ b/hammond-gtk/src/utils.rs @@ -59,6 +59,8 @@ fn refresh_podcasts_view() -> glib::Continue { glib::Continue(false) } +// FIXME: use something that would just scale? + pub fn get_pixbuf_from_path(pd: &Podcast) -> Option { let img_path = downloader::cache_image(pd)?; Pixbuf::new_from_file_at_scale(&img_path, 256, 256, true).ok() @@ -69,6 +71,11 @@ pub fn get_pixbuf_from_path_128(pd: &Podcast) -> Option { Pixbuf::new_from_file_at_scale(&img_path, 128, 128, true).ok() } +pub fn get_pixbuf_from_path_64(pd: &Podcast) -> Option { + let img_path = downloader::cache_image(pd)?; + Pixbuf::new_from_file_at_scale(&img_path, 64, 64, true).ok() +} + #[cfg(test)] mod tests { use hammond_data::Source; diff --git a/hammond-gtk/src/views/episodes.rs b/hammond-gtk/src/views/episodes.rs index 120bc7f..00a883b 100644 --- a/hammond-gtk/src/views/episodes.rs +++ b/hammond-gtk/src/views/episodes.rs @@ -2,9 +2,10 @@ use gtk; use gtk::prelude::*; use hammond_data::dbqueries; -use hammond_data::EpisodeWidgetQuery; +use hammond_data::EpisodeViewWidgetQuery; use widgets::episode::EpisodeWidget; +use utils::get_pixbuf_from_path_64; use std::rc::Rc; @@ -32,11 +33,12 @@ impl EpisodesView { let view = EpisodesView::default(); let episodes = dbqueries::get_episodes_view_widgets_with_limit(100).unwrap(); - let frame = gtk::Frame::new("Recent Episodes"); + let frame = gtk::Frame::new(None); let list = gtk::ListBox::new(); - view.frame_parent.add(&frame); + view.frame_parent.pack_start(&frame, true, false, 10); frame.add(&list); + frame.set_shadow_type(gtk::ShadowType::In); list.set_vexpand(false); list.set_hexpand(false); @@ -44,7 +46,7 @@ impl EpisodesView { list.set_selection_mode(gtk::SelectionMode::None); episodes.into_iter().for_each(|ep| { - let viewep = EpisodesViewWidget::new(&mut ep.into()); + let viewep = EpisodesViewWidget::new(ep); list.add(&viewep.container); let sep = gtk::Separator::new(gtk::Orientation::Vertical); @@ -84,12 +86,20 @@ impl Default for EpisodesViewWidget { } impl EpisodesViewWidget { - fn new(episode: &mut EpisodeWidgetQuery) -> EpisodesViewWidget { + fn new(episode: EpisodeViewWidgetQuery) -> EpisodesViewWidget { let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/episodes_view_widget.ui"); let container: gtk::Box = builder.get_object("container").unwrap(); let image: gtk::Image = builder.get_object("cover").unwrap(); - let ep = EpisodeWidget::new(episode); + + // FIXME: + let pd = dbqueries::get_podcast_from_id(episode.podcast_id()).unwrap(); + let img = get_pixbuf_from_path_64(&pd); + if let Some(i) = img { + image.set_from_pixbuf(&i); + } + + let ep = EpisodeWidget::new(&mut episode.into()); container.pack_start(&ep.container, true, true, 5); EpisodesViewWidget {