Skip to content

Commit

Permalink
add option to open the upload URL after Cabrillo export
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Thienel <[email protected]>
  • Loading branch information
ftl committed Jan 1, 2025
1 parent 7231bfa commit cab624b
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 15 deletions.
9 changes: 6 additions & 3 deletions core/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ func (c *Controller) SaveAs() {

func (c *Controller) ExportCabrillo() {
var err error
export, openCabrilloFile, ok := c.ExportCabrilloController.Run(c.Settings, c.Score.Result(), c.QSOList.All())
result, ok := c.ExportCabrilloController.Run(c.Settings, c.Score.Result(), c.QSOList.All())
if !ok {
return
}
Expand All @@ -563,13 +563,16 @@ func (c *Controller) ExportCabrillo() {
}
defer file.Close()

err = cabrillo.Export(file, export)
err = cabrillo.Export(file, result.Export)
if err != nil {
c.view.ShowErrorDialog("Cannot export Cabrillo to %s: %v", filename, err)
return
}

if openCabrilloFile {
if result.OpenUploadAfterExport {
c.OpenContestUploadPage()
}
if result.OpenAfterExport {
c.openWithExternalApplication(filename)
}
}
Expand Down
25 changes: 20 additions & 5 deletions core/export/cabrillo/cabrillo.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type View interface {
SetCertificate(bool)
SetSoapBox(string)

SetOpenUploadAfterExport(bool)
SetOpenAfterExport(bool)
}

Expand All @@ -64,12 +65,21 @@ type Controller struct {
specific string
certificate bool
soapBox string
openAfterExport bool

openUploadAfterExport bool
openAfterExport bool
}

type Result struct {
Export *cabrillo.Log
OpenUploadAfterExport bool
OpenAfterExport bool
}

func NewController() *Controller {
result := &Controller{
openAfterExport: false,
openUploadAfterExport: false,
openAfterExport: false,
}

return result
Expand All @@ -86,7 +96,7 @@ func (c *Controller) SetView(view View) {
c.view = view
}

func (c *Controller) Run(settings core.Settings, claimedScore int, qsos []core.QSO) (*cabrillo.Log, bool, bool) {
func (c *Controller) Run(settings core.Settings, claimedScore int, qsos []core.QSO) (Result, bool) {
c.definition = settings.Contest().Definition
c.qsoBand, c.qsoMode = findBandAndMode(qsos)
c.category.Band = c.qsoBand
Expand All @@ -105,10 +115,11 @@ func (c *Controller) Run(settings core.Settings, claimedScore int, qsos []core.Q
c.view.SetSpecific(c.specific)
c.view.SetCertificate(c.certificate)
c.view.SetSoapBox(c.soapBox)
c.view.SetOpenUploadAfterExport(c.openUploadAfterExport)
c.view.SetOpenAfterExport(c.openAfterExport)
accepted := c.view.Show()
if !accepted {
return nil, false, false
return Result{nil, false, false}, false
}

export := createCabrilloLog(settings, claimedScore, qsos)
Expand All @@ -126,7 +137,7 @@ func (c *Controller) Run(settings core.Settings, claimedScore int, qsos []core.Q
export.Certificate = c.certificate
export.Soapbox = c.soapBox

return export, c.openAfterExport, true
return Result{export, c.openUploadAfterExport, c.openAfterExport}, true
}

func (c *Controller) Categories() []string {
Expand Down Expand Up @@ -401,6 +412,10 @@ func (c *Controller) SetSoapBox(soapBox string) {
c.soapBox = soapBox
}

func (c *Controller) SetOpenUploadAfterExport(open bool) {
c.openUploadAfterExport = open
}

func (c *Controller) SetOpenAfterExport(open bool) {
c.openAfterExport = open
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ go 1.22.3
require (
github.com/ftl/cabrillo v0.2.4
github.com/ftl/clusterix v0.1.0
github.com/ftl/conval v0.8.1
github.com/ftl/conval v0.8.2
github.com/ftl/gmtry v0.0.0-20201120192810-fa4a1b99fc04
github.com/ftl/godxmap v1.0.1
github.com/ftl/hamradio v0.2.12
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ github.com/ftl/cabrillo v0.2.4 h1:htBOjPCkZIOBf4CL2QypTEb83G7+z6/YF8rAP6vGdPk=
github.com/ftl/cabrillo v0.2.4/go.mod h1:yrVvhb4datmP7OTEfX6gpEsTP8QNpXH0LAoatwvsjCI=
github.com/ftl/clusterix v0.1.0 h1:+fbTybTvkVorx3B4zZ3DBiVbmLV0hhFpfDGW50Ss9cg=
github.com/ftl/clusterix v0.1.0/go.mod h1:N89RHOExeAbnWqoXs/MD76uackK2/9Dcu+FooVq1tKg=
github.com/ftl/conval v0.8.1 h1:V7wcoh25dt9OfhBnKmeJzKfjMWSLfRhpZLsKTvFdk6A=
github.com/ftl/conval v0.8.1/go.mod h1:McmMHWMs0y/rY1RVUoUB7GbeBxGDdVovfNXqHDOKhj4=
github.com/ftl/conval v0.8.2 h1:PDWC4EfpxDWQnPOp1lE371865BOYxW33YgtMZMXhR0E=
github.com/ftl/conval v0.8.2/go.mod h1:McmMHWMs0y/rY1RVUoUB7GbeBxGDdVovfNXqHDOKhj4=
github.com/ftl/gmtry v0.0.0-20201120192810-fa4a1b99fc04 h1:S7z3LXqDYk4avXKj+B2orGWquOo/A+1ZJbcUPx0duLo=
github.com/ftl/gmtry v0.0.0-20201120192810-fa4a1b99fc04/go.mod h1:AQpbHYBSPV1Bc1nqG8vv8BK3qxXMZIn32OQBi/4A7Sc=
github.com/ftl/godxmap v1.0.1 h1:VzzpC2TBTO3/NMHDeqNTpGhhFxHrTLfhycUq0edh4JE=
Expand Down
10 changes: 8 additions & 2 deletions ui/exportCabrilloDialog.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ type exportCabrilloDialog struct {
certificate bool
soapBox string

openAfterExport bool
openUploadAfterExport bool
openAfterExport bool
}

func setupExportCabrilloDialog(parent gtk.IWidget, controller ExportCabrilloController) *exportCabrilloDialog {
Expand Down Expand Up @@ -76,7 +77,8 @@ func (d *exportCabrilloDialog) Show() bool {
d.view.certificateCheckButton.SetActive(d.certificate)
buffer, _ := d.view.soapBoxEntry.GetBuffer()
buffer.SetText(d.soapBox)
// d.view.soapBoxEntry.SetBuffer(buffer)

d.view.openUploadAfterExportCheckButton.SetActive(d.openUploadAfterExport)
d.view.openAfterExportCheckButton.SetActive(d.openAfterExport)

dialog, _ := gtk.DialogNew()
Expand Down Expand Up @@ -248,6 +250,10 @@ func (d *exportCabrilloDialog) SetSoapBox(soapBox string) {
}
}

func (d *exportCabrilloDialog) SetOpenUploadAfterExport(open bool) {
d.openUploadAfterExport = open
}

func (d *exportCabrilloDialog) SetOpenAfterExport(open bool) {
d.openAfterExport = open
}
11 changes: 9 additions & 2 deletions ui/exportCabrilloView.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type ExportCabrilloController interface {
SetSpecific(string)
SetCertificate(bool)
SetSoapBox(string)
SetOpenUploadAfterExport(bool)
SetOpenAfterExport(bool)
}

Expand Down Expand Up @@ -71,7 +72,8 @@ type exportCabrilloView struct {
certificateCheckButton *gtk.CheckButton
soapBoxEntry *gtk.TextView

openAfterExportCheckButton *gtk.CheckButton
openUploadAfterExportCheckButton *gtk.CheckButton
openAfterExportCheckButton *gtk.CheckButton
}

func newExportCabrilloView(controller ExportCabrilloController) *exportCabrilloView {
Expand Down Expand Up @@ -148,7 +150,8 @@ func newExportCabrilloView(controller ExportCabrilloController) *exportCabrilloV

buildSeparator(result.root, 6, 1)

result.openAfterExportCheckButton = buildCheckButton(result.root, 7, "Open the file after export", result.onOpenAfterExportToggled)
result.openUploadAfterExportCheckButton = buildCheckButton(result.root, 7, "Open the upload URL after export", result.onOpenUploadAfterExportToggled)
result.openAfterExportCheckButton = buildCheckButton(result.root, 8, "Open the file after export", result.onOpenAfterExportToggled)

return result
}
Expand Down Expand Up @@ -253,6 +256,10 @@ func (v *exportCabrilloView) onSoapBoxChanged() {
v.controller.SetSoapBox(text)
}

func (v *exportCabrilloView) onOpenUploadAfterExportToggled() {
v.controller.SetOpenUploadAfterExport(v.openUploadAfterExportCheckButton.GetActive())
}

func (v *exportCabrilloView) onOpenAfterExportToggled() {
v.controller.SetOpenAfterExport(v.openAfterExportCheckButton.GetActive())
}

0 comments on commit cab624b

Please sign in to comment.