summaryrefslogtreecommitdiffstats
path: root/qt-ui/divelogimportdialog.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'qt-ui/divelogimportdialog.cpp')
-rw-r--r--qt-ui/divelogimportdialog.cpp19
1 files changed, 17 insertions, 2 deletions
diff --git a/qt-ui/divelogimportdialog.cpp b/qt-ui/divelogimportdialog.cpp
index ebd46f2d3..3c5d595e8 100644
--- a/qt-ui/divelogimportdialog.cpp
+++ b/qt-ui/divelogimportdialog.cpp
@@ -341,11 +341,26 @@ void DiveLogImportDialog::loadFileContents() {
QStringList currColumns;
f.open(QFile::ReadOnly);
+ // guess the separator
+ QString firstLine = f.readLine();
+ QString separator;
+ int tabs = firstLine.count('\t');
+ int commas = firstLine.count(',');
+ int semis = firstLine.count(';');
+ if (tabs > commas && tabs > semis)
+ separator = "\t";
+ else if (commas > tabs && commas > semis)
+ separator = ",";
+ else if (semis > tabs && semis > commas)
+ separator = ";";
+ else
+ separator = ui->CSVSeparator->currentText() == tr("Tab") ? "\t" : ui->CSVSeparator->currentText();
+ if (ui->CSVSeparator->currentText() != separator)
+ ui->CSVSeparator->setCurrentText(separator);
+ f.reset();
int rows = 0;
while (rows < 10 || !f.atEnd()) {
QString currLine = f.readLine();
- QString separator = ui->CSVSeparator->currentText() == tr("Tab") ? "\t"
- : ui->CSVSeparator->currentText();
currColumns = currLine.split(separator);
fileColumns.append(currColumns);
rows += 1;