From e560cce8797b7a39da0dc08bb5198032791cfc8d Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Sat, 21 Apr 2018 08:01:34 +0300 Subject: [PATCH] h-gtk: Further refactor of the ShowStack. --- hammond-gtk/src/stacks/show.rs | 26 ++++++++------------------ hammond-gtk/src/views/shows.rs | 5 +++-- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/hammond-gtk/src/stacks/show.rs b/hammond-gtk/src/stacks/show.rs index 5ba26d2..7af65dd 100644 --- a/hammond-gtk/src/stacks/show.rs +++ b/hammond-gtk/src/stacks/show.rs @@ -1,6 +1,5 @@ use gtk; use gtk::prelude::*; -use gtk::Cast; use failure::Error; @@ -20,7 +19,7 @@ use std::sync::Arc; #[derive(Debug, Clone)] pub struct ShowStack { stack: gtk::Stack, - podcasts: ShowsPopulated, + podcasts: Rc, show: Rc, empty: EmptyView, sender: Sender, @@ -55,26 +54,18 @@ impl ShowStack { // self.update_podcasts(); // } - pub fn update_podcasts(&self) -> Result<(), Error> { + pub fn update_podcasts(&mut self) -> Result<(), Error> { let vis = self.stack .get_visible_child_name() .ok_or_else(|| format_err!("Failed to get visible child name."))?; - let old = self.stack - .get_child_by_name("podcasts") - .ok_or_else(|| format_err!("Faild to get \"podcasts\" child from the stack."))? - .downcast::() - .map_err(|_| format_err!("Failed to downcast stack child to a Box."))?; - debug!("Name: {:?}", WidgetExt::get_name(&old)); + let old = &self.podcasts.container.clone(); + debug!("Name: {:?}", WidgetExt::get_name(old)); let pop = ShowsPopulated::new(self.sender.clone())?; - // Copy the vertical scrollbar adjustment from the old view into the new one. - // scrolled_window - // .get_vadjustment() - // .map(|x| pop.set_vadjustment(&x)); - - self.stack.remove(&old); - self.stack.add_named(&pop.container, "podcasts"); + self.podcasts = pop; + self.stack.remove(old); + self.stack.add_named(&self.podcasts.container, "podcasts"); if !dbqueries::is_podcasts_populated()? { self.stack.set_visible_child_name("empty"); @@ -108,10 +99,9 @@ impl ShowStack { WidgetExt::get_name(&new.container) ); - let root = new.container.clone(); self.show = new; self.stack.remove(&old); - self.stack.add_named(&root, "widget"); + self.stack.add_named(&self.show.container, "widget"); Ok(()) } diff --git a/hammond-gtk/src/views/shows.rs b/hammond-gtk/src/views/shows.rs index 3467551..7633454 100644 --- a/hammond-gtk/src/views/shows.rs +++ b/hammond-gtk/src/views/shows.rs @@ -8,6 +8,7 @@ use hammond_data::Podcast; use app::Action; use utils::{get_ignored_shows, lazy_load, set_image_from_path}; +use std::rc::Rc; use std::sync::mpsc::Sender; use std::sync::Arc; @@ -36,8 +37,8 @@ impl Default for ShowsPopulated { impl ShowsPopulated { #[inline] - pub fn new(sender: Sender) -> Result { - let pop = ShowsPopulated::default(); + pub fn new(sender: Sender) -> Result, Error> { + let pop = Rc::new(ShowsPopulated::default()); pop.init(sender)?; Ok(pop) }