summaryrefslogtreecommitdiffstats
path: root/dive.h
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2012-09-19 23:42:11 -0400
committerGravatar Dirk Hohndel <dirk@hohndel.org>2012-09-19 23:49:56 -0400
commitc804c4e02e0530889697fab524cba294a55ffeeb (patch)
tree6a6afb7d8a82a890cb4390cdeeda0658d3034d3a /dive.h
parentbf83aa21046e7dfe63cb3bd13ea608067400967e (diff)
downloadsubsurface-c804c4e02e0530889697fab524cba294a55ffeeb.tar.gz
Partial rewrite of the dive trip code
This introduces a new data structure for dive trips - reuseing the struct dive just got way too messy. The dive_trip_t datastructure now allows the code to remember if the trip was auto generated or if its time stamp changed when dives where added to the trip during auto generation. The algorithm also distinguishes between dives that were intentionally added to a trip (either in an XML file or by adding them to trip in the UI) and dives that were added to trips via autogen. Saving dives that were added to trips via autogen makes that assignment "intentional". With this partial rewrite several of the oddities of the old code should be resolved - especially turning autogen on and off again should get the divelist back to the previous stage. Also, when dives are merged during file open or import we now try to pick the correct tripflag (instead of just ignoring the tripflag completely and resetting it to TF_NONE by mistake). Finally, the dive trip debugging code got more verbose and is trying harder to detect issues at the earliest time possible. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'dive.h')
-rw-r--r--dive.h44
1 files changed, 32 insertions, 12 deletions
diff --git a/dive.h b/dive.h
index e443ce965..c326de1ea 100644
--- a/dive.h
+++ b/dive.h
@@ -236,13 +236,21 @@ struct event {
#define W_IDX_PRIMARY 0
#define W_IDX_SECONDARY 1
-typedef enum { TF_NONE, NO_TRIP, IN_TRIP, NUM_TRIPFLAGS } tripflag_t;
+typedef enum { TF_NONE, NO_TRIP, IN_TRIP, ASSIGNED_TRIP, AUTOGEN_TRIP, NUM_TRIPFLAGS } tripflag_t;
extern const char *tripflag_names[NUM_TRIPFLAGS];
+typedef struct dive_trip {
+ tripflag_t tripflag;
+ time_t when;
+ time_t when_from_file;
+ char *location;
+ char *notes;
+} dive_trip_t;
+
struct dive {
int number;
tripflag_t tripflag;
- struct dive *divetrip;
+ dive_trip_t *divetrip;
int selected;
time_t when;
char *location;
@@ -275,21 +283,21 @@ extern gboolean autogroup;
#define TRIP_THRESHOLD 3600*24*3
#define UNGROUPED_DIVE(_dive) ((_dive)->tripflag == NO_TRIP)
-#define DIVE_IN_TRIP(_dive) ((_dive)->tripflag == IN_TRIP)
+#define DIVE_IN_TRIP(_dive) ((_dive)->tripflag == IN_TRIP || (_dive)->tripflag == ASSIGNED_TRIP)
#define DIVE_NEEDS_TRIP(_dive) ((_dive)->tripflag == TF_NONE)
#define NEXT_TRIP(_entry) ((_entry) ? g_list_next(_entry) : (dive_trip_list))
#define PREV_TRIP(_entry) ((_entry) ? g_list_previous(_entry) : g_list_last(dive_trip_list))
-#define DIVE_TRIP(_trip) ((struct dive *)(_trip)->data)
+#define DIVE_TRIP(_trip) ((dive_trip_t *)(_trip)->data)
#define DIVE_FITS_TRIP(_dive, _dive_trip) ((_dive_trip)->when - TRIP_THRESHOLD <= (_dive)->when)
/* compare two dives by when they happened */
static inline int dive_date_cmp(gconstpointer _a, gconstpointer _b) {
- return ((struct dive *)_a)->when - ((struct dive *)_b)->when;
+ return ((dive_trip_t *)_a)->when - ((dive_trip_t *)_b)->when;
}
/* returns 0 if the dive happened exactly at time */
-static inline int dive_when_find(gconstpointer _dive, gconstpointer _time) {
- return ((struct dive *)_dive)->when != (time_t) _time;
+static inline int dive_when_find(gconstpointer _dive_trip, gconstpointer _time) {
+ return ((dive_trip_t *)_dive_trip)->when != (time_t) _time;
}
#define FIND_TRIP(_when) g_list_find_custom(dive_trip_list, (gconstpointer)(_when), dive_when_find)
@@ -299,10 +307,22 @@ static void dump_trip_list(void)
{
GList *p = NULL;
int i=0;
+ time_t last_time = 0;
while ((p = NEXT_TRIP(p))) {
- struct tm *tm = gmtime(&DIVE_TRIP(p)->when);
- printf("trip %d to \"%s\" on %04u-%02u-%02u %02u:%02u:%02u\n", ++i, DIVE_TRIP(p)->location,
+ dive_trip_t *dive_trip = DIVE_TRIP(p);
+ struct tm *tm = gmtime(&dive_trip->when);
+ if (dive_trip->when < last_time)
+ printf("\n\ndive_trip_list OUT OF ORDER!!!\n\n\n");
+ printf("%s trip %d to \"%s\" on %04u-%02u-%02u %02u:%02u:%02u\n",
+ dive_trip->tripflag == AUTOGEN_TRIP ? "autogen " : "",
+ ++i, dive_trip->location,
tm->tm_year + 1900, tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
+ if (dive_trip->when_from_file && dive_trip->when != dive_trip->when_from_file) {
+ tm = gmtime(&dive_trip->when_from_file);
+ printf("originally on %04u-%02u-%02u %02u:%02u:%02u\n", tm->tm_year + 1900,
+ tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
+ }
+ last_time = dive_trip->when;
}
printf("-----\n");
}
@@ -311,9 +331,9 @@ static void dump_trip_list(void)
/* insert the trip into the dive_trip_list - but ensure you don't have
* two trips for the same date; but if you have, make sure you don't
* keep the one with less information */
-static void inline insert_trip(struct dive **trip)
+static void inline insert_trip(dive_trip_t **trip)
{
- struct dive *dive_trip = *trip;
+ dive_trip_t *dive_trip = *trip;
GList *result = FIND_TRIP(dive_trip->when);
if (result) {
if (! DIVE_TRIP(result)->location)
@@ -447,7 +467,7 @@ extern void remember_event(const char *eventname);
extern void evn_foreach(void (*callback)(const char *, int *, void *), void *data);
extern int add_new_dive(struct dive *dive);
-extern gboolean edit_trip(struct dive *trip);
+extern gboolean edit_trip(dive_trip_t *trip);
extern int edit_dive_info(struct dive *dive);
extern int edit_multi_dive_info(struct dive *single_dive);
extern void dive_list_update_dives(void);