{-# LANGUAGE DeriveDataTypeable, TemplateHaskell, TypeFamilies #-}
module Clckwrks.NavBar.Acid where

import Clckwrks.NavBar.Types  (NavBar(..), NavBarItem(..))
import Control.Applicative  ((<$>))
import Control.Monad.Reader (ask)
import Control.Monad.State  (modify)
import Data.Acid            (Update, Query, makeAcidic)
import Data.Data            (Data, Typeable)
import Data.SafeCopy        (base, deriveSafeCopy)

data NavBarState = NavBarState
    { NavBarState -> NavBar
navBar :: NavBar
    }
    deriving (NavBarState -> NavBarState -> Bool
(NavBarState -> NavBarState -> Bool)
-> (NavBarState -> NavBarState -> Bool) -> Eq NavBarState
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NavBarState -> NavBarState -> Bool
$c/= :: NavBarState -> NavBarState -> Bool
== :: NavBarState -> NavBarState -> Bool
$c== :: NavBarState -> NavBarState -> Bool
Eq, ReadPrec [NavBarState]
ReadPrec NavBarState
Int -> ReadS NavBarState
ReadS [NavBarState]
(Int -> ReadS NavBarState)
-> ReadS [NavBarState]
-> ReadPrec NavBarState
-> ReadPrec [NavBarState]
-> Read NavBarState
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [NavBarState]
$creadListPrec :: ReadPrec [NavBarState]
readPrec :: ReadPrec NavBarState
$creadPrec :: ReadPrec NavBarState
readList :: ReadS [NavBarState]
$creadList :: ReadS [NavBarState]
readsPrec :: Int -> ReadS NavBarState
$creadsPrec :: Int -> ReadS NavBarState
Read, Int -> NavBarState -> ShowS
[NavBarState] -> ShowS
NavBarState -> String
(Int -> NavBarState -> ShowS)
-> (NavBarState -> String)
-> ([NavBarState] -> ShowS)
-> Show NavBarState
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NavBarState] -> ShowS
$cshowList :: [NavBarState] -> ShowS
show :: NavBarState -> String
$cshow :: NavBarState -> String
showsPrec :: Int -> NavBarState -> ShowS
$cshowsPrec :: Int -> NavBarState -> ShowS
Show, Typeable NavBarState
DataType
Constr
Typeable NavBarState
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> NavBarState -> c NavBarState)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c NavBarState)
-> (NavBarState -> Constr)
-> (NavBarState -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c NavBarState))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c NavBarState))
-> ((forall b. Data b => b -> b) -> NavBarState -> NavBarState)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> NavBarState -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> NavBarState -> r)
-> (forall u. (forall d. Data d => d -> u) -> NavBarState -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> NavBarState -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> NavBarState -> m NavBarState)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> NavBarState -> m NavBarState)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> NavBarState -> m NavBarState)
-> Data NavBarState
NavBarState -> DataType
NavBarState -> Constr
(forall b. Data b => b -> b) -> NavBarState -> NavBarState
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NavBarState -> c NavBarState
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NavBarState
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> NavBarState -> u
forall u. (forall d. Data d => d -> u) -> NavBarState -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NavBarState -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NavBarState -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> NavBarState -> m NavBarState
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NavBarState -> m NavBarState
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NavBarState
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NavBarState -> c NavBarState
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c NavBarState)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c NavBarState)
$cNavBarState :: Constr
$tNavBarState :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> NavBarState -> m NavBarState
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NavBarState -> m NavBarState
gmapMp :: (forall d. Data d => d -> m d) -> NavBarState -> m NavBarState
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NavBarState -> m NavBarState
gmapM :: (forall d. Data d => d -> m d) -> NavBarState -> m NavBarState
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> NavBarState -> m NavBarState
gmapQi :: Int -> (forall d. Data d => d -> u) -> NavBarState -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> NavBarState -> u
gmapQ :: (forall d. Data d => d -> u) -> NavBarState -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> NavBarState -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NavBarState -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NavBarState -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NavBarState -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NavBarState -> r
gmapT :: (forall b. Data b => b -> b) -> NavBarState -> NavBarState
$cgmapT :: (forall b. Data b => b -> b) -> NavBarState -> NavBarState
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c NavBarState)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c NavBarState)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c NavBarState)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c NavBarState)
dataTypeOf :: NavBarState -> DataType
$cdataTypeOf :: NavBarState -> DataType
toConstr :: NavBarState -> Constr
$ctoConstr :: NavBarState -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NavBarState
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NavBarState
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NavBarState -> c NavBarState
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NavBarState -> c NavBarState
$cp1Data :: Typeable NavBarState
Data, Typeable)
$(deriveSafeCopy 2 'base ''NavBarState)

initialNavBarState :: NavBarState
initialNavBarState :: NavBarState
initialNavBarState =
    NavBarState :: NavBar -> NavBarState
NavBarState { navBar :: NavBar
navBar = [NavBarItem] -> NavBar
NavBar [] }

setNavBar :: NavBar
        -> Update NavBarState ()
setNavBar :: NavBar -> Update NavBarState ()
setNavBar NavBar
m = (NavBarState -> NavBarState) -> Update NavBarState ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((NavBarState -> NavBarState) -> Update NavBarState ())
-> (NavBarState -> NavBarState) -> Update NavBarState ()
forall a b. (a -> b) -> a -> b
$ \NavBarState
ms -> NavBarState
ms { navBar :: NavBar
navBar = NavBar
m }

getNavBar :: Query NavBarState NavBar
getNavBar :: Query NavBarState NavBar
getNavBar = NavBarState -> NavBar
navBar (NavBarState -> NavBar)
-> Query NavBarState NavBarState -> Query NavBarState NavBar
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Query NavBarState NavBarState
forall r (m :: * -> *). MonadReader r m => m r
ask

$(makeAcidic ''NavBarState ['getNavBar, 'setNavBar])