EpisodeWidget: Expose the connect_clicked callbacks from the statemachine enum.
This commit is contained in:
parent
f50c990d93
commit
973d47ee05
@ -149,19 +149,21 @@ impl EpisodeWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let episode = Arc::new(Mutex::new(episode));
|
let episode = Arc::new(Mutex::new(episode));
|
||||||
|
self.connect_buttons(episode, sender);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn connect_buttons(&self, episode: Arc<Mutex<EpisodeWidgetQuery>>, sender: Sender<Action>) {
|
||||||
let title = self.title.clone();
|
let title = self.title.clone();
|
||||||
self.play
|
if let Ok(media) = self.media.lock() {
|
||||||
.connect_clicked(clone!(episode, sender => move |_| {
|
media.play_connect_clicked(clone!(episode, sender => move |_| {
|
||||||
if let Ok(mut ep) = episode.lock() {
|
if let Ok(mut ep) = episode.lock() {
|
||||||
if let Err(err) = on_play_bttn_clicked(&mut ep, title.clone(), sender.clone()){
|
if let Err(err) = on_play_bttn_clicked(&mut ep, title.clone(), sender.clone()){
|
||||||
error!("Error: {}", err);
|
error!("Error: {}", err);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
self.download
|
media.download_connect_clicked(clone!(episode, sender => move |dl| {
|
||||||
.connect_clicked(clone!(episode, sender => move |dl| {
|
|
||||||
dl.set_sensitive(false);
|
dl.set_sensitive(false);
|
||||||
if let Ok(ep) = episode.lock() {
|
if let Ok(ep) = episode.lock() {
|
||||||
if let Err(err) = on_download_clicked(&ep, sender.clone()) {
|
if let Err(err) = on_download_clicked(&ep, sender.clone()) {
|
||||||
@ -171,7 +173,8 @@ impl EpisodeWidget {
|
|||||||
info!("Donwload started succesfully.");
|
info!("Donwload started succesfully.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Determine the title state.
|
/// Determine the title state.
|
||||||
@ -271,6 +274,7 @@ impl EpisodeWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn on_download_clicked(ep: &EpisodeWidgetQuery, sender: Sender<Action>) -> Result<(), Error> {
|
fn on_download_clicked(ep: &EpisodeWidgetQuery, sender: Sender<Action>) -> Result<(), Error> {
|
||||||
let pd = dbqueries::get_podcast_from_id(ep.podcast_id())?;
|
let pd = dbqueries::get_podcast_from_id(ep.podcast_id())?;
|
||||||
let download_fold = get_download_folder(&pd.title().to_owned())?;
|
let download_fold = get_download_folder(&pd.title().to_owned())?;
|
||||||
@ -285,6 +289,7 @@ fn on_download_clicked(ep: &EpisodeWidgetQuery, sender: Sender<Action>) -> Resul
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn on_play_bttn_clicked(
|
fn on_play_bttn_clicked(
|
||||||
episode: &mut EpisodeWidgetQuery,
|
episode: &mut EpisodeWidgetQuery,
|
||||||
title: Arc<Mutex<TitleMachine>>,
|
title: Arc<Mutex<TitleMachine>>,
|
||||||
@ -317,6 +322,7 @@ fn open_uri(rowid: i32) -> Result<(), Error> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Setup a callback that will update the progress bar.
|
// Setup a callback that will update the progress bar.
|
||||||
|
#[inline]
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(if_same_then_else))]
|
#[cfg_attr(feature = "cargo-clippy", allow(if_same_then_else))]
|
||||||
fn update_progressbar_callback(
|
fn update_progressbar_callback(
|
||||||
prog: Arc<Mutex<manager::Progress>>,
|
prog: Arc<Mutex<manager::Progress>>,
|
||||||
@ -333,6 +339,7 @@ fn update_progressbar_callback(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn progress_bar_helper(
|
fn progress_bar_helper(
|
||||||
prog: Arc<Mutex<manager::Progress>>,
|
prog: Arc<Mutex<manager::Progress>>,
|
||||||
episode_rowid: i32,
|
episode_rowid: i32,
|
||||||
@ -380,6 +387,7 @@ fn progress_bar_helper(
|
|||||||
// Setup a callback that will update the total_size label
|
// Setup a callback that will update the total_size label
|
||||||
// with the http ContentLength header number rather than
|
// with the http ContentLength header number rather than
|
||||||
// relying to the RSS feed.
|
// relying to the RSS feed.
|
||||||
|
#[inline]
|
||||||
fn update_total_size_callback(prog: Arc<Mutex<manager::Progress>>, total_size: >k::Label) {
|
fn update_total_size_callback(prog: Arc<Mutex<manager::Progress>>, total_size: >k::Label) {
|
||||||
timeout_add(
|
timeout_add(
|
||||||
500,
|
500,
|
||||||
@ -389,6 +397,7 @@ fn update_total_size_callback(prog: Arc<Mutex<manager::Progress>>, total_size: &
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn total_size_helper(
|
fn total_size_helper(
|
||||||
prog: Arc<Mutex<manager::Progress>>,
|
prog: Arc<Mutex<manager::Progress>>,
|
||||||
total_size: >k::Label,
|
total_size: >k::Label,
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
// the wrong argument to the wrong position.
|
// the wrong argument to the wrong position.
|
||||||
|
|
||||||
use chrono;
|
use chrono;
|
||||||
|
use glib;
|
||||||
use gtk;
|
use gtk;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
|
|
||||||
@ -354,6 +355,14 @@ impl<S> DownloadPlay<S> {
|
|||||||
state: Hidden {},
|
state: Hidden {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn connect_download<F: Fn(>k::Button) + 'static>(&self, f: F) -> glib::SignalHandlerId {
|
||||||
|
self.download.connect_clicked(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn connect_play_button<F: Fn(>k::Button) + 'static>(&self, f: F) -> glib::SignalHandlerId {
|
||||||
|
self.play.connect_clicked(f)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DownloadPlay<UnInitialized> {
|
impl DownloadPlay<UnInitialized> {
|
||||||
@ -610,4 +619,36 @@ impl MediaMachine {
|
|||||||
// }
|
// }
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn download_connect_clicked<F: Fn(>k::Button) + 'static>(
|
||||||
|
&self,
|
||||||
|
f: F,
|
||||||
|
) -> glib::SignalHandlerId {
|
||||||
|
use self::MediaMachine::*;
|
||||||
|
|
||||||
|
match *self {
|
||||||
|
New(ref val) => val.dl.connect_download(f),
|
||||||
|
NewWithoutSize(ref val) => val.dl.connect_download(f),
|
||||||
|
Playable(ref val) => val.dl.connect_download(f),
|
||||||
|
PlayableWithoutSize(ref val) => val.dl.connect_download(f),
|
||||||
|
InProgress(ref val) => val.dl.connect_download(f),
|
||||||
|
UnInitialized(ref val) => val.dl.connect_download(f),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn play_connect_clicked<F: Fn(>k::Button) + 'static>(
|
||||||
|
&self,
|
||||||
|
f: F,
|
||||||
|
) -> glib::SignalHandlerId {
|
||||||
|
use self::MediaMachine::*;
|
||||||
|
|
||||||
|
match *self {
|
||||||
|
New(ref val) => val.dl.connect_play_button(f),
|
||||||
|
NewWithoutSize(ref val) => val.dl.connect_play_button(f),
|
||||||
|
Playable(ref val) => val.dl.connect_play_button(f),
|
||||||
|
PlayableWithoutSize(ref val) => val.dl.connect_play_button(f),
|
||||||
|
InProgress(ref val) => val.dl.connect_play_button(f),
|
||||||
|
UnInitialized(ref val) => val.dl.connect_play_button(f),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user