From cb5ab4bc8e192e65dded3bc3f3bfb703441e5436 Mon Sep 17 00:00:00 2001 From: Miika Turkia Date: Sat, 15 Feb 2014 10:51:23 +0200 Subject: Add unit support for CSV import Signed-off-by: Miika Turkia Signed-off-by: Dirk Hohndel --- dive.h | 2 +- file.c | 8 ++++++-- qt-ui/divelogimportdialog.cpp | 1 + qt-ui/divelogimportdialog.ui | 33 +++++++++++++++++++++++++++++++++ xslt/csv2xml.xslt | 34 +++++++++++++++++++++++++++++++--- 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 @@ stopdepthCheckBox CSVstopdepth + + + + 210 + 150 + 271 + 80 + + + + Units + + + + + 20 + 30 + 251 + 29 + + + + + Metric + + + + + Imperial + + + + 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 @@ + @@ -113,19 +114,39 @@ - + + + + + + + + + + + - + + + + + + + + + + + @@ -164,7 +185,14 @@ - + + + + + + + + -- cgit v1.2.3-70-g09d2