Clarify (and fix) dive trip auto-generation

This makes the dive trip auto-generation a separate pass from the
showing of the dive trips, which makes things much more understandable.
It simplifies the code a lot too, because it's much more natural to
generate the automatic trip data by walking the dives from oldest to
newest (while the tree model wants to walk the other way).

It gets rid of the most annoying part of using the gtk tree model for
dive trip management, but some still remains.

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 20:06:54 -08:00 committed by Dirk Hohndel
parent 85f0749c85
commit ffa3fd551c
3 changed files with 110 additions and 209 deletions

View file

@ -262,18 +262,8 @@ static gboolean ask_save_changes()
return quit;
}
static void dive_trip_unref(gpointer data, gpointer user_data)
{
dive_trip_t *dive_trip = (dive_trip_t *)data;
if (dive_trip->location)
free(dive_trip->location);
free(data);
}
static void file_close(GtkWidget *w, gpointer data)
{
int i;
if (unsaved_changes())
if (ask_save_changes() == FALSE)
return;
@ -283,20 +273,12 @@ static void file_close(GtkWidget *w, gpointer data)
existing_filename = NULL;
/* free the dives and trips */
for (i = 0; i < dive_table.nr; i++)
free(get_dive(i));
dive_table.nr = 0;
while (dive_table.nr)
delete_single_dive(0);
dive_table.preexisting = 0;
mark_divelist_changed(FALSE);
/* inlined version of g_list_free_full(dive_trip_list, free); */
g_list_foreach(dive_trip_list, (GFunc)dive_trip_unref, NULL);
g_list_free(dive_trip_list);
dive_trip_list = NULL;
/* clear the selection and the statistics */
amount_selected = 0;
selected_dive = 0;
process_selected_dives();
clear_stats_widgets();