2026-01-09 09:40:24 -05:00
|
|
|
/**
|
2026-01-17 15:24:43 -06:00
|
|
|
* @file LogBook.cpp
|
2026-01-09 09:40:24 -05:00
|
|
|
* @brief Implementation of LogBook class
|
|
|
|
|
*/
|
2026-01-17 15:24:43 -06:00
|
|
|
#include "LogBook.h"
|
2026-01-18 12:53:55 -06:00
|
|
|
|
2018-02-08 21:28:33 -05:00
|
|
|
#include <QDebug>
|
2026-01-18 12:53:55 -06:00
|
|
|
#include <QDir>
|
2018-02-08 21:28:33 -05:00
|
|
|
#include <QFontMetrics>
|
|
|
|
|
#include <QStandardPaths>
|
|
|
|
|
|
2026-01-18 12:53:55 -06:00
|
|
|
namespace {
|
|
|
|
|
auto logFileName = "js8call_log.adi";
|
|
|
|
|
auto countryFileName = "cty.dat";
|
|
|
|
|
} // namespace
|
2018-02-08 21:28:33 -05:00
|
|
|
|
2026-01-09 09:40:24 -05:00
|
|
|
/**
|
2026-01-18 12:53:55 -06:00
|
|
|
* @brief Initialize the logbook by loading country data and existing log
|
|
|
|
|
* entries.
|
2026-01-09 09:40:24 -05:00
|
|
|
*/
|
|
|
|
|
|
2026-01-18 12:53:55 -06:00
|
|
|
void LogBook::init() {
|
|
|
|
|
QDir dataPath{
|
|
|
|
|
QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)};
|
|
|
|
|
QString countryDataFilename;
|
|
|
|
|
if (dataPath.exists(countryFileName)) {
|
|
|
|
|
// User override
|
|
|
|
|
countryDataFilename = dataPath.absoluteFilePath(countryFileName);
|
|
|
|
|
} else {
|
|
|
|
|
countryDataFilename = QString{":/"} + countryFileName;
|
2018-02-08 21:28:33 -05:00
|
|
|
}
|
|
|
|
|
|
2026-01-18 12:53:55 -06:00
|
|
|
_countries.init(countryDataFilename);
|
|
|
|
|
_countries.load();
|
2018-02-08 21:28:33 -05:00
|
|
|
|
2026-01-18 12:53:55 -06:00
|
|
|
_worked.init(_countries.getCountryNames());
|
2018-02-08 21:28:33 -05:00
|
|
|
|
2026-01-18 12:53:55 -06:00
|
|
|
_log.init(dataPath.absoluteFilePath(logFileName));
|
|
|
|
|
_log.load();
|
2018-02-08 21:28:33 -05:00
|
|
|
|
2026-01-18 12:53:55 -06:00
|
|
|
_setAlreadyWorkedFromLog();
|
2018-02-08 21:28:33 -05:00
|
|
|
}
|
|
|
|
|
|
2026-01-09 09:40:24 -05:00
|
|
|
/**
|
|
|
|
|
* @brief Populate the CountriesWorked instance based on existing log entries.
|
|
|
|
|
*/
|
2026-01-18 12:53:55 -06:00
|
|
|
void LogBook::_setAlreadyWorkedFromLog() {
|
|
|
|
|
QList<QString> calls = _log.getCallList();
|
|
|
|
|
QString c;
|
|
|
|
|
foreach (c, calls) {
|
|
|
|
|
QString countryName = _countries.find(c);
|
|
|
|
|
if (countryName.length() > 0) {
|
|
|
|
|
_worked.setAsWorked(countryName);
|
2018-02-08 21:28:33 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-09 09:40:24 -05:00
|
|
|
/**
|
|
|
|
|
* @brief Check if a call has been worked before on a specific band.
|
|
|
|
|
* @param call The callsign to check.
|
|
|
|
|
* @param band The band to check.
|
2026-01-18 12:53:55 -06:00
|
|
|
* @return True if the call has been worked before on the specified band, false
|
|
|
|
|
* otherwise.
|
2026-01-09 09:40:24 -05:00
|
|
|
*/
|
2026-01-18 12:53:55 -06:00
|
|
|
bool LogBook::hasWorkedBefore(const QString &call, const QString &band) {
|
2018-11-30 17:02:14 -05:00
|
|
|
return _log.match(call, band);
|
2018-10-30 20:50:31 -04:00
|
|
|
}
|
|
|
|
|
|
2026-01-09 09:40:24 -05:00
|
|
|
/**
|
2026-01-18 12:53:55 -06:00
|
|
|
* @brief Match a callsign to its country and check if it has been worked
|
|
|
|
|
* before.
|
2026-01-09 09:40:24 -05:00
|
|
|
* @param call The callsign to match.
|
|
|
|
|
* @param countryName Output parameter to hold the matched country name.
|
2026-01-18 12:53:55 -06:00
|
|
|
* @param callWorkedBefore Output parameter indicating if the call has been
|
|
|
|
|
* worked before.
|
|
|
|
|
* @param countryWorkedBefore Output parameter indicating if the country has
|
|
|
|
|
* been worked before.
|
2026-01-09 09:40:24 -05:00
|
|
|
*/
|
2026-01-18 12:53:55 -06:00
|
|
|
void LogBook::match(/*in*/ const QString call,
|
|
|
|
|
/*out*/ QString &countryName, bool &callWorkedBefore,
|
|
|
|
|
bool &countryWorkedBefore) const {
|
|
|
|
|
if (call.isEmpty()) {
|
2019-03-10 23:48:56 -04:00
|
|
|
return;
|
|
|
|
|
}
|
2018-02-08 21:28:33 -05:00
|
|
|
|
2026-01-18 12:53:55 -06:00
|
|
|
QString currentBand = ""; // match any band
|
2019-03-10 23:48:56 -04:00
|
|
|
callWorkedBefore = _log.match(call, currentBand);
|
|
|
|
|
countryName = _countries.find(call);
|
|
|
|
|
|
2026-01-18 12:53:55 -06:00
|
|
|
if (countryName.length() > 0) { // country was found
|
2018-02-08 21:28:33 -05:00
|
|
|
countryWorkedBefore = _worked.getHasWorked(countryName);
|
2019-03-10 23:48:56 -04:00
|
|
|
} else {
|
2026-01-18 12:53:55 -06:00
|
|
|
countryName = "where?"; // error: prefix not found
|
2019-03-10 23:48:56 -04:00
|
|
|
countryWorkedBefore = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-09 09:40:24 -05:00
|
|
|
/**
|
|
|
|
|
* @brief Find details associated with a callsign in the logbook.
|
|
|
|
|
* @param call The callsign to search for.
|
|
|
|
|
* @param grid Output parameter to hold the grid locator.
|
|
|
|
|
* @param date Output parameter to hold the date of the QSO.
|
|
|
|
|
* @param name Output parameter to hold the name of the operator.
|
|
|
|
|
* @param comment Output parameter to hold any comments associated with the QSO.
|
|
|
|
|
* @return True if details were found, false otherwise.
|
|
|
|
|
*/
|
2019-03-10 23:48:56 -04:00
|
|
|
bool LogBook::findCallDetails(
|
2026-01-18 12:53:55 -06:00
|
|
|
/*in*/
|
|
|
|
|
const QString call,
|
|
|
|
|
/*out*/
|
|
|
|
|
QString &grid, QString &date, QString &name, QString &comment) const {
|
|
|
|
|
if (call.isEmpty()) {
|
2019-03-10 23:48:56 -04:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto qsos = _log.find(call);
|
2026-01-18 12:53:55 -06:00
|
|
|
if (qsos.isEmpty()) {
|
2019-03-10 23:48:56 -04:00
|
|
|
return false;
|
2018-02-08 21:28:33 -05:00
|
|
|
}
|
2019-03-10 23:48:56 -04:00
|
|
|
|
2026-01-18 12:53:55 -06:00
|
|
|
foreach (auto qso, qsos) {
|
|
|
|
|
if (grid.isEmpty() && !qso.grid.isEmpty())
|
|
|
|
|
grid = qso.grid;
|
|
|
|
|
if (date.isEmpty() && !qso.date.isEmpty())
|
|
|
|
|
date = qso.date;
|
|
|
|
|
if (name.isEmpty() && !qso.name.isEmpty())
|
|
|
|
|
name = qso.name;
|
|
|
|
|
if (comment.isEmpty() && !qso.comment.isEmpty())
|
|
|
|
|
comment = qso.comment;
|
2019-03-10 23:48:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
2018-02-08 21:28:33 -05:00
|
|
|
}
|
|
|
|
|
|
2026-01-09 09:40:24 -05:00
|
|
|
/**
|
|
|
|
|
* @brief Add a new QSO to the logbook and mark the country as worked.
|
|
|
|
|
* @param call The callsign of the contacted station.
|
|
|
|
|
* @param band The band on which the QSO was made.
|
|
|
|
|
* @param mode The mode of the QSO.
|
|
|
|
|
* @param submode The submode of the QSO.
|
|
|
|
|
* @param grid The grid locator of the contacted station.
|
|
|
|
|
* @param date The date of the QSO.
|
|
|
|
|
* @param name The name of the operator.
|
|
|
|
|
* @param comment Any comments associated with the QSO.
|
|
|
|
|
*/
|
2026-01-18 12:53:55 -06:00
|
|
|
void LogBook::addAsWorked(const QString call, const QString band,
|
|
|
|
|
const QString mode, const QString submode,
|
|
|
|
|
const QString grid, const QString date,
|
|
|
|
|
const QString name, const QString comment) {
|
|
|
|
|
_log.add(call, band, mode, submode, grid, date, name, comment);
|
|
|
|
|
QString countryName = _countries.find(call);
|
|
|
|
|
if (countryName.length() > 0)
|
|
|
|
|
_worked.setAsWorked(countryName);
|
2018-02-08 21:28:33 -05:00
|
|
|
}
|