These files contain a bit of extra data before the actual CSV part, so
we need to skip there to show sensible information to users.

Signed-off-by: Miika Turkia <[email protected]>
---
 qt-ui/divelogimportdialog.cpp | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/qt-ui/divelogimportdialog.cpp b/qt-ui/divelogimportdialog.cpp
index 681241a..f275f2f 100644
--- a/qt-ui/divelogimportdialog.cpp
+++ b/qt-ui/divelogimportdialog.cpp
@@ -359,6 +359,7 @@ void DiveLogImportDialog::loadFileContents(int value, 
whatChanged triggeredBy)
        QStringList currColumns;
        QStringList headers;
        bool matchedSome = false;
+       bool seabear = false;
 
        // reset everything
        ColumnNameProvider *provider = new ColumnNameProvider(this);
@@ -369,6 +370,10 @@ void DiveLogImportDialog::loadFileContents(int value, 
whatChanged triggeredBy)
 
        f.open(QFile::ReadOnly);
        QString firstLine = f.readLine();
+       if (firstLine.contains("SEABEAR")) {
+               seabear = true;
+               firstLine = "Time;Depth;NDT;TTS;Ceiling;Temperature;Pressure";
+       }
        QString separator = ui->CSVSeparator->currentText() == tr("Tab") ? "\t" 
: ui->CSVSeparator->currentText();
        currColumns = firstLine.split(separator);
        if (triggeredBy == INITIAL) {
@@ -449,6 +454,23 @@ void DiveLogImportDialog::loadFileContents(int value, 
whatChanged triggeredBy)
 
        f.reset();
        int rows = 0;
+
+       /* Skipping the header of Seabear CSV file. */
+       if (seabear) {
+               /*
+                * First set of data on Seabear CSV file is metadata
+                * that is separated by an empty line (windows line
+                * termination might be encountered.
+                */
+               while (strlen(f.readLine()) > 2 && !f.atEnd());
+               /*
+                * Next we have description of the fields and two dummy
+                * lines. Separated again with an empty line from the
+                * actual data.
+                */
+               while (strlen(f.readLine()) > 2 && !f.atEnd());
+       }
+
        while (rows < 10 || !f.atEnd()) {
                QString currLine = f.readLine();
                currColumns = currLine.split(separator);
-- 
1.9.1

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

Reply via email to