diff options
| author | hibby <d@vehibberd.com> | 2018-02-16 15:18:44 +0000 |
|---|---|---|
| committer | hibby <d@vehibberd.com> | 2018-02-16 15:18:44 +0000 |
| commit | 368f5331a7641772aa7e0cd1feea57d09a394a36 (patch) | |
| tree | b421ac60cc6eb726896ea268ea24e47fc4ce7c88 /logbook | |
| parent | 71c717edc92fa771c857b3c2e5ed65f523f68f90 (diff) | |
| parent | 37f727ac0746fd85504aa46c1f023c09b3eff33a (diff) | |
Update upstream source from tag 'upstream/1.8.0+repack'
Update to upstream version '1.8.0+repack'
with Debian dir a83ef78cb70a32d1211871fdc08f3ffa295e45a8
Diffstat (limited to 'logbook')
| -rw-r--r-- | logbook/adif.cpp | 140 | ||||
| -rw-r--r-- | logbook/adif.h | 23 | ||||
| -rw-r--r-- | logbook/countriesworked.cpp | 6 | ||||
| -rw-r--r-- | logbook/countriesworked.h | 16 | ||||
| -rw-r--r-- | logbook/countrydat.cpp | 55 | ||||
| -rw-r--r-- | logbook/countrydat.h | 27 | ||||
| -rw-r--r-- | logbook/logbook.cpp | 3 | ||||
| -rw-r--r-- | logbook/logbook.h | 2 |
8 files changed, 150 insertions, 122 deletions
diff --git a/logbook/adif.cpp b/logbook/adif.cpp index fb6b3bcd..fc1fdbeb 100644 --- a/logbook/adif.cpp +++ b/logbook/adif.cpp @@ -2,32 +2,33 @@ #include <QFile> #include <QTextStream> +#include <QDateTime> #include <QDebug> /* -<CALL:4>W1XT<BAND:3>20m<FREQ:6>14.076<GRIDSQUARE:4>DM33<MODE:4>JT65<RST_RCVD:3>-21<RST_SENT:3>-14<QSO_DATE:8>20110422<TIME_ON:4>0417<TIME_OFF:4>0424<TX_PWR:1>4<COMMENT:34>1st JT65A QSO. Him: mag loop 20W<STATION_CALLSIGN:6>VK3ACF<MY_GRIDSQUARE:6>qf22lb<eor> -<CALL:6>IK1SOW<BAND:3>20m<FREQ:6>14.076<GRIDSQUARE:4>JN35<MODE:4>JT65<RST_RCVD:3>-19<RST_SENT:3>-11<QSO_DATE:8>20110422<TIME_ON:4>0525<TIME_OFF:4>0533<TX_PWR:1>3<STATION_CALLSIGN:6>VK3ACF<MY_GRIDSQUARE:6>qf22lb<eor> +<CALL:4>W1XT<BAND:3>20m<FREQ:6>14.076<GRIDSQUARE:4>DM33<MODE:4>JT65<RST_RCVD:3>-21<RST_SENT:3>-14<QSO_DATE:8>20110422<TIME_ON:6>041712<TIME_OFF:6>042435<TX_PWR:1>4<COMMENT:34>1st JT65A QSO. Him: mag loop 20W<STATION_CALLSIGN:6>VK3ACF<MY_GRIDSQUARE:6>qf22lb<eor> +<CALL:6>IK1SOW<BAND:3>20m<FREQ:6>14.076<GRIDSQUARE:4>JN35<MODE:4>JT65<RST_RCVD:3>-19<RST_SENT:3>-11<QSO_DATE:8>20110422<TIME_ON:6>052501<TIME_OFF:6>053359<TX_PWR:1>3<STATION_CALLSIGN:6>VK3ACF<MY_GRIDSQUARE:6>qf22lb<eor> <CALL:6:S>W4ABC> ... */ -void ADIF::init(QString filename) +void ADIF::init(QString const& filename) { _filename = filename; _data.clear(); } -QString ADIF::_extractField(const QString line, const QString fieldName) +QString ADIF::extractField(QString const& record, QString const& fieldName) const { - int fieldNameIndex = line.indexOf(fieldName,0,Qt::CaseInsensitive); + int fieldNameIndex = record.indexOf (fieldName + ':', 0, Qt::CaseInsensitive); if (fieldNameIndex >=0) { - int closingBracketIndex = line.indexOf('>',fieldNameIndex); - int fieldLengthIndex = line.indexOf(':',fieldNameIndex); // find the size delimiter + int closingBracketIndex = record.indexOf('>',fieldNameIndex); + int fieldLengthIndex = record.indexOf(':',fieldNameIndex); // find the size delimiter int dataTypeIndex = -1; if (fieldLengthIndex >= 0) { - dataTypeIndex = line.indexOf(':',fieldLengthIndex+1); // check for a second : indicating there is a data type + dataTypeIndex = record.indexOf(':',fieldLengthIndex+1); // check for a second : indicating there is a data type if (dataTypeIndex > closingBracketIndex) dataTypeIndex = -1; // second : was found but it was beyond the closing > } @@ -37,11 +38,11 @@ QString ADIF::_extractField(const QString line, const QString fieldName) int fieldLengthCharCount = closingBracketIndex - fieldLengthIndex -1; if (dataTypeIndex >= 0) fieldLengthCharCount -= 2; // data type indicator is always a colon followed by a single character - QString fieldLengthString = line.mid(fieldLengthIndex+1,fieldLengthCharCount); + QString fieldLengthString = record.mid(fieldLengthIndex+1,fieldLengthCharCount); int fieldLength = fieldLengthString.toInt(); if (fieldLength > 0) { - QString field = line.mid(closingBracketIndex+1,fieldLength); + QString field = record.mid(closingBracketIndex+1,fieldLength); return field; } } @@ -57,36 +58,71 @@ void ADIF::load() QFile inputFile(_filename); if (inputFile.open(QIODevice::ReadOnly)) { - QTextStream in(&inputFile); - while ( !in.atEnd() ) + QTextStream in(&inputFile); + QString buffer; + bool pre_read {false}; + int end_position {-1}; + + // skip optional header record + do + { + buffer += in.readLine () + '\n'; + if (buffer.startsWith (QChar {'<'})) // denotes no header + { + pre_read = true; + } + else + { + end_position = buffer.indexOf ("<EOH>", 0, Qt::CaseInsensitive); + } + } + while (!in.atEnd () && !pre_read && end_position < 0); + if (!pre_read) // found header { - QString line = in.readLine(); - QSO q; - q.call = _extractField(line,"CALL:"); - q.band = _extractField(line,"BAND:"); - q.mode = _extractField(line,"MODE:"); - q.date = _extractField(line,"QSO_DATE:"); - if (q.call != "") - _data.insert(q.call,q); + buffer.remove (0, end_position + 5); } - inputFile.close(); + while (buffer.size () || !in.atEnd ()) + { + do + { + end_position = buffer.indexOf ("<EOR>", 0, Qt::CaseInsensitive); + if (!in.atEnd () && end_position < 0) + { + buffer += in.readLine () + '\n'; + } + } + while (!in.atEnd () && end_position < 0); + int record_length {end_position >= 0 ? end_position + 5 : -1}; + auto record = buffer.left (record_length).trimmed (); + auto next_record = buffer.indexOf (QChar {'<'}, record_length); + buffer.remove (0, next_record >=0 ? next_record : buffer.size ()); + record = record.mid (record.indexOf (QChar {'<'})); + add (extractField (record, "CALL") + , extractField (record, "BAND") + , extractField (record, "MODE") + , extractField (record, "QSO_DATE")); + } + inputFile.close (); } } -void ADIF::add(const QString call, const QString band, const QString mode, const QString date) +void ADIF::add(QString const& call, QString const& band, QString const& mode, QString const& date) { QSO q; q.call = call; q.band = band; q.mode = mode; q.date = date; - _data.insert(q.call,q); - //qDebug() << "Added as worked:" << call << band << mode << date; + if (q.call.size ()) + { + _data.insert(q.call,q); + // qDebug() << "Added as worked:" << call << band << mode << date; + } } // return true if in the log same band and mode (where JT65 == JT9) -bool ADIF::match(const QString call, const QString band, const QString mode) +bool ADIF::match(QString const& call, QString const& band, QString const& mode) const { QList<QSO> qsos = _data.values(call); if (qsos.size()>0) @@ -100,9 +136,13 @@ bool ADIF::match(const QString call, const QString band, const QString mode) { if ( ( - ((mode.compare("JT65",Qt::CaseInsensitive)==0) || (mode.compare("JT9",Qt::CaseInsensitive)==0)) + ((mode.compare("JT65",Qt::CaseInsensitive)==0) || + (mode.compare("JT9",Qt::CaseInsensitive)==0) || + (mode.compare("FT8",Qt::CaseInsensitive)==0)) && - ((q.mode.compare("JT65",Qt::CaseInsensitive)==0) || (q.mode.compare("JT9",Qt::CaseInsensitive)==0)) + ((q.mode.compare("JT65",Qt::CaseInsensitive)==0) || + (q.mode.compare("JT9",Qt::CaseInsensitive)==0) || + (q.mode.compare("FT8",Qt::CaseInsensitive)==0)) ) || (mode.compare(q.mode,Qt::CaseInsensitive)==0) || (mode=="") @@ -115,7 +155,7 @@ bool ADIF::match(const QString call, const QString band, const QString mode) return false; } -QList<QString> ADIF::getCallList() +QList<QString> ADIF::getCallList() const { QList<QString> p; QMultiHash<QString,QSO>::const_iterator i = _data.constBegin(); @@ -127,15 +167,15 @@ QList<QString> ADIF::getCallList() return p; } -int ADIF::getCount() +int ADIF::getCount() const { return _data.size(); } // open ADIF file and append the QSO details. Return true on success -bool ADIF::addQSOToFile(const QString hisCall, const QString hisGrid, const QString mode, const QString rptSent, const QString rptRcvd, const QString date, const QString time, const QString band, - const QString comments, const QString name, const QString strDialFreq, const QString m_myCall, const QString m_myGrid, const QString m_txPower) +bool ADIF::addQSOToFile(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, QString const& name, QString const& strDialFreq, QString const& m_myCall, QString const& m_myGrid, QString const& m_txPower) { QFile f2(_filename); if (!f2.open(QIODevice::Text | QIODevice::Append)) @@ -152,8 +192,10 @@ bool ADIF::addQSOToFile(const QString hisCall, const QString hisGrid, const QStr t+=" <mode:" + 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>" + date; - t+=" <time_on:4>" + time; + t+=" <qso_date:8>" + dateTimeOn.date ().toString ("yyyyMMdd"); + t+=" <time_on:6>" + dateTimeOn.time ().toString ("hhmmss"); + t+=" <qso_date_off:8>" + dateTimeOff.date ().toString ("yyyyMMdd"); + t+=" <time_off:6>" + dateTimeOff.time ().toString ("hhmmss"); t+=" <band:" + QString::number(band.length()) + ">" + band; t+=" <freq:" + QString::number(strDialFreq.length()) + ">" + strDialFreq; t+=" <station_callsign:" + QString::number(m_myCall.length()) + ">" + @@ -172,35 +214,3 @@ bool ADIF::addQSOToFile(const QString hisCall, const QString hisGrid, const QStr } return true; } - -QString ADIF::bandFromFrequency(double dialFreq) -{ - QString band=""; - if(dialFreq>0.135 and dialFreq<0.139) band="2200m"; - else if(dialFreq>0.45 and dialFreq<0.55) band="630m"; - else if(dialFreq>1.8 and dialFreq<2.0) band="160m"; - else if(dialFreq>3.5 and dialFreq<4.0) band="80m"; - else if(dialFreq>5.1 and dialFreq<5.45) band="60m"; - else if(dialFreq>7.0 and dialFreq<7.3) band="40m"; - else if(dialFreq>10.0 and dialFreq<10.15) band="30m"; - else if(dialFreq>14.0 and dialFreq<14.35) band="20m"; - else if(dialFreq>18.068 and dialFreq<18.168) band="17m"; - else if(dialFreq>21.0 and dialFreq<21.45) band="15m"; - else if(dialFreq>24.890 and dialFreq<24.990) band="12m"; - else if(dialFreq>28.0 and dialFreq<29.7) band="10m"; - else if(dialFreq>50.0 and dialFreq<54.0) band="6m"; - else if(dialFreq>70.0 and dialFreq<71.0) band="4m"; - else if(dialFreq>144.0 and dialFreq<148.0) band="2m"; - else if(dialFreq>222.0 and dialFreq<225.0) band="1.25m"; - else if(dialFreq>420.0 and dialFreq<450.0) band="70cm"; - else if(dialFreq>902.0 and dialFreq<928.0) band="33cm"; - else if(dialFreq>1240.0 and dialFreq<1300.0) band="23cm"; - else if(dialFreq>2300.0 and dialFreq<2450.0) band="13cm"; - else if(dialFreq>3300.0 and dialFreq<3500.0) band="9cm"; - else if(dialFreq>5650.0 and dialFreq<5925.0) band="6cm"; - else if(dialFreq>10000.0 and dialFreq<10500.0) band="3cm"; - else if(dialFreq>24000.0 and dialFreq<24250.0) band="1.25cm"; - else if(dialFreq>47000.0 and dialFreq<47200.0) band="6mm"; - else if(dialFreq>75500.0 and dialFreq<81000.0) band="4mm"; - return band; -} diff --git a/logbook/adif.h b/logbook/adif.h index 7445d4aa..e4772055 100644 --- a/logbook/adif.h +++ b/logbook/adif.h @@ -16,22 +16,21 @@ #include <QtGui> #endif +class QDateTime; class ADIF { public: - void init(QString filename); - void load(); - void add(const QString call, const QString band, const QString mode, const QString date); - bool match(const QString call, const QString band, const QString mode); - QList<QString> getCallList(); - int getCount(); + void init(QString const& filename); + void load(); + void add(QString const& call, QString const& band, QString const& mode, QString const& date); + bool match(QString const& call, QString const& band, QString const& mode) const; + QList<QString> getCallList() const; + int getCount() const; // open ADIF file and append the QSO details. Return true on success - bool addQSOToFile(const QString hisCall, const QString hisGrid, const QString mode, const QString rptSent, const QString rptRcvd, const QString date, const QString time, const QString band, - const QString comments, const QString name, const QString strDialFreq, const QString m_myCall, const QString m_myGrid, const QString m_txPower); - - static QString bandFromFrequency(double dialFreq); + bool addQSOToFile(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, QString const& name, QString const& strDialFreq, QString const& m_myCall, QString const& m_myGrid, QString const& m_txPower); private: struct QSO @@ -39,10 +38,10 @@ class ADIF QString call,band,mode,date; }; - QMultiHash<QString, QSO> _data; + QMultiHash<QString, QSO> _data; QString _filename; - QString _extractField(const QString line, const QString fieldName); + QString extractField(QString const& line, QString const& fieldName) const; }; diff --git a/logbook/countriesworked.cpp b/logbook/countriesworked.cpp index a70a4e1a..6a991f8a 100644 --- a/logbook/countriesworked.cpp +++ b/logbook/countriesworked.cpp @@ -13,7 +13,7 @@ void CountriesWorked::setAsWorked(const QString countryName) _data.insert(countryName,true); } -bool CountriesWorked::getHasWorked(const QString countryName) +bool CountriesWorked::getHasWorked(const QString countryName) const { if (_data.contains(countryName)) return _data.value(countryName); @@ -21,7 +21,7 @@ bool CountriesWorked::getHasWorked(const QString countryName) return false; } -int CountriesWorked::getWorkedCount() +int CountriesWorked::getWorkedCount() const { int count = 0; foreach (bool value,_data) @@ -30,7 +30,7 @@ int CountriesWorked::getWorkedCount() return count; } -int CountriesWorked::getSize() +int CountriesWorked::getSize() const { return _data.count(); } diff --git a/logbook/countriesworked.h b/logbook/countriesworked.h index 34fcc0c0..fedfa752 100644 --- a/logbook/countriesworked.h +++ b/logbook/countriesworked.h @@ -14,15 +14,15 @@ class CountriesWorked { - public: - void init(const QStringList countryNames); - void setAsWorked(const QString countryName); - bool getHasWorked(const QString countryName); - int getWorkedCount(); - int getSize(); + public: + void init(const QStringList countryNames); + void setAsWorked(const QString countryName); + bool getHasWorked(const QString countryName) const; + int getWorkedCount() const; + int getSize() const; - private: - QHash<QString, bool> _data; + private: + QHash<QString, bool> _data; }; #endif diff --git a/logbook/countrydat.cpp b/logbook/countrydat.cpp index 1d88e059..7f3d613b 100644 --- a/logbook/countrydat.cpp +++ b/logbook/countrydat.cpp @@ -26,7 +26,7 @@ void CountryDat::init(const QString filename) _data.clear(); } -QString CountryDat::_extractName(const QString line) +QString CountryDat::_extractName(const QString line) const { int s1 = line.indexOf(':'); if (s1>=0) @@ -37,7 +37,7 @@ QString CountryDat::_extractName(const QString line) return ""; } -void CountryDat::_removeBrackets(QString &line, const QString a, const QString b) +void CountryDat::_removeBrackets(QString &line, const QString a, const QString b) const { int s1 = line.indexOf(a); while (s1 >= 0) @@ -48,10 +48,9 @@ void CountryDat::_removeBrackets(QString &line, const QString a, const QString b } } -QStringList CountryDat::_extractPrefix(QString &line, bool &more) +QStringList CountryDat::_extractPrefix(QString &line, bool &more) const { line = line.remove(" \n"); - line = line.replace("=",""); line = line.replace(" ",""); _removeBrackets(line,"(",")"); @@ -117,20 +116,38 @@ void CountryDat::load() } // return country name else "" -QString CountryDat::find(const QString prefix) +QString CountryDat::find(QString call) const { - QString pf = prefix.toUpper(); - while(pf.length() >= 1) - { - if (_data.contains(pf)) - { - QString country = _data.value(pf); - return country; - } - pf = pf.left(pf.length()-1); - } - return ""; -} - - + call = call.toUpper (); + // check for exact match first + if (_data.contains ("=" + call)) + { + return fixup (_data.value ("=" + call), call); + } + + auto prefix = call; + while (prefix.size () >= 1) + { + if (_data.contains (prefix)) + { + return fixup (_data.value (prefix), call); + } + prefix = prefix.left (prefix.size () - 1); + } + return QString {}; +} + +QString CountryDat::fixup (QString country, QString const& call) const +{ + // + // deal with special rules that cty.dat does not cope with + // + + // KG4 2x1 and 2x3 calls that map to Gitmo are mainland US not Gitmo + if (call.startsWith ("KG4") && call.size () != 5) + { + country.replace ("Guantanamo Bay", "United States"); + } + return country; +} diff --git a/logbook/countrydat.h b/logbook/countrydat.h index cd550cf1..d0430892 100644 --- a/logbook/countrydat.h +++ b/logbook/countrydat.h @@ -16,20 +16,21 @@ class CountryDat { - public: - void init(const QString filename); - void load(); - QString find(const QString prefix); // return country name or "" - QStringList getCountryNames() { return _countryNames; }; +public: + void init(const QString filename); + void load(); + QString find(QString prefix) const; // return country name or "" + QStringList getCountryNames() const { return _countryNames; }; - private: - QString _extractName(const QString line); - void _removeBrackets(QString &line, const QString a, const QString b); - QStringList _extractPrefix(QString &line, bool &more); - - QString _filename; - QStringList _countryNames; - QHash<QString, QString> _data; +private: + QString _extractName(const QString line) const; + void _removeBrackets(QString &line, const QString a, const QString b) const; + QStringList _extractPrefix(QString &line, bool &more) const; + QString fixup (QString country, QString const& call) const; + + QString _filename; + QStringList _countryNames; + QHash<QString, QString> _data; }; #endif diff --git a/logbook/logbook.cpp b/logbook/logbook.cpp index f074116b..48d6a2a6 100644 --- a/logbook/logbook.cpp +++ b/logbook/logbook.cpp @@ -67,7 +67,7 @@ void LogBook::_setAlreadyWorkedFromLog() void LogBook::match(/*in*/const QString call, /*out*/ QString &countryName, bool &callWorkedBefore, - bool &countryWorkedBefore) + bool &countryWorkedBefore) const { if (call.length() > 0) { @@ -75,6 +75,7 @@ void LogBook::match(/*in*/const QString call, 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 diff --git a/logbook/logbook.h b/logbook/logbook.h index 38ea9d18..4b80974d 100644 --- a/logbook/logbook.h +++ b/logbook/logbook.h @@ -23,7 +23,7 @@ public: void match(/*in*/ const QString call, /*out*/ QString &countryName, bool &callWorkedBefore, - bool &countryWorkedBefore); + bool &countryWorkedBefore) const; void addAsWorked(const QString call, const QString band, const QString mode, const QString date); private: |
