summaryrefslogtreecommitdiff
path: root/logbook
diff options
context:
space:
mode:
authortony mancill <tmancill@debian.org>2023-09-03 19:46:43 -0700
committertony mancill <tmancill@debian.org>2023-09-03 19:46:43 -0700
commit393a486ee1d7e308a49f8e0b8c3a4b2f43223248 (patch)
tree6a6e8a56ace360795e1cf1a310d5652bb23f1386 /logbook
parent6a285ab382ebff18c88e52bec75dc1773ac33b74 (diff)
New upstream version 2.7.0~rc2+repackupstream/2.7.0_rc2+repack
Diffstat (limited to 'logbook')
-rwxr-xr-xlogbook/AD1CCty.cpp162
-rwxr-xr-xlogbook/AD1CCty.hpp3
-rwxr-xr-xlogbook/WorkedBefore.cpp16
-rwxr-xr-xlogbook/WorkedBefore.hpp3
-rwxr-xr-xlogbook/logbook.cpp5
-rwxr-xr-xlogbook/logbook.h4
6 files changed, 128 insertions, 65 deletions
diff --git a/logbook/AD1CCty.cpp b/logbook/AD1CCty.cpp
index 222a4b5a..e54b1a40 100755
--- a/logbook/AD1CCty.cpp
+++ b/logbook/AD1CCty.cpp
@@ -16,9 +16,11 @@
#include <QTextStream>
#include <QDebug>
#include <QDebugStateSaver>
+#include <QRegularExpression>
#include "Configuration.hpp"
#include "Radio.hpp"
#include "pimpl_impl.hpp"
+#include "Logger.hpp"
#include "moc_AD1CCty.cpp"
@@ -163,6 +165,9 @@ public:
{
}
+ QString get_cty_path(const Configuration *configuration);
+ void load_cty(QFile &file);
+
entity_by_id::iterator lookup_entity (QString call, prefix const& p) const
{
call = call.toUpper ();
@@ -228,6 +233,9 @@ public:
Configuration const * configuration_;
QString path_;
+ QString cty_version_;
+ QString cty_version_date_;
+
entities_type entities_;
prefixes_type prefixes_;
};
@@ -314,76 +322,104 @@ char const * AD1CCty::continent (Continent c)
}
}
-AD1CCty::AD1CCty (Configuration const * configuration)
- : m_ {configuration}
+QString AD1CCty::impl::get_cty_path(Configuration const * configuration)
{
- Q_ASSERT (configuration);
- // TODO: G4WJS - consider doing the following asynchronously to
- // speed up startup. Not urgent as it takes less than 0.5s 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
- : configuration->data_dir ().absoluteFilePath (file_name); // or original
- QFile file {m_->path_};
- if (file.open (QFile::ReadOnly))
+ auto path = dataPath.exists (file_name)
+ ? dataPath.absoluteFilePath (file_name) // user override
+ : configuration->data_dir ().absoluteFilePath (file_name); // or original
+ return path;
+}
+
+void AD1CCty::impl::load_cty(QFile &file)
+{
+ QRegularExpression version_pattern{R"(VER\d{8})"};
+ int entity_id = 0;
+ int line_number{0};
+
+ entities_.clear();
+ prefixes_.clear();
+ cty_version_ = QString{};
+ cty_version_date_ = QString{};
+
+ QTextStream in{&file};
+ while (!in.atEnd())
+ {
+ auto const &entity_line = in.readLine();
+ ++line_number;
+ if (!in.atEnd())
{
- int entity_id = 0;
- int line_number {0};
- QTextStream in {&file};
- while (!in.atEnd ())
+ auto const &entity_parts = entity_line.split(':');
+ if (entity_parts.size() >= 8)
+ {
+ auto primary_prefix = entity_parts[7].trimmed();
+ bool WAE_only{false};
+ if (primary_prefix.startsWith('*'))
{
- auto const& entity_line = in.readLine ();
+ primary_prefix = primary_prefix.mid(1);
+ WAE_only = true;
+ }
+ bool ok1, ok2, ok3, ok4, ok5;
+ entities_.emplace(++entity_id, entity_parts[0].trimmed(), WAE_only, entity_parts[1].trimmed().toInt(&ok1),
+ entity_parts[2].trimmed().toInt(&ok2), continent(entity_parts[3].trimmed()),
+ entity_parts[4].trimmed().toFloat(&ok3), entity_parts[5].trimmed().toFloat(&ok4),
+ static_cast<int> (entity_parts[6].trimmed().toFloat(&ok5) * 60 * 60), primary_prefix);
+ if (!(ok1 && ok2 && ok3 && ok4 && ok5))
+ {
+ throw std::domain_error{"Invalid number in cty.dat line " + boost::lexical_cast<std::string>(line_number)};
+ }
+ QString line;
+ QString detail;
+ do
+ {
+ in.readLineInto(&line);
++line_number;
- if (!in.atEnd ())
+ } while (detail += line, !detail.endsWith(';'));
+ for (auto prefix: detail.left(detail.size() - 1).split(','))
+ {
+ prefix = prefix.trimmed();
+ bool exact{false};
+ if (prefix.startsWith('='))
+ {
+ prefix = prefix.mid(1);
+ exact = true;
+ // match version pattern to prefix
+ if (version_pattern.match(prefix).hasMatch())
{
- auto const& entity_parts = entity_line.split (':');
- if (entity_parts.size () >= 8)
- {
- auto primary_prefix = entity_parts[7].trimmed ();
- bool WAE_only {false};
- if (primary_prefix.startsWith ('*'))
- {
- primary_prefix = primary_prefix.mid (1);
- WAE_only = true;
- }
- bool ok1, ok2, ok3, ok4, ok5;
- m_->entities_.emplace (++entity_id
- , entity_parts[0].trimmed ()
- , WAE_only
- , entity_parts[1].trimmed ().toInt (&ok1)
- , entity_parts[2].trimmed ().toInt (&ok2)
- , continent (entity_parts[3].trimmed ())
- , entity_parts[4].trimmed ().toFloat (&ok3)
- , entity_parts[5].trimmed ().toFloat (&ok4)
- , static_cast<int> (entity_parts[6].trimmed ().toFloat (&ok5) * 60 * 60)
- , primary_prefix);
- if (!(ok1 && ok2 && ok3 && ok4 && ok5))
- {
- throw std::domain_error {"Invalid number in cty.dat line " + boost::lexical_cast<std::string> (line_number)};
- }
- QString line;
- QString detail;
- do
- {
- in.readLineInto (&line);
- ++line_number;
- } while (detail += line, !detail.endsWith (';'));
- for (auto prefix : detail.left (detail.size () - 1).split (','))
- {
- prefix = prefix.trimmed ();
- bool exact {false};
- if (prefix.startsWith ('='))
- {
- prefix = prefix.mid (1);
- exact = true;
- }
- m_->prefixes_.emplace (prefix, exact, entity_id);
- }
- }
+ cty_version_date_ = prefix;
}
+ }
+ prefixes_.emplace(prefix, exact, entity_id);
}
+ }
}
+ }
+}
+
+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 0.5s on a Core
+ // i7 reading BIG CTY.DAT.
+ AD1CCty::reload (configuration);
+ }
+
+void AD1CCty::reload(Configuration const * configuration)
+{
+ m_->path_ = m_->impl::get_cty_path(configuration);
+ QFile file {m_->path_};
+
+ LOG_INFO(QString{"Loading CTY.DAT from %1"}.arg (m_->path_));
+
+ if (file.open (QFile::ReadOnly))
+ {
+ m_->impl::load_cty(file);
+ m_->cty_version_ = AD1CCty::lookup("VERSION").entity_name;
+ Q_EMIT cty_loaded(m_->cty_version_);
+ LOG_INFO(QString{"Loaded CTY.DAT version %1, %2"}.arg (m_->cty_version_date_).arg (m_->cty_version_));
+ }
}
AD1CCty::~AD1CCty ()
@@ -421,3 +457,7 @@ auto AD1CCty::lookup (QString const& call) const -> Record
}
return Record {};
}
+auto AD1CCty::version () const -> QString
+{
+ return m_->cty_version_date_;
+}
diff --git a/logbook/AD1CCty.hpp b/logbook/AD1CCty.hpp
index 9bc7529a..0908bb56 100755
--- a/logbook/AD1CCty.hpp
+++ b/logbook/AD1CCty.hpp
@@ -42,8 +42,11 @@ public:
};
explicit AD1CCty (Configuration const *);
+ void reload(Configuration const * configuration);
~AD1CCty ();
Record lookup (QString const& call) const;
+ QString version () const;
+ Q_SIGNAL void cty_loaded (QString const& version) const;
private:
class impl;
diff --git a/logbook/WorkedBefore.cpp b/logbook/WorkedBefore.cpp
index f60a4e72..0186bea5 100755
--- a/logbook/WorkedBefore.cpp
+++ b/logbook/WorkedBefore.cpp
@@ -23,6 +23,7 @@
#include <QDateTime>
#include "Configuration.hpp"
#include "revision_utils.hpp"
+#include "Logger.hpp"
#include "qt_helpers.hpp"
#include "pimpl_impl.hpp"
@@ -225,7 +226,7 @@ namespace
{
auto const logFileName = "wsjtx_log.adi";
- // Expception class suitable for using with QtConcurrent across
+ // Exception class suitable for using with QtConcurrent across
// thread boundaries
class LoaderException final
: public QException
@@ -374,6 +375,7 @@ public:
void reload ()
{
+ prefixes_.reload (configuration_);
async_loader_ = QtConcurrent::run (loader, path_, &prefixes_);
loader_watcher_.setFuture (async_loader_);
}
@@ -402,11 +404,18 @@ WorkedBefore::WorkedBefore (Configuration const * configuration)
{
error = e.error ();
}
- Q_EMIT finished_loading (n, error);
+ QString cty_ver = m_->prefixes_.version();
+ LOG_DEBUG(QString{"WorkedBefore::reload: CTY.DAT version %1"}.arg (cty_ver));
+ Q_EMIT finished_loading (n, cty_ver, error);
});
reload ();
}
+QString WorkedBefore::cty_version () const
+{
+ return m_->prefixes_.version ();
+}
+
void WorkedBefore::reload ()
{
m_->reload ();
@@ -668,6 +677,7 @@ bool WorkedBefore::CQ_zone_worked (int CQ_zone, QString const& mode, QString con
}
}
+
bool WorkedBefore::ITU_zone_worked (int ITU_zone, QString const& mode, QString const& band) const
{
if (mode.size ())
@@ -699,3 +709,5 @@ bool WorkedBefore::ITU_zone_worked (int ITU_zone, QString const& mode, QString c
}
}
}
+
+
diff --git a/logbook/WorkedBefore.hpp b/logbook/WorkedBefore.hpp
index 59adc91b..c1302f06 100755
--- a/logbook/WorkedBefore.hpp
+++ b/logbook/WorkedBefore.hpp
@@ -36,8 +36,9 @@ public:
bool continent_worked (Continent continent, QString const& mode, QString const& band) const;
bool CQ_zone_worked (int CQ_zone, QString const& mode, QString const& band) const;
bool ITU_zone_worked (int ITU_zone, QString const& mode, QString const& band) const;
+ QString cty_version () const;
- Q_SIGNAL void finished_loading (int worked_before_record_count, QString const& error) const;
+ Q_SIGNAL void finished_loading (int worked_before_record_count, QString const, QString const& error) const;
private:
class impl;
diff --git a/logbook/logbook.cpp b/logbook/logbook.cpp
index 8ba47e8f..bc825a8f 100755
--- a/logbook/logbook.cpp
+++ b/logbook/logbook.cpp
@@ -69,6 +69,11 @@ void LogBook::rescan ()
worked_before_.reload ();
}
+QString const LogBook::cty_version() const
+{
+ return worked_before_.cty_version();
+}
+
QByteArray LogBook::QSOToADIF (QString const& hisCall, QString const& hisGrid, QString const& mode,
QString const& rptSent, QString const& rptRcvd, QDateTime const& dateTimeOn,
QDateTime const& dateTimeOff, QString const& band, QString const& comments,
diff --git a/logbook/logbook.h b/logbook/logbook.h
index 6a515f48..74931d46 100755
--- a/logbook/logbook.h
+++ b/logbook/logbook.h
@@ -46,7 +46,9 @@ public:
QString const& m_myGrid, QString const& m_txPower, QString const& operator_call,
QString const& xSent, QString const& xRcvd, QString const& propmode);
- Q_SIGNAL void finished_loading (int worked_before_record_count, QString const& error) const;
+ QString const cty_version() const;
+
+ Q_SIGNAL void finished_loading (int worked_before_record_count, QString const cty_version, QString const& error) const;
CabrilloLog * contest_log ();
Multiplier const * multiplier () const;