Skip to content

Commit

Permalink
let the user choose to open the file after export
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Thienel <[email protected]>
  • Loading branch information
ftl committed Dec 24, 2024
1 parent d341df8 commit 09e65cb
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 56 deletions.
53 changes: 26 additions & 27 deletions core/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,23 @@ type Controller struct {
callHistoryFinder *callhistory.Finder
hamDXMap *hamdxmap.HamDXMap

VFO *vfo.VFO
Logbook *logbook.Logbook
QSOList *logbook.QSOList
Entry *entry.Controller
Workmode *workmode.Controller
Radio *radio.Controller
Keyer *keyer.Keyer
Callinfo *callinfo.Callinfo
Score *score.Counter
Rate *rate.Counter
ServiceStatus *ServiceStatus
NewContestDialog *newcontest.Controller
ExportCabrilloDialog *cabrillo.Controller
Settings *settings.Settings
Bandmap *bandmap.Bandmap
Clusters *cluster.Clusters
Parrot *parrot.Parrot
VFO *vfo.VFO
Logbook *logbook.Logbook
QSOList *logbook.QSOList
Entry *entry.Controller
Workmode *workmode.Controller
Radio *radio.Controller
Keyer *keyer.Keyer
Callinfo *callinfo.Callinfo
Score *score.Counter
Rate *rate.Counter
ServiceStatus *ServiceStatus
NewContestController *newcontest.Controller
ExportCabrilloController *cabrillo.Controller
Settings *settings.Settings
Bandmap *bandmap.Bandmap
Clusters *cluster.Clusters
Parrot *parrot.Parrot
}

// View defines the visual functionality of the main application window.
Expand Down Expand Up @@ -147,8 +147,8 @@ func (c *Controller) Startup() {
c.configuration.Contest(),
)
c.callHistoryFinder.Notify(c.Settings)
c.NewContestDialog = newcontest.NewController(c.Settings, c.configuration.LogDirectory())
c.ExportCabrilloDialog = cabrillo.NewController()
c.NewContestController = newcontest.NewController(c.Settings, c.configuration.LogDirectory())
c.ExportCabrilloController = cabrillo.NewController()

c.bandplan = bandplan.IARURegion1 // TODO: make the bandplan configurable
c.dxccFinder = dxcc.New()
Expand Down Expand Up @@ -398,7 +398,7 @@ func proposeFilename(contestName, callsign string) string {

func (c *Controller) New() {
var err error
newContest, ok := c.NewContestDialog.Run()
newContest, ok := c.NewContestController.Run()
if !ok {
return
}
Expand Down Expand Up @@ -541,7 +541,7 @@ func (c *Controller) SaveAs() {

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

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

if openCabrilloFile {
c.openWithExternalApplication(filename)
}
}

func (c *Controller) ExportADIF() {
Expand Down
35 changes: 26 additions & 9 deletions core/export/cabrillo/cabrillo.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,20 @@ import (

type View interface {
Show() bool

SetOpenAfterExport(bool)
}

type Controller struct {
view View

openAfterExport bool
}

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

return result
}
Expand All @@ -37,22 +43,27 @@ func (c *Controller) SetView(view View) {
c.view = view
}

func (c *Controller) Run() bool {
func (c *Controller) Run(settings core.Settings, claimedScore int, qsos []core.QSO) (*cabrillo.Log, bool, bool) {
c.view.SetOpenAfterExport(c.openAfterExport)
accepted := c.view.Show()
if !accepted {
return false
return nil, false, false
}

return accepted
export := createCabrilloLog(settings, claimedScore, qsos)

return export, c.openAfterExport, true
}

// Export writes the given QSOs to the given writer in the Cabrillo format.
// The header is very limited and needs to be completed manually after the log was written.
func Export(w io.Writer, settings core.Settings, claimedScore int, qsos ...core.QSO) error {
func (c *Controller) SetOpenCabrilloFile(open bool) {
c.openAfterExport = open
}

func createCabrilloLog(settings core.Settings, claimedScore int, qsos []core.QSO) *cabrillo.Log {
export := cabrillo.NewLog()
export.Callsign = settings.Station().Callsign
export.CreatedBy = "Hello Contest"
export.Contest = cabrillo.ContestIdentifier(settings.Contest().Name)
export.Contest = cabrillo.ContestIdentifier(settings.Contest().Definition.Identifier)
export.Operators = []callsign.Callsign{settings.Station().Operator}
export.GridLocator = settings.Station().Locator
export.ClaimedScore = claimedScore
Expand All @@ -70,9 +81,15 @@ func Export(w io.Writer, settings core.Settings, claimedScore int, qsos ...core.
export.QSOData = qsoData
export.IgnoredQSOs = ignoredQSOs

return export
}

// Export writes the given QSOs to the given writer in the Cabrillo format.
// The header is very limited and needs to be completed manually after the log was written.
func Export(w io.Writer, export *cabrillo.Log) error {
return cabrillo.WriteWithTags(w, export, false, false, cabrillo.CreatedByTag, cabrillo.ContestTag,
cabrillo.CallsignTag, cabrillo.OperatorsTag, cabrillo.GridLocatorTag, cabrillo.ClaimedScoreTag,
cabrillo.Tag("SPECIFIC"), cabrillo.CategoryAssistedTag, cabrillo.CategoryBandTag, cabrillo.CategoryModeTag,
cabrillo.CategoryAssistedTag, cabrillo.CategoryBandTag, cabrillo.CategoryModeTag,
cabrillo.CategoryOperatorTag, cabrillo.CategoryPowerTag, cabrillo.ClubTag, cabrillo.NameTag,
cabrillo.EmailTag)
}
Expand Down
24 changes: 12 additions & 12 deletions core/export/cabrillo/cabrillo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,25 +88,25 @@ func TestExport(t *testing.T) {

expected := `START-OF-LOG: 3.0
CREATED-BY: Hello Contest
CONTEST:
CONTEST:
CALLSIGN: AA1ZZZ
OPERATORS: AA2ZZZ
GRID-LOCATOR: AA00aa
CLAIMED-SCORE: 123
SPECIFIC:
CATEGORY-ASSISTED:
CATEGORY-BAND:
CATEGORY-MODE:
CATEGORY-OPERATOR:
CATEGORY-POWER:
CLUB:
NAME:
EMAIL:
CATEGORY-ASSISTED:
CATEGORY-BAND:
CATEGORY-MODE:
CATEGORY-OPERATOR:
CATEGORY-POWER:
CLUB:
NAME:
EMAIL:
QSO: 7000 CW 2009-05-30 0002 AA1ZZZ 599 001 ABC S50A 589 004 DEF
END-OF-LOG:
END-OF-LOG:
`

Export(buffer, settings, 123, qso)
export := createCabrilloLog(settings, 123, []core.QSO{qso})
Export(buffer, export)

assert.Equal(t, expected, buffer.String())
}
Expand Down
8 changes: 4 additions & 4 deletions ui/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ func (a *application) activate() {
a.spotsWindow = setupSpotsWindow(a.windowGeometry, a.style, a.controller.Bandmap)
a.settingsDialog = setupSettingsDialog(a.mainWindow.window, a.controller.Settings)
a.keyerSettingsDialog = setupKeyerSettingsDialog(a.mainWindow.window, a.controller.Keyer)
a.newContestDialog = setupNewContestDialog(a.mainWindow.window, a.controller.NewContestDialog)
a.exportCabrilloDialog = setupExportCabrilloDialog(a.mainWindow.window, a.controller.ExportCabrillo)
a.newContestDialog = setupNewContestDialog(a.mainWindow.window, a.controller.NewContestController)
a.exportCabrilloDialog = setupExportCabrilloDialog(a.mainWindow.window, a.controller.ExportCabrilloController)

Check failure on line 99 in ui/app.go

View workflow job for this annotation

GitHub Actions / Build

cannot use a.controller.ExportCabrilloController (variable of type *"github.com/ftl/hellocontest/core/export/cabrillo".Controller) as ExportCabrilloController value in argument to setupExportCabrilloDialog: *"github.com/ftl/hellocontest/core/export/cabrillo".Controller does not implement ExportCabrilloController (missing method SetOpenAfterExport)

a.mainWindow.SetMainMenuController(a.controller)
a.mainWindow.SetRadioMenuController(a.controller)
Expand Down Expand Up @@ -125,8 +125,8 @@ func (a *application) activate() {
a.controller.Bandmap.SetView(a.spotsWindow)
a.controller.Settings.SetView(a.settingsDialog)
a.controller.Settings.Notify(a.mainWindow)
a.controller.NewContestDialog.SetView(a.newContestDialog)
a.controller.ExportCabrilloDialog.SetView(a.exportCabrilloDialog)
a.controller.NewContestController.SetView(a.newContestDialog)
a.controller.ExportCabrilloController.SetView(a.exportCabrilloDialog)
a.controller.Clusters.SetView(a.mainWindow)
a.controller.Parrot.SetView(a.mainWindow)

Expand Down
27 changes: 23 additions & 4 deletions ui/exportCabrilloDialog.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,39 @@ import (
type exportCabrilloDialog struct {
dialog *gtk.Dialog
parent gtk.IWidget

controller ExportCabrilloController
view *exportCabrilloView

openAfterExport bool
}

func setupExportCabrilloDialog(parent gtk.IWidget, controller ExportCabrilloController) *exportCabrilloDialog {
result := &exportCabrilloDialog{
parent: parent,
parent: parent,
controller: controller,
}
return result
}

func (d *exportCabrilloDialog) onDestroy() {
d.dialog = nil
d.view = nil
}

func (d *exportCabrilloDialog) Show() bool {
label, _ := gtk.LabelNew("Export the log as Cabrillo format.")

d.view = &exportCabrilloView{}
grid, _ := gtk.GridNew()
grid.SetOrientation(gtk.ORIENTATION_VERTICAL)
grid.Add(label)

label, _ := gtk.LabelNew("Export the log as Cabrillo format.")
grid.Attach(label, 0, 0, 2, 1)

d.view.openAfterExportCheckButton, _ = gtk.CheckButtonNewWithLabel("Open the file after export")
d.view.openAfterExportCheckButton.SetActive(d.openAfterExport)
grid.Attach(d.view.openAfterExportCheckButton, 0, 1, 2, 1)

d.view.setup(d.controller)

dialog, _ := gtk.DialogNew()
d.dialog = dialog
Expand All @@ -46,6 +60,11 @@ func (d *exportCabrilloDialog) Show() bool {
d.dialog.Close()
d.dialog.Destroy()
d.dialog = nil
d.view = nil

return result
}

func (d *exportCabrilloDialog) SetOpenAfterExport(open bool) {
d.openAfterExport = open
}
18 changes: 18 additions & 0 deletions ui/exportCabrilloView.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
package ui

import "github.com/gotk3/gotk3/gtk"

type ExportCabrilloController interface {
SetOpenAfterExport(bool)
}

type exportCabrilloView struct {
controller ExportCabrilloController

openAfterExportCheckButton *gtk.CheckButton
}

func (v *exportCabrilloView) setup(controller ExportCabrilloController) {
v.controller = controller
v.openAfterExportCheckButton.Connect("toggled", v.onOpenAfterExportToggled)
}

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

0 comments on commit 09e65cb

Please sign in to comment.