Add GUI support for exporting in CSV format

This patch adds an item to File menu to export all dives in CSV format.
Naturally this includes also the code to perform the export.

Fixes #434

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Miika Turkia 2014-04-26 10:55:41 +03:00 committed by Dirk Hohndel
parent 2b559225d6
commit f6be4ccf22
7 changed files with 47 additions and 28 deletions

2
dive.h
View file

@ -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;

View file

@ -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");
}

View file

@ -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()

View file

@ -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();

View file

@ -577,6 +577,7 @@
<addaction name="separator"/>
<addaction name="actionClose"/>
<addaction name="actionExportUDDF"/>
<addaction name="actionExport_CSV"/>
<addaction name="actionExportHTMLworldmap"/>
<addaction name="actionPrint"/>
<addaction name="actionPreferences"/>
@ -945,6 +946,11 @@
<string>&amp;Check for Updates</string>
</property>
</action>
<action name="actionExport_CSV">
<property name="text">
<string>Export CSV</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>

View file

@ -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));

View file

@ -36,6 +36,7 @@
<file>xslt/SuuntoSDM.xslt</file>
<file>xslt/udcf.xslt</file>
<file>xslt/uddf-export.xslt</file>
<file>xslt/xml2csv.xslt</file>
<file>xslt/uddf.xslt</file>
<file>xslt/sensuscsv.xslt</file>
<file>xslt/manualcsv2xml.xslt</file>