diff --git a/hammond-gtk/src/content.rs b/hammond-gtk/src/content.rs index 7554cb3..e8c359f 100644 --- a/hammond-gtk/src/content.rs +++ b/hammond-gtk/src/content.rs @@ -17,7 +17,7 @@ pub struct Content { } impl Content { - fn new() -> Content { + pub fn new() -> Content { let stack = gtk::Stack::new(); let widget = PodcastWidget::new(); @@ -36,6 +36,22 @@ impl Content { } } + pub fn new_initialized() -> Content { + let ct = Content::new(); + ct.init(); + ct + } + + pub fn init(&self) { + self.podcasts.init(&self.stack); + if self.podcasts.flowbox.get_children().is_empty() { + self.stack.set_visible_child_name("empty"); + return + } + + self.stack.set_visible_child_name("podcasts"); + } + fn replace_widget(&mut self, pdw: PodcastWidget) { let vis = self.stack.get_visible_child_name().unwrap(); let old = self.stack.get_child_by_name("widget").unwrap(); @@ -60,6 +76,8 @@ impl Content { } #[derive(Debug)] +// Experiementing with Wrapping gtk::Stack into a State machine. +// Gonna revist it when TryInto trais is stabilized. pub struct ContentState { content: Content, state: S, @@ -153,6 +171,7 @@ impl UpdateView for ContentState { } impl ContentState { + #[allow(dead_code)] pub fn new() -> Result, ContentState> { let content = Content::new(); @@ -173,6 +192,7 @@ impl ContentState { }) } + #[allow(dead_code)] pub fn get_stack(&self) -> gtk::Stack { self.content.stack.clone() } @@ -192,14 +212,6 @@ fn replace_podcasts(stack: >k::Stack, pop: &PopulatedView) { old.destroy(); } -// This won't ever be needed probably -// pub fn replace_empty(stack: >k::Stack, emp: &EmptyView ) { -// let old = stack.get_child_by_name("empty").unwrap(); -// stack.remove(&old); -// stack.add_named(&emp.container, "empty"); -// old.destroy(); -// } - #[allow(dead_code)] pub fn show_widget(stack: >k::Stack) { stack.set_visible_child_name("widget") diff --git a/hammond-gtk/src/main.rs b/hammond-gtk/src/main.rs index afe1012..f4fd89b 100644 --- a/hammond-gtk/src/main.rs +++ b/hammond-gtk/src/main.rs @@ -64,8 +64,11 @@ fn build_ui(app: >k::Application) { window.set_default_size(1150, 650); // TODO: this will blow horribly - let ct = content::ContentState::new().unwrap(); - let stack = ct.get_stack(); + // let ct = content::ContentState::new().unwrap(); + // let stack = ct.get_stack(); + + let ct = content::Content::new_initialized(); + let stack = ct.stack; window.add(&stack); window.connect_delete_event(|w, _| {