From 5b1a2c3accba5fd70054a591e7c0f91692000bbd Mon Sep 17 00:00:00 2001 From: Murray Curtis Date: Fri, 6 Sep 2013 05:00:28 +0000 Subject: [PATCH] Moved code that writes to the ADIF log from logqso into logbook/adif git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@3569 ab8295b8-cf94-4d9e-aec4-7959e3be5d79 --- logbook/adif.cpp | 87 +++++++++++++++++++++++++++++++++++++++++---- logbook/adif.h | 9 +++-- logbook/logbook.cpp | 4 +-- logbook/logbook.h | 2 +- logqso.cpp | 71 ++++++------------------------------ mainwindow.cpp | 30 +++++++++------- 6 files changed, 120 insertions(+), 83 deletions(-) diff --git a/logbook/adif.cpp b/logbook/adif.cpp index fa2802cc2..fb6b3bcda 100644 --- a/logbook/adif.cpp +++ b/logbook/adif.cpp @@ -2,6 +2,7 @@ #include #include +#include /* W1XT20m14.076DM33JT65-21-14201104220417042441st JT65A QSO. Him: mag loop 20WVK3ACFqf22lb @@ -73,14 +74,15 @@ void ADIF::load() } -void ADIF::add(const QString call) +void ADIF::add(const QString call, const QString band, const QString mode, const QString date) { QSO q; q.call = call; - q.band = ""; //TODO - q.mode = "JT9"; //TODO - q.date = ""; //TODO + q.band = band; + q.mode = mode; + q.date = date; _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) @@ -92,7 +94,7 @@ bool ADIF::match(const QString call, const QString band, const QString mode) QSO q; foreach(q,qsos) { - if ( (band.compare(q.band) == 0) + if ( (band.compare(q.band,Qt::CaseInsensitive) == 0) || (band=="") || (q.band=="")) { @@ -102,8 +104,9 @@ bool ADIF::match(const QString call, const QString band, const QString mode) && ((q.mode.compare("JT65",Qt::CaseInsensitive)==0) || (q.mode.compare("JT9",Qt::CaseInsensitive)==0)) ) - || (mode.compare(q.mode)==0) + || (mode.compare(q.mode,Qt::CaseInsensitive)==0) || (mode=="") + || (q.mode=="") ) return true; } @@ -129,3 +132,75 @@ int ADIF::getCount() 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) +{ + QFile f2(_filename); + if (!f2.open(QIODevice::Text | QIODevice::Append)) + return false; + else + { + QTextStream out(&f2); + if (f2.size()==0) + out << "WSJT-X ADIF Export" << endl; // new file + + QString t; + t="" + hisCall; + t+=" " + hisGrid; + t+=" " + mode; + t+=" " + rptSent; + t+=" " + rptRcvd; + t+=" " + date; + t+=" " + time; + t+=" " + band; + t+=" " + strDialFreq; + t+=" " + + m_myCall; + t+=" " + + m_myGrid; + if(m_txPower!="") t+= " " + m_txPower; + if(comments!="") t+=" " + comments; + if(name!="") t+=" " + name; + t+=" "; + out << t << endl; + f2.close(); + } + 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 91d3ca555..7445d4aaf 100644 --- a/logbook/adif.h +++ b/logbook/adif.h @@ -22,12 +22,17 @@ class ADIF public: void init(QString filename); void load(); - void add(const QString call); + 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 getCallList(); int getCount(); - + // 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); + private: struct QSO { diff --git a/logbook/logbook.cpp b/logbook/logbook.cpp index 0e1d4fb3c..e0e6d50c6 100644 --- a/logbook/logbook.cpp +++ b/logbook/logbook.cpp @@ -70,10 +70,10 @@ void LogBook::match(/*in*/const QString call, //qDebug() << "Logbook:" << call << ":" << countryName << "Cty B4:" << countryWorkedBefore << "call B4:" << callWorkedBefore; } -void LogBook::addAsWorked(const QString call) +void LogBook::addAsWorked(const QString call, const QString band, const QString mode, const QString date) { //qDebug() << "adding " << call << " as worked"; - _log.add(call); + _log.add(call,band,mode,date); QString countryName = _countries.find(call); if (countryName.length() > 0) _worked.setAsWorked(countryName); diff --git a/logbook/logbook.h b/logbook/logbook.h index f274ea8a0..4e61305f4 100644 --- a/logbook/logbook.h +++ b/logbook/logbook.h @@ -22,7 +22,7 @@ public: /*out*/ QString &countryName, bool &callWorkedBefore, bool &countryWorkedBefore); - void addAsWorked(const QString call); + void addAsWorked(const QString call, const QString band, const QString mode, const QString date); private: CountryDat _countries; diff --git a/logqso.cpp b/logqso.cpp index 9c1d49f79..d898493f1 100644 --- a/logqso.cpp +++ b/logqso.cpp @@ -1,5 +1,6 @@ #include "logqso.h" #include "ui_logqso.h" +#include "logbook/adif.h" #include #include @@ -70,33 +71,7 @@ void LogQSO::initLogQSO(QString hisCall, QString hisGrid, QString mode, m_dialFreq=dialFreq; m_myCall=myCall; m_myGrid=myGrid; - QString band=""; - if(dialFreq>0.135 and dialFreq<0.139) band="2200m"; - if(dialFreq>0.45 and dialFreq<0.55) band="630m"; - if(dialFreq>1.8 and dialFreq<2.0) band="160m"; - if(dialFreq>3.5 and dialFreq<4.0) band="80m"; - if(dialFreq>5.1 and dialFreq<5.45) band="60m"; - if(dialFreq>7.0 and dialFreq<7.3) band="40m"; - if(dialFreq>10.0 and dialFreq<10.15) band="30m"; - if(dialFreq>14.0 and dialFreq<14.35) band="20m"; - if(dialFreq>18.068 and dialFreq<18.168) band="17m"; - if(dialFreq>21.0 and dialFreq<21.45) band="15m"; - if(dialFreq>24.890 and dialFreq<24.990) band="12m"; - if(dialFreq>28.0 and dialFreq<29.7) band="10m"; - if(dialFreq>50.0 and dialFreq<54.0) band="6m"; - if(dialFreq>70.0 and dialFreq<71.0) band="4m"; - if(dialFreq>144.0 and dialFreq<148.0) band="2m"; - if(dialFreq>222.0 and dialFreq<225.0) band="1.25m"; - if(dialFreq>420.0 and dialFreq<450.0) band="70cm"; - if(dialFreq>902.0 and dialFreq<928.0) band="33cm"; - if(dialFreq>1240.0 and dialFreq<1300.0) band="23cm"; - if(dialFreq>2300.0 and dialFreq<2450.0) band="13cm"; - if(dialFreq>3300.0 and dialFreq<3500.0) band="9cm"; - if(dialFreq>5650.0 and dialFreq<5925.0) band="6cm"; - if(dialFreq>10000.0 and dialFreq<10500.0) band="3cm"; - if(dialFreq>24000.0 and dialFreq<24250.0) band="1.25cm"; - if(dialFreq>47000.0 and dialFreq<47200.0) band="6mm"; - if(dialFreq>75500.0 and dialFreq<81000.0) band="4mm"; + QString band= ADIF::bandFromFrequency(dialFreq); ui->band->setText(band); show (); @@ -122,39 +97,15 @@ void LogQSO::accept() m_comments=comments; QString strDialFreq(QString::number(m_dialFreq,'f',6)); -//Log this QSO to file "wsjtx_log.adi" - QFile f2("wsjtx_log.adi"); - if(!f2.open(QIODevice::Text | QIODevice::Append)) { - QMessageBox m; - m.setText("Cannot open file \"wsjtx_log.adi\"."); - m.exec(); - } else { - QTextStream out(&f2); - if(f2.size()==0) out << "WSJT-X ADIF Export" << endl; - - QString t; - t="" + hisCall; - t+=" " + hisGrid; - t+=" " + mode; - t+=" " + rptSent; - t+=" " + rptRcvd; - t+=" " + date; - t+=" " + time; - t+=" " + band; - t+=" " + strDialFreq; - t+=" " + - m_myCall; - t+=" " + - m_myGrid; - if(m_txPower!="") t+= " " + m_txPower; - if(comments!="") t+=" " + comments; - if(name!="") t+=" " + name; - t+=" "; - out << t << endl; - f2.close(); + //Log this QSO to ADIF file "wsjtx_log.adi" + QString filename = "wsjtx_log.adi"; // TODO allow user to set + ADIF adifile; + adifile.init(filename); + if (!adifile.addQSOToFile(hisCall,hisGrid,mode,rptSent,rptRcvd,date,time,band,comments,name,strDialFreq,m_myCall,m_myGrid,m_txPower)) + { + QMessageBox m; + m.setText("Cannot open file \"wsjtx_log.adi\"."); + m.exec(); } //Log this QSO to file "wsjtx.log" diff --git a/mainwindow.cpp b/mainwindow.cpp index 16afd399d..ad19adf11 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -2447,19 +2447,25 @@ void MainWindow::on_logQSOButton_clicked() //Log QSO button void MainWindow::acceptQSO2(bool accepted) { - if(accepted) { - m_logBook.addAsWorked(m_hisCall); - if(m_clearCallGrid) { - m_hisCall=""; - ui->dxCallEntry->setText(""); - m_hisGrid=""; - ui->dxGridEntry->setText(""); - m_rptSent=""; - m_rptRcvd=""; - m_qsoStart=""; - m_qsoStop=""; + if(accepted) + { + QString band = ADIF::bandFromFrequency(m_dialFreq+m_txFreq/1.0e6); + QString date = m_dateTimeQSO.toString("yyyy-MM-dd"); + date=date.mid(0,4) + date.mid(5,2) + date.mid(8,2); + m_logBook.addAsWorked(m_hisCall,band,m_modeTx,date); + + if (m_clearCallGrid) + { + m_hisCall=""; + ui->dxCallEntry->setText(""); + m_hisGrid=""; + ui->dxGridEntry->setText(""); + m_rptSent=""; + m_rptRcvd=""; + m_qsoStart=""; + m_qsoStop=""; + } } - } } void MainWindow::on_actionJT9_1_triggered()