ShowWidget: Replace the unsub simple action with a Channel Action.

This commit is contained in:
Jordan Petridis
2018-01-03 06:23:12 +02:00
parent c8537e9474
commit 84da6aac8c
4 changed files with 50 additions and 12 deletions
+26 -6
View File
@@ -13,8 +13,10 @@ use widgets::episode::episodes_listbox;
use utils::get_pixbuf_from_path;
use content::ShowStack;
use headerbar::Header;
use app::Action;
use std::rc::Rc;
use std::sync::mpsc::Sender;
use std::fs;
#[derive(Debug, Clone)]
@@ -53,18 +55,30 @@ impl Default for ShowWidget {
}
impl ShowWidget {
pub fn new(shows: Rc<ShowStack>, header: Rc<Header>, pd: &Podcast) -> ShowWidget {
pub fn new(
shows: Rc<ShowStack>,
header: Rc<Header>,
pd: &Podcast,
sender: Sender<Action>,
) -> ShowWidget {
let pdw = ShowWidget::default();
pdw.init(shows, header, pd);
pdw.init(shows, header, pd, sender);
pdw
}
pub fn init(&self, shows: Rc<ShowStack>, header: Rc<Header>, pd: &Podcast) {
pub fn init(
&self,
shows: Rc<ShowStack>,
header: Rc<Header>,
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 => move |bttn| {
on_unsub_button_clicked(shows.clone(), &pd, bttn);
self.unsub
.connect_clicked(clone!(shows, pd, sender => move |bttn| {
on_unsub_button_clicked(shows.clone(), &pd, bttn, sender.clone());
header.switch_to_normal();
}));
@@ -104,7 +118,12 @@ impl ShowWidget {
}
}
fn on_unsub_button_clicked(shows: Rc<ShowStack>, pd: &Podcast, unsub_button: &gtk::Button) {
fn on_unsub_button_clicked(
shows: Rc<ShowStack>,
pd: &Podcast,
unsub_button: &gtk::Button,
sender: Sender<Action>,
) {
let res = dbqueries::remove_feed(pd);
if res.is_ok() {
info!("{} was removed succesfully.", pd.title());
@@ -120,6 +139,7 @@ fn on_unsub_button_clicked(shows: Rc<ShowStack>, pd: &Podcast, unsub_button: &gt
}
};
}
sender.send(Action::RefreshViews).unwrap();
shows.switch_podcasts_animated();
}