h-gtk: Further refactor of the ShowStack.

This commit is contained in:
Jordan Petridis 2018-04-21 08:01:34 +03:00
parent 6406c3af13
commit e560cce879
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
2 changed files with 11 additions and 20 deletions

View File

@ -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<ShowsPopulated>,
show: Rc<ShowWidget>,
empty: EmptyView,
sender: Sender<Action>,
@ -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::<gtk::Box>()
.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(())
}

View File

@ -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<Action>) -> Result<ShowsPopulated, Error> {
let pop = ShowsPopulated::default();
pub fn new(sender: Sender<Action>) -> Result<Rc<ShowsPopulated>, Error> {
let pop = Rc::new(ShowsPopulated::default());
pop.init(sender)?;
Ok(pop)
}