From 00295eded52d532e145e52e832f2baf2cc447b05 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Mon, 20 Aug 2012 15:43:26 -0400 Subject: [PATCH] Switch from a FilePath to a CookieJar in the config. --- src/Configuration.hs | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) 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', -- 2.43.2