Skip to content

Commit

Permalink
qso copy constructor and subdivisions query fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ea4k committed Aug 15, 2024
1 parent ab7392f commit eada6f8
Show file tree
Hide file tree
Showing 10 changed files with 304 additions and 575 deletions.
8 changes: 3 additions & 5 deletions src/Changelog
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
Complete the copy constructor of QSO
TODO-Test: Add tests to test the subsivisions
TODO-Test: the copy constructor of QSO
Complete: void MainWindow::slotQSOReceived(const QSO &_qso) to add the QSO
Check the bug that makes WSJTX not logging automatically
TODO: After refactor, remove/comment out
void UDPServer::adifParse(QByteArray &msg)
udpserver signal logged_qso
void MainWindow::slotWSJTXloggedQSO


BUG: When entering/modifying a QSO thre is an error related to awarddxcc table not existing
TODO: After update, it is needed to restart KLog to be able to use the primary subdivisions
Expand Down
67 changes: 62 additions & 5 deletions src/dataproxy_sqlite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2385,9 +2385,6 @@ bool DataProxy_SQLite::clublogModifyFullLog(const int _currentLog)
{
//qDebug() << Q_FUNC_INFO << ": " << _dxcall;
//void MainWindow::slotWSJTXloggedQSO(const int _type, const QString &_dxcall, const quint64 _freq, const QString &_mode,
// const QString &_dx_grid, const QString &_time_off, const QString &_report_sent, const QString &_report_rec,
// const QString &_tx_power, const QString &_comments, const QString &_name, const QString &_time_on)
//_qso format: Date/TimeOn/call/bandid/modeid/freq/dxgrid/timeOff/rsttx/rstrx/txpower/comments/name
Expand Down Expand Up @@ -2714,6 +2711,66 @@ int DataProxy_SQLite::isWorkedB4(const QString &_qrz, const int _currentLog)
}
}

QList<int> DataProxy_SQLite::isThisQSODuplicated (const QSO &_qso, const int _secs)
{
QList<int> dupeQsos;
dupeQsos.clear();
QSO q(_qso);
if (!q.isValid())
{
//qDebug() << Q_FUNC_INFO << " - END Empty 3" ;
return dupeQsos;
}

int validityPeriod = _secs * 60;
QString initTime = util->getDateTimeSQLiteStringFromDateTime(q.getDateTimeOn().addSecs(-validityPeriod));
QString endTime = util->getDateTimeSQLiteStringFromDateTime(q.getDateTimeOn().addSecs(validityPeriod));

//yyyy-MM-dd hh:mm:ss
// We will match +-15min

QString queryString = QString("SELECT id, qso_date FROM log WHERE call=':call' AND bandid =':bandid' AND modeid=':modeid' AND qso_date >=':initTime' AND qso_date <=':endTime'");
//queryString = QString("SELECT id, qso_date FROM log WHERE call='%1' AND bandid='%2' AND modeid='%3' AND qso_date>='%4' AND qso_date<='%5'").arg(_qrz).arg(_band).arg(_mode).arg(initTime).arg(endTime);
QSqlQuery query;
query.prepare(queryString);
query.bindValue(":call", q.getCall());
query.bindValue(":bandid", getIdFromBandName(q.getBand()));
query.bindValue(":modeid", getIdFromModeName(q.getMode()));
query.bindValue(":initTime", initTime);
query.bindValue(":endTime", endTime);

bool sqlOK = query.exec(queryString);

if (sqlOK)
{
while (query.next())
{
if (query.isValid())
{
int dupeQSO = (query.value(0)).toInt();
if (dupeQSO>0)
{
dupeQsos.append(dupeQSO);
}
}
else
{
//qDebug() << Q_FUNC_INFO << " - END Empty 2" ;
}
}
//qDebug() << Q_FUNC_INFO << " - END" ;
return dupeQsos;
}
else
{
emit queryError(Q_FUNC_INFO, query.lastError().databaseText(), query.lastError().nativeErrorCode(), query.lastQuery());
query.finish();
//qDebug() << Q_FUNC_INFO << " - END Empty 1" ;
return dupeQsos;
}
}

/*
QList<int> DataProxy_SQLite::isThisQSODuplicated(const QString &_callingFunc, const QString &_qrz, const QDateTime &_dateTime, const int _band, const int _mode, const int _secs)
//QList<int> DataProxy_SQLite::isThisQSODuplicated(const QString &_qrz, const QDateTime &_dateTime, const int _band, const int _mode)
{
Expand Down Expand Up @@ -2761,11 +2818,11 @@ QList<int> DataProxy_SQLite::isThisQSODuplicated(const QString &_callingFunc, co
return dupeQsos;
}
}

*/

int DataProxy_SQLite::getDuplicatedQSOId(const QString &_qrz, const QDateTime &_datetime, const int _band, const int _mode)
{
//qDebug() << "DataProxy_SQLite::isThisQSODuplicated";
//qDebug() << Q_FUNC_INFO;
QSqlQuery query;
QString queryString;
QString datetime = util->getDateTimeSQLiteStringFromDateTime(_datetime);
Expand Down
3 changes: 2 additions & 1 deletion src/dataproxy_sqlite.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ class DataProxy_SQLite : public QObject

bool deleteQSO(const int _qsoId);
int isWorkedB4(const QString &_qrz, const int _currentLog);
QList<int> isThisQSODuplicated(const QString &_callingFunc, const QString &_qrz, const QDateTime &_dateTime, const int _band, const int _mode, const int _secs);
//QList<int> isThisQSODuplicated(const QString &_callingFunc, const QString &_qrz, const QDateTime &_dateTime, const int _band, const int _mode, const int _secs);
QList<int> isThisQSODuplicated (const QSO &_qso, const int _secs);
int getDuplicatedQSOId(const QString &_qrz, const QDateTime &_datetime, const int _band, const int _mode);
bool isDXCCConfirmed(const int _dxcc, const int _currentLog);
bool isQSLReceived(const int _qsoId);
Expand Down
8 changes: 6 additions & 2 deletions src/mainqsoentrywidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1061,8 +1061,12 @@ void MainQSOEntryWidget::checkIfDupe(const QString &_func)
QDateTime _dateTime;
_dateTime.setDate(dateEdit->date());
_dateTime.setTime(timeEdit->time());

if ((dataProxy->isThisQSODuplicated(Q_FUNC_INFO, qrzLineEdit->text(), _dateTime, dataProxy->getIdFromBandName(bandComboBox->currentText()), dataProxy->getIdFromModeName(modeComboBox->currentText()), duplicatedQSOSlotInSecs).length()<2) || modify)
QSO q;
q.setCall(qrzLineEdit->text());
q.setDateTimeOn(_dateTime);
q.setBand(bandComboBox->currentText());
q.setMode(modeComboBox->currentText());
if ((dataProxy->isThisQSODuplicated(q, duplicatedQSOSlotInSecs).length()<2) || modify)
{
//qDebug() << Q_FUNC_INFO << " - NOT DUPE ";
//qDebug() << Q_FUNC_INFO << " - Modify: " << util->boolToQString(modify);
Expand Down
199 changes: 34 additions & 165 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,9 +725,9 @@ void MainWindow::createActionsCommon(){

// UDPLogServer - WSJT-x
connect(UDPLogServer, SIGNAL(status_update(int, QString, double, QString, QString, QString, QString, QString, QString)), this, SLOT(slotWSJXstatusFromUDPServer(int, QString, double, QString, QString, QString, QString, QString, QString) ) );
connect(UDPLogServer, SIGNAL( logged_qso(QString, QString, QString, double, QString, QString, QString, QString, QString, QString, QString, QString, QDateTime, QDateTime, QString, QString, QString)), this, SLOT(slotWSJTXloggedQSO (QString, QString, QString, double, QString, QString, QString, QString, QString, QString, QString, QString, QDateTime, QDateTime, QString, QString, QString) ) );

connect(UDPLogServer, SIGNAL(clearSignal(QString)), this, SLOT(slotClearButtonClicked(QString) ) );
connect(UDPLogServer, SIGNAL( logged(QSO)), this, SLOT(slotQSOReceived(QSO) ) );
connect(UDPLogServer, SIGNAL(logged(QSO)), this, SLOT(slotQSOReceived(QSO) ) );

connect(this, SIGNAL(queryError(QString, QString, QString, QString)), this, SLOT(slotQueryErrorManagement(QString, QString, QString, QString)) );
connect(setupDialog, SIGNAL(debugLog(QString, QString, DebugLogLevel)), this, SLOT(slotCaptureDebugLogs(QString, QString, DebugLogLevel)) );
Expand Down Expand Up @@ -5736,15 +5736,31 @@ void MainWindow::slotQSOReceived(const QSO &_qso)
{
qDebug() << Q_FUNC_INFO << " - Start";
//logEvent(Q_FUNC_INFO, "Start", Debug);
if (!askToAddQSOReceived(_qso))
return;

if (!wsjtxAutoLog)
if (!askToAddQSOReceived(_qso))
return;
QSO q(_qso);

int dxcc = world->getQRZARRLId(q.getCall());
dxcc = util->getNormalizedDXCCValue (dxcc);
q.setDXCC(dxcc);

if (!showWSJTXDuplicatedMSG(q))
return;


int addedQSO = q.toDB();
if (addedQSO>0)
{
qDebug() << Q_FUNC_INFO << " - QSO added";
else
qDebug() << Q_FUNC_INFO << " - QSO NOT added";

//qDebug() << Q_FUNC_INFO << " Logged QSO OK: " << _dxcall ;
actionsJustAfterAddingOneQSO();
slotShowInfoLabel(tr("QSO logged from WSJT-X:"));
infoLabel2->setText(q.getCall() + " - " + dataProxy->getBandNameFromFreq(q.getFreqTX()) + "/" + q.getMode());
slotClearButtonClicked(Q_FUNC_INFO);
}

qDebug() << Q_FUNC_INFO << " - END";
logEvent(Q_FUNC_INFO, "END", Debug);
Expand Down Expand Up @@ -5774,32 +5790,11 @@ bool MainWindow::askToAddQSOReceived(const QSO &_qso)
"<TR><TH>DX-Grid:</TH><TD>%9</TD></TR>"
"<TR><TH>Local-Grid:</TH><TD>%10</TD></TR>"
"<TR><TH>Station Callsign:</TH><TD>%11</TD></TR>"
"<TR><TH>Operator Callsign:</TH>º<TD>%12</TD></TR></table></body></html>")).arg(qsoM.getCall(), QString::number(qsoM.getFreqTX()), qsoM.getMode(),
util->getADIFTimeFromQTime(qsoM.getTimeOn()), util->getADIFTimeFromQTime(qsoM.getTimeOff()), qsoM.getRSTTX(), qsoM.getRSTRX(),
qsoM.getComment(), qsoM.getGridSquare(), qsoM.getMyGridSquare(),
qsoM.getStationCallsign(), qsoM.getOperatorCallsign());

/*
"<UL>"
"<LI><b>Callsign:</b>%1</LI>"
"<LI><b>Freq:</b>%2</LI>"
"<LI><b>Mode:</b>%3</LI>"
"<LI><b>Time On:</b>%4</LI>"
"<LI><b>Time Off:</b>%5</LI>"
"<LI><b>RST TX:</b>%6</LI>"
"<LI><b>RST RX:</b>%7</LI>"
"<LI><b>Comment:</b>%8</LI>"
"<LI><b>DX-Grid:</b>%9</LI>"
"<LI><b>Local-Grid:</b>%10</LI>"
"<LI><b>Station Callsign:</b>%11</LI>"
"<LI><b>Operator Callsign:</b>%12</LI></UL></body></html>")).arg(qsoM.getCall(), QString::number(qsoM.getFreqTX()), qsoM.getMode(),
"<TR><TH>Operator Callsign:</TH><TD>%12</TD></TR></table></body></html>")).arg(qsoM.getCall(), QString::number(qsoM.getFreqTX()), qsoM.getMode(),
util->getADIFTimeFromQTime(qsoM.getTimeOn()), util->getADIFTimeFromQTime(qsoM.getTimeOff()), qsoM.getRSTTX(), qsoM.getRSTRX(),
qsoM.getComment(), qsoM.getGridSquare(), qsoM.getMyGridSquare(),
qsoM.getStationCallsign(), qsoM.getOperatorCallsign());

*/

msgBox.setText(aux);
int ret = msgBox.exec();
switch (ret)
Expand All @@ -5818,141 +5813,11 @@ bool MainWindow::askToAddQSOReceived(const QSO &_qso)
}
}

void MainWindow::slotWSJTXloggedQSO (const QString &_dxcall, const QString &_mode, const QString &_band, const double _freq,
const QString &_mygrid, const QString &_dxgrid, const QString &_rstTX, const QString &_rstRX,
const QString &_comment, const QString &_stationcallsign, const QString &_name,
const QString &_opCall, const QDateTime &_datetime, const QDateTime &_datetime_off,
const QString &_exchangeTX, const QString &_exchangeRX, const QString &_mypwr)
bool MainWindow::showWSJTXDuplicatedMSG(const QSO &_qso)
{
//qDebug() << "MainWindow::slotWSJTX-loggedQSO" ;
//logEvent(Q_FUNC_INFO, "Start", Debug);


if (!_datetime.isValid() || !_datetime_off.isValid())
{
//qDebug() << Q_FUNC_INFO << " DATES NOT VALID " ;
return ;
}

QString opCall = stationCallsign;
if (util->isValidCall(_opCall))
{
opCall = _opCall.toUpper();
}
double pwr = _mypwr.toDouble();
if (pwr<=0.0)
{
pwr = myDataTabWidget->getMyPower ();
}

//qDebug() << Q_FUNC_INFO << " dxcall: " << _dxcall ;
//qDebug() << Q_FUNC_INFO << " freq: " << QString::number(_freq/1000000) ;
//qDebug() << Q_FUNC_INFO << " freq no div: " << QString::number(_freq) ;
//qDebug() << Q_FUNC_INFO << " mode: " << _mode ;
//qDebug() << Q_FUNC_INFO << " band: " << _band ;
//qDebug() << Q_FUNC_INFO << " my_grid: " << _mygrid ;
//qDebug() << Q_FUNC_INFO << " dx_grid: " << _dxgrid ;
//qDebug() << Q_FUNC_INFO << " comment: " << _comment ;
//qDebug() << Q_FUNC_INFO << " StationCall: " << _stationcallsign ;
//qDebug() << Q_FUNC_INFO << " _opCall: " << _opCall ;
//qDebug() << Q_FUNC_INFO << " opCall: " << opCall ;
//qDebug() << Q_FUNC_INFO << " time_on: " << util->getDateTimeSQLiteStringFromDateTime(_datetime) ;
//qDebug() << Q_FUNC_INFO << " time_off: " << util->getDateTimeSQLiteStringFromDateTime(_datetime_off) ;
//qDebug() << Q_FUNC_INFO << " report_sent: " << _rstTX ;
//qDebug() << Q_FUNC_INFO << " report_rec: " << _rstRX ;
//qDebug() << Q_FUNC_INFO << " exchange_sent: " << _exchangeTX ;
//qDebug() << Q_FUNC_INFO << " exchange_rec: " << _exchangeRX ;
//qDebug() << Q_FUNC_INFO << " MY_PWR: " << _mypwr ;

if (wsjtxAutoLog)
{ // Log automatically, without confirmation
//logTheQso = true;
//qDebug() << Q_FUNC_INFO << " LogTheQSO = true" ;
}
else
{ // Ask for confirmation before logging
//qDebug() << Q_FUNC_INFO << " LogTheQSO = false - we ask for confirmation" ;
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Information);
msgBox.setWindowTitle(tr("KLog - QSO received"));
msgBox.setTextFormat(Qt::RichText);
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No );
msgBox.setDefaultButton(QMessageBox::Yes);
QString aux = QString("The following QSO data has been received from WSJT-X to be logged:\n\n"
"<UL>"
"<LI><b>Callsign:</b>%1</LI>"
"<LI><b>Freq:</b>%2</LI>"
"<LI><b>Mode:</b>%3</LI>"
"<LI><b>Time On:</b>%4</LI>"
"<LI><b>Time Off:</b>%5</LI>"
"<LI><b>RST TX:</b>%6</LI>"
"<LI><b>RST RX:</b>%7</LI>"
"<LI><b>Comment:</b>%8</LI>"
"<LI><b>DX-Grid:</b>%9</LI>"
"<LI><b>Local-Grid:</b>%10</LI>"
"<LI><b>Station Callsign:</b>%11</LI>"
"<LI><b>Operator Callsign:</b>%12</LI>").arg(_dxcall.toUpper())
.arg(QString::number(_freq)).arg(_mode.toUpper()).arg(util->getDateTimeSQLiteStringFromDateTime(_datetime))
.arg(util->getDateTimeSQLiteStringFromDateTime(_datetime_off))
.arg(_rstTX).arg(_rstRX)
.arg(_comment).arg(_dxgrid.toUpper()).arg(_mygrid.toUpper())
.arg(_stationcallsign.toUpper()).arg(opCall.toUpper());

msgBox.setText(aux);
int ret = msgBox.exec();
switch (ret)
{
//case QMessageBox::Yes:
//break;
case QMessageBox::No:
//logTheQso = false;
return;
break;
default:
// should never be reached
//logTheQso = false;
return;
break;
}
}

//qDebug() << Q_FUNC_INFO << " QSO must be logged" ;

int dxcc = world->getQRZARRLId(_dxcall);
dxcc = util->getNormalizedDXCCValue (dxcc);
QString _myLoc = _mygrid;

if (!(locator->isValidLocator(_myLoc)))
{
_myLoc = myDataTabWidget->getMyLocator();
}

if ((dataProxy->isThisQSODuplicated(Q_FUNC_INFO, _dxcall, _datetime, dataProxy->getBandIdFromFreq(_freq), dataProxy->getIdFromModeName(_mode), dupeSlotInSeconds)).length()>1)
{
showWSJTXDuplicatedMSG();
}

bool qsoLogged = dataProxy->addQSOFromWSJTX(_dxcall, _mode, _band, _freq,
_myLoc, _dxgrid, _rstTX, _rstRX,
_exchangeRX, _exchangeTX, _comment,
_stationcallsign, _name, opCall,
_datetime, _datetime_off, pwr, dxcc, currentLog, sendQSLByDefault);

if (qsoLogged)
{
//qDebug() << Q_FUNC_INFO << " Logged QSO OK: " << _dxcall ;
actionsJustAfterAddingOneQSO();
slotShowInfoLabel(tr("QSO logged from WSJT-X:"));
infoLabel2->setText(_dxcall + " - " + dataProxy->getBandNameFromFreq(_freq) + "/" + _mode);
slotClearButtonClicked(Q_FUNC_INFO);
}

logEvent(Q_FUNC_INFO, "END", Debug);
//qDebug() << Q_FUNC_INFO << " - END" ;
}
if (!((dataProxy->isThisQSODuplicated(_qso, dupeSlotInSeconds)).length()>0))
return true;

void MainWindow::showWSJTXDuplicatedMSG()
{
QMessageBox msgBox;
msgBox.setWindowTitle(tr("KLog - WSJTX Dupe QSO"));

Expand All @@ -5968,16 +5833,17 @@ void MainWindow::showWSJTXDuplicatedMSG()
{
case QMessageBox::Save:
logEvent(Q_FUNC_INFO, "END-1", Debug);
return true;

break;
case QMessageBox::Discard:
logEvent(Q_FUNC_INFO, "END-1", Debug);
return; //No more error shown
return false; //No more error shown
// break;
default:
// should never be reached
logEvent(Q_FUNC_INFO, "END-3", Debug);
return; // The user wants to keepseeing errors
return false; // The user wants to keepseeing errors
//break;
}
}
Expand Down Expand Up @@ -6125,8 +5991,11 @@ void MainWindow::slotClearNoMorErrorShown()

void MainWindow::slotQueryErrorManagement(QString functionFailed, QString errorCodeS, QString nativeError, QString queryFailed)
{
//qDebug() << "MainWindow::slotQueryErrorManagement: Function: " << functionFailed ;
//qDebug() << "MainWindow::slotQueryErrorManagement: Error: " << functionFailed << " - " << errorCodeS;
qDebug() << Q_FUNC_INFO << " - Function: " << functionFailed ;
qDebug() << Q_FUNC_INFO << " - Error: - " << errorCodeS;
qDebug() << Q_FUNC_INFO << " - Native: - " << nativeError;
qDebug() << Q_FUNC_INFO << " - QueryFailed: - " << queryFailed;

logEvent(Q_FUNC_INFO, "Start", Debug);

if (noMoreErrorShown)
Expand Down
Loading

0 comments on commit eada6f8

Please sign in to comment.