As we think about the buttons available in the main window, three of them correspond to tasks that could take a while to complete: update, download, and fetch. While these operations take place, we’d like to do two things with our GUI: provide the user with the status of the operation and the ability to cancel the operation as it is in progress.
Since all three of these things are very
similar operations, it makes sense to provide a generic way to handle
this interaction. We have defined a single status window widget in the
Glade file that will be used by all three of these. In our Haskell
source code, we’ll define a generic
statusWindow function that will be used by all
three of these operations as well.
statusWindow takes four parameters: the GUI
information, the database information, a
String giving the title of the window, and a
function that will perform the operation. This function will itself be
passed a function that it can call to report its progress. Here’s the
-- file: ch23/PodMainGUI.hs statusWindow :: IConnection conn => GUI -> conn -> String -> ((String -> IO ()) -> IO ()) -> IO () statusWindow gui dbh title func = do -- Clear the status text labelSetText (swLabel gui) "" -- Disable the OK button, enable Cancel button widgetSetSensitivity (swOKBt gui) False widgetSetSensitivity (swCancelBt gui) True -- Set the title windowSetTitle (statusWin gui) title -- Start the operation childThread <- forkIO childTasks -- Define what happens when clicking ...