Commit graph

2687 commits

Author SHA1 Message Date
Anton Lundin
725b70e64c Correctly find min o2 in get_dive_gas
When the import from a dive computer gives you 100% as the first gas,
the get_dive_gas never finds which gas had the lowest o2 percent.

This fixes the logic to find the lowest o2 percent in any dive cylinder
list.

Signed-off-by: Anton Lundin <glance@ac2.se>
2023-10-18 21:34:56 +13:00
Anton Lundin
8f4b6cfcb9 Ignore not used cylinders in get_dive_gas
Signed-off-by: Anton Lundin <glance@ac2.se>
2023-10-18 21:34:56 +13:00
Anton Lundin
fea074986a Ignore oxygen cylinders in get_dive_gas
It looks kinda strange that all CCR dives have a dive gas ..100%, so
rather than showing it as the dive gas used, just ignore cylinders
with usage flagged as oxygen.

Signed-off-by: Anton Lundin <glance@ac2.se>
2023-10-18 21:34:56 +13:00
Jef Driesen
c7b7c3f691 Add support for the new Ratio bluetooth name
The new Ratio iX3M 2 models use "RATIO-" as the prefix in the bluetooth
name instead of "IX5M".

Signed-off-by: Jef Driesen <jef@libdivecomputer.org>
2023-10-07 23:30:27 +13:00
Richard Fuchs
3c5f22ac25 Fix certificate_check_cb() return value
libgit documents the return value of callbacks.certificate_check[0] as
0 for success and <0 as failure. Returning 1 for success (kind of)
works because some parts of libgit[1] check for <0 return values and
only treat those as errors, but the function actually calling the
callback (check_certificate) treats anything non-zero as error[2] and
ends up setting a spurious error message with a return value of 1.

[0] https://libgit2.org/libgit2/#HEAD/group/callback/git_transport_certificate_check_cb
[1] https://github.com/libgit2/libgit2/blob/maint/v1.5/src/libgit2/transports/httpclient.c#L1054
[2] https://github.com/libgit2/libgit2/blob/maint/v1.5/src/libgit2/transports/httpclient.c#L785

Signed-off-by: Richard Fuchs <dfx@dfx.at>
2023-10-06 11:58:36 +13:00
Jef Driesen
97a76a6615 Report an error if enabling notifications fails
If enabling the notification fails, receiving data packets is not
possible. Instead of silently ignoring this fatal problem and trying to
continue, report the error back to the caller.

Signed-off-by: Jef Driesen <jef@libdivecomputer.org>
2023-09-14 09:52:29 +12:00
Michael Werle
fae68b7a68 fix: merge_pressure does not calculate starting pressures correctly
The existing logic correctly calculates the minimum (ie, ending) pressure, but not the maximum
(ie starting) pressure.

For example, 2 tanks A and B with manual pressures (same tank on subsequent dives, which were
then merged):
A: 205 - 84
B: 83 - 55

When merging the starting pressures, the call is : merge_pressure(205, 0, 83, 0, false)

The final comparison is:
  if(false && 205 < 83) return 205;
  else return 83;

-> So 83 is returned even though 205 should have been.

Signed-off-by: Michael Werle <micha@michaelwerle.com>
2023-08-09 14:35:32 +02:00
Michael Keller
26f20b805d Desktop: Consider Severity when Hiding Events.
When events are hidden in the profile, only hide events with the same
name and the same severity (flags).
From discussion in https://github.com/subsurface/libdc/pull/54.

Signed-off-by: Michael Keller <github@ike.ch>
2023-08-04 01:11:12 +12:00
Michael Keller
8f0380fd05 Equipment: Fix 'used' Gas Selection for CCR Dives.
Fix how gases are marked as 'used' and kept from being deleted in the
equipment tab for CCR dives.
It does not make sense to treat the (arbitrary) first gas in the list
with a usage type of 'diluent' or 'oxygen' as 'used' and prevent the
user from deleting it. Dive computers report the initial diluent and
any other diluents used through a 'gaschange' event, so the actually
used diluents are already picked up as part of gaschange event based
logic.
Also clarify the selection of the first diluent used as a default if no
gaschange events exist.
Also fixed the test data - gases that have a pressure change should be
included in the profile if they do not have a gas change recorded
against them by other dive computers, even if they are oxygen.
A secondary problem shown by this is that the pressure change is not
applied to the profile - the pressure is currently shown as constant on
the start pressure. But this is for another pull request.

Signed-off-by: Michael Keller <github@ike.ch>
2023-07-25 12:05:51 +12:00
Michael Keller
5fae7ce7a0 Equipment: Include Unused Tanks in Merge if Preference is Enabled.
Include unused tanks in merges of multiple logs into a single dive if
the 'Show unused cylinders' preference is enabled.
Also rename the preference (in code) to `include_unused_tanks` to
reflect the fact that it is already used in more places than just the
display (exporting, cloning dives).
Simplified the cylinder model to make forced inclusion of unused tanks
dependent on use of the model in planner.
Leaving the persisted name of the preference as `display_unused_tanks`
to avoid resetting this for all users - is there a good way to migrate
preference names?

Signed-off-by: Michael Keller <github@ike.ch>
2023-07-25 11:19:03 +12:00
Michael Keller
cb6f768865 Equipment: Mark Gas Mixes Reported as 'inactive' as 'not used.
Mark gases that are reported as 'inactive' by the dive computer as 'not
used' in the Equipment tab.

Requires https://github.com/subsurface/libdc/pull/52.

Signed-off-by: Michael Keller <github@ike.ch>
2023-07-23 18:55:20 +02:00
Rafael M. Salvioni
695c37499a Core: Fix bug salinity and pressure values in mbar <-> depth conversion
The conversion between mbar and depth sometimes uses DC's salinity, sometimes user's salinity. By other hand, it uses surface pressure given by user in calculation.
This fix try to standartize this values, using them from same source.

Signed-off-by: Rafael M. Salvioni <rafael.salvioni@gmail.com>
2023-07-11 13:26:24 +12:00
Michael Keller
ce67c8b902 Desktop: Add a Button to Hide the Infobox in the Dive Profile.
Add a button that allows the user to hide the infobox with statistics
about the point in the dive under the mouse cursor in order to be able
to see the full dive profile unobstructed.

Signed-off-by: Michael Keller <github@ike.ch>
2023-06-25 14:40:23 +02:00
Michael Keller
b0d5b23227 Desktop: Add Meaningful Error Messages for libdivecomputer Dump.
Add meaningful error messages when creating a libdivecomputer dump. In
particular show if creating a dump is not supported on the dive computer
that is used.

Signed-off-by: Michael Keller <github@ike.ch>
2023-06-17 12:06:34 +02:00
Michael Keller
35d88fa6ce Build: Fix build warning on MacOS.
Fix a build warning for an unused variable.

Signed-off-by: Michael Keller <github@ike.ch>
2023-06-12 08:04:30 -07:00
Berthold Stoeger
3939cc8da2 core: use range based for and std::string in enumerate_devices()
Just because now we can...

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-06-03 12:54:24 +02:00
Berthold Stoeger
81cd91f78b core: more std::[w]string conversions in windows.cpp
No free()in necessary means less convoluted control flow.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-06-03 12:54:24 +02:00
Berthold Stoeger
a3f540fe34 core: fix warnings in windows.cpp
The compiler was (correctly) complaining about a const char *
to char * conversion.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-06-03 12:54:24 +02:00
Berthold Stoeger
540cba07f3 core: use C++ std::strings for default directory and filename
The memory management and string concatenation was hard to follow.

Since the mobile files ios.cpp and android.cpp were already
converted to C++, let's do the same for Unix, Windows and MacOS.

Simply store the default directory and filename in a function-level
static string. Thus, it will be initialized on first call and
freed on application exit. Since the std::string data is
guaranteed to be contiguous and zero-terminated, it can be used
from C code.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-06-03 12:54:24 +02:00
Michael Keller
6002387d7b Desktop: Add Multi-Tank Support for Profile Ruler.
Add support for tracking the gas usage across multiple tanks to the 'bar
used' and SAC values shown for the profile ruler.
The following rules are implemented:
- a tank is considered 'used' if at least one bar has been consumed;
- only used tanks are taken into account for calculations;
- 'bar used' is only shown if all tanks used have the same (or unknown)
  volume;
- SAC is only shown if all tanks used have a known volume.

Fixes #3902.

Reported-by: @pabdakine
Signed-off-by: Michael Keller <github@ike.ch>
2023-05-30 11:21:12 +02:00
Michael Keller
7ee5b10810 Desktop: Remove 'renderSVGIcon' methods.
Remove `renderSVGIcon()` and `renderSVGIconWidth()`, as QPixmaps can be
loaded directly from SVG, and support scaling.

Signed-off-by: Michael Keller <github@ike.ch>
2023-05-28 14:11:37 -07:00
Michael Andreen
9e95746797 profile: Fix so min pressure is not always 0
Signed-off-by: Michael Andreen <michael@andreen.dev>
2023-05-23 13:12:48 +02:00
Michael Andreen
7217506072 profile: Use all sensors to scale the pressure graph
It's possible for the first sensor to start with a pressure
significantly lower than other sensors.

Signed-off-by: Michael Andreen <michael@andreen.dev>
2023-05-23 13:12:48 +02:00
Michael Keller
84d9d0abe7 Desktop: Fix incorrect use of 'free()'.
Use 'xmlFree()' to free memory returned by libxml.
Follow-up to #3900.

Signed-off-by: Michael Keller <github@ike.ch>
2023-05-19 10:51:02 +02:00
Michael Keller
d7bfb9d61e Desktop: Fix memory leak during XSLT transformation.
Fix a memory leak occurring during XSLT transformations.

Fixes #3899.

Signed-off-by: Michael Keller <github@ike.ch>
2023-05-18 16:44:15 +02:00
Berthold Stoeger
cf95c3bd82 cleanup: remove unnecessary string duplication
I don't understand why the functions must be called on a copy
of the string.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-05-02 09:35:01 +02:00
Berthold Stoeger
a8d2b2ff70 divelog: fix erroneous use of std::move()
This has to be applied to the object, not the pointer to the object.
Fixes a double-free crash introduced in 8cd451f.

Alternatively, we could use std::swap() for C++98 charm and perhaps
better readability for people unfamiliar with C++11. Nowadays,
std::move() is more idiomatic though. Shrug.

Reported-by: Michael Keller <github@ike.ch>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-04-18 13:15:50 +02:00
Michael Keller
a38ea971a0 Import: Add option to sync time on dive computer download
Add an option for users to sync the dive computer time with the PC time
every time dives are downloaded.
Obviously this will only work on dive computers that have time
synchronisation support in libdivecomputer, for other computers a notice
is logged.
The selection for this option is persisted as a preference.

Signed-off-by: Michael Keller <github@ike.ch>
2023-04-17 07:56:02 -07:00
Berthold Stoeger
4c02d1c279 planner: get rid of global displayed_dive variable
Allocate the dive in the planner. This is all a bit convoluted
and needs more cleanup.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-04-16 20:23:59 +02:00
Berthold Stoeger
c5d6e0f44f core: make owning pointers a top-level features
The undo-code uses owning pointers based on std::unique_ptr to
manage lifetime of C-objects. Since these are generally useful,
move them from the undo-code to the core-code. In fact, this
eliminates one instance of code duplication.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-04-16 20:23:59 +02:00
Berthold Stoeger
5b1557ccb1 core: don't clear displayed_dive when clearing data
displayed_dive used to contain the currently displayed (as in
shown on the profile) dive. However, now it is only a "scratch"
dive used by the planner and initialized every time the planner
is started. There is no point in clearing this dive when clearing
the dive data. In fact, the dive should probably be cleared when
the planner finishes.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-04-16 20:23:59 +02:00
Berthold Stoeger
cad80e5a53 selection: move current dc logic to profile widget
The current dc global makes no sense on mobile. Therefore,
move the logic of the currently displayed dive computer
to the profile widget and remove the dc_number global
variable.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-04-16 20:23:59 +02:00
Berthold Stoeger
de2c4d93e0 map: fold selectionChanged() into setSelection()
This was very weird: a setSelection() call was always followed
by a selectionChanged() call, though sometimes in convoluted
ways. Notably, the formed was called by the DiveListView, the
lattern then by the MainWindow.

Let's just merge these two functions.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-04-16 20:23:59 +02:00
Berthold Stoeger
72a15c46d9 selection: move dive selection, current dive and dc through signals
To reduce access of global variables.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-04-16 20:23:59 +02:00
Berthold Stoeger
8581e213ed selection: trickle down trip selection
The trip selection code was an awkward layering violation.
Whereas dive selections due to dive undo-commands trickled
down via DiveTripModel-->MultiFilterSortModel-->DiveListView,
for trip editing, the DiveListView directly intercepted the
TripEdited signal.

Instead, mimic the dive-selection code. This is a bit longer
but more consistent and logical. The undo/redo of trip changes
is now also a "programmatical" change of the selection.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-04-16 20:23:59 +02:00
Berthold Stoeger
9ccb940a1b list models: include current dive in selection signal
After sending a selection-change signal, there follows a current
dive changed signal. Combine these two into a single signal, since
usually the current dive is changed when the selection is changed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-04-16 20:23:59 +02:00
Berthold Stoeger
996f85771a selection: remove select_dive() and deselect_dive() functions
These were not optimal, because they would recalculate the current
dive and divecomputers for every invocation.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-04-16 20:23:59 +02:00
Berthold Stoeger
1f453094a9 selection: don't call deselect_dive() from delete_single_dive()
delete_single_dive() is one of those remnants from before the
undo-code. Now it is only called in two contexts:

1) When clearing the whole dive log.
2) When importing dives from the cloud on mobile.

In the first case, the selection is cleared before deleting
the dives.

In the second case, let's just do the same.

Thus, we can remove the last call to the deselect_dive()
function that does some complex calculations concerning
the current dive and divecomputer.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-04-16 20:23:59 +02:00
Berthold Stoeger
487974ea91 selection: avoid select_dive() and deselect_dive calls in dive list
Each of these calls recalculates the current dive and divecomputer.
Instead, collect the dives to be selected/deselected and (de)select
them at once.

This needs some code refactoring in the core, because we need a
function that
1) doesn't send a signal by itself.
2) doesn't clear the trip-selection.

This contains some reorganization of the selection functions
signatures: The filter code is the only caller that keeps the
selected dive and the only caller that cares about whether the
current dive changed. So let only the function that keeps the
selected dive return whether the current dive changed.

It's all very fragile.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-04-16 20:23:59 +02:00
Berthold Stoeger
6df1c62dfc filter: set dive selection at once
For each selected dive that is hidden by the filter,
unselect_dive() was called, which led to a recalculation
of the current dive and divecomputer.

Instead, collect all deselected dives and deselect them
at the end. Thus, these calculations are performed
only once.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-04-16 20:23:59 +02:00
Berthold Stoeger
9f455b1457 selection: move current dive and divecomputer to selection.cpp
This tries to encapsulate the management of the current dive and
divecomputer in the selection code. The current dive is alreay
set by setSelection(). Add a new parameter to also set the
current divecomputer. If -1 is passed, then the current
computer number is remained. This will allow us to audit the code.
Because for now, the whole "current dive computer" thing seems
to be ill-defined.

This fixes a bug: the dive-computer number wasn't validated
when making a new dive the current dive. The new code has some
drawbacks though: when selecting a whole trip, the validation
will be called for all dives in the trip and thus the dive computer
number will depend on the dive with the lowest amount of dive
computers in the trip. This will need to be fixed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-04-16 20:23:59 +02:00
Berthold Stoeger
b56b7abcf5 core: use divelog struct in downloader code
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-04-14 21:20:23 +02:00
Berthold Stoeger
a2845ece82 cleanup: use range based for in download code
This removes a constant describing the length of the array.

The enumerated_range code had to be adapted, because the
interaction of C-type arrays with the C++ typesystem is mad.
With C-type arrays, one has to pass a reference to std::declval.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-04-14 21:20:23 +02:00
Berthold Stoeger
b61732da42 core: remove autogroup global
Use the flag in the divelog structure, since this will be saved
in the dive log.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-04-14 21:20:23 +02:00
Berthold Stoeger
aa34afc3f7 cleanup: remove ARRAY_SIZE macro from header
It is only used in a single source file, so no point having
it in a (non-generic) header.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-04-14 21:20:23 +02:00
Berthold Stoeger
59d678b5b1 cleanup: use range based for instead of loop with index
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-04-14 21:20:23 +02:00
Berthold Stoeger
7d5c6be188 core: use divelog struct in git parser state
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-04-14 21:20:23 +02:00
Berthold Stoeger
40275ea56b core: use divelog struct in parser state
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-04-14 21:20:23 +02:00
Berthold Stoeger
8cd451fc33 core: use divelog in importDives() and process_imported_dives()
Instead of a long argument list.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-04-14 21:20:23 +02:00
Berthold Stoeger
9c253ee6c5 core: introduce divelog structure
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.

Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).

The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.

To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.

The whole commit is large, but was mostly an automatic
conversion.

One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-04-14 21:20:23 +02:00