diff --git a/hammond-gtk/src/content.rs b/hammond-gtk/src/content.rs index b7dc9be..dc8e0d0 100644 --- a/hammond-gtk/src/content.rs +++ b/hammond-gtk/src/content.rs @@ -2,6 +2,7 @@ use gtk; use gtk::prelude::*; use hammond_data::Podcast; +use hammond_data::dbqueries; use widgets::podcast::PodcastWidget; use views::podcasts::PopulatedView; @@ -36,6 +37,10 @@ impl Content { } } +trait UpdateView { + fn update(&mut self); +} + #[derive(Debug)] struct Empty { content: Content @@ -67,6 +72,10 @@ impl Empty { } } +impl UpdateView for Empty { + fn update(&mut self) {} +} + impl PodcastsView { fn into_empty(self) -> Result { if !self.content.podcasts.flowbox.get_children().is_empty() { @@ -91,6 +100,19 @@ impl PodcastsView { } } +impl UpdateView for PodcastsView { + fn update(&mut self) { + let old = self.content.stack.get_child_by_name("podcasts").unwrap(); + + self.content.podcasts = PopulatedView::new_initialized(&self.content.stack); + + self.content.stack.remove(&old); + self.content.stack.add_named(&self.content.podcasts.container, "podcasts"); + + old.destroy(); + } +} + impl WidgetsView { fn into_podcasts(self) -> PodcastsView { self.content.stack.set_visible_child_name("podcasts"); @@ -107,6 +129,20 @@ impl WidgetsView { } } +impl UpdateView for WidgetsView { + fn update(&mut self) { + let old = self.content.stack.get_child_by_name("widget").unwrap(); + let id = WidgetExt::get_name(&old).unwrap(); + let pd = dbqueries::get_podcast_from_id(id.parse::().unwrap()).unwrap(); + + self.content.widget = PodcastWidget::new_initialized(&self.content.stack, &pd);; + self.content.stack.remove(&old); + self.content.stack.add_named(&self.content.widget.container, "widget"); + + old.destroy(); + } +} + #[derive(Debug)] pub enum ContentState { empty(Empty), @@ -135,6 +171,14 @@ impl ContentState { ContentState::pd(ref e) => e.content.stack.clone(), } } + + pub fn update(&mut self) { + match *self { + ContentState::empty(ref mut e) => e.update(), + ContentState::pop(ref mut e) => e.update(), + ContentState::pd(ref mut e) => e.update(), + } + } } fn replace_widget(stack: >k::Stack, pdw: &PodcastWidget) { diff --git a/hammond-gtk/src/widgets/podcast.rs b/hammond-gtk/src/widgets/podcast.rs index 4fe93dd..206ffd9 100644 --- a/hammond-gtk/src/widgets/podcast.rs +++ b/hammond-gtk/src/widgets/podcast.rs @@ -1,5 +1,6 @@ use gtk::prelude::*; use gtk; +use diesel::Identifiable; use std::fs; @@ -53,6 +54,8 @@ impl PodcastWidget { } pub fn init(&self, stack: >k::Stack, pd: &Podcast) { + WidgetExt::set_name(&self.container, &pd.id().to_string()); + // TODO: should spawn a thread to avoid locking the UI probably. self.unsub.connect_clicked(clone!(stack, pd => move |bttn| { on_unsub_button_clicked(&stack, &pd, bttn);