Commit graph

146 commits

Author SHA1 Message Date
Henrik Brautaset Aronsen
b03ae632d5 Recognize O2 percentage from MacDive import
MacDive use "o2percent" in its XML export

Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-01 09:19:38 +11:00
Dirk Hohndel
8843ee6156 Allow using two different tables to hold dives and gps locations
This only changes the infrastructure and actually loses functionality as
it no longer does the simplistic "just treat the locations as dives and
merge them".

The new code that does something "smart" with the gps_location_table is
yet to be written. But now we can use the XML parser to put the gps
locations downloaded from the webservice into their own data structure.

In the process I noticed that we never used the two delete functions in
parse-xml.c and removed them.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-31 12:01:03 +11:00
Henrik Brautaset Aronsen
9b47dc1f59 Make sure imported rating and visibility are within limits.
The "visibility" value in MacDive XML files could be a random
string, while it's a value of 0-5 in Subsurface.  Importing an
illegal value (such as "11m") resulted in a segfault from
libpangocairo and an "Invalid UTF-8 string passed to
pango_layout_set_text()".

[Dirk Hohndel: fixed int * vs. int issue]

Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-30 12:06:33 +11:00
Linus Torvalds
7aff4d70a6 parse-xml: allow XML nodes with empty tag names
They happen for CDATA content, where libxml2 turns the CDATA fields into
a child of the parent entry, but without a name.

Now, of course, any sane person would just want to use the CDATA as the
string value of the parent itself, but libxml2 probably does this
insanity for a reason.  And the reason is probably that some misguided
people want to *write* XML using libxml2, and then the stupid child node
actually acts as a "now I want you to write this data as CDATA".

Whatever the reason, let's just ignore it.  We will just traverse such a
nameless child and be happy, and we'll give the nameless child the name
of the parent.  Our XML node matching logic will then never see this
insane nameless child at all, and doesn't have to care.

Our whole XML parsing rule-of-thumb is to take the whole "be strict in
what you output, but generous in what you accept" to its logical
conclusion.  Because we will literally accept almost anything, in any
format.  You can mix tags or attributes wildly, and youc an use CDATA or
not as you see fit.  We just don't care.

We're the honeybadger of the divelog world.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-28 21:43:49 -08:00
Linus Torvalds
a1dfae87ae xml-parsing: accept 'sitelat' and 'sitelon' for GPS coordinates
Are they ugly and insane tags? Yes.  Are they used? Bingo.  MacDive uses
this lovely format for specifying dive site location.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-28 21:43:46 -08:00
Linus Torvalds
d322f6762a Be even more permissive in our date parsing logic
Not that we aren't already insanely permissive in parsing just about any
random noise that could _possibly_ be construed as xml and turn it into
a dive, this makes us even laxer.

If somebody wants to have a <date> tag with both date and time, why the
heck not? It's fine.  And if it has just the date, that's fine too.  And
the date can be in any of several formats.  We really don't care, the
more permissive, the better.

We strive to always write beautiful xml, but let's face it, not
everybody else does.  If we can turn random line noise into a dive, we
should do so.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-28 21:43:43 -08:00
Dirk Hohndel
3f261f56f3 Remove some unnecessary variable initializations
Not really bugs, just wasted. They clutter up the output of static
analysis with cppcheck.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-25 16:28:37 -08:00
Jan Schubert
50d0391dfb Centralization for Kelvin and Standardization to milliKelvin
This centralizes all occurrences of Kelvin to dive.h and standardizes all
usages to milliKelvin.

[Dirk Hohndel: renamed the constant plus minor white space cleanup]

Signed-off-by: Jan Schubert <Jan.Schubert@GMX.li>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-24 15:00:52 -08:00
Dirk Hohndel
67d8891af5 Slight change to the parser to avoid false posititives
The webservice output uses 'name' as the tag for the dive location. This
was added to the parser as unqualified tag and without this change
test24.xml was suddenly recognized as a dive (the parser was triggering on
the program 'name' attribute). Name should only be recognized as a dive
location if it is indeed a child of dive.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-24 14:44:29 -08:00
Linus Torvalds
b8efe709a8 Remove saving of dive computer nicnames in system config
We save the (more complete) dive computer information in the XML file
with serial numbers and firmware version if we know about them, so using
a complicated string in the system config was redundant and confusing.

So remove that code.

NOTE! Since the dive computer nicknames are now only saved if the XML
file is saved, we also mark the dive list "changed" when we edit the
nicknames.  That way we'll be prompted to save things before exiting,
even if we don't actually edit any actual dive data.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-24 12:59:36 -08:00
Dirk Hohndel
100c400809 Merge branch 'webservice-import'
Update maxdepth / duration that have moved into the divecomputer
structure.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-24 12:05:16 -08:00
Linus Torvalds
aac44f9b07 Remove XML parsing special case temperature code
We had various hacky historical artifacts in our XML parsing, partly
from our legacy of parsing integer and floating point data separately
(we used to recognize certain import format differences based on whether
the data was in a floating point or integer format).  And partly from
trying to do a good job of importing crap from other dive log software.

Anyway, that actually meant that we refused to parse negative numbers,
and we ignored temperatures of zero because some diving log would do
that for missing values.

Both of these actually bit us when parsing our native XML.  Of course,
only crazy ice divers would ever notice.

Noticed by Henrik Brautaset Aronsen.

Reported-acked-and-tested-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-23 12:55:37 -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
Dirk Hohndel
c521aec884 Import and merge GPS data from the webservice
Dive locations marked (and named) via the companion app are downloaded
from the webservice, parsed and merged with the existing dives.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-23 11:53:42 -08:00
Dirk Hohndel
62c4ec20c7 Fix potential crash with old XML files
A file with no divecomputer section in a dive can trigger a SEGV as cur_dc
could be NULL.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-18 10:39:25 -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
868a2cc090 Split up preference data structure definition into 'pref.h'
.. and rename the badly named 'output_units/input_units' variables.

We used to have this confusing thing where we had two different units
(input vs output) that *look* like they are mirror images, but in fact
"output_units" was the user units, and "input_units" are the XML parsing
units.

So this renames them to be clearer.  "output_units" is now just "units"
(it's the units a user would ever see), and "input_units" is now
"xml_parsing_units" and set by the XML file parsers to reflect the units
of the parsed file.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-10 20:30:32 -08:00
Linus Torvalds
1aa3c0d514 Assemble the actual Suunto serial number
It turns out that the serial number returned by libdivecomputer isn't
really the serial number as interpreted by the vendor. Those tend to be
strings, but libdivecomputer gives us a 32bit number.

Some experimenting showed that for the Suunto devies tested the serial
number is encoded in that 32bit number:

It so happens that the Suunto serial number strings are strings that have
all numbers, but they aren't *one* number. They are four bytes
representing two numbers each, and the "23500027" string is actually the
four bytes 23 50 00 27 (0x17 0x32 0x00 0x1b). And libdivecomputer has
incorrectly parsed those four bytes as one number, not as the encoded
serial number string it is. So the value 389152795 is actually hex
0x1732001b, which is 0x17 0x32 0x00 0x1b, which is - 23 50 00 27.

This should be done by libdivecomputer, but hey, in the meantime this at
least shows the concept. And helps test the XML save/restore code.

It depends on the two patches that create the whole "device.c"
infrastructure, of course. With this, my dive file ends up having the
settings section look like this:

  <divecomputerid model='Suunto Vyper Air' deviceid='d4629110'
serial='01201094' firmware='1.1.22'/>
  <divecomputerid model='Suunto HelO2' deviceid='995dd566'
serial='23500027' firmware='1.0.4'/>

where the format of the firmware version is something I guessed at,
but it was the obvious choice (again, it's byte-based, I'm ignoring
the high byte that is zero for both of my Suuntos).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-09 16:38:21 -08:00
Dirk Hohndel
a58d470bad Remove autogroup from the preferences and store per file instead
Having two spots to toggle autogroup had always been a clear sign of
insanity. The inconsistent ludicrous semantic of when we remembered the
state of autogroup was even worse.

This finally gets rid of that disaster and drops the autogroup setting
from the preferences and makes it instead a per file property. When you
save a file, it saves the state of the autogroup toggle. This seems much
more useful - you may have files where you want to create trips by
default. And others, where you don't.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-01 17:29:38 -08:00
Linus Torvalds
d720e133d8 First step in cleaning up cylinder pressure sensor logic
This clarifies/changes the meaning of our "cylinderindex" entry in our
samples. It has been rather confused, because different dive computers
have done things differently, and the naming really hasn't helped.

There are two totally different - and independent - cylinder "indexes":

 - the pressure sensor index, which indicates which cylinder the sensor
   data is from.

 - the "active cylinder" index, which indicates which cylinder we actually
   breathe from.

These two values really are totally independent, and have nothing
what-so-ever to do with each other. The sensor index may well be fixed:
many dive computers only support a single pressure sensor (whether
wireless or wired), and the sensor index is thus always zero.

Other dive computers may support multiple pressure sensors, and the gas
switch event may - or may not - indicate that the sensor changed too. A
dive computer might give the sensor data for *all* cylinders it can read,
regardless of which one is the one we're actively breathing. In fact, some
dive computers might give sensor data for not just *your* cylinder, but
your buddies.

This patch renames "cylinderindex" in the samples as "sensor", making it
quite clear that it's about which sensor index the pressure data in the
sample is about.

The way we figure out which is the currently active gas is with an
explicit has change event. If a computer (like the Uemis Zurich) joins the
two concepts together, then a sensor change should also create a gas
switch event. This patch also changes the Uemis importer to do that.

Finally, it should be noted that the plot info works totally separately
from the sample data, and is about what we actually *display*, not about
the sample pressures etc. In the plot info, the "cylinderindex" does in
fact mean the currently active cylinder, and while it is initially set to
match the sensor information from the samples, we then walk the gas change
events and fix it up - and if the active cylinder differs from the sensor
cylinder, we clear the sensor data.

[Dirk Hohndel:  this conflicted with some of my recent changes - I think
		I merged things correctly...]

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-30 20:44:47 -08:00
Dirk Hohndel
e3ab1c0701 Update deco handling
This commit makes deco handling in Subsurface more compatible with the way
libdivecomputer creates the data. Previously we assumed that having a
stopdepth or stoptime and no ndl meant that we were in deco. But
libdivecomputer supports many dive computers that provide the deco state
of the diver but with no information about the next stop or the time
needed there. In order to be able to model this in Subsurface this adds an
in_deco flag to the samples. This is only stored to the XML file when it
changes so it doesn't add much overhead but will allow us to display some
deco information on dive computers like the Atomic Aquatics Cobalt or many
of the Suuntos (among others).

The commit also removes the old event based deco code that was commented
out already. And fixes the code so that the deco / ndl information is
stored for the very last sample as well.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-30 18:17:21 -08:00
Lubomir I. Ivanov
8bce372eb1 Don't allocate an intermediate buffer for most parsed xmlNode contents
parse-xml.c:
Instead of always allocating a buffer when parsing a node, only
do so for "strings" in the utf8_string() function. Also move the
whitespace trimming of node contents in there.

This change also requires that most parsing functions don't
free the passed buffer, as it will be part of memory allocated
by libxml2.

visit_one_node(), now also has a xmlIsBlankNode() check, where if
1 is returned, the node contains only whitespace or is empty and should
not be processed.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-28 08:58:44 -08:00
Lubomir I. Ivanov
cc3b87c044 Clear memory allocated for event names
parse-xml.c:
When parsing events, we allocate memory for the event 'name' attribute,
but also have to free this memory eventually. Let's do that in event_end()
right after add_event() is called.

Fixes a long-running memory leak in the parser.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-27 08:05:18 -08:00
Dirk Hohndel
e726c9d65c Add settings section to XML file format and store dive computer IDs
We only store the model/deviceid/nickname for those dive computers that
are mentioned in the XML file. This should make the XML files nicely
selfcontained.

This also changes the code to consistently use model & deviceid to
identify a dive computer. The deviceid is NOT guaranteed to be collision
free between different libdivecomputer backends...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-26 16:46:21 -08:00
Dirk Hohndel
8d2abc05f6 Remove nickname from divecomputer data structure
Having it there with the model information seemed to make sense but on
second thought it's the wrong spot to keep that information, especially
since we were storing it in the XML file in every single dive.

This change removes the nickname member from the divecomputer and makes
the rest of the code reasonably self consistent. It does not add much of
the new code for the new design to handle nicknames.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-21 20:58:47 -08:00
Linus Torvalds
e897b95b62 Prevent bleeding deco/ndl for XML files without divecomputer entries
Miika's xslt patch creates correct XML data without divecomputer entries.
What happens is that the stop information at xml parse time is only
cleared by the divecomputer entries, so if the XML lacks them, we will
bleed stop data from one dive to the next.

This patch makes sure that the deco/ndl information is cleared even if the
dive has no divecomputer entry.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-19 20:07:28 -10:00
Dirk Hohndel
713a4fcff6 Add the ability to set a nickname for a dive computer
We maintain a list of dive computers that we know about (by deviceid) and
their nicknames in our config. If the user downloads dive from a dive
computer that we haven't seen before, we give them the option to set a
nickname for that dive computer. That nickname is displayed in the profile
(and stored in the XML file, assuming it is not the same as the model).

This implementation attempts to make sure that it correctly deals with
utf8 nicknames.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-13 21:33:30 -10:00
Dirk Hohndel
afda6dac51 Fix minor indentation issue
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-11 13:40:07 -08:00
Dirk Hohndel
91577f11b5 Merge branch 'cns' into cns-merge
I foolishly changed visible_columns in both the (ill-named) cns branch and
master...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>

Conflicts:
	divelist.c
	gtk-gui.c
	profile.c
2012-12-11 13:09:48 -08:00
Dirk Hohndel
92c0d8c516 Move global variables covered by Preferences into one structure
Now we can simply remember the state of all the preferences at the
beginning of preferences_dialog() and restore them if the user presses
'Cancel'.

Fixes #21

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-10 10:26:06 -08:00
Dirk Hohndel
9d80e7bfe4 Add CNS and pO2 tracking in the samples
This adds the new members to the sample structure and fills them from
supported dive computers (Uemis SDA and OSTC / Shearwater Predator,
assuming you have libdivecomputer 0.3).

Save relvant values of this to the XML file and load it back. Handle the
new fields when merging dives.

At this stage we don't DO anything with this, all we do is extract them
from the dive computer, save them to the XML file and load them back.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-07 21:03:39 -08:00
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
1bc4aba8e7 Remove the ability to import Uemis SDA files
The downloader has been integrated into Subsurface for a while and with
the recent change to no longer have it create the old style SDA files as
intermediary format there is no need anymore to support that format in the
XML parser.

This deletes almost 300 lines of code. Yay!

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-30 13:50:54 -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
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
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
Miika Turkia
2feaf1e815 Fix error message (parsing weight here)
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-24 09:00:30 -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
Linus Torvalds
2a78f3436c Fix the XML gps parsing and saving when using non-US locales
The GPS parsing and saving was using sscanf and sprintf respecively, and
since it is using floating point values (boo!) that affects both of
them.  In a C/US locale, we use a period for decimal values, while most
European locales use a comma.

We really should probably just fix things to use integer values (degrees
and nanodegrees?) but this is the simplest fix/workaround for the issue.

Probably nobody ever really noticed until I tested the Swedish locale
for grins, since we don't have a good way to actually set the GPS
coordinates yet.  I've got a few dives with GPS information that I
entered manually.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-19 12:03:44 -08:00
Dirk Hohndel
56f62cc4ab Store and parse salinity and surface pressure
In my excitement about extracting these from libdivecomputer I forgot to
actually store them and then parse them again. Oops.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-12 20:57:49 +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
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
7b18674871 Fix cut and paste error in an error message
This has been around for a loooong time, I just happened to stamble across
it when reading the code...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-10 11:54:15 +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
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