Update podcast view after db refresh.
This commit is contained in:
parent
74715292b3
commit
63af61d9f6
@ -27,6 +27,7 @@ pub fn get_headerbar(db: Arc<Mutex<SqliteConnection>>, stack: gtk::Stack) -> gtk
|
||||
|
||||
let add_popover_clone = add_popover.clone();
|
||||
let db_clone = db.clone();
|
||||
let stack_clone = stack.clone();
|
||||
|
||||
add_button.connect_clicked(move |_| {
|
||||
let tempdb = db_clone.lock().unwrap();
|
||||
@ -41,7 +42,8 @@ pub fn get_headerbar(db: Arc<Mutex<SqliteConnection>>, stack: gtk::Stack) -> gtk
|
||||
}
|
||||
|
||||
// update the db
|
||||
utils::refresh_db(db_clone.clone());
|
||||
// TODO: have it fettch only the added feed.
|
||||
utils::refresh_db(db_clone.clone(), stack_clone.clone());
|
||||
|
||||
// TODO: lock the button instead of hiding and add notification of feed added.
|
||||
// TODO: map the spinner
|
||||
@ -52,13 +54,17 @@ pub fn get_headerbar(db: Arc<Mutex<SqliteConnection>>, stack: gtk::Stack) -> gtk
|
||||
|
||||
// TODO: make it a back arrow button, that will hide when appropriate,
|
||||
// and add a StackSwitcher when more views are added.
|
||||
let grid = stack.get_child_by_name("pd_grid").unwrap();
|
||||
home_button.connect_clicked(move |_| stack.set_visible_child(&grid));
|
||||
let stack_clone = stack.clone();
|
||||
home_button.connect_clicked(move |_| {
|
||||
let grid = stack_clone.get_child_by_name("pd_grid").unwrap();
|
||||
stack_clone.set_visible_child(&grid)
|
||||
});
|
||||
|
||||
let stack_clone = stack.clone();
|
||||
// FIXME: There appears to be a memmory leak here.
|
||||
refresh_button.connect_clicked(move |_| {
|
||||
// fsdaa, The things I do for the borrow checker.
|
||||
utils::refresh_db(db.clone());
|
||||
utils::refresh_db(db.clone(), stack_clone.clone());
|
||||
});
|
||||
|
||||
header
|
||||
|
||||
@ -38,7 +38,7 @@ fn build_ui(app: >k::Application) {
|
||||
|
||||
// Get the main window
|
||||
let window = gtk::ApplicationWindow::new(app);
|
||||
window.set_default_size(1000, 600);
|
||||
window.set_default_size(1050, 600);
|
||||
app.add_window(&window);
|
||||
// Setup the Stack that will magane the switche between podcasts_view and podcast_widget.
|
||||
let stack = podcasts_view::setup_stack(db.clone());
|
||||
|
||||
@ -1,20 +1,30 @@
|
||||
// use glib;
|
||||
|
||||
use gtk;
|
||||
// use gtk::prelude::*;
|
||||
|
||||
use hammond_data;
|
||||
use diesel::prelude::SqliteConnection;
|
||||
|
||||
use std::thread;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
pub fn refresh_db(db: Arc<Mutex<SqliteConnection>>) {
|
||||
use views::podcasts_view;
|
||||
|
||||
pub fn refresh_db(db: Arc<Mutex<SqliteConnection>>, stack: gtk::Stack) {
|
||||
let db_clone = db.clone();
|
||||
thread::spawn(move || {
|
||||
let handle = thread::spawn(move || {
|
||||
let t = hammond_data::index_feed::index_loop(db_clone.clone(), false);
|
||||
if t.is_err() {
|
||||
error!("Error While trying to update the database.");
|
||||
error!("Error msg: {}", t.unwrap_err());
|
||||
};
|
||||
});
|
||||
// FIXME: atm freezing the ui till update is done.
|
||||
// Make it instead emmit a signal on update completion.
|
||||
handle.join();
|
||||
|
||||
podcasts_view::update_podcasts_view(db.clone(), stack.clone());
|
||||
}
|
||||
|
||||
// https://github.
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
use gtk;
|
||||
use gtk::prelude::*;
|
||||
// use gtk::StackTransitionType;
|
||||
use gdk_pixbuf::Pixbuf;
|
||||
|
||||
use hammond_downloader::downloader;
|
||||
@ -23,6 +24,7 @@ pub fn populate_podcasts_flowbox(
|
||||
it
|
||||
} else {
|
||||
// TODO: Display an empty view
|
||||
info!("Empty view.");
|
||||
return;
|
||||
};
|
||||
|
||||
@ -67,6 +69,7 @@ pub fn populate_podcasts_flowbox(
|
||||
break;
|
||||
}
|
||||
}
|
||||
flowbox.show_all();
|
||||
}
|
||||
|
||||
fn setup_podcast_widget(db: Arc<Mutex<SqliteConnection>>, stack: gtk::Stack) {
|
||||
@ -90,7 +93,26 @@ fn setup_podcasts_grid(db: Arc<Mutex<SqliteConnection>>, stack: gtk::Stack) {
|
||||
|
||||
pub fn setup_stack(db: Arc<Mutex<SqliteConnection>>) -> gtk::Stack {
|
||||
let stack = gtk::Stack::new();
|
||||
let _st_clone = stack.clone();
|
||||
setup_podcast_widget(db.clone(), stack.clone());
|
||||
setup_podcasts_grid(db.clone(), stack.clone());
|
||||
// stack.connect("foo", true, move |_| {
|
||||
// update_podcasts_view(db.clone(), st_clone);
|
||||
// });
|
||||
stack
|
||||
}
|
||||
|
||||
pub fn update_podcasts_view(db: Arc<Mutex<SqliteConnection>>, stack: gtk::Stack) {
|
||||
let builder = include_str!("../../gtk/podcasts_view.ui");
|
||||
let builder = gtk::Builder::new_from_string(builder);
|
||||
let grid: gtk::Grid = builder.get_object("grid").unwrap();
|
||||
|
||||
let flowbox: gtk::FlowBox = builder.get_object("flowbox").unwrap();
|
||||
// Populate the flowbox with the Podcasts.
|
||||
populate_podcasts_flowbox(db.clone(), stack.clone(), flowbox.clone());
|
||||
|
||||
let old = stack.get_child_by_name("pd_grid").unwrap();
|
||||
stack.remove(&old);
|
||||
stack.add_named(&grid, "pd_grid");
|
||||
// stack.set_visible_child_full("pd_grid", StackTransitionType::None);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user