Commit graph

230 commits

Author SHA1 Message Date
Dirk Hohndel
1b103c5c69 Another small tweak to whitespace tool
clang-format doesn't appear to reindent multi line #define statements
correctly - so this hopefully will clean those up.

The included whitespace corrections to the code should stay in place when
using the updated tool.

This includes cleaning up some multi-line comments that were messed up the
last time around as well as a few other minor changes.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-05 13:02:23 -08:00
Dirk Hohndel
e80a6822d5 Whitespace cleanup for parse-xml.c and save-xml.c
This is looking really good. Done using our whitespace tool.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-16 15:58:13 -08:00
Dirk Hohndel
cdb69aea09 Remove some unused variables
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-15 17:45:22 -08:00
Miika Turkia
bbda9dd108 Import gas info for Shearwater Desktop
Used gas mixes and gas changes are imported. Also po2, ndl, cns and
ceiling are added to profile samples. As far as I can tell, the Searwater
Desktop shows ceiling in 3 meter (or feet equivalent) steps, but stores in feet
(or probably meters). I just use the value reported, no conversion to 3 meter
steps.

Fixes #432

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-14 22:47:10 -08:00
Miika Turkia
62e313df35 Import Shearwater Desktop divelog database
Sqlite database from Shearwater Desktop log software is imported. Just
the basic information like location, buddy, notes and dive profile
(depth and temperature).

This is tested with a DB in Imperial units, thus metric input might
contain errors.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-14 22:46:35 -08:00
Miika Turkia
4b949936c2 Refactoring sqlite import support
Move the opening of DB connection to occur before DC dependent code.
This way we can try to detect log software before calling the DC
dependent import function. This prepares for adding support for
Shearwater sqlite database.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-14 22:45:07 -08:00
Linus Torvalds
23baf20f56 Use "rint()" instead of rounding manually with "+ 0.5"
rint() is "round to nearest integer", and does a better job than +0.5
(followed by the implicit truncation inherent in integer casting).  We
already used 'rint()' for values that could be negative (where +0.5 is
actively wrong), let's just make it consistent.

Of course, as is usual for the messy C math functions, it depends on the
current rounding mode.  But the default round-to-nearest is what we want
and use, and the functions that explicitly always round to nearest
aren't standard enough to worry about.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-12 17:41:49 -08:00
Boris Barbulovski
772c9fb0b1 Fix calloc parameter order.
* Set correct calloc parameters order(num, size)

Signed-off-by: Boris Barbulovski <bbarbulovski@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-10 07:56:09 -08:00
Linus Torvalds
22f66501ac Add support for heartrate and bearing information in samples
libdivecomputer already supports this, but we didn't save it.

Tested-by: Oscar Isoz <jan.oscar.isoz@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-10 07:03:24 -08:00
Lubomir I. Ivanov
a8823c1793 parse-xml.c: Fix a warning about missing braces
warning: suggest explicit braces to avoid ambiguous 'else'

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-09 14:03:57 -08:00
Miika Turkia
361f8ede76 Check XML attribute to detect correct XSLT
Very few dive log files can be identified by the name of the root
element in the XML log. As same element names are used between different
software, we need to use attributes as well to identify correct XSLT to
convert the log to Subsurface format. I would not be surprised if at
some point we'll just have to present a dialog to the user and ask which
software is in use...but this is enough for now.

This also adds the shearwater.xslt to the list.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-08 07:12:35 -08:00
Miika Turkia
b6ef5198f2 Hook up XSLT and include it in resources
XSLT to import manually kept CSV logs is hooked up and included in
resources.

Fixes #427

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-25 06:52:50 -08:00
Robert C. Helling
162d674c5b Don't compare floats for equality
Now that we have a macro to replace float equality testing, we should use
it in places where floating point jitter might bite use otherwise.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-21 14:11:52 -08:00
Miika Turkia
2167088f1c Add Sensus XSLT as a resource and enable it
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-17 05:57:42 +07:00
Dirk Hohndel
a27f67c026 Whitespace and coding style updates
Another futile attempt to cleanup the code and make coding style and
whitespace consistent. I tried to add a file that describes the key points
of our coding style. I have no illusions that this will help the least
bit...

This commit should ONLY change whitespace

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-16 11:50:56 +07:00
Anton Lundin
33391a77e9 Convert the C code to using stdbool and true/false
Earlier we converted the C++ code to using true/false, and this converts
the C code to using the same style.

We already depended on stdbool.h in subsurfacestartup.[ch], and we build
with -std=gnu99 so nobody could build subsurface without a c99 compiler.

[Dirk Hohndel: small change suggested by Thiago Macieira: don't include
               stdbool.h for C++]

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-16 09:34:50 +07:00
Miika Turkia
6037be946f Add a few more Suunto events
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-10 16:13:32 +07:00
Miika Turkia
18e625129e Import tags from Suunto database file
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-10 16:13:29 +07:00
Miika Turkia
b79ef63388 Do not plot temperatures on DM4 import if no info
If we do not have temperature readings, we do not want to plot the
temperature samples either.

See #415

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-10 16:13:22 +07:00
Linus Torvalds
2d1d78ebfe const'ify our strtod() helper functions
The C library doesn't use const char pointers for legacy reasons (and
because you *can* modify the string the end pointer points to), but
let's do it in our internal implementation just because it's a nice
guarantee to have.

We actually used to have a non-const end pointer and replace a decimal
comma with a decimal dot, but that was because we didn't have the fancy
"allow commas" flags.  So by using our own strtod_flags() function, we
can now keep all the strings we parse read-only rather than modify them
as we parse them.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-08 16:38:47 +08:00
Linus Torvalds
cb53a78674 Make our 'ascii_strtod()' helper more generic
We'll want to do sane parsing of strings, but the C library makes it
hard to handle user input sanely and the Qt toDouble() function
interface was designed by a retarded chipmunk.

So just extend our existing hacky "ascii_strtod()" to allow a more
generic interface.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-02 21:17:41 -08:00
Dirk Hohndel
0421a161b4 Silence a few warnings
None of these are actual bugs. But none of the fixes are harmful, either.
And much as I hate adding the 'default' clauses, I'd rather not have the
build output cluttered by invalid warnings.

The exception is the fix in divelistview.cpp - while I don't think it is
possible for this function to be called with no dive selected,
initializing pd to NULL is cheap insurance in case that does happen for
some weird reason.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-20 09:53:06 -08:00
Lubomir I. Ivanov
22b8d95d58 Fix a small coding style issue
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-19 07:28:23 -08:00
Thiago Macieira
397898434e Remove the xslt_path now that all XSLT files are kept in a resource
Signed-off-by: Thiago Macieira <thiago@macieira.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-16 16:20:54 -08:00
Thiago Macieira
ca8aee4701 Move the XSLT files into a Qt resource
This means we no longer need to keep them on disk and worry about
installing / uninstalling them. They will always be kept in-memory
(compressed).

Signed-off-by: Thiago Macieira <thiago@macieira.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-16 16:20:52 -08:00
Dirk Hohndel
89a58e23e0 Correctly parse multiple tags in the divelog
The old parsing code overwrote the first comma with a '\0' and then
checked the index against the length of the buffer - which was changed by
replacing the ',' with the '\0'.

This means that since commit 78acf20848 ("Don't crash on loading tags
longer than 127 chars") Subsurface has potentially damaged / lost data in
dive files!

Added a test dive that shows the issue if opened by a Subsurface version
after the commit mentioned above but before this commit.

Reported-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-12 16:29:06 -08:00
Anton Lundin
2419e074f4 Fix some whitespace damage
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-11 22:19:37 +01:00
Anton Lundin
78acf20848 Don't crash on loading tags longer than 127 chars
We didn't enforce a limit on tag length, but we would crash on a tag
longer than 127 chars.
This uses the xml buffer as scratch space. Don't really know if this is
fair, but it looks like it works.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-11 22:19:15 +01:00
Anton Lundin
d0c7b3bf7d Plug memory leak in duration()
Strdup should be followed by a free()...

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-11 03:13:30 +01:00
Linus Torvalds
4d0d5f8c07 Quiet down valgrind warnings
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-28 12:15:24 -08:00
Anton Lundin
3fd39a7a87 Remove some constants and use helpers instead
We have allot of helpers, use them instead of local variants.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-27 08:30:12 -08:00
Dirk Hohndel
a6b35141e4 Don't parse 32bit hex values with strtol
On a 32bit machine this will truncate values with MSB set to 0x7fffffff

Fixes #164

(thanks to Linus for pointing me in the right direction)

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-22 13:31:52 -08:00
Anton Lundin
a31499de88 Use the get_o2/get_he helpers
We have helpers that take care of O2_IN_AIR and so on.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-20 11:31:23 -08:00
Linus Torvalds
58fa613236 Speed up XML loading
This tries to speed up XML loading for large XML files (and thus
subsurface startup times) by trimming the fat off our own matching code.

The actual libxml overhead (particularly string allocation) tends to be
the dominant part, so this only speeds up a big load by about 12% for me,
but hey, it can be noticeable. Dirk's example nasty 175MB xml file with
~5200 dives takes "only' 7.7 seconds to load, when it used to take 8.8s.
And that's on a fast machine.

For smaller xml files, the dynamic loading costs etc startup costs tend to
be big enough that the xml parsing costs aren't as noticeable.

Aside from switching the node names around to "little endian" (ie least
significant name first) format to avoid some unnecessary strlen() calls,
this makes the nodename generation use a non-locale 'tolower()', and only
decodes up to two levels of names (since that's the maximum we ever match
against anyway).

It also introduces a "-q" argument to make startup timing easier. Passing
in "-q" just makes subsurface quit imediately after doing all necessary
startup code.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-02 12:51:32 -07:00
Maximilian Güntner
6fe8cb6521 Replaced the tag implementation
The new implementation supports custom tags
which are provided by the user as well as
default tags which are provided by subsurface.
Default tags can be translated and will be written
to XML in their non-localized form.

Signed-off-by: Maximilian Güntner <maximilian.guentner@gmail.com>
2013-11-02 02:55:03 +01:00
Miika Turkia
bdedf46e4c Get rid of compiler warning on format strings
This gets rid of compiler warnings "format not a string literal and no
format arguments [-Wformat-security]". E.g. when building distribution
packages these warnings are often treated as errors preventing the
build (with good reason).

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2013-10-20 15:25:27 +02:00
Miika Turkia
4c49670cdb GUI for CSV import
This patch implements GUI for importing CSV log files. One is able to
configure what columns contain time, depth and temperature fields.
Pre-configured log applications currently included are ADP log viewer
and XP5. (Both of these use actually tab as separator, so the field
separator currently hard-coded.)

[Dirk Hohndel: minor fixes]

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-16 12:44:07 -07:00
Dirk Hohndel
193d20c479 Next step towards working translations
This may seem like a really odd change - but with this change the Qt tools
can correctly parse the C files (and qt-gui.cpp) and get the context for
the translatable strings right.

It's not super-pretty (I'll admit that _("string literal") is much easier
on the eye than translate("gettextFromC", "string literal") ) but I think
this will be the price of success.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-09 22:51:59 -07:00
Dirk Hohndel
d9f24b282a Allow passing NULL as second argument to ascii_strtod
We do this in our own sources...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-07 10:59:50 -07:00
Linus Torvalds
8ba5423e65 ascii_strtod that actually does what we need
Dirk's ascii_strtod was blindly copied from other GPL code and didn't do
what was the main purpose (i.e. ignore the locale and still accept the
numbers we have in our data files).

This implementation does *not* care about INF/NaN, and it does *not* try
to handle some strange conditions (overflow/underflow), and I do *not*
guarantee that it doesn't have rounding issues.

That said, for our native format, we never print odd FP numbers anyway
(since we use fixed-point integer arithmetic), and while we *do* care
about exponents for some of the odder import formats (I remember
seeing them in jdivelog output), we don't care about the crazy cases.
So rather than worry about getting the edge cases right for the max
double exponents (around +-308), it just says "screw you" and gives
you something close enough.

So what it *does* try to do is handle the actual parsing right, and
get the right answer for all the reasonable cases.

Works-For-Me(tm).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-07 09:26:08 -07:00
Dirk Hohndel
4d3e74a236 Trying to switch to Qt translation
This compiles and looks about right, but it doesn't appear to work, yet.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-06 10:42:32 -07:00
Dirk Hohndel
4b12f28ca4 First steps towards removing glib dependencies
- remove the build flags and libraries from the Makefile / Configure.mk
- remove the glib types (gboolean, gchar, gint64, gint)
- comment out / hack around gettext
- replace the glib file helper functions
- replace g_ascii_strtod
- replace g_build_filename
- use environment variables instead of g_get_home_dir() & g_get_user_name()
- comment out GPS string parsing (uses glib utf8 macros)

This needs massive cleanup, but it's a snapshot of what I have right now, in
case people want to look at it.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-06 10:41:44 -07:00
Dirk Hohndel
f8708e2921 Use helper function to find xslt folder
This seems much better than the different hard coded and semi-hard coded
paths we had before.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-04 13:21:31 -07:00
Miika Turkia
ba5b5c3952 Initial code to import CSV log files
This patch implements basic functionality to import CSV formatted log
profiles to Subsurface. The import includes time, depth and temperature
from AP Logviewer based on one sample log file I have received. It is
assumed that dive time is the first parameter and depth second.

Temperature is given as a parameter from C source (hard coded currently
to field 15) but we should have a GUI implemented for selecting the
wanted fields.

The two different sample logs of CSV dive log export I have received use
tabulator as field separator. I assume the possible GUI should have
option for the FS as well to be given as parameter to the XSLT.

[Dirk Hohndel: small fix to the error string malloc]

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-02 08:49:52 -07:00
Michael Andreen
169d9e9c01 Identify below floor event type properly.
This event is on when accumulating deco time. Once you reach the floor
deco time will start decreasing and the event will stop. Going below the
floor again will re-activate the event.

Also identify event type 13 in DM4 imports as airtime.

Signed-off-by: Michael Andreen <harv@ruin.nu>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-09-19 13:31:31 -05:00
Anton Lundin
b75aee33fe Use the right event type
11 is SAMPLE_EVENT_GASCHANGE, and thats the one that doesn't contain any
He-part. The type where He and O2 is packed togeather is 25,
SAMPLE_EVENT_GASCHANGE2.

Left to implement is to figure out the type of the event when we read
the xml, so we can create the right type there.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-09-18 11:59:13 -05:00
Dirk Hohndel
29b242c703 Converting the device_info list into a Qt data structure
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>
2013-06-18 00:24:28 -07:00
Miika Turkia
e504742dc8 Support for aquadivelog UDDF import
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>
2013-06-07 21:41:52 -07:00
Dirk Hohndel
478baf1076 Replace GError handling with a kMessageWidget based approach
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>
2013-05-21 23:39:49 -07:00
Miika Turkia
97594ffd23 Fix DM4 dive time
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>
2013-05-15 01:22:11 -04:00