summaryrefslogtreecommitdiffstats
path: root/divelist.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2012-09-02 21:48:30 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2012-09-02 21:50:43 -0700
commitf6e8903a528a65f0e0fd050c203c95d57afd2db9 (patch)
tree48752b81acfd112e62ecb1bd7618f0ad2cf76bf8 /divelist.c
parent22ff8df880461c6e66d45fa8eaba9c9c26edb1bd (diff)
downloadsubsurface-f6e8903a528a65f0e0fd050c203c95d57afd2db9.tar.gz
Add autogen menu command
This adds the ability to auto create trips from the menu. It's a toggle entry (and while at it, we made the zoom toggle a toggle entry as well). We can therfore switch back and forth between auto generated trips. There is one bug. Assume you have no trips. You manually create a trip from some dives out of a group of trips that autogen would turn into a trip. Now you turn on autogen and this trip gets expanded with all the dives that would normally be grouped together. If you turn off autogen again, all those dives are still part of the remaining (initially manually created) trip. Working around this issue seemed a lot more work than the likelihood of anyone running into it seemed worth. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'divelist.c')
-rw-r--r--divelist.c40
1 files changed, 38 insertions, 2 deletions
diff --git a/divelist.c b/divelist.c
index 5f45e900b..64b392f54 100644
--- a/divelist.c
+++ b/divelist.c
@@ -970,11 +970,16 @@ static void fill_dive_list(void)
/* allocate new trip - all fields default to 0
and get filled in further down */
dive_trip = create_and_hookup_trip_from_dive(dive);
+ dive_trip->tripflag = IN_TRIP; /* this marks an autogen trip */
trip = FIND_TRIP(dive_trip->when);
}
} else if (DIVE_IN_TRIP(dive)) {
trip = find_matching_trip(dive->when);
dive_trip = DIVE_TRIP(trip);
+ } else {
+ /* dive is not in a trip and we aren't autogrouping */
+ dive_trip = NULL;
+ parent_ptr = NULL;
}
/* update dive as part of dive_trip and
* (if necessary) update dive_trip time and location */
@@ -1427,7 +1432,7 @@ static void remove_from_trip_cb(GtkWidget *menuitem, GtkTreePath *path)
dive->divetrip = NULL;
}
-void remove_trip_cb(GtkWidget *menuitem, GtkTreePath *trippath)
+void remove_trip(GtkTreePath *trippath, gboolean force_no_trip)
{
GtkTreeIter newiter, parent, child, *lastiter = &parent;
struct dive *dive, *dive_trip = NULL;
@@ -1450,7 +1455,10 @@ void remove_trip_cb(GtkWidget *menuitem, GtkTreePath *trippath)
dive = get_dive(idx);
if (dive->selected)
gtk_tree_selection_select_iter(selection, &newiter);
- dive->tripflag = NO_TRIP;
+ if (force_no_trip)
+ dive->tripflag = NO_TRIP;
+ else
+ dive->tripflag = TF_NONE;
if (!dive_trip)
dive_trip = dive->divetrip;
dive->divetrip = NULL;
@@ -1464,6 +1472,11 @@ void remove_trip_cb(GtkWidget *menuitem, GtkTreePath *trippath)
free(dive_trip);
}
+void remove_trip_cb(GtkWidget *menuitem, GtkTreePath *trippath)
+{
+ remove_trip(trippath, TRUE);
+}
+
void merge_trips_cb(GtkWidget *menuitem, GtkTreePath *trippath)
{
GtkTreePath *prevpath;
@@ -1784,3 +1797,26 @@ int unsaved_changes()
{
return dive_list.changed;
}
+
+void remove_autogen_trips()
+{
+ GtkTreeIter iter;
+ GtkTreePath *path;
+ time_t when;
+ int idx;
+ GList *trip;
+
+ /* 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(when);
+ if (DIVE_TRIP(trip)->tripflag == IN_TRIP) { /* this was autogen */
+ remove_trip(path, FALSE);
+ continue;
+ }
+ }
+ gtk_tree_path_next(path);
+ }
+}