diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-09-23 12:53:35 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-09-23 11:50:53 -0700 |
commit | 35b8a4f404de3297cb8d126654e0ec37245a7537 (patch) | |
tree | 4d44463ad16f3661d45902eaa0fc80827f106e19 /core | |
parent | 0ae57cfe921d6107848a7a66deb16861affffc89 (diff) | |
download | subsurface-35b8a4f404de3297cb8d126654e0ec37245a7537.tar.gz |
Core: split process_dives() in post-import and post-load versions
process_dives() is used to post-process the dive table after loading
or importing. The first parameter states whether this was after
load or import.
Especially in the light of undo, load and import are fundamentally
different things. Notably, that latter should be undo-able, whereas
the former is not. Therefore, as a first step to make import undo-able,
split the function in two versions and remove the first parameter.
It turns out the the load-version is very light. It only sets the
DC nicknames and sorts the dive-table. There seems to be no reason
to merge dives.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core')
-rw-r--r-- | core/divelist.c | 40 | ||||
-rw-r--r-- | core/divelist.h | 3 | ||||
-rw-r--r-- | core/import-csv.c | 2 |
3 files changed, 28 insertions, 17 deletions
diff --git a/core/divelist.c b/core/divelist.c index 1906d002a..62af3120c 100644 --- a/core/divelist.c +++ b/core/divelist.c @@ -3,6 +3,8 @@ /* core logic for the dive list - * accessed through the following interfaces: * + * void process_loaded_dives(); + * void process_imported_dives(bool prefer_imported); * dive_trip_t *dive_trip_list; * unsigned int amount_selected; * void dump_selection(void) @@ -1259,17 +1261,32 @@ static void try_to_renumber(struct dive *last, int preexisting) } } -void process_dives(bool is_imported, bool prefer_imported) +void process_loaded_dives() +{ + int i; + struct dive *dive; + + /* Register dive computer nick names */ + for_each_dive(i, dive) + set_dc_nickname(dive); + + sort_table(&dive_table); +} + +void process_imported_dives(bool prefer_imported) { int i; int preexisting = dive_table.preexisting; - bool did_merge = false; struct dive *last; + /* If no dives were imported, don't bother doing anything */ + if (preexisting >= dive_table.nr) + return; + /* check if we need a nickname for the divecomputer for newly downloaded dives; * since we know they all came from the same divecomputer we just check for the * first one */ - if (preexisting < dive_table.nr && dive_table.dives[preexisting]->downloaded) + if (dive_table.dives[preexisting]->downloaded) set_dc_nickname(dive_table.dives[preexisting]); else /* they aren't downloaded, so record / check all new ones */ @@ -1315,24 +1332,17 @@ void process_dives(bool is_imported, bool prefer_imported) delete_single_dive(i + 1); // keep the id or the first dive for the merged dive merged->id = id; - - /* this means the table was changed */ - did_merge = true; } + /* make sure no dives are still marked as downloaded */ for (i = 1; i < dive_table.nr; i++) dive_table.dives[i]->downloaded = false; - if (is_imported) { - /* If there are dives in the table, are they numbered */ - if (!last || last->number) - try_to_renumber(last, preexisting); + /* If there are dives in the table, are they numbered */ + if (!last || last->number) + try_to_renumber(last, preexisting); - /* did we add dives or divecomputers to the dive table? */ - if (did_merge || preexisting < dive_table.nr) { - mark_divelist_changed(true); - } - } + mark_divelist_changed(true); } void set_dive_nr_for_current_dive() diff --git a/core/divelist.h b/core/divelist.h index 5467f10ae..937909d2b 100644 --- a/core/divelist.h +++ b/core/divelist.h @@ -18,7 +18,8 @@ extern void remove_autogen_trips(void); extern int init_decompression(struct deco_state *ds, struct dive *dive); /* divelist core logic functions */ -extern void process_dives(bool imported, bool prefer_imported); +extern void process_loaded_dives(); +extern void process_imported_dives(bool prefer_imported); extern char *get_dive_gas_string(struct dive *dive); struct dive **grow_dive_table(struct dive_table *table); diff --git a/core/import-csv.c b/core/import-csv.c index 898dfdbd0..8d6c229fd 100644 --- a/core/import-csv.c +++ b/core/import-csv.c @@ -135,7 +135,7 @@ static int parse_dan_format(const char *filename, char **params, int pnr) */ if (end_ptr) - process_dives(true, false); + process_imported_dives(false); mem_csv.buffer = malloc(mem.size + 1); mem_csv.size = mem.size; |