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
## Prototype of a multithreaded, safe, and reliable Gtk+ Podcast client.
Description...
## Multithreaded, safe, and reliable Gtk+ Podcast client.
This is a prototype of a podcast client written in Rust.
![podcasts_view](./assets/podcasts_view.png)
![podcast_widget](./assets/podcast_widget.png)

View File

@ -39,9 +39,9 @@ macro_rules! clone {
}
thread_local!(
static GLOBAL: RefCell<Option<((gtk::Button,
gtk::Button,
Receiver<bool>))>> = RefCell::new(None));
static GLOBAL: RefCell<Option<((
gtk::Button, gtk::Button, gtk::Button, Receiver<bool>,
))>> = RefCell::new(None));
fn epidose_widget(db: &Database, episode: &mut Episode, pd_title: &str) -> gtk::Box {
// 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();
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(
&db,
&pd_title,
&mut episode.clone(),
dl,
&play_button,
&delete_button,
);
}));
}),
);
ep
}
@ -116,13 +119,14 @@ fn on_download_clicked(
ep: &mut Episode,
download_bttn: &gtk::Button,
play_bttn: &gtk::Button,
del_bttn: &gtk::Button,
) {
// Create a async channel.
let (sender, receiver) = channel();
// Pass the desired arguments into the Local Thread Storage.
GLOBAL.with(clone!(download_bttn, play_bttn => move |global| {
*global.borrow_mut() = Some((download_bttn, play_bttn, receiver));
GLOBAL.with(clone!(download_bttn, play_bttn, del_bttn => move |global| {
*global.borrow_mut() = Some((download_bttn, play_bttn, del_bttn, receiver));
}));
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 {
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() {
download_bttn.hide();
play_bttn.show();
del_bttn.show();
}
}
});