mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Import: control process_imported_dives() by flags
process_imported_dives() takes four boolean parameters. Replace these by flags. This makes the function calls much more descriptive. Morover, it becomes easier to add or remove flags. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
ff9506b21b
commit
891fcbf520
14 changed files with 51 additions and 52 deletions
|
@ -1570,9 +1570,7 @@ static bool merge_dive_tables(struct dive_table *dives_from, struct dive_table *
|
|||
/* Merge the dives of the trip "from" and the dive_table "dives_from" into the trip "to"
|
||||
* and dive_table "dives_to". If "prefer_imported" is true, dive data of "from" takes
|
||||
* precedence */
|
||||
void add_imported_dives(struct dive_table *import_table, struct trip_table *import_trip_table,
|
||||
bool prefer_imported, bool downloaded, bool merge_all_trips,
|
||||
bool add_to_new_trip)
|
||||
void add_imported_dives(struct dive_table *import_table, struct trip_table *import_trip_table, int flags)
|
||||
{
|
||||
int i, idx;
|
||||
struct dive_table dives_to_add = { 0 };
|
||||
|
@ -1581,8 +1579,7 @@ void add_imported_dives(struct dive_table *import_table, struct trip_table *impo
|
|||
|
||||
/* Process imported dives and generate lists of dives
|
||||
* to-be-added and to-be-removed */
|
||||
process_imported_dives(import_table, import_trip_table,
|
||||
prefer_imported, downloaded, merge_all_trips, add_to_new_trip,
|
||||
process_imported_dives(import_table, import_trip_table, flags,
|
||||
&dives_to_add, &dives_to_remove, &trips_to_add);
|
||||
|
||||
/* Add new dives to trip, so that trips don't get deleted
|
||||
|
@ -1672,16 +1669,19 @@ bool try_to_merge_trip(struct dive_trip *trip_import, struct dive_table *import_
|
|||
* *not* be part of the trip. The caller has to add them to the trip.
|
||||
*
|
||||
* The lists are generated by merging dives if possible. This is
|
||||
* performed trip-wise. If "prefer_imported" is true, data of the
|
||||
* new dives are prioritized in such a case. If "merge_all_trips" is
|
||||
* true, all overlapping trips will be merged, not only non-autogenerated
|
||||
* trips. If "downloaded" is true, only the divecomputer of the first dive
|
||||
* will be considered, as it is assumed that all dives come from
|
||||
* the same computer. If "add_to_new_trip" is true, dives that are not
|
||||
* assigned to a trip will be added to a newly generated trip.
|
||||
* performed trip-wise. Finer control on merging is provided by
|
||||
* the "flags" parameter:
|
||||
* - If IMPORT_PREFER_IMPORTED is set, data of the new dives are
|
||||
* prioritized on merging.
|
||||
* - If IMPORT_MERGE_ALL_TRIPS is set, all overlapping trips will
|
||||
* be merged, not only non-autogenerated trips.
|
||||
* - If IMPORT_IS_DOWNLOADED is true, only the divecomputer of the
|
||||
* first dive will be considered, as it is assumed that all dives
|
||||
* come from the same computer.
|
||||
* - If IMPORT_ADD_TO_NEW_TRIP is true, dives that are not assigned
|
||||
* to a trip will be added to a newly generated trip.
|
||||
*/
|
||||
void process_imported_dives(struct dive_table *import_table, struct trip_table *import_trip_table,
|
||||
bool prefer_imported, bool downloaded, bool merge_all_trips, bool add_to_new_trip,
|
||||
void process_imported_dives(struct dive_table *import_table, struct trip_table *import_trip_table, int flags,
|
||||
/* output parameters: */
|
||||
struct dive_table *dives_to_add, struct dive_table *dives_to_remove,
|
||||
struct trip_table *trips_to_add)
|
||||
|
@ -1721,7 +1721,7 @@ void process_imported_dives(struct dive_table *import_table, struct trip_table *
|
|||
/* 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 (downloaded)
|
||||
if (flags & IMPORT_IS_DOWNLOADED)
|
||||
set_dc_nickname(import_table->dives[0]);
|
||||
else
|
||||
/* they aren't downloaded, so record / check all new ones */
|
||||
|
@ -1734,7 +1734,7 @@ void process_imported_dives(struct dive_table *import_table, struct trip_table *
|
|||
|
||||
/* Autogroup tripless dives if desired by user. But don't autogroup
|
||||
* if tripless dives should be added to a new trip. */
|
||||
if (!add_to_new_trip)
|
||||
if (!(flags & IMPORT_ADD_TO_NEW_TRIP))
|
||||
autogroup_dives(import_table, import_trip_table);
|
||||
|
||||
preexisting = dive_table.nr; /* Remember old size for renumbering */
|
||||
|
@ -1745,8 +1745,8 @@ void process_imported_dives(struct dive_table *import_table, struct trip_table *
|
|||
*/
|
||||
for (i = 0; i < import_trip_table->nr; i++) {
|
||||
trip_import = import_trip_table->trips[i];
|
||||
if (merge_all_trips || trip_import->autogen) {
|
||||
if (try_to_merge_trip(trip_import, import_table, prefer_imported, dives_to_add, dives_to_remove,
|
||||
if ((flags & IMPORT_MERGE_ALL_TRIPS) || trip_import->autogen) {
|
||||
if (try_to_merge_trip(trip_import, import_table, flags & IMPORT_PREFER_IMPORTED, dives_to_add, dives_to_remove,
|
||||
&sequence_changed, &start_renumbering_at))
|
||||
continue;
|
||||
}
|
||||
|
@ -1769,7 +1769,7 @@ void process_imported_dives(struct dive_table *import_table, struct trip_table *
|
|||
}
|
||||
import_trip_table->nr = 0; /* All trips were consumed */
|
||||
|
||||
if (add_to_new_trip && import_table->nr > 0) {
|
||||
if ((flags & IMPORT_ADD_TO_NEW_TRIP) && import_table->nr > 0) {
|
||||
/* Create a new trip for unassigned dives, if desired. */
|
||||
new_trip = create_trip_from_dive(import_table->dives[0]);
|
||||
insert_trip(new_trip, trips_to_add);
|
||||
|
@ -1787,7 +1787,7 @@ void process_imported_dives(struct dive_table *import_table, struct trip_table *
|
|||
/* The remaining dives in import_table are those that don't belong to
|
||||
* a trip and the caller does not want them to be associated to a
|
||||
* new trip. Merge them into the global table. */
|
||||
sequence_changed |= merge_dive_tables(import_table, NULL, &dive_table, prefer_imported, NULL,
|
||||
sequence_changed |= merge_dive_tables(import_table, NULL, &dive_table, flags & IMPORT_PREFER_IMPORTED, NULL,
|
||||
dives_to_add, dives_to_remove, &start_renumbering_at);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,10 +18,13 @@ extern int init_decompression(struct deco_state *ds, struct dive *dive);
|
|||
|
||||
/* divelist core logic functions */
|
||||
extern void process_loaded_dives();
|
||||
extern void add_imported_dives(struct dive_table *import_table, struct trip_table *import_trip_table,
|
||||
bool prefer_imported, bool downloaded, bool merge_all_trips, bool add_to_new_trip);
|
||||
extern void process_imported_dives(struct dive_table *import_table, struct trip_table *import_trip_table,
|
||||
bool prefer_imported, bool downloaded, bool merge_all_trips, bool add_to_new_trip,
|
||||
/* flags for process_imported_dives() */
|
||||
#define IMPORT_PREFER_IMPORTED (1 << 0)
|
||||
#define IMPORT_IS_DOWNLOADED (1 << 1)
|
||||
#define IMPORT_MERGE_ALL_TRIPS (1 << 2)
|
||||
#define IMPORT_ADD_TO_NEW_TRIP (1 << 3)
|
||||
extern void add_imported_dives(struct dive_table *import_table, struct trip_table *import_trip_table, int flags);
|
||||
extern void process_imported_dives(struct dive_table *import_table, struct trip_table *import_trip_table, int flags,
|
||||
struct dive_table *dives_to_add, struct dive_table *dives_to_remove,
|
||||
struct trip_table *trips_to_add);
|
||||
extern char *get_dive_gas_string(const struct dive *dive);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue