diff --git a/hammond-gtk/src/app.rs b/hammond-gtk/src/app.rs index 198c718..836fb0c 100644 --- a/hammond-gtk/src/app.rs +++ b/hammond-gtk/src/app.rs @@ -6,18 +6,13 @@ use gtk; use gtk::prelude::*; use gtk::SettingsExt as GtkSettingsExt; -use failure::Error; -use rayon; - -use hammond_data::utils::delete_show; use hammond_data::Podcast; -use appnotif::*; use headerbar::Header; use settings::WindowGeometry; use stacks::Content; 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::Arc; @@ -191,61 +186,11 @@ impl App { Ok(Action::HeaderBarShowUpdateIndicator) => headerbar.show_update_notification(), Ok(Action::HeaderBarHideUpdateIndicator) => headerbar.hide_update_notification(), Ok(Action::MarkAllPlayerNotification(pd)) => { - 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(); - let notif = InAppNotification::new(text, callback, undo_callback); + let notif = mark_all_notif(pd, sender.clone()); notif.show(&overlay); } Ok(Action::RemoveShow(pd)) => { - 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 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); + let notif = remove_show_notif(pd, sender.clone()); notif.show(&overlay); } Err(_) => (), diff --git a/hammond-gtk/src/main.rs b/hammond-gtk/src/main.rs index aa343e9..caa96f3 100644 --- a/hammond-gtk/src/main.rs +++ b/hammond-gtk/src/main.rs @@ -5,7 +5,7 @@ ) )] #![allow(unknown_lints)] -#![deny(unused_extern_crates, unused)] +// #![deny(unused_extern_crates, unused)] extern crate gdk; extern crate gdk_pixbuf; diff --git a/hammond-gtk/src/widgets/mod.rs b/hammond-gtk/src/widgets/mod.rs index 72acb20..7d46f47 100644 --- a/hammond-gtk/src/widgets/mod.rs +++ b/hammond-gtk/src/widgets/mod.rs @@ -3,5 +3,5 @@ mod episode_states; mod show; pub use self::episode::EpisodeWidget; -pub use self::show::mark_all_watched; pub use self::show::ShowWidget; +pub use self::show::{mark_all_notif, remove_show_notif}; diff --git a/hammond-gtk/src/widgets/show.rs b/hammond-gtk/src/widgets/show.rs index 0d44e21..2ff735e 100644 --- a/hammond-gtk/src/widgets/show.rs +++ b/hammond-gtk/src/widgets/show.rs @@ -1,15 +1,19 @@ -use failure::Error; -// use glib; +use glib; use gtk; use gtk::prelude::*; + +use failure::Error; use html2pango::markup_from_raw; use open; +use rayon; use hammond_data::dbqueries; +use hammond_data::utils::delete_show; use hammond_data::Podcast; use app::Action; -use utils::set_image_from_path; +use appnotif::InAppNotification; +use utils; use widgets::episode::episodes_listbox; use std::sync::mpsc::{SendError, Sender}; @@ -110,7 +114,7 @@ impl ShowWidget { /// Set the show cover. fn set_cover(&self, pd: Arc) -> 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. @@ -155,7 +159,7 @@ fn on_played_button_clicked(pd: Arc, episodes: >k::Frame, sender: Sen .ok(); } -pub fn mark_all_watched(pd: &Podcast, sender: Sender) -> Result<(), Error> { +fn mark_all_watched(pd: &Podcast, sender: Sender) -> Result<(), Error> { dbqueries::update_none_to_played_now(pd)?; // Not all widgets migth have been loaded when the mark_all is hit // So we will need to refresh again after it's done. @@ -163,6 +167,63 @@ pub fn mark_all_watched(pd: &Podcast, sender: Sender) -> Result<(), Erro sender.send(Action::RefreshEpisodesView).map_err(From::from) } +pub fn mark_all_notif(pd: Arc, sender: Sender) -> 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, sender: Sender) -> 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: // `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