Skip to content

Commit

Permalink
export contest data as call history
Browse files Browse the repository at this point in the history
  • Loading branch information
ftl committed Feb 13, 2022
1 parent 2760e9f commit ee4b679
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 8 deletions.
23 changes: 23 additions & 0 deletions core/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,29 @@ func (c *Controller) ExportCSV() {
}
}

func (c *Controller) ExportCallhistory() {
filename, ok, err := c.view.SelectSaveFile("Export Call History File", "*.txt")
if !ok {
return
}
if err != nil {
c.view.ShowErrorDialog("Cannot select a file: %v", err)
}

file, err := os.OpenFile(filename, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
if err != nil {
c.view.ShowErrorDialog("Cannot open file %s: %v", filename, err)
}
defer file.Close()

err = callhistory.Export(file, c.QSOList.All()...)
if err != nil {
c.view.ShowErrorDialog("Cannot export call history to %s: %v", filename, err)
return
}
c.openTextFile(filename)
}

func (c *Controller) ShowCallinfo() {
c.Callinfo.Show()
c.view.BringToFront()
Expand Down
30 changes: 30 additions & 0 deletions core/callhistory/callhistory.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package callhistory

import (
"fmt"
"io"
"log"
"os"
"sort"
"strings"

"github.com/ftl/hamradio/callsign"
"github.com/ftl/hamradio/scp"
Expand Down Expand Up @@ -157,3 +160,30 @@ func loadCallHistory(filename string) *scp.Database {
}
return result
}

func Export(w io.Writer, qsos ...core.QSO) error {
callsignToXchange := make(map[string]string)
for _, qso := range qsos {
if qso.TheirXchange == "" {
continue
}
callsignToXchange[qso.Callsign.String()] = strings.ToUpper(qso.TheirXchange)
}
entries := make([]string, 0, len(callsignToXchange))
for callsign, xchange := range callsignToXchange {
entries = append(entries, fmt.Sprintf("%s,%s", callsign, xchange))
}
sort.Strings(entries)

_, err := fmt.Fprintln(w, "!!Order!!,Call,Exch1\n# Call history created with Hello Contest\n# Enter some additional information here")
if err != nil {
return err
}
for _, entry := range entries {
_, err = fmt.Fprintln(w, entry)
if err != nil {
return err
}
}
return nil
}
8 changes: 8 additions & 0 deletions ui/glade/contest.glade
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,14 @@
<property name="use-underline">True</property>
</object>
</child>
<child>
<object class="GtkMenuItem" id="menuFileExportCallhistory">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Export Call _History...</property>
<property name="use-underline">True</property>
</object>
</child>
<child>
<object class="GtkSeparatorMenuItem" id="separatorFile2">
<property name="visible">True</property>
Expand Down
24 changes: 16 additions & 8 deletions ui/mainMenu.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type MainMenuController interface {
ExportCabrillo()
ExportADIF()
ExportCSV()
ExportCallhistory()
OpenSettings()
Quit()
ShowCallinfo()
Expand All @@ -30,14 +31,15 @@ type MainMenuController interface {
type mainMenu struct {
controller MainMenuController

fileNew *gtk.MenuItem
fileOpen *gtk.MenuItem
fileSaveAs *gtk.MenuItem
fileExportCabrillo *gtk.MenuItem
fileExportADIF *gtk.MenuItem
fileExportCSV *gtk.MenuItem
fileSettings *gtk.MenuItem
fileQuit *gtk.MenuItem
fileNew *gtk.MenuItem
fileOpen *gtk.MenuItem
fileSaveAs *gtk.MenuItem
fileExportCabrillo *gtk.MenuItem
fileExportADIF *gtk.MenuItem
fileExportCSV *gtk.MenuItem
fileExportCallhistory *gtk.MenuItem
fileSettings *gtk.MenuItem
fileQuit *gtk.MenuItem

editClearEntryFields *gtk.MenuItem
editGotoEntryFields *gtk.MenuItem
Expand All @@ -61,6 +63,7 @@ func setupMainMenu(builder *gtk.Builder) *mainMenu {
result.fileExportCabrillo = getUI(builder, "menuFileExportCabrillo").(*gtk.MenuItem)
result.fileExportADIF = getUI(builder, "menuFileExportADIF").(*gtk.MenuItem)
result.fileExportCSV = getUI(builder, "menuFileExportCSV").(*gtk.MenuItem)
result.fileExportCallhistory = getUI(builder, "menuFileExportCallhistory").(*gtk.MenuItem)
result.fileSettings = getUI(builder, "menuFileSettings").(*gtk.MenuItem)
result.fileQuit = getUI(builder, "menuFileQuit").(*gtk.MenuItem)
result.editClearEntryFields = getUI(builder, "menuEditClearEntryFields").(*gtk.MenuItem)
Expand All @@ -80,6 +83,7 @@ func setupMainMenu(builder *gtk.Builder) *mainMenu {
result.fileExportCabrillo.Connect("activate", result.onExportCabrillo)
result.fileExportADIF.Connect("activate", result.onExportADIF)
result.fileExportCSV.Connect("activate", result.onExportCSV)
result.fileExportCallhistory.Connect("activate", result.onExportCallhistory)
result.fileSettings.Connect("activate", result.onSettings)
result.fileQuit.Connect("activate", result.onQuit)
result.editClearEntryFields.Connect("activate", result.onClearEntryFields)
Expand Down Expand Up @@ -143,6 +147,10 @@ func (m *mainMenu) onExportCSV() {
m.controller.ExportCSV()
}

func (m *mainMenu) onExportCallhistory() {
m.controller.ExportCallhistory()
}

func (m *mainMenu) onSettings() {
m.controller.OpenSettings()
}
Expand Down

0 comments on commit ee4b679

Please sign in to comment.