diff options
author | Salvador Cuñat <salvador.cunat@gmail.com> | 2015-11-08 18:50:05 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-11-12 07:39:14 -0800 |
commit | ddc77845142c19097b5c8094d7601f78719d3e53 (patch) | |
tree | c144f5bd37c0cff89c498257f341ceac41907a3a /smtk-import/smrtk2ssrfc_window.cpp | |
parent | dc4d8f26ece3d11b0931e486c7190813afbfb6f3 (diff) | |
download | subsurface-ddc77845142c19097b5c8094d7601f78719d3e53.tar.gz |
SmartTrak import - CLI parser and GUI files
The tool can be called from CLI with or without arguments, if called with a
single argument (this is, no destination file specified) an usage message will
be displayed on the terminal; if called with arguments, these should be the .slg
file(s) to be imported and a single .xml file to store the resulting Subsurface
formatted data; if called without arguments a GUI will display to select the
file(s) to import and to store.
WARNING, if destination file exists, its previous content will be erased.
The GUI is pretty simple and don't think any more is needed but, as this is my
first QT thing, I expect those with much better knowledge of QT/C++ will
improve it as needed.
Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'smtk-import/smrtk2ssrfc_window.cpp')
-rw-r--r-- | smtk-import/smrtk2ssrfc_window.cpp | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/smtk-import/smrtk2ssrfc_window.cpp b/smtk-import/smrtk2ssrfc_window.cpp new file mode 100644 index 000000000..cb332cd81 --- /dev/null +++ b/smtk-import/smrtk2ssrfc_window.cpp @@ -0,0 +1,104 @@ +#include "smrtk2ssrfc_window.h" +#include "ui_smrtk2ssrfc_window.h" +#include "filtermodels.h" +#include "dive.h" +#include "divelist.h" +#include <QFileDialog> +#include <QFileInfo> +#include <QSettings> +#include <QDebug> + +QStringList inputFiles; +QString outputFile; + +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; +} + +QString Smrtk2ssrfcWindow::lastUsedDir() +{ + QSettings settings; + QString lastDir = QDir::homePath(); + + settings.beginGroup("FileDialog"); + if (settings.contains("LastDir")) + if (QDir::setCurrent(settings.value("LastDir").toString())) + lastDir = settings.value("LastDir").toString(); + return lastDir; +} + +void Smrtk2ssrfcWindow::updateLastUsedDir(const QString &dir) +{ + QSettings s; + s.beginGroup("FileDialog"); + s.setValue("LastDir", dir); +} + +void Smrtk2ssrfcWindow::on_inputFilesButton_clicked() +{ + inputFiles = QFileDialog::getOpenFileNames(this, tr("Open SmartTrak files"), lastUsedDir(), + tr("SmartTrak files (*.slg *.SLG);;" + "All files (*)")); + 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(), + tr("Subsurface files (*.ssrf *SSRF *.xml *.XML);;" + "All files (*)")); + 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()); + for (int i = 0; i < inputFiles.size(); ++i) { + ui->progressBar->setValue(i); + fileNamePtr = QFile::encodeName(inputFiles.at(i)); + smartrak_import(fileNamePtr.data(), &dive_table); + ui->plainTextEdit->appendPlainText(QString(get_error_string())); + } + ui->progressBar->setValue(inputFiles.size()); + save_dives_logic(outputFile.toUtf8().data(), false); + 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(" "); +} |