~alcinnz/rhapsode

ref: 9946bf63055c178274fe2e4efabf5061ecb89913 rhapsode/src/Types.hs -rw-r--r-- 1.6 KiB
9946bf63 — Adrian Cochrane Log browser history in memory 3 years ago
                                                                                
943ea735 Adrian Cochrane
9946bf63 Adrian Cochrane
943ea735 Adrian Cochrane
ee018b49 Adrian Cochrane
943ea735 Adrian Cochrane
ee018b49 Adrian Cochrane
943ea735 Adrian Cochrane
a9c0bfc0 Adrian Cochrane
9946bf63 Adrian Cochrane
943ea735 Adrian Cochrane
48419960 Adrian Cochrane
a9c0bfc0 Adrian Cochrane
48419960 Adrian Cochrane
943ea735 Adrian Cochrane
9946bf63 Adrian Cochrane
943ea735 Adrian Cochrane
48419960 Adrian Cochrane
a9c0bfc0 Adrian Cochrane
48419960 Adrian Cochrane
943ea735 Adrian Cochrane
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
{-# LANGUAGE OverloadedStrings #-}
module Types(CArray, Page(..), Application(..), visitedURLs) where

import System.Directory (getCurrentDirectory) -- default referer URI
import SpeechStyle (SpeechStyle)
import Data.CSS.Preprocessor.Conditions (ConditionalStyles, conditionalStyles)
import Data.CSS.Preprocessor.Text (TextStyle)
import Text.XML
import qualified Data.Map.Strict as M
import Network.URI
import Network.URI.Fetch (Application(..))
import Data.Trie.Text (Trie)
import Control.Concurrent.MVar

import Foreign.Ptr
import Foreign.StablePtr

type CArray a = Ptr a

data Page = Page {
    url :: URI,
    css :: ConditionalStyles (TextStyle SpeechStyle),
    html :: Document,
    pageTitle :: String,
    pageMIME :: String,
    apps :: [Application],
    backStack :: [(String, URI)],
    forwardStack :: [(String, URI)]
}

visitedURLs :: IO (MVar (Trie ()))
visitedURLs = newEmptyMVar

foreign export ccall c_initialReferer :: IO (StablePtr Page)

c_initialReferer = do
    cwd <- getCurrentDirectory
    newStablePtr $ Page {
        -- Default to URIs being relative to CWD.
        url = URI {uriScheme = "file:", uriPath = cwd,
            uriAuthority = Nothing, uriQuery = "", uriFragment = ""},
        -- Blank values:
        css = conditionalStyles nullURI "temp",
        html = Document {
            documentPrologue = Prologue [] Nothing [],
            documentRoot = Element "temp" M.empty [],
            documentEpilogue = []
        },
        pageTitle = "", pageMIME = "", apps = [],
        backStack = [], forwardStack = []
    }

foreign export ccall c_freePage :: StablePtr Page -> IO ()

c_freePage = freeStablePtr