summaryrefslogtreecommitdiffstats
path: root/divelist.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2012-11-25 19:04:45 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2012-11-26 09:27:54 -0800
commit544a8b9d7742befe8af768eca00c254b8a11cfb1 (patch)
treec43d6fa8388f1d94fbd612763adf70409a936952 /divelist.c
parentba3e6bcc5185b0427f5591c4fc8566f5d66ffb7d (diff)
downloadsubsurface-544a8b9d7742befe8af768eca00c254b8a11cfb1.tar.gz
Rewrite 'remove_autogen_trips()' without the gtk tree model walking
I'm trying to remove (or at least simplify) the gtk tree model usage for our trip handling, but I'm doing it in small chunks. The goal is to just do all our trip handling logic explicitly using our own data structures, and use the gtk tree model purely for showing the end result. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'divelist.c')
-rw-r--r--divelist.c39
1 files changed, 8 insertions, 31 deletions
diff --git a/divelist.c b/divelist.c
index 28c2e8d53..7174e9dfb 100644
--- a/divelist.c
+++ b/divelist.c
@@ -1093,6 +1093,7 @@ void remove_dive_from_trip(struct dive *dive)
next->pprev = pprev;
dive->divetrip = NULL;
+ dive->tripflag = TF_NONE;
assert(trip->nrdives > 0);
if (!--trip->nrdives)
delete_trip(trip);
@@ -2513,37 +2514,13 @@ int unsaved_changes()
void remove_autogen_trips()
{
- GtkTreeIter iter;
- GtkTreePath *path;
- timestamp_t when;
- int idx;
- GList *trip;
+ int i;
+ struct dive *dive;
- /* start with the first top level entry and walk all of them */
- path = gtk_tree_path_new_from_string("0");
- while(gtk_tree_model_get_iter(TREEMODEL(dive_list), &iter, path)) {
- gtk_tree_model_get(TREEMODEL(dive_list), &iter, DIVE_INDEX, &idx, DIVE_DATE, &when, -1);
- if (idx < 0) {
- trip = find_trip_by_time(when);
- if (trip && DIVE_TRIP(trip)->tripflag == AUTOGEN_TRIP) { /* this was autogen */
- remove_trip(path, FALSE);
- continue;
- }
- }
- gtk_tree_path_next(path);
- }
- /* now walk the remaining trips in the dive_trip_list and restore
- * their original time stamp; we don't do this in the loop above
- * to ensure that the list stays in chronological order */
- trip = NULL;
- while(NEXT_TRIP(trip)) {
- trip = NEXT_TRIP(trip);
- DIVE_TRIP(trip)->when = DIVE_TRIP(trip)->when_from_file;
- }
- /* finally walk the dives and remove the 'ASSIGNED_TRIP' designator */
- for (idx = 0; idx < dive_table.nr; idx++) {
- struct dive *dive = get_dive(idx);
- if (dive->tripflag == ASSIGNED_TRIP)
- dive->tripflag = TF_NONE;
+ for_each_dive(i, dive) {
+ dive_trip_t *trip = dive->divetrip;
+
+ if (trip && trip->tripflag == AUTOGEN_TRIP)
+ remove_dive_from_trip(dive);
}
}