Migrate Headerbar transitions into Channel actions.
This commit is contained in:
@@ -16,24 +16,9 @@ use hammond_downloader::downloader;
|
||||
use app::Action;
|
||||
|
||||
use std::thread;
|
||||
use std::cell::RefCell;
|
||||
use std::sync::mpsc::{channel, Receiver, Sender};
|
||||
use std::sync::mpsc::Sender;
|
||||
use std::path::Path;
|
||||
|
||||
type Foo = RefCell<
|
||||
Option<
|
||||
(
|
||||
gtk::Button,
|
||||
gtk::Button,
|
||||
gtk::Button,
|
||||
gtk::ProgressBar,
|
||||
Receiver<bool>,
|
||||
),
|
||||
>,
|
||||
>;
|
||||
|
||||
thread_local!(static GLOBAL: Foo = RefCell::new(None));
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct EpisodeWidget {
|
||||
pub container: gtk::Box,
|
||||
@@ -126,21 +111,18 @@ impl EpisodeWidget {
|
||||
};
|
||||
}));
|
||||
|
||||
let play = &self.play;
|
||||
let cancel = &self.cancel;
|
||||
let progress = self.progress.clone();
|
||||
self.download.connect_clicked(
|
||||
clone!(play, episode, cancel, progress, sender => move |dl| {
|
||||
self.download
|
||||
.connect_clicked(clone!(episode, cancel, progress, sender => move |dl| {
|
||||
on_download_clicked(
|
||||
&mut episode.clone(),
|
||||
dl,
|
||||
&play,
|
||||
&cancel,
|
||||
progress.clone(),
|
||||
sender.clone()
|
||||
);
|
||||
}),
|
||||
);
|
||||
}));
|
||||
}
|
||||
|
||||
/// Show or hide the play/delete/download buttons upon widget initialization.
|
||||
@@ -216,7 +198,6 @@ impl EpisodeWidget {
|
||||
fn on_download_clicked(
|
||||
ep: &mut EpisodeWidgetQuery,
|
||||
download_bttn: >k::Button,
|
||||
play_bttn: >k::Button,
|
||||
cancel_bttn: >k::Button,
|
||||
progress_bar: gtk::ProgressBar,
|
||||
sender: Sender<Action>,
|
||||
@@ -235,7 +216,7 @@ fn on_download_clicked(
|
||||
cancel_bttn.show();
|
||||
progress.show();
|
||||
download_bttn.hide();
|
||||
sender.send(Action::RefreshEpisodesViewBGR);
|
||||
sender.send(Action::RefreshEpisodesViewBGR).unwrap();
|
||||
thread::spawn(move || {
|
||||
let download_fold = downloader::get_download_folder(&pd_title).unwrap();
|
||||
let e = downloader::get_episode(&mut ep, download_fold.as_str());
|
||||
@@ -243,7 +224,7 @@ fn on_download_clicked(
|
||||
error!("Error while trying to download: {:?}", ep.uri());
|
||||
error!("Error: {}", err);
|
||||
};
|
||||
sender.send(Action::RefreshViews);
|
||||
sender.send(Action::RefreshViews).unwrap();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -279,27 +260,6 @@ fn on_play_bttn_clicked(episode_id: i32) {
|
||||
// };
|
||||
// }
|
||||
|
||||
fn receive() -> glib::Continue {
|
||||
GLOBAL.with(|global| {
|
||||
if let Some((
|
||||
ref download_bttn,
|
||||
ref play_bttn,
|
||||
ref cancel_bttn,
|
||||
ref progress_bar,
|
||||
ref reciever,
|
||||
)) = *global.borrow()
|
||||
{
|
||||
if reciever.try_recv().is_ok() {
|
||||
download_bttn.hide();
|
||||
play_bttn.show();
|
||||
cancel_bttn.hide();
|
||||
progress_bar.hide();
|
||||
}
|
||||
}
|
||||
});
|
||||
glib::Continue(false)
|
||||
}
|
||||
|
||||
pub fn episodes_listbox(pd: &Podcast, sender: Sender<Action>) -> Result<gtk::ListBox> {
|
||||
let episodes = dbqueries::get_pd_episodeswidgets(pd)?;
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ use hammond_downloader::downloader;
|
||||
use widgets::episode::episodes_listbox;
|
||||
use utils::get_pixbuf_from_path;
|
||||
use content::ShowStack;
|
||||
use headerbar::Header;
|
||||
use app::Action;
|
||||
|
||||
use std::rc::Rc;
|
||||
@@ -55,31 +54,20 @@ impl Default for ShowWidget {
|
||||
}
|
||||
|
||||
impl ShowWidget {
|
||||
pub fn new(
|
||||
shows: Rc<ShowStack>,
|
||||
header: Rc<Header>,
|
||||
pd: &Podcast,
|
||||
sender: Sender<Action>,
|
||||
) -> ShowWidget {
|
||||
pub fn new(shows: Rc<ShowStack>, pd: &Podcast, sender: Sender<Action>) -> ShowWidget {
|
||||
let pdw = ShowWidget::default();
|
||||
pdw.init(shows, header, pd, sender);
|
||||
pdw.init(shows, pd, sender);
|
||||
pdw
|
||||
}
|
||||
|
||||
pub fn init(
|
||||
&self,
|
||||
shows: Rc<ShowStack>,
|
||||
header: Rc<Header>,
|
||||
pd: &Podcast,
|
||||
sender: Sender<Action>,
|
||||
) {
|
||||
pub fn init(&self, shows: Rc<ShowStack>, pd: &Podcast, sender: Sender<Action>) {
|
||||
// Hacky workaround so the pd.id() can be retrieved from the `ShowStack`.
|
||||
WidgetExt::set_name(&self.container, &pd.id().to_string());
|
||||
|
||||
self.unsub
|
||||
.connect_clicked(clone!(shows, pd, sender => move |bttn| {
|
||||
on_unsub_button_clicked(shows.clone(), &pd, bttn, sender.clone());
|
||||
header.switch_to_normal();
|
||||
sender.send(Action::HeaderBarNormal).unwrap();
|
||||
}));
|
||||
|
||||
self.setup_listbox(pd, sender.clone());
|
||||
|
||||
Reference in New Issue
Block a user