diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2013-04-06 21:28:03 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-04-06 21:28:42 -0700 |
commit | 081000963a822c1a9814bf4eba3e9dd4485a2cf9 (patch) | |
tree | 29de215da759de5549a75e1057b0c73b0f53efc4 /divelist.c | |
parent | 1d61955be973cfcc67f4e82a65487721a9ae84b8 (diff) | |
download | subsurface-081000963a822c1a9814bf4eba3e9dd4485a2cf9.tar.gz |
Continue to separate Gtk related code from core logic: divelist
Move some more logic out of the divelist-gtk.c file.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'divelist.c')
-rw-r--r-- | divelist.c | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/divelist.c b/divelist.c index f574a31fd..61b9116b2 100644 --- a/divelist.c +++ b/divelist.c @@ -88,6 +88,43 @@ dive_trip_t *find_trip_by_idx(int idx) return NULL; } +int dive_nr_sort(int idx_a, int idx_b, timestamp_t when_a, timestamp_t when_b) +{ + struct dive *a, *b; + dive_trip_t *tripa = NULL, *tripb = NULL; + + if (idx_a < 0) { + a = NULL; + tripa = find_trip_by_idx(idx_a); + } else { + a = get_dive(idx_a); + if (a) + tripa = a->divetrip; + } + + if (idx_b < 0) { + b = NULL; + tripb = find_trip_by_idx(idx_b); + } else { + b = get_dive(idx_b); + if (b) + tripb = b->divetrip; + } + + /* + * Compare dive dates within the same trip (or when there + * are no trips involved at all). But if we have two + * different trips use the trip dates for comparison + */ + if (tripa != tripb) { + if (tripa) + when_a = tripa->when; + if (tripb) + when_b = tripb->when; + } + return when_a - when_b; +} + int trip_has_selected_dives(dive_trip_t *trip) { struct dive *dive; @@ -98,6 +135,38 @@ int trip_has_selected_dives(dive_trip_t *trip) return 0; } +/* Get the values as we want to show them. Whole feet. But meters with one decimal for + * values less than 20m, without decimals for larger values */ +void get_depth_values(int depth, int *depth_int, int *depth_decimal, int *show_decimal) +{ + int integer, frac; + + *show_decimal = 1; + switch (prefs.units.length) { + case METERS: + /* To tenths of meters */ + depth = (depth + 49) / 100; + integer = depth / 10; + frac = depth % 10; + if (integer < 20) + break; + if (frac >= 5) + integer++; + *show_decimal = 0; + break; + case FEET: + integer = mm_to_feet(depth) + 0.5; + *show_decimal = 0; + break; + default: + /* can't happen */ + return; + } + *depth_int = integer; + if (*show_decimal) + *depth_decimal = frac; +} + /* * Get "maximal" dive gas for a dive. * Rules: |