EpisodesView: Use show cover image.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user