Commit graph

1355 commits

Author SHA1 Message Date
Dirk Hohndel
f93f578eca Merge branch 'deco2'
Bringing in the first attempts to do our own deco calculations
2013-01-03 21:58:46 -08:00
Lubomir I. Ivanov
fc882f574f Improvements to select_prev_dive() and select_next_dive()
There were some minor problems when moving the selection
cursor around:

1) If the selection was larger than 1, it was possible
for the selection to get "stuck" in the middle of the list.

This patch approaches this by always calling
gtk_tree_selection_unselect_all() before
gtk_tree_selection_select_iter(), or simply always making
sure we have one selected iterator when navigating with the keys.

2) When there was a single top level dive before the first trip
it wasn't possible to navigate trough the child dives of said
trip in both directions.

The patch attempts to fix this by having the hunks/checks:
if (idx < 0) {

(idx is of a trip) performed regardless of other conditions.

*** Note: testing was done by importing all test*.xml
dives with auto-group on.

[Dirk Hohndel: adjusted the patch to also fix on_key_press to only grab
               the key if no modifier key is pressed; otherwise this
	       breaks shift-cursor-keys for selecting multiple dives.]

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-03 21:52:30 -08:00
Linus Torvalds
e5e2fb2038 Fix cylinder printout information
If we print out the pressure difference (because we do not have a cylinder
size), we didn't initialize the precision. We should print out pressures
without decimals.

The attached patch fixes that, and also avoids a NULL pointer printout
(which on Linux will just print out "(null)") if there is no cylinder
type descriptor string. It also cleans things up a bit and uses the
"cyl" pointer instead of repeating the "dive->cylinder[n]" thing.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-03 21:43:34 -08:00
Dirk Hohndel
9cd18c43aa Make GF values configurable
There are a couple of issues with this commit:

GtkEntry should emit the 'changed' signal when it is modified (so that
changes in the preferences get applied right away) - but that doesn't
appear to be working consistently.

Also, this doesn't appear to affect the deco of any dives that I try it
with. So my guess is something is wrong with the underlying deco
algorithm. That's diappointing.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-03 21:41:35 -08:00
Dirk Hohndel
2c33603256 Consider previous dives when calculating deco
This also initializes the N2 tissue saturations to correct numbers
(setting them to zero was clearly silly).

With this commit we walk back in the dive_table until we find a surface
intervall that's longer than 48h. Or a dive that comes after the last one
we looked at; that would indicate that this is a divelist that contains
dives from multiple divers or dives that for other reasons are not
ordered. In a sane environment one would assume that the dives that need
to be taken into account when doing deco calculations are organized as one
trip in the XML file and so this logic should work.

One major downside of the current implementation is that we recalculate
everything whenever the plot_info is recreated - which happens quite
frequently, for example when resizing the window or even when we go into
loup mode. While this isn't all that compute intensive, this is an utter
waste and we should at least cache the saturation inherited from previous
dives (and clear that number when the selected dive changes). We don't
want to cache all of it as the recreation of the plot_info may be
triggered by the user changing equipment (and most importantly, gasmix)
information. In that case the deco data for this dive does indeed have to
be recreated. But without changing the current dive the saturation after
the last surface intervall should stay the same.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-03 20:45:20 -08:00
Dirk Hohndel
5ba250bd48 Use gradient factors in deco calculation
Usually dive computers show the ceiling in terms of the next deco stop -
and those are in 3m increments. This commit also adds the ability to chose
either the typical 3m increments or the smooth ceiling that the Bühlmann
algorithm actually calculates.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-03 20:44:37 -08:00
Dirk Hohndel
aab67e2a5b Add configurable visualization of calculated ceiling
This is on top of the deco information reported by the dive computer (in a
different color - currently ugly green). The user needs to enable this via
the Tec page of the preferences.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-03 20:43:19 -08:00
Dirk Hohndel
3c31d0401d First stab at deco calculations
This seems to give us roughly the right data but needs a lot more testing.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-03 20:43:14 -08:00
Linus Torvalds
3c5ebfe036 Fix cylinder printout information
The cylinder information in the printouts was wrong in many ways. As
Dirk noted, it didn't work at all for air-integrated computers that
had the pressures in the samples, but the math was also confusing and
wrong.

This should fix it.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-03 12:47:19 -08:00
Dirk Hohndel
6f8e9bcff3 Rewrite the nickname replacement function
This function had a couple of bugs. Two different off by one errors and on
top of that it was matching only the deviceid instead of model and
deviceid.

So I simply rewrote it to match against the full pattern and take a much
more straight forward approach to replacing the entry for the divecomputer
under consideration. If the new nickname is entry this implementation
allocates one extra byte - but that didn't seem worth the extra code to
fix it.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-03 12:33:48 -08:00
Salvador Cuñat
8dbe3528b4 Limit to 4 the number of cylinders shown in the data frame
For dives with more than 4 cylinders, the frame got very crowded and we
needed a magnifier to see the numbers.
If we used more than four tanks, let's put the info in another frame, if not, print
the OTUs, the maxcns and the weight sytem in the new frame.
There is still room for two more short data.

Changed naming of nitrox and trimix mixes.

Changed cylinder description.

There are issues with the size of some translations.

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-02 13:03:45 -08:00
Dirk Hohndel
a319d66c4a Use old style (pre gtk-2.22) keysyms
And include the compatibility header to build on newer versions.

Reported-by: Salvador Cuñat <salvador.cunat@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-02 13:01:02 -08:00
Linus Torvalds
b900a21165 Fix mixed dive/trip tree model grouping
In commit 96db56f89c ("Allow overlapping (and disjoint) dive trips")
I allowed dives to be part of arbitrary dive trips regardless of date,
which meant that the divelist tree model code needed to find the right
parent for a dive as it was inserted.

That code stupidly assumed that the top level of the dive list tree
containted *only* trips, which is not at all the case. It happens to
be true if you group all your dives into divetrips (the common case
for autogroup=1, which real users do tend to have), but now that Dirk
made the autogrouping be a per-xml-file setting, it became much easier
to trigger the "mixed trips and non-trip dives" case, and that showed
the stupid bug with the test dives.

So instead of just blindly iterating to the 'n'th entry, search for
the actual entry that is the dive trip we want to associate a dive
with.

Reported-by: Lubomir Ivanov <neolit123@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-02 10:26:30 -08:00
Miika Turkia
52f438bcd0 Treat headings properly when importing Suunto logs
This patch will convert a heading bookmark to Subsurface format.
Suunto's bookmark uses "Heading: <degrees>°" format and was previously
set as the full event name. Now the resulting event will look like:

<event name="heading" value="333" time="0:58 min"/>

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-01 21:51:42 -08:00
Linus Torvalds
bc16f06536 Keep the selected dive visible in the divelist
This patch makes the divelist behave more as you would expect it as you
scroll up and down through its entries.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-01 17:33:11 -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
Dirk Hohndel
030d0c1294 Make sure remember_dc has its own copy of the model string
When called from the parser the model string is freed right after passing
it to remember_dc. So we need to get our own copy.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-01 17:27:33 -08:00
Dirk Hohndel
8fa81a5577 Add ability to remove a divecomputer from our data structures
Right now this isn't used but it will be needed for the yet to be written
UI to manage our divecomputer database.

This commit also fixes an oversight in the remember_dc function. Updates
to nicknames weren't committed to the config.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-01 13:30:20 -08:00
Dirk Hohndel
1c72d90b37 Merge branch 'updown'
Bring in the keyboard handling change
2013-01-01 10:29:18 -08:00
Dirk Hohndel
8f364d0094 Use the Left and Right keys to switch between divecomputers
The existing code had the somewhat retarded Ctrl-C binding for displaying
the next divecomputer and no way to go back to the previous one. With this
commit we use our keyboard grab to map Left and Right to previous and next
divecomputer. Much nicer.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-01 10:20:22 -08:00
Dirk Hohndel
c2e003975e Clear divecomputer saved status before saving the nicknames to XML
In commit c7169bd24f22 "Fix nickname saving in XML file to deal with utf8
characters" I added the helper function to clear the "this divecomputer
has already been saved"-flag. But then forgot to call it from save_dives
before saving the divecomputer nicknames.

Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-01 08:29:43 -08:00
Dirk Hohndel
91ca0d2cf6 First step towards grabbing keys and handling them ourselves
This commit steals the cursor up and down keys away from gtk so regardless
where gtk thinks the focus may be, we can still use the keys to change
between dives.

In the current UI design where all editing happens in separate windows
this works as expected, as we only grab the keys for the main window. If
we manage to re-enable in-place editing then we need to make sure that
this doesn't cause problems (as gtk uses up/down for the ability to change
drop down selections in combo boxes or values in spin buttons. So we must
make sure that we stop stealing these keys once we start editing something
(in which case simply switching to the next/prev dive wouldn't be a good
thing, anyway).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-01 08:24:42 -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
df0ea07292 Fix nickname saving in XML file to deal with utf8 characters
This makes the whole code much cleaner and simpler.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-30 20:27:01 -08:00
Linus Torvalds
96db56f89c Allow overlapping (and disjoint) dive trips
We used to have the rule that a dive trip has to have all dives in it in
sequential order, even though our XML file really is much more flexible,
and allows arbitrary nesting of dives within a dive trip.

Put another way, the old model had fairly inflexible rules:

 - the dive array is sorted by time

 - a dive trip is always a contiguous slice of this sorted array

which makes perfect sense when you think of the dive and trip list as a
physical activity by one person, but leads to various very subtle issues
in the general case when there are no guarantees that the user then uses
subsurface that way.

In particular, if you load the XML files of two divers that have
overlapping dive trips, the end result is incredibly messy, and does not
conform to the above model at all.

There's two ways to enforce such conformance:

 - disallow that kind of behavior entirely.

   This is actually hard.  Our XML files aren't date-based, they are
   based on XML nesting rules, and even a single XML file can have
   nesting that violates the date ordering.  With multiple XML files,
   it's trivial to do in practice, and while we could just fail at
   loading, the failure would have to be a hard failure that leaves the
   user no way to use the data at all.

 - try to "fix it up" by sorting, splitting, and combining dive trips
   automatically.

   Dirk had a patch to do this, but it really does destroy the actual
   dive data: if you load both mine and Dirk's dive trips, you ended up
   with a result that followed the above two technical rules, but that
   didn't actually make any *sense*.

So this patch doesn't try to enforce the rules, and instead just changes
them to be more generic:

 - the dive array is still sorted by dive time

 - a dive trip is just an arbitrary collection of dives.

The relaxed rules means that mixing dives and dive trips for two people
is trivial, and we can easily handle any XML file.  The dive trip is
defined by the XML nesting level, and is totally independent of any
date-based sorting.

It does require a few things:

 - when we save our dive data, we have to do it hierarchically by dive
   trip, not just by walking the dive array linearly.

 - similarly, when we create the dive tree model, we can't just blindly
   walk the array of dives one by one, we have to look up the correct
   trip (parent)

 - when we try to merge two dives that are adjacent (by date sorting),
   we can't do it if they are in different trips.

but apart from that, nothing else really changes.

NOTE! Despite the new relaxed model, creating totally disjoing dive
trips is not all that easy (nor is there any *reason* for it to be
easty).  Our GUI interfaces still are "add dive to trip above" etc, and
the automatic adding of dives to dive trips is obviously still based on
date.

So this does not really change the expected normal usage, the relaxed
data structure rules just mean that we don't need to worry about the odd
cases as much, because we can just let them be.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-30 19:40:15 -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
Dirk Hohndel
46b64d8e21 Add time stamp to the debugging printout of vendor specific samples
They are useful for debugging things in libdivecomputer and this way it's
easier to match the data to specific points in the dive profile.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-30 17:53:51 -08:00
Dirk Hohndel
2581b3870f Make the tooltip text for gaschange events more informative
We now print out "air", "nn% O2", or "(nn/xx)" for trimix.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-29 11:44:11 -08:00
Dirk Hohndel
7aaa539afe Make sure the model is non-NULL before comparing with it
In commit 194a05b18911 "Correct the detection of existing dives in the
Uemis downloader" I forgot to add that check before calling strcmp.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-29 11:28:35 -08:00
Linus Torvalds
e862f7c343 Allow sorting dives by date - without the dive trips in the dive list
We used to enable dive trips whenever we sorted by date, which can be
a bit annoying. Sometimes you really just want to sort all your dives
by date, without necessarily seeing the trip data.

So this changes the default sort to be the "dive number" table, and
then does *not* actually sort by the dive number, but instead enables
the trips, and then sorts the result by date. So the "dive number"
column - which used to be non-sortable - becomes semantically
equivalent to the old date column sorting.

And now sorting by date makes it act like sorting by depth or any
other attribute - we hide the dive trip tree, and just show the plain
list of dives (sorted by date, obviously).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-28 22:35:55 -08:00
Dirk Hohndel
2287dc87cf When libdivecomputer reports a DECOSTOP or DEEPSTOP, set ndl to 0
Without this deco could be mistaken as safety stop (in the case where
between two samples we go from a positive ndl to suddenly having a stop -
so we never reach ndl of 0)

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-28 18:39:01 -08:00
Dirk Hohndel
fd983a0992 Don't store notes that are just one space on the Uemis
Sometimes the Uemis appears to return " " as notes instead of no notes.
This patch filters this out (otherwise redownloading divecomputers can
cause silly things like notes that say "(existing note) or ( )" )

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-28 18:30:02 -08:00
Dirk Hohndel
0233239198 Correct the detection of existing dives in the Uemis downloader
This didn't take multiple divecomputers into account and didn't compare
the model as well as the deviceid to match a divecomputer.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-28 18:23:19 -08:00
Linus Torvalds
020154215d Don't match existing dives by date if the dive computers are known to be different
When downloading from a dive computer, we fall back on matching the
exact date of the dive if we can't tell whether we already have that
exact dive computer data some other way.

However, if you have multiple dive computers and they are sufficiently
well synchronized, they might actually have the exact same date,
despite the fact that we do want to download both dive computers. We
do check the dive start to the exact second, so this sounds unlikely,
but with dive computers rounding time to the next minute etc, it's not
as unlikely as you'd think. Dirk hit it.

So when we match against date, do check that the dive computer might
actually be one we've already downloaded from. If we have full model
information, we can dismiss the "match date" logic.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-28 14:16:29 -08:00
Linus Torvalds
3b136f23ee Make add_dc_to_string() skip redundant entries
There is no point writing out divecomputer nicknames that do not exist
(or that match the dive computer model), so don't.

Also, make the function to do this static to save-xml.c, which is the
only user (I initially didn't _find_ the function to create the XML
string because it was illogically hidden in gtk-gui.c), and change the
calling convention to be more direct (pass in a string and return a
result, rather than modify a "pointer to string").

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-28 09:04:59 -08:00
Lubomir I. Ivanov
fc1bb0a32c Added some extra space for the "or" word when merging two strings
dive.c:merge_text():
When "or" is translated into other languages it may be longer than 2 letters,
therefore there is a need for a slightly larger buffer to be reserved.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-28 08:59:51 -08:00
Lubomir I. Ivanov
596b13e310 Free trip notes memory when deleting a trip
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-28 08:59:42 -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
Dirk Hohndel
df613bf107 Support tank size information download from Atomic Aquatics Cobalt
This should really be done in libdivecomputer, but that can't happen until
the API there gets extended to support tank sizes. So for now with this
code we manually parse the raw dive data (if downloaded via
libdivecomputer from a Cobalt) and setup the tank size ourselves.

This had relatively limited testing so far.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-28 08:53:16 -08:00
Dirk Hohndel
3872921ffe Divecomputer entries with deviceid 0 should be ignored for nicknames
Those only come from a number of development versions of Subsurface that
didn't include the deviceid in the divecomputer entry. There is no way of
telling different dive computers (of the same model) apart, so assigning a
nickname to such an entry then creates incorrect output when loading an
XML file from someone else (e.g. Linus and I both have a Uemis SDA and
both may have entries for our own SDA with deviceid 0; then the nickname
Subsurface shows for any Uemis SDA entry with a deviceid of 0 depends on
whether I last loaded his XML file or mine; that makes no sense).

This should only affect the develoers who stored XML files with one of the
development version of Subsurface that didn't store deviceids.

Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-28 06:36:47 -08:00
Dirk Hohndel
f6fb882337 Fix incorrect memory access in nickname handling
There was one code path where we didn't strdup the nickname - and this got
triggered when parsing XML files with divecomputerid entries for dive
computers that were already in the config. The nickname is then replaced
with the nickname from the parser - and that memory is later reused...

We should cleanup that nickname, anyway, and that also takes care of
making sure we have our own copy.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-27 21:41:12 -08:00
Lubomir I. Ivanov
fd03fcd66d Clear redundant "description" when merging two cylinder types
dive.c:
merge_cyclinder_type() can cause a small memory leak if two cylinder types
are about to be merged, but the redundant one has a "description" string
allocated.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-27 08:15:25 -08:00
Lubomir I. Ivanov
310b05ac84 When a dive computer is deleted also clear its model
dive.c:
A dive computer may have its model allocated in memory.
Let's clear that as well when calling free_dc().

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-27 08:15:11 -08:00
Lubomir I. Ivanov
906fd400e7 Small changes in the memory management when dive-merging
This patch makes a couple of modifications:
1) divelist.c:delete_single_dive() now tries to free all memory associated
with a dive, such as the string values for divemaster, location, notes &
etc.

2) dive.c:merge_text(), now always makes a copy in memory for the returned
string - either combined or one of the two which are passed
to the function.

The reason for the above two changes is that when (say) importing the same
data over and over, technically a merge will occur for the contained dives,
but mapped pointers can go out of scope.

main.c:report_dives() calls try_to_merge() and if succeeds the two dives
that were merged are deleted from the table. when we delete a dive,
we now make sure all string data is cleared with it, but also in the actual merge
itself, which precedes, copies of the merged texts are made (with merge_text()),
so that the new, resulted dive has his own text allocations.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-27 08:08:59 -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
720d4c65e8 Fix crash when trip info changes across remember/restore tree state
Interesting crash. Importing a file gets us to a stage where we have a
trip tree note with a date that doesn't exist as trip date. That's clearly
bogus. And in import_files() we assume that all is still fine and try to
restore the old expanded / selected state for the various trips.

There is clearly a bigger issue here, this patch at least prevents the
actual crash from happening by making sure the pointer is non-NULL before
dereferencing it.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-26 19:44:01 -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
1bd6f72d31 Different is different from the same (fix silly bug in nickname handling)
Trying to simplify the API for nickname handling I went a bit too far. We
indeed need to different API calls, one that returns an entry in the
nicknamelist for the deviceid that we have. And one that looks if there is
an entry for a different deviceid but the same model that we have.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-23 09:06:23 -08:00
Dirk Hohndel
06cd494a2f Next improvement of the nickname code
Now it is able to replace nicknames for existing entries (which will be
needed by the yet to be written UI).

This commit fixes a couple issues with the previous code:
- a potential SIGSEGV with malformed config entries
- missing closing parenthesis in the dialog box text

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-22 21:38:07 -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