From 1902d527d5362308eaa31db9e864b36c54548671 Mon Sep 17 00:00:00 2001 From: Miika Turkia Date: Tue, 3 May 2016 19:47:50 +0300 Subject: [PATCH] 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 Signed-off-by: Dirk Hohndel --- core/file.c | 2 +- desktop-widgets/divelogimportdialog.cpp | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/core/file.c b/core/file.c index 85bc949fe..b9da21fb2 100644 --- a/core/file.c +++ b/core/file.c @@ -974,7 +974,7 @@ int parse_csv_file(const char *filename, char **params, int pnr, const char *csv return -1; } mem.size = ptr - (char*)mem.buffer; - } else { + } else if (strcmp(params[0], "date")) { time(&now); timep = localtime(&now); 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 #include #include +#include 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");