Commit graph

941 commits

Author SHA1 Message Date
Berthold Stoeger
44bcc5a307 Cleanup: make local functions in core/plannernotes.c of static linkage
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-04-11 14:01:51 +03:00
Jeremie Guichard
5d96d4af0c Add usage documentation for membuffer helper functions
Added a comment block on top of membuffer.h describing common usage
of membuffer helper functions

Signed-off-by: Jeremie Guichard <djebrest@gmail.com>
2018-04-10 08:18:32 -07:00
Berthold Stoeger
8b0055d15c Cleanup: remove unused function get_selected_dives_text()
The only caller was removed in commit c3f07b9f81.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-04-10 08:16:33 -07:00
Berthold Stoeger
bbacdf94e3 Cleanup: Slightly shorten code in vqasprintf_loc()
Move duplicate code, which reads '*' arguments from va_list into
parse_fmt_int() function. To pass pointers-to-va_list, the va_list
has to be copied first.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-04-09 11:29:43 -07:00
Berthold Stoeger
5afe1a53d8 Cleanup: Move *_loc formatting functions into new format.cpp file
qthelper.cpp is already quite voluminous. Move the recently
introduced localized versions of (v)snprintf() and put_format()
into their own translation unit.

Moreover, adopt C-style semantics for asprintf_loc(). This function
will be used to remove fixed-size buffers in core/plannernotes.c.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-04-09 11:29:43 -07:00
Jeremie Guichard
7753352e62 Change taglist_get_tagstring to support 'unlimited' tag list size
Previous taglist_get_tagstring signature/implementation did not allow
handling of cases where inputted buffer could not contain all tags.
New implementation allocates buffer based on pre-computed size allowing to
insert all tags in the returned string.

Added get_taglist_string in qthelper to handle conversion to QString
Added TestTagList with tests for taglist_get_tagstring

Signed-off-by: Jeremie Guichard <djebrest@gmail.com>
2018-04-09 07:59:51 -07:00
Miika Turkia
b28e3db7f1 Temperature 0x7F appears to mean no reading
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2018-04-07 11:33:09 -07:00
Miika Turkia
6cfbe10bc3 Handle int and float temperatures
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2018-04-07 11:33:09 -07:00
Miika Turkia
e04dadc378 Explicitly mark DM4 conversion
Same as default branch, but as 0x01 appears to be converted from DM4 to
DM5, let's just be explicit about it.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2018-04-07 11:33:09 -07:00
Miika Turkia
06a2f36a62 Start to describe DM5 sampleBlob
Currently the best guess of sampleBlob format. Unfortunately there seems
to be some version of DM that stores the temperature in different
location that I have not been able to figure out yet. Note that some
version of DM does not utilize sampleBlob but specific blobs for each
value (temperature, pressure, ...).

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2018-04-07 11:33:09 -07:00
Berthold Stoeger
b01c9328b4 Dive pictures: extract timestamp from MP4 and related formats
Parse MP4s and related video files and extract the creation timestamp
from the "mdhd" (media header) atom.

Introduce helper function templates to extract arbitrary-length
unsigned integers in big-endian format from file or memory.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-04-01 16:04:48 +03:00
Berthold Stoeger
66b71c60a0 Dive pictures: use get_metadata() in dive_create_picture()
Thus, metadata has to be only read once and the picture_load_exif_data()
function can be removed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-04-01 16:04:48 +03:00
Berthold Stoeger
9b2482aca9 Dive pictures: Move metadata functions into own translation unit
Move all metadata function into new core/metadata.cpp file.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-04-01 16:04:48 +03:00
Berthold Stoeger
d9df8c3f47 Debug: Error reporting for SHashedImage loading
Overwrite QImage::load() in SHashedImage so that we can perform better
error reporting.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-04-01 15:59:46 +03:00
Berthold Stoeger
376b737891 Debug: sprinkle debug messages in thumbnailing code
To ease trouble-shooting of the picture thumbnailer add a number
of debug- and info-messages.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2018-04-01 15:59:46 +03:00
Dirk Hohndel
99bc940551 Use older API to remove dependency on Qt 5.8 or newer
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-03-22 07:40:32 -07:00
Dirk Hohndel
78937ce572 iOS: build fix
Otherwise the moc build fails.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-03-22 07:33:33 -07:00
Stefan Fuchs
b38eb45b29 Profile heartrate: Nicer min/max values and tic distance
Correct a bug in finding the minimum heartrate.

Use the minimum and maximum heartrate value to set min/max and
tic distance for the heartrate axis in the profile.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-03-19 15:44:02 -07:00
Berthold Stoeger
c896938f7a Dive pictures: If EXIF data couldn't be parsed, use creation date
This is a preparation for supporting videos. Some video formats may
not possess such meta data, or we may not yet be able to parse them.
In such a case, use the file creation date.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-03-19 13:14:54 -07:00
Berthold Stoeger
d9b502f0c7 Dive pictures: Don't read whole file for parsing EXIF data
This is a preparation for video support. We don't want to read a whole
potentially multi-GB file into memory just to detect that it isn't a
JPEG. Especially since at the moment EXIF metadata are parsed twice,
once for GPS, once for timestamp.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-03-19 13:14:36 -07:00
Berthold Stoeger
2105d3c7d0 Cleanup: consistently use toUtf8() instead of toLocal8Bit()
These do the same, since the text-codex is set to UTF-8 on startup.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-14 13:55:36 +02:00
Berthold Stoeger
d1572a8d95 Cleanup: introduce copy_qstring() function
strdup(qPrintable(s)) and copy_string(qPrintable(s)) were such common
occurrences that they seem worthy of a short helper-function.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-14 13:55:36 +02:00
Berthold Stoeger
b72cc1f317 Cleanup: consistently use qPrintable()
Replace constructs of the kind
  s.toUtf8().data(),
  s.toUtf8().constData(),
  s.toLocal8Bit().data(),
  s.toLocal8Bit.constData() or
  qUtf8Printable(s)
by
  qPrintable(s).

This is concise, consistent and - in principle - more performant than
the .data() versions.

Sadly, owing to a suboptimal implementation, qPrintable(s) currently
is a pessimization compared to s.toUtf8().data(). A fix is scheduled for
new Qt versions: https://codereview.qt-project.org/#/c/221331/

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-14 13:55:36 +02:00
Berthold Stoeger
4e44fe7598 Cleanup: constify string arguments in core/dive.c
Make arguments to set_informational_units(), set_git_prefs(),
set_userid(), dive_remove_picture() and update_event_name()
"const char *" for consistency with the rest of core/dive.c.

This will allow replacing toUtf8().data() with the constData()
version in a subsequent commit.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-14 13:55:36 +02:00
Berthold Stoeger
6f2169488a Cleanup: Set text encoding to UTF-8 for all platforms.
This was only done explicitly for Windows. Other platforms were
implicitly supposed to be UTF-8.

Suggested-by: Lubomir I. Ivanov <neolit123@gmail.com>

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-14 13:55:36 +02:00
Dirk Hohndel
f799c9ca3f Subsurface-mobile: Add OSTC 2 TR as support dive computer
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-03-14 01:03:31 -07:00
Linus Torvalds
f5e2a17e7d Subsurface update for upstream libdivecomputer changes
So because I merged with upstream libdivecomputer, and it no longer does
the "halfduplex emulation" thing in the IO layer, and instead does it in
the only Suunto backend that needed it, that also affected our custom IO
layer in subsurface.

Sure, I could have left a dummy interface and left subsurface with some
ugly dead code, but it's really better to just get rid of the code.

So when Dirk pulls in the libdivecomputer updates from

    https://github.com/torvalds/libdc-for-dirk.git Subsurface-branch

this patch to remove the halfduplex code in subsurface is also needed.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Stefan Fuchs <sfuchs@gmx.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-03-13 22:34:57 -07:00
Anton Lundin
8de887c8ee Treat a PSCR dive with sensors more like a CCR dive
PSCR dives with o2 sensors are more like CCR dives. The math is exactly
the same, its just a different diluent and a different po2.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
2018-03-13 18:54:16 +02:00
Anton Lundin
b48eb47178 Fix up CCR/PSCR dives with sensors values without no_o2sensors
This introduces a fixup function that walks all the samples and
populates the no_o2sensors if its zero and supposed to be something
else.

There is a bug somewhere which Willem hit, causing this to never be set.

Reported-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Anton Lundin <glance@acc.umu.se>
2018-03-13 18:54:16 +02:00
Anton Lundin
15b6953438 Use the current dive mode instead of constant
In the if case above, we already conclude its a OC dive, but its cleaner
to actually pass the current mode instead of a hard coded value.

This also makes the code less prune to future bugs.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
2018-03-13 18:54:16 +02:00
Lubomir I. Ivanov
2317fed9b6 DiveObjectHelper: add dive_site_uuid()
The map widget on the mobile version requires that
a dive object from a model has a dive_site uuid.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2018-03-11 11:40:12 -07:00
Stefan Fuchs
5d32fd0723 Cosmetic modifications in profile delta sample string
Consistently do not use a space between value and unit.
Consistently do not use a space between "name:" and value.
Add "/min" for SAC rate.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-03-06 13:06:52 +02:00
Berthold Stoeger
bdc470a80e Cleanup: Remove hash field from picture-structure
The hash field in the picture-structure was in principle non-operational.
It was set on loading, but never actually changed. The authoritative
hash comes from the filename->hash map.

Therefore, make this explicit by removing the hash field from the
picture structure.

Instead of filling the picture structure on loading, add the
hash directly to the filename->hash map. This is done in the
register_hash() function, which does not overwrite old entries.
I.e. the local hash has priority over the save-file. This
policy might be refined in the future.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-05 18:04:57 +02:00
Berthold Stoeger
e5dcd9fc16 Cleanup: pass QString and QByteArray const-refs to qthelper functions
Passing of QStrings and QByteArrays was inconsistent in qthelper.cpp.
Unify to passing const-references. Passing by value is no big deal, since
QString and QByteArray do copy-on-write "optimization". Nevertheless, let's
keep it as consistent and effective as possible.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-05 18:04:57 +02:00
Berthold Stoeger
f5eafe2a71 Cleanup: Fold add_hash() call into learnHash() function
learnHash() was always called in conjunction with add_hash(). The
pattern was that a local filename and a hash were connected in
the hash-to-filename and the filename-to-hash maps. Then, the
original picture-filename or url were registered in the filename-to-hash
map.

This commit changes learnHash() to take three parameters (original-filename,
local-filename and hash) and do all of the above. The new code is
simpler because no dummy picture struct has to be generated in
DiveListView::loadImageFromURL().

The tests were extended to check for all hash<->filename associations.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-05 18:04:57 +02:00
Berthold Stoeger
b750a48f0f Cleanup: Don't store hash in picture struct in learnHash()
learnHash() is called either on a local picture structure
[DiveListView::loadImageFromURL()] or on a cloned picture structure
[ImageDownloader::saveImage()]. In neither case the picture structure
is passed to the frontend. Therefore, storing the new hash in the
picture struct is not necessary.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-05 18:04:57 +02:00
Berthold Stoeger
83b2870648 Cleanup: Don't call learnHash() in hashPicture()
hashPicture() calls hashFile(), which calls add_hash(). add_hash()
updates the filename-to-hash and hash-to-filename maps. Therefore,
there is no point in calling learnHash() in hashPicture(), which
updates the filename-to-hash map.

Note that learnHash() updates the picture-struct with the new hash,
but since hashPicture() works on a cloned picture-struct, which
is free()d in hashPicture(), these changes are lost anyway.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-05 18:04:57 +02:00
Berthold Stoeger
a0d02bacf3 Cleanup: remove updateHash() function
updateHash() and hashPicture() did the same thing, with the exception
that hashPicture() marked the dive list as changed if a hash changed.
This seems like a good idea in any case, therefore always use
hashPicture().

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-05 18:04:57 +02:00
Berthold Stoeger
f8835751dc Cleanup: Make helper function haveHash() of static linkage
The function is only used in the qthelper.cpp translation unit.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-05 18:04:57 +02:00
Berthold Stoeger
eaff0ddee7 core/imagedownloader.cpp: Use signal to exit eventloop
Don't do busy-waiting.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-05 18:04:57 +02:00
Berthold Stoeger
907c07ce50 core/imagedownloader.cpp: Use implicit default constructor of QImage
No point in move-constructing from a different default constructed
QImage.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-05 18:04:57 +02:00
Berthold Stoeger
117f4a0d7d core/imagedownloader.cpp: remove recursion
If loading from hash failed in the saveImage() slot(!) it would
recurse into loadFromUrl(), which would generate a new network
reply. Very scary and a (small) wonder that it worked.

Let's try to make this all more explicit.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-05 18:04:57 +02:00
Berthold Stoeger
54d56a74aa core/imagedownloader.cpp: Make the manager object local to load()
The QNetworkAccessManager is only used in the load() function. No
point in it being a subobject.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-05 18:04:57 +02:00
Berthold Stoeger
2803b7d385 core/imagedownloader.cpp: Simplify deletion of objects
1) Destroying the QNetworkManager seems like a bug: this was a
subobject of ImageDonwloader. It's mysterious how this didn't
crash.

2) Instead of calling deleteLater() on the reply object, simply
delete it after completion.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-05 18:04:57 +02:00
Berthold Stoeger
c1cd2e0f02 core/imagedownloader.cpp: Fix memory leak
A cloned picture struct would not be freed if the filename was already
in the queued-for-download set.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-05 18:04:57 +02:00
Stefan Fuchs
aacc688670 Use correct numeric format based on selected locale (Qt domain part)
This changes the numeric format of many values printed to the UI to
reflect the correct numeric format of the selected locale:
- dot or comma as decimal separator
- comma or dot as thousands separator

In the Qt domain the `L` flag is used case specific mostly
in qthelper.cpp.
Then the helper functions get_xxx_string() are used more consistently.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-03-05 16:28:18 +01:00
Berthold Stoeger
18c034ea37 Localization: implement *_loc() functions in plannernotes.c
Replace snprintf() and put_format() by snprintf_loc() and
put_format_loc(), respectively to localize formatting of
integers and floats.

Acked-by: Stefan Fuchs <sfuchs@gmx.de>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-05 16:23:55 +01:00
Berthold Stoeger
57c3e43df9 Localization: implement *_loc() functions in profile.c
Replace snprintf() and put_format() by snprintf_loc() and
put_format_loc(), respectively to localize formatting of
integers and floats.

Acked-by: Stefan Fuchs <sfuchs@gmx.de>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-05 16:23:55 +01:00
Berthold Stoeger
bec3e80683 Localization: Make Qt's locale-aware formatting accessible from C
This commit introduces functions:
 - QString asprintf_loc(const char *cformat, ...);
 - int snprintf_loc(char *dst, size_t size, const char *cformat, ...);
 - put_format_loc(struct membuffer *, const char *fmt, ...);
and their va_arg equivalents, which use Qt's QString::arg() formatting
options to render the strings.

The snprintf_loc() function takes care not to truncate multi-byte
UTF-8 encodings. Thus, on overflow, the resulting string might be
shorter than size-1.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-05 16:23:55 +01:00
Stefan Fuchs
1723db9d0b Configure DC dialog: Add a few missing translations
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-03-05 16:19:49 +01:00