diff --git a/dive.h b/dive.h index 8713d8c67..5215c4997 100644 --- a/dive.h +++ b/dive.h @@ -702,7 +702,7 @@ extern int parse_manual_file(const char *filename, int separator_index, int unit extern int save_dives(const char *filename); extern int save_dives_logic(const char *filename, bool select_only); extern int save_dive(FILE *f, struct dive *dive); -extern int export_dives_uddf(const char *filename, const bool selected); +extern int export_dives_xslt(const char *filename, const bool selected, const char *export_xslt); struct git_oid; struct git_repository; diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp index a3e2e5cf8..cbabdcffe 100644 --- a/qt-ui/divelistview.cpp +++ b/qt-ui/divelistview.cpp @@ -813,7 +813,7 @@ void DiveListView::exportSelectedDivesAsUDDF() filename = QFileDialog::getSaveFileName(this, tr("Export UDDF File as"), fi.absolutePath(), tr("UDDF files (*.uddf *.UDDF)")); if (!filename.isNull() && !filename.isEmpty()) - export_dives_uddf(filename.toUtf8(), true); + export_dives_xslt(filename.toUtf8(), true, "uddf-export.xslt"); } diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index f93ad2d23..5e8459ecd 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -280,7 +280,17 @@ void MainWindow::on_actionExportUDDF_triggered() QString filename = QFileDialog::getSaveFileName(this, tr("Export UDDF File as"), fi.absolutePath(), tr("UDDF files (*.uddf *.UDDF)")); if (!filename.isNull() && !filename.isEmpty()) - export_dives_uddf(filename.toUtf8(), false); + export_dives_xslt(filename.toUtf8(), false, "uddf-export.xslt"); +} + +void MainWindow::on_actionExport_CSV_triggered() +{ + QFileInfo fi(system_default_filename()); + QString filename = QFileDialog::getSaveFileName(this, tr("Export CSV File as"), fi.absolutePath(), + tr("CSV files (*.csv *.CSV)")); + + if (!filename.isNull() && !filename.isEmpty()) + export_dives_xslt(filename.toUtf8(), false, "xml2csv.xslt"); } void MainWindow::on_actionExportHTMLworldmap_triggered() diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h index 40d32b5e5..60081e957 100644 --- a/qt-ui/mainwindow.h +++ b/qt-ui/mainwindow.h @@ -91,6 +91,7 @@ slots: void on_actionSaveAs_triggered(); void on_actionClose_triggered(); void on_actionExportUDDF_triggered(); + void on_actionExport_CSV_triggered(); void on_actionExportHTMLworldmap_triggered(); void on_actionPrint_triggered(); void on_actionPreferences_triggered(); diff --git a/qt-ui/mainwindow.ui b/qt-ui/mainwindow.ui index a2621de9a..072d321fc 100644 --- a/qt-ui/mainwindow.ui +++ b/qt-ui/mainwindow.ui @@ -294,14 +294,14 @@ - - - - Show/hide heart rate - - - ... - + + + + Show/hide heart rate + + + ... + :/icon_HR:/icon_HR @@ -312,14 +312,14 @@ 24 - - true - - - true - - - + + true + + + true + + + @@ -475,7 +475,7 @@ true - + @@ -577,6 +577,7 @@ + @@ -709,7 +710,7 @@ Ctrl+U - + Export HTML World Map @@ -945,6 +946,11 @@ &Check for Updates + + + Export CSV + + diff --git a/save-xml.c b/save-xml.c index 1db2513d0..b61f79440 100644 --- a/save-xml.c +++ b/save-xml.c @@ -618,7 +618,7 @@ int save_dives_logic(const char *filename, const bool select_only) return error; } -int export_dives_uddf(const char *filename, const bool selected) +int export_dives_xslt(const char *filename, const bool selected, const char *export_xslt) { FILE *f; struct membuffer buf = { 0 }; @@ -626,15 +626,16 @@ int export_dives_uddf(const char *filename, const bool selected) xsltStylesheetPtr xslt = NULL; xmlDoc *transformed; + if (!filename) - return report_error("No filename for UDDF export"); + return report_error("No filename for export"); /* Save XML to file and convert it into a memory buffer */ save_dives_buffer(&buf, selected); /* * Parse the memory buffer into XML document and - * transform it to UDDF format, finally dumping + * transform it to selected export format, finally dumping * the XML into a character buffer. */ doc = xmlReadMemory(buf.buffer, buf.len, "divelog", NULL, 0); @@ -642,16 +643,16 @@ int export_dives_uddf(const char *filename, const bool selected) if (!doc) return report_error("Failed to read XML memory"); - /* Convert to UDDF format */ - xslt = get_stylesheet("uddf-export.xslt"); + /* Convert to export format */ + xslt = get_stylesheet(export_xslt); if (!xslt) - return report_error("Failed to open UDDF conversion stylesheet"); + return report_error("Failed to open export conversion stylesheet"); transformed = xsltApplyStylesheet(xslt, doc, NULL); xsltFreeStylesheet(xslt); xmlFreeDoc(doc); - /* Write the transformed XML to file */ + /* Write the transformed export to file */ f = subsurface_fopen(filename, "w"); if (!f) return report_error("Failed to open %s for writing (%s)", filename, strerror(errno)); diff --git a/subsurface.qrc b/subsurface.qrc index 27716b604..d074ea324 100644 --- a/subsurface.qrc +++ b/subsurface.qrc @@ -36,6 +36,7 @@ xslt/SuuntoSDM.xslt xslt/udcf.xslt xslt/uddf-export.xslt + xslt/xml2csv.xslt xslt/uddf.xslt xslt/sensuscsv.xslt xslt/manualcsv2xml.xslt