Commit graph

121 commits

Author SHA1 Message Date
Dirk Hohndel
4cf244e228 Fix some of the gcc-4.8 warnings
Most of the warnings are IMHO false positives:
e.g.: an enum variable is initialized in a switch statement that has a case for
      each possible enum value - yet gcc 4.8 warns that it could be used
      uninitialized;
or:   two variables are initialized together in the code - second one of them
      is previously initialized to -1 at declaration time, both are initialized
      in an if (second one == -1) clause - so they are guaranteed to both be
      initialized...
I did not "fix" those as the code is actually correct.

But there are three spots where it catches things that could indeed go wrong
(with odd input data in one of them).

This commit also adds a check to only call g_type_init() for older versions of
glib as in newer ones it is deprecated.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-07 20:25:14 -07:00
Linus Torvalds
1b05d28944 Use the new get_o2()/get_he() helper functions more widely
They do the "02=0 means air" thing autmatically, and make for less
typing.  So use them more widely in places that looked up the o2 and he
permille values of a gasmix.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-03-28 13:47:31 -07:00
Dirk Hohndel
0129192958 Try to capture some more potential buffer overflows caused by localization
A couple of these could clearly cause a crash just like the one fixed by
commit 00865f5a1e1a ("equipment.c: Fix potential buffer overflow in
size_data_funct()").

One would append user input to fixed length buffer without checking.

We were hardcoding the (correct) max path length in macos.c - replaced by
the actual OS constant.

But the vast majority are just extremely generous guesses how long
localized strings could possibly be.

Yes, this commit is likely leaning towards overkill. But we have now been
bitten by buffer overflow crashes twice that were caused by localization,
so I tried to go through all of the code and identify every possible
buffer that could be affected by this.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-03-03 20:18:23 -08:00
Linus Torvalds
308d71ec39 Take incompressibility of gas into account at higher pressures
This creates a helper function called "gas_volume()" that takes the
cylinder and a particular pressure, and returns the estimated volume of
the gas at surface pressure, including proper approximation of the
incompressibility of gas.

It very much is an approximation, but it's closer to reality than
assuming a pure ideal gas.  See for example compressibility at

    http://en.wikipedia.org/wiki/Compressibility_factor

Suggested-by: Jukka Lind <jukka.lind@iki.fi>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-25 16:48:16 -08:00
Lubomir I. Ivanov
dd5e181890 statistics.c: Fix a potential compiler bug triggered in gcc 3.4.5
This may look as a simple formatting change and won't make much sense
to the C programmer. It is an actual bug fix in Subsurface for the
target compiler, since it introduces bogus instructions.

The "month" variable ends up being incremented up to 72 for a single
"month++" call (if inside offset brackets).

gcc -v
Configured with: ../gcc-3.4.5-20060117-3/configure --with-gcc --with-gnu-ld
--with-gnu-as --host=mingw32 --target=mingw32 --prefix=/mingw --enable-threads
--disable-nls --enable-languages=c,c++,f77,ada,objc,java --disable-win32-registry
--disable-shared --enable-sjlj-exceptions --enable-libgcj --disable-java-awt
--without-x --enable-java-gc=boehm --disable-libgcj-debug --enable-interpreter
--enable-hash-synchronization --enable-libstdcxx-debug
Thread model: win32
gcc version 3.4.5 (mingw-vista special r3)

OS: Windows 7 [6.1.7601] - x64

Better explained here:
http://lists.hohndel.org/pipermail/subsurface/2013-February/003967.html

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-23 15:22:34 -08:00
Lubomir I. Ivanov
4e32a5031f statistics.c: Added missing translation of "<unit>/min"
"<unit>/min" should be OK for most Latin languages, but for Cyrillic
we have to translate "min" as well.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-23 08:23:51 -08:00
Dirk Hohndel
6ce4d29f49 Clear statistics and equipment when no dive is selected
This all seems very strange forward.

The reason for the check whether the stats_w widget has been populated is
that at the very beginning, when the UI is still being assembled, a first
call to switch_page() happens as the notebook pages are assembled. At that
point the stats_w widget is still empty which tells us that we aren't
ready to display anything.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-18 17:00:18 -08:00
Dirk Hohndel
23cfd907de Better handling of manually edited air temperature
We now load and save this in the XML file, we do the right thing when
merging dives and show the edited air temperature in the Dive Info
notebook when a divecomputer doesn't have an air temperature.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-14 09:44:18 -08:00
Dirk Hohndel
b9865d6bbc Move duration to dive structure and replace accessor function
When starting on this quest to stop using the first divecomputer instead
of data for the whole dive in commit eb73b5a528c8 ("Duration of a dive is
the maximum duration from all divecomputers") I introduced an accessor
function that calculates the dive duration on the fly as the maximum of
the durations in the divecomputers.

Since then Linus and I have added quite a few of the variables back to the
dive data structure and it makes perfect sense to do the same thing for
the duration as well and simply do the calculation once during fixup.

This commit also replaces accesses to the first divecomputer in
likely_same_dive to use the maxdepth and meandepth of the dive (those two
slipped through the cracks in the previous commits, it seems).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-09 07:19:29 -08:00
Dirk Hohndel
c7efcb23a9 Add a meandepth to the dive structure
This is currently only used in one place (in statistics.c), but it
certainly is consistent with the other recent changes to avoid using only
the first divecomputer when trying to make statements about a dive.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-09 07:02:43 -08:00
Dirk Hohndel
0755cc522b Show the actice divecomputer's data in the Info notebook
While the profile switched between different divecomputers, the Dive Info
notebook always showed either information from the first divecomputer or
(with some of the recent changes) information that had been collected from
all divecomputers and somehow consolidated for the dive.

With this commit we now show the data from the same divecomputer that is
also shown in the profile (which means if some data is available from one
of the divecomputers and not from another that will be correctly reflected
in the Dive Info notebook as the user cycles through the divecomputers.

This does beg the question if we should have some kind of "best data
available, considering all divecomputers" mode - but that's definitely not
something I'll tackle prior to 3.0.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-09 06:17:25 -08:00
Dirk Hohndel
1511271201 Add maxdepth back to the dive structure
Populate during dive fixup as the maximum depth shown by all the
divecomputers. Use this value (instead of the one in the first
divecomputer) in printing, statistics, etc.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-08 20:44:04 -08:00
Dirk Hohndel
b8c7992bbf Improve calculation of maxtemp and mintemp of dive
The existing code only populated the maxtemp based on the samples of a
dive and then in statistics.c checked if there was no such temperature and
replaced it with the water temperature of the first divecomputer.

It makes much more sense to add the water temperature information in every
divecomputer to the min / max calculation during the dive fixup phase.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-08 20:14:13 -08:00
Linus Torvalds
b286ea638c Simplify/clarify the get_surface_pressure_in_mbar() function
Instead of maintaining a rolling average and re-calculating it at each
stage, just calculate the surface_pressure average the natural way: as
the sum divided by the number of entries.

This results in a single rounding, rather than doing rounding multiple
times and possibly rounding wrong as a result.

Not that we care all that deeply about the LSB of the mbar value, but
the code is simpler and more obvious this way too.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-08 18:15:51 -08:00
Dirk Hohndel
61861d2611 Clean up the handling of surface pressure
There are two ways to look at surface pressure. One is to say "what was
the surface pressure during that dive?" - in that case we now return an
average over the pressure reported by the different divecomputers (or the
standard 1013mbar if none reported any).

Or you want to do specific calculations for a specific divecomputer - in
which case we access only the pressure reported by THAT divecomputer, if
present (and fall back to the previous case, otherwise).

We still have lots of places in Subsurface that only act on the first
divecomputer. As a side effect of this change we now make this more
obvious as we in those cases pass a pointer to the first divecomputer
explicitly to the calculations.

Either way, this commit should prevent us from ever mistakenly basing our
calculations on a surface pressure of 0 (which is the initial bug in
deco.c that triggered all this).

Similar changes need to be made for other elements that we currently only
use from the first divecomputer, i.e., salinity.

Reported-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-09 08:01:59 +11:00
Dirk Hohndel
9846ba9e94 Duration of a dive is the maximum duration from all divecomputers
So far we always used the duration of the first divecomputer. The same fix
needs to be done for some of the other calculations that always use the
first divecomputer.

This commit also removes some obsolete code from the webservice merging.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-08 17:48:07 +11:00
Dirk Hohndel
7f59026dbf Distinguish the two uses of "Gas Used" for translation purposes
One is about the amount, the other about the specific type of gar that was
used.

Reported-by: Sergey Starosek <sergey.starosek@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-03 18:03:10 +11:00
Dirk Hohndel
b709dff23d Clear yearly statistics when closing data file
Another oversight of what needed to be done when cleaning up the UI after
closing the data file.

Reported-by: Sergey Starosek <sergey.starosek@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-01 00:19:03 +11:00
Dirk Hohndel
d37f8736db Place Info and Stats page at the top of notebook page
This seems to look better than the previous "centered" setup when
switching between notebook pages.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-31 17:18:06 +11:00
Dirk Hohndel
e3a8ed5183 Massive cleanup
Mostly coding style and whitespace changes plus making lots of functions
static that have no need to be extern. This also helped find a bit of code
that is actually no longer used.

This should have absolutely no functional impact - all changes should be
purely cosmetic. But it removes a bunch of lines of code and makes the
rest easier to read.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-30 08:31:53 +11:00
Dirk Hohndel
8cbe2af4e9 Display air pressure in the Info notebook
I can't find it in myself to care enough to display this in other units.
mm/Hg anyone? I didn't think so.

We still can't edit this value, but at least if w are able to read it from
the dive computer we also show it to the user.

See #19

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-30 06:44:00 +11:00
Linus Torvalds
41027c2843 Make subsurface compile with -DGSEAL_ENABLE
This forces us to use the proper gtk accessor functions.  It may not be
worth it if people actually do the Qt conversion, but if we want to try
gtk3 at some point, this might help.

This all came about because I was trying to explain on G+ what an
immense pain this all was to even figure out, if you don't actually know
gtk at all.  Google and the gtk migration guide are almost useless, and
the gtk2 documentation itself actually uses the fields directly without
any accessor functions in several places.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-28 07:54:55 -08:00
Dirk Hohndel
55296e9dad Remove unused variable for unit name in statistics calculations
The code was incorrect - and completely unnecessary.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-24 13:10:04 -08:00
Henrik Brautaset Aronsen
e3088930ab Use actual min and max temperatures in statistics.
The statistics page only used each dive's "watertemp" attribute,
regardless of actual higher/lower temperatures in the samples.  By
finding the actual max/min temperatures, the statistics page utilize
more "real" data, and look better even on single dives.

Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-24 13:00:03 -08:00
Linus Torvalds
b6c9301e58 Move more dive computer filled data to the divecomputer structure
This moves the fields 'duration', 'surfacetime', 'maxdepth',
'meandepth', 'airtemp', 'watertemp', 'salinity' and 'surface_pressure'
to the per-divecomputer data structure.  They are filled in by the dive
computer, and normally not edited.

NOTE! All actual *use* of this data was then changed from dive->field to
dive->dc.field programmatically with a shell-script and sed, and the
result then edited for details.  So while the XML save and restore code
has been updated, all the displaying etc will currently always just show
the first dive computer entry.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-23 12:55:33 -08:00
Jan Schubert
90d3c5614a Centralising and redefining values as integers
This patch centralizes the definition for surface pressure, oxygen in
air, (re)defines all such values as plain integers and adapts calculations.

It eliminates 11 (!) occurrences of definitions for surface pressure and
also a few for oxygen in air.

It also rewrites the calculation for EAD, END and EADD using the new
definitons, harmonizing it for OC and CC and fixes a bug for EADD OC
calculation.

And finally it removes the unneeded variable entry_ead in gtk-gui.c.

Jan

Signed-off-by: Jan Schubert <Jan.Schubert@GMX.li>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-14 20:12:40 -08:00
Linus Torvalds
6a10700ca5 Add default filename and divelist font to prefs structure
.. and add the usual logic to not save the default values.

This also simplifies the initial system-specific setup of both of these:
since we have defaults for all the preferences that get set up at
startup, we can just initialize those defaults to the system-specific
fonts then and there.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-11 17:46:00 -08:00
Lubomir I. Ivanov
267476e3fe Add some text in statistics.c for translation
Some UI texts were missing translation, such as:
"for selected dive"
"for all dives"

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-22 20:21:59 -08:00
Dirk Hohndel
75f6159a04 If no dives are selected, clear the stats widget
Previously we had lots of zeros and some non-sensical data displayed (the
temp values were actually not zeroed out).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-20 14:47:18 -10:00
Dirk Hohndel
8bbe24f485 Show which dives are covered by the statistics
If all selected dives appear to have numbers that make sense, assemble a
string that lists the selected dives (and try to be smart about finding
ranges) and display those in the frame of the statistics widget.

The code sets an arbitrary length limit on that list of dive numbers and
tries to be smart about creating an ellipsis if necessary.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-20 14:32:39 -10:00
Dirk Hohndel
54919c1c4e Rename on_delete function in statistics.c
We made the one in gtk-gui.c a global function and now had a clash with
the static one in statistics.c

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-09 16:16:35 -08:00
Linus Torvalds
fbbdb834f9 Fix average temperature statistics
We generate the average temperature statistics by adding up the
(converted to user unites - not in millikelvin) temperatures and then
dividing by the number of dives we've added up over.

HOWEVER.

We did that summing of the temperatures into an integer variable, even
though the converted temperatures are floating point.  So things got
rounded down to integers and the average temperature was just bogus
(although reasonably close).

We could do the summing of the temperatures in millikelvin and only
doing the conversion to the user at the very end.  But the smaller patch
is to just change the accumulator to a double value.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-11 18:49:29 +01:00
Dirk Hohndel
01f1ccff14 Add support for visibility tracking and allow manual entry air temp
Turns out we had a data field for visibility as a length unit - but never
used it. I can never guess how much visibility we actually had on a dive -
but I think most everyone can assign a rating between abysmal (zero stars,
"I couldn't read my dive computer even right in front of my mask" - trust
me, I had some of those dives) to amazing ("five stars, I could see farther
than I though possible" - and I had one or two of those, too). So I
changed this to an integer and am re-using the star infrastructure we have
for the overall dive rating.

When displaying this I was dismayed that we are running out of space in
the "Dive Notes" notbook. So I moved this to the "Dive Info" notebook.
This is not consistent and not logical. I think we need to revisit the
notebooks and think about what we want to display where.

While adding the infrastructure to manually enter the visibility I went
ahead and added the ability to manually enter the air temperature as well
(that was one of the things missing in the previous commit).

Fixes #7

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-28 16:03:03 -07:00
Dirk Hohndel
601ac0c362 Display air temperature in the info notebook page
So far we don't parse air temperature data via libdivecomputer. Nor are we
set up to allow the user to manually enter it. We can parse it when
downloading from a Uemis Zurich, though.

This feature was suggested via trac.hohndel.org; this commit implements
only part of what is requested there, so I simply reference the ticket
here without closing it.

References ticket #7

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-28 13:17:12 -07:00
Lubomir I. Ivanov
6ff784113e Translate the SAC value in 'Dive Info'
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-17 15:08:42 -07:00
Dirk Hohndel
dbae888abc Handle dates and a "calculated plural" in translations
This looks like a massive commit mainly because of the line number changes
in the .po files. That sadly hides what really happened here:

- the places where we manually build dates have now been localized
- the one place where we did the English "calculated plural" has been
  modified so that it now can be correctly translated (in English this
  just adds an 's' to the noun if the number is != 1 - in other languages
  this tends to be much more complicated)

I then updated the two German translations to take advantage of the new
constructs. And while I was at it, I changed the translation Trip->Gruppe
to Trip->Reise as that seemed much more appropriate.
I also fixed another error in the German translation where I translated
"dive time" as "Startzeit" - but in the context it was "Dauer".

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-17 01:25:49 -07:00
Henrik Brautaset Aronsen
13cc5afb7f Avoid zero degrees Kelvin in yearly statistics
Maximum and minimum degrees in the yearly statistics were displayed
as -273.1°C if no temperature info was present.

H

From 7d9aad01133bc03980f66a2d109c9ef909e518ad Mon Sep 17 00:00:00 2001
From: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Date: Tue, 16 Oct 2012 18:13:16 +0200
Subject: [PATCH] Avoid zero degrees Kelvin in yearly statistics
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Maximum and minimum degrees in the yearly statistics were displayed
as -273.1°C if no temperature info was present.

Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-16 09:19:48 -07:00
Dirk Hohndel
f1569a206e Improve translations
- fix two missing strings in equipment.c (thanks to Tommi Saviranta for
  pointing this out)

- add context for the translations of the Yearly/monthly statistics. The code
  for this ended up being incredibly ugly, but the gettext infrastructure
  really clashed with the way this is implemented. What I have now at least
  works (tested with the German translation)

- merge the new strings into all the po files. The non-German translations need
  to be updated. Make sure you remove the "# , fuzzy" lines or the current
  Makefile will ignore those additions.

- some minor cleanup of the po files (many listed the wrong language, all of
  them copied my incorrect use of PACKAGE (instead of saying "Subsurface").

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-14 20:47:00 -07:00
Dirk Hohndel
99846da77f Conversion to gettext to allow localization
This is just the first step - convert the string literals, try to catch
all the places where this isn't possible and the program needs to convert
string constants at runtime (those are the N_ macros).

Add a very rough first German localization so I can at least test what I
have done. Seriously, I have never used a localized OS, so I am certain
that I have many of the 'standard' translations wrong. Someone please take
over :-)

Major issues with this:

- right now it hardcodes the search path for the message catalog to be
  ./locale - that's of course bogus, but it works well while doing initial
  testing. Once the tooling support is there we just should use the OS
  default.

- even though de_DE defaults to ISO-8859-15 (or ISO-8859-1 - the internets
  can't seem to agree) I went with UTF-8 as that is what Gtk appears to
  want to use internally. ISO-8859-15 encoded .mo files create funny
  looking artefacts instead of Umlaute.

- no support at all in the Makefile - I was hoping someone with more
  experience in how to best set this up would contribute a good set of
  Makefile rules - likely this will help fix the first issue in that it
  will also install the .mo file(s) in the correct place(s)

  For now simply run

  msgfmt -c -o subsurface.mo deutsch.po

  to create the subsurface.mo file and then move it to
  ./locale/de_DE.UTF-8/LC_MESSAGES/subsurface.mo

  If you make changes to the sources and need to add new strings to be
  translated, this is what seems to work (again, should be tooled through
  the Makefile):

  xgettext -o subsurface-new.pot -s -k_ -kN_ --add-comments="++GETTEXT" *.c
  msgmerge -s -U po/deutsch.po subsurface-new.pot

  If you do this PLEASE do one commit that just has the new msgid as
  changes in line numbers create a TON of diff-noise. Do changes to
  translations in a SEPARATE commit.

- no testing at all on Windows or Mac
  It builds on Windows :-)

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-11 10:03:03 +09:00
Miika Turkia
49948e205b Fix yearly statistics after 64-bit time changes
One of the "+1900" cases got incorrectly dropped.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
[ I really wanted the utc_mkdate/mktime functions to use proper years,
  rather than the idiotic "offset by 1900".  However, we still mix
  things with "localtime()" in one place, so for now we have to be
  compatible with the insane tm_year semantics.  - Linus ]
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-09-20 12:36:48 -07:00
Linus Torvalds
dce08deb34 Use a 64-bit 'timestamp_t' for all timestamps, rather than 'time_t'
This makes the time type unambiguous, and we can use G_TYPE_INT64 for it
in the divelist too.

It also implements a portable (and thread-safe) "utc_mkdate()" function
that acts kind of like gmtime_r(), but using the 64-bit timestamp_t.  It
matches our original "utc_mktime()".

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-09-19 17:35:52 -07:00
Dirk Hohndel
3835faa8fb Merge branch 'defaultfile'
By now the default file code seems quite matured, so in preparation for
2.0 we'll bring it back into master.

I made a few small clean-ups during the merge, but the merge itself is
very much straight forward.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-17 21:44:28 -04:00
Dirk Hohndel
febae4d165 Changing Miika's code to avoid global iter
Two things I disliked in Miika's code in commit cbb5bd125b03:

Having an integer variable named "something_iter" with all the GtkTreeIter
around was really confusing.

And having the yearly_iter as a global variable instead of cleanly passing
it around really seemed suboptimal.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-14 10:13:29 -07:00
Miika Turkia
e7d4bbdd72 Improving the yearly statistics code
This will update the yearly statistics window (if open) whenever there
are changes to the dive list.

I also added a check not to open multiple statistics windows.

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

Reworded commit message

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-14 10:09:56 -07:00
Miika Turkia
ae33b5ef52 Display yearly/monthly statistics
Display yearly statistics in a statistics window with option to expand
the viewing on monthly level. The amount of dives along with basic
information like duration, depth, water temperature and air consumption
is displayed in yearly and monthly level. Thus you are able to compare
e.g. development of air consumption or diving activity from year to
year.

Using already existing macro for splitting seconds into minutes:seconds.
Moving repetitive code to a function (couldn't think of the suggested
clever macro, but this should pretty much do the trick).
Now the statistics are updated every time the process_all_dives function
is called. It might make sense to actually verify the structures need to
be re-allocated, but such optimization is currently not implemented.

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

Combined two commits.
Minor cleanups for white space and boolean values.
Significant changes to use the correct units for volumes vs. depths and to
avoid unneccesary lookups of the model storage based on the tree.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-11 07:29:06 -07:00
Dirk Hohndel
a8fd77865c Implement Close menu option that allows closing the data file
This requires some helper routines that allow us to clear out all the
widgets.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-10 14:32:55 -07:00
Linus Torvalds
9380f78c82 Do some whitespace cleanup
The previous commit was a patch from Lubomir, which also had some
whitespace fixes (to go with some new whitespace bugs to replace them)
in it.

I removed the whitespace changes from that patch (don't mix whitespace
fixes with other fixes, unless they are on the same lines!) but decided
to look for other whitespace issues, and this is the result.

I left the non-C files alone, some of the spec and script files also
have whitespace at the end of lines etc.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-08-26 14:41:05 -07:00
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