EpisodeWidget: Move state machine implementations into a separate module.
This commit is contained in:
parent
e22a78fac6
commit
23979b8f22
@ -15,6 +15,7 @@ use hammond_data::utils::get_download_folder;
|
||||
|
||||
use app::Action;
|
||||
use manager;
|
||||
use widgets::episode_states::*;
|
||||
|
||||
use std::path::Path;
|
||||
use std::sync::{Arc, Mutex};
|
||||
@ -40,89 +41,6 @@ lazy_static! {
|
||||
static ref NOW: DateTime<Utc> = Utc::now();
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct Normal;
|
||||
#[derive(Debug, Clone)]
|
||||
struct GreyedOut;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct Title<S> {
|
||||
title: gtk::Label,
|
||||
state: S,
|
||||
}
|
||||
|
||||
impl<S> Title<S> {
|
||||
fn set_title(&self, s: &str) {
|
||||
self.title.set_text(s);
|
||||
}
|
||||
}
|
||||
|
||||
impl Title<Normal> {
|
||||
fn new(title: gtk::Label) -> Self {
|
||||
Title {
|
||||
title,
|
||||
state: Normal {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Title<Normal>> for Title<GreyedOut> {
|
||||
fn from(machine: Title<Normal>) -> Self {
|
||||
machine
|
||||
.title
|
||||
.get_style_context()
|
||||
.map(|c| c.add_class("dim-label"));
|
||||
|
||||
Title {
|
||||
title: machine.title,
|
||||
state: GreyedOut {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Title<GreyedOut>> for Title<Normal> {
|
||||
fn from(machine: Title<GreyedOut>) -> Self {
|
||||
machine
|
||||
.title
|
||||
.get_style_context()
|
||||
.map(|c| c.remove_class("dim-label"));
|
||||
|
||||
Title {
|
||||
title: machine.title,
|
||||
state: Normal {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
enum TitleMachine {
|
||||
Normal(Title<Normal>),
|
||||
GreyedOut(Title<GreyedOut>),
|
||||
}
|
||||
|
||||
impl TitleMachine {
|
||||
fn new(label: gtk::Label, is_played: bool) -> Self {
|
||||
let m = TitleMachine::Normal(Title::<Normal>::new(label));
|
||||
m.determine_state(is_played)
|
||||
}
|
||||
|
||||
fn determine_state(self, is_played: bool) -> Self {
|
||||
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()),
|
||||
}
|
||||
}
|
||||
|
||||
fn set_title(&self, s: &str) {
|
||||
match *self {
|
||||
TitleMachine::Normal(ref val) => val.set_title(s),
|
||||
TitleMachine::GreyedOut(ref val) => val.set_title(s),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct EpisodeWidget {
|
||||
pub container: gtk::Box,
|
||||
|
||||
85
hammond-gtk/src/widgets/episode_states.rs
Normal file
85
hammond-gtk/src/widgets/episode_states.rs
Normal file
@ -0,0 +1,85 @@
|
||||
use gtk;
|
||||
use gtk::prelude::*;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Normal;
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct GreyedOut;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Title<S> {
|
||||
title: gtk::Label,
|
||||
state: S,
|
||||
}
|
||||
|
||||
impl<S> Title<S> {
|
||||
fn set_title(&self, s: &str) {
|
||||
self.title.set_text(s);
|
||||
}
|
||||
}
|
||||
|
||||
impl Title<Normal> {
|
||||
fn new(title: gtk::Label) -> Self {
|
||||
Title {
|
||||
title,
|
||||
state: Normal {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Title<Normal>> for Title<GreyedOut> {
|
||||
fn from(machine: Title<Normal>) -> Self {
|
||||
machine
|
||||
.title
|
||||
.get_style_context()
|
||||
.map(|c| c.add_class("dim-label"));
|
||||
|
||||
Title {
|
||||
title: machine.title,
|
||||
state: GreyedOut {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Title<GreyedOut>> for Title<Normal> {
|
||||
fn from(machine: Title<GreyedOut>) -> Self {
|
||||
machine
|
||||
.title
|
||||
.get_style_context()
|
||||
.map(|c| c.remove_class("dim-label"));
|
||||
|
||||
Title {
|
||||
title: machine.title,
|
||||
state: Normal {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum TitleMachine {
|
||||
Normal(Title<Normal>),
|
||||
GreyedOut(Title<GreyedOut>),
|
||||
}
|
||||
|
||||
impl TitleMachine {
|
||||
pub fn new(label: gtk::Label, is_played: bool) -> Self {
|
||||
let m = TitleMachine::Normal(Title::<Normal>::new(label));
|
||||
m.determine_state(is_played)
|
||||
}
|
||||
|
||||
pub fn determine_state(self, is_played: bool) -> Self {
|
||||
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()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_title(&self, s: &str) {
|
||||
match *self {
|
||||
TitleMachine::Normal(ref val) => val.set_title(s),
|
||||
TitleMachine::GreyedOut(ref val) => val.set_title(s),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,6 @@
|
||||
mod show;
|
||||
mod episode;
|
||||
mod episode_states;
|
||||
|
||||
pub use self::episode::EpisodeWidget;
|
||||
pub use self::show::ShowWidget;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user