filter: load filter presets from XML files

This is a bit painful: since we don't want to modify the filter
presets when the user imports (as opposed to opens) a log,
we have to provide a table where the parser stores the presets.
Calling the parser is getting quite unwieldy, since many tables
are passed. We probably should introduce a structure representing
a full log-book at one point, which collects all the things that
are saved to the log.

Apart from that, this is simply the counterpart to saving to XML.
The interpretation of the string data is performed by core
functions, not the parser itself to avoid code duplication with
the git parser.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2020-06-17 22:45:33 +02:00 committed by Dirk Hohndel
parent cef15c978d
commit 41cf83583d
21 changed files with 273 additions and 107 deletions

View file

@ -76,7 +76,8 @@ out:
}
static void zip_read(struct zip_file *file, const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
static void zip_read(struct zip_file *file, const char *filename, struct dive_table *table, struct trip_table *trips,
struct dive_site_table *sites, filter_preset_table_t *filter_presets)
{
int size = 1024, n, read = 0;
char *mem = malloc(size);
@ -87,11 +88,12 @@ static void zip_read(struct zip_file *file, const char *filename, struct dive_ta
mem = realloc(mem, size);
}
mem[read] = 0;
(void) parse_xml_buffer(filename, mem, read, table, trips, sites, NULL);
(void) parse_xml_buffer(filename, mem, read, table, trips, sites, filter_presets, NULL);
free(mem);
}
int try_to_open_zip(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
int try_to_open_zip(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
filter_preset_table_t *filter_presets)
{
int success = 0;
/* Grr. libzip needs to re-open the file, it can't take a buffer */
@ -106,7 +108,7 @@ int try_to_open_zip(const char *filename, struct dive_table *table, struct trip_
/* skip parsing the divelogs.de pictures */
if (strstr(zip_get_name(zip, index, 0), "pictures/"))
continue;
zip_read(file, filename, table, trips, sites);
zip_read(file, filename, table, trips, sites, filter_presets);
zip_fclose(file);
success++;
}
@ -126,7 +128,6 @@ static int db_test_func(void *param, int columns, char **data, char **column)
return *data[0] == '0';
}
static int try_to_open_db(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
{
sqlite3 *handle;
@ -225,7 +226,8 @@ static int try_to_open_db(const char *filename, struct memblock *mem, struct div
* Followed by the data values (all comma-separated, all one long line).
*/
static int open_by_filename(const char *filename, const char *fmt, struct memblock *mem,
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
filter_preset_table_t *filter_presets)
{
// hack to be able to provide a comment for the translated string
static char *csv_warning = QT_TRANSLATE_NOOP3("gettextFromC",
@ -234,7 +236,7 @@ static int open_by_filename(const char *filename, const char *fmt, struct memblo
/* Suunto Dive Manager files: SDE, ZIP; divelogs.de files: DLD */
if (!strcasecmp(fmt, "SDE") || !strcasecmp(fmt, "ZIP") || !strcasecmp(fmt, "DLD"))
return try_to_open_zip(filename, table, trips, sites);
return try_to_open_zip(filename, table, trips, sites, filter_presets);
/* CSV files */
if (!strcasecmp(fmt, "CSV"))
@ -255,17 +257,18 @@ static int open_by_filename(const char *filename, const char *fmt, struct memblo
return 0;
}
static int parse_file_buffer(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
static int parse_file_buffer(const char *filename, struct memblock *mem, struct dive_table *table,
struct trip_table *trips, struct dive_site_table *sites, filter_preset_table_t *filter_presets)
{
int ret;
char *fmt = strrchr(filename, '.');
if (fmt && (ret = open_by_filename(filename, fmt + 1, mem, table, trips, sites)) != 0)
if (fmt && (ret = open_by_filename(filename, fmt + 1, mem, table, trips, sites, filter_presets)) != 0)
return ret;
if (!mem->size || !mem->buffer)
return report_error("Out of memory parsing file %s\n", filename);
return parse_xml_buffer(filename, mem->buffer, mem->size, table, trips, sites, NULL);
return parse_xml_buffer(filename, mem->buffer, mem->size, table, trips, sites, filter_presets, NULL);
}
int check_git_sha(const char *filename, struct git_repository **git_p, const char **branch_p)
@ -302,7 +305,7 @@ int check_git_sha(const char *filename, struct git_repository **git_p, const cha
return 1;
}
int parse_file(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
int parse_file(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, filter_preset_table_t *filter_presets)
{
struct git_repository *git;
const char *branch = NULL;
@ -372,7 +375,7 @@ int parse_file(const char *filename, struct dive_table *table, struct trip_table
return 0;
}
ret = parse_file_buffer(filename, &mem, table, trips, sites);
ret = parse_file_buffer(filename, &mem, table, trips, sites, filter_presets);
free(mem.buffer);
return ret;
}

View file

@ -2,6 +2,8 @@
#ifndef FILE_H
#define FILE_H
#include "filterpreset.h"
#include <sys/stat.h>
#include <stdio.h>
@ -24,8 +26,8 @@ extern int datatrak_import(struct memblock *mem, struct memblock *wl_mem, struct
extern void ostctools_import(const char *file, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
extern int readfile(const char *filename, struct memblock *mem);
extern int parse_file(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
extern int try_to_open_zip(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
extern int parse_file(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, filter_preset_table_t *filter_presets);
extern int try_to_open_zip(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, filter_preset_table_t *filter_presets);
// Platform specific functions
extern int subsurface_rename(const char *path, const char *newpath);

View file

@ -104,7 +104,8 @@ static char *parse_dan_new_line(char *buf, const char *NL)
static int try_to_xslt_open_csv(const char *filename, struct memblock *mem, const char *tag);
static int parse_dan_format(const char *filename, char **params, int pnr, struct dive_table *table,
struct trip_table *trips, struct dive_site_table *sites)
struct trip_table *trips, filter_preset_table_t *filter_presets,
struct dive_site_table *sites)
{
int ret = 0, i;
size_t end_ptr = 0;
@ -214,7 +215,7 @@ static int parse_dan_format(const char *filename, char **params, int pnr, struct
}
}
params[pnr_local] = NULL;
ret |= parse_xml_buffer(filename, "<csv></csv>", 11, table, trips, sites, (const char **)params);
ret |= parse_xml_buffer(filename, "<csv></csv>", 11, table, trips, sites, filter_presets, (const char **)params);
continue;
}
@ -271,7 +272,7 @@ static int parse_dan_format(const char *filename, char **params, int pnr, struct
if (try_to_xslt_open_csv(filename, &mem_csv, "csv"))
return -1;
ret |= parse_xml_buffer(filename, mem_csv.buffer, mem_csv.size, table, trips, sites, (const char **)params);
ret |= parse_xml_buffer(filename, mem_csv.buffer, mem_csv.size, table, trips, sites, filter_presets, (const char **)params);
end_ptr += ptr - (char *)mem_csv.buffer;
free(mem_csv.buffer);
}
@ -284,7 +285,8 @@ static int parse_dan_format(const char *filename, char **params, int pnr, struct
}
int parse_csv_file(const char *filename, char **params, int pnr, const char *csvtemplate,
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
filter_preset_table_t *filter_presets)
{
int ret, i;
struct memblock mem;
@ -304,7 +306,7 @@ int parse_csv_file(const char *filename, char **params, int pnr, const char *csv
mem.size = 0;
if (!strcmp("DL7", csvtemplate)) {
return parse_dan_format(filename, params, pnr, table, trips, sites);
return parse_dan_format(filename, params, pnr, table, trips, sites, filter_presets);
} else if (strcmp(params[0], "date")) {
time(&now);
timep = localtime(&now);
@ -339,7 +341,7 @@ int parse_csv_file(const char *filename, char **params, int pnr, const char *csv
fprintf(stderr, "%s/xslt/%s -\n", SUBSURFACE_SOURCE, csvtemplate);
}
#endif
ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, trips, sites, (const char **)params);
ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, trips, sites, filter_presets, (const char **)params);
free(mem.buffer);
for (i = 0; params[i]; i += 2)
@ -806,15 +808,15 @@ int parse_txt_file(const char *filename, const char *csv, struct dive_table *tab
#define SBPARAMS 40
static int parse_seabear_csv_file(const char *filename, char **params, int pnr, const char *csvtemplate,
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
int parse_seabear_log(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, filter_preset_table_t *filter_presets);
int parse_seabear_log(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, filter_preset_table_t *filter_presets)
{
char *params[SBPARAMS];
int pnr = 0;
pnr = parse_seabear_header(filename, params, pnr);
if (parse_seabear_csv_file(filename, params, pnr, "csv", table, trips, sites) < 0) {
if (parse_seabear_csv_file(filename, params, pnr, "csv", table, trips, sites, filter_presets) < 0) {
return -1;
}
@ -823,7 +825,8 @@ int parse_seabear_log(const char *filename, struct dive_table *table, struct tri
static int parse_seabear_csv_file(const char *filename, char **params, int pnr, const char *csvtemplate,
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
filter_preset_table_t *filter_presets)
{
int ret, i;
struct memblock mem;
@ -942,7 +945,7 @@ static int parse_seabear_csv_file(const char *filename, char **params, int pnr,
fprintf(stderr, "xslt/csv2xml.xslt\n");
}
ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, trips, sites, (const char **)params);
ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, trips, sites, filter_presets, (const char **)params);
free(mem.buffer);
for (i = 0; params[i]; i += 2)
free(params[i + 1]);
@ -950,7 +953,8 @@ static int parse_seabear_csv_file(const char *filename, char **params, int pnr,
return ret;
}
int parse_manual_file(const char *filename, char **params, int pnr, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
int parse_manual_file(const char *filename, char **params, int pnr, struct dive_table *table, struct trip_table *trips,
struct dive_site_table *sites, filter_preset_table_t *filter_presets)
{
struct memblock mem;
time_t now;
@ -989,7 +993,7 @@ int parse_manual_file(const char *filename, char **params, int pnr, struct dive_
fprintf(stderr, "%s/xslt/manualcsv2xml.xslt -\n", SUBSURFACE_SOURCE);
}
#endif
ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, trips, sites, (const char **)params);
ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, trips, sites, filter_presets, (const char **)params);
free(mem.buffer);
for (i = 0; i < pnr - 2; ++i)

View file

@ -2,6 +2,8 @@
#ifndef IMPORTCSV_H
#define IMPORTCSV_H
#include "filterpreset.h"
enum csv_format {
CSV_DEPTH,
CSV_TEMP,
@ -21,12 +23,15 @@ enum csv_format {
extern "C" {
#endif
int parse_csv_file(const char *filename, char **params, int pnr, const char *csvtemplate, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
int parse_csv_file(const char *filename, char **params, int pnr, const char *csvtemplate, struct dive_table *table,
struct trip_table *trips, struct dive_site_table *sites, filter_preset_table_t *filter_presets);
int try_to_open_csv(struct memblock *mem, enum csv_format type, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
int parse_txt_file(const char *filename, const char *csv, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
int parse_seabear_log(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
int parse_manual_file(const char *filename, char **params, int pnr, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
int parse_seabear_log(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
filter_preset_table_t *filter_presets);
int parse_manual_file(const char *filename, char **params, int pnr, struct dive_table *table, struct trip_table *trips,
struct dive_site_table *sites, filter_preset_table_t *filter_presets);
#ifdef __cplusplus
}

View file

@ -1416,6 +1416,50 @@ static void try_to_fill_dive_site(struct parser_state *state, const char *name,
nonmatch("divesite", name, buf);
}
static void try_to_fill_filter(struct filter_preset *filter, const char *name, char *buf)
{
start_match("filterpreset", name, buf);
char *s = NULL;
if (MATCH("name", utf8_string, &s)) {
filter_preset_set_name(filter, s);
free(s);
return;
}
nonmatch("filterpreset", name, buf);
}
static void try_to_fill_fulltext(const char *name, char *buf, struct parser_state *state)
{
start_match("fulltext", name, buf);
if (MATCH("mode", utf8_string, &state->fulltext_string_mode))
return;
if (MATCH("fulltext", utf8_string, &state->fulltext))
return;
nonmatch("fulltext", name, buf);
}
static void try_to_fill_filter_constraint(const char *name, char *buf, struct parser_state *state)
{
start_match("fulltext", name, buf);
if (MATCH("type", utf8_string, &state->filter_constraint_type))
return;
if (MATCH("string_mode", utf8_string, &state->filter_constraint_string_mode))
return;
if (MATCH("range_mode", utf8_string, &state->filter_constraint_range_mode))
return;
if (MATCH("negate", get_bool, &state->filter_constraint_negate))
return;
if (MATCH("constraint", utf8_string, &state->filter_constraint))
return;
nonmatch("fulltext", name, buf);
}
static bool entry(const char *name, char *buf, struct parser_state *state)
{
if (!strncmp(name, "version.program", sizeof("version.program") - 1) ||
@ -1435,6 +1479,18 @@ static bool entry(const char *name, char *buf, struct parser_state *state)
try_to_fill_dive_site(state, name, buf);
return true;
}
if (state->in_filter_constraint) {
try_to_fill_filter_constraint(name, buf, state);
return true;
}
if (state->in_fulltext) {
try_to_fill_fulltext(name, buf, state);
return true;
}
if (state->cur_filter) {
try_to_fill_filter(state->cur_filter, name, buf);
return true;
}
if (!state->cur_event.deleted) {
try_to_fill_event(name, buf, state);
return true;
@ -1567,6 +1623,9 @@ static struct nesting {
{ "divecomputerid", dc_settings_start, dc_settings_end },
{ "settings", settings_start, settings_end },
{ "site", dive_site_start, dive_site_end },
{ "filterpreset", filter_preset_start, filter_preset_end },
{ "fulltext", fulltext_start, fulltext_end },
{ "constraint", filter_constraint_start, filter_constraint_end },
{ "dive", dive_start, dive_end },
{ "Dive", dive_start, dive_end },
{ "trip", trip_start, trip_end },
@ -1662,7 +1721,7 @@ static const char *preprocess_divelog_de(const char *buffer)
int parse_xml_buffer(const char *url, const char *buffer, int size,
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
const char **params)
filter_preset_table_t *filter_presets, const char **params)
{
UNUSED(size);
xmlDoc *doc;
@ -1674,6 +1733,7 @@ int parse_xml_buffer(const char *url, const char *buffer, int size,
state.target_table = table;
state.trips = trips;
state.sites = sites;
state.filter_presets = filter_presets;
doc = xmlReadMemory(res, strlen(res), url, NULL, 0);
if (!doc)
doc = xmlReadMemory(res, strlen(res), url, "latin1", 0);

View file

@ -31,6 +31,7 @@ void free_parser_state(struct parser_state *state)
free_dive(state->cur_dive);
free_trip(state->cur_trip);
free_dive_site(state->cur_dive_site);
free_filter_preset(state->cur_filter);
free((void *)state->cur_extra_data.key);
free((void *)state->cur_extra_data.value);
free((void *)state->cur_settings.dc.model);
@ -39,6 +40,12 @@ void free_parser_state(struct parser_state *state)
free((void *)state->cur_settings.dc.firmware);
free(state->country);
free(state->city);
free(state->fulltext);
free(state->fulltext_string_mode);
free(state->filter_constraint_type);
free(state->filter_constraint_string_mode);
free(state->filter_constraint_range_mode);
free(state->filter_constraint);
}
/*
@ -223,7 +230,64 @@ void dive_site_end(struct parser_state *state)
state->cur_dive_site = NULL;
}
// now we need to add the code to parse the parts of the divesite enry
void filter_preset_start(struct parser_state *state)
{
if (state->cur_filter)
return;
state->cur_filter = alloc_filter_preset();
}
void filter_preset_end(struct parser_state *state)
{
add_filter_preset_to_table(state->cur_filter, state->filter_presets);
free_filter_preset(state->cur_filter);
state->cur_filter = NULL;
}
void fulltext_start(struct parser_state *state)
{
if (!state->cur_filter)
return;
state->in_fulltext = true;
}
void fulltext_end(struct parser_state *state)
{
if (!state->in_fulltext)
return;
filter_preset_set_fulltext(state->cur_filter, state->fulltext, state->fulltext_string_mode);
free(state->fulltext);
free(state->fulltext_string_mode);
state->fulltext = NULL;
state->fulltext_string_mode = NULL;
state->in_fulltext = false;
}
void filter_constraint_start(struct parser_state *state)
{
if (!state->cur_filter)
return;
state->in_filter_constraint = true;
}
void filter_constraint_end(struct parser_state *state)
{
if (!state->in_filter_constraint)
return;
filter_preset_add_constraint(state->cur_filter, state->filter_constraint_type, state->filter_constraint_string_mode,
state->filter_constraint_range_mode, state->filter_constraint_negate, state->filter_constraint);
free(state->filter_constraint_type);
free(state->filter_constraint_string_mode);
free(state->filter_constraint_range_mode);
free(state->filter_constraint);
state->filter_constraint_type = NULL;
state->filter_constraint_string_mode = NULL;
state->filter_constraint_range_mode = NULL;
state->filter_constraint_negate = false;
state->filter_constraint = NULL;
state->in_filter_constraint = false;
}
void dive_start(struct parser_state *state)
{
@ -456,4 +520,3 @@ int atoi_n(char *ptr, unsigned int len)
}
return 0;
}

View file

@ -5,6 +5,7 @@
#define MAX_EVENT_NAME 128
#include "dive.h" // for struct event!
#include "filterpreset.h"
#include <sqlite3.h>
@ -51,11 +52,21 @@ struct parser_state {
struct dive_trip *cur_trip; /* owning */
struct sample *cur_sample; /* non-owning */
struct picture cur_picture; /* owning */
struct filter_preset *cur_filter; /* owning */
char *fulltext; /* owning */
char *fulltext_string_mode; /* owning */
char *filter_constraint_type; /* owning */
char *filter_constraint_string_mode; /* owning */
char *filter_constraint_range_mode; /* owning */
bool filter_constraint_negate;
char *filter_constraint; /* owning */
char *country, *city; /* owning */
int taxonomy_category, taxonomy_origin;
bool in_settings;
bool in_userid;
bool in_fulltext;
bool in_filter_constraint;
struct tm cur_tm;
int lastcylinderindex, next_o2_sensor;
int o2pressure_sensor;
@ -65,6 +76,7 @@ struct parser_state {
struct dive_table *target_table; /* non-owning */
struct trip_table *trips; /* non-owning */
struct dive_site_table *sites; /* non-owning */
filter_preset_table_t *filter_presets; /* non-owning */
sqlite3 *sql_handle; /* for SQL based parsers */
event_allocation_t event_allocation;
@ -100,6 +112,12 @@ void dive_site_start(struct parser_state *state);
void dive_site_end(struct parser_state *state);
void dive_start(struct parser_state *state);
void dive_end(struct parser_state *state);
void filter_preset_start(struct parser_state *state);
void filter_preset_end(struct parser_state *state);
void filter_constraint_start(struct parser_state *state);
void filter_constraint_end(struct parser_state *state);
void fulltext_start(struct parser_state *state);
void fulltext_end(struct parser_state *state);
void trip_start(struct parser_state *state);
void trip_end(struct parser_state *state);
void picture_start(struct parser_state *state);
@ -121,7 +139,8 @@ void add_dive_site(char *ds_name, struct dive *dive, struct parser_state *state)
int atoi_n(char *ptr, unsigned int len);
void parse_xml_init(void);
int parse_xml_buffer(const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, const char **params);
int parse_xml_buffer(const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
filter_preset_table_t *filter_presets, const char **params);
void parse_xml_exit(void);
int parse_dm4_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
int parse_dm5_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);

View file

@ -10,6 +10,7 @@
#include <QRegExp>
#include <QUndoStack>
#include <QPainter>
#include "core/filterpreset.h"
#include "core/qthelper.h"
#include "core/divesite.h"
#include "core/trip.h"
@ -908,11 +909,12 @@ void DiveLogImportDialog::on_buttonBox_accepted()
struct dive_table table = empty_dive_table;
struct trip_table trips = empty_trip_table;
struct dive_site_table sites = empty_dive_site_table;
filter_preset_table_t filter_presets;
QStringList r = resultModel->result();
if (ui->knownImports->currentText() != "Manual import") {
for (int i = 0; i < fileNames.size(); ++i) {
if (ui->knownImports->currentText() == "Seabear CSV") {
parse_seabear_log(qPrintable(fileNames[i]), &table, &trips, &sites);
parse_seabear_log(qPrintable(fileNames[i]), &table, &trips, &sites, &filter_presets);
} else if (ui->knownImports->currentText() == "Poseidon MkVI") {
QPair<QString, QString> pair = poseidonFileNames(fileNames[i]);
parse_txt_file(qPrintable(pair.second), qPrintable(pair.first), &table, &trips, &sites);
@ -932,7 +934,7 @@ void DiveLogImportDialog::on_buttonBox_accepted()
pnr = setup_csv_params(r, params, pnr);
parse_csv_file(qPrintable(fileNames[i]), params, pnr - 1,
specialCSV.contains(ui->knownImports->currentIndex()) ? qPrintable(CSVApps[ui->knownImports->currentIndex()].name) : "csv",
&table, &trips, &sites);
&table, &trips, &sites, &filter_presets);
}
}
} else {
@ -998,7 +1000,7 @@ void DiveLogImportDialog::on_buttonBox_accepted()
params[pnr++] = intdup(r.indexOf(tr("Rating")));
params[pnr++] = NULL;
parse_manual_file(qPrintable(fileNames[i]), params, pnr - 1, &table, &trips, &sites);
parse_manual_file(qPrintable(fileNames[i]), params, pnr - 1, &table, &trips, &sites, &filter_presets);
} else {
char *params[53];
int pnr = 0;
@ -1015,7 +1017,7 @@ void DiveLogImportDialog::on_buttonBox_accepted()
pnr = setup_csv_params(r, params, pnr);
parse_csv_file(qPrintable(fileNames[i]), params, pnr - 1,
specialCSV.contains(ui->knownImports->currentIndex()) ? qPrintable(CSVApps[ui->knownImports->currentIndex()].name) : "csv",
&table, &trips, &sites);
&table, &trips, &sites, &filter_presets);
}
}
}

View file

@ -530,7 +530,7 @@ void MainWindow::on_actionCloudstorageopen_triggered()
showProgressBar();
QByteArray fileNamePtr = QFile::encodeName(filename);
if (!parse_file(fileNamePtr.data(), &dive_table, &trip_table, &dive_site_table))
if (!parse_file(fileNamePtr.data(), &dive_table, &trip_table, &dive_site_table, &filter_preset_table))
setCurrentFile(fileNamePtr.data());
process_loaded_dives();
hideProgressBar();
@ -1549,10 +1549,11 @@ void MainWindow::importFiles(const QStringList fileNames)
struct dive_table table = empty_dive_table;
struct trip_table trips = empty_trip_table;
struct dive_site_table sites = empty_dive_site_table;
filter_preset_table_t filter_presets;
for (int i = 0; i < fileNames.size(); ++i) {
fileNamePtr = QFile::encodeName(fileNames.at(i));
parse_file(fileNamePtr.data(), &table, &trips, &sites);
parse_file(fileNamePtr.data(), &table, &trips, &sites, &filter_presets);
}
QString source = fileNames.size() == 1 ? fileNames[0] : tr("multiple files");
Command::importDives(&table, &trips, &sites, IMPORT_MERGE_ALL_TRIPS, source);
@ -1569,7 +1570,7 @@ void MainWindow::loadFiles(const QStringList fileNames)
showProgressBar();
for (int i = 0; i < fileNames.size(); ++i) {
fileNamePtr = QFile::encodeName(fileNames.at(i));
if (!parse_file(fileNamePtr.data(), &dive_table, &trip_table, &dive_site_table)) {
if (!parse_file(fileNamePtr.data(), &dive_table, &trip_table, &dive_site_table, &filter_preset_table)) {
setCurrentFile(fileNamePtr.data());
addRecentFile(fileNamePtr, false);
}
@ -1646,7 +1647,7 @@ void MainWindow::on_actionImportDiveSites_triggered()
for (const QString &s: fileNames) {
QByteArray fileNamePtr = QFile::encodeName(s);
parse_file(fileNamePtr.data(), &table, &trips, &sites);
parse_file(fileNamePtr.data(), &table, &trips, &sites, &filter_preset_table);
}
// The imported dive sites still have pointers to imported dives - remove them
for (int i = 0; i < sites.nr; ++i)

View file

@ -456,7 +456,8 @@ void DivelogsDeWebServices::buttonClicked(QAbstractButton *button)
struct dive_table table = empty_dive_table;
struct trip_table trips = empty_trip_table;
struct dive_site_table sites = empty_dive_site_table;
parse_file(QFile::encodeName(zipFile.fileName()), &table, &trips, &sites);
filter_preset_table_t filter_presets;
parse_file(QFile::encodeName(zipFile.fileName()), &table, &trips, &sites, &filter_presets);
Command::importDives(&table, &trips, &sites, IMPORT_MERGE_ALL_TRIPS, QStringLiteral("divelogs.de"));
/* store last entered user/pass in config */

View file

@ -44,7 +44,7 @@ int main(int argc, char **argv)
qDebug() << "need --source and --output";
exit(1);
}
int ret = parse_file(qPrintable(source), &dive_table, &trip_table, &dive_site_table);
int ret = parse_file(qPrintable(source), &dive_table, &trip_table, &dive_site_table, &filter_preset_table);
if (ret) {
fprintf(stderr, "parse_file returned %d\n", ret);
exit(1);

View file

@ -353,7 +353,7 @@ void QMLManager::openLocalThenRemote(QString url)
* we try to open this), parse_file (which is called by openAndMaybeSync) will ALWAYS connect
* to the remote and populate the cache.
* Otherwise parse_file will respect the git_local_only flag and only update if that isn't set */
int error = parse_file(encodedFilename.constData(), &dive_table, &trip_table, &dive_site_table);
int error = parse_file(encodedFilename.constData(), &dive_table, &trip_table, &dive_site_table, &filter_preset_table);
if (error) {
/* there can be 2 reasons for this:
* 1) we have cloud credentials, but there is no local repo (yet).
@ -451,7 +451,8 @@ void QMLManager::mergeLocalRepo()
struct dive_table table = empty_dive_table;
struct trip_table trips = empty_trip_table;
struct dive_site_table sites = empty_dive_site_table;
parse_file(qPrintable(nocloud_localstorage()), &table, &trips, &sites);
filter_preset_table_t filter_presets;
parse_file(qPrintable(nocloud_localstorage()), &table, &trips, &sites, &filter_presets);
add_imported_dives(&table, &trips, &sites, IMPORT_MERGE_ALL_TRIPS);
}
@ -525,7 +526,7 @@ void QMLManager::finishSetup()
qPrefCloudStorage::set_cloud_verification_status(qPrefCloudStorage::CS_NOCLOUD);
saveCloudCredentials(qPrefCloudStorage::cloud_storage_email(), qPrefCloudStorage::cloud_storage_password(), qPrefCloudStorage::cloud_storage_pin());
appendTextToLog(tr("working in no-cloud mode"));
int error = parse_file(existing_filename, &dive_table, &trip_table, &dive_site_table);
int error = parse_file(existing_filename, &dive_table, &trip_table, &dive_site_table, &filter_preset_table);
if (error) {
// we got an error loading the local file
setNotificationText(tr("Error parsing local storage, giving up"));
@ -709,7 +710,7 @@ void QMLManager::loadDivesWithValidCredentials()
error = git_load_dives(git, branch, &dive_table, &trip_table, &dive_site_table);
} else {
appendTextToLog(QString("didn't receive valid git repo, try again"));
error = parse_file(fileNamePrt.data(), &dive_table, &trip_table, &dive_site_table);
error = parse_file(fileNamePrt.data(), &dive_table, &trip_table, &dive_site_table, &filter_preset_table);
}
setDiveListProcessing(false);
if (!error) {
@ -2235,9 +2236,10 @@ void QMLManager::importCacheRepo(QString repo)
struct dive_table table = empty_dive_table;
struct trip_table trips = empty_trip_table;
struct dive_site_table sites = empty_dive_site_table;
filter_preset_table_t filter_presets;
QString repoPath = QString("%1/cloudstorage/%2").arg(system_default_directory()).arg(repo);
appendTextToLog(QString("importing %1").arg(repoPath));
parse_file(qPrintable(repoPath), &table, &trips, &sites);
parse_file(qPrintable(repoPath), &table, &trips, &sites, &filter_presets);
add_imported_dives(&table, &trips, &sites, IMPORT_MERGE_ALL_TRIPS);
changesNeedSaving();
}

View file

@ -19,7 +19,7 @@ void TestAirPressure::get_dives()
struct dive *dive;
verbose = 1;
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/TestAtmPress.xml", &dive_table, &trip_table, &dive_site_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/TestAtmPress.xml", &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
dive = get_dive(0);
dive->selected = true;
QVERIFY(dive != NULL);
@ -54,7 +54,7 @@ void TestAirPressure::testWriteReadBackAirPressure()
dive->surface_pressure.mbar = ap;
QCOMPARE(save_dives("./testout.ssrf"), 0);
clear_dive_file_data();
QCOMPARE(parse_file("./testout.ssrf", &dive_table, &trip_table, &dive_site_table), 0);
QCOMPARE(parse_file("./testout.ssrf", &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
dive = get_dive(0);
QVERIFY(dive != NULL);
dive->selected = true;

View file

@ -7,7 +7,7 @@
void TestDiveSiteDuplication::testReadV2()
{
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/TwoTimesTwo.ssrf", &dive_table, &trip_table, &dive_site_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/TwoTimesTwo.ssrf", &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
QCOMPARE(dive_site_table.nr, 2);
}

View file

@ -153,7 +153,7 @@ void TestGitStorage::initTestCase()
// cleanup local and remote branches
localRemoteCleanup();
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
}
void TestGitStorage::cleanupTestCase()
@ -185,7 +185,7 @@ void TestGitStorage::testGitStorageLocal()
{
// test writing and reading back from local git storage
git_repository *repo;
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/SampleDivesV2.ssrf", &dive_table, &trip_table, &dive_site_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/SampleDivesV2.ssrf", &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
QFETCH(QString, testDirName);
QFETCH(QString, prefixRead);
QFETCH(QString, prefixWrite);
@ -198,7 +198,7 @@ void TestGitStorage::testGitStorageLocal()
QCOMPARE(save_dives(qPrintable(repoNameWrite + "[test]")), 0);
QCOMPARE(save_dives("./SampleDivesV3.ssrf"), 0);
clear_dive_file_data();
QCOMPARE(parse_file(qPrintable(repoNameRead + "[test]"), &dive_table, &trip_table, &dive_site_table), 0);
QCOMPARE(parse_file(qPrintable(repoNameRead + "[test]"), &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
QCOMPARE(save_dives("./SampleDivesV3viagit.ssrf"), 0);
QFile org("./SampleDivesV3.ssrf");
org.open(QFile::ReadOnly);
@ -216,10 +216,10 @@ void TestGitStorage::testGitStorageCloud()
// test writing and reading back from cloud storage
// connect to the ssrftest repository on the cloud server
// and repeat the same test as before with the local git storage
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/SampleDivesV2.ssrf", &dive_table, &trip_table, &dive_site_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/SampleDivesV2.ssrf", &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0);
clear_dive_file_data();
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
QCOMPARE(save_dives("./SampleDivesV3viacloud.ssrf"), 0);
QFile org("./SampleDivesV3.ssrf");
org.open(QFile::ReadOnly);
@ -237,8 +237,8 @@ void TestGitStorage::testGitStorageCloudOfflineSync()
// make a change to local cache repo (pretending that we did some offline changes)
// and then open the remote one again and check that things were propagated correctly
// read the local repo from the previous test and add dive 10
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test10.xml", &dive_table, &trip_table, &dive_site_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test10.xml", &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
// calling process_loaded_dives() sorts the table, but calling add_imported_dives()
// causes it to try to update the window title... let's not do that
process_loaded_dives();
@ -249,7 +249,7 @@ void TestGitStorage::testGitStorageCloudOfflineSync()
clear_dive_file_data();
// now pretend that we are online again and open the cloud storage and compare
git_local_only = false;
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
QCOMPARE(save_dives("./SampleDivesV3plus10viacloud.ssrf"), 0);
QFile org("./SampleDivesV3plus10local.ssrf");
org.open(QFile::ReadOnly);
@ -264,7 +264,7 @@ void TestGitStorage::testGitStorageCloudOfflineSync()
QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0);
clear_dive_file_data();
moveDir(localCacheDir, localCacheDir + "save");
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
QCOMPARE(save_dives("./SampleDivesV3plus10fromcloud.ssrf"), 0);
org.close();
org.open(QFile::ReadOnly);
@ -293,8 +293,8 @@ void TestGitStorage::testGitStorageCloudMerge()
// (1) open the repo, add dive test11 and save to the cloud
git_local_only = false;
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test11.xml", &dive_table, &trip_table, &dive_site_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test11.xml", &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
process_loaded_dives();
QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0);
clear_dive_file_data();
@ -305,27 +305,27 @@ void TestGitStorage::testGitStorageCloudMerge()
// (3) open the repo from the old cache and add dive test12 while offline
git_local_only = true;
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test12.xml", &dive_table, &trip_table, &dive_site_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test12.xml", &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
process_loaded_dives();
QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0);
clear_dive_file_data();
// (4) now take things back online
git_local_only = false;
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
clear_dive_file_data();
// (5) now we should have all the dives in our repo on the second client
// first create the reference data from the xml files:
QCOMPARE(parse_file("./SampleDivesV3plus10local.ssrf", &dive_table, &trip_table, &dive_site_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test11.xml", &dive_table, &trip_table, &dive_site_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test12.xml", &dive_table, &trip_table, &dive_site_table), 0);
QCOMPARE(parse_file("./SampleDivesV3plus10local.ssrf", &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test11.xml", &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test12.xml", &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
process_loaded_dives();
QCOMPARE(save_dives("./SampleDivesV3plus10-11-12.ssrf"), 0);
// then load from the cloud
clear_dive_file_data();
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
process_loaded_dives();
QCOMPARE(save_dives("./SampleDivesV3plus10-11-12-merged.ssrf"), 0);
// finally compare what we have
@ -342,7 +342,7 @@ void TestGitStorage::testGitStorageCloudMerge()
// (6) move ourselves back to the first client and compare data there
moveDir(localCacheDir + "client1", localCacheDir);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
process_loaded_dives();
QCOMPARE(save_dives("./SampleDivesV3plus10-11-12-merged-client1.ssrf"), 0);
QFile client1("./SampleDivesV3plus10-11-12-merged-client1.ssrf");
@ -358,7 +358,7 @@ void TestGitStorage::testGitStorageCloudMerge2()
// edit the same dive in the cloud repo
// merge
// (1) open repo, delete second dive, save offline
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
process_loaded_dives();
struct dive *dive = get_dive(1);
delete_single_dive(1);
@ -372,7 +372,7 @@ void TestGitStorage::testGitStorageCloudMerge2()
moveDir(localCacheDir, localCacheDir + "save");
// (3) now we open the cloud storage repo and modify that second dive
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
process_loaded_dives();
dive = get_dive(1);
QVERIFY(dive != NULL);
@ -384,7 +384,7 @@ void TestGitStorage::testGitStorageCloudMerge2()
// (4) move the saved local cache backinto place and try to open the cloud repo
// -> this forces a merge
moveDir(localCacheDir + "save", localCacheDir);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
QCOMPARE(save_dives("./SampleDivesMinus1-merged.ssrf"), 0);
QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0);
QFile org("./SampleDivesMinus1-merged.ssrf");
@ -407,7 +407,7 @@ void TestGitStorage::testGitStorageCloudMerge3()
// (1) open repo, edit notes of first three dives
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
process_loaded_dives();
struct dive *dive;
QVERIFY((dive = get_dive(0)) != 0);
@ -423,7 +423,7 @@ void TestGitStorage::testGitStorageCloudMerge3()
clear_dive_file_data();
// (2) make different edits offline
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
process_loaded_dives();
QVERIFY((dive = get_dive(0)) != 0);
free(dive->notes);
@ -442,7 +442,7 @@ void TestGitStorage::testGitStorageCloudMerge3()
// (3) simulate a second system by moving the cache away and open the cloud storage repo and modify
// those first dive notes differently while online
moveDir(localCacheDir, localCacheDir + "save");
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
process_loaded_dives();
QVERIFY((dive = get_dive(0)) != 0);
free(dive->notes);
@ -458,7 +458,7 @@ void TestGitStorage::testGitStorageCloudMerge3()
// (4) move the saved local cache back into place and open the cloud repo -> this forces a merge
moveDir(localCacheDir + "save", localCacheDir);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
QCOMPARE(save_dives("./SampleDivesMerge3.ssrf"), 0);
// we are not trying to compare this to a pre-determined result... what this test
// checks is that there are no parsing errors with the merge

View file

@ -25,9 +25,10 @@ void TestMerge::testMergeEmpty()
struct dive_table table = empty_dive_table;
struct trip_table trips = empty_trip_table;
struct dive_site_table sites = empty_dive_site_table;
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &table, &trips, &sites), 0);
filter_preset_table_t filter_presets;
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &table, &trips, &sites, &filter_presets), 0);
add_imported_dives(&table, &trips, &sites, IMPORT_MERGE_ALL_TRIPS);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &table, &trips, &sites), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &table, &trips, &sites, &filter_presets), 0);
add_imported_dives(&table, &trips, &sites, IMPORT_MERGE_ALL_TRIPS);
QCOMPARE(save_dives("./testmerge47+48.ssrf"), 0);
QFile org(SUBSURFACE_TEST_DATA "/dives/test47+48.xml");
@ -51,9 +52,10 @@ void TestMerge::testMergeBackwards()
struct dive_table table = empty_dive_table;
struct trip_table trips = empty_trip_table;
struct dive_site_table sites = empty_dive_site_table;
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &table, &trips, &sites), 0);
filter_preset_table_t filter_presets;
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &table, &trips, &sites, &filter_presets), 0);
add_imported_dives(&table, &trips, &sites, IMPORT_MERGE_ALL_TRIPS);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &table, &trips, &sites), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &table, &trips, &sites, &filter_presets), 0);
add_imported_dives(&table, &trips, &sites, IMPORT_MERGE_ALL_TRIPS);
QCOMPARE(save_dives("./testmerge47+48.ssrf"), 0);
QFile org(SUBSURFACE_TEST_DATA "/dives/test48+47.xml");

View file

@ -108,7 +108,7 @@ int TestParse::parseCSV(int units, std::string file)
params[pnr++] = intdup(-1);
params[pnr++] = NULL;
return parse_manual_file(file.c_str(), params, pnr - 1, &dive_table, &trip_table, &dive_site_table);
return parse_manual_file(file.c_str(), params, pnr - 1, &dive_table, &trip_table, &dive_site_table, &filter_preset_table);
}
int TestParse::parseDivingLog()
@ -129,13 +129,13 @@ int TestParse::parseDivingLog()
int TestParse::parseV2NoQuestion()
{
// parsing of a V2 file should work
return parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table, &trip_table, &dive_site_table);
return parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table, &trip_table, &dive_site_table, &filter_preset_table);
}
int TestParse::parseV3()
{
// parsing of a V3 files should succeed
return parse_file(SUBSURFACE_TEST_DATA "/dives/test42.xml", &dive_table, &trip_table, &dive_site_table);
return parse_file(SUBSURFACE_TEST_DATA "/dives/test42.xml", &dive_table, &trip_table, &dive_site_table, &filter_preset_table);
}
void TestParse::testParse()
@ -217,7 +217,7 @@ void TestParse::testParseHUDC()
params[pnr++] = NULL;
QCOMPARE(parse_csv_file(SUBSURFACE_TEST_DATA "/dives/TestDiveSeabearHUDC.csv",
params, pnr - 1, "csv", &dive_table, &trip_table, &dive_site_table),
params, pnr - 1, "csv", &dive_table, &trip_table, &dive_site_table, &filter_preset_table),
0);
QCOMPARE(dive_table.nr, 1);
@ -262,7 +262,7 @@ void TestParse::testParseNewFormat()
"/dives/")
.append(files.at(i))
.toLatin1()
.data(), &dive_table, &trip_table, &dive_site_table),
.data(), &dive_table, &trip_table, &dive_site_table, &filter_preset_table),
0);
QCOMPARE(dive_table.nr, i + 1);
}
@ -281,7 +281,7 @@ void TestParse::testParseDLD()
QString filename = SUBSURFACE_TEST_DATA "/dives/TestDiveDivelogsDE.DLD";
QVERIFY(readfile(filename.toLatin1().data(), &mem) > 0);
QVERIFY(try_to_open_zip(filename.toLatin1().data(), &dive_table, &trip_table, &dive_site_table) > 0);
QVERIFY(try_to_open_zip(filename.toLatin1().data(), &dive_table, &trip_table, &dive_site_table, &filter_preset_table) > 0);
fprintf(stderr, "number of dives from DLD: %d \n", dive_table.nr);
@ -296,8 +296,8 @@ void TestParse::testParseMerge()
/*
* check that we correctly merge mixed cylinder dives
*/
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/ostc.xml", &dive_table, &trip_table, &dive_site_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/vyper.xml", &dive_table, &trip_table, &dive_site_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/ostc.xml", &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/vyper.xml", &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
QCOMPARE(save_dives("./testmerge.ssrf"), 0);
FILE_COMPARE("./testmerge.ssrf",
SUBSURFACE_TEST_DATA "/dives/mergedVyperOstc.xml");
@ -366,14 +366,14 @@ int TestParse::parseCSVmanual(int units, std::string file)
params[pnr++] = intdup(units);
params[pnr++] = NULL;
return parse_manual_file(file.c_str(), params, pnr - 1, &dive_table, &trip_table, &dive_site_table);
return parse_manual_file(file.c_str(), params, pnr - 1, &dive_table, &trip_table, &dive_site_table, &filter_preset_table);
}
void TestParse::exportCSVDiveDetails()
{
int saved_sac = 0;
parse_file(SUBSURFACE_TEST_DATA "/dives/test25.xml", &dive_table, &trip_table, &dive_site_table);
parse_file(SUBSURFACE_TEST_DATA "/dives/test25.xml", &dive_table, &trip_table, &dive_site_table, &filter_preset_table);
export_dives_xslt("testcsvexportmanual.csv", 0, 0, "xml2manualcsv.xslt", false);
export_dives_xslt("testcsvexportmanualimperial.csv", 0, 1, "xml2manualcsv.xslt", false);
@ -409,7 +409,7 @@ void TestParse::exportSubsurfaceCSV()
int pnr = 0;
/* Test SubsurfaceCSV with multiple cylinders */
parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table, &trip_table, &dive_site_table);
parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table, &trip_table, &dive_site_table, &filter_preset_table);
export_dives_xslt("testcsvexportmanual-cyl.csv", 0, 0, "xml2manualcsv.xslt", false);
export_dives_xslt("testcsvexportmanualimperial-cyl.csv", 0, 1, "xml2manualcsv.xslt", false);
@ -426,7 +426,7 @@ void TestParse::exportSubsurfaceCSV()
params[pnr++] = strdup("units");
params[pnr++] = intdup(1);
params[pnr++] = 0;
parse_csv_file("testcsvexportmanualimperial-cyl.csv", params, pnr - 1, "SubsurfaceCSV", &dive_table, &trip_table, &dive_site_table);
parse_csv_file("testcsvexportmanualimperial-cyl.csv", params, pnr - 1, "SubsurfaceCSV", &dive_table, &trip_table, &dive_site_table, &filter_preset_table);
// We do not currently support reading SAC, thus faking it
if (dive_table.nr > 0) {
@ -470,12 +470,12 @@ int TestParse::parseCSVprofile(int units, std::string file)
params[pnr++] = intdup(units);
params[pnr++] = NULL;
return parse_csv_file(file.c_str(), params, pnr - 1, "csv", &dive_table, &trip_table, &dive_site_table);
return parse_csv_file(file.c_str(), params, pnr - 1, "csv", &dive_table, &trip_table, &dive_site_table, &filter_preset_table);
}
void TestParse::exportCSVDiveProfile()
{
parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table, &trip_table, &dive_site_table);
parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table, &trip_table, &dive_site_table, &filter_preset_table);
export_dives_xslt("testcsvexportprofile.csv", 0, 0, "xml2csv.xslt", false);
export_dives_xslt("testcsvexportprofileimperial.csv", 0, 1, "xml2csv.xslt", false);
@ -493,13 +493,13 @@ void TestParse::exportCSVDiveProfile()
void TestParse::exportUDDF()
{
parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table, &trip_table, &dive_site_table);
parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table, &trip_table, &dive_site_table, &filter_preset_table);
export_dives_xslt("testuddfexport.uddf", 0, 1, "uddf-export.xslt", false);
clear_dive_file_data();
parse_file("testuddfexport.uddf", &dive_table, &trip_table, &dive_site_table);
parse_file("testuddfexport.uddf", &dive_table, &trip_table, &dive_site_table, &filter_preset_table);
export_dives_xslt("testuddfexport2.uddf", 0, 1, "uddf-export.xslt", false);
FILE_COMPARE("testuddfexport.uddf",
@ -565,7 +565,7 @@ void TestParse::parseDL7()
clear_dive_file_data();
QCOMPARE(parse_csv_file(SUBSURFACE_TEST_DATA "/dives/DL7.zxu",
params, pnr - 1, "DL7", &dive_table, &trip_table, &dive_site_table),
params, pnr - 1, "DL7", &dive_table, &trip_table, &dive_site_table, &filter_preset_table),
0);
QCOMPARE(dive_table.nr, 3);

View file

@ -63,7 +63,7 @@ void TestParsePerformance::parseSsrf()
return;
}
QBENCHMARK {
parse_file(SUBSURFACE_TEST_DATA "/dives/large-anon.ssrf", &dive_table, &trip_table, &dive_site_table);
parse_file(SUBSURFACE_TEST_DATA "/dives/large-anon.ssrf", &dive_table, &trip_table, &dive_site_table, &filter_preset_table);
}
}
@ -74,12 +74,12 @@ void TestParsePerformance::parseGit()
// first parse this once to populate the local cache - this way network
// effects don't dominate the parse time
parse_file(LARGE_TEST_REPO "[git]", &dive_table, &trip_table, &dive_site_table);
parse_file(LARGE_TEST_REPO "[git]", &dive_table, &trip_table, &dive_site_table, &filter_preset_table);
cleanup();
QBENCHMARK {
parse_file(LARGE_TEST_REPO "[git]", &dive_table, &trip_table, &dive_site_table);
parse_file(LARGE_TEST_REPO "[git]", &dive_table, &trip_table, &dive_site_table, &filter_preset_table);
}
}

View file

@ -26,7 +26,7 @@ void TestPicture::addPicture()
struct picture *pic1, *pic2;
verbose = 1;
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test44.xml", &dive_table, &trip_table, &dive_site_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test44.xml", &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
dive = get_dive(0);
// Pictures will be added to selected dives
dive->selected = true;

View file

@ -15,7 +15,7 @@
void TestProfile::testProfileExport()
{
parse_file("../dives/abitofeverything.ssrf", &dive_table, &trip_table, &dive_site_table);
parse_file("../dives/abitofeverything.ssrf", &dive_table, &trip_table, &dive_site_table, &filter_preset_table);
save_profiledata("exportprofile.csv", false);
QFile org("../dives/exportprofilereference.csv");
org.open(QFile::ReadOnly);

View file

@ -8,7 +8,7 @@
void TestRenumber::setup()
{
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &dive_table, &trip_table, &dive_site_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
process_loaded_dives();
}
@ -17,7 +17,8 @@ void TestRenumber::testMerge()
struct dive_table table = empty_dive_table;
struct trip_table trips = empty_trip_table;
struct dive_site_table sites = empty_dive_site_table;
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47b.xml", &table, &trips, &sites), 0);
filter_preset_table_t filter_presets;
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47b.xml", &table, &trips, &sites, &filter_presets), 0);
add_imported_dives(&table, &trips, &sites, IMPORT_MERGE_ALL_TRIPS);
QCOMPARE(dive_table.nr, 1);
QCOMPARE(unsaved_changes(), 1);
@ -29,7 +30,8 @@ void TestRenumber::testMergeAndAppend()
struct dive_table table = empty_dive_table;
struct trip_table trips = empty_trip_table;
struct dive_site_table sites = empty_dive_site_table;
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47c.xml", &table, &trips, &sites), 0);
filter_preset_table_t filter_presets;
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47c.xml", &table, &trips, &sites, &filter_presets), 0);
add_imported_dives(&table, &trips, &sites, IMPORT_MERGE_ALL_TRIPS);
QCOMPARE(dive_table.nr, 2);
QCOMPARE(unsaved_changes(), 1);