2017-04-27 18:13:48 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2015-11-08 17:50:05 +00:00
|
|
|
#include "smrtk2ssrfc_window.h"
|
|
|
|
#include "ui_smrtk2ssrfc_window.h"
|
2016-06-15 18:59:34 +00:00
|
|
|
#include "qt-models/filtermodels.h"
|
|
|
|
#include "core/dive.h"
|
core: introduce divelog structure
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.
Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).
The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.
To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.
The whole commit is large, but was mostly an automatic
conversion.
One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-11-08 20:31:08 +00:00
|
|
|
#include "core/divelog.h"
|
2016-06-15 18:59:34 +00:00
|
|
|
#include "core/divelist.h"
|
2019-08-05 17:41:15 +00:00
|
|
|
#include "core/errorhelper.h"
|
2018-08-18 18:07:35 +00:00
|
|
|
#include "core/settings/qPrefDisplay.h"
|
2015-11-08 17:50:05 +00:00
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
QStringList inputFiles;
|
|
|
|
QString outputFile;
|
2018-02-11 21:41:06 +00:00
|
|
|
QString error_buf;
|
|
|
|
|
2024-06-08 21:32:17 +00:00
|
|
|
void getErrorFromC(std::string buf)
|
2018-02-11 21:41:06 +00:00
|
|
|
{
|
2024-06-08 21:32:17 +00:00
|
|
|
error_buf = QString::fromStdString(std::move(buf));
|
2018-02-11 21:41:06 +00:00
|
|
|
}
|
2015-11-08 17:50:05 +00:00
|
|
|
|
|
|
|
Smrtk2ssrfcWindow::Smrtk2ssrfcWindow(QWidget *parent) :
|
|
|
|
QMainWindow(parent),
|
|
|
|
ui(new Ui::Smrtk2ssrfcWindow)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
ui->plainTextEdit->setDisabled(true);
|
|
|
|
ui->progressBar->setDisabled(true);
|
|
|
|
ui->statusBar->adjustSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
Smrtk2ssrfcWindow::~Smrtk2ssrfcWindow()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2018-06-09 14:24:39 +00:00
|
|
|
static QString lastUsedDir()
|
2015-11-08 17:50:05 +00:00
|
|
|
{
|
|
|
|
QString lastDir = QDir::homePath();
|
|
|
|
|
2018-08-18 18:07:35 +00:00
|
|
|
if (QDir(qPrefDisplay::lastDir()).exists())
|
|
|
|
lastDir = qPrefDisplay::lastDir();
|
2015-11-08 17:50:05 +00:00
|
|
|
return lastDir;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Smrtk2ssrfcWindow::updateLastUsedDir(const QString &dir)
|
|
|
|
{
|
2018-08-18 18:07:35 +00:00
|
|
|
qPrefDisplay::set_lastDir(dir);
|
2015-11-08 17:50:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Smrtk2ssrfcWindow::on_inputFilesButton_clicked()
|
|
|
|
{
|
|
|
|
inputFiles = QFileDialog::getOpenFileNames(this, tr("Open SmartTrak files"), lastUsedDir(),
|
2017-10-27 12:52:27 +00:00
|
|
|
tr("SmartTrak files") + " (*.slg);;" + tr("All files") + " (*.*)");
|
2015-11-08 17:50:05 +00:00
|
|
|
if (inputFiles.isEmpty())
|
|
|
|
return;
|
|
|
|
updateLastUsedDir(QFileInfo(inputFiles[0]).dir().path());
|
|
|
|
ui->inputLine->setText(inputFiles.join(" "));
|
|
|
|
ui->progressBar->setEnabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Smrtk2ssrfcWindow::on_outputFileButton_clicked()
|
|
|
|
{
|
|
|
|
outputFile = QFileDialog::getSaveFileName(this, tr("Open Subsurface files"), lastUsedDir(),
|
2017-10-27 12:52:27 +00:00
|
|
|
tr("Subsurface files") + " (*.ssrf *.xml);;" + tr("All files") + " (*.*)");
|
2015-11-08 17:50:05 +00:00
|
|
|
if (outputFile.isEmpty())
|
|
|
|
return;
|
|
|
|
updateLastUsedDir(QFileInfo(outputFile).dir().path());
|
|
|
|
ui->outputLine->setText(outputFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Smrtk2ssrfcWindow::on_importButton_clicked()
|
|
|
|
{
|
|
|
|
if (inputFiles.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
QByteArray fileNamePtr;
|
|
|
|
|
|
|
|
ui->plainTextEdit->setDisabled(false);
|
|
|
|
ui->progressBar->setRange(0, inputFiles.size());
|
2018-02-11 21:41:06 +00:00
|
|
|
set_error_cb(&getErrorFromC);
|
2015-11-08 17:50:05 +00:00
|
|
|
for (int i = 0; i < inputFiles.size(); ++i) {
|
|
|
|
ui->progressBar->setValue(i);
|
|
|
|
fileNamePtr = QFile::encodeName(inputFiles.at(i));
|
core: introduce divelog structure
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.
Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).
The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.
To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.
The whole commit is large, but was mostly an automatic
conversion.
One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-11-08 20:31:08 +00:00
|
|
|
smartrak_import(fileNamePtr.data(), &divelog);
|
2018-02-11 21:41:06 +00:00
|
|
|
ui->plainTextEdit->appendPlainText(error_buf);
|
2015-11-08 17:50:05 +00:00
|
|
|
}
|
|
|
|
ui->progressBar->setValue(inputFiles.size());
|
2018-09-10 12:47:56 +00:00
|
|
|
save_dives_logic(qPrintable(outputFile), false, false);
|
2015-11-08 17:50:05 +00:00
|
|
|
ui->progressBar->setDisabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Smrtk2ssrfcWindow::on_exitButton_clicked()
|
|
|
|
{
|
|
|
|
this->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Smrtk2ssrfcWindow::on_outputLine_textEdited()
|
|
|
|
{
|
|
|
|
outputFile = ui->outputLine->text();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Smrtk2ssrfcWindow::on_inputLine_textEdited()
|
|
|
|
{
|
|
|
|
inputFiles = ui->inputLine->text().split(" ");
|
|
|
|
}
|