Skip to content

Commit

Permalink
move synchronization of VFO events out of the ui package
Browse files Browse the repository at this point in the history
  • Loading branch information
ftl committed May 28, 2024
1 parent cdc7e36 commit 7cc2912
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 48 deletions.
69 changes: 37 additions & 32 deletions core/entry/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,23 +424,24 @@ func (c *Controller) bandEntered(band core.Band) {
}

func (c *Controller) VFOFrequencyChanged(frequency core.Frequency) {
if c.editing {
return
}
if c.selectedFrequency == frequency {
return
}
jump := math.Abs(float64(c.selectedFrequency-frequency)) > float64(jumpThreshold)
c.selectedFrequency = frequency
c.view.SetFrequency(c.selectedFrequency)
c.asyncRunner(func() {
if c.editing {
return
}
if c.selectedFrequency == frequency {
return
}
jump := math.Abs(float64(c.selectedFrequency-frequency)) > float64(jumpThreshold)
c.selectedFrequency = frequency

if jump {
c.asyncRunner(func() {
c.view.SetFrequency(frequency)

if jump {
c.Clear()
c.activeField = core.CallsignField
c.view.SetActiveField(c.activeField)
})
}
}
})
}

func (c *Controller) bandSelected(s string) {
Expand All @@ -453,15 +454,17 @@ func (c *Controller) bandSelected(s string) {
}

func (c *Controller) VFOBandChanged(band core.Band) {
if c.editing {
return
}
if band == core.NoBand || band == c.selectedBand {
return
}
c.selectedBand = band
c.input.band = c.selectedBand.String()
c.view.SetBand(c.input.band)
c.asyncRunner(func() {
if c.editing {
return
}
if band == core.NoBand || band == c.selectedBand {
return
}
c.selectedBand = band
c.input.band = c.selectedBand.String()
c.view.SetBand(c.input.band)
})
}

func (c *Controller) modeSelected(s string) {
Expand All @@ -478,7 +481,7 @@ func (c *Controller) modeSelected(s string) {
}

func (c *Controller) generateReportForMode(mode core.Mode) {
generatedReport := defaultReportForMode(c.selectedMode)
generatedReport := defaultReportForMode(mode)
myIndex := c.myReportExchangeField.Field.ExchangeIndex()
if myIndex > 0 {
c.input.myReport = generatedReport
Expand All @@ -505,15 +508,17 @@ func defaultReportForMode(mode core.Mode) string {
}

func (c *Controller) VFOModeChanged(mode core.Mode) {
if c.editing {
return
}
if mode == core.NoMode || mode == c.selectedMode {
return
}
c.selectedMode = mode
c.input.mode = c.selectedMode.String()
c.view.SetMode(c.input.mode)
c.asyncRunner(func() {
if c.editing {
return
}
if mode == core.NoMode || mode == c.selectedMode {
return
}
c.selectedMode = mode
c.input.mode = c.selectedMode.String()
c.view.SetMode(c.input.mode)
})
}

func (c *Controller) SendQuestion() {
Expand Down
10 changes: 6 additions & 4 deletions core/entry/entry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ func TestEntryController_EditQSO(t *testing.T) {

log.Activate()
log.On("Log", changedQSO).Once()
log.On("LastExchange").Return([]string{"599", "001", ""}).Once()
log.On("LastExchange").Return([]string{"599", "001", ""}).Times(2)
log.On("NextNumber").Return(core.QSONumber(35))
controller.Log()

Expand All @@ -603,7 +603,7 @@ func setupEntryTest() (core.Clock, *mocked.Log, *mocked.QSOList, *mocked.EntryVi
qsoList := new(mocked.QSOList)
view := new(mocked.EntryView)
settings := &testSettings{myCall: "DL0ABC"}
controller := NewController(settings, clock, qsoList, new(nullBandmap), testIgnoreAsync)
controller := NewController(settings, clock, qsoList, new(nullBandmap), testRunSync)
vfo := &testVFO{controller}
controller.SetVFO(vfo)
controller.SetLogbook(log)
Expand All @@ -621,7 +621,7 @@ func setupEntryTestWithClassicExchangeFields() (core.Clock, *mocked.Log, *mocked
view := new(mocked.EntryView)
exchangeFields := []conval.ExchangeField{{conval.RSTProperty}, {conval.SerialNumberProperty}, {conval.GenericTextProperty}}
settings := &testSettings{myCall: "DL0ABC", exchangeFields: exchangeFields, exchangeValues: []string{"599", "", ""}, generateSerialExchange: true}
controller := NewController(settings, clock, qsoList, new(nullBandmap), testIgnoreAsync)
controller := NewController(settings, clock, qsoList, new(nullBandmap), testRunSync)
vfo := &testVFO{controller}
controller.SetVFO(vfo)
controller.SetLogbook(log)
Expand All @@ -643,7 +643,7 @@ func setupEntryTestWithExchangeFields(exchangeFieldCount int) (core.Clock, *mock
exchangeFields[i] = conval.ExchangeField{conval.GenericTextProperty}
}
settings := &testSettings{myCall: "DL0ABC", exchangeFields: exchangeFields, exchangeValues: exchangeValues}
controller := NewController(settings, clock, qsoList, new(nullBandmap), testIgnoreAsync)
controller := NewController(settings, clock, qsoList, new(nullBandmap), testRunSync)
vfo := &testVFO{controller}
controller.SetVFO(vfo)
controller.SetLogbook(log)
Expand Down Expand Up @@ -692,6 +692,8 @@ func (s *testSettings) Contest() core.Contest {

func testIgnoreAsync(f func()) {}

func testRunSync(f func()) { f() }

func fieldDefinition(fields ...conval.ExchangeField) *conval.Definition {
return &conval.Definition{
Exchange: []conval.ExchangeDefinition{
Expand Down
16 changes: 4 additions & 12 deletions ui/entryView.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,19 +208,15 @@ func (v *entryView) setTextWithoutChangeEvent(f func(string), value string) {
}

func (v *entryView) SetUTC(text string) {
runAsync(func() {
v.utc.SetText(text)
})
v.utc.SetText(text)
}

func (v *entryView) SetMyCall(text string) {
v.myCall.SetText(text)
}

func (v *entryView) SetFrequency(frequency core.Frequency) {
runAsync(func() {
v.frequency.SetText(fmt.Sprintf("%.2f kHz", frequency/1000.0))
})
v.frequency.SetText(fmt.Sprintf("%.2f kHz", frequency/1000.0))
}

func (v *entryView) SetCallsign(text string) {
Expand All @@ -236,15 +232,11 @@ func (v *entryView) SetTheirExchange(index int, text string) {
}

func (v *entryView) SetBand(text string) {
runAsync(func() {
v.setTextWithoutChangeEvent(func(s string) { v.band.SetActiveID(s) }, text)
})
v.setTextWithoutChangeEvent(func(s string) { v.band.SetActiveID(s) }, text)
}

func (v *entryView) SetMode(text string) {
runAsync(func() {
v.setTextWithoutChangeEvent(func(s string) { v.mode.SetActiveID(s) }, text)
})
v.setTextWithoutChangeEvent(func(s string) { v.mode.SetActiveID(s) }, text)
}

func (v *entryView) SetMyExchange(index int, text string) {
Expand Down

0 comments on commit 7cc2912

Please sign in to comment.