ShowWidget: Replace the unsub simple action with a Channel Action.
This commit is contained in:
parent
c8537e9474
commit
84da6aac8c
@ -151,7 +151,6 @@
|
||||
<property name="receives_default">True</property>
|
||||
<property name="halign">center</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="action_name">app.refresh</property>
|
||||
<style>
|
||||
<class name="destructive-action"/>
|
||||
</style>
|
||||
|
||||
@ -18,6 +18,8 @@ use std::time::Duration;
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Action {
|
||||
UpdateSources(Option<Source>),
|
||||
RefreshViews,
|
||||
RefreshEpisodesView,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -57,7 +59,7 @@ impl App {
|
||||
let header = Rc::new(Header::default());
|
||||
|
||||
// Create a content instance
|
||||
let content = Content::new(header.clone());
|
||||
let content = Content::new(header.clone(), sender.clone());
|
||||
|
||||
// Initialize the headerbar
|
||||
header.init(content.clone(), sender.clone());
|
||||
@ -164,6 +166,12 @@ impl App {
|
||||
utils::refresh_feed(content.clone(), headerbar.clone(), Some(vec!(s)))
|
||||
}
|
||||
}
|
||||
Ok(Action::RefreshViews) => {
|
||||
content.update();
|
||||
}
|
||||
Ok(Action::RefreshEpisodesView) => {
|
||||
content.update_episode_view();
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
|
||||
@ -10,21 +10,24 @@ use views::episodes::EpisodesView;
|
||||
|
||||
use widgets::show::ShowWidget;
|
||||
use headerbar::Header;
|
||||
use app::Action;
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::sync::mpsc::Sender;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Content {
|
||||
stack: gtk::Stack,
|
||||
shows: Rc<ShowStack>,
|
||||
episodes: Rc<EpisodeStack>,
|
||||
sender: Sender<Action>,
|
||||
}
|
||||
|
||||
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 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(&shows.stack, "shows", "Shows");
|
||||
@ -33,6 +36,7 @@ impl Content {
|
||||
stack,
|
||||
shows,
|
||||
episodes,
|
||||
sender,
|
||||
})
|
||||
}
|
||||
|
||||
@ -63,16 +67,18 @@ pub struct ShowStack {
|
||||
stack: gtk::Stack,
|
||||
header: Rc<Header>,
|
||||
epstack: Rc<EpisodeStack>,
|
||||
sender: Sender<Action>,
|
||||
}
|
||||
|
||||
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 show = Rc::new(ShowStack {
|
||||
stack,
|
||||
header: header.clone(),
|
||||
epstack,
|
||||
sender,
|
||||
});
|
||||
|
||||
let pop = ShowsPopulated::new(show.clone(), header);
|
||||
@ -124,7 +130,12 @@ impl ShowStack {
|
||||
|
||||
pub fn replace_widget(&self, pd: &Podcast) {
|
||||
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.add_named(&new.container, "widget");
|
||||
|
||||
@ -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: >k::Button) {
|
||||
fn on_unsub_button_clicked(
|
||||
shows: Rc<ShowStack>,
|
||||
pd: &Podcast,
|
||||
unsub_button: >k::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: >
|
||||
}
|
||||
};
|
||||
}
|
||||
sender.send(Action::RefreshViews).unwrap();
|
||||
shows.switch_podcasts_animated();
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user