diff --git a/hammond-gtk/src/widgets/episode_states.rs b/hammond-gtk/src/widgets/episode_states.rs index e42b3bb..463cf47 100644 --- a/hammond-gtk/src/widgets/episode_states.rs +++ b/hammond-gtk/src/widgets/episode_states.rs @@ -9,11 +9,19 @@ use chrono; use gtk; use gtk::prelude::*; +pub trait Visibility {} + +#[derive(Debug, Clone)] +pub struct UnItialized; + #[derive(Debug, Clone)] pub struct Shown; #[derive(Debug, Clone)] pub struct Hidden; +impl Visibility for Shown {} +impl Visibility for Hidden {} + #[derive(Debug, Clone)] pub struct Normal; #[derive(Debug, Clone)] @@ -101,14 +109,14 @@ impl TitleMachine { } #[derive(Debug, Clone)] -pub struct Duration { +pub struct Duration { // TODO: make duration and separator diff types duration: gtk::Label, separator: gtk::Label, state: S, } -impl Duration { +impl Duration { // This needs a better name. // TODO: make me mut fn set_duration(&self, minutes: i64) { @@ -201,13 +209,22 @@ pub struct Size { } impl Size { - fn set_size(&mut self, s: &str) { + fn set_size(self, s: &str) -> Size { self.size.set_text(s); self.separator.show(); + self.into() } } impl Size { + fn set_size(self, s: &str) -> Size { + self.size.set_text(s); + self.separator.show(); + self.into() + } +} + +impl Size { fn new(size: gtk::Label, separator: gtk::Label) -> Self { size.hide(); separator.hide(); @@ -215,7 +232,7 @@ impl Size { Size { size, separator, - state: Hidden {}, + state: UnItialized {}, } } @@ -240,7 +257,6 @@ impl From> for Size { } 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(); @@ -253,6 +269,34 @@ impl From> for Size { } } +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 {}, + } + } +} + +impl From> for Size { + /// This is suposed to be called only from Size::::set_size. + fn from(f: Size) -> Self { + f.size.hide(); + f.separator.hide(); + + Size { + size: f.size, + separator: f.separator, + state: Hidden {}, + } + } +} + #[derive(Debug, Clone)] pub struct Download; @@ -268,7 +312,7 @@ pub struct DownloadPlay { state: S, } -impl DownloadPlay { +impl DownloadPlay { fn new(play: gtk::Button, download: gtk::Button) -> Self { play.hide(); download.hide(); @@ -276,7 +320,7 @@ impl DownloadPlay { DownloadPlay { play, download, - state: Hidden {}, + state: UnItialized {}, } } } @@ -359,6 +403,45 @@ impl From> for DownloadPlay { } } +impl From> for DownloadPlay { + fn from(f: DownloadPlay) -> Self { + f.play.hide(); + f.download.show(); + + DownloadPlay { + play: f.play, + download: f.download, + state: Download {}, + } + } +} + +impl From> for DownloadPlay { + fn from(f: DownloadPlay) -> Self { + f.play.show(); + f.download.show(); + + DownloadPlay { + play: f.play, + download: f.download, + state: Play {}, + } + } +} + +impl From> for DownloadPlay { + fn from(f: DownloadPlay) -> Self { + f.play.hide(); + f.download.hide(); + + DownloadPlay { + play: f.play, + download: f.download, + state: Hidden {}, + } + } +} + #[derive(Debug, Clone)] pub struct Progress { bar: gtk::ProgressBar, @@ -368,7 +451,7 @@ pub struct Progress { state: S, } -impl Progress { +impl Progress { fn new( bar: gtk::ProgressBar, cancel: gtk::Button, @@ -385,7 +468,7 @@ impl Progress { cancel, local_size, prog_separator, - state: Hidden {}, + state: UnItialized {}, } } } @@ -394,8 +477,8 @@ impl From> for Progress { fn from(f: Progress) -> Self { f.bar.show(); f.cancel.show(); - f.local_size.hide(); - f.prog_separator.hide(); + f.local_size.show(); + f.prog_separator.show(); Progress { bar: f.bar, @@ -424,11 +507,122 @@ impl From> for Progress { } } +impl From> for Progress { + fn from(f: Progress) -> Self { + f.bar.show(); + f.cancel.show(); + f.local_size.show(); + f.prog_separator.show(); + + Progress { + bar: f.bar, + cancel: f.cancel, + local_size: f.local_size, + prog_separator: f.prog_separator, + state: Shown {}, + } + } +} + +impl From> for Progress { + fn from(f: Progress) -> Self { + f.bar.hide(); + f.cancel.hide(); + f.local_size.hide(); + f.prog_separator.hide(); + + Progress { + bar: f.bar, + cancel: f.cancel, + local_size: f.local_size, + prog_separator: f.prog_separator, + state: Hidden {}, + } + } +} + #[derive(Debug, Clone)] -pub struct Media { +pub struct Media { dl: DownloadPlay, - progress: Progress, total_size: Size, + progress: Progress, +} + +// From New fro InProgress +impl From