From 02de2059db6c8a213eb3672f141d1982d765cd30 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Tue, 13 Feb 2018 05:03:16 +0200 Subject: [PATCH] EpisodeWidget: Shrink the Size state Machine. --- hammond-gtk/src/widgets/episode_states.rs | 119 ++++++++-------------- 1 file changed, 45 insertions(+), 74 deletions(-) diff --git a/hammond-gtk/src/widgets/episode_states.rs b/hammond-gtk/src/widgets/episode_states.rs index edd6d19..012ed3f 100644 --- a/hammond-gtk/src/widgets/episode_states.rs +++ b/hammond-gtk/src/widgets/episode_states.rs @@ -110,6 +110,7 @@ pub struct Duration { impl Duration { // This needs a better name. + // TODO: make me mut fn set_duration(&self, minutes: i64) { self.duration.set_text(&format!("{} min", minutes)); } @@ -192,82 +193,55 @@ impl DurationMachine { } } -#[derive(Debug, Clone)] -pub struct TotalShown; - -#[derive(Debug, Clone)] -pub struct Unkown; - -#[derive(Debug, Clone)] -pub struct InProgress; - #[derive(Debug, Clone)] pub struct Size { local_size: gtk::Label, - total_size: gtk::Label, separator: gtk::Label, prog_separator: gtk::Label, state: S, } -impl Size { - fn set_total_size(&self, text: &str) { - self.total_size.set_text(text) - } -} - -impl Size { - fn new( - local_size: gtk::Label, - total_size: gtk::Label, - separator: gtk::Label, - prog_separator: gtk::Label, - ) -> Self { +impl Size { + fn new(local_size: gtk::Label, separator: gtk::Label, prog_separator: gtk::Label) -> Self { local_size.hide(); - total_size.hide(); separator.hide(); prog_separator.hide(); Size { local_size, - total_size, separator, prog_separator, - state: Unkown {}, + state: Hidden {}, } } } -impl From> for Size { - fn from(f: Size) -> Self { +impl From> for Size { + fn from(f: Size) -> Self { f.prog_separator.show(); - f.total_size.show(); f.local_size.show(); f.separator.show(); Size { local_size: f.local_size, - total_size: f.total_size, separator: f.separator, prog_separator: f.prog_separator, - state: InProgress {}, + state: Shown {}, } } } -impl From> for Size { - fn from(f: Size) -> Self { - f.prog_separator.show(); - f.total_size.show(); - f.local_size.show(); - f.separator.show(); +impl From> for Size { + fn from(f: Size) -> Self { + f.prog_separator.hide(); + f.local_size.hide(); + f.separator.hide(); Size { local_size: f.local_size, - total_size: f.total_size, separator: f.separator, prog_separator: f.prog_separator, - state: InProgress {}, + state: Hidden {}, } } } @@ -425,21 +399,17 @@ impl From> for Progress { } #[derive(Debug, Clone)] -pub struct Media { +pub struct Media { dl: DownloadPlay, - progress: Progress

, + progress: Progress, size: Size, } #[derive(Debug, Clone)] pub enum MediaMachine { - NewWithSize(Media), - NewWithoutSize(Media), - // TODO: Since you've download it you probably know it's size - // Adjust accordignly - PlayableWithSize(Media), - PlayableWithoutSize(Media), - InProgress(Media), + New(Media