ShowWidget: Migrate unsub button to use the GAction instead.

This commit is contained in:
Jordan Petridis 2017-12-29 20:33:47 +02:00
parent 036292284d
commit bcc089bd82
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
3 changed files with 9 additions and 33 deletions

View File

@ -151,6 +151,7 @@
<property name="receives_default">True</property> <property name="receives_default">True</property>
<property name="halign">center</property> <property name="halign">center</property>
<property name="valign">center</property> <property name="valign">center</property>
<property name="action_name">app.update</property>
<style> <style>
<class name="destructive-action"/> <class name="destructive-action"/>
</style> </style>

View File

@ -124,12 +124,7 @@ impl ShowStack {
pub fn replace_widget(&self, pd: &Podcast) { pub fn replace_widget(&self, pd: &Podcast) {
let old = self.stack.get_child_by_name("widget").unwrap(); let old = self.stack.get_child_by_name("widget").unwrap();
let new = ShowWidget::new( let new = ShowWidget::new(Rc::new(self.clone()), self.header.clone(), pd);
Rc::new(self.clone()),
self.epstack.clone(),
self.header.clone(),
pd,
);
self.stack.remove(&old); self.stack.remove(&old);
self.stack.add_named(&new.container, "widget"); self.stack.add_named(&new.container, "widget");

View File

@ -11,7 +11,7 @@ use hammond_downloader::downloader;
use widgets::episode::episodes_listbox; use widgets::episode::episodes_listbox;
use utils::get_pixbuf_from_path; use utils::get_pixbuf_from_path;
use content::{EpisodeStack, ShowStack}; use content::ShowStack;
use headerbar::Header; use headerbar::Header;
use std::rc::Rc; use std::rc::Rc;
@ -53,30 +53,17 @@ impl Default for ShowWidget {
} }
impl ShowWidget { impl ShowWidget {
pub fn new( pub fn new(shows: Rc<ShowStack>, header: Rc<Header>, pd: &Podcast) -> ShowWidget {
shows: Rc<ShowStack>,
epstack: Rc<EpisodeStack>,
header: Rc<Header>,
pd: &Podcast,
) -> ShowWidget {
let pdw = ShowWidget::default(); let pdw = ShowWidget::default();
pdw.init(shows, epstack, header, pd); pdw.init(shows, header, pd);
pdw pdw
} }
pub fn init( pub fn init(&self, shows: Rc<ShowStack>, header: Rc<Header>, pd: &Podcast) {
&self,
shows: Rc<ShowStack>,
epstack: Rc<EpisodeStack>,
header: Rc<Header>,
pd: &Podcast,
) {
WidgetExt::set_name(&self.container, &pd.id().to_string()); WidgetExt::set_name(&self.container, &pd.id().to_string());
// TODO: should spawn a thread to avoid locking the UI probably. self.unsub.connect_clicked(clone!(shows, pd => move |bttn| {
self.unsub on_unsub_button_clicked(shows.clone(), &pd, bttn);
.connect_clicked(clone!(shows, epstack, pd => move |bttn| {
on_unsub_button_clicked(shows.clone(), epstack.clone(), &pd, bttn);
header.switch_to_normal(); header.switch_to_normal();
})); }));
@ -106,12 +93,7 @@ impl ShowWidget {
} }
} }
fn on_unsub_button_clicked( fn on_unsub_button_clicked(shows: Rc<ShowStack>, pd: &Podcast, unsub_button: &gtk::Button) {
shows: Rc<ShowStack>,
epstack: Rc<EpisodeStack>,
pd: &Podcast,
unsub_button: &gtk::Button,
) {
let res = dbqueries::remove_feed(pd); let res = dbqueries::remove_feed(pd);
if res.is_ok() { if res.is_ok() {
info!("{} was removed succesfully.", pd.title()); info!("{} was removed succesfully.", pd.title());
@ -128,8 +110,6 @@ fn on_unsub_button_clicked(
}; };
} }
shows.switch_podcasts_animated(); shows.switch_podcasts_animated();
shows.update_podcasts();
epstack.update();
} }
#[allow(dead_code)] #[allow(dead_code)]