diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-11-11 13:09:51 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-11-18 16:50:09 -0800 |
commit | 64e6e435f82801f4f440ef5b1caf58a91a7c9929 (patch) | |
tree | 0f2c662daab035463de05c1564af7026c7edbd7e /core | |
parent | 431b2bb84542d4f45952b48aa91231f979762e00 (diff) | |
download | subsurface-64e6e435f82801f4f440ef5b1caf58a91a7c9929.tar.gz |
Core: remove "when" field of struct dive_trip
The when field gives the time of the first dive. Instead of keeping
this field in sync, replace it by a function that determines the time
of the first dive.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core')
-rw-r--r-- | core/dive.h | 2 | ||||
-rw-r--r-- | core/divelist.c | 17 | ||||
-rw-r--r-- | core/divelist.h | 1 | ||||
-rw-r--r-- | core/load-git.c | 24 | ||||
-rw-r--r-- | core/parse-xml.c | 4 | ||||
-rw-r--r-- | core/save-git.c | 2 | ||||
-rw-r--r-- | core/save-xml.c | 2 | ||||
-rw-r--r-- | core/subsurface-qt/DiveObjectHelper.cpp | 2 |
8 files changed, 14 insertions, 40 deletions
diff --git a/core/dive.h b/core/dive.h index 76f01a8c0..18c40c6cf 100644 --- a/core/dive.h +++ b/core/dive.h @@ -293,7 +293,6 @@ struct dive_table { typedef struct dive_trip { - timestamp_t when; char *location; char *notes; struct dive_table dives; @@ -432,6 +431,7 @@ extern void delete_single_dive(int idx); extern void insert_trip(dive_trip_t *trip); extern void unregister_trip(dive_trip_t *trip); extern void free_trip(dive_trip_t *trip); +extern timestamp_t trip_date(const struct dive_trip *trip); extern const struct units SI_units, IMPERIAL_units; diff --git a/core/divelist.c b/core/divelist.c index 0fea7594e..7f946b039 100644 --- a/core/divelist.c +++ b/core/divelist.c @@ -739,7 +739,7 @@ void dump_trip_list(void) for (trip = dive_trip_list; trip; trip = trip->next) { struct tm tm; - utc_mkdate(trip->when, &tm); + utc_mkdate(trip_date(trip), &tm); if (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 (%d dives - %p)\n", @@ -805,9 +805,12 @@ static void delete_trip(dive_trip_t *trip) free_trip(trip); } -void find_new_trip_start_time(dive_trip_t *trip) + +timestamp_t trip_date(const struct dive_trip *trip) { - trip->when = trip->dives.nr > 0 ? trip->dives.dives[0]->when : 0; + if (!trip || trip->dives.nr == 0) + return 0; + return trip->dives.dives[0]->when; } /* check if we have a trip right before / after this dive */ @@ -876,8 +879,6 @@ struct dive_trip *unregister_dive_from_trip(struct dive *dive, short was_autogen dive->tripflag = TF_NONE; else dive->tripflag = NO_TRIP; - if (trip->dives.nr > 0 && trip->when == dive->when) - find_new_trip_start_time(trip); return trip; } @@ -908,7 +909,6 @@ dive_trip_t *create_trip_from_dive(struct dive *dive) dive_trip_t *trip; trip = alloc_trip(); - trip->when = dive->when; trip->location = copy_string(get_dive_location(dive)); return trip; @@ -1345,7 +1345,6 @@ dive_trip_t *combine_trips_create(struct dive_trip *trip_a, struct dive_trip *tr dive_trip_t *trip; trip = alloc_trip(); - trip->when = trip_a->when; trip->location = copy_non_empty_string(trip_a->location, trip_b->location); trip->notes = copy_non_empty_string(trip_a->notes, trip_b->notes); @@ -1726,9 +1725,9 @@ static int comp_dives(const struct dive *a, const struct dive *b) return -1; if (!a->divetrip) return 1; - if (a->divetrip->when < b->divetrip->when) + if (trip_date(a->divetrip) < trip_date(b->divetrip)) return -1; - if (a->divetrip->when > b->divetrip->when) + if (trip_date(a->divetrip) > trip_date(b->divetrip)) return 1; } if (a->id < b->id) diff --git a/core/divelist.h b/core/divelist.h index f98587cff..26218af05 100644 --- a/core/divelist.h +++ b/core/divelist.h @@ -46,7 +46,6 @@ extern void deselect_dives_in_trip(struct dive_trip *trip); extern void filter_dive(struct dive *d, bool shown); extern void combine_trips(struct dive_trip *trip_a, struct dive_trip *trip_b); extern dive_trip_t *combine_trips_create(struct dive_trip *trip_a, struct dive_trip *trip_b); -extern void find_new_trip_start_time(dive_trip_t *trip); extern struct dive *first_selected_dive(); extern struct dive *last_selected_dive(); extern bool is_trip_before_after(const struct dive *dive, bool before); diff --git a/core/load-git.c b/core/load-git.c index 8e3254abd..1447becb2 100644 --- a/core/load-git.c +++ b/core/load-git.c @@ -799,12 +799,6 @@ static void parse_dc_event(char *line, struct membuffer *str, void *_dc) } } -static void parse_trip_date(char *line, struct membuffer *str, void *_trip) -{ UNUSED(str); dive_trip_t *trip = _trip; update_date(&trip->when, line); } - -static void parse_trip_time(char *line, struct membuffer *str, void *_trip) -{ UNUSED(str); dive_trip_t *trip = _trip; update_time(&trip->when, line); } - static void parse_trip_location(char *line, struct membuffer *str, void *_trip) { UNUSED(line); dive_trip_t *trip = _trip; trip->location = get_utf8(str); } @@ -1007,7 +1001,7 @@ static void site_parser(char *line, struct membuffer *str, void *_ds) struct keyword_action trip_action[] = { #undef D #define D(x) { #x, parse_trip_ ## x } - D(date), D(location), D(notes), D(time), + D(location), D(notes), }; static void trip_parser(char *line, struct membuffer *str, void *_trip) @@ -1202,20 +1196,6 @@ static struct dive *create_new_dive(timestamp_t when) return dive; } -static dive_trip_t *create_new_trip(int yyyy, int mm, int dd) -{ - dive_trip_t *trip = alloc_trip(); - struct tm tm = { 0 }; - - /* We'll fill in the real data from the trip descriptor file */ - tm.tm_year = yyyy; - tm.tm_mon = mm-1; - tm.tm_mday = dd; - trip->when = utc_mktime(&tm); - - return trip; -} - static bool validate_date(int yyyy, int mm, int dd) { return yyyy > 1930 && yyyy < 3000 && @@ -1243,7 +1223,7 @@ static int dive_trip_directory(const char *root, const char *name) if (!validate_date(yyyy, mm, dd)) return GIT_WALK_SKIP; finish_active_trip(); - active_trip = create_new_trip(yyyy, mm, dd); + active_trip = alloc_trip(); return GIT_WALK_OK; } diff --git a/core/parse-xml.c b/core/parse-xml.c index 5f70fdc52..d9185cd32 100644 --- a/core/parse-xml.c +++ b/core/parse-xml.c @@ -1352,10 +1352,6 @@ static void try_to_fill_trip(dive_trip_t **dive_trip_p, const char *name, char * dive_trip_t *dive_trip = *dive_trip_p; - if (MATCH_STATE("date", divedate, &dive_trip->when)) - return; - if (MATCH_STATE("time", divetime, &dive_trip->when)) - return; if (MATCH("location", utf8_string, &dive_trip->location)) return; if (MATCH("notes", utf8_string, &dive_trip->notes)) diff --git a/core/save-git.c b/core/save-git.c index 422201324..c53c2bb97 100644 --- a/core/save-git.c +++ b/core/save-git.c @@ -956,7 +956,7 @@ static int create_git_tree(git_repository *repo, struct dir *root, bool select_o } /* Create the date-based hierarchy */ - utc_mkdate(trip ? trip->when : dive->when, &tm); + utc_mkdate(trip ? trip_date(trip) : dive->when, &tm); tree = mktree(repo, root, "%04d", tm.tm_year); tree = mktree(repo, tree, "%02d", tm.tm_mon + 1); diff --git a/core/save-xml.c b/core/save-xml.c index 4a85053ab..4abb3cc12 100644 --- a/core/save-xml.c +++ b/core/save-xml.c @@ -520,7 +520,7 @@ static void save_trip(struct membuffer *b, dive_trip_t *trip, bool anonymize) struct dive *dive; put_format(b, "<trip"); - show_date(b, trip->when); + show_date(b, trip_date(trip)); show_utf8(b, trip->location, " location=\'", "\'", 1); put_format(b, ">\n"); show_utf8(b, trip->notes, "<notes>", "</notes>\n", 0); diff --git a/core/subsurface-qt/DiveObjectHelper.cpp b/core/subsurface-qt/DiveObjectHelper.cpp index b254ed13f..3a9216d63 100644 --- a/core/subsurface-qt/DiveObjectHelper.cpp +++ b/core/subsurface-qt/DiveObjectHelper.cpp @@ -343,7 +343,7 @@ QString DiveObjectHelper::tripMeta() const if (dt) { QString numDives = tr("(%n dive(s))", "", dt->showndives); QString title(dt->location); - QDateTime firstTime = QDateTime::fromMSecsSinceEpoch(1000*dt->when, Qt::UTC); + QDateTime firstTime = QDateTime::fromMSecsSinceEpoch(1000*trip_date(dt), Qt::UTC); QString firstMonth = firstTime.toString("MMM"); QString tripDate = QStringLiteral("%1@%2").arg(firstMonth,firstTime.toString("yy")); |