summaryrefslogtreecommitdiff
path: root/logbook/logbook.cpp
diff options
context:
space:
mode:
authorIain R. Learmonth <irl@debian.org>2015-10-18 18:51:00 +0100
committerIain R. Learmonth <irl@debian.org>2015-10-18 18:51:00 +0100
commitd63dd8d081a6fcd0715cd13f26df59fb831769d2 (patch)
treeb9c1f6245147a310aac3762630bad389bbb57335 /logbook/logbook.cpp
parentc720a3d55c5ec832c29cb7ce50b6fb4b70c55b11 (diff)
Imported Upstream version 1.5.0upstream/1.5.0
Diffstat (limited to 'logbook/logbook.cpp')
-rw-r--r--logbook/logbook.cpp99
1 files changed, 99 insertions, 0 deletions
diff --git a/logbook/logbook.cpp b/logbook/logbook.cpp
new file mode 100644
index 00000000..f074116b
--- /dev/null
+++ b/logbook/logbook.cpp
@@ -0,0 +1,99 @@
+#include "logbook.h"
+#include <QDebug>
+#include <QFontMetrics>
+#include <QStandardPaths>
+#include <QDir>
+
+namespace
+{
+ auto logFileName = "wsjtx_log.adi";
+ auto countryFileName = "cty.dat";
+}
+
+void LogBook::init()
+{
+ QDir dataPath {QStandardPaths::writableLocation (QStandardPaths::DataLocation)};
+ QString countryDataFilename;
+ if (dataPath.exists (countryFileName))
+ {
+ // User override
+ countryDataFilename = dataPath.absoluteFilePath (countryFileName);
+ }
+ else
+ {
+ countryDataFilename = QString {":/"} + countryFileName;
+ }
+
+ _countries.init(countryDataFilename);
+ _countries.load();
+
+ _worked.init(_countries.getCountryNames());
+
+ _log.init(dataPath.absoluteFilePath (logFileName));
+ _log.load();
+
+ _setAlreadyWorkedFromLog();
+
+ /*
+ int QSOcount = _log.getCount();
+ int count = _worked.getWorkedCount();
+ qDebug() << QSOcount << "QSOs and" << count << "countries worked in file" << logFilename;
+ */
+
+ // QString call = "ok1ct";
+ // QString countryName;
+ // bool callWorkedBefore,countryWorkedBefore;
+ // match(/*in*/call, /*out*/ countryName,callWorkedBefore,countryWorkedBefore);
+ // qDebug() << countryName;
+
+}
+
+
+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);
+ //qDebug() << countryName << " worked " << c;
+ }
+ }
+}
+
+void LogBook::match(/*in*/const QString call,
+ /*out*/ QString &countryName,
+ bool &callWorkedBefore,
+ bool &countryWorkedBefore)
+{
+ if (call.length() > 0)
+ {
+ QString currentMode = "JT9"; // JT65 == JT9 in ADIF::match()
+ QString currentBand = ""; // match any band
+ callWorkedBefore = _log.match(call,currentBand,currentMode);
+ countryName = _countries.find(call);
+ if (countryName.length() > 0) // country was found
+ countryWorkedBefore = _worked.getHasWorked(countryName);
+ else
+ {
+ countryName = "where?"; //error: prefix not found
+ countryWorkedBefore = false;
+ }
+ }
+ //qDebug() << "Logbook:" << call << ":" << countryName << "Cty B4:" << countryWorkedBefore << "call B4:" << callWorkedBefore;
+}
+
+void LogBook::addAsWorked(const QString call, const QString band, const QString mode, const QString date)
+{
+ //qDebug() << "adding " << call << " as worked";
+ _log.add(call,band,mode,date);
+ QString countryName = _countries.find(call);
+ if (countryName.length() > 0)
+ _worked.setAsWorked(countryName);
+}
+
+
+