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 +#include +#include +#include + +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(" "); +} diff --git a/smtk-import/smrtk2ssrfc_window.h b/smtk-import/smrtk2ssrfc_window.h new file mode 100644 index 000000000..8d5ae9027 --- /dev/null +++ b/smtk-import/smrtk2ssrfc_window.h @@ -0,0 +1,39 @@ +#ifndef SMRTK2SSRFC_WINDOW_H +#define SMRTK2SSRFC_WINDOW_H + +#include +#include +#include + +extern "C" void smartrak_import(const char *file, struct dive_table *divetable); + +namespace Ui { +class Smrtk2ssrfcWindow; +} + +class Smrtk2ssrfcWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit Smrtk2ssrfcWindow(QWidget *parent = 0); + ~Smrtk2ssrfcWindow(); + +private: + Ui::Smrtk2ssrfcWindow *ui; + QString lastUsedDir(); + QString filter(); + void updateLastUsedDir(const QString &s); + void closeCurrentFile(); + +private +slots: + void on_inputFilesButton_clicked(); + void on_outputFileButton_clicked(); + void on_importButton_clicked(); + void on_exitButton_clicked(); + void on_outputLine_textEdited(); + void on_inputLine_textEdited(); +}; + +#endif // SMRTK2SSRFC_WINDOW_H diff --git a/smtk-import/smrtk2ssrfc_window.ui b/smtk-import/smrtk2ssrfc_window.ui new file mode 100644 index 000000000..4e5e2ecb3 --- /dev/null +++ b/smtk-import/smrtk2ssrfc_window.ui @@ -0,0 +1,823 @@ + + + Smrtk2ssrfcWindow + + + + 0 + 0 + 512 + 431 + + + + + 0 + 0 + + + + SmartTrak files importer + + + Qt::LeftToRight + + + true + + + + + + false + + + false + + + + true + + + Qt::LeftToRight + + + + + 30 + 360 + 438 + 16 + + + + + + + Qt::Horizontal + + + + + + 10 + 150 + 127 + 16 + + + + + + + QFrame::Panel + + + QFrame::Sunken + + + <html><head/><body><p><span style=" color:#6ebeb9;">Subsurface divelog</span></p></body></html> + + + + + true + + + + 142 + 150 + 241 + 22 + + + + + + + + + + 390 + 150 + 80 + 22 + + + + + + + Choose + + + + + + 10 + 120 + 113 + 16 + + + + + + + QFrame::Panel + + + QFrame::Sunken + + + <html><head/><body><p><span style=" color:#6ebeb9;">Smartrak divelog</span></p></body></html> + + + Qt::NoTextInteraction + + + + + true + + + + 142 + 120 + 241 + 22 + + + + + 0 + 0 + + + + + + + Qt::ImhNone + + + + + + 390 + 120 + 80 + 22 + + + + + + + Choose + + + + + true + + + + 50 + 380 + 401 + 22 + + + + + 0 + 0 + + + + ArrowCursor + + + false + + + + + + 0 + + + Qt::AlignCenter + + + Qt::Horizontal + + + false + + + QProgressBar::TopToBottom + + + + + + 390 + 180 + 80 + 22 + + + + + 0 + 0 + + + + + + + Exit + + + + + + 300 + 180 + 80 + 22 + + + + + 0 + 0 + + + + Qt::WheelFocus + + + Qt::PreventContextMenu + + + + + + Import + + + + + + 40 + 10 + 431 + 101 + + + + Qt::LeftToRight + + + + + + QFrame::NoFrame + + + QFrame::Plain + + + <html><head/><body><p><span style=" font-weight:600; color:#6ebeb9;">Select the .slg file(s) you want to import to Subsurface format, and the exported .xml file. It's advisable to use a new output file, as its actual content will be erased.</span></p></body></html> + + + Qt::AutoText + + + false + + + true + + + 0 + + + -1 + + + + + true + + + + -40 + -30 + 571 + 471 + + + + + + + + + + :/subsurface-icon + + + true + + + Qt::AlignCenter + + + + + + 50 + 220 + 401 + 131 + + + + + 8 + + + + false + + + Qt::ImhNone + + + QFrame::Box + + + QFrame::Sunken + + + QPlainTextEdit::NoWrap + + + Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + true + + + Import messages (Errors, warnings, etc) + + + label_4 + line + label_3 + outputLine + outputFileButton + label_2 + inputLine + inputFilesButton + progressBar + exitButton + importButton + label + plainTextEdit + + + + + + + + + 0 + 0 + 0 + + + + + + + 34 + 74 + 133 + + + + + + + 51 + 111 + 200 + + + + + + + 42 + 92 + 166 + + + + + + + 17 + 37 + 66 + + + + + + + 22 + 49 + 89 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 34 + 74 + 133 + + + + + + + 0 + 0 + 0 + + + + + + + 144 + 164 + 194 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + + 0 + 0 + 0 + + + + + + + 34 + 74 + 133 + + + + + + + 51 + 111 + 200 + + + + + + + 42 + 92 + 166 + + + + + + + 17 + 37 + 66 + + + + + + + 22 + 49 + 89 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 34 + 74 + 133 + + + + + + + 0 + 0 + 0 + + + + + + + 144 + 164 + 194 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + + 17 + 37 + 66 + + + + + + + 34 + 74 + 133 + + + + + + + 51 + 111 + 200 + + + + + + + 42 + 92 + 166 + + + + + + + 17 + 37 + 66 + + + + + + + 22 + 49 + 89 + + + + + + + 17 + 37 + 66 + + + + + + + 255 + 255 + 255 + + + + + + + 17 + 37 + 66 + + + + + + + 34 + 74 + 133 + + + + + + + 34 + 74 + 133 + + + + + + + 0 + 0 + 0 + + + + + + + 34 + 74 + 133 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + true + + + + + + + + + + + + diff --git a/smtk-import/smtk_standalone.cpp b/smtk-import/smtk_standalone.cpp new file mode 100644 index 000000000..54d5b6a99 --- /dev/null +++ b/smtk-import/smtk_standalone.cpp @@ -0,0 +1,49 @@ +#include +#include +#include "dive.h" +#include "smrtk2ssrfc_window.h" +#include +#include + +extern "C" void smartrak_import(const char *file, struct dive_table *table); + +/* + * Simple command line interface to call directly smartrak_import() or launch + * the GUI if called without arguments. + */ + +int main(int argc, char *argv[]) +{ + char *infile, *outfile; + int i; + QApplication a(argc, argv); + Smrtk2ssrfcWindow w; + + switch (argc) { + case 1: + w.show(); + return a.exec(); + break; + case 2: + qDebug() << "\nUsage:\n"; + qDebug() << "Smrtk2ssrfc importer can be used without arguments (in a graphical UI)"; + qDebug() << "or with, at least, two arguments (in a CLI, the file to be imported and"; + qDebug() << "the file to store the Subsurface formatted dives), so you have to use one"; + qDebug() << "of these examples:\n"; + qDebug() << "$smrtk2ssrfc"; + qDebug() << "or"; + qDebug() << "$smrtk2ssrfc /input/file.slg[ file_2[ file_n]] /output/file.xml\n\n"; + break; + default: + outfile = argv[argc - 1]; + qDebug() << "\n[Importing]\n"; + for(i = 1; i < argc -1; i++) { + infile = argv[i]; + qDebug() << "\t" << infile << "\n"; + smartrak_import(infile, &dive_table); + } + qDebug() << "\n[Writing]\n\t" << outfile << "\n"; + save_dives_logic(outfile, false); + break; + } +}