Skip to content

Commit

Permalink
Config: Reset sounds, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tgass committed May 17, 2016
1 parent 60c875d commit fd0b891
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Macbeth/Wx/Config/DefaultSounds.hs
Expand Up @@ -16,11 +16,11 @@ defaultSounds = Just Sounds {

gameS :: GameS
gameS = GameS {
newGame = Just "ding1.wav"
newGame = Nothing
, move = MoveS {
normal = Just "move.wav"
, capture = Nothing
, check = Just "slap.wav"
, check = Nothing
, castling = Nothing
, pieceDrop = Nothing
, illegal = Just "penalty.wav"
Expand Down
9 changes: 8 additions & 1 deletion src/Macbeth/Wx/Configuration.hs
Expand Up @@ -4,6 +4,7 @@ module Macbeth.Wx.Configuration (

import Macbeth.Fics.FicsMessage
import Macbeth.Wx.Utils
import Macbeth.Wx.Config.DefaultSounds
import qualified Macbeth.Wx.Config.UserConfig as C

import Control.Concurrent.Chan
Expand All @@ -23,6 +24,7 @@ wxConfiguration chan = do
status <- statusField []

b_current <- button f [text := "Reset", on command := showConfig ct]
b_resetSounds <- button f [text := "Reset Sounds", on command := resetSounds ct]
b_save <- button f [ text := "Save",
on command := either (\_ -> set status [text := "Illegal file format."]) return
=<< runExceptT (parseAndSave ct status)]
Expand All @@ -31,7 +33,7 @@ wxConfiguration chan = do
set f [ statusBar := [status],
layout := margin 10 $ column 10 [
boxed "Configuration" $ fill $ minsize (Size 380 220) $ widget ct
, hfloatRight $ row 5 [widget b_current, widget b_save]]
, hfloatRight $ row 5 [widget b_current, widget b_resetSounds, widget b_save]]
]
registerWxCloseEventListener f chan

Expand All @@ -41,6 +43,11 @@ showConfig ct = do
config <- C.loadConfig
set ct [text := comments ++ BS.unpack (Y.encode $ removeUser config)]

resetSounds :: TextCtrl() -> IO ()
resetSounds ct = do
c <- C.loadConfig
set ct [text := comments ++ BS.unpack (Y.encode $ removeUser c{C.sounds = defaultSounds})]


parseAndSave :: TextCtrl () -> StatusField -> ExceptT Y.ParseException IO ()
parseAndSave ct status = do
Expand Down

0 comments on commit fd0b891

Please sign in to comment.