From 1b74947bf56a2ef3b38470044d991a75ed0c5e30 Mon Sep 17 00:00:00 2001 From: Miika Turkia Date: Tue, 25 Nov 2014 19:47:04 +0200 Subject: Allow user to select date format on manual 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 | 72 ++++++++++++++++++++++++++++--------------- xslt/manualcsv2xml.xslt | 41 +++++++++++++++++++++--- 5 files changed, 92 insertions(+), 32 deletions(-) diff --git a/dive.h b/dive.h index 0ddc43f02..95f4d6f68 100644 --- a/dive.h +++ b/dive.h @@ -631,7 +631,7 @@ extern int parse_file(const char *filename); extern int parse_csv_file(const char *filename, int time, int depth, int temp, int po2f, int cnsf, int ndlf, int ttsf, int stopdepthf, int pressuref, int sepidx, const char *csvtemplate, int units); extern int parse_seabear_csv_file(const char *filename, int time, int depth, int temp, int po2f, int cnsf, int ndlf, int ttsf, int stopdepthf, int pressuref, int sepidx, const char *csvtemplate, int units); extern int parse_txt_file(const char *filename, const char *csv); -extern int 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); +extern int parse_manual_file(const char *filename, int separator_index, int units, int dateformat, int number, int date, int time, int duration, int location, int gps, int maxdepth, int meandepth, int buddy, int notes, int weight, int tags); extern int save_dives(const char *filename); extern int save_dives_logic(const char *filename, bool select_only); diff --git a/file.c b/file.c index f6b415e76..e755b3ad4 100644 --- a/file.c +++ b/file.c @@ -943,11 +943,11 @@ int parse_seabear_csv_file(const char *filename, int timef, int depthf, int temp return 0; } -int parse_manual_file(const char *filename, int sepidx, int units, int numberf, int datef, int timef, int durationf, int locationf, int gpsf, int maxdepthf, int meandepthf, int buddyf, int notesf, int weightf, int tagsf) +int parse_manual_file(const char *filename, int sepidx, int units, int dateformat, int numberf, int datef, int timef, int durationf, int locationf, int gpsf, int maxdepthf, int meandepthf, int buddyf, int notesf, int weightf, int tagsf) { struct memblock mem; int pnr = 0; - char *params[33]; + char *params[35]; char numberbuf[MAXCOLDIGITS]; char datebuf[MAXCOLDIGITS]; char timebuf[MAXCOLDIGITS]; @@ -962,6 +962,7 @@ int parse_manual_file(const char *filename, int sepidx, int units, int numberf, char tagsbuf[MAXCOLDIGITS]; char separator_index[MAXCOLDIGITS]; char unit[MAXCOLDIGITS]; + char datefmt[MAXCOLDIGITS]; time_t now; struct tm *timep; char curdate[9]; @@ -984,6 +985,7 @@ int parse_manual_file(const char *filename, int sepidx, int units, int numberf, snprintf(tagsbuf, MAXCOLDIGITS, "%d", tagsf); snprintf(separator_index, MAXCOLDIGITS, "%d", sepidx); snprintf(unit, MAXCOLDIGITS, "%d", units); + snprintf(datefmt, MAXCOLDIGITS, "%d", dateformat); time(&now); timep = localtime(&now); strftime(curdate, DATESTR, "%Y%m%d", timep); @@ -1024,6 +1026,8 @@ int parse_manual_file(const char *filename, int sepidx, int units, int numberf, params[pnr++] = separator_index; params[pnr++] = "units"; params[pnr++] = unit; + params[pnr++] = "datefmt"; + params[pnr++] = datefmt; params[pnr++] = NULL; if (filename == NULL) diff --git a/qt-ui/divelogimportdialog.cpp b/qt-ui/divelogimportdialog.cpp index 91c1d738e..8946e6a78 100644 --- a/qt-ui/divelogimportdialog.cpp +++ b/qt-ui/divelogimportdialog.cpp @@ -107,6 +107,7 @@ void DiveLogImportDialog::on_buttonBox_accepted() parse_manual_file(fileNames[i].toUtf8().data(), ui->ManualSeparator->currentIndex(), ui->Units->currentIndex(), + ui->DateFormat->currentIndex(), VALUE_IF_CHECKED(DiveNumber), VALUE_IF_CHECKED(Date), VALUE_IF_CHECKED(Time), VALUE_IF_CHECKED(Duration), VALUE_IF_CHECKED(Location), diff --git a/qt-ui/divelogimportdialog.ui b/qt-ui/divelogimportdialog.ui index 97b698901..accf3fe2a 100644 --- a/qt-ui/divelogimportdialog.ui +++ b/qt-ui/divelogimportdialog.ui @@ -296,6 +296,53 @@ Manual dives + + + + Field separator + + + + + + + + + + + + Choose day, month and year order for date format. The field separator can be any of the characters .-/. + + + Date format + + + + + 20 + 40 + 131 + 27 + + + + + dd.mm.yyyy + + + + + mm/dd/yyyy + + + + + yyyy-mm-dd + + + + + @@ -544,31 +591,6 @@ - - - - Field separator - - - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - diff --git a/xslt/manualcsv2xml.xslt b/xslt/manualcsv2xml.xslt index 7e138d1e0..cbfb9ea14 100644 --- a/xslt/manualcsv2xml.xslt +++ b/xslt/manualcsv2xml.xslt @@ -18,6 +18,7 @@ + @@ -79,10 +80,42 @@ - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3-70-g09d2