X-Git-Url: http://gitweb.michael.orlitzky.com/?p=dead%2Flwn-epub.git;a=blobdiff_plain;f=src%2FConfiguration.hs;fp=src%2FConfiguration.hs;h=4d5604354cf51cf032e26939d81565aa5d9c2606;hp=118f10f3c101513a1a0427f77f35118b7088fea5;hb=00295eded52d532e145e52e832f2baf2cc447b05;hpb=9522dae5ae266206b10e5517215e9d7143bf3df8 diff --git a/src/Configuration.hs b/src/Configuration.hs index 118f10f..4d56043 100644 --- a/src/Configuration.hs +++ b/src/Configuration.hs @@ -2,15 +2,16 @@ module Configuration ( Cfg(..), + cj_empty, get_cfg, use_account ) where -import Control.Monad (mplus) import Data.ConfigFile import Data.Maybe (isJust) import Data.Monoid (Monoid(..)) +import Network.HTTP.Conduit (CookieJar, createCookieJar, destroyCookieJar) import System.Directory ( doesFileExist, getAppUserDataDirectory @@ -29,27 +30,42 @@ import ExitCodes -- | Contains all of our configurable options. data Cfg = Cfg { article :: String, - cookie_jar :: Maybe FilePath, + cookie_jar :: CookieJar, full_stories :: Bool, output :: FilePath, password :: Maybe String, username :: Maybe String } +-- An empty CookieJar. See cj_append for rationale. +cj_empty :: CookieJar +cj_empty = createCookieJar [] + + +-- Defined for convenience; I would really like to use mappend but GHC +-- bitches about the orphan instance. +cj_append :: CookieJar -> CookieJar -> CookieJar +cj_append cj1 cj2 = + createCookieJar (cookies1 ++ cookies2) + where + -- Decompose the cookie jars into lists. + cookies1 = destroyCookieJar cj1 + cookies2 = destroyCookieJar cj2 + instance Monoid Cfg where - mempty = Cfg { article = "", - cookie_jar = Nothing, + mempty = Cfg { article = mempty, + cookie_jar = cj_empty, full_stories = False, - output = "", + output = mempty, password = Nothing, username = Nothing } mappend c1 c2 = let article' = (if null article1 then article2 else article1) - cookie_jar' = cookie_jar1 `mplus` cookie_jar2 + cookie_jar' = cookie_jar1 `cj_append` cookie_jar2 full_stories' = full_stories1 || full_stories2 output' = (if null output1 then output2 else output1) - password' = password1 `mplus` password2 - username' = username1 `mplus` username2 + password' = password1 `mappend` password2 + username' = username1 `mappend` username2 in Cfg { article = article', cookie_jar = cookie_jar',