Skip to content
This repository has been archived by the owner on Jan 15, 2022. It is now read-only.

Commit

Permalink
Various cleaning.
Browse files Browse the repository at this point in the history
  • Loading branch information
koral committed Nov 25, 2012
1 parent 9234fe8 commit c11e26b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 29 deletions.
20 changes: 2 additions & 18 deletions Hbro/Boot.hs
Expand Up @@ -27,10 +27,6 @@ import Data.IORef

import Graphics.UI.Gtk.General.General hiding(initGUI)

import Network.URI as N

import System.Directory
import System.FilePath
import System.Exit
import System.Posix.Signals
import qualified System.ZMQ as ZMQ
Expand All @@ -53,11 +49,10 @@ hbro config setup = do
realMain :: (Config, Setup, CliOptions) -> IO ()
realMain (config, Setup customSetup, options) = do
void $ installHandler sigINT (Catch (runReaderT interruptHandler options)) Nothing
runReaderT (whenLoud Dyre.printPaths) options

gui <- runReaderT Gui.build' config
hooks <- Hooks <$> newIORef Nothing <*> newIORef Nothing <*> newIORef Nothing
startURI <- getStartURI options
startURI <- Options.getStartURI options
keys <- newIORef ""
zmqContext <- ZMQ.init 1

Expand All @@ -82,17 +77,6 @@ realMain (config, Setup customSetup, options) = do
runReaderT (logNormal "Exiting...") options


--
getStartURI :: CliOptions -> IO (Maybe URI)
getStartURI options = case (__startURI options) of
Just uri -> do
fileURI <- doesFileExist uri
case fileURI of
True -> getCurrentDirectory >>= return . N.parseURIReference . ("file://" ++) . (</> uri)
_ -> return $ N.parseURIReference uri
_ -> return Nothing


--
interruptHandler :: (MonadIO m, MonadReader r m, HasOptions r) => m ()
interruptHandler = logVerbose "Received SIGINT." >> io mainQuit
interruptHandler = logNormal "Received SIGINT." >> io mainQuit
6 changes: 5 additions & 1 deletion Hbro/Dyre.hs
@@ -1,3 +1,4 @@
-- | Designed to be imported as @qualified@.
module Hbro.Dyre where

-- {{{ Imports
Expand All @@ -9,6 +10,7 @@ import Config.Dyre.Compile
import Config.Dyre.Paths

import Control.Monad.IO.Class
import Control.Monad.Reader

import System.IO
-- }}}
Expand Down Expand Up @@ -39,7 +41,9 @@ parameters main = defaultParams {
main' (Right x) = main x

wrap :: (a -> IO ()) -> CliOptions -> a -> IO ()
wrap main opts = wrapMain ((parameters main) { configCheck = not $ _vanilla opts }) . Right
wrap main opts args = do
when (_verbose opts) printPaths
wrapMain ((parameters main) { configCheck = not $ _vanilla opts }) $ Right args


-- | Launch a recompilation of the configuration file
Expand Down
17 changes: 8 additions & 9 deletions Hbro/Gui.hs
Expand Up @@ -44,10 +44,17 @@ getObject cast name = do
builder <- asks _builder
io $ builderGetObject builder cast name

-- | Toggle a widget's visibility (provided for convenience).
toggleVisibility :: (MonadIO m, WidgetClass a) => a -> m ()
toggleVisibility widget = io $ do
visibility <- get widget widgetVisible
visibility ? widgetHide widget ?? widgetShow widget


build' :: (MonadIO m, MonadReader r m, HasConfig r) => m GUI
build' = do
xmlPath <- asks _UIFile
io $ void GTK.initGUI
io . void $ GTK.initGUI
-- Load XML
xmlPath' <- io xmlPath
--logNormal $ "Loading GUI from " ++ xmlPath' ++ "... "
Expand Down Expand Up @@ -149,11 +156,3 @@ initWebInspector webView windowBox = do

return inspectorWindow
-- }}}

-- {{{ Util
-- | Toggle a widget's visibility (provided for convenience).
toggleVisibility :: (MonadIO m, WidgetClass a) => a -> m ()
toggleVisibility widget = io $ do
visibility <- get widget widgetVisible
visibility ? widgetHide widget ?? widgetShow widget
-- }}}
14 changes: 14 additions & 0 deletions Hbro/Options.hs
@@ -1,3 +1,4 @@
-- | Designed to be imported as @qualified@.
module Hbro.Options where

-- {{{ Imports
Expand All @@ -11,8 +12,12 @@ import Control.Monad.IO.Class
import Data.Default
import Data.Functor

import Network.URI as N

import System.Console.GetOpt
import System.Directory
import System.Environment
import System.FilePath
-- }}}

description :: [OptDescr (CliOptions -> CliOptions)]
Expand All @@ -35,3 +40,12 @@ get = io $ do
case options of
(opts, input, _, []) -> return $ (foldl (flip id) def opts) { __startURI = (null $ concat input) ? Nothing ?? Just (concat input) }
(_, _, _, _) -> return def

getStartURI :: (MonadIO m, HasOptions a) => a -> m (Maybe URI)
getStartURI options = io $ case (_startURI options) of
Just uri -> do
fileURI <- doesFileExist uri
case fileURI of
True -> getCurrentDirectory >>= return . N.parseURIReference . ("file://" ++) . (</> uri)
_ -> return $ N.parseURIReference uri
_ -> return Nothing
1 change: 0 additions & 1 deletion Hbro/Util.hs
Expand Up @@ -68,7 +68,6 @@ whenLoud f = do
_ -> return ()



logNormal, logVerbose :: (MonadIO m, MonadReader s m, HasOptions s) => String -> m ()
logNormal = whenNormal . io . putStrLn
logVerbose = whenLoud . io . putStrLn
Expand Down

0 comments on commit c11e26b

Please sign in to comment.