fix: Cabrillo contest

This commit is contained in:
2026-07-04 18:06:11 +02:00
parent ee9fb51066
commit fda21e5a6f
4 changed files with 43 additions and 33 deletions
+29 -13
View File
@@ -3712,7 +3712,7 @@ type CabrilloResult struct {
}
// cabrilloHeader fills the Cabrillo header from the active profile (callsign,
// operator, grid) plus the contest name the user supplied.
// operator, grid) plus the contest name (taken from the QSOs' ADIF CONTEST_ID).
func (a *App) cabrilloHeader(contest string) cabrillo.Header {
h := cabrillo.Header{Contest: contest}
if a.profiles != nil {
@@ -3727,8 +3727,9 @@ func (a *App) cabrilloHeader(contest string) cabrillo.Header {
}
// writeCabrillo collects the QSOs via the given iterator and writes a Cabrillo
// document to path.
func (a *App) writeCabrillo(path, contest string, iterate func(func(qso.QSO) error) error) (CabrilloResult, error) {
// document to path. The contest name is taken from the QSOs' ADIF CONTEST_ID
// (the most common one), so no separate prompt is needed.
func (a *App) writeCabrillo(path string, iterate func(func(qso.QSO) error) error) (CabrilloResult, error) {
if a.qso == nil {
return CabrilloResult{}, fmt.Errorf("db not initialized")
}
@@ -3736,9 +3737,24 @@ func (a *App) writeCabrillo(path, contest string, iterate func(func(qso.QSO) err
return CabrilloResult{}, fmt.Errorf("empty path")
}
var qsos []qso.QSO
if err := iterate(func(q qso.QSO) error { qsos = append(qsos, q); return nil }); err != nil {
contests := map[string]int{}
if err := iterate(func(q qso.QSO) error {
qsos = append(qsos, q)
if c := strings.TrimSpace(q.ContestID); c != "" {
contests[c]++
}
return nil
}); err != nil {
return CabrilloResult{}, err
}
// Pick the most-used CONTEST_ID across the exported QSOs.
contest := ""
best := 0
for c, n := range contests {
if n > best {
contest, best = c, n
}
}
f, err := os.Create(path)
if err != nil {
return CabrilloResult{}, err
@@ -3752,31 +3768,31 @@ func (a *App) writeCabrillo(path, contest string, iterate func(func(qso.QSO) err
}
// ExportCabrillo writes every QSO to a Cabrillo file.
func (a *App) ExportCabrillo(path, contest string) (CabrilloResult, error) {
return a.writeCabrillo(path, contest, func(fn func(qso.QSO) error) error { return a.qso.IterateAll(a.ctx, fn) })
func (a *App) ExportCabrillo(path string) (CabrilloResult, error) {
return a.writeCabrillo(path, func(fn func(qso.QSO) error) error { return a.qso.IterateAll(a.ctx, fn) })
}
// ExportCabrilloFiltered writes the QSOs matching the current filter.
func (a *App) ExportCabrilloFiltered(path, contest string, f qso.QueryFilter) (CabrilloResult, error) {
return a.writeCabrillo(path, contest, func(fn func(qso.QSO) error) error { return a.qso.IterateFiltered(a.ctx, f, fn) })
func (a *App) ExportCabrilloFiltered(path string, f qso.QueryFilter) (CabrilloResult, error) {
return a.writeCabrillo(path, func(fn func(qso.QSO) error) error { return a.qso.IterateFiltered(a.ctx, f, fn) })
}
// ExportCabrilloSelected writes only the highlighted QSOs.
func (a *App) ExportCabrilloSelected(path, contest string, ids []int64) (CabrilloResult, error) {
func (a *App) ExportCabrilloSelected(path string, ids []int64) (CabrilloResult, error) {
if len(ids) == 0 {
return CabrilloResult{}, fmt.Errorf("no QSOs selected")
}
return a.writeCabrillo(path, contest, func(fn func(qso.QSO) error) error { return a.qso.IterateByIDs(a.ctx, ids, fn) })
return a.writeCabrillo(path, func(fn func(qso.QSO) error) error { return a.qso.IterateByIDs(a.ctx, ids, fn) })
}
// SaveCabrilloFile opens a save dialog for a Cabrillo (.cbr / .log) file.
// SaveCabrilloFile opens a save dialog for a Cabrillo (.log) file.
func (a *App) SaveCabrilloFile() (string, error) {
suggested := "OpsLog_" + time.Now().UTC().Format("20060102_150405") + ".cbr"
suggested := "OpsLog_" + time.Now().UTC().Format("20060102_150405") + ".log"
return wruntime.SaveFileDialog(a.ctx, wruntime.SaveDialogOptions{
Title: "Export Cabrillo",
DefaultFilename: suggested,
Filters: []wruntime.FileFilter{
{DisplayName: "Cabrillo files (*.cbr, *.log)", Pattern: "*.cbr;*.log"},
{DisplayName: "Cabrillo log (*.log, *.cbr)", Pattern: "*.log;*.cbr"},
{DisplayName: "All files (*.*)", Pattern: "*.*"},
},
})