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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
The "Tec settings" dialog contains some strings with the
subscript "2" character, which have to be translated. While
the "2" is part of the string xgettext doesn't seem to recognize
such. To trick it we use a temporary buffer and c-format:
sprintf(utf8_buf, _("Show pO%s graph"), UTF8_SUBSCRIPT_2);
button = gtk_check_button_new_with_label(utf8_buf);
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
init_ui():
We add the char pointer "conf_copy" and free it afterwards, since
once "next_token" is changed it no longer points to the allocated heap
location the mapper returned.
[Dirk Hohndel: original patch rewritten to have better variable names and
to match the recent changes to this code]
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
From the GTK docs on gtk_tree_model_get_path():
"Returns a newly-created GtkTreePath referenced by iter.
This path should be freed with gtk_tree_path_free()."
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
We now store the model information together with the deviceid and nickname
in order to be able to check if we have a record for any dive computer
with the same model (as that now triggers our nickname dialog).
This changes the format of the config entries for nicknames - the best
solution might be to just delete those and start again.
What is still missing is the code to store the nicknames in the XML file.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
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>
This will normally happen for CCR dives with a set pO2. The old
calculations was only valid for OC dives.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Previously we had lots of zeros and some non-sensical data displayed (the
temp values were actually not zeroed out).
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
If all selected dives appear to have numbers that make sense, assemble a
string that lists the selected dives (and try to be smart about finding
ranges) and display those in the frame of the statistics widget.
The code sets an arbitrary length limit on that list of dive numbers and
tries to be smart about creating an ellipsis if necessary.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Some acronyms (SAC, OLF, OTU) were not translated since
there's no settled/common ones in russian.
Signed-off-by: Sergey Starosek <sergey.starosek@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
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>
This patch correctly converts the available deco data from JDiveLog files.
In order for this to work correctly the next patch from Linus is needed as
well.
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This adds the capability to actually view all your dive computers, by
adding a menu item under "Log"->"View"->"Next DC" to show the next dive
computer.
Realistically, if you actually commonly use this, you'd use the
accelerator shortcut. Which right now is Ctrl-C ("C for Computer"),
which is probably a horrible choice.
I really would want to have nice "next/prev dive" accelerators too,
because the cursor keys don't work very well with the gtk focus issues.
Being able to switch between dives would also make the "just the dive
profile, maam" view (ctrl-2) much more useful.
The prev/next dive in the profile view should probably be done with a
keyboard action callback, which also avoids some of the limitations of
accelerators (ie you can make any key do the action). Some gtk person,
please?
Anyway, this commit only does the dive computer choice thing, and only
using the accelerators.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This changes two things to improve the appearance of the profile:
- the partial pressure scale is now in 0.5 increments if the total is <= 4
and in 1.0 increments if it is > 4.
- the depth marker lines end slightly below the depth chart so that we no
longer have overlap between the depth scale and the partial pressure
scale.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
In profile.c:create_plot_info(), store the last address in which
memory was allocated for the plot data entries in the static
variable "last_pi_entry". If "last_pi_entry" isn't a NULL
pointer in each call to create_plot_info(), free memory at that
address.
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
In gtk-gui.c:expose_event(), right before clearing the list of tooltips,
we also want to free memory for the associated texts for each one of them.
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
In gtk-gui.c:init() we retrieve the configuration values
for PO2, PN2, PHE thresholds but have to also free the values
once done parsing with sscanf().
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
In render_dc_vendor() and render_dc_product(), there is
no need to allocate memory for the texts that are about to
be added in the combo box trees. Most GTK widgets seem to make
copies of the passed text to them, using g_strdup() and
automatically release said memory when a widget is destroyed.
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
We had logic to remove duplicate dive computer information after merging
dives, but it didn't actually work.
Why? Because we had used the 'res' dive computer pointer to traverse the
list of dive computers, so it no longer actually pointed to the first
dive computer in the result list any more, and so the "remove redundant"
code only removed redundant dive computers from a limited and incomplete
list.
Oops.
Also, before checking the whole event and sample list, check if it's the
exact same dive computer using our new "match_one_dc()" helper function,
and don't even bother checking for sample details if it is.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
If we have a dive computer model and dive ID, use that to match newly
downloaded dives against the existing dives.
Otherwise fall back to "exact date match" again, like we've always done.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
If we havd divecomputer model and dive ID information available, use
that to match existing dives when trying to merge them.
Otherwise fall back to the fuzzy time-based merging logic.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
If the sizes of the two char buffers in set_dc_nickname() (nickname)
and remember_dc() (buffer) are at least twice the size of the allowed
maximum number of characters (sizeof(gunichar) = 2) set by
gtk_entry_set_max_length() for the user nickname,
no truncation will accur then calling snprintf() and cleanedup_nickname()
on said buffers.
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The idea behind editing timestamps had of course been the typical "oops, I
forgot to set my time correctly" which shifts a dive (or a few of them) by
a few hours but keeps the overall order of dives the same).
But reasonable people might argue that they can envision a scenario where
more dramatic changes are being made. And we need to deal with the impact
this has on dive trips.
Here we handle a couple of simple cases:
- this is the only dive in a trip; just update the trip
(this can still cause problems if the new time is in the middle of an
existing trip).
- this dives moves before the start of the trip it is in; let's remove it
from that trip (this response is a bit simplistic - but as I tried to
say, I don't expect this to be a common use case; and removing it at
least doesn't lead to entirely unexpected behavior).
- this dive moves past the end of this trip into the range of a different
trip (in this case we remove the dive from the current trip and allow it
to interrupt the trip it is moving into).
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
in gtk-gui.c:
The input text field in set_dc_nickname() has a limit of 68 unicode
characters, which are 136 bytes. In remember_dc(), to make sure
that this nickname, the deviceid (4 bytes) and also the extra
characters (",{}") always fit wihout truncation (from snprintf) in the
allocated stack buffer, we increase the size of the buffer to 256 bytes.
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Silly typo, but this is the better solution, anyway.
Reported-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>`
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
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>
A vendor of -1 indicates that we should have no product selection in the
dive download dialog. Having the empty product model be the last made it
hard to keep the correct index for that empty model around (and we got it
wrong by default).
With this change the product models are offset by one, so the unset vendor
(-1) turns into index 0 which is where we now store the empty model.
Reported-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
We don't want to directly use the strings returned to us from
libdivecomputer.
Fixes bug 34
Reported-by: Sergey Starosek <sergey.starosek@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>