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
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
4 changed files with 50 additions and 12 deletions

View File

@ -151,7 +151,6 @@
<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.refresh</property>
<style> <style>
<class name="destructive-action"/> <class name="destructive-action"/>
</style> </style>

View File

@ -18,6 +18,8 @@ use std::time::Duration;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum Action { pub enum Action {
UpdateSources(Option<Source>), UpdateSources(Option<Source>),
RefreshViews,
RefreshEpisodesView,
} }
#[derive(Debug)] #[derive(Debug)]
@ -57,7 +59,7 @@ impl App {
let header = Rc::new(Header::default()); let header = Rc::new(Header::default());
// Create a content instance // Create a content instance
let content = Content::new(header.clone()); let content = Content::new(header.clone(), sender.clone());
// Initialize the headerbar // Initialize the headerbar
header.init(content.clone(), sender.clone()); header.init(content.clone(), sender.clone());
@ -164,6 +166,12 @@ impl App {
utils::refresh_feed(content.clone(), headerbar.clone(), Some(vec!(s))) utils::refresh_feed(content.clone(), headerbar.clone(), Some(vec!(s)))
} }
} }
Ok(Action::RefreshViews) => {
content.update();
}
Ok(Action::RefreshEpisodesView) => {
content.update_episode_view();
}
_ => (), _ => (),
} }

View File

@ -10,21 +10,24 @@ use views::episodes::EpisodesView;
use widgets::show::ShowWidget; use widgets::show::ShowWidget;
use headerbar::Header; use headerbar::Header;
use app::Action;
use std::rc::Rc; use std::rc::Rc;
use std::sync::mpsc::Sender;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Content { pub struct Content {
stack: gtk::Stack, stack: gtk::Stack,
shows: Rc<ShowStack>, shows: Rc<ShowStack>,
episodes: Rc<EpisodeStack>, episodes: Rc<EpisodeStack>,
sender: Sender<Action>,
} }
impl Content { impl Content {
pub fn new(header: Rc<Header>) -> Rc<Content> { pub fn new(header: Rc<Header>, sender: Sender<Action>) -> Rc<Content> {
let stack = gtk::Stack::new(); let stack = gtk::Stack::new();
let episodes = EpisodeStack::new(); let episodes = EpisodeStack::new();
let shows = ShowStack::new(header, episodes.clone()); let shows = ShowStack::new(header, episodes.clone(), sender.clone());
stack.add_titled(&episodes.stack, "episodes", "Episodes"); stack.add_titled(&episodes.stack, "episodes", "Episodes");
stack.add_titled(&shows.stack, "shows", "Shows"); stack.add_titled(&shows.stack, "shows", "Shows");
@ -33,6 +36,7 @@ impl Content {
stack, stack,
shows, shows,
episodes, episodes,
sender,
}) })
} }
@ -63,16 +67,18 @@ pub struct ShowStack {
stack: gtk::Stack, stack: gtk::Stack,
header: Rc<Header>, header: Rc<Header>,
epstack: Rc<EpisodeStack>, epstack: Rc<EpisodeStack>,
sender: Sender<Action>,
} }
impl ShowStack { impl ShowStack {
fn new(header: Rc<Header>, epstack: Rc<EpisodeStack>) -> Rc<ShowStack> { fn new(header: Rc<Header>, epstack: Rc<EpisodeStack>, sender: Sender<Action>) -> Rc<ShowStack> {
let stack = gtk::Stack::new(); let stack = gtk::Stack::new();
let show = Rc::new(ShowStack { let show = Rc::new(ShowStack {
stack, stack,
header: header.clone(), header: header.clone(),
epstack, epstack,
sender,
}); });
let pop = ShowsPopulated::new(show.clone(), header); let pop = ShowsPopulated::new(show.clone(), header);
@ -124,7 +130,12 @@ 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(Rc::new(self.clone()), self.header.clone(), pd); let new = ShowWidget::new(
Rc::new(self.clone()),
self.header.clone(),
pd,
self.sender.clone(),
);
self.stack.remove(&old); self.stack.remove(&old);
self.stack.add_named(&new.container, "widget"); self.stack.add_named(&new.container, "widget");

View File

@ -13,8 +13,10 @@ use widgets::episode::episodes_listbox;
use utils::get_pixbuf_from_path; use utils::get_pixbuf_from_path;
use content::ShowStack; use content::ShowStack;
use headerbar::Header; use headerbar::Header;
use app::Action;
use std::rc::Rc; use std::rc::Rc;
use std::sync::mpsc::Sender;
use std::fs; use std::fs;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -53,18 +55,30 @@ impl Default for ShowWidget {
} }
impl 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(); let pdw = ShowWidget::default();
pdw.init(shows, header, pd); pdw.init(shows, header, pd, sender);
pdw 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`. // Hacky workaround so the pd.id() can be retrieved from the `ShowStack`.
WidgetExt::set_name(&self.container, &pd.id().to_string()); WidgetExt::set_name(&self.container, &pd.id().to_string());
self.unsub.connect_clicked(clone!(shows, pd => move |bttn| { self.unsub
on_unsub_button_clicked(shows.clone(), &pd, bttn); .connect_clicked(clone!(shows, pd, sender => move |bttn| {
on_unsub_button_clicked(shows.clone(), &pd, bttn, sender.clone());
header.switch_to_normal(); 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); 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());
@ -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(); shows.switch_podcasts_animated();
} }