diff options
-rw-r--r-- | core/dive.h | 2 | ||||
-rw-r--r-- | core/save-xml.c | 16 | ||||
-rw-r--r-- | desktop-widgets/divelogexportdialog.cpp | 18 |
3 files changed, 23 insertions, 13 deletions
diff --git a/core/dive.h b/core/dive.h index 72928c5ec..517c18c8b 100644 --- a/core/dive.h +++ b/core/dive.h @@ -304,7 +304,7 @@ extern int save_dives_logic(const char *filename, bool select_only, bool anonymi extern int save_dive(FILE *f, struct dive *dive, bool anonymize); extern int export_dives_xslt(const char *filename, const bool selected, const int units, const char *export_xslt, bool anonymize); -extern int save_dive_sites_logic(const char *filename, bool select_only, bool anonymize); +extern int save_dive_sites_logic(const char *filename, const struct dive_site *sites[], int nr_sites, bool anonymize); struct membuffer; extern void save_one_dive_to_mb(struct membuffer *b, struct dive *dive, bool anonymize); diff --git a/core/save-xml.c b/core/save-xml.c index c2e9828d1..356ee36a7 100644 --- a/core/save-xml.c +++ b/core/save-xml.c @@ -811,20 +811,14 @@ int export_dives_xslt(const char *filename, const bool selected, const int units return res; } -static void save_dive_sites_buffer(struct membuffer *b, const bool select_only, bool anonymize) +static void save_dive_sites_buffer(struct membuffer *b, const struct dive_site *sites[], int nr_sites, bool anonymize) { int i; put_format(b, "<divesites program='subsurface' version='%d'>\n", DATAFORMAT_VERSION); /* save the dive sites */ - for (i = 0; i < dive_site_table.nr; i++) { - struct dive_site *ds = get_dive_site(i, &dive_site_table); - /* Don't export empty dive sites */ - if (dive_site_is_empty(ds)) - continue; - /* Only write used dive sites when exporting selected dives */ - if (select_only && !is_dive_site_selected(ds)) - continue; + for (i = 0; i < nr_sites; i++) { + const struct dive_site *ds = sites[i]; put_format(b, "<site uuid='%8x'", ds->uuid); show_utf8_blanked(b, ds->name, " name='", "'", 1, anonymize); @@ -848,13 +842,13 @@ static void save_dive_sites_buffer(struct membuffer *b, const bool select_only, put_format(b, "</divesites>\n"); } -int save_dive_sites_logic(const char *filename, const bool select_only, bool anonymize) +int save_dive_sites_logic(const char *filename, const struct dive_site *sites[], int nr_sites, bool anonymize) { struct membuffer buf = { 0 }; FILE *f; int error = 0; - save_dive_sites_buffer(&buf, select_only, anonymize); + save_dive_sites_buffer(&buf, sites, nr_sites, anonymize); if (same_string(filename, "-")) { f = stdout; diff --git a/desktop-widgets/divelogexportdialog.cpp b/desktop-widgets/divelogexportdialog.cpp index 9bf8c16a8..2b1409aea 100644 --- a/desktop-widgets/divelogexportdialog.cpp +++ b/desktop-widgets/divelogexportdialog.cpp @@ -130,6 +130,21 @@ void DiveLogExportDialog::on_exportGroup_buttonClicked(QAbstractButton*) showExplanation(); } +static std::vector<const dive_site *> getDiveSitesToExport(bool selectedOnly) +{ + std::vector<const dive_site *> res; + res.reserve(dive_site_table.nr); + for (int i = 0; i < dive_site_table.nr; i++) { + struct dive_site *ds = get_dive_site(i, &dive_site_table); + if (dive_site_is_empty(ds)) + continue; + if (selectedOnly && !is_dive_site_selected(ds)) + continue; + res.push_back(ds); + } + return res; +} + void DiveLogExportDialog::on_buttonBox_accepted() { QString filename; @@ -178,7 +193,8 @@ void DiveLogExportDialog::on_buttonBox_accepted() if (!filename.contains('.')) filename.append(".xml"); QByteArray bt = QFile::encodeName(filename); - save_dive_sites_logic(bt.data(), ui->exportSelected->isChecked(), ui->anonymize->isChecked()); + std::vector<const dive_site *> sites = getDiveSitesToExport(ui->exportSelected->isChecked()); + save_dive_sites_logic(bt.data(), &sites[0], (int)sites.size(), ui->anonymize->isChecked()); } } else if (ui->exportImageDepths->isChecked()) { filename = QFileDialog::getSaveFileName(this, tr("Save image depths"), lastDir); |