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