h-gtk: Move show notification creation into widgets/show.rs
This commit is contained in:
parent
a9abd75b51
commit
0589f2fe2a
@ -6,18 +6,13 @@ use gtk;
|
|||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use gtk::SettingsExt as GtkSettingsExt;
|
use gtk::SettingsExt as GtkSettingsExt;
|
||||||
|
|
||||||
use failure::Error;
|
|
||||||
use rayon;
|
|
||||||
|
|
||||||
use hammond_data::utils::delete_show;
|
|
||||||
use hammond_data::Podcast;
|
use hammond_data::Podcast;
|
||||||
|
|
||||||
use appnotif::*;
|
|
||||||
use headerbar::Header;
|
use headerbar::Header;
|
||||||
use settings::WindowGeometry;
|
use settings::WindowGeometry;
|
||||||
use stacks::Content;
|
use stacks::Content;
|
||||||
use utils;
|
use utils;
|
||||||
use widgets::mark_all_watched;
|
use widgets::{mark_all_notif, remove_show_notif};
|
||||||
|
|
||||||
use std::sync::mpsc::{channel, Receiver, Sender};
|
use std::sync::mpsc::{channel, Receiver, Sender};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@ -191,61 +186,11 @@ impl App {
|
|||||||
Ok(Action::HeaderBarShowUpdateIndicator) => headerbar.show_update_notification(),
|
Ok(Action::HeaderBarShowUpdateIndicator) => headerbar.show_update_notification(),
|
||||||
Ok(Action::HeaderBarHideUpdateIndicator) => headerbar.hide_update_notification(),
|
Ok(Action::HeaderBarHideUpdateIndicator) => headerbar.hide_update_notification(),
|
||||||
Ok(Action::MarkAllPlayerNotification(pd)) => {
|
Ok(Action::MarkAllPlayerNotification(pd)) => {
|
||||||
let id = pd.id();
|
let notif = mark_all_notif(pd, sender.clone());
|
||||||
let callback = clone!(sender => move || {
|
|
||||||
mark_all_watched(&pd, sender.clone())
|
|
||||||
.map_err(|err| error!("Notif Callback Error: {}", err))
|
|
||||||
.ok();
|
|
||||||
glib::Continue(false)
|
|
||||||
});
|
|
||||||
|
|
||||||
let undo_callback = clone!(sender => move || {
|
|
||||||
sender.send(Action::RefreshWidgetIfSame(id))
|
|
||||||
.map_err(|err| error!("Action Sender: {}", err))
|
|
||||||
.ok();
|
|
||||||
});
|
|
||||||
|
|
||||||
let text = "Marked all episodes as listened".into();
|
|
||||||
let notif = InAppNotification::new(text, callback, undo_callback);
|
|
||||||
notif.show(&overlay);
|
notif.show(&overlay);
|
||||||
}
|
}
|
||||||
Ok(Action::RemoveShow(pd)) => {
|
Ok(Action::RemoveShow(pd)) => {
|
||||||
let text = format!("Unsubscribed from {}", pd.title());
|
let notif = remove_show_notif(pd, sender.clone());
|
||||||
|
|
||||||
utils::ignore_show(pd.id())
|
|
||||||
.map_err(|err| error!("Error: {}", err))
|
|
||||||
.map_err(|_| error!("Could not insert {} to the ignore list.", pd.title()))
|
|
||||||
.ok();
|
|
||||||
|
|
||||||
let callback = clone!(pd => move || {
|
|
||||||
utils::uningore_show(pd.id())
|
|
||||||
.map_err(|err| error!("Error: {}", err))
|
|
||||||
.map_err(|_| error!("Could not remove {} from the ignore list.", pd.title()))
|
|
||||||
.ok();
|
|
||||||
|
|
||||||
// Spawn a thread so it won't block the ui.
|
|
||||||
rayon::spawn(clone!(pd => move || {
|
|
||||||
delete_show(&pd)
|
|
||||||
.map_err(|err| error!("Error: {}", err))
|
|
||||||
.map_err(|_| error!("Failed to delete {}", pd.title()))
|
|
||||||
.ok();
|
|
||||||
}));
|
|
||||||
glib::Continue(false)
|
|
||||||
});
|
|
||||||
|
|
||||||
let sender_ = sender.clone();
|
|
||||||
let undo_wrap = move || -> Result<(), Error> {
|
|
||||||
utils::uningore_show(pd.id())?;
|
|
||||||
sender_.send(Action::RefreshShowsView)?;
|
|
||||||
sender_.send(Action::RefreshEpisodesView)?;
|
|
||||||
Ok(())
|
|
||||||
};
|
|
||||||
|
|
||||||
let undo_callback = move || {
|
|
||||||
undo_wrap().map_err(|err| error!("{}", err)).ok();
|
|
||||||
};
|
|
||||||
|
|
||||||
let notif = InAppNotification::new(text, callback, undo_callback);
|
|
||||||
notif.show(&overlay);
|
notif.show(&overlay);
|
||||||
}
|
}
|
||||||
Err(_) => (),
|
Err(_) => (),
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
)
|
)
|
||||||
)]
|
)]
|
||||||
#![allow(unknown_lints)]
|
#![allow(unknown_lints)]
|
||||||
#![deny(unused_extern_crates, unused)]
|
// #![deny(unused_extern_crates, unused)]
|
||||||
|
|
||||||
extern crate gdk;
|
extern crate gdk;
|
||||||
extern crate gdk_pixbuf;
|
extern crate gdk_pixbuf;
|
||||||
|
|||||||
@ -3,5 +3,5 @@ mod episode_states;
|
|||||||
mod show;
|
mod show;
|
||||||
|
|
||||||
pub use self::episode::EpisodeWidget;
|
pub use self::episode::EpisodeWidget;
|
||||||
pub use self::show::mark_all_watched;
|
|
||||||
pub use self::show::ShowWidget;
|
pub use self::show::ShowWidget;
|
||||||
|
pub use self::show::{mark_all_notif, remove_show_notif};
|
||||||
|
|||||||
@ -1,15 +1,19 @@
|
|||||||
use failure::Error;
|
use glib;
|
||||||
// use glib;
|
|
||||||
use gtk;
|
use gtk;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
|
|
||||||
|
use failure::Error;
|
||||||
use html2pango::markup_from_raw;
|
use html2pango::markup_from_raw;
|
||||||
use open;
|
use open;
|
||||||
|
use rayon;
|
||||||
|
|
||||||
use hammond_data::dbqueries;
|
use hammond_data::dbqueries;
|
||||||
|
use hammond_data::utils::delete_show;
|
||||||
use hammond_data::Podcast;
|
use hammond_data::Podcast;
|
||||||
|
|
||||||
use app::Action;
|
use app::Action;
|
||||||
use utils::set_image_from_path;
|
use appnotif::InAppNotification;
|
||||||
|
use utils;
|
||||||
use widgets::episode::episodes_listbox;
|
use widgets::episode::episodes_listbox;
|
||||||
|
|
||||||
use std::sync::mpsc::{SendError, Sender};
|
use std::sync::mpsc::{SendError, Sender};
|
||||||
@ -110,7 +114,7 @@ impl ShowWidget {
|
|||||||
|
|
||||||
/// Set the show cover.
|
/// Set the show cover.
|
||||||
fn set_cover(&self, pd: Arc<Podcast>) -> Result<(), Error> {
|
fn set_cover(&self, pd: Arc<Podcast>) -> Result<(), Error> {
|
||||||
set_image_from_path(&self.cover, Arc::new(pd.into()), 128)
|
utils::set_image_from_path(&self.cover, Arc::new(pd.into()), 128)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the descripton text.
|
/// Set the descripton text.
|
||||||
@ -155,7 +159,7 @@ fn on_played_button_clicked(pd: Arc<Podcast>, episodes: >k::Frame, sender: Sen
|
|||||||
.ok();
|
.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mark_all_watched(pd: &Podcast, sender: Sender<Action>) -> Result<(), Error> {
|
fn mark_all_watched(pd: &Podcast, sender: Sender<Action>) -> Result<(), Error> {
|
||||||
dbqueries::update_none_to_played_now(pd)?;
|
dbqueries::update_none_to_played_now(pd)?;
|
||||||
// Not all widgets migth have been loaded when the mark_all is hit
|
// Not all widgets migth have been loaded when the mark_all is hit
|
||||||
// So we will need to refresh again after it's done.
|
// So we will need to refresh again after it's done.
|
||||||
@ -163,6 +167,63 @@ pub fn mark_all_watched(pd: &Podcast, sender: Sender<Action>) -> Result<(), Erro
|
|||||||
sender.send(Action::RefreshEpisodesView).map_err(From::from)
|
sender.send(Action::RefreshEpisodesView).map_err(From::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn mark_all_notif(pd: Arc<Podcast>, sender: Sender<Action>) -> InAppNotification {
|
||||||
|
let id = pd.id();
|
||||||
|
let callback = clone!(sender => move || {
|
||||||
|
mark_all_watched(&pd, sender.clone())
|
||||||
|
.map_err(|err| error!("Notif Callback Error: {}", err))
|
||||||
|
.ok();
|
||||||
|
glib::Continue(false)
|
||||||
|
});
|
||||||
|
|
||||||
|
let undo_callback = clone!(sender => move || {
|
||||||
|
sender.send(Action::RefreshWidgetIfSame(id))
|
||||||
|
.map_err(|err| error!("Action Sender: {}", err))
|
||||||
|
.ok();
|
||||||
|
});
|
||||||
|
|
||||||
|
let text = "Marked all episodes as listened".into();
|
||||||
|
InAppNotification::new(text, callback, undo_callback)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn remove_show_notif(pd: Arc<Podcast>, sender: Sender<Action>) -> InAppNotification {
|
||||||
|
let text = format!("Unsubscribed from {}", pd.title());
|
||||||
|
|
||||||
|
utils::ignore_show(pd.id())
|
||||||
|
.map_err(|err| error!("Error: {}", err))
|
||||||
|
.map_err(|_| error!("Could not insert {} to the ignore list.", pd.title()))
|
||||||
|
.ok();
|
||||||
|
|
||||||
|
let callback = clone!(pd => move || {
|
||||||
|
utils::uningore_show(pd.id())
|
||||||
|
.map_err(|err| error!("Error: {}", err))
|
||||||
|
.map_err(|_| error!("Could not remove {} from the ignore list.", pd.title()))
|
||||||
|
.ok();
|
||||||
|
|
||||||
|
// Spawn a thread so it won't block the ui.
|
||||||
|
rayon::spawn(clone!(pd => move || {
|
||||||
|
delete_show(&pd)
|
||||||
|
.map_err(|err| error!("Error: {}", err))
|
||||||
|
.map_err(|_| error!("Failed to delete {}", pd.title()))
|
||||||
|
.ok();
|
||||||
|
}));
|
||||||
|
glib::Continue(false)
|
||||||
|
});
|
||||||
|
|
||||||
|
let undo_wrap = move || -> Result<(), Error> {
|
||||||
|
utils::uningore_show(pd.id())?;
|
||||||
|
sender.send(Action::RefreshShowsView)?;
|
||||||
|
sender.send(Action::RefreshEpisodesView)?;
|
||||||
|
Ok(())
|
||||||
|
};
|
||||||
|
|
||||||
|
let undo_callback = move || {
|
||||||
|
undo_wrap().map_err(|err| error!("{}", err)).ok();
|
||||||
|
};
|
||||||
|
|
||||||
|
InAppNotification::new(text, callback, undo_callback)
|
||||||
|
}
|
||||||
|
|
||||||
// Ideally if we had a custom widget this would have been as simple as:
|
// Ideally if we had a custom widget this would have been as simple as:
|
||||||
// `for row in listbox { ep = row.get_episode(); ep.dim_title(); }`
|
// `for row in listbox { ep = row.get_episode(); ep.dim_title(); }`
|
||||||
// But now I can't think of a better way to do it than hardcoding the title
|
// But now I can't think of a better way to do it than hardcoding the title
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user