summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-07-28 21:26:59 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-10-11 16:22:27 -0700
commit6ac4ddbeeda5286faacac9633b622dcf298eea7b (patch)
tree93a3e8ad8388e18866477168688a6162a469e9e0
parent43c3885249fb867e7c33c8b3b5846d44e908774f (diff)
downloadsubsurface-6ac4ddbeeda5286faacac9633b622dcf298eea7b.tar.gz
Core: introduce insert_trip_dont_merge() function
insert_trip() adds a trip to the backend, but merges trips if there exists a trip with the same date. This is a disaster for the MergeTrips command, because this command adds a new trip and removes the previous two. Of course if the added trip is merged, this cannot work. Therefore, add an insert_trip_dont_merge() function, which adds the trip, but doesn't merge. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r--core/dive.h1
-rw-r--r--core/divelist.c17
-rw-r--r--desktop-widgets/command_divelist.cpp12
3 files changed, 22 insertions, 8 deletions
diff --git a/core/dive.h b/core/dive.h
index 6fd53fba9..3077c5bce 100644
--- a/core/dive.h
+++ b/core/dive.h
@@ -422,6 +422,7 @@ extern int dive_get_insertion_index(struct dive *dive);
extern void add_single_dive(int idx, struct dive *dive);
extern void insert_trip(dive_trip_t **trip);
+extern void insert_trip_dont_merge(dive_trip_t *trip);
extern void unregister_trip(dive_trip_t *trip);
extern void free_trip(dive_trip_t *trip);
diff --git a/core/divelist.c b/core/divelist.c
index f6453e04c..08fde01ff 100644
--- a/core/divelist.c
+++ b/core/divelist.c
@@ -16,6 +16,7 @@
* void update_cylinder_related_info(struct dive *dive)
* void dump_trip_list(void)
* void insert_trip(dive_trip_t **dive_trip_p)
+ * void insert_trip_dont_merge(dive_trip_t *dive_trip_p)
* void unregister_trip(dive_trip_t *trip)
* void free_trip(dive_trip_t *trip)
* void remove_dive_from_trip(struct dive *dive)
@@ -739,6 +740,22 @@ void insert_trip(dive_trip_t **dive_trip_p)
#endif
}
+/* same as insert_trip, but don't merge trips with the same date.
+ * this is cruical for the merge undo-command, because there we
+ * add a new trip with the same date and then remove the old one. */
+void insert_trip_dont_merge(dive_trip_t *dive_trip)
+{
+ dive_trip_t **p = &dive_trip_list;
+ dive_trip_t *trip;
+
+ /* Walk the dive trip list looking for the right location.. */
+ while ((trip = *p) != NULL && trip->when < dive_trip->when)
+ p = &trip->next;
+
+ dive_trip->next = trip;
+ *p = dive_trip;
+}
+
/* free resources associated with a trip structure */
void free_trip(dive_trip_t *trip)
{
diff --git a/desktop-widgets/command_divelist.cpp b/desktop-widgets/command_divelist.cpp
index d12aebfc2..f0c0a82e2 100644
--- a/desktop-widgets/command_divelist.cpp
+++ b/desktop-widgets/command_divelist.cpp
@@ -34,10 +34,8 @@ static DiveToAdd removeDive(struct dive *d)
// Returns pointer to added dive (which is owned by the backend!)
static dive *addDive(DiveToAdd &d)
{
- if (d.tripToAdd) {
- dive_trip *t = d.tripToAdd.release(); // Give up ownership of trip
- insert_trip(&t); // Return ownership to backend
- }
+ if (d.tripToAdd)
+ insert_trip_dont_merge(d.tripToAdd.release()); // Return ownership to backend
if (d.trip)
add_dive_to_trip(d.dive.get(), d.trip);
dive *res = d.dive.release(); // Give up ownership of dive
@@ -124,10 +122,8 @@ static OwningTripPtr moveDiveToTrip(DiveToTrip &diveToTrip)
static void moveDivesBetweenTrips(DivesToTrip &dives)
{
// first bring back the trip(s)
- for (OwningTripPtr &trip: dives.tripsToAdd) {
- dive_trip *t = trip.release(); // Give up ownership
- insert_trip(&t); // Return ownership to backend
- }
+ for (OwningTripPtr &trip: dives.tripsToAdd)
+ insert_trip_dont_merge(trip.release()); // Return ownership to backend
dives.tripsToAdd.clear();
for (DiveToTrip &dive: dives.divesToMove) {