From 5ccdb5d100f40e7ca4591dfa3f6308dc7b3f1452 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Thu, 15 Feb 2018 05:31:36 +0200 Subject: [PATCH] Minor cleanup. --- hammond-gtk/src/widgets/episode_states.rs | 132 +++++++++++++--------- 1 file changed, 79 insertions(+), 53 deletions(-) diff --git a/hammond-gtk/src/widgets/episode_states.rs b/hammond-gtk/src/widgets/episode_states.rs index 153636b..d2ad65b 100644 --- a/hammond-gtk/src/widgets/episode_states.rs +++ b/hammond-gtk/src/widgets/episode_states.rs @@ -10,7 +10,7 @@ use gtk; use gtk::prelude::*; #[derive(Debug, Clone)] -pub struct UnItialized; +pub struct UnInitialized; #[derive(Debug, Clone)] pub struct Shown; @@ -34,11 +34,35 @@ impl From for Hidden { } } +impl Into for UnInitialized { + fn into(self) -> Hidden { + Hidden {} + } +} + +impl Into for UnInitialized { + fn into(self) -> Shown { + Shown {} + } +} + #[derive(Debug, Clone)] pub struct Normal; #[derive(Debug, Clone)] pub struct GreyedOut; +impl From for GreyedOut { + fn from(_: Normal) -> Self { + GreyedOut {} + } +} + +impl From for Normal { + fn from(_: GreyedOut) -> Self { + Normal {} + } +} + #[derive(Debug, Clone)] pub struct Title { title: gtk::Label, @@ -64,29 +88,27 @@ impl Title { } impl From> for Title { - fn from(machine: Title) -> Self { - machine - .title + fn from(f: Title) -> Self { + f.title .get_style_context() .map(|c| c.add_class("dim-label")); Title { - title: machine.title, - state: GreyedOut {}, + title: f.title, + state: f.state.into(), } } } impl From> for Title { - fn from(machine: Title) -> Self { - machine - .title + fn from(f: Title) -> Self { + f.title .get_style_context() .map(|c| c.remove_class("dim-label")); Title { - title: machine.title, - state: Normal {}, + title: f.title, + state: f.state.into(), } } } @@ -104,18 +126,22 @@ impl TitleMachine { } pub fn determine_state(self, is_played: bool) -> Self { + use self::TitleMachine::*; + match (self, is_played) { - (title @ TitleMachine::Normal(_), false) => title, - (title @ TitleMachine::GreyedOut(_), true) => title, - (TitleMachine::Normal(val), true) => TitleMachine::GreyedOut(val.into()), - (TitleMachine::GreyedOut(val), false) => TitleMachine::Normal(val.into()), + (title @ Normal(_), false) => title, + (title @ GreyedOut(_), true) => title, + (Normal(val), true) => GreyedOut(val.into()), + (GreyedOut(val), false) => Normal(val.into()), } } pub fn set_title(&mut self, s: &str) { + use self::TitleMachine::*; + match *self { - TitleMachine::Normal(ref mut val) => val.set_title(s), - TitleMachine::GreyedOut(ref mut val) => val.set_title(s), + Normal(ref mut val) => val.set_title(s), + GreyedOut(ref mut val) => val.set_title(s), } } } @@ -157,7 +183,7 @@ impl From> for Duration { Duration { duration: f.duration, separator: f.separator, - state: Shown {}, + state: f.state.into(), } } } @@ -170,7 +196,7 @@ impl From> for Duration { Duration { duration: f.duration, separator: f.separator, - state: Hidden {}, + state: f.state.into(), } } } @@ -236,7 +262,7 @@ impl Size { } } -impl Size { +impl Size { fn new(size: gtk::Label, separator: gtk::Label) -> Self { size.hide(); separator.hide(); @@ -244,7 +270,7 @@ impl Size { Size { size, separator, - state: UnItialized {}, + state: UnInitialized {}, } } @@ -263,7 +289,7 @@ impl From> for Size { Size { size: f.size, separator: f.separator, - state: Hidden {}, + state: f.state.into(), } } } @@ -276,35 +302,35 @@ impl From> for Size { Size { size: f.size, separator: f.separator, - state: Shown {}, + state: f.state.into(), } } } -impl From> for Size { - /// This is suposed to be called only from Size::::set_size. - fn from(f: Size) -> Self { +impl From> for Size { + /// This is suposed to be called only from Size::::set_size. + fn from(f: Size) -> Self { f.size.show(); f.separator.show(); Size { size: f.size, separator: f.separator, - state: Shown {}, + state: f.state.into(), } } } -impl From> for Size { +impl From> for Size { /// This is suposed to be called only from Size::::set_size. - fn from(f: Size) -> Self { + fn from(f: Size) -> Self { f.size.hide(); f.separator.hide(); Size { size: f.size, separator: f.separator, - state: Hidden {}, + state: f.state.into(), } } } @@ -324,7 +350,7 @@ pub struct DownloadPlay { state: S, } -impl DownloadPlay { +impl DownloadPlay { fn new(play: gtk::Button, download: gtk::Button) -> Self { play.hide(); download.hide(); @@ -332,7 +358,7 @@ impl DownloadPlay { DownloadPlay { play, download, - state: UnItialized {}, + state: UnInitialized {}, } } } @@ -415,8 +441,8 @@ impl From> for DownloadPlay { } } -impl From> for DownloadPlay { - fn from(f: DownloadPlay) -> Self { +impl From> for DownloadPlay { + fn from(f: DownloadPlay) -> Self { f.play.hide(); f.download.show(); @@ -428,8 +454,8 @@ impl From> for DownloadPlay { } } -impl From> for DownloadPlay { - fn from(f: DownloadPlay) -> Self { +impl From> for DownloadPlay { + fn from(f: DownloadPlay) -> Self { f.play.show(); f.download.show(); @@ -441,8 +467,8 @@ impl From> for DownloadPlay { } } -impl From> for DownloadPlay { - fn from(f: DownloadPlay) -> Self { +impl From> for DownloadPlay { + fn from(f: DownloadPlay) -> Self { f.play.hide(); f.download.hide(); @@ -463,7 +489,7 @@ pub struct Progress { state: S, } -impl Progress { +impl Progress { fn new( bar: gtk::ProgressBar, cancel: gtk::Button, @@ -480,7 +506,7 @@ impl Progress { cancel, local_size, prog_separator, - state: UnItialized {}, + state: UnInitialized {}, } } } @@ -519,8 +545,8 @@ impl From> for Progress { } } -impl From> for Progress { - fn from(f: Progress) -> Self { +impl From> for Progress { + fn from(f: Progress) -> Self { f.bar.show(); f.cancel.show(); f.local_size.show(); @@ -536,8 +562,8 @@ impl From> for Progress { } } -impl From> for Progress { - fn from(f: Progress) -> Self { +impl From> for Progress { + fn from(f: Progress) -> Self { f.bar.hide(); f.cancel.hide(); f.local_size.hide(); @@ -583,7 +609,7 @@ impl From