Handle XSLT based imports correctly

XSLT conversions create V2 XML files, but we shouldn't abort when we parse
those without having the user informed about the potential slowness - all
XSLT based imports are slow, anyway.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2015-04-22 13:20:27 -07:00
parent 959077c66b
commit 6f7e3d04cb
3 changed files with 10 additions and 5 deletions

1
dive.h
View file

@ -51,6 +51,7 @@ extern "C" {
extern int last_xml_version;
extern bool abort_read_of_old_file;
extern bool v2_question_shown;
extern bool imported_via_xslt;
enum dive_comp_type {OC, CCR, PSCR, FREEDIVE, NUM_DC_TYPE}; // Flags (Open-circuit and Closed-circuit-rebreather) for setting dive computer type
enum cylinderuse {OC_GAS, DILUENT, OXYGEN, NUM_GAS_USE}; // The different uses for cylinders

View file

@ -24,6 +24,7 @@ int metric = 1;
int last_xml_version = -1;
bool abort_read_of_old_file = false;
bool v2_question_shown = false;
bool imported_via_xslt = false;
static xmlDoc *test_xslt_transforms(xmlDoc *doc, const char **params);
@ -1681,7 +1682,7 @@ static bool entry(const char *name, char *buf)
if (!strncmp(name, "version.program", sizeof("version.program") - 1) ||
!strncmp(name, "version.divelog", sizeof("version.divelog") - 1)) {
last_xml_version = atoi(buf);
if (last_xml_version < 3 && !v2_question_shown) {
if (last_xml_version < 3 && !v2_question_shown && !imported_via_xslt) {
// let's ask the user what they want to do about reverse geo coding
// and warn them that opening older XML files can take a while
// since C code shouldn't call the UI we set a global flag and bail
@ -1953,7 +1954,7 @@ int parse_xml_buffer(const char *url, const char *buffer, int size,
}
dive_end();
xmlFreeDoc(doc);
imported_via_xslt = false;
return ret;
}
@ -3154,7 +3155,7 @@ static xmlDoc *test_xslt_transforms(xmlDoc *doc, const char **params)
}
free((void *)attribute);
}
imported_via_xslt = true;
xmlSubstituteEntitiesDefault(1);
xslt = get_stylesheet(info->file);
if (xslt == NULL) {

View file

@ -574,6 +574,7 @@ void DiveLogImportDialog::loadFileContents(int value, whatChanged triggeredBy)
void DiveLogImportDialog::on_buttonBox_accepted()
{
imported_via_xslt = true;
QStringList r = resultModel->result();
if (ui->knownImports->currentText() != "Manual import") {
for (int i = 0; i < fileNames.size(); ++i) {
@ -592,9 +593,10 @@ void DiveLogImportDialog::on_buttonBox_accepted()
specialCSV.contains(ui->knownImports->currentIndex()) ? CSVApps[ui->knownImports->currentIndex()].name.toUtf8().data() : "csv",
ui->CSVUnits->currentIndex(),
delta.toUtf8().data()
) < 0)
) < 0) {
imported_via_xslt = false;
return;
}
// Seabear CSV stores NDL and TTS in Minutes, not seconds
struct dive *dive = dive_table.dives[dive_table.nr - 1];
for(int s_nr = 0 ; s_nr <= dive->dc.samples ; s_nr++) {
@ -667,6 +669,7 @@ void DiveLogImportDialog::on_buttonBox_accepted()
}
process_dives(true, false);
MainWindow::instance()->refreshDisplay();
imported_via_xslt = false;
}
TagDragDelegate::TagDragDelegate(QObject *parent) : QStyledItemDelegate(parent)