Signalling

To complete the interaction of our GoMail examples, we'll make use of the standard signals and slots within qt. Firstly, we need to set up an instance of our test email server and load the data. We add a setMessage(*client.EmailMessage) function to set the content of our labels, which can be called on the loading of our GUI and when the email list is clicked:

func (m *mainUI) setMessage(message *client.EmailMessage) {
m.subject.SetText(message.Subject)
m.to.SetText(message.ToEmailString())
m.from.SetText(message.FromEmailString())
m.date.SetText(message.DateString())

m.content.SetText(message.Content)
}

The code to handle clicking on the email list looks something like the following snippet. We're creating an anonymous function and connecting it to the selectionChanged signal. Remember to check whether there are no selected indexes before finding the selected row number:

list.ConnectSelectionChanged(func(selected *core.QItemSelection, _ *core.QItemSelection) {
if len(selected.Indexes()) == 0 {
return
}

row := selected.Indexes()[0].Row()
m.setMessage(m.server.ListMessages()[row])
})

Next, we need to update our toolbar and menu to open the compose dialog when New is clicked. The triggered signal is the one to connect to; we need to wrap showCompose() in an anonymous function as the signal type passes a bool flag (for the checked status) that we want to ignore. The code is identical for toolbars and menus:

new := file.AddAction("New")
new.ConnectTriggered(func(_ bool){showCompose()})

Similar code is used to handle button presses, which send a clicked signal; our compose dialog, c, will connect an anonymous function to compose an email, send it, and hide the dialog when Send is clicked:

send.ConnectClicked(func(_ bool) {
email := c.createEmail()
c.server.Send(email)
c.dialog.Close()
})
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.93.141