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 <[email protected]>
---
 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 85bc949..b9da21f 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 af1f26e..c8402ab 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");
-- 
2.5.0

_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to