Skip to content

Commit

Permalink
keep track of the ui model in the window types, forward the updates t…
Browse files Browse the repository at this point in the history
…o the views only if they are visible
  • Loading branch information
ftl committed Sep 20, 2023
1 parent 0f2c65e commit e15aa07
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 70 deletions.
4 changes: 2 additions & 2 deletions core/rate/rate.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type Counter struct {
clock core.Clock
view View

listeners []interface{}
listeners []any

lastHourQSOs qsoList
lastQSOTime time.Time
Expand Down Expand Up @@ -95,7 +95,7 @@ func (c *Counter) ContestChanged(contest core.Contest) {
c.view.SetGoals(contest.QSOsGoal, contest.PointsGoal, contest.MultisGoal)
}

func (c *Counter) Notify(listener interface{}) {
func (c *Counter) Notify(listener any) {
c.listeners = append(c.listeners, listener)
}

Expand Down
36 changes: 4 additions & 32 deletions ui/callinfoView.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ func setupCallinfoView(builder *gtk.Builder, colors colorProvider, controller Ca
return result
}

func (c *callinfoView) SetCallinfoController(controller CallinfoController) {
c.controller = controller
}

func (v *callinfoView) RefreshStyle() {
v.style.Refresh()
if v.controller != nil {
Expand All @@ -94,10 +90,6 @@ func attr(name, value string) string {
}

func (v *callinfoView) SetCallsign(callsign string, worked, duplicate bool) {
if v == nil {
return
}

normalized := strings.ToUpper(strings.TrimSpace(callsign))
if normalized == "" {
normalized = "-"
Expand All @@ -115,35 +107,27 @@ func (v *callinfoView) SetCallsign(callsign string, worked, duplicate bool) {
}
}

func (v *callinfoView) SetDXCC(name, continent string, itu, cq int, arrlCompliant bool) {
if v == nil {
return
}

if name == "" {
func (v *callinfoView) SetDXCC(dxccName, continent string, itu, cq int, arrlCompliant bool) {
if dxccName == "" {
v.dxccLabel.SetMarkup("")
return
}

text := fmt.Sprintf("%s, %s", name, continent)
text := fmt.Sprintf("%s, %s", dxccName, continent)
if itu != 0 {
text += fmt.Sprintf(", ITU %d", itu)
}
if cq != 0 {
text += fmt.Sprintf(", CQ %d", cq)
}
if name != "" && !arrlCompliant {
if dxccName != "" && !arrlCompliant {
text += ", <span foreground='red' font-weight='heavy'>not ARRL compliant</span>"
}

v.dxccLabel.SetMarkup(text)
}

func (v *callinfoView) SetValue(points, multis int) {
if v == nil {
return
}

style.RemoveClass(&v.valueLabel.Widget, callinfoWorthlessClass)
style.RemoveClass(&v.valueLabel.Widget, callinfoMultiClass)

Expand All @@ -158,10 +142,6 @@ func (v *callinfoView) SetValue(points, multis int) {
}

func (v *callinfoView) SetExchange(exchange string) {
if v == nil {
return
}

var exchangeMarkup string
if exchange == "" {
exchange = "-"
Expand All @@ -173,18 +153,10 @@ func (v *callinfoView) SetExchange(exchange string) {
}

func (v *callinfoView) SetUserInfo(value string) {
if v == nil {
return
}

v.userInfoLabel.SetText(value)
}

func (v *callinfoView) SetSupercheck(callsigns []core.AnnotatedCallsign) {
if v == nil {
return
}

var text string
for _, callsign := range callsigns {
// see https://docs.gtk.org/Pango/pango_markup.html for reference
Expand Down
80 changes: 78 additions & 2 deletions ui/callinfoWindow.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,33 @@ import (
"github.com/ftl/gmtry"
"github.com/gotk3/gotk3/gtk"

"github.com/ftl/hellocontest/core"
"github.com/ftl/hellocontest/ui/style"
)

const CallinfoWindowID = gmtry.ID("callinfo")

type callinfoWindow struct {
*callinfoView
controller CallinfoController
callinfoView *callinfoView
controller CallinfoController

window *gtk.Window
geometry *gmtry.Geometry
style *style.Style

callsign string
worked bool
duplicate bool
dxccName string
continent string
itu int
cq int
arrlCompliant bool
points int
multis int
exchange string
userInfo string
matchingCallsigns []core.AnnotatedCallsign
}

func setupCallinfoWindow(geometry *gmtry.Geometry, style *style.Style, controller CallinfoController) *callinfoWindow {
Expand Down Expand Up @@ -45,6 +60,12 @@ func (w *callinfoWindow) Show() {
w.window.SetTitle("Callsign Information")
w.window.Connect("destroy", w.onDestroy)
w.callinfoView = setupCallinfoView(builder, w.style.ForWidget(w.window.ToWidget()), w.controller)
w.callinfoView.SetCallsign(w.callsign, w.worked, w.duplicate)
w.callinfoView.SetDXCC(w.dxccName, w.continent, w.itu, w.cq, w.arrlCompliant)
w.callinfoView.SetValue(w.points, w.multis)
w.callinfoView.SetExchange(w.exchange)
w.callinfoView.SetUserInfo(w.userInfo)
w.callinfoView.SetSupercheck(w.matchingCallsigns)
w.window.Connect("style-updated", w.callinfoView.RefreshStyle)
connectToGeometry(w.geometry, CallinfoWindowID, w.window)
}
Expand Down Expand Up @@ -78,3 +99,58 @@ func (w *callinfoWindow) onDestroy() {
w.window = nil
w.callinfoView = nil
}

func (w *callinfoWindow) SetCallsign(callsign string, worked, duplicate bool) {
w.callsign = callsign
w.worked = worked
w.duplicate = duplicate

if w.callinfoView != nil {
w.callinfoView.SetCallsign(callsign, worked, duplicate)
}
}

func (w *callinfoWindow) SetDXCC(dxccName, continent string, itu, cq int, arrlCompliant bool) {
w.dxccName = dxccName
w.continent = continent
w.itu = itu
w.cq = cq
w.arrlCompliant = arrlCompliant

if w.callinfoView != nil {
w.callinfoView.SetDXCC(dxccName, continent, itu, cq, arrlCompliant)
}
}

func (w *callinfoWindow) SetValue(points, multis int) {
w.points = points
w.multis = multis

if w.callinfoView != nil {
w.callinfoView.SetValue(points, multis)
}
}

func (w *callinfoWindow) SetExchange(exchange string) {
w.exchange = exchange

if w.callinfoView != nil {
w.callinfoView.SetExchange(exchange)
}
}

func (w *callinfoWindow) SetUserInfo(userInfo string) {
w.userInfo = userInfo

if w.callinfoView != nil {
w.callinfoView.SetUserInfo(userInfo)
}
}

func (w *callinfoWindow) SetSupercheck(matchingCallsigns []core.AnnotatedCallsign) {
w.matchingCallsigns = matchingCallsigns

if w.callinfoView != nil {
w.callinfoView.SetSupercheck(matchingCallsigns)
}
}
4 changes: 1 addition & 3 deletions ui/rateView.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ func setupNewRateView(builder *gtk.Builder, colors colorProvider) *rateView {

func (v *rateView) ShowRate(rate core.QSORate) {
v.indicator.SetRate(rate)
if v.indicatorArea != nil {
v.indicatorArea.QueueDraw()
}
v.indicatorArea.QueueDraw()
}

func (v *rateView) SetGoals(qsos int, points int, multis int) {
Expand Down
4 changes: 2 additions & 2 deletions ui/rateWindow.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
const RateWindowID = "rate"

type rateWindow struct {
rateView *rateView

window *gtk.Window
geometry *gmtry.Geometry
style *style.Style
Expand All @@ -19,8 +21,6 @@ type rateWindow struct {
qsosGoal int
pointsGoal int
multisGoal int

*rateView
}

func setupRateWindow(geometry *gmtry.Geometry, style *style.Style) *rateWindow {
Expand Down
13 changes: 3 additions & 10 deletions ui/scoreView.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,17 @@ func setupNewScoreView(builder *gtk.Builder, colors colorProvider) *scoreView {
func (v *scoreView) ShowScore(score core.Score) {
v.graph.SetGraphs(score.StackedGraphPerBand())

if v.tableLabel != nil {
renderedScore := fmt.Sprintf("<span allow_breaks='true' font_family='monospace'>%s</span>", score)
v.tableLabel.SetMarkup(renderedScore)
}
renderedScore := fmt.Sprintf("<span allow_breaks='true' font_family='monospace'>%s</span>", score)
v.tableLabel.SetMarkup(renderedScore)

if v.graphArea != nil {
v.graphArea.QueueDraw()
}
v.graphArea.QueueDraw()
}

func (v *scoreView) SetGoals(points int, multis int) {
v.graph.SetGoals(points, multis)
}

func (v *scoreView) RateUpdated(rate core.QSORate) {
if v == nil {
return
}
v.graph.UpdateTimeFrame()

if v.graphArea != nil {
Expand Down
13 changes: 11 additions & 2 deletions ui/scoreWindow.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ import (
const ScoreWindowID = "score"

type scoreWindow struct {
scoreView *scoreView

window *gtk.Window
geometry *gmtry.Geometry
style *style.Style

score core.Score
rate core.QSORate
pointsGoal int
multisGoal int

*scoreView
}

func setupScoreWindow(geometry *gmtry.Geometry, style *style.Style) *scoreWindow {
Expand Down Expand Up @@ -50,6 +51,7 @@ func (w *scoreWindow) Show() {
w.scoreView = setupNewScoreView(builder, w.style.ForWidget(w.window.ToWidget()))
w.scoreView.SetGoals(w.pointsGoal, w.multisGoal)
w.scoreView.ShowScore(w.score)
w.scoreView.RateUpdated(w.rate)
connectToGeometry(w.geometry, ScoreWindowID, w.window)
}
w.window.ShowAll()
Expand Down Expand Up @@ -97,3 +99,10 @@ func (w *scoreWindow) SetGoals(points int, multis int) {
w.scoreView.SetGoals(points, multis)
}
}

func (w *scoreWindow) RateUpdated(rate core.QSORate) {
w.rate = rate
if w.scoreView != nil {
w.scoreView.RateUpdated(rate)
}
}
16 changes: 0 additions & 16 deletions ui/spotsView.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@ func (v *spotsView) filterRow(row *gtk.ListBoxRow) bool {
}

func (v *spotsView) ShowFrame(frame core.BandmapFrame) {
if v == nil {
return
}

runAsync(func() {
v.currentFrame = frame
v.setupBands(frame.Bands)
Expand All @@ -109,9 +105,6 @@ func (v *spotsView) ShowFrame(frame core.BandmapFrame) {
}

func (v *spotsView) setupBands(bands []core.BandSummary) {
if v == nil {
return
}
bandsID := toBandsID(bands)
if bandsID == v.bandsID {
return
Expand Down Expand Up @@ -330,9 +323,6 @@ func updateListEntry(row *gtk.ListBoxRow, entry core.BandmapEntry) {
}

func (v *spotsView) EntryAdded(entry core.BandmapEntry) {
if v == nil {
return
}
runAsync(func() {
w := v.newListEntry(entry)
if w == nil {
Expand All @@ -343,9 +333,6 @@ func (v *spotsView) EntryAdded(entry core.BandmapEntry) {
}

func (v *spotsView) EntryUpdated(entry core.BandmapEntry) {
if v == nil {
return
}
runAsync(func() {
row := v.entryList.GetRowAtIndex(entry.Index)
if row == nil {
Expand All @@ -356,9 +343,6 @@ func (v *spotsView) EntryUpdated(entry core.BandmapEntry) {
}

func (v *spotsView) EntryRemoved(entry core.BandmapEntry) {
if v == nil {
return
}
runAsync(func() {
row := v.entryList.GetRowAtIndex(entry.Index)
if row == nil {
Expand Down
Loading

0 comments on commit e15aa07

Please sign in to comment.