diff --git a/src/Qoropa.hs b/src/Qoropa.hs index 5c6d62c..1402172 100644 --- a/src/Qoropa.hs +++ b/src/Qoropa.hs @@ -25,8 +25,8 @@ import Qoropa.Config (QoropaConfig) import Qoropa.UI (start, mainLoop) qoropa :: QoropaConfig -> IO () -qoropa conf = do - ui <- start - mainLoop conf ui +qoropa cfg = do + ui <- start cfg + mainLoop ui -- vim: set ft=haskell et ts=4 sts=4 sw=4 fdm=marker : diff --git a/src/Qoropa/Config.hs b/src/Qoropa/Config.hs index 794fdf5..a06ab40 100644 --- a/src/Qoropa/Config.hs +++ b/src/Qoropa/Config.hs @@ -303,13 +303,14 @@ searchDrawStatusMessage :: Search.Attributes -> Search.StatusMessage -> Image searchDrawStatusMessage attr msg = string (Search.attrStatusMessage attr) (Search.sMessage msg) data QoropaConfig = QoropaConfig - { databasePath :: FilePath - , folderList :: [(String,String)] - , keys :: Map Event (UI -> IO ()) - , logPriority :: Priority - , themeSearch :: Search.Theme - , themeFolder :: Folder.Theme - , themeLog :: Log.Theme + { configDatabasePath :: FilePath + , configFolderList :: [(String,String)] + , configKeys :: Map Event (UI -> IO ()) + , configLogPriority :: Priority + , configThemeSearch :: Search.Theme + , configThemeFolder :: Folder.Theme + , configThemeLog :: Log.Theme + , configVtyEscDelay :: Int } defaultKeys :: Map Event (UI -> IO ()) @@ -332,13 +333,14 @@ defaultKeys = Map.fromList $ defaultConfig :: QoropaConfig defaultConfig = QoropaConfig - { databasePath = "~/.maildir" - , folderList = [("inbox", "tag:inbox"), ("unread", "tag:inbox and tag:unread")] - , keys = defaultKeys - , logPriority = NOTICE - , themeSearch = defaultSearchTheme - , themeFolder = defaultFolderTheme - , themeLog = defaultLogTheme + { configDatabasePath = "~/.maildir" + , configFolderList = [("inbox", "tag:inbox"), ("unread", "tag:inbox and tag:unread")] + , configKeys = defaultKeys + , configLogPriority = NOTICE + , configThemeSearch = defaultSearchTheme + , configThemeFolder = defaultFolderTheme + , configThemeLog = defaultLogTheme + , configVtyEscDelay = 1000 } -- vim: set ft=haskell et ts=4 sts=4 sw=4 fdm=marker : diff --git a/src/Qoropa/Config.hs-boot b/src/Qoropa/Config.hs-boot new file mode 100644 index 0000000..ac2ac11 --- /dev/null +++ b/src/Qoropa/Config.hs-boot @@ -0,0 +1,22 @@ +{- +- Qoropa -- Love Your Mail! +- Copyright © 2010 Ali Polatel +- +- This file is part of the Qoropa mail reader. Qoropa is free software; +- you can redistribute it and/or modify it under the terms of the GNU General +- Public License version 2, as published by the Free Software Foundation. +- +- Qoropa is distributed in the hope that it will be useful, but WITHOUT ANY +- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +- A PARTICULAR PURPOSE. See the GNU General Public License for more details. +- +- You should have received a copy of the GNU General Public License along with +- this program; if not, write to the Free Software Foundation, Inc., 59 Temple +- Place, Suite 330, Boston, MA 02111-1307 USA +- +- Author: Ali Polatel +-} + +module Qoropa.Config where data QoropaConfig + +-- vim: set ft=haskell et ts=4 sts=4 sw=4 fdm=marker : diff --git a/src/Qoropa/UI.hs b/src/Qoropa/UI.hs index 11080a1..1c860f1 100644 --- a/src/Qoropa/UI.hs +++ b/src/Qoropa/UI.hs @@ -47,7 +47,7 @@ import System.Log.Logger ) import Graphics.Vty - ( Vty, mkVty, reserve_display, shutdown, terminal, update + ( Vty, mkVtyEscDelay, reserve_display, shutdown, terminal, update , DisplayRegion(..), display_bounds , Event(..), Key(..), Modifier(..), next_event ) @@ -79,7 +79,8 @@ import Qoropa.Config (QoropaConfig(..)) import Qoropa.Util (beep, expandTilde) data UI = UI - { vty :: Vty + { userConfig :: QoropaConfig + , vty :: Vty , uiEvent :: MVar UIEvent , uiThread :: ThreadId , scrSize :: IORef (Int, Int) @@ -215,17 +216,18 @@ cancelOperation ui = do BufSearch ref -> Search.cancelLoad ref _ -> beep -start :: IO UI -start = do - tid <- myThreadId - eventUI <- newEmptyMVar +start :: QoropaConfig -> IO UI +start cfg = do + tid <- myThreadId + eventUI <- newEmptyMVar - vtyUI <- mkVty + vtyUI <- mkVtyEscDelay (configVtyEscDelay cfg) DisplayRegion x0 y0 <- display_bounds $ terminal vtyUI size <- newIORef (fromEnum y0, fromEnum x0) sq <- newIORef Seq.empty cur <- newIORef 0 - let ui = UI { vty = vtyUI + let ui = UI { userConfig = cfg + , vty = vtyUI , scrSize = size , uiEvent = eventUI , uiThread = tid @@ -246,21 +248,21 @@ exit ui = do throwTo (uiThread ui) ExitSuccess return () -mainLoop :: QoropaConfig -> UI -> IO () -mainLoop conf ui = do - path <- expandTilde (databasePath conf) +mainLoop :: UI -> IO () +mainLoop ui = do + path <- expandTilde $ configDatabasePath $ userConfig ui -- Initialize the log buffer - sq <- readIORef (bufSeq ui) - el <- Log.emptyLog (themeLog conf) + sq <- readIORef $ bufSeq ui + el <- Log.emptyLog $ configThemeLog $ userConfig ui logRef <- newIORef el logLock <- Lock.new writeIORef (bufSeq ui) (sq Seq.|> (BufLog logRef, logLock)) writeIORef (bufCurrent ui) (Seq.length sq + 1) -- Add the log handler - let logHandler = Log.handler (logRef, logLock) (uiEvent ui) (logPriority conf) - updateGlobalLogger rootLoggerName $ setLevel (logPriority conf) . setHandlers [logHandler] + let logHandler = Log.handler (logRef, logLock) (uiEvent ui) (configLogPriority $ userConfig ui) + updateGlobalLogger rootLoggerName $ setLevel (configLogPriority $ userConfig ui) . setHandlers [logHandler] noticeM rootLoggerName "Initialized" forkIO $ putMVar (uiEvent ui) NewFolder @@ -275,21 +277,21 @@ mainLoop conf ui = do (EvResize x y) -> writeIORef (scrSize ui) (y, x) >> redraw ui (EvKey (KASCII 'z') [MCtrl]) -> raiseSignal sigTSTP _ -> - case Map.lookup e (keys conf) of + case Map.lookup e (configKeys $ userConfig ui) of Just f -> f ui Nothing -> debugM rootLoggerName $ "Unhandled event: " ++ show e NewFolder -> do sq <- readIORef (bufSeq ui) - ef <- Folder.emptyFolder (themeFolder conf) + ef <- Folder.emptyFolder (configThemeFolder $ userConfig ui) folderRef <- newIORef ef folderLock <- Lock.new writeIORef (bufSeq ui) (sq Seq.|> (BufFolder folderRef, folderLock)) writeIORef (bufCurrent ui) (Seq.length sq + 1) - forkIO $ Folder.new (folderRef, folderLock) (uiEvent ui) path (folderList conf) + forkIO $ Folder.new (folderRef, folderLock) (uiEvent ui) path (configFolderList $ userConfig ui) return () NewSearch term -> do sq <- readIORef (bufSeq ui) - es <- Search.emptySearch (themeSearch conf) + es <- Search.emptySearch (configThemeSearch $ userConfig ui) searchRef <- newIORef es searchLock <- Lock.new writeIORef (bufSeq ui) (sq Seq.|> (BufSearch searchRef, searchLock)) diff --git a/src/Qoropa/UI.hs-boot b/src/Qoropa/UI.hs-boot index 4fac808..3c7c2f3 100644 --- a/src/Qoropa/UI.hs-boot +++ b/src/Qoropa/UI.hs-boot @@ -34,9 +34,11 @@ import Graphics.Vty (Vty, Event) import Qoropa.Lock (Lock) import {-# SOURCE #-} Qoropa.Buffer (Buffer) +import {-# SOURCE #-} Qoropa.Config (QoropaConfig) data UI = UI - { vty :: Vty + { userConfig :: QoropaConfig + , vty :: Vty , uiEvent :: MVar UIEvent , uiThread :: ThreadId , scrSize :: IORef (Int, Int)