On download completion also show the delete button for the episode widget.

This commit is contained in:
Jordan Petridis 2017-10-28 09:08:18 +03:00
parent 1cdae2b8b0
commit 9c032a7f17
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
2 changed files with 17 additions and 10 deletions

View File

@ -1,6 +1,6 @@
# Hammond # Hammond
## Prototype of a multithreaded, safe, and reliable Gtk+ Podcast client. ## Multithreaded, safe, and reliable Gtk+ Podcast client.
Description... This is a prototype of a podcast client written in Rust.
![podcasts_view](./assets/podcasts_view.png) ![podcasts_view](./assets/podcasts_view.png)
![podcast_widget](./assets/podcast_widget.png) ![podcast_widget](./assets/podcast_widget.png)

View File

@ -39,9 +39,9 @@ macro_rules! clone {
} }
thread_local!( thread_local!(
static GLOBAL: RefCell<Option<((gtk::Button, static GLOBAL: RefCell<Option<((
gtk::Button, gtk::Button, gtk::Button, gtk::Button, Receiver<bool>,
Receiver<bool>))>> = RefCell::new(None)); ))>> = RefCell::new(None));
fn epidose_widget(db: &Database, episode: &mut Episode, pd_title: &str) -> gtk::Box { fn epidose_widget(db: &Database, episode: &mut Episode, pd_title: &str) -> gtk::Box {
// This is just a prototype and will be reworked probably. // This is just a prototype and will be reworked probably.
@ -96,15 +96,18 @@ fn epidose_widget(db: &Database, episode: &mut Episode, pd_title: &str) -> gtk::
); );
let pd_title = pd_title.to_owned(); let pd_title = pd_title.to_owned();
download_button.connect_clicked(clone!(db, play_button, episode => move |dl| { download_button.connect_clicked(
clone!(db, play_button, delete_button, episode => move |dl| {
on_download_clicked( on_download_clicked(
&db, &db,
&pd_title, &pd_title,
&mut episode.clone(), &mut episode.clone(),
dl, dl,
&play_button, &play_button,
&delete_button,
); );
})); }),
);
ep ep
} }
@ -116,13 +119,14 @@ fn on_download_clicked(
ep: &mut Episode, ep: &mut Episode,
download_bttn: &gtk::Button, download_bttn: &gtk::Button,
play_bttn: &gtk::Button, play_bttn: &gtk::Button,
del_bttn: &gtk::Button,
) { ) {
// Create a async channel. // Create a async channel.
let (sender, receiver) = channel(); let (sender, receiver) = channel();
// Pass the desired arguments into the Local Thread Storage. // Pass the desired arguments into the Local Thread Storage.
GLOBAL.with(clone!(download_bttn, play_bttn => move |global| { GLOBAL.with(clone!(download_bttn, play_bttn, del_bttn => move |global| {
*global.borrow_mut() = Some((download_bttn, play_bttn, receiver)); *global.borrow_mut() = Some((download_bttn, play_bttn, del_bttn, receiver));
})); }));
let pd_title = pd_title.to_owned(); let pd_title = pd_title.to_owned();
@ -177,10 +181,13 @@ fn on_delete_bttn_clicked(db: &Database, episode_id: i32) {
fn receive() -> glib::Continue { fn receive() -> glib::Continue {
GLOBAL.with(|global| { GLOBAL.with(|global| {
if let Some((ref download_bttn, ref play_bttn, ref reciever)) = *global.borrow() { if let Some((ref download_bttn, ref play_bttn, ref del_bttn, ref reciever)) =
*global.borrow()
{
if reciever.try_recv().is_ok() { if reciever.try_recv().is_ok() {
download_bttn.hide(); download_bttn.hide();
play_bttn.show(); play_bttn.show();
del_bttn.show();
} }
} }
}); });