This data structure was quite fragile and made 'undo' when editing
rather hard to implement. So instead I decided to turn this into a
QMultiMap which seemed like the ideal data structure for it.
This map holds all the dive computer related data indexed by the model. As
QMultiMap it allows multiple entries per key (model string) and
disambiguates between them with the deviceId.
This commit turned out much larger than I wanted. But I didn't manage to
find a clean way to break it up and make the pieces make sense.
So this brings back the Ok / Cancel button for the dive computer edit
dialog. And it makes those two buttons actually do the right thing (which
is what started this whole process). For this to work we simply copy the
map to a working copy and do all edits on that one - and then copy that
over the 'real' map when we accept the changes.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This implements limited support for importing dives from a Palm divelog
software called aquadivelog. Basic depth graph is imported but most of
the metadata is currently discarded.
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Instead of passing pointers to GError around we pass just pointers to
error message texts around and use kMessageWidget to show those. Problem
is that right now the close button on that doesn't do a thing - so the
error stays around indefinitely. Oops.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
DM4 stores the divetime in local time. The conversion from seconds since
year 1 was 2 hours off. (So there is no timezones involved, which is
good for us!)
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Writing to the dive fields for maxdepth, surface pressure, airtemp and
watertemp is not correct. In the case of duration the longer time should
go into the dive, the shorter time into the divecomputer.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Conditional inclusion of libzip, xslt and osm-gps-map just
makes testing more cumbersome, since testers might lack
Subsurface features without knowing.
Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This should fix a crash on Windows when importing Suunto DM4 dive logs.
(Timezones are not handled properly.)
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This will take the DM4 XSLT into use.
In the future it is quite likely that we will have to start using
something more specific on top of the root element name to identify dive
log formats. But as "Dive" is currently a unique root element name for
us, this suffices for now.
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
And as we need the names for that, simplify the way we show the tags in the
Dive Info tab (and mark them for translation while we are at it).
In the process I renamed the constants to DTAG_ from DTYPE_ (and made
their nature as being just bits more obvious).
Also mark the box on the Info tab "Dive Tags", not "Dive Type".
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This started out as a way to keep dives in the dive list but being able to
mark them as 'invalid' so they wouldn't be visible (with an option to
disable that feature).
Now it supports an (at this point, fixed) set of tags that can be assigned
to a dive with 'invalid' being just one of them (but one that is special
as it gets some additional support for hiding such dive and marking dives
as (in)valid from the divelist).
[Dirk Hohndel: merged with the latest code and minor changes for coding
style and consistency. Ensure divelist is marked as
modified when changing 'invalid' tag]
Signed-Off-By: Jozef Ivanecký (dodo.sk@gmail.com)
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Valid divelogs.de export might contain non-ascii characters in CDATA
fields as long as these characters are found in iso-8859-1. So we'll
have to test to make sure the content is fully ascii before calling
xmlStringLenDecodeEntities to decode possible character references.
Acked-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Previously the heading information was on bookmark event, but now we
trigger a heading event when direction info is available.
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Seems that we have to NULL terminate the buffer for
xmlStringLenDecodeEntitites() as otherwise we might end up having extra
data at the end of returned buffer. (Somehow the length parameter is
not respected always, even if it is the proper size returned by the
zip_fread() - header_skip).
Also free the buffer returned by xmlStringLenDecodeEntitites().
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
divelogs.de sends us XML files that explicitly state that they are in
ISO-8859-1 encoding (which is true). These files contain the HTML encoded
Cyrillic characters. Once we decode those characters the resulting file is
actually UTF-8 encoded (which is a superset of ISO-8859-1). That seriously
confuses libxml when it tries to parse things.
So instead recognize divelogs.de files and skip the encoding declaration
for them before decoding the HTML encoded non-ISO-8859-1 characters.
This does show, however, that divelogs.de incorrectly truncates the
encoded strings (at least in some sample data that I created the parsing
throws errors because of that).
Reported-by: Sergey Starosek <sergey.starosek@gmail.com>
Based-on-code-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This generates a .DLD file of selected dives to be uploaded to
divelogs.de. The actual upload functionality along with sensible user
interface is still to be implemented. However, the resulting file from
this patch is tested to work (as far as I can tell) using upload API of
divelogs.de.
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Seems that DM4 has useless cylinder size data on global level and real
data on DiveMixture table. So using the correct data instead of the
global un-used value.
Similarly the DiveMixture table contains cylinder pressures. However, it
appears this information is available on DiveMixture table only in some
cases. So we use start and end pressures from DM table if available,
otherwise we use the global pressures. (My guess is that the DM table
has the pressure info only when the pressure has dropped from the
initial pressure reading that is reported in Dive table before the dive
is considered to have started.)
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The range is still very wide (as we get both air and water temperatures),
but it will at least eliminate some completely bogus outliers.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Localization could be causing floating point numbers to have a comma
instead of a decimal point (in a file format that is really stupid).
If we detect this we replace the comma with a decimal point instead, and
try to re-parse the number, and see if we get further.
The downside of that is that we're changing the buffer we get passed in.
Nobody cares, but still, it's kind of ugly. It's simple, though.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Testing the Planner in Subsurface on a Windows XP SP3 installation,
shows corrupted UTF-8 strings in the case of Cyrillic locales, but
possibly others as well. Instead limited to the Planner, this affects
the entire application.
After some examination it appears that <ctype>'s isspace() in MSVC
on the tested version of Windows is broken for some UTF-8 characters,
after enabling the user locale using: setlocale(LC_ALL, "");
For example, characters such as the Cyrillic capital "BE" are defined as:
0xD091, where isspace() for the first byte returns 0x08, which is the
bytemask for C1_SPACE and the character is treated as space.
After a byte is treated as space, it is usually discarded from a UTF-8
character/string, where if only one byte left, corrupting the entire
string.
In Subsurface, usages of string trimming are present in multiple
locations, so to make this work try to use GLib's g_ascii_isspace(),
which is a locale agnostic version of isspace().
Affected versions of Windows could be everything up to XP SP3,
but not apparently Vista.
Reported-by: Sergey Starosek <sergey.starosek@gmail.com>
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Seems that the database can contain either null or empty string when
there is no pressure data available. Changing the pressureblob
validation to reflect this new information.
Since the temperature profile is binary data, we most likely should
accept 0 as a valid value. My samples have null in this blob if there is
no data so it seems to be different than the pressure blob. But of
course there are no guarantees...
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
I got a few more events from a new sample database. Bookmark heading is
now shown if such information is stored. Also the unknown events display
the event number for easier identification.
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Basic functionality is implemented but at least support for multiple
cylinders is missing. Event/alarm support is only partial.
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
A couple of these could clearly cause a crash just like the one fixed by
commit 00865f5a1e1a ("equipment.c: Fix potential buffer overflow in
size_data_funct()").
One would append user input to fixed length buffer without checking.
We were hardcoding the (correct) max path length in macos.c - replaced by
the actual OS constant.
But the vast majority are just extremely generous guesses how long
localized strings could possibly be.
Yes, this commit is likely leaning towards overkill. But we have now been
bitten by buffer overflow crashes twice that were caused by localization,
so I tried to go through all of the code and identify every possible
buffer that could be affected by this.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
On Tue, Feb 26, 2013 at 6:19 PM, Dirk Hohndel <dirk@hohndel.org> wrote:
> Miika Turkia <miika.turkia@gmail.com> writes:
>
>> On Tue, Feb 26, 2013 at 5:54 PM, Dirk Hohndel <dirk@hohndel.org> wrote:
>>> Miika Turkia <miika.turkia@gmail.com> writes:
>>>
>>>> On Tue, Feb 26, 2013 at 6:45 AM, Dirk Hohndel <dirk@hohndel.org> wrote:
>>>>> I added a few test dives exported from other software (Dm3, DiveLog 5.08,
>>>>> JDiveLog 10.2 from Mac - last one doesn't parse because of encoding... Also
>>>>> a composed XML zip file from DiveLog isn't supported, yet)
>>>>> Find them under dives
>>>>
>>>> Now this gets interesting. Is there ANY logic in the units in the
>>>> dives/TestDiveDiveLog5.08.xml? It seems that some of the temperatures
>>>> are in C (Airtemp and Watertemp) and some in F (samples). Otherwise I
>>>> would guess we are talking metric here, but I do not see any specs
>>>> (another log I have seen from DivingLog had all the units in metric,
>>>> as far as I could guess). BTW is the Weight in kg or lb?
>>>
>>> I have purchased DivingLog and should be able to create any combination
>>> of data for the test file that we could possibly want. I'll do a set in
>>> a moment that describe what SHOULD be there in their notes, maybe that
>>> will clear things up.
>>>
>>> That said, I really want to release 3.0.1 in the next couple of hours,
>>> so this may have to wait for 3.0.2 (if we end up needing that) or 3.1.
>>>
>>>> The divelogs.de UDCF format looks like it shouldn't take long to write
>>>> support for. I'll look into it this evening.
>>>
>>> It is evening for you, right? No pressure, just making sure I understand
>>> what may be coming in in patches in the next hour or two
>>
>> I currently have one version of the DivingLog XSLT. So a bit of
>> verification and that could possibly be used as is. However, this
>> could use a bit more testing than a new support to make sure things
>> are not going to be any worse than they currently are.
>>
>> I have not started with the UDCF yet, but that could be reasonably
>> fast to implement. However, no guarantees. (And yes, it is evening for
>> me)
>
> I can hold off 3.0.1 a couple hours longer if that is a realistic thing
> to do. I don't see the UDCF as that important since we have a different
> format from them that we support. So I think the best possible DivingLog
> support would be my preference.
>
> I'll add a few more exported dives from DivingLog next (and fix the
> naming of the existing ones).
In that case, here is the DivingLog XSLT if anyone can give it a test.
miika
From 4a62058f4f6fd4780f04bce6e1fe45e20abcf33f Mon Sep 17 00:00:00 2001
From: Miika Turkia <miika.turkia@gmail.com>
Date: Tue, 26 Feb 2013 17:46:53 +0200
Subject: [PATCH] XSLT for DivingLog
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Ticket #63 - divinglog 5.08 import issues
This patch will include the GPS coordinates from divinglog.
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This XSLT imports the UDDF logs that I have received samples of. This
includes kenzooid and Heinrichs Weikamp's DR5.
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Commit 28aba5a206 ("Flesh out the UDDF xml parsing a bit more")
improved on parsing UDDF files by teaching "percent()" to also handle
pure fractions like UDDF uses. So in a UDDF file, an o2 value of "1.0"
means "100%".
But it turns out that I have a few dives with "1% He", and the "Turn
fractions into percent" logic also turns that into 100%.
So this makes the 'percent()' function a bit smarter. If it actually
finds a percentage-sign after the number, it knows it is already
percent, not a fraction. That disambiguates the two cases: "1.0" is
100%, but "1.0%" (note the explicit percentage sign) is 1%.
So now our native format cannot get confused, because it generally
tries to avoid naked numbers. Good choice.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This uses the example UDDF file from Jan Schubert's Heinrichs Weikamp
DR5 dives, and now parses the dive dates, the cylinder mixes and the gas
switch events correctly (or at least partially).
It's not perfect: the gas mix has an "id" field that we ignore, and
instead we just depend on the cylinders being in order (which they seem
to be). And I have rather limited test-cases, so maybe something else
is messed up too. But for the six example dives I have, this gives
reasonable data.
Test-data-by: Jan Schubert <Jan.Schubert@gmx.li>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
test_xslt_transforms():
xmlGetProp uses strdup(), so we have to clear the memory if a pointer
is returned.
xmlFree() doesn't seem very portable (strangly enought), so we
use free(..) directly.
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This XSLT converts divelogs.de logs into Subsurface format. Data that is
discarded: weather, water visibility, boat name.
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
We now load and save this in the XML file, we do the right thing when
merging dives and show the edited air temperature in the Dive Info
notebook when a divecomputer doesn't have an air temperature.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Making sure the XSL transformation does not occur on Subsurface's old
XML format. A deeper inspection on the XML content is required as
MacDive and Subsurface (old format) have the same root element (dives).
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This XSLT converts MacDive logs into Subsurface format. It supports both
the current version and the upcoming version of the log format.
Conversion was not tested with Imperial units as no samples were
available of such logs. Thus functionality with Imperial units is not
guaranteed.
Note that the gear inventory is currently discarded.
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>