summaryrefslogtreecommitdiffstats
path: root/divelist.c
diff options
context:
space:
mode:
Diffstat (limited to 'divelist.c')
-rw-r--r--divelist.c85
1 files changed, 79 insertions, 6 deletions
diff --git a/divelist.c b/divelist.c
index b19971087..ca2e9827f 100644
--- a/divelist.c
+++ b/divelist.c
@@ -115,8 +115,6 @@ void get_dive_gas(struct dive *dive, int *o2_p, int *he_p, int *o2low_p)
cylinder_t *cyl = dive->cylinder + i;
int o2 = get_o2(&cyl->gasmix);
int he = get_he(&cyl->gasmix);
- int used = 0;
- int first_gas_explicit = 0;
if (!cyl->used)
continue;
@@ -154,12 +152,9 @@ int total_weight(struct dive *dive)
static int active_o2(struct dive *dive, struct divecomputer *dc, duration_t time)
{
- int o2permille = dive->cylinder[0].gasmix.o2.permille;
+ int o2permille = get_o2(&dive->cylinder[0].gasmix);
struct event *event;
- if (!o2permille)
- o2permille = O2_IN_AIR;
-
for (event = dc->events; event; event = event->next) {
if (event->time.seconds > time.seconds)
break;
@@ -583,6 +578,44 @@ void find_new_trip_start_time(dive_trip_t *trip)
trip->when = when;
}
+/* check if we have a trip right before / after this dive */
+bool is_trip_before_after(struct dive *dive, bool before)
+{
+ int idx = get_idx_by_uniq_id(dive->id);
+ if (before) {
+ if (idx > 0 && get_dive(idx - 1)->divetrip)
+ return true;
+ } else {
+ if (idx < dive_table.nr - 1 && get_dive(idx + 1)->divetrip)
+ return true;
+ }
+ return false;
+}
+
+struct dive *first_selected_dive()
+{
+ int idx;
+ struct dive *d;
+
+ for_each_dive (idx, d) {
+ if (d->selected)
+ return d;
+ }
+ return NULL;
+}
+
+struct dive *last_selected_dive()
+{
+ int idx;
+ struct dive *d, *ret = NULL;
+
+ for_each_dive (idx, d) {
+ if (d->selected)
+ ret = d;
+ }
+ return ret;
+}
+
void remove_dive_from_trip(struct dive *dive, short was_autogen)
{
struct dive *next, **pprev;
@@ -813,6 +846,43 @@ void deselect_dive(int idx)
}
}
+void deselect_dives_in_trip(struct dive_trip *trip)
+{
+ struct dive *dive;
+ if (!trip)
+ return;
+ for (dive = trip->dives; dive; dive = dive->next)
+ deselect_dive(get_divenr(dive));
+}
+
+void select_dives_in_trip(struct dive_trip *trip)
+{
+ struct dive *dive;
+ if (!trip)
+ return;
+ for (dive = trip->dives; dive; dive = dive->next)
+ select_dive(get_divenr(dive));
+}
+
+/* This only gets called with non-NULL trips.
+ * It does not combine notes or location, just picks the first one
+ * (or the second one if the first one is empty */
+void combine_trips(struct dive_trip *trip_a, struct dive_trip *trip_b)
+{
+ if (same_string(trip_a->location, "") && trip_b->location) {
+ free(trip_a->location);
+ trip_a->location = strdup(trip_b->location);
+ }
+ if (same_string(trip_a->notes, "") && trip_b->notes) {
+ free(trip_a->notes);
+ trip_a->notes = strdup(trip_b->notes);
+ }
+ /* this also removes the dives from trip_b and eventually
+ * calls delete_trip(trip_b) when the last dive has been moved */
+ while (trip_b->dives)
+ add_dive_to_trip(trip_b->dives, trip_a);
+}
+
void mark_divelist_changed(int changed)
{
dive_list_changed = changed;
@@ -912,6 +982,9 @@ void process_dives(bool is_imported, bool prefer_imported)
for (i = preexisting; i < dive_table.nr; i++)
set_dc_nickname(dive_table.dives[i]);
+ for (i = preexisting; i < dive_table.nr; i++)
+ dive_table.dives[i]->downloaded = true;
+
/* This does the right thing for -1: NULL */
last = get_dive(preexisting - 1);