EpisodeWidget: Add a state machine that will manager progress_bar and cancel bttn.
This commit is contained in:
parent
f7b5b35374
commit
2fbc833ebe
@ -99,6 +99,7 @@ impl TitleMachine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Duration<S> {
|
pub struct Duration<S> {
|
||||||
// TODO: make duration and separator diff types
|
// TODO: make duration and separator diff types
|
||||||
@ -128,26 +129,26 @@ impl Duration<Hidden> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl From<Duration<Hidden>> for Duration<Shown> {
|
impl From<Duration<Hidden>> for Duration<Shown> {
|
||||||
fn from(d: Duration<Hidden>) -> Self {
|
fn from(f: Duration<Hidden>) -> Self {
|
||||||
d.duration.show();
|
f.duration.show();
|
||||||
d.separator.show();
|
f.separator.show();
|
||||||
|
|
||||||
Duration {
|
Duration {
|
||||||
duration: d.duration,
|
duration: f.duration,
|
||||||
separator: d.separator,
|
separator: f.separator,
|
||||||
state: Shown {},
|
state: Shown {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Duration<Shown>> for Duration<Hidden> {
|
impl From<Duration<Shown>> for Duration<Hidden> {
|
||||||
fn from(d: Duration<Shown>) -> Self {
|
fn from(f: Duration<Shown>) -> Self {
|
||||||
d.duration.hide();
|
f.duration.hide();
|
||||||
d.separator.hide();
|
f.separator.hide();
|
||||||
|
|
||||||
Duration {
|
Duration {
|
||||||
duration: d.duration,
|
duration: f.duration,
|
||||||
separator: d.separator,
|
separator: f.separator,
|
||||||
state: Hidden {},
|
state: Hidden {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -329,6 +330,7 @@ impl SizeMachine {
|
|||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Download;
|
pub struct Download;
|
||||||
|
|
||||||
@ -472,3 +474,70 @@ impl DownloadPlayMachine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct Progress<S> {
|
||||||
|
bar: gtk::ProgressBar,
|
||||||
|
cancel: gtk::Button,
|
||||||
|
state: S,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Progress<Hidden> {
|
||||||
|
fn new(bar: gtk::ProgressBar, cancel: gtk::Button) -> Self {
|
||||||
|
bar.hide();
|
||||||
|
cancel.hide();
|
||||||
|
|
||||||
|
Progress {
|
||||||
|
bar,
|
||||||
|
cancel,
|
||||||
|
state: Hidden {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Progress<Hidden>> for Progress<Shown> {
|
||||||
|
fn from(f: Progress<Hidden>) -> Self {
|
||||||
|
f.bar.show();
|
||||||
|
f.cancel.show();
|
||||||
|
|
||||||
|
Progress {
|
||||||
|
bar: f.bar,
|
||||||
|
cancel: f.cancel,
|
||||||
|
state: Shown {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Progress<Shown>> for Progress<Hidden> {
|
||||||
|
fn from(f: Progress<Shown>) -> Self {
|
||||||
|
f.bar.hide();
|
||||||
|
f.cancel.hide();
|
||||||
|
|
||||||
|
Progress {
|
||||||
|
bar: f.bar,
|
||||||
|
cancel: f.cancel,
|
||||||
|
state: Hidden {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub enum ProgressMachine {
|
||||||
|
Hidden(Progress<Hidden>),
|
||||||
|
Shown(Progress<Shown>),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ProgressMachine {
|
||||||
|
pub fn new(bar: gtk::ProgressBar, cancel: gtk::Button) -> Self {
|
||||||
|
ProgressMachine::Hidden(Progress::<Hidden>::new(bar, cancel))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn determine_state(self, is_active: bool) -> Self {
|
||||||
|
match (self, is_active) {
|
||||||
|
(ProgressMachine::Hidden(val), false) => ProgressMachine::Hidden(val.into()),
|
||||||
|
(ProgressMachine::Hidden(val), true) => ProgressMachine::Shown(val.into()),
|
||||||
|
(ProgressMachine::Shown(val), false) => ProgressMachine::Hidden(val.into()),
|
||||||
|
(ProgressMachine::Shown(val), true) => ProgressMachine::Shown(val.into()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user