Commit graph

24 commits

Author SHA1 Message Date
Linus Torvalds
666538ec77 Add helper 'for_each_dive()' dive iterator
It's an easy thing to do, but the for-loop ends up being pretty ugly, so
hide it behind the macro.

It would be even prettier with one of the (few) useful C99 features:
local for-loop variables.  However, gcc needs special command line
options, and other compilers may not do it at all. So instead of doing

   #define for_each_dive(_x) \
      for (int _i = 0; ((_x) = get_dive(_i)) != NULL; _i++)

we require that the user declare the index iterator too, and the use
syntax becomes

   for_each_dive(idx, dive) {
	... use idx/dive here ...
   }

And hey, maybe somebody actually will want to use the index, so maybe
that's not all bad.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-08-21 15:51:34 -07:00
Linus Torvalds
972669d636 Rework dive selection logic
This completely changes how we keep track of selected dives: instead of
having an array listing the selection ("selectiontracker") or trusting
the gtk selection information, just save the information about whether a
dive is selected in the dive itself.

That makes it trivial to keep track of the state of selection across
group collapse/expand events, or when changing the tree view model.  It
also ends up simplifying the code and logic in other ways.

HOWEVER, it does currently (re-)introduce an annoying oddity with gtk:
if you collapse a dive trip that has individual selections, gtk will
forget those selections ("out of sight, out of mind"), and when you do
*new* selections, the old hidden ones remain.

So there's some games required to make gtk do sane things.  We may need
to either explicitly drop selections when collapsing trips, or make sure
the group entry gets selected when collapsing a group that has
selections in it. Or something.

There may be other issues introduced by this too.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-08-20 05:48:07 -07:00
Dirk Hohndel
d7ea559d8b Change default behavior for Stats to show selected dives
Previously when only one dive was selected, the Stats notebook page would show
the statistics for all dive. That creates a very illogical behavior when
clicking on the different dive groups in the dive list. The stats page would
always show how many dives where in a group when the group was selected, except
when there was only one dive in the group, in which case the statistics for all
the dives were shown.

With this change we also show the statistics for the selected dives, even if it
is just one. If you want the statistics for all dives, simply select them all
(Ctrl-A or Command-A on a Mac).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-08-18 18:08:54 -07:00
Dirk Hohndel
7cf0f6d5e1 Stop relying on gtk to track which dives are selected
We spend way too much effort trying to get gtk to manage the dives that
are selected. The straw that broke the camel's back is that gtk forces us
to expand any nodes that we want to select - so selecting a summary entry
for a dive trip forced us to expand all the dives in the dive trip. Which
as Linus pointed out really sucked from a user experience.

So instead we now completeley ignore gtk's weird idea of what is selected
and what isn't and simply track things ourselves. We still need to play
some games with gtk to make sure that the correct rows are SHOWN as
selected, but still, the overall code seems much cleaner.

This commit contains a bunch of debugging code that is ifdef'ed out -
this is extremely useful to make sure I didn't mess anything up, but
eventually I'll want to remove that again as it just looks ugly in the
code.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-08-16 16:47:49 -07:00
Dirk Hohndel
822b6409d7 Fix selecting and unselecting summary items
The dive list now seems to behave intuitively.

In order to do this we had to intercept the select function in addition to
having a selection-changed callback. That way we can simulate the
multi-level selection and unselection that was missing.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-08-14 13:22:31 -07:00
Dirk Hohndel
dc9d0e23e5 Maintain selected rows when switching between list model and tree model
We keep track of the DIVE_INDEX of all selected dives and simply re-select
those dives after changing model (date based sort or sort by other
column).

There are a few TODOs left. We lose the sort direction (ascending /
descending) when switching models. We also don't correctly deal with the
user selecting summary rows in the tree model.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-08-14 12:43:16 -07:00
Linus Torvalds
4033625567 Fix a couple of possible divide-by-zero conditions in statistics
Several people reported the average time problem, but there's another
one lurking there too: if the dive duration is zero, you get bogus
average depth information too (but because that one was a floating point
divide, and by default they are unsignalling on x86, it didn't crash, it
just resulted in bogus results).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-06-30 20:12:11 -07:00
Miika Turkia
9fad1cb50f Fix broken average SAC calculation
old_sac_time was always 0 when calculating average air consumption.
Thus the results were incorrect.  Move the counter to stats_t structure
as suggested by Linus.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-03-29 22:37:32 -07:00
Miika Turkia
9933ccd7cf Show statistics of selected dives
If at least 2 dives are selected, show statistics of these dives on
Overall Stats. Otherwise, show the statistics of all dives. Temperature
is also added to the shown statistics.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>

Minor change to avoid adding statistics.h (moved the global variable and
external function declaration to display-gtk.h).
Another minor change to the text displayed for the "Stats" notebook page.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-03-16 12:12:19 -07:00
Dirk Hohndel
dfb94e5470 Add statistics for longest, shortest, and shallowest dive
I don't really like calling the shallowest dive "min depth", but all other
texts that I could come up with that were reasonably short weren't any
better...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-01-15 15:50:16 -08:00
Dirk Hohndel
788ebc0500 Create separate single dive and total stats pages
No additional statistics added, yet.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-01-15 14:29:08 -08:00
Dirk Hohndel
68a1ff9cf5 Separate out single dive statistics and total statistics
Right now this just changes the infrastructure - nothing outside of
statistics.c is modified. This is simply in preparation to split out the
single dive info and the total dive statistics in the future (as we are
creating more info and more stats and they will overflow the screen area
available - so this will turn into two notebook tabs).

This commit does not change any functionality.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-01-15 13:57:25 -08:00
Henrik Brautaset Aronsen
16b6df559f Define O2 permille for air in one spot
Having the O2 permille defined once is more readable.

Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
2011-12-31 17:15:59 +01:00
Linus Torvalds
9b1ea2ae6d Use common helper function for the "no cylinder info" case
Miika fixed the statistics code that didn't properly check for the "no
cylinder info" case - this cleans it up and just uses the helper
function in equipment.c.

Rename the helper to be slightly better named while at it.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-12-09 09:52:59 -08:00
Miika Turkia
fe532a585c Show O2 per cent if given in cylinder info
O2 per cent from dive computer should be shown in Dive Info if one is
given even without pressure information for the cylinder.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-12-09 09:49:04 -08:00
Linus Torvalds
66c04f4f47 Fix up the statistics page use of pressure data
The statistics page calculates air use separately, and also needs to be
fixed up for the split of the pressures into sample-vs-start/end.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-11-09 08:18:00 -08:00
Lubomir I. Ivanov
97f09f3ea8 don't use strftime() due to locale issues
Make statistics.c use snprintf() with weekday(), monthname() instead of
strftime().  The mingw strftime() ends up having lots of problems at
least on Windows unless you set the locale just right, so just avoid the
problem by doing the simple function by hand.  We already did that in
other places anyway.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-11-07 08:50:06 -08:00
Dirk Hohndel
93d07f631a Don't test for liquid Helium
Simply accept temperatures that are above absolute zero.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-11-04 15:09:56 -07:00
Dirk Hohndel
d906c82f31 Clear O2/H2 field if there is no tank information
Found using the new test dives

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-11-04 11:00:48 -07:00
Dirk Hohndel
0e64a22c14 Don't display a water temperature of absolute 0 in info/stats page
Found using the new test dives

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-11-04 10:57:26 -07:00
Dirk Hohndel
a416847d3b Exclude obviously bogus SAC values from statistics calculations
Random cutoff is 2.8l/min (or about 0.1cuft/min)

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-11-02 15:31:41 -07:00
Dirk Hohndel
b9179aabd5 Fix typo that broke min SAC calculation
Actually more of a cut'n'paste-o

Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-11-02 13:30:49 -07:00
Dirk Hohndel
ba6c570831 Surface interval is calculated from the END of previous dive
Silly mistake

Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-11-02 13:27:25 -07:00
Dirk Hohndel
619ab9e828 Add Info & Stats page to the notebook
This provides the relevant information for the currently selected dive
plus a bunch of statistics over all dives in the dive_table.

The visual design has lots of room for improvement
- right now the different fields change size
- it might be nice to have a more modern look for the entries
- the O2/He field is odd - for most divers the He value will
  always be 0, so maybe we should only show He if there's at least one
  dive that uses He? Also, we simply do a comma separated list of gases
  for all the tanks used

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-11-02 12:27:12 -07:00