EpisodesView: Use show cover image.

This commit is contained in:
Jordan Petridis 2017-12-19 13:19:38 +02:00
parent ad9a932143
commit 895591f628
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
4 changed files with 32 additions and 7 deletions

View File

@ -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)]

View File

@ -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)]

View File

@ -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<Pixbuf> {
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> {
Pixbuf::new_from_file_at_scale(&img_path, 128, 128, true).ok()
}
pub fn get_pixbuf_from_path_64(pd: &Podcast) -> Option<Pixbuf> {
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;

View File

@ -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 {