diff options
-rw-r--r-- | parse-xml.c | 1 | ||||
-rw-r--r-- | qt-ui/divelogimportdialog.cpp | 4 | ||||
-rw-r--r-- | qt-ui/divelogimportdialog.h | 2 | ||||
-rw-r--r-- | subsurface.qrc | 1 | ||||
-rw-r--r-- | xslt/subsurfacecsv.xslt | 360 |
5 files changed, 367 insertions, 1 deletions
diff --git a/parse-xml.c b/parse-xml.c index 42f5fe123..ac7820971 100644 --- a/parse-xml.c +++ b/parse-xml.c @@ -2558,6 +2558,7 @@ static struct xslt_files { { "Divinglog", "DivingLog.xslt", NULL }, { "csv", "csv2xml.xslt", NULL }, { "sensuscsv", "sensuscsv.xslt", NULL }, + { "SubsurfaceCSV", "subsurfacecsv.xslt", NULL }, { "manualcsv", "manualcsv2xml.xslt", NULL }, { NULL, } }; diff --git a/qt-ui/divelogimportdialog.cpp b/qt-ui/divelogimportdialog.cpp index b91cc6782..5c2a04434 100644 --- a/qt-ui/divelogimportdialog.cpp +++ b/qt-ui/divelogimportdialog.cpp @@ -12,6 +12,7 @@ const DiveLogImportDialog::CSVAppConfig DiveLogImportDialog::CSVApps[CSVAPPS] = { "XP5", 1, 2, 10, -1, -1, -1, -1, -1, -1, "Tab" }, { "SensusCSV", 10, 11, -1, -1, -1, -1, -1, -1, -1, "," }, { "Seabear CSV", 1, 2, 6, -1, -1, 3, 4, 5, 7, ";" }, + { "SubsurfaceCSV", -1, -1, -1, -1, -1, -1, -1, -1, -1, "," }, { NULL, } }; @@ -25,6 +26,7 @@ DiveLogImportDialog::DiveLogImportDialog(QStringList *fn, QWidget *parent) : QDi /* Add indexes of XSLTs requiring special handling to the list */ specialCSV << 3; + specialCSV << 5; for (int i = 0; !CSVApps[i].name.isNull(); ++i) ui->knownImports->addItem(CSVApps[i].name); @@ -160,8 +162,10 @@ void DiveLogImportDialog::on_knownImports_currentIndexChanged(int index) { if (specialCSV.contains(index)) { ui->groupBox_3->setEnabled(false); + ui->CSVUnits->setEnabled(false); } else { ui->groupBox_3->setEnabled(true); + ui->CSVUnits->setEnabled(true); } if (index == 0) return; diff --git a/qt-ui/divelogimportdialog.h b/qt-ui/divelogimportdialog.h index 3faceeceb..36314f7f5 100644 --- a/qt-ui/divelogimportdialog.h +++ b/qt-ui/divelogimportdialog.h @@ -64,7 +64,7 @@ private: QString separator; }; -#define CSVAPPS 6 +#define CSVAPPS 7 static const CSVAppConfig CSVApps[CSVAPPS]; }; diff --git a/subsurface.qrc b/subsurface.qrc index e1103bb92..6faf96f76 100644 --- a/subsurface.qrc +++ b/subsurface.qrc @@ -45,6 +45,7 @@ <file>xslt/xml2manualcsv.xslt</file> <file>xslt/uddf.xslt</file> <file>xslt/sensuscsv.xslt</file> + <file>xslt/subsurfacecsv.xslt</file> <file>xslt/manualcsv2xml.xslt</file> <file>xslt/shearwater.xslt</file> <file alias="icon_lung">icons/gas.png</file> diff --git a/xslt/subsurfacecsv.xslt b/xslt/subsurfacecsv.xslt new file mode 100644 index 000000000..ec6e871e4 --- /dev/null +++ b/xslt/subsurfacecsv.xslt @@ -0,0 +1,360 @@ +<?xml version="1.0"?> +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> + <xsl:include href="commonTemplates.xsl"/> + <xsl:strip-space elements="*"/> + <xsl:param name="separatorIndex" select="separatorIndex"/> + <xsl:param name="units" select="units"/> + <xsl:output method="xml" encoding="utf-8" indent="yes"/> + + <xsl:variable name="lf"><xsl:text> +</xsl:text></xsl:variable> + <xsl:variable name="fs"> + <xsl:choose> + <xsl:when test="$separatorIndex = 0"><xsl:text> </xsl:text></xsl:when> + <xsl:when test="$separatorIndex = 2"><xsl:text>;</xsl:text></xsl:when> + <xsl:otherwise><xsl:text>,</xsl:text></xsl:otherwise> + </xsl:choose> + </xsl:variable> + + <xsl:template match="/"> + <divelog program="subsurface-import" version="2"> + <dives> + <xsl:call-template name="printLine"> + <xsl:with-param name="line" select="substring-before(substring-after(//SubsurfaceCSV, $lf), $lf)"/> + <xsl:with-param name="remaining" select="substring-after(substring-after(//SubsurfaceCSV, $lf), $lf)"/> + </xsl:call-template> + </dives> + </divelog> + </xsl:template> + + <xsl:template name="printLine"> + <xsl:param name="line"/> + <xsl:param name="remaining"/> + + <xsl:call-template name="printFields"> + <xsl:with-param name="line" select="$line"/> + </xsl:call-template> + + <xsl:if test="$remaining != ''"> + <xsl:call-template name="printLine"> + <xsl:with-param name="line" select="substring-before($remaining, $lf)"/> + <xsl:with-param name="remaining" select="substring-after($remaining, $lf)"/> + </xsl:call-template> + </xsl:if> + </xsl:template> + + <xsl:template name="printFields"> + <xsl:param name="line"/> + + + <dive> + <xsl:attribute name="date"> + <xsl:call-template name="getFieldByIndex"> + <xsl:with-param name="index" select="1"/> + <xsl:with-param name="line" select="$line"/> + </xsl:call-template> + </xsl:attribute> + + <xsl:attribute name="time"> + <xsl:call-template name="getFieldByIndex"> + <xsl:with-param name="index" select="2"/> + <xsl:with-param name="line" select="$line"/> + </xsl:call-template> + </xsl:attribute> + + <xsl:attribute name="number"> + <xsl:call-template name="getFieldByIndex"> + <xsl:with-param name="index" select="0"/> + <xsl:with-param name="line" select="$line"/> + </xsl:call-template> + </xsl:attribute> + + <xsl:attribute name="duration"> + <xsl:call-template name="getFieldByIndex"> + <xsl:with-param name="index" select="3"/> + <xsl:with-param name="line" select="$line"/> + </xsl:call-template> + </xsl:attribute> + + <xsl:attribute name="tags"> + <xsl:call-template name="getFieldByIndex"> + <xsl:with-param name="index" select="22"/> + <xsl:with-param name="line" select="$line"/> + </xsl:call-template> + </xsl:attribute> + + <xsl:variable name="rating"> + <xsl:call-template name="getFieldByIndex"> + <xsl:with-param name="index" select="18"/> + <xsl:with-param name="line" select="$line"/> + </xsl:call-template> + </xsl:variable> + <xsl:if test="$rating != ''"> + <xsl:attribute name="rating"> + <xsl:value-of select="$rating"/> + </xsl:attribute> + </xsl:if> + + <xsl:variable name="visibility"> + <xsl:call-template name="getFieldByIndex"> + <xsl:with-param name="index" select="19"/> + <xsl:with-param name="line" select="$line"/> + </xsl:call-template> + </xsl:variable> + <xsl:if test="$visibility != ''"> + <xsl:attribute name="visibility"> + <xsl:value-of select="$visibility"/> + </xsl:attribute> + </xsl:if> + + <divecomputerid deviceid="ffffffff" model="csv" /> + + <depth> + <xsl:variable name="max"> + <xsl:call-template name="getFieldByIndex"> + <xsl:with-param name="index" select="4"/> + <xsl:with-param name="line" select="$line"/> + </xsl:call-template> + </xsl:variable> + <xsl:variable name="mean"> + <xsl:call-template name="getFieldByIndex"> + <xsl:with-param name="index" select="5"/> + <xsl:with-param name="line" select="$line"/> + </xsl:call-template> + </xsl:variable> + <xsl:if test="$max != ''"> + <xsl:attribute name="max"> + <xsl:value-of select="$max"/> + </xsl:attribute> + </xsl:if> + <xsl:if test="$mean != ''"> + <xsl:attribute name="mean"> + <xsl:value-of select="$mean"/> + </xsl:attribute> + </xsl:if> + </depth> + + <divetemperature> + <xsl:variable name="air"> + <xsl:call-template name="getFieldByIndex"> + <xsl:with-param name="index" select="6"/> + <xsl:with-param name="line" select="$line"/> + </xsl:call-template> + </xsl:variable> + <xsl:variable name="water"> + <xsl:call-template name="getFieldByIndex"> + <xsl:with-param name="index" select="7"/> + <xsl:with-param name="line" select="$line"/> + </xsl:call-template> + </xsl:variable> + <xsl:if test="$air != ''"> + <xsl:attribute name="air"> + <xsl:value-of select="$air"/> + </xsl:attribute> + </xsl:if> + <xsl:if test="$water != ''"> + <xsl:attribute name="water"> + <xsl:value-of select="$water"/> + </xsl:attribute> + </xsl:if> + </divetemperature> + + <cylinder> + <xsl:variable name="size"> + <xsl:call-template name="getFieldByIndex"> + <xsl:with-param name="index" select="8"/> + <xsl:with-param name="line" select="$line"/> + </xsl:call-template> + </xsl:variable> + <xsl:variable name="start"> + <xsl:call-template name="getFieldByIndex"> + <xsl:with-param name="index" select="9"/> + <xsl:with-param name="line" select="$line"/> + </xsl:call-template> + </xsl:variable> + <xsl:variable name="end"> + <xsl:call-template name="getFieldByIndex"> + <xsl:with-param name="index" select="10"/> + <xsl:with-param name="line" select="$line"/> + </xsl:call-template> + </xsl:variable> + <xsl:variable name="o2"> + <xsl:call-template name="getFieldByIndex"> + <xsl:with-param name="index" select="11"/> + <xsl:with-param name="line" select="$line"/> + </xsl:call-template> + </xsl:variable> + <xsl:variable name="he"> + <xsl:call-template name="getFieldByIndex"> + <xsl:with-param name="index" select="12"/> + <xsl:with-param name="line" select="$line"/> + </xsl:call-template> + </xsl:variable> + <xsl:if test="$size != ''"> + <xsl:attribute name="size"> + <xsl:value-of select="$size"/> + </xsl:attribute> + </xsl:if> + <xsl:if test="$start != ''"> + <xsl:attribute name="start"> + <xsl:value-of select="$start"/> + </xsl:attribute> + </xsl:if> + <xsl:if test="$end != ''"> + <xsl:attribute name="end"> + <xsl:value-of select="$end"/> + </xsl:attribute> + </xsl:if> + <xsl:if test="$o2 != ''"> + <xsl:attribute name="o2"> + <xsl:value-of select="$o2"/> + </xsl:attribute> + </xsl:if> + <xsl:if test="$he != ''"> + <xsl:attribute name="he"> + <xsl:value-of select="$he"/> + </xsl:attribute> + </xsl:if> + </cylinder> + + <location> + <xsl:variable name="gps"> + <xsl:call-template name="getFieldByIndex"> + <xsl:with-param name="index" select="14"/> + <xsl:with-param name="line" select="$line"/> + </xsl:call-template> + </xsl:variable> + <xsl:variable name="location"> + <xsl:call-template name="getFieldByIndex"> + <xsl:with-param name="index" select="13"/> + <xsl:with-param name="line" select="$line"/> + </xsl:call-template> + </xsl:variable> + <xsl:if test="$gps != ''"> + <xsl:attribute name="gps"> + <xsl:value-of select="$gps"/> + </xsl:attribute> + </xsl:if> + <xsl:if test="$location != ''"> + <xsl:value-of select="$location"/> + </xsl:if> + </location> + + <xsl:variable name="dm"> + <xsl:call-template name="getFieldByIndex"> + <xsl:with-param name="index" select="15"/> + <xsl:with-param name="line" select="$line"/> + </xsl:call-template> + </xsl:variable> + <xsl:if test="$dm != ''"> + <divemaster> + <xsl:value-of select="$dm"/> + </divemaster> + </xsl:if> + + <xsl:variable name="buddy"> + <xsl:call-template name="getFieldByIndex"> + <xsl:with-param name="index" select="16"/> + <xsl:with-param name="line" select="$line"/> + </xsl:call-template> + </xsl:variable> + <xsl:if test="$buddy != ''"> + <buddy> + <xsl:value-of select="$buddy"/> + </buddy> + </xsl:if> + + <xsl:variable name="suit"> + <xsl:call-template name="getFieldByIndex"> + <xsl:with-param name="index" select="17"/> + <xsl:with-param name="line" select="$line"/> + </xsl:call-template> + </xsl:variable> + <xsl:if test="$suit != ''"> + <suit> + <xsl:value-of select="$suit"/> + </suit> + </xsl:if> + + <xsl:variable name="notes"> + <xsl:call-template name="getFieldByIndex"> + <xsl:with-param name="index" select="20"/> + <xsl:with-param name="line" select="$line"/> + </xsl:call-template> + </xsl:variable> + <xsl:if test="$notes != ''"> + <notes> + <xsl:value-of select="$notes"/> + </notes> + </xsl:if> + + <xsl:variable name="weight"> + <xsl:call-template name="getFieldByIndex"> + <xsl:with-param name="index" select="21"/> + <xsl:with-param name="line" select="$line"/> + </xsl:call-template> + </xsl:variable> + <xsl:if test="$weight != ''"> + <weightsystem description="unknown"> + <xsl:attribute name="weight"> + <xsl:value-of select="$weight"/> + </xsl:attribute> + </weightsystem> + </xsl:if> + + </dive> + </xsl:template> + + <xsl:template name="getFieldByIndex"> + <xsl:param name="index"/> + <xsl:param name="line"/> + <xsl:choose> + <xsl:when test="$index > 0"> + <xsl:choose> + <xsl:when test="substring($line, 1, 1) = '"'"> + <xsl:call-template name="getFieldByIndex"> + <xsl:with-param name="index" select="$index -1"/> + <xsl:with-param name="line" select="substring-after($line, $fs)"/> + </xsl:call-template> + </xsl:when> + <xsl:otherwise> + <xsl:call-template name="getFieldByIndex"> + <xsl:with-param name="index" select="$index -1"/> + <xsl:with-param name="line" select="substring-after($line, $fs)"/> + </xsl:call-template> + </xsl:otherwise> + </xsl:choose> + </xsl:when> + <xsl:otherwise> + <xsl:choose> + <xsl:when test="substring($line, 1, 1) = '"'"> + <xsl:choose> + <xsl:when test="substring-before($line,'"$fs') != ''"> + <xsl:value-of select="substring-before($line,'"$fs')"/> + </xsl:when> + <xsl:otherwise> + <xsl:if test="substring-after($line, '"$fs') = ''"> + <xsl:value-of select="substring-before(substring-after($line, '"'), '"')"/> + </xsl:if> + </xsl:otherwise> + </xsl:choose> + </xsl:when> + + <xsl:otherwise> + <xsl:choose> + <xsl:when test="substring-before($line,$fs) != ''"> + <xsl:value-of select="substring-before($line,$fs)"/> + </xsl:when> + <xsl:otherwise> + <xsl:if test="substring-after($line, $fs) = ''"> + <xsl:value-of select="$line"/> + </xsl:if> + </xsl:otherwise> + </xsl:choose> + </xsl:otherwise> + </xsl:choose> + </xsl:otherwise> + </xsl:choose> + + </xsl:template> +</xsl:stylesheet> |