diff --git a/hammond-gtk/src/widgets/episode_states.rs b/hammond-gtk/src/widgets/episode_states.rs index c8078f9..b7cdef9 100644 --- a/hammond-gtk/src/widgets/episode_states.rs +++ b/hammond-gtk/src/widgets/episode_states.rs @@ -99,6 +99,7 @@ impl TitleMachine { } } } + #[derive(Debug, Clone)] pub struct Duration { // TODO: make duration and separator diff types @@ -128,26 +129,26 @@ impl Duration { } impl From> for Duration { - fn from(d: Duration) -> Self { - d.duration.show(); - d.separator.show(); + fn from(f: Duration) -> Self { + f.duration.show(); + f.separator.show(); Duration { - duration: d.duration, - separator: d.separator, + duration: f.duration, + separator: f.separator, state: Shown {}, } } } impl From> for Duration { - fn from(d: Duration) -> Self { - d.duration.hide(); - d.separator.hide(); + fn from(f: Duration) -> Self { + f.duration.hide(); + f.separator.hide(); Duration { - duration: d.duration, - separator: d.separator, + duration: f.duration, + separator: f.separator, state: Hidden {}, } } @@ -329,6 +330,7 @@ impl SizeMachine { unimplemented!() } } + #[derive(Debug, Clone)] pub struct Download; @@ -472,3 +474,70 @@ impl DownloadPlayMachine { } } } + +#[derive(Debug, Clone)] +pub struct Progress { + bar: gtk::ProgressBar, + cancel: gtk::Button, + state: S, +} + +impl Progress { + fn new(bar: gtk::ProgressBar, cancel: gtk::Button) -> Self { + bar.hide(); + cancel.hide(); + + Progress { + bar, + cancel, + state: Hidden {}, + } + } +} + +impl From> for Progress { + fn from(f: Progress) -> Self { + f.bar.show(); + f.cancel.show(); + + Progress { + bar: f.bar, + cancel: f.cancel, + state: Shown {}, + } + } +} + +impl From> for Progress { + fn from(f: Progress) -> Self { + f.bar.hide(); + f.cancel.hide(); + + Progress { + bar: f.bar, + cancel: f.cancel, + state: Hidden {}, + } + } +} + +#[derive(Debug, Clone)] +pub enum ProgressMachine { + Hidden(Progress), + Shown(Progress), +} + +impl ProgressMachine { + pub fn new(bar: gtk::ProgressBar, cancel: gtk::Button) -> Self { + ProgressMachine::Hidden(Progress::::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()), + } + } +}