packages feed

tabloid-0.3: DataProcController.hs

module DataProcController where

import Graphics.UI.Gtk
import Control.Monad
import Control.Applicative

import qualified DataProcView as View
import qualified ShellCmdInputController as Shell
import qualified LineSplitterController as RxDef
import qualified TableController as Table

import qualified Data.ByteString.Lazy.Char8 as L
import SimpleRegex
 
import WindowedApp
import Component

type Controller = Ref C

view = View.mainWidget . gui

new :: IO Controller
new = do
  s <- Shell.new
  r <- RxDef.new
  t <- Table.new
  sv <- (s.>Shell.view) 
  rv <- (r.>RxDef.view) 
  tv <- (t.>Table.view)
  g <- View.new sv rv tv 
  this <- newRef $ C g s r t RxDef.defaultFilter
  s .< Shell.onUpdate 
        (Just (\lines -> this .>> showData lines))
  r .< RxDef.onUpdate 
        (Just (\filt -> do
                   this .< (\stat -> stat {filterFun = filt})
                   postGUIAsync $ s .<< Shell.runText))
  return this

-- internal

showData :: L.ByteString -> C -> IO ()
showData x state = (filterFun state x) >>= Table.push (table state) 

data C = C {
      gui :: View.ViewState
    , shell :: Shell.Controller
    , rxdef :: RxDef.Controller
    , table :: Table.Controller
    , filterFun :: RxDef.Filter
    }

-- tests
test = windowedApp "DataProcController test" $ do
         t <- new  :: IO Controller
         t .> view