~alcinnz/rhapsode

ref: 65356894485c86c5bc5c0abe54941fbe2f6132cd rhapsode/src/Types.hs -rw-r--r-- 1.8 KiB
65356894 — Adrian Cochrane Factor out URI Fetching logic into seperate hackage. 1 year, 7 months ago
                                                                                
943ea735 Adrian Cochrane
65356894 Adrian Cochrane
943ea735 Adrian Cochrane
ee018b49 Adrian Cochrane
943ea735 Adrian Cochrane
ee018b49 Adrian Cochrane
943ea735 Adrian Cochrane
65356894 Adrian Cochrane
8bf7b85d Adrian Cochrane
481a1088 Adrian Cochrane
8bf7b85d Adrian Cochrane
943ea735 Adrian Cochrane
989a5032 Adrian Cochrane
943ea735 Adrian Cochrane
65356894 Adrian Cochrane
943ea735 Adrian Cochrane
65356894 Adrian Cochrane
49f50591 Adrian Cochrane
943ea735 Adrian Cochrane
65356894 Adrian Cochrane
943ea735 Adrian Cochrane
65356894 Adrian Cochrane
943ea735 Adrian Cochrane
65356894 Adrian Cochrane
943ea735 Adrian Cochrane
48419960 Adrian Cochrane
a9c0bfc0 Adrian Cochrane
65356894 Adrian Cochrane
943ea735 Adrian Cochrane
65356894 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
56
57
{-# LANGUAGE OverloadedStrings #-}
module Types(CArray, Page(..), Application(..), RhapsodeCSS, buildDirFile, readStrict) 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(..), url)
import Network.URI.Fetch.XML (Page(..), loadVisited, readStrict)

-- For the in-memory history log
import qualified Data.Set as Set
import Data.Set (Set)
import Data.Text (Text(..))
import qualified Data.Text as Txt
import System.Directory
import System.FilePath ((</>))
import Control.Parallel (par)

import Foreign.Ptr
import Foreign.StablePtr

buildDir = "."
buildDirFile = (buildDir </>)

type CArray a = Ptr a
type RhapsodeCSS = ConditionalStyles (TextStyle SpeechStyle)

foreign export ccall c_initialReferer :: IO (StablePtr (Page RhapsodeCSS))

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

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

c_freePage = freeStablePtr