Permalink
Browse files

Gathered hook functions into a single data structure (Hooks).

  • Loading branch information...
1 parent 55b6a06 commit 5c117181a25d8c2582402858bbd34ee32ffbfa55 koral committed Jan 15, 2012
Showing with 18 additions and 10 deletions.
  1. +8 −5 Hbro/Config.hs
  2. +2 −2 Hbro/Hbro.hs
  3. +7 −2 Hbro/Types.hs
  4. +1 −1 README.rst
View
@@ -1,6 +1,7 @@
module Hbro.Config (
-- * Default configuration
defaultConfig,
+ defaultHooks,
defaultNewWindowHook,
defaultCommandsList
) where
@@ -12,7 +13,7 @@ import Hbro.Util
import Control.Monad.Reader hiding(mapM_)
-import Data.ByteString.Char8 (pack, unpack)
+import Data.ByteString.Char8 (pack)
import Data.Foldable
import Graphics.UI.Gtk.General.General
@@ -41,18 +42,20 @@ defaultConfig directories = Config {
mWebSettings = [],
mSetup = const (return () :: IO ()),
mCommands = defaultCommandsList,
- mNewWindowHook = defaultNewWindowHook,
- mDownloadHook = \_ _ _ _ -> return (),
+ mHooks = defaultHooks,
mError = Nothing
}
-
+
+-- | Pack of default hooks
+defaultHooks :: Hooks
+defaultHooks = Hooks defaultNewWindowHook (\_ _ _ _ -> return ())
+
-- | Default behavior when a new window is requested: load URI in current window.
defaultNewWindowHook :: Environment -> URI -> IO WebView
defaultNewWindowHook env uri = webViewLoadUri webView uri >> return webView
where
webView = (mWebView . mGUI) env
-
-- | List of default supported requests.
defaultCommandsList :: CommandsList
defaultCommandsList = [
View
@@ -145,7 +145,7 @@ realMain' config options gui@GUI {mWebView = webView, mWindow = window} context
_ <- on webView createWebView $ \frame -> do
webFrameGetUri frame >>= maybe (return webView) (\uri -> do
whenLoud $ putStrLn ("Requesting new window: " ++ show uri ++ "...")
- (mNewWindowHook config) environment uri)
+ ((mNewWindow . mHooks) config) environment uri)
-- Bind download hook
void $ on webView downloadRequested $ \download -> do
@@ -156,7 +156,7 @@ realMain' config options gui@GUI {mWebView = webView, mWindow = window} context
case (uri, filename) of
(Just uri', Just filename') -> do
whenNormal $ putStrLn ("Requested download: " ++ show uri')
- (mDownloadHook config) environment uri' filename' size
+ ((mDownload . mHooks) config) environment uri' filename' size
_ -> return ()
return False
View
@@ -55,8 +55,7 @@ data Config = {-forall a.-} Config {
mWebSettings :: [AttrOp WebSettings], -- ^ WebSettings' attributes to use with webkit (see Webkit.WebSettings documentation)
mSetup :: Environment -> IO (), -- ^ Custom startup instructions
mCommands :: CommandsList, -- ^ Custom commands to use with IPC sockets
- mNewWindowHook :: Environment -> URI -> IO WebView, -- ^ Function triggered on a new window request
- mDownloadHook :: Environment -> URI -> String -> Int -> IO (), -- ^ Function triggered on a download request
+ mHooks :: Hooks,
mError :: Maybe String -- ^ Error
--mCustom :: a
}
@@ -69,6 +68,12 @@ data CommonDirectories = CommonDirectories {
mData :: FilePath -- ^ Data directory
}
+-- | Set of functions to be triggered when some events occur
+data Hooks = Hooks {
+ mNewWindow :: Environment -> URI -> IO WebView, -- ^ On a new window request
+ mDownload :: Environment -> URI -> String -> Int -> IO () -- ^ On a download request
+}
+
-- | Graphical elements
data GUI = GUI {
mWindow :: Window, -- ^ Main window
View
@@ -3,7 +3,7 @@ hbro
====
-**In a nutshell**: *hbro* is a minimal KISS compliant browser written in Haskell and for linux, still in development but pretty usable.
+**In a nutshell**: *hbro* is a minimal KISS compliant browser for linux written and configured in Haskell, still in development but pretty usable.
Informations about versions, dependencies, source repositories and contacts can be found in hackage_.

0 comments on commit 5c11718

Please sign in to comment.