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

Commit

Permalink
Gathered hook functions into a single data structure (Hooks).
Browse files Browse the repository at this point in the history
  • Loading branch information
koral committed Jan 15, 2012
1 parent 55b6a06 commit 5c11718
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
13 changes: 8 additions & 5 deletions Hbro/Config.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Hbro.Config (
-- * Default configuration
defaultConfig,
defaultHooks,
defaultNewWindowHook,
defaultCommandsList
) where
Expand All @@ -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
Expand Down Expand Up @@ -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 = [
Expand Down
4 changes: 2 additions & 2 deletions Hbro/Hbro.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
9 changes: 7 additions & 2 deletions Hbro/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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_.

Expand Down

0 comments on commit 5c11718

Please sign in to comment.