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>
This commit is contained in:
Linus Torvalds 2012-11-25 19:04:45 -08:00 committed by Dirk Hohndel
parent ba3e6bcc51
commit 544a8b9d77

View file

@ -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);
}
}