EpisodeWidget: Expose cancel button from the state machine.
This commit is contained in:
parent
ed87a00225
commit
c9bf58af66
@ -45,9 +45,8 @@ lazy_static! {
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct EpisodeWidget {
|
||||
pub container: gtk::Box,
|
||||
cancel: gtk::Button,
|
||||
title: Arc<Mutex<TitleMachine>>,
|
||||
date: gtk::Label,
|
||||
title: Arc<Mutex<TitleMachine>>,
|
||||
duration: Arc<Mutex<DurationMachine>>,
|
||||
progress: gtk::ProgressBar,
|
||||
total_size: gtk::Label,
|
||||
@ -80,21 +79,20 @@ impl Default for EpisodeWidget {
|
||||
let dur = DurationMachine::new(duration, separator1, None);
|
||||
let duration_machine = Arc::new(Mutex::new(dur));
|
||||
let _media = MediaMachine::new(
|
||||
play.clone(),
|
||||
download.clone(),
|
||||
play,
|
||||
download,
|
||||
progress.clone(),
|
||||
cancel.clone(),
|
||||
cancel,
|
||||
total_size.clone(),
|
||||
local_size.clone(),
|
||||
separator2.clone(),
|
||||
prog_separator.clone(),
|
||||
separator2,
|
||||
prog_separator,
|
||||
);
|
||||
let media_machine = Arc::new(Mutex::new(_media));
|
||||
|
||||
EpisodeWidget {
|
||||
container,
|
||||
progress,
|
||||
cancel,
|
||||
total_size,
|
||||
local_size,
|
||||
title: title_machine,
|
||||
@ -130,7 +128,7 @@ impl EpisodeWidget {
|
||||
|
||||
// Determine what the state of the media widgets should be.
|
||||
if let Err(err) = self.determine_media_state(&episode) {
|
||||
error!("Something went wrong determining the ProgressBar State.");
|
||||
error!("Something went wrong determining the Media State.");
|
||||
error!("Error: {}", err);
|
||||
}
|
||||
|
||||
@ -231,12 +229,7 @@ impl EpisodeWidget {
|
||||
// relying to the RSS feed.
|
||||
update_total_size_callback(prog.clone(), &total_size);
|
||||
|
||||
self.cancel.connect_clicked(clone!(prog => move |cancel| {
|
||||
if let Ok(mut m) = prog.lock() {
|
||||
m.cancel();
|
||||
cancel.set_sensitive(false);
|
||||
}
|
||||
}));
|
||||
lock.cancel_connect_clicked(prog);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@ -10,6 +10,9 @@ use glib;
|
||||
use gtk;
|
||||
use gtk::prelude::*;
|
||||
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use manager::Progress as OtherProgress;
|
||||
use widgets::episode::SIZE_OPTS;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@ -421,6 +424,15 @@ impl<S> Progress<S> {
|
||||
state: Hidden {},
|
||||
}
|
||||
}
|
||||
|
||||
fn cancel_connect_clicked(&self, prog: Arc<Mutex<OtherProgress>>) -> glib::SignalHandlerId {
|
||||
self.cancel.connect_clicked(move |cancel| {
|
||||
if let Ok(mut m) = prog.lock() {
|
||||
m.cancel();
|
||||
cancel.set_sensitive(false);
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Progress<UnInitialized> {
|
||||
@ -675,6 +687,17 @@ impl ButtonsState {
|
||||
PlayableWithoutSize(ref val) => val.dl.play_connect_clicked(f),
|
||||
}
|
||||
}
|
||||
|
||||
fn cancel_connect_clicked(&self, prog: Arc<Mutex<OtherProgress>>) -> glib::SignalHandlerId {
|
||||
use self::ButtonsState::*;
|
||||
|
||||
match *self {
|
||||
New(ref val) => val.progress.cancel_connect_clicked(prog),
|
||||
NewWithoutSize(ref val) => val.progress.cancel_connect_clicked(prog),
|
||||
Playable(ref val) => val.progress.cancel_connect_clicked(prog),
|
||||
PlayableWithoutSize(ref val) => val.progress.cancel_connect_clicked(prog),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@ -728,6 +751,16 @@ impl MediaMachine {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cancel_connect_clicked(&self, prog: Arc<Mutex<OtherProgress>>) -> glib::SignalHandlerId {
|
||||
use self::MediaMachine::*;
|
||||
|
||||
match *self {
|
||||
UnInitialized(ref val) => val.progress.cancel_connect_clicked(prog),
|
||||
Initialized(ref val) => val.cancel_connect_clicked(prog),
|
||||
InProgress(ref val) => val.progress.cancel_connect_clicked(prog),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn determine_state(self, bytes: Option<i32>, is_active: bool, is_downloaded: bool) -> Self {
|
||||
use self::ButtonsState::*;
|
||||
use self::MediaMachine::*;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user