Commit graph

148 commits

Author SHA1 Message Date
Linus Torvalds
5e5e3460ac Turn latitude and longitude into integer micro-degree values
This actually makes us internally use 'micro-degrees' for latitude and
longitude, and we never turn them into floating point either at parse
time or save time.

That said, the Uemis downloader internally does still use atof() when
converting things, which is likely a bug (locale issues and all that),
but I'll ask Dirk to check it out.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-05 10:34:02 -08:00
Dirk Hohndel
dcb6574dc4 Improve deco handling and add NDL support
This commit changes the code that was recently introduced to deal with
deco ceilings. Instead of handling these through events we now store the
ceiling (which in reality is the deepest deco stop with all known dive
computers) and the stop time at that ceiling in the samples.

This also adds support for NDL (non stop dive limit) which both dive
computers that appear to give us ceiling / deco information appear to
give us as well (when the diver isn't in deco).

If the mouse hovers over the profile we now add support for displaying the
NDL, the current deco obligation and (if we are able to tell from the
data) whether we are at a safety stop.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-04 21:05:26 -08:00
Dirk Hohndel
15edba9ab0 Remove the hack to mark parsed XML files as downloaded
This was necessary for the Uemis downloader when we used the SDA file
format as intermediary data format and imported that as XML buffer.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-30 13:56:10 -07:00
Dirk Hohndel
4c4dff7683 Convert Uemis downloader to directly create dives
The initial downloader reused the XML parsing of SDA files that was
implemented early in order to support the information extracted from the
SDA with the java applet. But creating this intermediary XML file and
handing it off to the XML import function always seemed like an ugly way
to do things. This became even more obvious when adding more features to
the Uemis downloader.

This commit completely changes the downloader to instead create dives and
record them directly.

This also adds support for divespots (which are stored in a seperate
database that needs to be queried after the divelog and dive entries have
been combined - the Uemis firmware clearly was written by monkeys on
crack - oh wait: I'm trusting these same people to get the deco right?).

This commit leaves the SDA import capability in the XML parser intact.
I'll remove that later. Because of this it actually adds a few lines of
code, but the overall change will be a substantial code deletion.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-30 13:41:58 -07:00
Linus Torvalds
6fe52ee19e Simplify tripflags: remove tripflag_names[]
This removes the tripflag name array, since it's not actually useful.
The only information we ever save in the XML file is whether a dive is
explicitly not supposed to ever be grouped with a trip ("NOTRIP"), and
everything else is implicit.

I'm going to simplify the trip flags further (possibly removing it
entirely - like I did for dive trips already), and don't like having to
maintain the tripflag_names[] array logic.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-26 21:44:51 -07:00
Linus Torvalds
3f197336aa Remove 'tripflag' from dive trips
Both dives and dive trips have the same 'tripflag' thing, but they are
used very differently.  In particular, for dive trips, the only case
that has any meaning is the TF_AUTOGEN case, so instead of having that
trip flag, replace it with a bitfield that says whether the trip was
auto-generated or not.

And make the one-bit bitfields explicitly unsigned.  Signed bitfields
are almost always a mistake, and can be confusing.

Also remove a few now stale macros that are no longer needed now that we
don't do the GList thing for dive list handling, and our autogen logic
has been simplified.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-26 21:44:04 -07:00
Linus Torvalds
ffa3fd551c Clarify (and fix) dive trip auto-generation
This makes the dive trip auto-generation a separate pass from the
showing of the dive trips, which makes things much more understandable.
It simplifies the code a lot too, because it's much more natural to
generate the automatic trip data by walking the dives from oldest to
newest (while the tree model wants to walk the other way).

It gets rid of the most annoying part of using the gtk tree model for
dive trip management, but some still remains.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-26 09:30:27 -08:00
Linus Torvalds
85f0749c85 Remove 'when_from_file' field from dive trip
It had become a write-only field (apart from some now useless debugging)
when simplifying the remove_autogen_trips() function.

So remove it.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-26 09:28:34 -08:00
Linus Torvalds
ba3e6bcc51 Associate each dive trip with the dives in that trip
We already kept a count of dives per trip in order to figure out when
there are no more dives left and the trip needs to be freed.  Now we
explicitly keep track of the list of dives associated with the trip too,
which simplifies the "find the time of the trip" logic.

We may want to sort it in time, but for now this is mainly about trying
to keep track of the divetrip relationships explicitly.  I want to move
away from the whole "use the gtk tree model to keep track of things"
approach.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-26 09:27:24 -08:00
Linus Torvalds
1ca1fe7994 Improve on divecomputer data handling
This simplifies the vendor/product fields into just a single "model"
string for the dive computer, since we can't really validly ever use it
any other way anyway.

Also, add 'deviceid' and 'diveid' fields: they are just 32-bit hex
values that are unique for that particular dive computer model.  For
libdivecomputer, they are basically the first word of the SHA1 of the
data that libdivecomputer gives us.

(Trying to expose it in some other way is insane - different dive
computers use different models for the ID, so don't try to do some kind
of serial number or something like that)

For the Uemis Zurich, which doesn't use the libdivecomputer import, we
currently only set the model name.  The computer does have some kind of
device ID string, and we could/should just do the same "SHA1 over the
ID" to give it a unique ID, but the pseudo-xml parsing confuses me, so
I'll let Dirk fix that up.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-25 13:05:11 -08:00
Linus Torvalds
c019da8fd5 Add basic divecomputer info setup with xml parsing and saving
This also knows how to save and restore multiple dive computers in the
XML data, but there's no way to actually *create* that kind of
information yet (nor do we display it).  Tested by creating fake XML
files with multiple dive computers by hand so far.

The dive computer information right now contains (apart from the sample
and event data that we've always had):

 - the vendor and product name of the dive computer
 - the date of the dive according to the dive computer (so if you change
   the dive date manually, the dive computer date stays around)

Note that if the dive computer date matches the dive date, we won't
bother saving the redundant information in the XML file.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-25 13:04:59 -08:00
Linus Torvalds
25b4fee655 Move events and samples into a 'struct divecomputer'
For now we only have one fixed divecomputer associated with each dive,
so this doesn't really change any current semantics.  But it will make
it easier for us to associate a dive with multiple dive computers.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-23 19:36:27 -08:00
Linus Torvalds
a9786564c2 Allocate dive samples separately from 'struct dive'
We used to avoid some extra allocations by just allocating the dive
samples as part of the 'struct dive' allocation itself, but that ends up
complicating things, and will make it impossible to have multiple
different sets of samples (for multiple dive computers).

So stop doing it. Just allocate the dive samples array separately.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-23 19:33:39 -08:00
Dirk Hohndel
10ce60e212 Fix "prefer download" behavior
When this was first implemented the assumption was that a downloaded dive
that is to be merged with an existing dive would have the same time stamp.
But as Linus pointed out even back then, this does fail if a dive has been
merged with a download from a different dive computer before (think:
download from computer a, then download same dive from b, then improve
something in the parsing from computer a and try to redownload; the time
stamp could have changed).

This commit also fixes a silly omission in the merge_dives() function
(which ended up ALWAYS prefering the downloaded dive) and finally
implements the necessary changes to mark dives downloaded from a Uemis SDA
as well.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-21 15:34:04 -08:00
Dirk Hohndel
05b55542c8 Extract salinity for Uemis SDA and improve depth calculation
THe Uemis SDA allows the user to set it up for salt water and fresh water
use. We should take this into consideration for the water pressure to
depth conversion.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-12 21:17:52 +01:00
Dirk Hohndel
fe4f13f184 Add special download modes to force updates from the divecomputer
This will hopefully not be something we need often, but if we improve
support for a divecomputer (either in libdivecomputer or in our native
Uemis code or even in the way we handle (and potentially discard) events),
then it is extremely useful to be able to say "re-download things
from the divecomputer and for things that were not edited in Subsurface,
don't try to merge the data (which gives BAD results if for example you
fixed a bug in the depth calculation in libdivecomputer) but instead
simply take the samples, the events and some of the other unedited data
straight from the download".

This commit implements just that - a "force download" checkbox in the
download dialog that makes us reimport all dives from the dive computer,
even the ones we already have, and an "always prefer downloaded dive"
checkbox that then tells Subsurface not to merge but simply to take the
data from the downloaded dive - without overwriting the things we have
already edited in Subsurface (like location, buddy, equipment, etc).

This, as a precaution, refuses to merge dives that don't have identical
start times. So if you have edited the date / time of a dive or if you
have previously merged your dive with a different dive computer (and
therefore modified samples and events) you are out of luck.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-11 14:29:26 +01:00
Linus Torvalds
8514ec8723 Support merging of two adjacent dives
This introduces the notion of merging two disjoint dives: you can select
two dives from the dive list, and if the selection is exactly two dives,
and they are adjacent (and share the same dive trip), we support the
notion of merging the dives into one dive.

The most common reason for this is an extended surface event, which made
the dive computer decide that the dive was ended, but maybe you were
just waiting for a buddy or a student at the surface, and you want to
stitch together two dives into one.

There are still details to be sorted out: my Suunto dive computers don't
actually do surface samples at the beginning or end of the dive, so when
you stitch two dives together, the profile ends up being this odd "a
couple of feet under water between the two parts of the dive" thing.

But that's an independent thing from the actual merging logic, and I'll
work on that separately.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-11 10:48:14 +01:00
Linus Torvalds
cda1b73bf6 Prepare to merge non-overlapping dives
This just re-organizes the dive merging code so that we expose a new
"merge_dives(a, b, offset)" function that merges two dives together into
one with the samples (and events) of 'b' at the specified offset after
'a'.

We'll want to use this if a dive computer has decided that the dive
ended (due to a pause at the surface), but we really want to just turn
the two computer dives into one long one with an extended surface swim.

No functional changes, but some independent cleanups due to the trip
simplifications.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-11 10:48:09 +01:00
Dirk Hohndel
7c09991876 Trim the dive to exclude surface time at beginning and end
We don't change any of the samples, we just don't plot (or consider for
dive time / mean calculations) the samples at the beginning or end of the
dive that are less than a certain threshold under water. Right now that's
an arbitrary 75cm which seems to Do The Right Thing(tm) for the dives I
tried this with - but I'm happy to look at other values if this causes
problems for people with dive computers I do not have access to.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-11 10:36:46 +01:00
Dirk Hohndel
4c3dfee446 Merge branch 'pressure'
Make depth to absolute pressure conversions consistent.
2012-11-11 10:00:45 +01:00
Dirk Hohndel
e167108c76 Add depth to mbar helper function
This ensures that we use consistent math to get the absolute pressure at a
certain depth.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-11 08:50:56 +01:00
Linus Torvalds
38c79d149d Simplify and clean up dive trip management
This adds a couple of helper functions to manage dive trips
("add_dive_to_trip()" and "remove_dive_from_trip()") and makes those
functions do the trip statistics maintenance (trip beginning times,
number of dives, etc).

This was needed because the dive merge cases for multiple dive
computers showed some rather nasty special cases: especially if the
new dive information has been loaded into an XML file with trips
auto-generated, merging several of these kinds of xml files with
multiple dives in several overlapping trips would completely confuse
our previous code.

In particular, auto-generated trips that had the exact same date as
previous trips (because they were generated from the same dive
computer) really confused the code that used the trip timestamp to
manage the trips.

Adding the helper functions allows us to get the general case right
without having to have each piece of code that handles trip
information having to bother about all the odd rules. It will
eventually also allow us to make the dive trip data structures more
logical: right now the dive trip list is largely designed around the
odd gtk model handling, rather than some more higher-level conceptual
relationship with the actual dives.

But for now, this keeps all the data structures unchanged, and just
modifies them using the new helper functions.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-11 05:17:00 +01:00
Dirk Hohndel
f53788e5e4 Add support for obtaining salinity from libdivecomputer
This requires a patched libdivecomputer that can return salinity of the
water the dive was conducted in. Experimental patches exist that implement
this for the OSTC. The code is designed so that it simply defaults to salt
water if libdivecomputer doesn't include the feature.

The patch also fixes the dive merge code to merge two other recent
additions to the dive structure (surface_pressure and visibility).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-10 19:22:22 +01:00
Linus Torvalds
3d8c1e50fc Fix default filename handling errors
The default filename handling is broken in two different ways:

 (a) if we start subsurface with a non-existing file, we warn about
the inability to read that file, and then we exit without setting the
default filename.

This is broken because it means that if the user (perhaps by mistake,
by pressing ^S) now saves the file, he will overwrite the default
filename, even though that was *not* the file we read, and *not* the
file that subsurface was started with.

So just set the default filename even for a failed file open.

The exact same logic is true of a failed parse of an XML file that we
successfully opened. We do *not* want to leave the old default
filename in place just because the XML parsing failed, and possibly
then overwriting some file that was never involved with that failure
in the first place. So just get rid of all the logic to push the
filename saving into the XML parsing layer, it has zero relevance at
that point.

 (b) if we do replace the default filename with a NULL file, we need
to set that even if we cannot do a strdup() on the NULL.

This fixes both errors.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-10 16:02:05 +01:00
Dirk Hohndel
e29a436810 Merge branch 'ceiling-plot'
This enables plotting the ceiling in deco dives and also adds the
necessary code to the uemis importer. The only other dive computer this
has been tested with the OSTC and that needs a libdivecomputer patch in
order to provide the deco/ceiling information to Subsurface.

Fixes #5
2012-11-10 12:02:33 +01:00
Dirk Hohndel
6ad73a8f04 Improve logic handling events
We now throw away redundant events, just as we throw away other redundant
data coming from the dive computer. Events are considered redundant if
they are less than 61 seconds apart and identical.

This also improves the display of the remaining events in the profile as
we now show the value of the event, if it is present (for example for a
deco event we show the duration of the deepest stop).

Finally, for events that define a range (so they set the beginning flag
and assume and end flag some time later) we no loger show the triangle but
assume that some other code handles visualizing them (as happens for the
ceiling events).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-10 11:54:15 +01:00
Dirk Hohndel
cc53a0cf5c Use correct surface pressure to detect ceiling with Uemis Zurich
The dive data contains the surface pressure prior to the dive, and that is
what we need to compare p_amb_tol to, not the standard 1013mbar.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-10 11:54:14 +01:00
Linus Torvalds
7f515eb7e5 Fix dive trip merging logic
We used to have very spotty logic for picking the dive trip when
merging two dives. It turns out that that spotty logic almost never
really matters, because in practice you'll never hit the situation of
merging two dives with different dive trips, but it *can* happen.

In particular, it happens when you use multiple dive computers, and
end up loading the dives from one computer on top of the dives of your
other computer. If the clocks of the dive computers was set
sufficiently close to each other, the dive merging logic will kick in
and you may now have slightly different times for the dives that get
merged, and the trip merging logic got *really* confused.

The trip management also depends on the trip dates being updated
correctly when the dives associated with a trip are updated (whether
added or removed), and the trip merging code did none of that.

This fixes it all up. Hopefully correctly.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-09 21:46:56 +01:00
Henrik Brautaset Aronsen
37e3ade2e2 Repair broken Add Dive menu item
Lubomir's commit aec904b612 broke the Add
Dive menu item:  The Edit Dive dialogue didn't show up after the initial
dialogue.

Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-05 09:05:02 -08: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
Lubomir I. Ivanov
5b3e480be3 Added a function to check if specific OS features are available
linux.c, macos.c, windows.c now contain
subsurface_os_feature_available() that can accept an enum type
os_feature_t defined in dive.h.

The function can be useful to check if a specific global feature
is available on a certain OS version.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-19 21:14:00 -07:00
Dirk Hohndel
834825f406 Find translation files on Linux after Subsurface was installed
So far we only looked in the a local subdirectory, but once Subsurface has
been installed, we don't need to change the search path for translation
files anymore.

Fixes #2

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-18 14:30:45 -07:00
Dirk Hohndel
4b9a59a154 Merge branch 'gettext'
Bring all the localization changes into master in preparation for
Subsurface 2.1
2012-10-15 09:37:09 -07:00
Henrik Brautaset Aronsen
ef039c9d32 Support for gettext in MacOSX application bundle
The MacOSX applications bundle needs to be told where to bind the
text domain from.

Also copy the gettext .mo files in the install-macosx target.

[Dirk Hohndel: minor change in main(): move the path declaration to
               the beginning of the function]

Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-15 09:36:30 -07:00
Linus Torvalds
94c98865a7 Improve on the DivingLog importer a bit
This adds a few fields that we parse, but more importantly it also tries
to dynamically decide if the sample temperatures and pressures are in
imperial or metric units.

Dirk suspects that DivingLog generally always does everything in metric,
and the reason why he has crazy sample data in imperial units (both for
pressure and temperature) may be due to a bug in the early Uemis
importer for DivingLog.

Which would actually make a lot more sense than DivingLog really being
so insane on purpose.

Anyway, Dirk's brother Jurgen seems to have everything in metric units,
which would be much saner.  Maybe we should throw away the support for
insane DivingLog files entirely, since it is possible that the only use
ever of the possible source of that bug was Dirk's use of the Uemis
importer.

But for now, we end up just guessing. Current guesses:

 - water temperature is below 32 dgC, so 32+ degrees is in Fahrenheit.

 - tank pressures are below 400 bar, so higher values than that must be
   psi.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-11 15:13:39 +09:00
Dirk Hohndel
a2afe41280 A file that we import should never become the default file we save to
Only files that are opened should be considered r/w. Files that are
imported should be treated as if they were r/o.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-09 21:50:16 +09:00
Lubomir I. Ivanov
f928be5061 Provide a method to use unicode command line arguments on Windows
For unicode command line characters Windows uses UTF-16, while Glib
and GTK use UTF-8. To solve that we retrieve the command line
via __wgetmainargs() and use g_utf16_to_utf8() to convert each argument.

The used method should support wildcards passed as arguments
(e.g. *.xml).

Two new, OS abstracted functions appear in linux.c (NOP), macos.c (NOP),
windows.c:

subsurface_command_line_init(...)
subsurface_command_line_exit(...)

which are being called in main()

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-04 03:12:19 -07:00
Dirk Hohndel
7f5ecb5bb7 Redo the delete dive code
The existing code (both my first single dive delete and then Lubomir's
multi dive delete code) had way too many issues and was just painfully
inefficient.

This new code takes a radically different approach and mostly ignores the
Gtk tree model (as that gets recreated after a delete, anyway) and instead
is linear time on the number of dives in the list. It does do its best to
maintain the existing selection and the expand state of tree model (the
latter isn't possible if we have switched to the list model).

Many thanks to "Lubomir I. Ivanov" <neolit123@gmail.com> for his work on
this - this commit actually contains a few lines out of one of the patches
that he wrote.

Reported-by: "Lubomir I. Ivanov" <neolit123@gmail.com>
Tested-by: "Lubomir I. Ivanov" <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-28 16:23:59 -07:00
Dirk Hohndel
85925afe43 Merge branch 'uemis-native'
This brings in the code to download dive information directly from a Uemis
Zurich dive computer.

The implementation contains a major hack that hooks the uemis code into
the same data structures used to setup libdivecomputer. This gives the
best result for the user, but is not something that I like as a long term
solution as it relies on internal libdivecomputer data structures.
2012-09-26 11:04:50 -07:00
Dirk Hohndel
5305fb152b Add the ability to create a log file for debugging output
Especially when asking non-developers for help debugging a problem it can
be extremely useful to have debugging output not go to the console but to
a log file instead.

This just adds the infrastructure to create (and close) such a file. No
changes to the debug output are made.

All this is of course #ifdef'ed out.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-26 08:34:39 -07:00
Linus Torvalds
6ae67f96f8 Update cylinder info properly
The "cylinders_equal()/copy_cylinders()" functions were buggered, and
only checked (and copied) the cylinder type.  That was on purpose, since
you do want to be able to change the type of a cylinder without changing
the gasmix of the cylinder.

HOWEVER, the reverse is also true: you may want to change the gasmix of
a cylinder without changing the type.

So it's not that the type of the cylinder is special - it's that the
type and the gasmix should be considered separately.

Do that properly for the equipment editing case.

Reported-by: Ďoďo <dodo.sk@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-09-24 12:03:58 -07:00
Linus Torvalds
c4c636fb4f Fix missing save of (almost empty) cylinder information
If we have no explicit cylinder info at all (it's normal air, no size or
working pressure information, and no beginning/end pressure information),
we don't save the cylinders in question because that would be redundant.

Such non-saved cylinders may still show up in the equipment list because
there may be implicit mention of them elsewhere, notably due to sample
data, so not saving them is the right thing to do - there is nothing to
save.

However, we missed one case: if there were other cylinders that *did* have
explicit information in it following such an uninteresting cylinder, we do
need to save the cylinder information for the useless case - if only in
order to be able to save the non-useless information for subsequent
cylinders.

This patch does that. Now, if you had an air-filled cylinder with no
information as your first cylinder, and a 51% nitrox as your second one,
it will save that information as

  <cylinder />
  <cylinder o2='51.0%' />

rather than dropping the cylinder information entirely.

This bug has been there for a long time, and was hidden by the fact that
normally you'd fill in cylinder descriptions etc after importing new
dives. It also used to be that we saved the cylinder beginning/end
pressure even if that was generated from the sample data, so if you
imported from a air-integrated computer and had samples for that cylinder,
we used to save it even though it was technically redundant.

We stopped saving redundant air sample information in commit 0089dd8819
("Don't save cylinder start/end pressures unless set by hand").

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Removed start and end in save_cylinder_info(). These two variables are no
longer used.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-21 21:01:42 -07:00
Linus Torvalds
e8578ad9c9 Merge branch 'divetrip-rewrite' of git://github.com/torvalds/subsurface
Merge the dive trip rewrite by Dirk Hohndel.

This just merges the dive trip changes with the timestamp handling
changes.  There were multiple small data conflicts, along with some
newly added 'time_t' cases in the dive trip handling that needed to be
converted to 'timestamp_t' along the way.

* 'divetrip-rewrite' of git://github.com/torvalds/subsurface:
  Convert FIND_TRIP into function
  Partial rewrite of the dive trip code
  Check if trip is NULL before calling DIVE_TRIP
2012-09-20 12:30:58 -07:00
Linus Torvalds
6d16a15196 FIND_TRIP: don't cast a timestamp to a pointer
The pointer size may not be large enough to contain a timestamp, so make
FIND_TRIP() just pass the pointer to the timestamp instead.

And use an inline function instead of macros with casts.  That gets us
proper type safety while at it, so that we get a warning if somebody
doesn't pass the expected "timestamp_t *".  Plus the code actually looks
simpler and way more straightforward.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-09-20 11:08:15 -07:00
Dirk Hohndel
a8e2fd10c7 Convert FIND_TRIP into function
This helps us deal with the issue that the g_list convenience functions
don't allow us to easily compare 64bit values on 32bit architectures. And
since these convenience functions are truly trivial in nature, it seemed
easier to simply implement our own logic here.

In the process I moved all the dive_trip_list helper functions into the
same spot in divelist.c

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-20 13:00:26 -04:00
Dirk Hohndel
c804c4e02e 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>
2012-09-19 23:49:56 -04: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
d14932058f Fix some of the problems reported by cppcheck
Thanks to Christian for running the static code analysis tool against
subsurface...

There were some false positives, a few style issues that I'll ignore for
now, and two actual potential bugs.

First: Don't check unsigned variables for < 0

This has been around for a while and we are lucky that while technically a
bug it still works as expected. Passing a negative idx simply turns it
into a very large unsigned integer which then fails the > dive_table.nr
test. So it still gets a NULL returned. A bug? Yes. Critical? No.

Mismatched allocation and free

This is an actual bug that potentially could cause issues. We allocate
memory with malloc and free it with g_free. Not good.

Reported-by: Cristian Ionescu-Idbohrn <cristian.ionescu-idbohrn@axis.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-18 20:25:45 -04:00
Lubomir I. Ivanov
7226a48a8c Call xmlCleanupParser only once - when we are done with libxml
Calling xmlCleanupParser in parse-xml.c:parse_xml_buffer()
caused massive memory corruption mostly affecting gtk's FileChooser
dialogs and the application menu.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-18 18:57:52 -04: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