ShowsView: Do not block while loading ShowChilds.

This commit is contained in:
Jordan Petridis 2018-04-19 07:51:48 +03:00
parent 5336981154
commit 3b5831f317
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
6 changed files with 67 additions and 47 deletions

View File

@ -377,6 +377,34 @@ pub fn is_episodes_populated() -> Result<bool, DataError> {
.map_err(From::from)
}
/// Check `episode` table empty
///
// FIXME: Return true if `episode` table is populated.
pub fn is_podcasts_populated() -> Result<bool, DataError> {
use schema::podcast::dsl::*;
let db = connection();
let con = db.get()?;
// FIXME
// select(exists(select(podcast)))
// .get_result(&con)
// .map_err(From::from)
podcast
.count()
.get_result(&con)
// FIXME: fix the diesel querry
.map(|b: i64| {
if b == 0 {
false
} else {
true
}
})
.map_err(From::from)
}
pub(crate) fn index_new_episodes(eps: &[NewEpisode]) -> Result<(), DataError> {
use schema::episode::dsl::*;
let db = connection();

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.21.0
<!-- Generated with glade 3.22.0
Copyright (C) 2017 - 2018
@ -39,26 +39,17 @@ Tobias Bernard
<property name="valign">center</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkOverlay">
<object class="GtkImage" id="pd_cover">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<placeholder/>
</child>
<child type="overlay">
<object class="GtkImage" id="pd_cover">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="pixel_size">256</property>
<property name="icon_name">image-x-generic-symbolic</property>
<property name="icon_size">0</property>
</object>
</child>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="pixel_size">256</property>
<property name="icon_name">image-x-generic-symbolic</property>
<property name="icon_size">0</property>
</object>
<packing>
<property name="expand">True</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>

View File

@ -126,7 +126,10 @@ impl App {
utils::cleanup(cleanup_date);
gtk::idle_add(move || {
// The ui loads async, after initialization
// so we need to delay this a bit so it won't block
// requests that will come from loading the gui on startup.
gtk::timeout_add(1500, move || {
let s: Option<Vec<_>> = None;
utils::refresh(s, sender.clone());
glib::Continue(false)

View File

@ -6,6 +6,7 @@ use failure::Error;
use send_cell::SendCell;
use hammond_data::dbqueries;
use hammond_data::errors::DataError;
use hammond_data::Podcast;
use views::{EmptyView, ShowsPopulated};
@ -43,12 +44,7 @@ impl ShowStack {
show.stack.add_named(&pop.container, "podcasts");
show.stack.add_named(&widget.container, "widget");
show.stack.add_named(&empty.container, "empty");
if pop.is_empty() {
show.stack.set_visible_child_name("empty")
} else {
show.stack.set_visible_child_name("podcasts")
}
set_stack_visible(&show.get_stack())?;
Ok(show)
}
@ -70,24 +66,16 @@ impl ShowStack {
.map_err(|_| format_err!("Failed to downcast stack child to a Box."))?;
debug!("Name: {:?}", WidgetExt::get_name(&old));
let scrolled_window = old.get_children()
.first()
.ok_or_else(|| format_err!("Box container has no childs."))?
.clone()
.downcast::<gtk::ScrolledWindow>()
.map_err(|_| format_err!("Failed to downcast stack child to a ScrolledWindow."))?;
debug!("Name: {:?}", WidgetExt::get_name(&scrolled_window));
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));
// scrolled_window
// .get_vadjustment()
// .map(|x| pop.set_vadjustment(&x));
self.stack.remove(&old);
self.stack.add_named(&pop.container, "podcasts");
if pop.is_empty() {
if !dbqueries::is_podcasts_populated()? {
self.stack.set_visible_child_name("empty");
} else if vis != "empty" {
self.stack.set_visible_child_name(&vis);
@ -215,6 +203,17 @@ impl ShowStack {
}
}
#[inline]
fn set_stack_visible(stack: &gtk::Stack) -> Result<(), DataError> {
if dbqueries::is_podcasts_populated()? {
stack.set_visible_child_name("podcasts")
} else {
stack.set_visible_child_name("empty")
}
Ok(())
}
// ATTENTION: EXPECTS THE SHOW WIDGET CONTAINER
fn save_alignment(oldid: i32, widget: &gtk::Box) -> Result<(), Error> {
let scrolled_window = widget

View File

@ -64,6 +64,7 @@ use chrono::Duration;
/// let list = gtk::ListBox::new();
/// lazy_load(widgets, list, |w| w, || {});
/// ```
#[inline]
pub fn lazy_load<T, C, F, W, U>(data: T, container: C, mut contructor: F, callback: U)
where
T: IntoIterator + 'static,
@ -83,6 +84,7 @@ where
/// This is a more flexible version of `lazy_load` with less constrains.
/// If you just want to lazy add `widgets` to a `container` check if
/// `lazy_load` fits your needs first.
#[inline]
pub fn lazy_load_full<T, F, U>(data: T, mut func: F, finish_callback: U)
where
T: IntoIterator + 'static,

View File

@ -6,7 +6,7 @@ use hammond_data::dbqueries;
use hammond_data::Podcast;
use app::Action;
use utils::{get_ignored_shows, set_image_from_path};
use utils::{get_ignored_shows, lazy_load, set_image_from_path};
use std::sync::mpsc::Sender;
use std::sync::Arc;
@ -58,17 +58,14 @@ impl ShowsPopulated {
let ignore = get_ignored_shows()?;
let podcasts = dbqueries::get_podcasts_filter(&ignore)?;
podcasts.iter().for_each(|parent| {
let flowbox_child = ShowsChild::new(parent);
self.flowbox.add(&flowbox_child.child);
});
self.flowbox.show_all();
Ok(())
}
let flowbox = self.flowbox.clone();
let constructor = |parent| ShowsChild::new(&parent).child;
let callback = move || flowbox.show_all();
#[inline]
pub fn is_empty(&self) -> bool {
self.flowbox.get_children().is_empty()
let flowbox = self.flowbox.clone();
lazy_load(podcasts, flowbox, constructor, callback);
Ok(())
}
#[inline]