diff --git a/hammond-gtk/src/content.rs b/hammond-gtk/src/content.rs index d022c05..7554cb3 100644 --- a/hammond-gtk/src/content.rs +++ b/hammond-gtk/src/content.rs @@ -37,109 +37,111 @@ impl Content { } 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(); self.stack.remove(&old); self.widget = pdw; self.stack.add_named(&self.widget.container, "widget"); + self.stack.set_visible_child_name(&vis); old.destroy(); } fn replace_podcasts(&mut self, pop: PopulatedView) { + let vis = self.stack.get_visible_child_name().unwrap(); let old = self.stack.get_child_by_name("podcasts").unwrap(); self.stack.remove(&old); self.podcasts = pop; self.stack.add_named(&self.podcasts.container, "podcasts"); + self.stack.set_visible_child_name(&vis); old.destroy(); } } -trait UpdateView { +#[derive(Debug)] +pub struct ContentState { + content: Content, + state: S, +} + +pub trait UpdateView { fn update(&mut self); } #[derive(Debug)] -struct Empty { - content: Content -} +pub struct Empty {} #[derive(Debug)] -struct PodcastsView { - content: Content -} +pub struct PodcastsView {} #[derive(Debug)] -struct WidgetsView { - content: Content -} +pub struct WidgetsView {} -#[derive(Debug)] -pub enum ContentState { - empty(Empty), - pop(PodcastsView), - pd(WidgetsView), -} - -impl Into for Empty { - fn into(self) -> PodcastsView { +impl Into> for ContentState { + fn into(self) -> ContentState { self.content.stack.set_visible_child_name("podcasts"); - PodcastsView { - content: self.content + ContentState{ + content: self.content, + state: PodcastsView{}, } } } -impl UpdateView for Empty { +impl UpdateView for ContentState { fn update(&mut self) {} } -impl Into for PodcastsView { - fn into(self) -> Empty { +impl Into> for ContentState { + fn into(self) -> ContentState { self.content.stack.set_visible_child_name("empty"); - Empty { - content: self.content + ContentState{ + content: self.content, + state: Empty{}, } } } -impl Into for PodcastsView { - fn into(self) -> WidgetsView { +impl Into> for ContentState { + fn into(self) -> ContentState { self.content.stack.set_visible_child_name("widget"); - WidgetsView { - content: self.content + ContentState{ + content: self.content, + state: WidgetsView{}, } } } -impl UpdateView for PodcastsView { +impl UpdateView for ContentState { fn update(&mut self) { let pop = PopulatedView::new_initialized(&self.content.stack); self.content.replace_podcasts(pop) } } -impl Into for WidgetsView { - fn into(self) -> PodcastsView { +impl Into> for ContentState { + fn into(self) -> ContentState { self.content.stack.set_visible_child_name("podcasts"); - PodcastsView { - content: self.content + ContentState{ + content: self.content, + state: PodcastsView{}, } } } -impl Into for WidgetsView { - fn into(self) -> Empty { +impl Into> for ContentState { + fn into(self) -> ContentState { self.content.stack.set_visible_child_name("empty"); - Empty { - content: self.content + ContentState{ + content: self.content, + state: Empty{}, } } } -impl UpdateView for WidgetsView { +impl UpdateView for ContentState { fn update(&mut self) { let old = self.content.stack.get_child_by_name("widget").unwrap(); let id = WidgetExt::get_name(&old).unwrap(); @@ -150,34 +152,29 @@ impl UpdateView for WidgetsView { } } -impl ContentState { - pub fn new() -> ContentState { +impl ContentState { + pub fn new() -> Result, ContentState> { let content = Content::new(); content.podcasts.init(&content.stack); if content.podcasts.flowbox.get_children().is_empty() { content.stack.set_visible_child_name("empty"); - return ContentState::empty(Empty { content }) + return Err( + ContentState{ + content, + state: Empty{}, + }); } content.stack.set_visible_child_name("podcasts"); - ContentState::pop(PodcastsView{ content }) + Ok(ContentState { + content, + state: PodcastsView{}, + }) } pub fn get_stack(&self) -> gtk::Stack { - match *self { - ContentState::empty(ref e) => e.content.stack.clone(), - ContentState::pop(ref e) => e.content.stack.clone(), - 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(), - } + self.content.stack.clone() } } diff --git a/hammond-gtk/src/main.rs b/hammond-gtk/src/main.rs index a4aa344..afe1012 100644 --- a/hammond-gtk/src/main.rs +++ b/hammond-gtk/src/main.rs @@ -63,7 +63,8 @@ fn build_ui(app: >k::Application) { let window = gtk::ApplicationWindow::new(app); window.set_default_size(1150, 650); - let ct = content::ContentState::new(); + // TODO: this will blow horribly + let ct = content::ContentState::new().unwrap(); let stack = ct.get_stack(); window.add(&stack);