summaryrefslogtreecommitdiff
path: root/logbook
diff options
context:
space:
mode:
Diffstat (limited to 'logbook')
-rw-r--r--logbook/AD1CCty.cpp52
-rw-r--r--logbook/AD1CCty.hpp8
-rw-r--r--logbook/Multiplier.cpp44
-rw-r--r--logbook/Multiplier.hpp30
-rw-r--r--logbook/WorkedBefore.cpp20
-rw-r--r--logbook/WorkedBefore.hpp5
-rw-r--r--logbook/logbook.cpp97
-rw-r--r--logbook/logbook.h14
-rw-r--r--logbook/logbook.pri6
9 files changed, 231 insertions, 45 deletions
diff --git a/logbook/AD1CCty.cpp b/logbook/AD1CCty.cpp
index 58ed375f..23d34fb4 100644
--- a/logbook/AD1CCty.cpp
+++ b/logbook/AD1CCty.cpp
@@ -16,6 +16,7 @@
#include <QTextStream>
#include <QDebug>
#include <QDebugStateSaver>
+#include "Configuration.hpp"
#include "Radio.hpp"
#include "pimpl_impl.hpp"
@@ -155,14 +156,16 @@ typedef multi_index_container<
class AD1CCty::impl final
{
public:
- explicit impl ()
+ using entity_by_id = entities_type::index<id>::type;
+
+ explicit impl (Configuration const * configuration)
+ : configuration_ {configuration}
{
}
- Record fixup (QString call, prefix const& p) const
+ entity_by_id::iterator lookup_entity (QString call, prefix const& p) const
{
call = call.toUpper ();
- using entity_by_id = entities_type::index<id>::type;
entity_by_id::iterator e; // iterator into entity set
//
@@ -171,23 +174,26 @@ public:
if (call.startsWith ("KG4") && call.size () != 5 && call.size () != 3)
{
// KG4 2x1 and 2x3 calls that map to Gitmo are mainland US not Gitmo
- e = entities_.project<id> (entities_.get<primary_prefix> ().find ("K"));
+ return entities_.project<id> (entities_.get<primary_prefix> ().find ("K"));
}
else
{
- e = entities_.get<id> ().find (p.entity_id_);
+ return entities_.get<id> ().find (p.entity_id_);
}
-
+ }
+
+ Record fixup (prefix const& p, entity const& e) const
+ {
Record result;
- result.continent = e->continent_;
- result.CQ_zone = e->CQ_zone_;
- result.ITU_zone = e->ITU_zone_;
- result.entity_name = e->name_;
- result.WAE_only = e->WAE_only_;
- result.latitude = e->lat_;
- result.longtitude = e->long_;
- result.UTC_offset = e->UTC_offset_;
- result.primary_prefix = e->primary_prefix_;
+ result.continent = e.continent_;
+ result.CQ_zone = e.CQ_zone_;
+ result.ITU_zone = e.ITU_zone_;
+ result.entity_name = e.name_;
+ result.WAE_only = e.WAE_only_;
+ result.latitude = e.lat_;
+ result.longtitude = e.long_;
+ result.UTC_offset = e.UTC_offset_;
+ result.primary_prefix = e.primary_prefix_;
// check for overrides
bool ok1 {true}, ok2 {true}, ok3 {true}, ok4 {true}, ok5 {true};
@@ -220,6 +226,7 @@ public:
return false;
}
+ Configuration const * configuration_;
QString path_;
entities_type entities_;
prefixes_type prefixes_;
@@ -307,8 +314,13 @@ char const * AD1CCty::continent (Continent c)
}
}
-AD1CCty::AD1CCty ()
+AD1CCty::AD1CCty (Configuration const * configuration)
+ : m_ {configuration}
{
+ Q_ASSERT (configuration);
+ // TODO: G4WJS - consider doing the following asynchronously to
+ // speed up startup. Not urgent as it takes less than 1s on a Core
+ // i7 reading BIG CTY.DAT.
QDir dataPath {QStandardPaths::writableLocation (QStandardPaths::DataLocation)};
m_->path_ = dataPath.exists (file_name)
? dataPath.absoluteFilePath (file_name) // user override
@@ -389,7 +401,7 @@ auto AD1CCty::lookup (QString const& call) const -> Record
auto p = m_->prefixes_.find (exact_search);
if (p != m_->prefixes_.end () && p->exact_)
{
- return m_->fixup (call, *p);
+ return m_->fixup (*p, *m_->lookup_entity (call, *p));
}
}
while (search_prefix.size ())
@@ -397,9 +409,11 @@ auto AD1CCty::lookup (QString const& call) const -> Record
auto p = m_->prefixes_.find (search_prefix);
if (p != m_->prefixes_.end ())
{
- if (!p->exact_ || call.size () == search_prefix.size ())
+ impl::entity_by_id::iterator e = m_->lookup_entity (call, *p);
+ if ((m_->configuration_->include_WAE_entities () || !e->WAE_only_)
+ && (!p->exact_ || call.size () == search_prefix.size ()))
{
- return m_->fixup (call, *p);
+ return m_->fixup (*p, *e);
}
}
search_prefix = search_prefix.left (search_prefix.size () - 1);
diff --git a/logbook/AD1CCty.hpp b/logbook/AD1CCty.hpp
index 37cada3e..4a485afa 100644
--- a/logbook/AD1CCty.hpp
+++ b/logbook/AD1CCty.hpp
@@ -1,17 +1,19 @@
#ifndef AD1C_CTY_HPP_
#define AD1C_CTY_HPP_
-#include <boost/core/noncopyable.hpp>
#include <QObject>
+#include <QDebug>
#include "pimpl_h.hpp"
+class QString;
+class Configuration;
+
//
// AD1CCty - Fast access database of Jim Reisert, AD1C's, cty.dat
// entity and entity override information file.
//
class AD1CCty final
: public QObject
- , private boost::noncopyable
{
Q_OBJECT
@@ -39,7 +41,7 @@ public:
QString primary_prefix;
};
- explicit AD1CCty ();
+ explicit AD1CCty (Configuration const *);
~AD1CCty ();
Record lookup (QString const& call) const;
diff --git a/logbook/Multiplier.cpp b/logbook/Multiplier.cpp
new file mode 100644
index 00000000..6323e4fe
--- /dev/null
+++ b/logbook/Multiplier.cpp
@@ -0,0 +1,44 @@
+#include "Multiplier.hpp"
+
+#include <QSet>
+#include <QString>
+#include <QDebug>
+#include "models/CabrilloLog.hpp"
+#include "pimpl_impl.hpp"
+
+class Multiplier::impl
+{
+public:
+ impl (AD1CCty const * countries)
+ : countries_ {countries}
+ {
+ }
+
+ AD1CCty const * countries_;
+ worked_set entities_worked_;
+ worked_set grids_worked_;
+};
+
+Multiplier::Multiplier (AD1CCty const * countries)
+ : m_ {countries}
+{
+}
+
+Multiplier::~Multiplier ()
+{
+}
+
+void Multiplier::reload (CabrilloLog const * log)
+{
+ m_->entities_worked_ = log->unique_DXCC_entities (m_->countries_);
+}
+
+auto Multiplier::entities_worked () const -> worked_set const&
+{
+ return m_->entities_worked_;
+}
+
+auto Multiplier::grids_worked () const -> worked_set const&
+{
+ return m_->grids_worked_;
+}
diff --git a/logbook/Multiplier.hpp b/logbook/Multiplier.hpp
new file mode 100644
index 00000000..2271dd77
--- /dev/null
+++ b/logbook/Multiplier.hpp
@@ -0,0 +1,30 @@
+#ifndef MULTIPLIER_HPP_
+#define MULTIPLIER_HPP_
+
+#include <boost/core/noncopyable.hpp>
+#include <QSet>
+#include "pimpl_h.hpp"
+
+class QString;
+class AD1CCty;
+class CabrilloLog;
+
+class Multiplier final
+ : private boost::noncopyable
+{
+public:
+ using worked_item = QPair<QString, QString>;
+ using worked_set = QSet<worked_item>;
+
+ explicit Multiplier (AD1CCty const *);
+ ~Multiplier ();
+ void reload (CabrilloLog const *);
+ worked_set const& entities_worked () const;
+ worked_set const& grids_worked () const;
+
+private:
+ class impl;
+ pimpl<impl> m_;
+};
+
+#endif
diff --git a/logbook/WorkedBefore.cpp b/logbook/WorkedBefore.cpp
index daaf18fc..aa65ab65 100644
--- a/logbook/WorkedBefore.cpp
+++ b/logbook/WorkedBefore.cpp
@@ -18,7 +18,7 @@
#include <QFileInfo>
#include <QFile>
#include <QTextStream>
-
+#include "Configuration.hpp"
#include "qt_helpers.hpp"
#include "pimpl_impl.hpp"
@@ -332,10 +332,15 @@ namespace
// will parse a record
{
auto const& entity = prefixes->lookup (call);
+ auto mode = extractField (record, "MODE").toUpper ();
+ if (!mode.size () || "MFSK" == mode)
+ {
+ mode = extractField (record, "SUBMODE").toUpper ();
+ }
worked.emplace (call.toUpper ()
, extractField (record, "GRIDSQUARE").left (4).toUpper () // not interested in 6-digit grids
, extractField (record, "BAND").toUpper ()
- , extractField (record, "MODE").toUpper ()
+ , mode
, entity.entity_name
, entity.continent
, entity.CQ_zone
@@ -356,8 +361,9 @@ namespace
class WorkedBefore::impl final
{
public:
- impl ()
+ impl (Configuration const * configuration)
: path_ {QDir {QStandardPaths::writableLocation (QStandardPaths::DataLocation)}.absoluteFilePath (logFileName)}
+ , prefixes_ {configuration}
{
}
@@ -374,8 +380,10 @@ public:
worked_before_database_type worked_;
};
-WorkedBefore::WorkedBefore ()
+WorkedBefore::WorkedBefore (Configuration const * configuration)
+ : m_ {configuration}
{
+ Q_ASSERT (configuration);
connect (&m_->loader_watcher_, &QFutureWatcher<worked_before_database_type>::finished, [this] () {
QString error;
size_t n {0};
@@ -407,9 +415,9 @@ QString const& WorkedBefore::path () const
return m_->path_;
}
-AD1CCty const& WorkedBefore::countries () const
+AD1CCty const * WorkedBefore::countries () const
{
- return m_->prefixes_;
+ return &m_->prefixes_;
}
bool WorkedBefore::add (QString const& call
diff --git a/logbook/WorkedBefore.hpp b/logbook/WorkedBefore.hpp
index 90a31813..1aae1aca 100644
--- a/logbook/WorkedBefore.hpp
+++ b/logbook/WorkedBefore.hpp
@@ -5,6 +5,7 @@
#include "AD1CCty.hpp"
#include "pimpl_h.hpp"
+class Configuration;
class CountryDat;
class QString;
class QByteArray;
@@ -17,7 +18,7 @@ class WorkedBefore final
public:
using Continent = AD1CCty::Continent;
- explicit WorkedBefore ();
+ explicit WorkedBefore (Configuration const *);
~WorkedBefore ();
Q_SLOT void reload ();
@@ -28,7 +29,7 @@ public:
, QByteArray const& ADIF_record);
QString const& path () const;
- AD1CCty const& countries () const;
+ AD1CCty const * countries () const;
bool country_worked (QString const& call, QString const& mode, QString const& band) const;
bool grid_worked (QString const& grid, QString const& mode, QString const& band) const;
bool call_worked (QString const& call, QString const& mode, QString const& band) const;
diff --git a/logbook/logbook.cpp b/logbook/logbook.cpp
index b84b65c1..a154664d 100644
--- a/logbook/logbook.cpp
+++ b/logbook/logbook.cpp
@@ -3,15 +3,25 @@
#include <QDateTime>
#include "Configuration.hpp"
#include "AD1CCty.hpp"
+#include "Multiplier.hpp"
+#include "logbook/AD1CCty.hpp"
+#include "models/CabrilloLog.hpp"
+#include "models/FoxLog.hpp"
#include "moc_logbook.cpp"
LogBook::LogBook (Configuration const * configuration)
: config_ {configuration}
+ , worked_before_ {configuration}
{
+ Q_ASSERT (configuration);
connect (&worked_before_, &WorkedBefore::finished_loading, this, &LogBook::finished_loading);
}
+LogBook::~LogBook ()
+{
+}
+
void LogBook::match (QString const& call, QString const& mode, QString const& grid,
AD1CCty::Record const& looked_up,
bool& callB4,
@@ -69,7 +79,14 @@ QByteArray LogBook::QSOToADIF (QString const& hisCall, QString const& hisGrid, Q
QString t;
t = "<call:" + QString::number(hisCall.length()) + ">" + hisCall;
t += " <gridsquare:" + QString::number(hisGrid.length()) + ">" + hisGrid;
- t += " <mode:" + QString::number(mode.length()) + ">" + mode;
+ if (mode != "FT4")
+ {
+ t += " <mode:" + QString::number(mode.length()) + ">" + mode;
+ }
+ else
+ {
+ t += " <mode:4>MFSK <submode:" + QString::number(mode.length()) + ">" + mode;
+ }
t += " <rst_sent:" + QString::number(rptSent.length()) + ">" + rptSent;
t += " <rst_rcvd:" + QString::number(rptRcvd.length()) + ">" + rptRcvd;
t += " <qso_date:8>" + dateTimeOn.date().toString("yyyyMMdd");
@@ -89,24 +106,80 @@ QByteArray LogBook::QSOToADIF (QString const& hisCall, QString const& hisGrid, Q
auto words = xSent.split (' ', QString::SkipEmptyParts);
if (words.size () > 1)
{
- bool ok;
- auto sn = words.back ().toUInt (&ok);
- if (ok && sn)
+ if (words.back ().toUInt ())
{
// assume last word is a serial if there are at least
// two words and if it is positive numeric
- t += " <STX:" + QString::number (words.back ().size ()) + '>' + words.back ();
+ t += " <stx:" + QString::number (words.back ().size ()) + '>' + words.back ();
+ }
+ else
+ {
+ if (words.front ().toUInt () && words.front ().size () > 3) // EU VHF contest mode
+ {
+ auto sn_text = words.front ().mid (2);
+ // assume first word is report+serial if there are
+ // at least two words and if the first word less the
+ // first two characters is a positive numeric
+ t += " <stx:" + QString::number (sn_text.size ()) + '>' + sn_text;
+ }
}
}
}
if (xRcvd.size ()) {
- QString t1="";
- if(xRcvd.split(" ").size()==2) t1=xRcvd.split(" ").at(1);
- if(t1.toInt()>0) {
- t += " <SRX:" + QString::number(t1.length()) + ">" + t1;
- } else {
- t += " <STATE:" + QString::number(t1.length()) + ">" + t1;
- }
+ auto words = xRcvd.split (' ', QString::SkipEmptyParts);
+ if (words.size () == 2)
+ {
+ if (words.at (1).toUInt ())
+ {
+ t += " <srx:" + QString::number (words.at (1).length ()) + ">" + words.at (1);
+ }
+ else if (words.at (0).toUInt () && words.at (0).size () > 3) // EU VHF contest exchange
+ {
+ // strip report and set SRX to serial
+ t += " <srx:" + QString::number (words.at (0).mid (2).length ()) + ">" + words.at (0).mid (2);
+ }
+ else
+ {
+ t += " <state:" + QString::number (words.at (1).length ()) + ">" + words.at (1);
+ }
+ }
}
return t.toLatin1();
}
+
+CabrilloLog * LogBook::contest_log ()
+{
+ // lazy create of Cabrillo log object instance
+ if (!contest_log_)
+ {
+ contest_log_.reset (new CabrilloLog {config_});
+ if (!multiplier_)
+ {
+ multiplier_.reset (new Multiplier {countries ()});
+ }
+ connect (contest_log_.data (), &CabrilloLog::data_changed, [this] () {
+ multiplier_->reload (contest_log_.data ());
+ });
+ }
+ return contest_log_.data ();
+}
+
+Multiplier const * LogBook::multiplier () const
+{
+ // lazy create of Multiplier object instance
+ if (!multiplier_)
+ {
+ multiplier_.reset (new Multiplier {countries ()});
+ }
+ return multiplier_.data ();
+}
+
+FoxLog * LogBook::fox_log ()
+{
+ // lazy create of Fox log object instance
+ if (!fox_log_)
+ {
+ fox_log_.reset (new FoxLog {config_});
+ }
+ return fox_log_.data ();
+}
diff --git a/logbook/logbook.h b/logbook/logbook.h
index 1850aa01..c87009e4 100644
--- a/logbook/logbook.h
+++ b/logbook/logbook.h
@@ -8,12 +8,16 @@
#include <QObject>
#include <QString>
+#include <QScopedPointer>
#include "WorkedBefore.hpp"
class Configuration;
class QByteArray;
class QDateTime;
+class CabrilloLog;
+class Multiplier;
+class FoxLog;
class LogBook final
: public QObject
@@ -22,13 +26,14 @@ class LogBook final
public:
LogBook (Configuration const *);
+ ~LogBook ();
QString const& path () const {return worked_before_.path ();}
bool add (QString const& call
, QString const& grid
, QString const& band
, QString const& mode
, QByteArray const& ADIF_record);
- AD1CCty const& countries () const {return worked_before_.countries ();}
+ AD1CCty const * countries () const {return worked_before_.countries ();}
void rescan ();
void match (QString const& call, QString const& mode, QString const& grid,
AD1CCty::Record const&, bool& callB4, bool& countryB4,
@@ -43,9 +48,16 @@ public:
Q_SIGNAL void finished_loading (int worked_before_record_count, QString const& error) const;
+ CabrilloLog * contest_log ();
+ Multiplier const * multiplier () const;
+ FoxLog * fox_log ();
+
private:
Configuration const * config_;
WorkedBefore worked_before_;
+ QScopedPointer<CabrilloLog> contest_log_;
+ QScopedPointer<Multiplier> mutable multiplier_;
+ QScopedPointer<FoxLog> fox_log_;
};
#endif
diff --git a/logbook/logbook.pri b/logbook/logbook.pri
index fcac6252..e67cdebd 100644
--- a/logbook/logbook.pri
+++ b/logbook/logbook.pri
@@ -2,10 +2,12 @@ SOURCES += \
logbook/countriesworked.cpp \
logbook/logbook.cpp \
logbook/AD1CCty.cpp \
- logbook/WorkedBefore.cpp
+ logbook/WorkedBefore.cpp \
+ logbook/Multiplier.cpp
HEADERS += \
logbook/WorkedBefore.hpp \
logbook/logbook.h \
logbook/countriesworked.h \
- logbook/AD1CCty.hpp
+ logbook/AD1CCty.hpp \
+ logbook/Multiplier.hpp