From f1f4d10fe32335dd55007ac38bfd30e0b7b24b7f Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Fri, 1 Dec 2017 01:00:07 +0200 Subject: [PATCH] Add PopulatedView struct. --- hammond-gtk/src/views/podcasts.rs | 39 ++++++++++++++++++++++++++++++ hammond-gtk/src/widgets/podcast.rs | 15 +++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/hammond-gtk/src/views/podcasts.rs b/hammond-gtk/src/views/podcasts.rs index 2b55a96..a3de458 100644 --- a/hammond-gtk/src/views/podcasts.rs +++ b/hammond-gtk/src/views/podcasts.rs @@ -9,6 +9,45 @@ use hammond_data::Podcast; use widgets::podcast::*; use utils::get_pixbuf_from_path; +#[derive(Debug, Clone)] +pub struct PopulatedView { + container: gtk::Box, + flowbox: gtk::FlowBox, + viewport: gtk::Viewport, +} + +impl PopulatedView { + pub fn new() -> PopulatedView { + let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/podcasts_view.ui"); + let container: gtk::Box = builder.get_object("fb_parent").unwrap(); + let flowbox: gtk::FlowBox = builder.get_object("flowbox").unwrap(); + let viewport: gtk::Viewport = builder.get_object("viewport").unwrap(); + + PopulatedView { + container, + flowbox, + viewport, + } + } + + pub fn init(&self, content_stack: >k::Stack) { + use gtk::WidgetExt; + + // TODO: handle unwraps. + let stack = content_stack; + self.flowbox + .connect_child_activated(clone!(stack => move |_, child| { + // This is such an ugly hack... + // let id = child.get_name().unwrap().parse::().unwrap(); + let id = WidgetExt::get_name(child).unwrap().parse::().unwrap(); + let parent = dbqueries::get_podcast_from_id(id).unwrap(); + on_flowbox_child_activate(&stack, &parent); + })); + // Populate the flowbox with the Podcasts. + populate_flowbox(&self.flowbox); + } +} + fn setup_empty_view(stack: >k::Stack) { let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/empty_view.ui"); let view: gtk::Box = builder.get_object("empty_view").unwrap(); diff --git a/hammond-gtk/src/widgets/podcast.rs b/hammond-gtk/src/widgets/podcast.rs index 9e9afd6..f40bea2 100644 --- a/hammond-gtk/src/widgets/podcast.rs +++ b/hammond-gtk/src/widgets/podcast.rs @@ -72,7 +72,17 @@ impl PodcastWidget { on_played_button_clicked(&stack, &pd); })); - show_played_button(pd, &self.played); + self.show_played_button(pd); + } + + fn show_played_button(&self, pd: &Podcast) { + let new_episodes = dbqueries::get_pd_unplayed_episodes(pd); + + if let Ok(n) = new_episodes { + if !n.is_empty() { + self.played.show() + } + } } } @@ -118,6 +128,7 @@ pub fn podcast_widget(stack: >k::Stack, pd: &Podcast) -> gtk::Box { pd_widget } +// Note: Stack manipulation fn on_unsub_button_clicked(stack: >k::Stack, pd: &Podcast, unsub_button: >k::Button) { let res = dbqueries::remove_feed(pd); if res.is_ok() { @@ -154,6 +165,7 @@ fn show_played_button(pd: &Podcast, played_button: >k::Button) { } } +// Note: Stack manipulation pub fn setup_podcast_widget(stack: >k::Stack) { let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/podcast_widget.ui"); let pd_widget: gtk::Box = builder.get_object("podcast_widget").unwrap(); @@ -161,6 +173,7 @@ pub fn setup_podcast_widget(stack: >k::Stack) { stack.add_named(&pd_widget, "pdw"); } +// Note: Stack manipulation pub fn update_podcast_widget(stack: >k::Stack, pd: &Podcast) { let old = stack.get_child_by_name("pdw").unwrap(); let pdw = podcast_widget(stack, pd);