summaryrefslogtreecommitdiffstats
path: root/desktop-widgets/divelogimportdialog.cpp
diff options
context:
space:
mode:
authorGravatar Miika Turkia <miika.turkia@gmail.com>2016-05-05 09:26:12 +0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2016-05-05 07:28:07 -0700
commit30976c05a42909c3ec2c15d4d627ab45602825e5 (patch)
tree8248060b8fa7475d16b5ad397feb1df5a04a6603 /desktop-widgets/divelogimportdialog.cpp
parent98741c864cf995c92fb0550d8b4d9aa1585f2494 (diff)
downloadsubsurface-30976c05a42909c3ec2c15d4d627ab45602825e5.tar.gz
Parse txt formatted log files
This parses .txt log files produced by Dataplus and Oceanlog software. Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'desktop-widgets/divelogimportdialog.cpp')
-rw-r--r--desktop-widgets/divelogimportdialog.cpp74
1 files changed, 72 insertions, 2 deletions
diff --git a/desktop-widgets/divelogimportdialog.cpp b/desktop-widgets/divelogimportdialog.cpp
index c8402abb9..0a964b003 100644
--- a/desktop-widgets/divelogimportdialog.cpp
+++ b/desktop-widgets/divelogimportdialog.cpp
@@ -342,6 +342,7 @@ DiveLogImportDialog::DiveLogImportDialog(QStringList fn, QWidget *parent) : QDia
column = 0;
delta = "0";
hw = "";
+ txtLog = false;
/* Add indexes of XSLTs requiring special handling to the list */
specialCSV << SENSUS;
@@ -489,8 +490,21 @@ void DiveLogImportDialog::loadFileContents(int value, whatChanged triggeredBy)
ui->knownImports->setCurrentText("DL7");
ui->CSVUnits->setCurrentText(units);
blockSignals(false);
+ } else if (firstLine.contains("Life Time Dive")) {
+ txtLog = true;
+
+ while ((firstLine = f.readLine().trimmed()).length() >= 0 && !f.atEnd()) {
+ if (firstLine.contains("Dive Profile")) {
+ f.readLine();
+ break;
+ }
+ }
+ firstLine = f.readLine().trimmed();
+
}
+
+
// Special handling for APD Log Viewer
if ((triggeredBy == KNOWNTYPES && (value == APD || value == APD2)) || (triggeredBy == INITIAL && fileNames.first().endsWith(".apd", Qt::CaseInsensitive))) {
apd=true;
@@ -694,6 +708,13 @@ void DiveLogImportDialog::loadFileContents(int value, whatChanged triggeredBy)
break;
}
}
+ } else if (txtLog) {
+ while ((firstLine = f.readLine().trimmed()).length() >= 0 && !f.atEnd()) {
+ if (firstLine.contains("Dive Profile")) {
+ firstLine = f.readLine().trimmed();
+ break;
+ }
+ }
}
while (rows < 10 && !f.atEnd()) {
@@ -768,6 +789,51 @@ int DiveLogImportDialog::setup_csv_params(QStringList r, char **params, int pnr)
return pnr;
}
+int DiveLogImportDialog::parseTxtHeader(QString fileName, char **params, int pnr)
+{
+ QFile f(fileNames.first());
+ QString date;
+ QString time;
+ QString line;
+
+ f.open(QFile::ReadOnly);
+ while ((line = f.readLine().trimmed()).length() >= 0 && !f.atEnd()) {
+ if (line.contains("Dive Profile")) {
+ f.readLine();
+ break;
+ } else if (line.contains("Dive Date: ")) {
+ date = line.replace(QString::fromLatin1("Dive Date: "), QString::fromLatin1(""));
+
+ if (date.contains('-')) {
+ QStringList fmtDate = date.split('-');
+ date = fmtDate[0] + fmtDate[1] + fmtDate[2];
+ } else if (date.contains('/')) {
+ QStringList fmtDate = date.split('/');
+ date = fmtDate[2] + fmtDate[0] + fmtDate[1];
+ } else {
+ QStringList fmtDate = date.split('.');
+ date = fmtDate[2] + fmtDate[1] + fmtDate[0];
+ }
+ } else if (line.contains("Elapsed Dive Time: ")) {
+ // Skipping dive duration for now
+ } else if (line.contains("Dive Time: ")) {
+ time = line.replace(QString::fromLatin1("Dive Time: "), QString::fromLatin1(""));
+
+ if (time.contains(':')) {
+ QStringList fmtTime = time.split(':');
+ time = fmtTime[0] + fmtTime[1];
+
+ }
+ }
+ }
+ f.close();
+
+ params[pnr++] = strdup("date");
+ params[pnr++] = strdup(date.toLatin1());
+ params[pnr++] = strdup("time");
+ params[pnr++] = strdup(time.toLatin1());
+ return pnr;
+}
void DiveLogImportDialog::on_buttonBox_accepted()
{
@@ -832,7 +898,9 @@ void DiveLogImportDialog::on_buttonBox_accepted()
int pnr = 0;
QRegExp apdRe("^.*[/\\][0-9a-zA-Z]*_([0-9]{6})_([0-9]{6})\\.apd");
- if (apdRe.exactMatch(fileNames[i])) {
+ if (txtLog) {
+ pnr = parseTxtHeader(fileNames[i], params, pnr);
+ } else if (apdRe.exactMatch(fileNames[i])) {
params[pnr++] = strdup("date");
params[pnr++] = strdup("20" + apdRe.cap(1).toLatin1());
params[pnr++] = strdup("time");
@@ -906,7 +974,9 @@ void DiveLogImportDialog::on_buttonBox_accepted()
int pnr = 0;
QRegExp apdRe("^.*[/\\][0-9a-zA-Z]*_([0-9]{6})_([0-9]{6})\\.apd");
- if (apdRe.exactMatch(fileNames[i])) {
+ if (txtLog) {
+ pnr = parseTxtHeader(fileNames[i], params, pnr);
+ } else if (apdRe.exactMatch(fileNames[i])) {
params[pnr++] = strdup("date");
params[pnr++] = strdup("20" + apdRe.cap(1).toLatin1());
params[pnr++] = strdup("time");