Added a PodcastChild struct and groupd some flowbox_child methods.

This commit is contained in:
Jordan Petridis 2017-12-01 04:22:26 +02:00
parent 300fc3467d
commit dcc541d832
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
2 changed files with 62 additions and 36 deletions

View File

@ -4,8 +4,6 @@ use gtk::prelude::*;
// use diesel::Identifiable; // use diesel::Identifiable;
use hammond_data::Podcast;
use widgets::podcast::PodcastWidget; use widgets::podcast::PodcastWidget;
use views::podcasts::PopulatedView; use views::podcasts::PopulatedView;
use views::empty::EmptyView; use views::empty::EmptyView;

View File

@ -12,10 +12,20 @@ use utils::get_pixbuf_from_path;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct PopulatedView { pub struct PopulatedView {
pub container: gtk::Box, pub container: gtk::Box,
pub flowbox: gtk::FlowBox, flowbox: gtk::FlowBox,
viewport: gtk::Viewport, viewport: gtk::Viewport,
} }
#[derive(Debug)]
struct PodcastChild {
container: gtk::Box,
title: gtk::Label,
cover: gtk::Image,
banner: gtk::Image,
number: gtk::Label,
child: gtk::FlowBoxChild,
}
impl PopulatedView { impl PopulatedView {
pub fn new() -> PopulatedView { pub fn new() -> PopulatedView {
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/podcasts_view.ui"); let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/podcasts_view.ui");
@ -51,53 +61,71 @@ impl PopulatedView {
if let Ok(pds) = podcasts { if let Ok(pds) = podcasts {
pds.iter().for_each(|parent| { pds.iter().for_each(|parent| {
let f = create_flowbox_child(parent); let flowbox_child = PodcastChild::new_initialized(parent);
self.flowbox.add(&f); self.flowbox.add(&flowbox_child.child);
}); });
self.flowbox.show_all(); self.flowbox.show_all();
} }
} }
} }
fn create_flowbox_child(pd: &Podcast) -> gtk::FlowBoxChild { impl PodcastChild {
fn new() -> PodcastChild {
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/podcasts_child.ui"); let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/podcasts_child.ui");
// Copy of gnome-music AlbumWidget // Copy of gnome-music AlbumWidget
let box_: gtk::Box = builder.get_object("fb_child").unwrap(); let container: gtk::Box = builder.get_object("fb_child").unwrap();
let pd_title: gtk::Label = builder.get_object("pd_title").unwrap(); let title: gtk::Label = builder.get_object("pd_title").unwrap();
let pd_cover: gtk::Image = builder.get_object("pd_cover").unwrap(); let cover: gtk::Image = builder.get_object("pd_cover").unwrap();
let banner: gtk::Image = builder.get_object("banner").unwrap(); let banner: gtk::Image = builder.get_object("banner").unwrap();
let banner_title: gtk::Label = builder.get_object("banner_label").unwrap(); let number: gtk::Label = builder.get_object("banner_label").unwrap();
pd_title.set_text(pd.title()); let child = gtk::FlowBoxChild::new();
child.add(&container);
PodcastChild {
container,
title,
cover,
banner,
number,
child,
}
}
fn init(&self, pd: &Podcast) {
self.title.set_text(pd.title());
let cover = get_pixbuf_from_path(pd); let cover = get_pixbuf_from_path(pd);
if let Some(img) = cover { if let Some(img) = cover {
pd_cover.set_from_pixbuf(&img); self.cover.set_from_pixbuf(&img);
}; };
configure_banner(pd, &banner, &banner_title); WidgetExt::set_name(&self.child, &pd.id().to_string());
self.configure_banner(pd);
}
let fbc = gtk::FlowBoxChild::new(); pub fn new_initialized(pd: &Podcast) -> PodcastChild {
// There's probably a better way to store the id somewhere. let child = PodcastChild::new();
// fbc.set_name(&pd.id().to_string()); child.init(pd);
WidgetExt::set_name(&fbc, &pd.id().to_string());
fbc.add(&box_);
fbc
}
fn configure_banner(pd: &Podcast, banner: &gtk::Image, banner_title: &gtk::Label) { child
let bann = Pixbuf::new_from_resource_at_scale("/org/gnome/hammond/banner.png", 256, 256, true); }
fn configure_banner(&self, pd: &Podcast) {
let bann =
Pixbuf::new_from_resource_at_scale("/org/gnome/hammond/banner.png", 256, 256, true);
if let Ok(b) = bann { if let Ok(b) = bann {
banner.set_from_pixbuf(&b); self.banner.set_from_pixbuf(&b);
let new_episodes = dbqueries::get_pd_unplayed_episodes(pd); let new_episodes = dbqueries::get_pd_unplayed_episodes(pd);
if let Ok(n) = new_episodes { if let Ok(n) = new_episodes {
if !n.is_empty() { if !n.is_empty() {
banner_title.set_text(&n.len().to_string()); self.number.set_text(&n.len().to_string());
banner.show(); self.banner.show();
banner_title.show(); self.number.show();
}
} }
} }
} }