summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Miika Turkia <miika.turkia@gmail.com>2014-02-15 10:51:23 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-02-15 06:33:33 -0800
commitcb5ab4bc8e192e65dded3bc3f3bfb703441e5436 (patch)
treea115e650a96881748c8ccdd60f62e3a01e0b322f
parent31aa93857a794078c6a43e4a5b9808a95f13a04e (diff)
downloadsubsurface-cb5ab4bc8e192e65dded3bc3f3bfb703441e5436.tar.gz
Add unit support for CSV import
Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--dive.h2
-rw-r--r--file.c8
-rw-r--r--qt-ui/divelogimportdialog.cpp1
-rw-r--r--qt-ui/divelogimportdialog.ui33
-rw-r--r--xslt/csv2xml.xslt34
5 files changed, 72 insertions, 6 deletions
diff --git a/dive.h b/dive.h
index e454420eb..fcb0727df 100644
--- a/dive.h
+++ b/dive.h
@@ -648,7 +648,7 @@ extern int parse_dm4_buffer(sqlite3 *handle, const char *url, const char *buf, i
extern int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, char **error);
extern void parse_file(const char *filename, char **error);
-extern void parse_csv_file(const char *filename, int time, int depth, int temp, int po2f, int cnsf, int stopdepthf, int sepidx, const char *csvtemplate, char **error);
+extern void parse_csv_file(const char *filename, int time, int depth, int temp, int po2f, int cnsf, int stopdepthf, int sepidx, const char *csvtemplate, int units, char **error);
extern void parse_manual_file(const char *filename, int separator_index, int units, int number, int date, int time, int duration, int location, int gps, int maxdepth, int meandepth, int buddy, int notes, int weight, int tags, char **error);
extern void save_dives(const char *filename);
diff --git a/file.c b/file.c
index 08b61b234..01c519e17 100644
--- a/file.c
+++ b/file.c
@@ -385,17 +385,18 @@ void parse_file(const char *filename, char **error)
#define MAXCOLDIGITS 3
#define MAXCOLS 100
-void parse_csv_file(const char *filename, int timef, int depthf, int tempf, int po2f, int cnsf, int stopdepthf, int sepidx, const char *csvtemplate, char **error)
+void parse_csv_file(const char *filename, int timef, int depthf, int tempf, int po2f, int cnsf, int stopdepthf, int sepidx, const char *csvtemplate, int unitidx, char **error)
{
struct memblock mem;
int pnr=0;
- char *params[19];
+ char *params[21];
char timebuf[MAXCOLDIGITS];
char depthbuf[MAXCOLDIGITS];
char tempbuf[MAXCOLDIGITS];
char po2buf[MAXCOLDIGITS];
char cnsbuf[MAXCOLDIGITS];
char stopdepthbuf[MAXCOLDIGITS];
+ char unitbuf[MAXCOLDIGITS];
char separator_index[MAXCOLDIGITS];
time_t now;
struct tm *timep;
@@ -416,6 +417,7 @@ void parse_csv_file(const char *filename, int timef, int depthf, int tempf, int
snprintf(cnsbuf, MAXCOLDIGITS, "%d", cnsf);
snprintf(stopdepthbuf, MAXCOLDIGITS, "%d", stopdepthf);
snprintf(separator_index, MAXCOLDIGITS, "%d", sepidx);
+ snprintf(unitbuf, MAXCOLDIGITS, "%d", unitidx);
time(&now);
timep = localtime(&now);
strftime(curdate, sizeof(curdate), "%Y%m%d", timep);
@@ -440,6 +442,8 @@ void parse_csv_file(const char *filename, int timef, int depthf, int tempf, int
params[pnr++] = curdate;
params[pnr++] = "time";
params[pnr++] = curtime;
+ params[pnr++] = "units";
+ params[pnr++] = unitbuf;
params[pnr++] = "separatorIndex";
params[pnr++] = separator_index;
params[pnr++] = NULL;
diff --git a/qt-ui/divelogimportdialog.cpp b/qt-ui/divelogimportdialog.cpp
index 3005d1584..36e69d06f 100644
--- a/qt-ui/divelogimportdialog.cpp
+++ b/qt-ui/divelogimportdialog.cpp
@@ -66,6 +66,7 @@ void DiveLogImportDialog::on_buttonBox_accepted()
VALUE_IF_CHECKED(CSVstopdepth),
ui->CSVSeparator->currentIndex(),
specialCSV.contains(ui->knownImports->currentIndex()) ? CSVApps[ui->knownImports->currentIndex()].name.toUtf8().data() : "csv",
+ ui->CSVUnits->currentIndex(),
&error);
if (error != NULL) {
MainWindow::instance()->showError(error);
diff --git a/qt-ui/divelogimportdialog.ui b/qt-ui/divelogimportdialog.ui
index 627a12a74..e2cf958a9 100644
--- a/qt-ui/divelogimportdialog.ui
+++ b/qt-ui/divelogimportdialog.ui
@@ -239,6 +239,39 @@
<zorder>stopdepthCheckBox</zorder>
<zorder>CSVstopdepth</zorder>
</widget>
+ <widget class="QGroupBox" name="groupBox_7">
+ <property name="geometry">
+ <rect>
+ <x>210</x>
+ <y>150</y>
+ <width>271</width>
+ <height>80</height>
+ </rect>
+ </property>
+ <property name="title">
+ <string>Units</string>
+ </property>
+ <widget class="QComboBox" name="CSVUnits">
+ <property name="geometry">
+ <rect>
+ <x>20</x>
+ <y>30</y>
+ <width>251</width>
+ <height>29</height>
+ </rect>
+ </property>
+ <item>
+ <property name="text">
+ <string>Metric</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Imperial</string>
+ </property>
+ </item>
+ </widget>
+ </widget>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
diff --git a/xslt/csv2xml.xslt b/xslt/csv2xml.xslt
index ee8b7556e..5ae689a0b 100644
--- a/xslt/csv2xml.xslt
+++ b/xslt/csv2xml.xslt
@@ -11,6 +11,7 @@
<xsl:param name="stopdepthField" select="stopdepthField"/>
<xsl:param name="date" select="date"/>
<xsl:param name="time" select="time"/>
+ <xsl:param name="units" select="units"/>
<xsl:param name="separatorIndex" select="separatorIndex"/>
<xsl:output method="xml" indent="yes"/>
@@ -113,19 +114,39 @@
</xsl:choose>
</xsl:attribute>
- <xsl:attribute name="depth">
+ <xsl:variable name="depth">
<xsl:call-template name="getFieldByIndex">
<xsl:with-param name="index" select="$depthField"/>
<xsl:with-param name="line" select="$line"/>
</xsl:call-template>
+ </xsl:variable>
+ <xsl:attribute name="depth">
+ <xsl:choose>
+ <xsl:when test="$units = 0">
+ <xsl:value-of select="$depth"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$depth * 0.3048"/>
+ </xsl:otherwise>
+ </xsl:choose>
</xsl:attribute>
<xsl:if test="$tempField >= 0">
- <xsl:attribute name="temp">
+ <xsl:variable name="temp">
<xsl:call-template name="getFieldByIndex">
<xsl:with-param name="index" select="$tempField"/>
<xsl:with-param name="line" select="$line"/>
</xsl:call-template>
+ </xsl:variable>
+ <xsl:attribute name="temp">
+ <xsl:choose>
+ <xsl:when test="$units = 0">
+ <xsl:value-of select="$temp"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="concat(format-number(($temp - 32) * 5 div 9, '0.0'), ' C')"/>
+ </xsl:otherwise>
+ </xsl:choose>
</xsl:attribute>
</xsl:if>
@@ -164,7 +185,14 @@
</xsl:call-template>
</xsl:variable>
<xsl:attribute name="stopdepth">
- <xsl:copy-of select="$stopdepth"/>
+ <xsl:choose>
+ <xsl:when test="$units = 0">
+ <xsl:copy-of select="$stopdepth"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:copy-of select="format-number($stopdepth * 0.3048, '0.00')"/>
+ </xsl:otherwise>
+ </xsl:choose>
</xsl:attribute>
<xsl:attribute name="in_deco">