Commit graph

2271 commits

Author SHA1 Message Date
Berthold Stoeger
f29278b700 cleanup: make local functions of static linkage
A few functions in save-html.c were local but not marked as static.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-29 09:20:17 -07:00
Miika Turkia
3f54af2ca6 Print correct template name on CSV export
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2020-05-26 11:33:10 -07:00
Berthold Stoeger
87c91af824 cleanup: constify time_during_dive_with_offset() function
There is no reason to pass a non-const dive pointer as first
argument.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-22 14:40:49 -07:00
Berthold Stoeger
9365061e27 cleanup: remove unused function get_dive_n_near()
The last caller was removed in 7eb422d988.
Since this is the only caller of dive_within_time_range(), remove that
function as well.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-22 14:40:49 -07:00
Berthold Stoeger
8f80129bac cleanup: create common QDateTime -> timestamp conversion function
In analogy to the timestamp -> QDateTime conversion, create a
common function.
1) For symmetry with the opposite conversion.
2) To remove numerous inconsistencies.
3) To remove use of the deprecated QDateTime::toTime_t() function.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-22 12:31:06 -07:00
Berthold Stoeger
e33e420ef3 cleanup: remove unused libc-structures from get_trip_date_string()
This must be an artifact from before using Qt's datetime functions.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-22 12:31:06 -07:00
Berthold Stoeger
f63485b444 cleanup: move timestampToDateTime() to qthelper.cpp
Move this function from maintab.cpp to qthelper.cpp. Since the
functionality was used in numerous places, use the helper function
there as well. This removes a number of inconsistencies. For example,
sometime setTimeSpec(Qt::UTC) was called, even though the
QDateTime object was already created with that time spec.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-22 12:31:06 -07:00
Paul Buxton
2ba2ea934a Fix incorrect Farenheit to Kelvin formula.
Use defined function instead.

Signed-off-by: Paul Buxton <paulbuxton.mail@googlemail.com>
2020-05-22 19:19:58 +02:00
Berthold Stoeger
757a4fa146 cleanup: set long and short date formats in independent branches
The short and long date formats where initialized in a common if-branch.
However, inside the if-branch the code rechecked which of the two should
be initialized. This could make sense if there was some common code between
the two, but there wasn't. Therefore, make this two independent branches
to avoid one nesting-level.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-22 10:00:43 -07:00
Linus Torvalds
dee52409b1 BLE: trivial updates to the GATT services lists
Add a couple of known services (Scubapro G2 and Shearwater), and update
the names of others that turn out to be used for multiple dive
computers.  Also add another Broadcom upgrade service UUID.

While at it, sort the services numerically to make it easier to see that
a UUID already exists, since these service numbers do get used across
multiple different devices.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-05-17 13:52:24 -07:00
Linus Torvalds
e91c252093 BLE: add list of known good/bad BLE GATT services
We've tried to do this "automagic" service discovery, and it mostly
works, but then occasionally it doesn't.

Making things worse, I think different platforms end up enumerating
services differently, so our "pick the first service that looks like it
might be a serial service" ends up working on some platforms, but not
necessarily on others.  Because "first" might be different.

So start a list of known good/bad services - and fall back to the old
logic when you can't decide reliably.

This fills in juat a few cases that I can easily check myself, and the
"details" field for them may be incomplete.  For example, I know Nordic
Semiconductor has their vendor-specific UUIDs, and they can be found in
different devices, so calling them "Nordic UART" and "Nordic Flash"
services makes sense.

But the "Scubapro i770R" service? It might indeed be specific to the
Scubapro i770R.  Or it might be a general service UUID that Pelagic
uses.  Or it might be the service UUID of a particular chip, and found
in dive computers from other designs too (and not necessarily in all
i770R's either).

So this is a preliminary first stab at this, and I'm sure we'll extend
the list and possibly improve on the explanations.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-05-17 09:29:07 -07:00
Berthold Stoeger
a7440ce277 filter: properly search for tags
The old code used get_taglist_string() and split the resulting
string at commas to get the list of tags. This was wrong for two
reasons:
1) It was buggy. Every tag but the first would start with a leading
   space and thus not be found.
2) It was inefficient. The tag list was concatenated, just to be split
   again.

Turn the tag list directly into a QStringList and remove whitespace
for good measure.

Fixes #2842.

Reported-by: Hartley Horwitz <hhrwtz@gmail.com>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-16 12:40:08 -07:00
Berthold Stoeger
04b6bb8cc9 filter: include tags in fulltext search
The tags have been forgotten when implementing the fulltext search.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-16 12:40:08 -07:00
Dirk Hohndel
34ebaf6599 core/bt: ensure that BT/BLE addresses with name sort first
We don't order the list of addresses alphabetically, but we want to ensure
that devices that offer us a name are listed before those that don't. This
should only be relevant if the user selects the option to show all BT/BLE
devices, not just recognized dive computer, because if we recognize a computer
we always have the product name prepended to the address.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-05-15 04:05:06 +03:00
Dirk Hohndel
a1a51e5d89 core/bt: always add bt name for devices
If the user asks to have all BT/BLE devices shown, we should behave
consistently to the case of a recognized dive computer and always show the
device name. In almost all cases the BT/BLE address (and even worse on
iOS/macOS the weird uuids) are completely meaningless.

If there isn't a name, don't add a leading space in order to make it easy to
detect if we have an address without a name (which almost certainly isn't a
dive computer, so it should be towards the end of the list of addresses - which
will be handled in a later commit).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-05-15 04:05:06 +03:00
Dirk Hohndel
658089d763 core/bt: match DC descriptor in lower case
This fixes a rather subtle bug.

In btdiscovery.cpp we are detecting dive computers based on their BT name and
are setting up product+vendor as the key for that lookup. QMap always uses case
sensitive comparisons and a tiny inconsistency snuck into our code.
libdivecomputer names for the Aqualung dive computers i200C / i300C / i550C end
in an upper case C (as matches the official branding), but in btdiscovery.cpp
we have those names with lower case c. And therefore didn't recognize these
dive computers.

Obviously this is easy to fix by fixing those three strings, but I decided that
it was silly to set ourselves up for similar oversights in the future. So
instead I switched the matching of the descriptor to simply be allways all
lower case.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-05-15 02:49:46 +03:00
Linus Torvalds
62e95fdc86 Save SAC, OTU and CNS in the XML export
We do _not_ read them back, since they are calculated values, although I
guess we could aim to do that too at some point in case we have an
import from somewhere else that has these values but not the profile (or
gas use) to actually calculate them.

Fix test-cases that are checked by TestParse (but nothing else) to match.

Requested-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-05-14 13:27:07 -07:00
Linus Torvalds
cdfcb7f896 Remove 'string marker after running out of strings' warning
This warning is unnecessarily scary - we had a problem with parsing
multiple strings on the same line, but it should be all solved, and
while it does mean that people may have old incorrect git save files
with empty strings, scaring users about it isn't going to help.

And with the warning removed, we can just remove the whole test for an
empty string, because the normal code sequence handles that case just
fine.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-05-12 11:36:59 -07:00
Berthold Stoeger
fb6210a99a cleanup: invert control-flow when resetting the core structures
To reset the core data structures, the mobile and desktop UIs
were calling into the dive-list models, which then reset the
core data structures, themselves and the unrelated
locationinformation model. The UI code then reset various other
things, such as the TankInformation model or the map. . This was
unsatisfying from a control-flow perspective, as the models should
display the core data, not act on it. Moreover, this meant lots
of intricate intermodule-dependencies.

Thus, straighten up the control flow: give the C core the
possibility to send a "all data reset" event. And do that
in those functions that reset the core data structures.
Let each module react to this event by itself. This removes
inter-module dependencies. For example, the MainWindow now
doesn't have to reset the TankInfoModel or the MapWidget.

Then, to reset the core data structures, let the UI code
simply directly call the respective core functions.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-07 08:43:27 -07:00
Berthold Stoeger
4374605c12 undo: make adding of pictures undoable
This one is a bit hairy, because two things might happen if the
picture has a geo location:
- A dive gets a newly generated dive site set.
- The dive site of a dive is edited.
Therefore the undo command has to store keep track of that.
Oh my.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06 13:58:09 -07:00
Berthold Stoeger
6ae2d36e38 core: move picture-related function from dive.c to picture.c
Move the two functions create_picture() and picture_check_valid_time()
from dive.c to picture.c.

This might be somewhat questionable, as these functions are not purely
picture related, but check the nearest selected dives, etc. However,
dive.c is so huge, that slimming it down can't hurt. Moreover,
getting the nearest selected dive is more divelist- than dive
functionality anyway.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06 13:58:09 -07:00
Berthold Stoeger
74f03e3537 media: move addition of pictures out of create_picture()
If we want to make addition of pictures undoable, then create_picture()
must not add directly to the dive. Instead, return the dive to which the
picture should be added and let the caller perform the addition.

This means that the picture-test has to be adapted.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06 13:58:09 -07:00
Berthold Stoeger
0935513636 core: remove new_picture_for_dive() function in dive.c
We can do the same with get_picture_idx(). Yes, it is a bit more
unwieldy. However a full reimplementation seems not worth it.
We could make this a one-liner helper function though.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06 13:58:09 -07:00
Berthold Stoeger
434644b381 undo: make picture (media) deletion undoable
The code is rather complex. Firstly, we have different representations
of pictures throughout the code. Secondly, this tries to do add the
pictures in batches to the divepicture model and that is always rather
tricky.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06 13:58:09 -07:00
Berthold Stoeger
fe82cb32b9 media: add small C++ helper describing a picture struct
By using a std::string instead of a C-string, memory management
becomes so much simpler! This class will be used for keeping track
of deleted/added pictures in the undo system.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06 13:58:09 -07:00
Berthold Stoeger
e61641c79c undo: implement undo of setting a picture time by drag&drop
Even though the functionality is seemingly trivial, this is a bit
invasive, as the code has to be split into two distinct parts:
1) Post undo command
2) React to changes to the divelist

Don't compile that code on mobile.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06 13:58:09 -07:00
Berthold Stoeger
ebdb3e3c30 media: create sort_picture_table function via macro
This needs a slight change to the macro, because here we sort by
value type. Yes, from a C-programming point of view this is horrible,
however a decent compiler should just inline everything and not
pass around value types.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06 13:58:09 -07:00
Berthold Stoeger
db24f16686 core: add get_picture_idx() function
A function that gets the index of a picture in a picture table
given its filename. Since we are going to identify pictures by
their filename, we will need this function in the undo code.

Use the function in the remove_picture() function.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06 13:58:09 -07:00
Berthold Stoeger
989d6a3f96 media: use table instead of linked list for media
For consistency with equipment, use our table macros for pictures.
Generally tables (arrays) are preferred over linked lists, because
they allow random access.

This is mostly copy & paste of the equipment code.

Sadly, our table macros are quite messy and need some revamping.
Therefore, the resulting code is likewise somewhat messy.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06 13:58:09 -07:00
Berthold Stoeger
282041e228 core: make picture.h compatible with C++
The "extern C {" guards were missing.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06 13:58:09 -07:00
Berthold Stoeger
2c4975f2ed cleanup: move copy_cylinders from dive.c to equipment.c
Since this doesn't touch struct dive, dive.c is not an appropriate
place for this function.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06 13:58:09 -07:00
Berthold Stoeger
fdca130387 cleanup: make remove_from_*_table equipment functions static
These functions were not used outside their translation unit.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06 13:58:09 -07:00
Berthold Stoeger
33b4ecf055 cleanup: move the inertgas enum from qthelper.hpp to deco.c
There are no outside users.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06 00:22:31 +02:00
Berthold Stoeger
123937901f planner: remove Bühlmann factor cache
The Bühlmann factors were cached in a thread-safe hashmap. It seemed
somewhat dubious that entering a critical section and doing a hash-lookup
would be significantly faster than a simple exp() call.

Indeed, in a very cache friendly test (16 entries, tight loop) calling the
factor() function 32 000 000 times from a different translation units we get:
  - with cache: 604 ms
  - without cache: 266 ms
Therefore, remove the cache. Given that 32 000 000 calls take only 266 ms,
it appears not sensible to try to optimize this function anyway.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06 00:22:31 +02:00
Monty Taylor
f37f428762 cleanup: capitalize use dc
It was suggested in a review of a previous patchset that we should
capitalize the use of "use dc" to "Use DC" - but if we were going
to do that we should do it everywhere, not just in the one place.

This is the followup to do that.

Signed-off-by: Monty Taylor <mordred@inaugust.com>
2020-05-05 10:23:18 -07:00
Monty Taylor
7a9214575e cleanup: Change Salty to Brackish
In the code, the difference between SALTYWATER and SALTWATER is hard
to see. More importantly, in the UI - Brackish is the word for water
that has more salt that freshwater but less salt that seawater. The
docs already use the word to clarify what is meant.
2020-05-05 08:25:21 -07:00
Monty Taylor
95e6792c4f Grantlee: Add salinity and water type to grantlee variables
These can be useful in a printed divelog, especially if the
log entry is also showing weight and exposure suit.

Signed-off-by: Monty Taylor <mordred@inaugust.com>
2020-05-05 17:31:47 +03:00
Berthold Stoeger
769915f3fe selection: create global single_selected_trip() function
The DiveListView had a singleSelectedTrip function that
returns the selected trip if exactly one trip is selected.
This could be very slow if numerous non-trip items were
selected, because all the selection indices were back-
translated by the proxy model.

This could make selection changes very slow, because the
MainTab used said function to determine whether it should
show trip or dive data.. Indeed, with a 3500 dive test log,
when selecting all dives in tree mode, the updating of the
TabWidgets is sped up from 130 ms to 5 ms this commit.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-03 15:02:21 -07:00
Berthold Stoeger
f961ec7a8b selection: introduce clear_selection() function
The DiveListView would touch the selection-innards directly.
Let's encapsulate that. Moreover, take care to reset the trip
selection when resetting the core data.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-03 15:02:21 -07:00
Berthold Stoeger
09b7fcbcf4 selection: add selection flag for trips
In analogy to dives add a selection flag for trips. The reason
being that search for a selected trip can be painfully slow when
we do it through Qt's proxy model.

Make sure to deselect trips when they are removed from the core.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-03 15:02:21 -07:00
Berthold Stoeger
32d87db8b3 cleanup: remove unused function append_dive()
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-02 14:52:51 +02:00
Berthold Stoeger
9c70261c0e cleanup: move declaration of utc_mk* functions to new subsurface-time.h header
No point in slurping in all of dive.h for translation units that only
want to do some time manipulation without ever touching a dive.

Don't call the header "time.h", because we don't want to end up in a
confusion with the system header of the same name.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-01 09:42:31 -07:00
Berthold Stoeger
46cdf24e11 cleanup: only include QString in desktop-widgets/importgps.h
This included QFile, which is fatter and not needed here. Include
QFile only in the actual translation unit.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-01 09:42:31 -07:00
Berthold Stoeger
95284c026e cleanup: move dive_table from dive.h to divelist.h
This allows us to decouple dive.h and divelist.h, a small step in
include disentangling.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-01 09:42:31 -07:00
Berthold Stoeger
c13040798c cleanup: move FRACTION macro from dive.h to units.h
There appears to be no reason to slurp in all dive.h when compiling
membuffer.c. units.h might not seem like the perfect place, but it
is the most fitting I found.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-01 09:42:31 -07:00
Berthold Stoeger
8ce7c4664a cleanup: move DECOTIMESTEP from dive.h to planner.h
Long-term project: reduce the size of dive.h

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-01 09:42:31 -07:00
Berthold Stoeger
44132e44a9 cleanup: make enumerate_devices of external linkage
For consistency: declare enumerate_dives as extern, since we do that
for all other C-functions.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-01 08:53:45 -07:00
Berthold Stoeger
c8334ad11b cleanup: make analyze_plot_info local to profile.c
No external caller of this function exists. Moreover, turn the return
type to void, as it only returned the passed-in plot_info and no
caller used that.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-01 08:53:45 -07:00
Berthold Stoeger
21e2488d2d cleanup: const-ify a few functions in planner.c
It make debugging much easier if the function signature tells you
that a parameter is not altered.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-01 08:53:45 -07:00
Berthold Stoeger
d787e8812c profile: for maxtime calculation include the sample after the last event
When plotting profiles with surface segments, there were strange
artifacts. As we found out with Robert, these were due to the fact
that the calculated maxtime was set to the last event which is just one
second inside the surface segment. This terribly confused the profile
code. For example, it didn't properly allocate samples for the surface
segment.

Thus, when calculating maxtime, consider the last sample beyond the
last event.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-01 12:36:28 +02:00
Berthold Stoeger
8bc4233add profile: return air for one-past last cylinder
This is the code for "surface air".

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-01 12:36:28 +02:00
Berthold Stoeger
ffc3e598fa core: create fake cylinder at end of cylinder table (hack!)
When we had fixed-sized cylinder arrays, the planner used the last
empty cylinder for "surface air". This was not recognized by the UI
as a separate cylinder, because "empty cylinder" was the sentinel for
the end of the table. The conversion to dynamically sized cylinder
tables broke this code: everytime the surface segment is changed,
a new dummy cylinder is added, which is visible in the UI.

As a very temporary stop-gap fix, emulate the old code by creating
a cylinder and then setting the end-of-table to before that cylinder.
This means that we have to loosen the out-of-bound checks.

That's all very scary and should be removed as soon as possible.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-01 12:36:28 +02:00
Berthold Stoeger
b949bad026 core: always keep an empty cylinder at the end of the cylinder array
This will be temporarilly used by the planner to mark consumption of
air at the surface. Do this by creating a new function add_cylinder,
which replaces add_to_cylinder_table() and takes care of always adding
a dummy cylinder at the end of the table. Make the original
add_to_cylinder_table() local, so that it cannot be accessed anymore.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-01 12:36:28 +02:00
Berthold Stoeger
5ba7c68433 cleanup: remove unused function get_divepoint_gas_string()
The last user was removed way back in commit
9fbd11744f.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-27 22:48:15 +03:00
Berthold Stoeger
f43b3f56b2 cleanup: remove Command::inCommand()
This was used by the divelist to check wether a selection change is
programmatical or user-initiated. However, since there is only one
entry point for programmatical selection changes, this is not needed
anymore. Remove it - this removes an inter-module dependency.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-26 13:54:59 -07:00
Dirk Hohndel
0fe02af0e8 build-system/android: remove libusb at QTest
We no longer use libusb to access USB devices on Android, therefore
there's no point including libusb in our build. Also, we have never even
attempted to run the tests on Android, so let's not even pretend to
support building them.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-04-25 13:18:41 -07:00
Berthold Stoeger
d8fabd241c cleanup: move clearing of event names to clear_dive_file_data()
Move this to the core so that desktop and mobile don't have
to call this explicitly. Matter of fact, mobile didn't call
this. It is unclear, whether that was even used on mobile,
though.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-24 10:40:12 -07:00
Berthold Stoeger
17526ded58 cleanup: move clearing of device nodes to clear_dive_file_data()
It makes no sense to keep the device nodes if all the other data
is cleared. Let's do this automatically and not explicitly.
This ensures that the function is also called on mobile.
Currently it was only called on desktop.

Weirdly, the parser-tests were expecting that the device nodes
were not reset by clear_dive_file_data() and therefore divecomputers
were accumulating in the test results. Thus, the additional
computers had to be removed from the expected test results.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-24 10:40:12 -07:00
Berthold Stoeger
52f93ea326 cleanup: whitespace fix
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-24 10:40:12 -07:00
Berthold Stoeger
9386eb2a0b cleanup: move get_dc_nickname from qthelper.cpp to divecomputer.cpp
1) qthelper is already huge.
2) set_dc_nickname et al. is already there.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-24 10:40:12 -07:00
Berthold Stoeger
3d4698c0a1 filter: add a week to maximum default date time
The filter sets the maximum date to now. This is so confusing when
you manually add a dive and it isn't shown, because it is slightly
in the future. Add seven days, that should help.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-24 10:05:27 -07:00
Berthold Stoeger
89784a176e filter: implement filtering for divemode
This only checks the first divecomputer as the semantics for
multiple dive computers with different dive modes are not
clear. Should we check them all?

The implementation is a bit hackish: the indexes [0...n] of the
combobox are mapped onto [-1...n-1], where -1 means don't filter
and n-1 is the last valid dive mode.

Implements #2329

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-24 10:05:27 -07:00
Berthold Stoeger
4aebcdc021 core: return -1 from explicit_first_cylinder() if dive has no cylinders
Arguably, returning 0 for a dive with no cylinders is wrong, since the
0 is a valid cylinder id, however that cylinder doesn't exist. Instead,
return -1. All callers of explicit_first_cylinder() return early anyway
for dives with no cylinders.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-20 12:59:06 -07:00
Berthold Stoeger
d81df0dd19 profile: avoid invalid accesses in setup_gas_sensor_pressure
Since we removed MAX_CYLINDERS, we have the possibility of dives
with no cylinders. In such a case, setup_gas_sensor_pressure()
would do invalid read- and write-accesses. Therefore, return
early in such a case.

Reported-by: Chirana Gheorghita Eugeniu Theodor <office@adaptcom.ro>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-20 12:59:06 -07:00
Dirk Hohndel
ad66297cfd desktop: remove user survey
We have never made good use of the results. Let's just remove it.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-04-19 14:27:54 -07:00
Dirk Hohndel
12bafa4e41 core: debug cert calls
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-04-18 09:00:21 -07:00
Dirk Hohndel
8629fa3f18 core: bring back libgit2 certificate callback
Turns out that at least on Android libgit2 sometimes rejects valid
certificates. And I cannot quite figure out when and why. But since we
actually already checked the validity of the certificate when we called
canReachCloudServer() (and the Qt code handles certificates correctly),
we'll simply ignore this here and override the check to always return
true for our cloud server.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-04-18 09:00:21 -07:00
Dirk Hohndel
f9f4a9c232 debug output: ensure our debug output is captured on Android
I would have bet money that Android used to send stderr to the logcat
log, but apparently it doesn't (anymore?). So in order to be able to
have a chance to debug weird cloud storage issues on Android, let's do
some wholesale replacement of fprintf(stderr,...) with our own version
of the INFO macro that we long ago borrowed from libdivecomputer (and
rename it to ensure we don't have a conflict there).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-04-18 09:00:21 -07:00
Robert C. Helling
39784be4e8 Fix CSV for profile export
The function to print a double did not print a comma while
the lines ended in a comma.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2020-04-18 13:41:29 +02:00
Berthold Stoeger
b1f8b6b950 profile: avoid double-free when reusing plot_info
free_plot_info_data() freed the pressure-data, but didn't set the
value to NULL. Thus, when the plot_info was reused, a double-free()
could ensue.

Crash condition: export the profiles of multiple dives with pressure
data.

Reported-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-18 11:17:32 +02:00
Dirk Hohndel
f24cbbcb2c git-storage: add additional debug output
This helps the user figure out why we weren't able to write a tree.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-04-15 07:58:10 -07:00
Dirk Hohndel
2f8f6c4fa1 git-storage: add helper function to delete remote branch
This will be used by the test to clean up test branches that are created
on the server. Since we aren't testing that functionality (it's not
something that Subsurface itself ever does) the helper prints out errors
it encounters, but doesn't report them back to the caller.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-04-15 07:58:10 -07:00
Linus Torvalds
f4ffd7a8fb git-storage: fix up old broken local caches to use the right branch
If you had one of the unfortunate local git caches with a local HEAD
just pointing to 'master', this will make note of that and then fix it
up to use the proper branch name in the cache repository.

[Dirk Hohndel: demoted from error to fprintf as most users won't care]

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-04-15 07:58:10 -07:00
Linus Torvalds
433149af19 git-storage: make creation of empty cache repo set the initial branch
In create_and_push_remote(), we set up the remote tracking etc to use
the proper branch name, but never actually set up the initial local
branch for the new cache repository at all.  So the repository would end
up with the default 'master' branch, instead of the branch name it
should have.

This went unnoticed, because most setups start by initializing the git
caches by cloning from the cloud, and that worked fine.

Debugged-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-04-15 07:58:10 -07:00
Berthold Stoeger
103951bc78 divelist: when removing/adding a dive unregister/register fulltext
This fixes a crash: when the undo commands removed a dive from
the list, the fulltext cache was not cleared. If now the divelist
is reset and then the undo-command deleted, deletion of the owned
dive tries to remove it's fulltext cache, which doesn't exist
anymore.

For reasons of symmetry, when readding the dive, its fulltext
has to be registered.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-13 08:52:48 -07:00
Berthold Stoeger
8b93d67106 mobile: remove fine-grained notification
When initializing the fulltext-cache and the dive-list, every
100 dives a notification was shown. I had a feeling that this
made startup significantly slower, but that could have been
purely psychological.

Therefore I measured and indeed, removing the fine-grained
notification, it becomes *significantly* faster. For a 3500
dives test log with mobile-on-desktop:

Initialization of the fulltext: 1350 ms -> 730 ms (-46%)
Initialization of the divelistmodel: 689 ms -> 113 ms (-83%)

Let's remove the fine-grained notification. There *is* a visual
indication of work-in-progress anyway.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-13 08:30:51 -07:00
Robert C. Helling
9feda56006 Remove extra argument and add a test
The compiler complained about this and it seems the
function does not need it.

Additional-test-suggested-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2020-04-13 09:42:29 +02:00
Robert C. Helling
b50d5b63ad Preserve events when editing dive in planner
The planner does not know about events except gas
changes. But if the dive comes from the log, we
should preserve the dive computer events. At least
those that happend before we started to delete
waypoints to let the planner take over.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2020-04-13 09:42:29 +02:00
Robert C. Helling
1690ba7c0c Fix compiler warning about variable length field not last in struct.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2020-04-13 09:42:29 +02:00
Berthold Stoeger
f3b817c2d5 media: invalidate correct dive when removing picture
This fixes a bug: when deleting a picture when multiple dives
were selected, possibly the wrong dive was invalidated.
Thus, the dive wouldn't have been saved to the git repository.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-11 11:12:33 -07:00
Dirk Hohndel
6d187b5f4a
Merge pull request #2643 from bstoeger/cylinder4
First steps of cylinder-editing undo
2020-04-11 11:03:05 -07:00
Dirk Hohndel
1c420dc64a
Merge pull request #2736 from Subsurface-divelog/removeCloudOverride
core: remove cloud certificate override
2020-04-10 17:22:06 -07:00
Dirk Hohndel
61f9c4114e
Merge pull request #2737 from Subsurface-divelog/libgitCleanup
Libgit cleanup
2020-04-10 17:19:51 -07:00
Dirk Hohndel
fe6ecb4cd8 code cleanup: once we find a match, stop checking
This isn't really a useful performance improvement, but it's still better,
IMHO, because we don't have a less specific match later on potentially change
an already executed match.

Because of our coding style the comment covering multiple cases of Pelagic dive
computers now is associated just with the first of those entries. I don't see a
way to do this differently without being in violation of our coding style, so
I'll just keep it like this.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-04-10 17:18:17 -07:00
Dirk Hohndel
55bbdc2728 BLE dive computer detection
Both Shearwater Petrel and Petrel 2 identify as 'Petrel' as their BT and BLE
names. But only the Petrel 2 supports BLE, thus only the Petrel 2 shows up in
the list of known dive computers on iOS (which supports only BLE but not
BT-only). By switching this around to always pick Petrel 2 we now correctly
detect such a dive computer on iOS.

Fixes #2739

Reported-by: Rick Holcombe <wrh@nc.rr.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-04-10 17:18:17 -07:00
Dirk Hohndel
b241d09694 mobile/models: correctly reset the connection model
Qt hates empty ranges, and even for a non-empty range, this is better
implemented as a reset than a remove.

This fixes a crash that I have been able to create on iOS by rescanning
for devices on the download page.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-04-10 17:18:17 -07:00
Berthold Stoeger
3f3869ff65 media: move picture function from dive.c to picture.c
Currently, move only those functions that do not access dive
structures.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-10 10:53:03 -07:00
Berthold Stoeger
34657f62ae cleanup: remove picture_free()
There is the free_picture() function with the same functionality.
The compiler/linker should recognize that and remove the duplicate
code, but still...

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-10 10:53:03 -07:00
Berthold Stoeger
aa8cadbcdd cleanup: remove dive_get_picture_count() function
The last user was removed in 5b7e4c57f7.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-10 10:53:03 -07:00
Dirk Hohndel
53fb533a99 cloud-storage: create consistent commit message for merges
This never made sense and I think I just forgot to complete this code
when I first worked on it. Now we can see which version of Subsurface or
Subsurface-mobile created a merge.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-04-10 09:53:24 -07:00
Dirk Hohndel
7a238b6146 cloud-storage: simplify creation of git authorship
While having the local user information in the repo on Linux seemed
clever when we implemented it, it's inconsistent with all the other
platforms. Let's just not do that unless the user has indeed set
a global name/email pair for git.

Instead indicate if this was Subsurface or Subsurface-mobile.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-04-09 17:05:44 -07:00
Dirk Hohndel
67a717dc05 cleanup: remove support for ancient versions of libgit2
We require a minimum of libgit2 0.26.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-04-09 17:05:30 -07:00
Dirk Hohndel
ccbd4d1916 core: remove cloud certificate override
This code stopped being useful a long time ago.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-04-09 13:54:43 -07:00
Berthold Stoeger
3a74f65063 fulltext: don't call words.clear() in FullText::populate()
This function was not meant to be called with already existing data.
However, if it was, it cleared the words without clearing the fulltext
caches of the dives. This lead to crashes.

Be more resilient by not clearing the words: Already existing dives
are unregistered during the process of populating anyway. So this
now *should* work if new dives are added to the dive list and then
this function is called.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-08 08:08:19 -07:00
Berthold Stoeger
d9599589c7 fulltext: rename fulltext_reload() to fulltext_populate()
This function was named improperly: it was only used on freshly
loaded data. Indeed, attempts to use it to actually reload lead
to crashes.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-08 08:08:19 -07:00
Berthold Stoeger
d8b92a1852 git: don't check for git sha in parse_file()
parse_file() refused to load from a git repository if we already
had that repository and there were no changes. However, this only
checked the global divelist_changed flag, which does not track
undo-commands. Thus, after editing dives the user couldn't reload
from git.

Remove this check. It is somewhat questionable that the io layer
refuses to load from a repository anyway. Let the caller decide.
There appears to be a check_git_sha function for that purpose(?).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 07:46:27 -07:00
Berthold Stoeger
2eeb5f4fc2 undo: more fine-grained editing of cylinder
Don't overwrite the full cylinder when editing a single field.
Implement three "modes": editing of type, pressure and gasmix.

Don't consider individual fields, because some of them are
related. E.g. you can change the gasmix by setting the MOD.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
5b65776e43 cleanup: remove same_cylinder
The last user was uses a more general function.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
bbd3f0dd6d cylinders: use preferences modpO2 preferences value
Use the user-editable MOD-pO2 preferences value when creating
a default cylinder. It is not clear to me, when that even has
a consequence, but it looks like the right thing to do.

Reported-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
48b4dc9c84 cleanup: remove commented-out evn_foreach() function
Apparently this was used to hide events in pre-Qt times. However,
that has already been reimplemented in different ways. Let's remove
that commented-out code.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
7081674b67 cleanup: remove remove_event() function
No user left.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
c585fd9f8e cleanup: remove vintage report_error() function declaration
Remove an old commented-out declaration.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
9fe1951db2 core: split out create_gas_change_event() from add_gas_change_event()
For undo, we want to create gas change events without adding them
immediately to the dive computer.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
b1906dd04f cleanup: move add_gas_switch_event to dive.c
Since all the other event-functions are also defined there.
Ultimately, we should probably move them to their own
event.c translation unit.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
ab8e317b28 undo: implement renaming of events
There is a slight complexity here owing to the fact that the profile
works on a copy of the current dive: We get a copy of the event and
have to search for the original event in the current dive. This
could be done in the undo command. Nevertheless, here we do it in
the profile so that when in the future the profile can work on a
non-copied dive we can simply remove this function.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
7018783f64 undo: replot profile if event changed
Add a DiveListNotifer::eventsChanged signal, which is emitted when
the events changed. This is very coarse, at it doesn't differentiate
between signal addition / editing / deletion. We might want to
be finer in the future.

Catch the signal in the profile-widget to replot the dive if this
is the currently displayed dive. Reuse the cylindersChanged() slot,
but rename it to the now more appropriate profileChanged().

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
3aa1bb5bfa core: add remove_event_from_dc() function
We have a remove_event() function that
1) frees the event
2) works on the current divecomputer
3) compares the events because the profile has copies of events

However, for undo commands
1) we want to keep the event so that we can readd it later
2) we have to work on arbitrary divecomputers
3) we don't work with copies of events

Therefore, create a new remove_event_from_dc() function that
does all that. Moreover, make the event argument to remove_event()
const to (slightly) point out the difference in the API.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
2417a54675 core: split add_event() in two parts
add_event() creates and adds an event from the given parameters.
For undo, we want to do these separately, therefore split this
function in two parts: create_event() and add_event_to_dc().
Keep the add_event() function for convenience. Moreover, keep
the remember_event() call in there, so that undo-commands can
call remember_event() once, not on every undo/redo action.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
dee7fd9f30 cleanup: use SAMPLE_EVENT_BOOKMARK in add_event() calls
In two cases we were passing the magic value 8 instead of the
symbolic SAMPLE_EVENT_BOOKMARK. Use the symbolic version instead.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
5b7a316593 undo: reorder cylinders on remove-cylinder undo/redo
The cylinders in the events must be reordered if we remove
a cylinder. To avoid duplication of code, move the reordering
function into qthelper.cpp, though it might not be ideal
there.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
aa7b0cadb2 undo: add cylinder undo commands by copy & paste
Do a simple copy & paste followed by a simple search & replace
to generate cylinder undo commands from weight undo commands.
Obviously, this is still missing the necessary code to keep
the dive-data consistent after cylinder editing.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:34 +02:00
Berthold Stoeger
36754d3399 cleanup: move fill_default_cylinder from planner.c to equipment.c
Moreover, move the declaration from dive.h to equipment.h.
The result is a) more consistent and b) more logical.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:34 +02:00
Berthold Stoeger
e008b42a59 core: add create_new_cylinder() function
Turn the code in CylindersModel that creates a new cylinder for
addition into its own function to avoid code duplication. This
will be used from the undo commands.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:34 +02:00
Berthold Stoeger
f1e08fd470 core: introduce set_cylinder() function
We have a set_weightsystem() function. For symmetry, introduce
a set_cylinder() function so that we can more-or-less copy&paste
the weightsystem undo code for cylinder undo.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:34 +02:00
Berthold Stoeger
1ca25ec039 core: make free_cylinder() global
The cylinder undo commands will keep a copy of a cylinder
and therefore need the ability to free a cylinder object.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:34 +02:00
Berthold Stoeger
2453d4fc1f core: introduce clone_cylinder() function
We have a clone_weightsystem function. For symmetry, introduce
a clone_cylinder() function so that we can more-or-less copy&paste
the weightsystem undo code for cylinder undo.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:34 +02:00
Dirk Hohndel
3df0cf6196 core/fulltext: give progress update while populating index
Especially with large dive logs this will prevent the user from thinking
that the app is hung.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-04-04 12:00:25 -07:00
Dirk Hohndel
f58bc91d8b core: add additional notification callback
Especially on slower devices with a large dive list the startup time has
become really long. This callback allows us to give the user an idea of
what the app is doing during that time.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-04-04 12:00:24 -07:00
Berthold Stoeger
d5e6a65944 cleanup: copy saved_git_id, don't use local buffer
In an attempt to reduce the number of global variables, don't use
a local buffer to store the currently loaded git-id. The git-id
itself is still a global variable, which in the future can hopefully
be encapsulated in a "struct File" or similar.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-04 10:13:14 -07:00
Dirk Hohndel
93ab1232f0 cleanup: fix unitialized value
Fixes CID 355179

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-24 16:45:48 -07:00
Dirk Hohndel
e6cbb28a9f translations: use German translation for non-Swiss German locales
Unless a German speaker explicitly asks for the Swiss localization, give
them the German localization.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-22 12:02:48 -07:00
Berthold Stoeger
463bb25705 cleanup: don't allocate translators on heap
This is pointless bike-shedding: instead of allocating the QTranslators
on the heap an assigning them to a variable at translation-unit scope,
we can simply generate them as static objects.

That makes
1) two fewer lines of code
2) the translator-resources are properly released when the application
   closes.

Not that either of these points would make *any* difference.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-22 12:01:09 -07:00
Berthold Stoeger
0f30ca9b33 cleanup: remove memory leak in initUiLocale()
The prefs.locale.lang_locale field was overwritten without
free()ing the old value. Not that the function would be called
numerous times, but as a matter of principle...

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-22 12:01:09 -07:00
Berthold Stoeger
eb55ffde16 cleanup: split uiLanguage() in two functions
The uiLanguage() function was used for two purposes: to initialize
the language related preferences and to read the current language.
To make things more easy to follow, split this function in two:
one for initializing, one for getting the current language.

Moreover, don't return the current locale in an out-parameter
as there is already a function to do that [getLocale()].

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-22 12:01:09 -07:00
Berthold Stoeger
2dca7d0ce5 locale: store locate to preferences after fixing up mac-weirdness
In uiLanguage() the preferences fields are initialized and there
is fixup for a MacOS indiosyncrasy. For some reason the uncorrected
value is written to the preferences. Let's store the corrected
value instead.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-22 12:01:09 -07:00
Berthold Stoeger
621d00d891 cleanup: don't call uiLanguage() in qPref::loadSync()
uiLanguage() initializes the language fields from the preferences
values. It is unclear why this function is called in qPref::loadSync()
*before* the fields are loaded from disk. It can only initialize to
the default values anyway. After qPref::loadSync() uiLanguage()
is called again so that everything can be initialized with the
correct perferences values.

Remove the first call. If things break, let's fix them in a sensible
way.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-22 12:01:09 -07:00
Berthold Stoeger
2db7d5cc23 Revert "core: use set_lang_locale to modify prefs.locale.lang_locale"
This reverts commit 573a4a5e2d.

The commit broke setting the language in the desktop preferences:
Instead of setting the locale in the prefs struct, the locale
is set via qPrefLanguage. However, that saves the default language
(extracted from the system) to disk. Now when the language is
read from the preferences, we get that default value.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-21 21:06:36 -07:00
Berthold Stoeger
f4f15039ac Ignore invalid dives in statistics
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-20 15:20:44 -07:00
Berthold Stoeger
0d78fe45c3 Core: consider invalid flag when adding dives
Adding dives uses the number of the last dive to create a new
dive number. Ignore invalid dives.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-20 15:20:44 -07:00
Berthold Stoeger
95b60d1b18 Filter: hide invalid dives
Hide invalid dives if prefs.display_invalid_dives is false.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-20 15:20:44 -07:00
Berthold Stoeger
4e47cdfa2c Undo: implement invalidate-dive command
Connect command to context menu.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-20 15:20:44 -07:00
Berthold Stoeger
329641fdcd Core: introduce invalid flag for dives
Implement reading/writing the flag from/to XML/git.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-20 15:20:44 -07:00
Dirk Hohndel
eb76bdb3e3 cleanup: fix mis-spelling of UCT in comments as well
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-19 08:41:19 -07:00
Berthold Stoeger
70fef60b5c cleanup: remove unnecessary include
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-19 00:25:13 +01:00
Berthold Stoeger
2da7b6d0f5 cleanup: remove record_dive() function
No user left.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-17 16:50:20 -07:00
Berthold Stoeger
ed3e68c36a git: load into arbitrary dive tables
The git parser loads into the global dive table, even if it
is called indirectly via parse_file(). However, parse_file()
may be given a different table. Fix this by extending the
git parser state.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-17 16:50:20 -07:00
Berthold Stoeger
4bd217299a mobile/edit: don't add dive site twice to table
When editing a dive on mobile we might have to create a new
dive site. That site is added to the global dive site table
in the undo command. However, the code in QMLManager created
the dive site with create_dive_site*() functions, which already
adds it to the table. The undo command then added the dive
site again leading to a hang of the application.

To solve this problem, create new alloc_dive_site*()
functions that do the same as create_dive_site*()
but do not add it to the table.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-17 14:05:24 -07:00
Berthold Stoeger
71f573da2a git: return strdup()ed empty string on error in pop_cstring
The pop_cstring() function is used by the git parser to
duplicate a quoted string. On error, it returns an empty
string literal. Since the caller expects a copied string
and takes ownership of that string, it will ultimately
be freed.

Concrete example: a log with erroneous cylinder data was opened
getting such an empty string literal as description. On closing or
syncing with the cloud, the dive is freed, leading to a free
of the string literal -> crash.

Return a copy of the empty string instead.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-16 10:57:12 -07:00
Dirk Hohndel
2265a27912 android/usb: better memory management
Instead of relying on the std::vector staying unchanged and not freeing
its members, instead keep a copy of the object in our DCDeviceData class.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-16 07:58:20 -07:00
Dirk Hohndel
0b72495413 android/usb: simply restart the download after receiving permission
If the user tries to download from a device that he hasn't given the app
permission to read from, Android will pop up a dialogue asking for that
permission. With this after giving the permission we continue (well,
technically, restart) the download which is likely the expected behavior.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-16 07:58:20 -07:00
Christof Arnosti
87e12029f9 android/usb: remove "autoselect driver" option for unknown VID/PIDs
Signed-off-by: Christof Arnosti <charno@charno.ch>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-16 07:58:20 -07:00
Dirk Hohndel
ec3a968df9 android/usb: pass in the UsbDevice when downloading
This finally allows us to download from not just the first device, but specifically
the device that the user picks.

Passing the object through a void pointer is not nice - but since this traverses
C code other solutions (like passing an index into the list) seemed even worse.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-16 07:58:20 -07:00
Dirk Hohndel
b0eccec8ed android/usb: pass the usbDevice for intent handling
Instead of creating a string with all the object information, simply pass
the actual object to the C++ code.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-16 07:58:20 -07:00
Dirk Hohndel
c19e3bd5ba android/usb: remove alternative way of scanning for devices
We now always create a list of usb devices that doesn't list a driver
for known devices, and adds multiple entries with each of the drivers
for devices that are unknown to us.

This removes some debugging output in the ..._open() function as well.

This could be combined with Christof's earlier commit.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-16 07:58:20 -07:00
Dirk Hohndel
c81854ca21 android/usb: add helper to recognize chipsets known to us
This will allow us to know when we can guess the driver.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-16 07:58:20 -07:00
Dirk Hohndel
c2077992ff android/usb: guess the actual manufacturer and product
For a small number of dive computers we can actually figure out the
real information which we can then later show to the user.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-16 07:58:20 -07:00
Christof Arnosti
ce7d4d1ca6 usb-serial-for-android: More fields in device descriptor
As discussed in issue #2657, there are now more fields about the usb
device information in android_usb_serial_device_descriptor.

Additionally, the user-facing string now makes more sense:
"vendor [<bus# as integer>:<dev# as integer>]"
Where vendor is as reported by android, but shortened to 16 characters.

Examples:
FTDI [1:2]
Silicon Labs [1:4]

Signed-off-by: Christof Arnosti <charno@charno.ch>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-16 07:58:20 -07:00
Christof Arnosti
344f7861b4 usb-serial-for-android: Use correct format spezifier for size_t
Signed-off-by: Christof Arnosti <charno@charno.ch>
2020-03-16 07:58:20 -07:00
Christof Arnosti
a34a81d120 android usb serial: Prepare device / driver select
This commit contains the serial_android_usb part of the changes proposed
in issue #2657.

What's implemented:
- A data structure that contains all the data that can be used to
  describe an usb device (including user-facing string).
- A function to get a list of all attached usb devices (optionally with
  selectable driver class).
- Changes in the serial_android_usb_open-function and in the Java part
  to use the information about the usb device and optionally selected
  driver when connecting.

This commit keeps compatibility with the current UI-Code in the case
that only one USB-Device is connected. If two devices are connected,
only the first one is tried.

There are still some small things to do:
- Change the user-facing string to something more descriptive.
- Parts which aren't uesd anymore when the UI-Part is implemented are
  simply marked as obsolete (to keep compatibility for now).

But generally it seems to work.

[Dirk Hohndel: some white space / coding style adjustments]

Signed-off-by: Christof Arnosti <charno@charno.ch>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-16 07:58:20 -07:00
Linus Torvalds
5e89d81d9d iostream: fix incorrect rfcomm error case when writing
This is the exact same case as the previous commit, just for the writing
side.

Once again, it's the subsurface rfcomm iostream code that can return
DC_STATUS_SUCCESS with a byte count of zero when something goes wrong
with the write.

And once again, our libdivecomputer iostream code didn't try to be
robust and protect itself from that case.

The fix is equivalent, although slightly simpler, since the write side
doesn't have the whole timeout issue.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-03-14 11:34:46 -07:00