mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2024-11-15 16:42:12 -05:00
75d371ebd9
Because of the way logged QSO times are split and rebuilt in the QSO logging code the UTC time specification is lost. This change sets them back to UTC since that is what they are. git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@7566 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
169 lines
5.9 KiB
C++
169 lines
5.9 KiB
C++
#include "logqso.h"
|
|
|
|
#include <QString>
|
|
#include <QSettings>
|
|
#include <QStandardPaths>
|
|
#include <QDir>
|
|
#include <QDebug>
|
|
|
|
#include "logbook/adif.h"
|
|
#include "MessageBox.hpp"
|
|
|
|
#include "ui_logqso.h"
|
|
#include "moc_logqso.cpp"
|
|
|
|
LogQSO::LogQSO(QString const& programTitle, QSettings * settings, QWidget *parent)
|
|
: QDialog(parent)
|
|
, ui(new Ui::LogQSO)
|
|
, m_settings (settings)
|
|
{
|
|
ui->setupUi(this);
|
|
setWindowTitle(programTitle + " - Log QSO");
|
|
loadSettings ();
|
|
}
|
|
|
|
LogQSO::~LogQSO ()
|
|
{
|
|
}
|
|
|
|
void LogQSO::loadSettings ()
|
|
{
|
|
m_settings->beginGroup ("LogQSO");
|
|
restoreGeometry (m_settings->value ("geometry", saveGeometry ()).toByteArray ());
|
|
ui->cbTxPower->setChecked (m_settings->value ("SaveTxPower", false).toBool ());
|
|
ui->cbComments->setChecked (m_settings->value ("SaveComments", false).toBool ());
|
|
m_txPower = m_settings->value ("TxPower", "").toString ();
|
|
m_comments = m_settings->value ("LogComments", "").toString();
|
|
m_settings->endGroup ();
|
|
}
|
|
|
|
void LogQSO::storeSettings () const
|
|
{
|
|
m_settings->beginGroup ("LogQSO");
|
|
m_settings->setValue ("geometry", saveGeometry ());
|
|
m_settings->setValue ("SaveTxPower", ui->cbTxPower->isChecked ());
|
|
m_settings->setValue ("SaveComments", ui->cbComments->isChecked ());
|
|
m_settings->setValue ("TxPower", m_txPower);
|
|
m_settings->setValue ("LogComments", m_comments);
|
|
m_settings->endGroup ();
|
|
}
|
|
|
|
void LogQSO::initLogQSO(QString hisCall, QString hisGrid, QString mode,
|
|
QString rptSent, QString rptRcvd, QDateTime dateTimeOn, QDateTime dateTimeOff,
|
|
Radio::Frequency dialFreq, QString myCall, QString myGrid,
|
|
bool noSuffix, bool toRTTY, bool dBtoComments)
|
|
{
|
|
if(!isHidden()) return;
|
|
ui->call->setText(hisCall);
|
|
ui->grid->setText(hisGrid);
|
|
ui->name->setText("");
|
|
ui->txPower->setText("");
|
|
ui->comments->setText("");
|
|
if (ui->cbTxPower->isChecked ()) ui->txPower->setText(m_txPower);
|
|
if (ui->cbComments->isChecked ()) ui->comments->setText(m_comments);
|
|
if(dBtoComments) {
|
|
QString t=mode;
|
|
if(rptSent!="") t+=" Sent: " + rptSent;
|
|
if(rptRcvd!="") t+=" Rcvd: " + rptRcvd;
|
|
ui->comments->setText(t);
|
|
}
|
|
if(noSuffix and mode.mid(0,3)=="JT9") mode="JT9";
|
|
if(toRTTY and mode.mid(0,3)=="JT9") mode="RTTY";
|
|
ui->mode->setText(mode);
|
|
ui->sent->setText(rptSent);
|
|
ui->rcvd->setText(rptRcvd);
|
|
m_dateTimeOn=dateTimeOn;
|
|
m_dateTimeOff=dateTimeOff;
|
|
QString dateOn=dateTimeOn.toString("yyyy-MM-dd");
|
|
ui->dateOn->setText(dateOn);
|
|
QString timeOn=dateTimeOn.toString("hhmm");
|
|
ui->timeOn->setText(timeOn);
|
|
QString dateOff=dateTimeOff.toString("yyyy-MM-dd");
|
|
ui->dateOff->setText(dateOff);
|
|
QString timeOff=dateTimeOff.toString("hhmm");
|
|
ui->timeOff->setText(timeOff);
|
|
m_dialFreq=dialFreq;
|
|
m_myCall=myCall;
|
|
m_myGrid=myGrid;
|
|
QString band= ADIF::bandFromFrequency(dialFreq / 1.e6);
|
|
ui->band->setText(band);
|
|
|
|
show ();
|
|
}
|
|
|
|
void LogQSO::accept()
|
|
{
|
|
QString hisCall,hisGrid,mode,rptSent,rptRcvd,dateOn,dateOff,timeOn,timeOff,band;
|
|
QString comments,name;
|
|
|
|
hisCall=ui->call->text();
|
|
hisGrid=ui->grid->text();
|
|
mode=ui->mode->text();
|
|
rptSent=ui->sent->text();
|
|
rptRcvd=ui->rcvd->text();
|
|
m_dateTimeOn = m_dateTimeOn.fromString(ui->dateOn->text()+" "+ui->timeOn->text(),"yyyy-MM-dd hhmm");
|
|
m_dateTimeOff = m_dateTimeOff.fromString(ui->dateOff->text()+" "+ui->timeOff->text(),"yyyy-MM-dd hhmm");
|
|
|
|
// set time off and on back to UTC as the above QDateTime::fromString()
|
|
// creates a local time value -- this would be al so much simpler if
|
|
// QDateTimeEdit widgets had been used
|
|
m_dateTimeOff.setTimeSpec (Qt::UTC);
|
|
m_dateTimeOn.setTimeSpec (Qt::UTC);
|
|
|
|
dateOn=ui->dateOn->text();
|
|
dateOn=dateOn.mid(0,4) + dateOn.mid(5,2) + dateOn.mid(8,2);
|
|
timeOn=ui->timeOn->text();
|
|
dateOff=ui->dateOff->text();
|
|
dateOff=dateOff.mid(0,4) + dateOff.mid(5,2) + dateOff.mid(8,2);
|
|
timeOff=ui->timeOff->text();
|
|
band=ui->band->text();
|
|
name=ui->name->text();
|
|
m_txPower=ui->txPower->text();
|
|
comments=ui->comments->text();
|
|
m_comments=comments;
|
|
QString strDialFreq(QString::number(m_dialFreq / 1.e6,'f',6));
|
|
|
|
//Log this QSO to ADIF file "wsjtx_log.adi"
|
|
QString filename = "wsjtx_log.adi"; // TODO allow user to set
|
|
ADIF adifile;
|
|
auto adifilePath = QDir {QStandardPaths::writableLocation (QStandardPaths::DataLocation)}.absoluteFilePath ("wsjtx_log.adi");
|
|
adifile.init(adifilePath);
|
|
if (!adifile.addQSOToFile(hisCall,hisGrid,mode,rptSent,rptRcvd,dateOn,timeOn,dateOff,timeOff,band,comments,name,strDialFreq,m_myCall,m_myGrid,m_txPower))
|
|
{
|
|
MessageBox::warning_message (this, tr ("Log file error"),
|
|
tr ("Cannot open \"%1\"").arg (adifilePath));
|
|
}
|
|
|
|
//Log this QSO to file "wsjtx.log"
|
|
static QFile f {QDir {QStandardPaths::writableLocation (QStandardPaths::DataLocation)}.absoluteFilePath ("wsjtx.log")};
|
|
if(!f.open(QIODevice::Text | QIODevice::Append)) {
|
|
MessageBox::warning_message (this, tr ("Log file error"),
|
|
tr ("Cannot open \"%1\" for append").arg (f.fileName ()),
|
|
tr ("Error: %1").arg (f.errorString ()));
|
|
} else {
|
|
QString logEntry=m_dateTimeOn.date().toString("yyyy-MM-dd,") +
|
|
m_dateTimeOn.time().toString("hh:mm,") +
|
|
m_dateTimeOff.date().toString("yyyy-MM-dd,") +
|
|
m_dateTimeOff.time().toString("hh:mm,") + hisCall + "," +
|
|
hisGrid + "," + strDialFreq + "," + mode +
|
|
"," + rptSent + "," + rptRcvd + "," + m_txPower +
|
|
"," + comments + "," + name;
|
|
QTextStream out(&f);
|
|
out << logEntry << endl;
|
|
f.close();
|
|
}
|
|
|
|
//Clean up and finish logging
|
|
Q_EMIT acceptQSO (m_dateTimeOff, hisCall, hisGrid, m_dialFreq, mode, rptSent, rptRcvd, m_txPower, comments, name,m_dateTimeOn);
|
|
QDialog::accept();
|
|
}
|
|
|
|
// closeEvent is only called from the system menu close widget for a
|
|
// modeless dialog so we use the hideEvent override to store the
|
|
// window settings
|
|
void LogQSO::hideEvent (QHideEvent * e)
|
|
{
|
|
storeSettings ();
|
|
QDialog::hideEvent (e);
|
|
}
|