-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgui.hs
More file actions
48 lines (40 loc) · 1.63 KB
/
gui.hs
File metadata and controls
48 lines (40 loc) · 1.63 KB
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
module GUI (
startGUI
) where
import Graphics.UI.Gtk hiding (disconnect)
import Graphics.UI.Gtk.Glade
import Manager
import Control.Concurrent (forkIO)
data GUI = GUI {
mainWindow :: Window,
startButton :: Button,
directoryChooser :: FileChooserButton,
statusBar :: Statusbar
}
startGUI :: IO ()
startGUI = initGUI >> loadGlade "gui.glade" >>= prepareGUI >> mainGUI
prepareGUI gui =
do
onDestroy (mainWindow gui) mainQuit
onClicked (startButton gui) $ processClick gui
where
processClick gui = fileChooserGetFilename (directoryChooser gui) >>= (\path -> forkIO $ startImport path) >> return ()
where
startImport (Just path) = do
widgetSetSensitivity (mainWindow gui) False
context <- statusbarGetContextId (statusBar gui) "import"
statusbarPush (statusBar gui) context "Import in progress..."
processDirectory path
statusbarPush (statusBar gui) context "Import finished!"
widgetSetSensitivity (mainWindow gui) True
startImport Nothing = return ()
loadGlade gladePath =
do
Just xml <- xmlNew gladePath
mainWindow <- xmlGetWidget xml castToWindow "mainWindow"
startButton <- xmlGetWidget xml castToButton "startButton"
directoryChooser <- xmlGetWidget xml castToFileChooserButton "directoryChooser"
statusBar <- xmlGetWidget xml castToStatusbar "statusBar"
context <- statusbarGetContextId statusBar "begin"
statusbarPush statusBar context "Ready!"
return $ GUI mainWindow startButton directoryChooser statusBar