90 lines
2.1 KiB
Haskell
90 lines
2.1 KiB
Haskell
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
|
|
|
|
module Types
|
|
( EpubEnv(..),
|
|
ChapterView(..),
|
|
Chapter(..),
|
|
AppState(..),
|
|
UserAction(..),
|
|
EpubAction,
|
|
NavItem(..),
|
|
ChapterIndex(..),
|
|
InternalPath(..),
|
|
EpubType(..),
|
|
BookInfo(..)
|
|
)
|
|
where
|
|
|
|
import qualified Data.Text as T
|
|
import Codec.Archive.Zip (Archive)
|
|
import qualified Codec.Epub.Data.Metadata as DMeta
|
|
import qualified Codec.Epub.Data.Manifest as DMan
|
|
import Control.Concurrent.Async (Async)
|
|
import Control.Monad.Reader (ReaderT)
|
|
import Data.String (IsString)
|
|
|
|
-- Unified interface for EPub 2 and EPub 3 formats, allows generic programming of both without having to repeat boilerplate
|
|
class BookInfo a where
|
|
getTitle :: a -> T.Text
|
|
getAuthors :: a -> [T.Text]
|
|
getLandmarks :: a -> [NavItem]
|
|
getBookPath :: a -> FilePath
|
|
getSpine :: a -> IO [(InternalPath, T.Text)]
|
|
loadChapter :: a -> (InternalPath, T.Text) -> ChapterIndex -> IO Chapter
|
|
|
|
newtype ChapterIndex = ChapterIndex Int
|
|
deriving (Show, Eq, Ord, Num)
|
|
|
|
newtype InternalPath = InternalPath FilePath
|
|
deriving (Show, Eq)
|
|
|
|
newtype EpubType = EpubType T.Text
|
|
deriving (Show,Eq, IsString)
|
|
|
|
data EpubEnv = EpubEnv
|
|
{ archive :: Archive,
|
|
opfXml :: String,
|
|
baseDir :: FilePath,
|
|
bookPath :: FilePath,
|
|
eMetadata :: DMeta.Metadata,
|
|
eManifest :: DMan.Manifest,
|
|
eVersion :: T.Text
|
|
}
|
|
|
|
data ChapterView = ChapterView
|
|
{ viewTitle :: T.Text,
|
|
viewHtml :: T.Text,
|
|
viewIdx :: ChapterIndex
|
|
}
|
|
|
|
data Chapter = Chapter
|
|
{ chapterTitle :: T.Text,
|
|
chapterTags :: T.Text,
|
|
chapterIdx :: ChapterIndex
|
|
}
|
|
|
|
data AppState = AppState
|
|
{ cEnv :: EpubEnv,
|
|
cIdx :: ChapterIndex,
|
|
zoomlvl :: Double,
|
|
cSpine :: [(InternalPath, T.Text)],
|
|
bTitle :: T.Text,
|
|
cAllChapters :: [Chapter],
|
|
activeTask :: Maybe (Async ()),
|
|
taskVersion :: Integer
|
|
}
|
|
|
|
type EpubAction a = ReaderT EpubEnv IO a
|
|
|
|
data UserAction
|
|
= NextChapter
|
|
| PrevChapter
|
|
| ZoomIn
|
|
| ZoomOut
|
|
| LoadSpecific ChapterIndex
|
|
|
|
data NavItem = NavItem
|
|
{ navLabel :: T.Text,
|
|
navPath :: InternalPath,
|
|
navTypes :: [EpubType]
|
|
} deriving (Show)
|