Files
WSJT-X/widgets/logqso.cpp
T

185 lines
6.4 KiB
C++
Raw Normal View History

2013-08-10 15:29:55 +00:00
#include "logqso.h"
2013-08-10 15:29:55 +00:00
#include <QString>
#include <QSettings>
2014-12-03 00:06:54 +00:00
#include <QStandardPaths>
#include <QDir>
2013-08-10 15:29:55 +00:00
#include <QDebug>
#include "logbook/logbook.h"
#include "MessageBox.hpp"
#include "Configuration.hpp"
#include "models/Bands.hpp"
#include "validators/MaidenheadLocatorValidator.hpp"
#include "ui_logqso.h"
#include "moc_logqso.cpp"
2013-08-10 15:29:55 +00:00
LogQSO::LogQSO(QString const& programTitle, QSettings * settings
, Configuration const * config, QWidget *parent)
: QDialog {parent, Qt::WindowStaysOnTopHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint}
2014-12-03 00:06:54 +00:00
, ui(new Ui::LogQSO)
, m_settings (settings)
, m_config {config}
2013-08-10 15:29:55 +00:00
{
ui->setupUi(this);
setWindowTitle(programTitle + " - Log QSO");
2013-08-10 15:29:55 +00:00
loadSettings ();
2018-04-21 19:09:47 +00:00
ui->grid->setValidator (new MaidenheadLocatorValidator {this});
2013-08-10 15:29:55 +00:00
}
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 ();
}
2017-07-09 20:45:53 +00:00
void LogQSO::initLogQSO(QString const& hisCall, QString const& hisGrid, QString mode,
QString const& rptSent, QString const& rptRcvd,
QDateTime const& dateTimeOn, QDateTime const& dateTimeOff,
2018-10-31 17:35:59 -05:00
Radio::Frequency dialFreq, bool noSuffix, QString xSent, QString xRcvd)
2013-08-10 15:29:55 +00:00
{
if(!isHidden()) return;
m_xSent=xSent;
m_xRcvd=xRcvd;
2013-08-10 15:29:55 +00:00
ui->call->setText(hisCall);
ui->grid->setText(hisGrid);
2013-09-13 13:42:11 +00:00
ui->name->setText("");
2013-08-10 15:29:55 +00:00
ui->txPower->setText("");
ui->comments->setText("");
if (ui->cbTxPower->isChecked ()) ui->txPower->setText(m_txPower);
if (ui->cbComments->isChecked ()) ui->comments->setText(m_comments);
2018-10-31 17:35:59 -05:00
if (m_config->report_in_comments()) {
2013-08-10 15:29:55 +00:00
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";
2018-10-31 17:35:59 -05:00
if(m_config->log_as_RTTY() and mode.mid(0,3)=="JT9") mode="RTTY";
2013-08-10 15:29:55 +00:00
ui->mode->setText(mode);
ui->sent->setText(rptSent);
ui->rcvd->setText(rptRcvd);
2017-07-09 20:45:53 +00:00
ui->start_date_time->setDateTime (dateTimeOn);
ui->end_date_time->setDateTime (dateTimeOff);
2013-08-10 15:29:55 +00:00
m_dialFreq=dialFreq;
2018-10-31 17:35:59 -05:00
m_myCall=m_config->my_callsign();
m_myGrid=m_config->my_grid();
ui->band->setText (m_config->bands ()->find (dialFreq));
2018-10-31 17:35:59 -05:00
ui->loggedOperator->setText(m_config->opCall());
ui->exchSent->setText(m_xSent);
ui->exchRcvd->setText(m_xRcvd);
2018-10-31 17:35:59 -05:00
using SpOp = Configuration::SpecialOperatingActivity;
if( SpOp::FOX == m_config->special_op_id() or
2018-11-02 16:25:47 -04:00
(m_config->autoLog() and SpOp::NONE < m_config->special_op_id() and
m_xSent!="" and m_xRcvd!="")) {
accept();
} else {
2018-11-02 16:25:47 -04:00
show();
}
2013-08-10 15:29:55 +00:00
}
void LogQSO::accept()
{
QString hisCall,hisGrid,mode,rptSent,rptRcvd,dateOn,dateOff,timeOn,timeOff,band,operator_call;
2013-08-10 15:29:55 +00:00
QString comments,name;
hisCall=ui->call->text();
hisGrid=ui->grid->text();
mode=ui->mode->text();
rptSent=ui->sent->text();
rptRcvd=ui->rcvd->text();
2017-07-09 20:45:53 +00:00
m_dateTimeOn = ui->start_date_time->dateTime ();
m_dateTimeOff = ui->end_date_time->dateTime ();
2013-08-10 15:29:55 +00:00
band=ui->band->text();
name=ui->name->text();
m_txPower=ui->txPower->text();
comments=ui->comments->text();
m_comments=comments;
2015-04-15 16:40:49 +00:00
QString strDialFreq(QString::number(m_dialFreq / 1.e6,'f',6));
operator_call = ui->loggedOperator->text();
//Log this QSO to file "wsjtx.log"
2014-12-03 00:06:54 +00:00
static QFile f {QDir {QStandardPaths::writableLocation (QStandardPaths::DataLocation)}.absoluteFilePath ("wsjtx.log")};
2013-08-10 15:29:55 +00:00
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 ()));
2013-08-10 15:29:55 +00:00
} else {
QString logEntry=m_dateTimeOn.date().toString("yyyy-MM-dd,") +
2017-07-09 20:45:53 +00:00
m_dateTimeOn.time().toString("hh:mm:ss,") +
m_dateTimeOff.date().toString("yyyy-MM-dd,") +
2017-07-09 20:45:53 +00:00
m_dateTimeOff.time().toString("hh:mm:ss,") + hisCall + "," +
2015-04-15 16:40:49 +00:00
hisGrid + "," + strDialFreq + "," + mode +
"," + rptSent + "," + rptRcvd + "," + m_txPower +
"," + comments + "," + name;
2013-08-10 15:29:55 +00:00
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
, operator_call
, m_myCall
, m_myGrid
, LogBook::QSOToADIF (hisCall
, hisGrid
, mode
, rptSent
, rptRcvd
, m_dateTimeOn
, m_dateTimeOff
, band
, comments
, name
, strDialFreq
, m_myCall
, m_myGrid
, m_txPower
, operator_call
, m_xSent
, m_xRcvd));
2013-08-10 15:29:55 +00:00
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);
}