diff options
author | Miika Turkia <miika.turkia@gmail.com> | 2016-05-03 19:47:50 +0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2016-05-03 09:50:32 -0700 |
commit | 1902d527d5362308eaa31db9e864b36c54548671 (patch) | |
tree | 797f1aa69aa52fc425b88dc29ef15fd18627225a /desktop-widgets/divelogimportdialog.cpp | |
parent | 029b524f37548ab9b10efa84a822ccd123ee7d9e (diff) | |
download | subsurface-1902d527d5362308eaa31db9e864b36c54548671.tar.gz |
Parse date and time from on APD import
This will parse the date and time information on CSV import if the file
name matches the one used by APD log viewer (date and time are available
in the file name). Hard coding the year to 20?? is a bit unfortunate,
but as there is only 2 digits in the year, we have to invent something.
And it would be quite optimistic to assume this will bite us back any
time soon :D
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'desktop-widgets/divelogimportdialog.cpp')
-rw-r--r-- | desktop-widgets/divelogimportdialog.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/desktop-widgets/divelogimportdialog.cpp b/desktop-widgets/divelogimportdialog.cpp index af1f26e2c..c8402abb9 100644 --- a/desktop-widgets/divelogimportdialog.cpp +++ b/desktop-widgets/divelogimportdialog.cpp @@ -5,6 +5,7 @@ #include <QShortcut> #include <QDrag> #include <QMimeData> +#include <QRegExp> static QString subsurface_mimedata = "subsurface/csvcolumns"; static QString subsurface_index = "subsurface/csvindex"; @@ -827,9 +828,16 @@ void DiveLogImportDialog::on_buttonBox_accepted() sample->tts.seconds *= 60; } } else { - char *params[47]; + char *params[49]; int pnr = 0; + QRegExp apdRe("^.*[/\\][0-9a-zA-Z]*_([0-9]{6})_([0-9]{6})\\.apd"); + if (apdRe.exactMatch(fileNames[i])) { + params[pnr++] = strdup("date"); + params[pnr++] = strdup("20" + apdRe.cap(1).toLatin1()); + params[pnr++] = strdup("time"); + params[pnr++] = strdup("1" + apdRe.cap(2).toLatin1()); + } pnr = setup_csv_params(r, params, pnr); parse_csv_file(fileNames[i].toUtf8().data(), params, pnr - 1, specialCSV.contains(ui->knownImports->currentIndex()) ? CSVApps[ui->knownImports->currentIndex()].name.toUtf8().data() : "csv"); @@ -894,9 +902,16 @@ void DiveLogImportDialog::on_buttonBox_accepted() parse_manual_file(fileNames[i].toUtf8().data(), params, pnr - 1); } else { - char *params[47]; + char *params[49]; int pnr = 0; + QRegExp apdRe("^.*[/\\][0-9a-zA-Z]*_([0-9]{6})_([0-9]{6})\\.apd"); + if (apdRe.exactMatch(fileNames[i])) { + params[pnr++] = strdup("date"); + params[pnr++] = strdup("20" + apdRe.cap(1).toLatin1()); + params[pnr++] = strdup("time"); + params[pnr++] = strdup("1" + apdRe.cap(2).toLatin1()); + } pnr = setup_csv_params(r, params, pnr); parse_csv_file(fileNames[i].toUtf8().data(), params, pnr - 1, specialCSV.contains(ui->knownImports->currentIndex()) ? CSVApps[ui->knownImports->currentIndex()].name.toUtf8().data() : "csv"); |