WSJT-X/widgets/ExportCabrillo.cpp

118 lines
5.2 KiB
C++
Raw Normal View History

#include "ExportCabrillo.h"
#include <QApplication>
#include <QFileDialog>
#include <QDir>
#include <QDebug>
#include "SettingsGroup.hpp"
#include "Configuration.hpp"
#include "MessageBox.hpp"
#include "models/CabrilloLog.hpp"
#include "ui_ExportCabrillo.h"
Preparation for UI i18n Re-enabling the WSJT-X i18n facilities. This allows translation files to be created for languages that are automatically used to lookup translatable strings. To enable a new language the language name must be added to the CMakeLists.txt LANGUAGES list variable in BCP47 format (i.e. en_US, en_GB, pt_PT, ...). Do one build with the CMake option UPDATE_TRANSLATIONS enabled (do not leave it enabled as there is a danger of loosing existing translated texts), that will create a fresh translations/wsjtx_<lang>.ts file which should be immediately checked in with the CMakeLists.txt change. The .ts should then be updated by the translator using the Qt Linguist tool to add translations. Check in the updated .ts file to complete the initial translation process for that language. To aid translators their WIP .ts file may be tested by releasing (using the lrelease tool or from the Linguist menu) a .qm file and placing that .qm file in the current directory before starting WSJT-X. The translations will be used if the system locale matches the file name. If the system locale does not match the file name; the language may be overridden by setting the LANG environment variable. For example if a wsjtx_pt_PT.qm file is in the current directory WSJT-X will use it for translation lookups, regardless of the current system locale setting, if the LANG variable is set to pt_PT or pt-PT. On MS Windows from a command prompt: set LANG=pt_PT C:\WSJT\wsjtx\bin\wsjtx elsewhere: LANG=pt_PT wsjtx
2019-06-06 07:56:25 -04:00
#include "moc_ExportCabrillo.cpp"
ExportCabrillo::ExportCabrillo (QSettings * settings, Configuration const * configuration
, CabrilloLog const * log, QWidget * parent)
: QDialog {parent},
settings_ {settings},
configuration_ {configuration},
log_ {log},
ui {new Ui::ExportCabrillo}
{
ui->setupUi (this);
read_settings ();
setWindowTitle (QApplication::applicationName() + " - Export Cabrillo");
connect (ui->buttonBox, &QDialogButtonBox::accepted, this, &ExportCabrillo::save_log);
}
ExportCabrillo::~ExportCabrillo ()
{
write_settings ();
}
void ExportCabrillo::read_settings ()
{
SettingsGroup group {settings_, "ExportCabrillo"};
restoreGeometry (settings_->value("window/geometry").toByteArray());
ui->location_line_edit->setText(settings_->value("Location").toString());
ui->contest_line_edit->setText(settings_->value("Contest").toString());
ui->call_line_edit->setText(settings_->value("Callsign").toString());
ui->category_op_line_edit->setText(settings_->value("Category-Operator").toString());
ui->category_xmtr_line_edit->setText(settings_->value("Category-Transmitter").toString());
ui->category_pwr_line_edit->setText(settings_->value("Category-Power").toString());
ui->category_assisted_line_edit->setText(settings_->value("Category-Assisted").toString());
ui->category_band_line_edit->setText(settings_->value("Category-Band").toString());
ui->claimed_line_edit->setText(settings_->value("Claimed-Score").toString());
ui->operators_line_edit->setText(settings_->value("Operators").toString());
ui->club_line_edit->setText(settings_->value("Club").toString());
ui->name_line_edit->setText(settings_->value("Name").toString());
ui->addr_1_line_edit->setText(settings_->value("Address1").toString());
ui->addr_2_line_edit->setText(settings_->value("Address2").toString());
}
void ExportCabrillo::write_settings ()
{
SettingsGroup group {settings_, "ExportCabrillo"};
settings_->setValue ("window/geometry", saveGeometry ());
settings_->setValue("Location",ui->location_line_edit->text());
settings_->setValue("Contest",ui->contest_line_edit->text());
settings_->setValue("Callsign",ui->call_line_edit->text());
settings_->setValue("Category-Operator",ui->category_op_line_edit->text());
settings_->setValue("Category-Transmitter",ui->category_xmtr_line_edit->text());
settings_->setValue("Category-Power",ui->category_pwr_line_edit->text());
settings_->setValue("Category-Assisted",ui->category_assisted_line_edit->text());
settings_->setValue("Category-Band",ui->category_band_line_edit->text());
settings_->setValue("Claimed-Score",ui->claimed_line_edit->text());
settings_->setValue("Operators",ui->operators_line_edit->text());
settings_->setValue("Club",ui->club_line_edit->text());
settings_->setValue("Name",ui->name_line_edit->text());
settings_->setValue("Address1",ui->addr_1_line_edit->text());
settings_->setValue("Address2",ui->addr_2_line_edit->text());
}
void ExportCabrillo::save_log ()
{
auto fname = QFileDialog::getSaveFileName (this
, tr ("Save Log File")
, configuration_->writeable_data_dir ().absolutePath ()
, tr ("Cabrillo Log (*.cbr)"));
if (fname.size ())
{
QFile f {fname};
if (f.open (QIODevice::WriteOnly | QIODevice::Text)) {
QTextStream out {&f};
out << "START-OF-LOG:3.0\n"
<< "LOCATION: " << ui->location_line_edit->text() << '\n'
<< "CONTEST: " << ui->contest_line_edit->text() << '\n'
<< "CALLSIGN: " << ui->call_line_edit->text() << '\n'
<< "CATEGORY-OPERATOR: " << ui->category_op_line_edit->text() << '\n'
<< "CATEGORY-TRANSMITTER: " << ui->category_xmtr_line_edit->text() << '\n'
<< "CATEGORY-POWER: " << ui->category_pwr_line_edit->text() << '\n'
<< "CATEGORY-ASSISTED: " << ui->category_assisted_line_edit->text() << '\n'
<< "CATEGORY-BAND: " << ui->category_band_line_edit->text() << '\n'
<< "CLAIMED-SCORE: " << ui->claimed_line_edit->text() << '\n'
<< "OPERATORS: " << ui->operators_line_edit->text() << '\n'
<< "CLUB: " << ui->club_line_edit->text() << '\n'
<< "NAME: " << ui->name_line_edit->text() << '\n'
<< "ADDRESS: " << ui->addr_1_line_edit->text() << '\n'
<< "ADDRESS: " << ui->addr_2_line_edit->text() << '\n';
if (log_) log_->export_qsos (out);
2020-06-13 11:04:41 -04:00
out << "END-OF-LOG:"
#if QT_VERSION >= QT_VERSION_CHECK (5, 15, 0)
<< Qt::endl
#else
<< endl
#endif
;
return;
} else {
auto const& message = tr ("Cannot open \"%1\" for writing: %2")
.arg (f.fileName ()).arg (f.errorString ());
MessageBox::warning_message (this, tr ("Export Cabrillo File Error"), message);
}
}
setResult (Rejected);
}