More events from Suunto DM4 added

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>
Fix import when locale set to decimal comma

This should take care of locale caused problems when the input uses decimal
point but locale uses decimal comma. Also the sample I have of Suunto DM3
format weight is represented with comma instead of dot so converting that as
well.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Test if .bak file is supported database dive log

Even though the documentation states to rename DM4 backup to .db file
extension, accept the default .bak extension as well. This, however,
does not enable the .bak extension in file selection dialog (so .bak
files must be given as command line parameters).

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
DM4 import pressure detection fix

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>
DM4 import user documentation update

Instructions how to find the effective database file from DM4, using
this method there is no need to rename the backup as the original file
works as is when found from a random directory structure.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Translate comma to colon on XML import

Translate decimal commas on XML import to decimal points. (As detected
from available sample files using Linus' debug printing.)

Also check for empty values on MacDive temperature import.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Fix potentially broken white space truncation on certain Windows versions

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>
Reorganise view menus and file import.

Move the view submenu to a top level location.

Alter the wording of File|Import to drop XML qualifier; we import more
formats than this.

Signed-off-by: Amit Chaudhuri <amit.k.chaudhuri@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Warn about commas in floating point values

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>
Never use localized floating point numbers

The GPS entry incorrectly used strtod

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Don't strdup(NULL)

merge_text() could call strdup(NULL) if one pointer was "" and the other
NULL. This commit fixes that.

Reported-by: fhuberts
Analyzed-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Identify converted files as imported

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Sanity check on temperature values

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>
Use information from proper table on DM4 import

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>