aboutsummaryrefslogtreecommitdiffstats
path: root/desktop-widgets/mainwindow.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-10-01 14:17:38 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-10-04 10:22:11 +0200
commita4051749fdb2dc94013673702e1d1858294541bd (patch)
treed67bd9d8f4e1f7ea197f90d8eba0c3f262a12a33 /desktop-widgets/mainwindow.cpp
parent9788d73d48939031806b5e58dec497dae354d0cf (diff)
downloadsubsurface-a4051749fdb2dc94013673702e1d1858294541bd.tar.gz
Import: import Poseidon MkVI logs via DiveLogImportDialog
Poseidon MkVI logs (.txt) were special cased in MainWindow.cpp, which led to a user-interface inconsistency. In some cases [user chooses ".txt" (non-Poseidon) and ".csv"], *two* import-dialogs were shown. Move handling of Poseidon MkVI logs into DiveLogImportDialog. There are already other "special" cases handled in this dialog. At the moment, this shows the first 10 depth-values, which is kind of useless, as this will all be at surface level. We might think about something more useful. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets/mainwindow.cpp')
-rw-r--r--desktop-widgets/mainwindow.cpp60
1 files changed, 21 insertions, 39 deletions
diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp
index e6b3424e8..0ab46fafd 100644
--- a/desktop-widgets/mainwindow.cpp
+++ b/desktop-widgets/mainwindow.cpp
@@ -1742,35 +1742,6 @@ void MainWindow::importFiles(const QStringList fileNames)
refreshDisplay();
}
-void MainWindow::importTxtFiles(const QStringList fileNames)
-{
- QStringList csvFiles;
-
- if (fileNames.isEmpty())
- return;
-
- QByteArray fileNamePtr, csv;
-
- for (int i = 0; i < fileNames.size(); ++i) {
- csv = fileNamePtr = QFile::encodeName(fileNames.at(i));
- csv.replace(csv.size() - 3, 3, "csv");
-
- QFileInfo check_file(csv);
- if (check_file.exists() && check_file.isFile()) {
- if (parse_txt_file(fileNamePtr.data(), csv, &dive_table) == 0)
- csvFiles += fileNames.at(i);
- } else {
- csvFiles += fileNamePtr;
- }
- }
- if (csvFiles.size()) {
- DiveLogImportDialog *diveLogImport = new DiveLogImportDialog(csvFiles, this);
- diveLogImport->show();
- }
- process_imported_dives(false);
- refreshDisplay();
-}
-
void MainWindow::loadFiles(const QStringList fileNames)
{
if (fileNames.isEmpty()) {
@@ -1805,6 +1776,19 @@ void MainWindow::loadFiles(const QStringList fileNames)
}
}
+static const char *csvExtensions[] = {
+ ".csv", ".apd", ".zxu", ".zxl", ".txt"
+};
+
+static bool isCsvFile(const QString &s)
+{
+ for (const char *ext: csvExtensions) {
+ if (s.endsWith(ext, Qt::CaseInsensitive))
+ return true;
+ }
+ return false;
+}
+
void MainWindow::on_actionImportDiveLog_triggered()
{
QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Open dive log file"), lastUsedDir(), filter_import());
@@ -1813,12 +1797,14 @@ void MainWindow::on_actionImportDiveLog_triggered()
return;
updateLastUsedDir(QFileInfo(fileNames[0]).dir().path());
- QStringList logFiles = fileNames.filter(QRegExp("^(?!.*\\.(csv|txt|apd|zxu|zxl))", Qt::CaseInsensitive));
- QStringList csvFiles = fileNames.filter(".csv", Qt::CaseInsensitive);
- csvFiles += fileNames.filter(".apd", Qt::CaseInsensitive);
- csvFiles += fileNames.filter(".zxu", Qt::CaseInsensitive);
- csvFiles += fileNames.filter(".zxl", Qt::CaseInsensitive);
- QStringList txtFiles = fileNames.filter(".txt", Qt::CaseInsensitive);
+ QStringList logFiles;
+ QStringList csvFiles;
+ for (const QString &fn: fileNames) {
+ if (isCsvFile(fn))
+ csvFiles.append(fn);
+ else
+ logFiles.append(fn);
+ }
if (logFiles.size()) {
importFiles(logFiles);
@@ -1828,10 +1814,6 @@ void MainWindow::on_actionImportDiveLog_triggered()
DiveLogImportDialog *diveLogImport = new DiveLogImportDialog(csvFiles, this);
diveLogImport->show();
}
-
- if (txtFiles.size()) {
- importTxtFiles(txtFiles);
- }
}
void MainWindow::editCurrentDive()