Commit graph

17998 commits

Author SHA1 Message Date
Dirk Hohndel
572e2678a0 cleanup: initialize all fields
This doesn't appear likely to cause an issue, but also doesn't
seem wrong.

Fixes CID 350734

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-25 13:58:03 -07:00
Dirk Hohndel
8e330f297e cleanup: fix over-eager Coverity warnings
Technically get_dive() could return a nullptr. The existing code made sure the
argument passed to get_dive() was one that always would result in a valid dive
pointer being returned. The new code is only slightly less efficient but allows
a static code analysis to easily see that we don't derefence NULL pointers here.

On some level this change is unnecessary. But it's also not wrong.

Fixes CID 354762

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-25 13:58:03 -07:00
Dirk Hohndel
e30ba8a8e0 cleanup: fix over-eager Coverity warnings
Technically get_dive(i) could return a nullptr. But given the range for i that
can never happen. Still, the test is extremely cheap and doesn't hurt.

Fixes CID 354768
Fixes CID 354766

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-25 13:58:03 -07:00
Berthold Stoeger
272b7b3e27 cleanup: remove double const qualifier
The redundant qualifier was introduced in an erroneous rebase.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25 09:59:36 +01:00
Dirk Hohndel
a58eee9aa3 tests: move TestGitStorage to its own test config
This way 'make check' doesn't execute TestGitStorage anymore.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-24 15:22:37 -07:00
Dirk Hohndel
7068e64e49 test: manually run gitStorageTest
This way we should see the output and hopefully be able to figure
out why that silly test keeps randomly failing.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-24 15:22:37 -07:00
Berthold Stoeger
1211520ca9 build-system: switch to using C++17 as default C++ dialect
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-24 15:21:55 -07:00
Berthold Stoeger
b7a586a5b4 core: remove create_device_node() from fixup_dive()
The device nodes are created for all DCs, when importing the
dives. There is no point in creating only the device node for
the first DC in fixup_dive().

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-24 09:51:37 -07:00
Berthold Stoeger
74d84a959a divecomputer: add device to provided table instead of global table
In the specuial case of suunto, where we may add a device directly
instead of via dive->dc, add the device to the provided table.
The caller will then pass on the new device to the undo system.
This makes downloading finally really undoable (at least I
hope so). So far, the dives and dive sites were removed, but any
new device remained.

However, when setting the device-id via serial, we now have
to check both, the global and the downloaded list of devices.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-24 09:51:37 -07:00
Berthold Stoeger
2bcb3d88a0 divecomputer: add device_table pointer to device_data_t
In one weird case (suunto), the code in libdivecomputer.c
generates a device node directly instead of going the usual
way (setting the data in the dc-structure of the imported
dive). It is unclear to me whether that has to be that way,
as it depends on the chronological order of callbacks to
event_cb() and dive_cb().

Therefore add a device_table pointer to device_data_t
so that the downloader can add the device to this table. This
only adds the pointer, but does not yet use it in the
downloading code.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-24 09:51:37 -07:00
Berthold Stoeger
5a19437311 cleanup: remove dc_user_device_t
The same structure was defined as "struct dc_user_device_t"
and typedefed as "device_data_t". Unify this. Since there
are much more of the latter, remove the former.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-24 09:51:37 -07:00
Berthold Stoeger
8c65558b5c devices: create device nodes in parsers
So far, we added a non-global device table to the parser states.
Now, create device nodes in that table instead of in the global
table. Thus, on undo of dive-import, the new device nodes will
be removed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-24 09:51:37 -07:00
Berthold Stoeger
255f561aff git: add device-table to git-parser-state
In analogy to the xml-parser add a device-table to git's parser-state.
Currently this is unused. In upcoming commits the git parser will
then be changed to add device nodes in this table instead of the
global device table. The long-term goal being to detach the
parsers from global state and to make dive-import fully undoable.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-24 09:51:37 -07:00
Berthold Stoeger
694776eed1 cleanup: rename set_dc_nickname() to add_devices_of_dive()
The function was misnamed in that it doesn't set the nickname
of a device. Instead, it adds all (unknown) devices of a
dive to the/a device-table. Let's call it appropriately.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-24 09:51:37 -07:00
Berthold Stoeger
39a4090c0a devices: add devices in Command::importTable()
Add a device_table parameters to Command::importTable() and
add_imported_dives(). The content of this table will be added
to the global device list (respectively removed on undo).

This is currently a no-op, as the parser doesn't yet fill
out the device table, but adds devices directly to the global
device table.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-24 09:51:37 -07:00
Berthold Stoeger
fadea413cd devices: return index from function adding / removing devices
This will be used to keep the model representing the device-list
up to date.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-24 09:51:37 -07:00
Berthold Stoeger
53118be1f9 devices: add functions to add / remove / check for devices
To include the device code in the undo system, we need functions
to check for the existence of devices and to add or remove them.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-24 09:51:37 -07:00
Berthold Stoeger
a261466594 parser: add device_table to parser state
If we want to avoid the parsers to directly modify global data,
we have to provide a device_table to parse into. This adds such
a state and the corresponding function parameters. However,
for now this is unused.

Adding new parameters is very painful and this commit shows that
we urgently need a "struct divelog" collecting all those tables!

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-24 09:51:37 -07:00
Berthold Stoeger
41975435a2 cleanup: remove TagWidget::fixPopupPosition()
No user of that member function!

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-24 09:50:39 -07:00
Berthold Stoeger
d543196059 desktop: overwrite drag & drop in TagWidget
The interaction of Qt's drag & drop with GroupedLineEdit was
exceedingly weird. The user was able to scroll the viewport
making the text invisible.

This implements a very primitive alternative drag & drop
functionality: dropped text is regarged as a distinct tag.
This means that it is not possible to modify existing tags
by dropping in the middle of them. Arguably, this might even
be better than arbitrary drag & drop. But even if not perfect,
this fixes a very nasty UI behavior.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-24 09:49:36 -07:00
Berthold Stoeger
a9a4249b23 desktop: avoid crashes on drag&drop in GroupedLineEdit
If the user manages to "scroll" through the QPlainTextEdit by
a drag&drop action, the state of the widget becomes inconsistent.
On the one hand, the text-block says that it has one line.
On the other hand, its layout says that it has no line.
When trying to fetch the line, a crash occurs.

Try to detect such a strange state and return early in
GroupedLineEdit::paintEvent().

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-24 09:49:36 -07:00
Dirk Hohndel
0278f3f90c Update Changelog
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-24 09:47:37 -07:00
Dirk Hohndel
28107efd30 mobile: show location service warning
Google play now requires that we show an explicit notification when turning
on background location. This is an attempt to fulfill that requirement - we
won't know if this is 'good enough' until we submit the app, though.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-24 09:47:37 -07:00
Dirk Hohndel
4638936a22 mobile: show text with location service icon
I don't recall why we removed that text, but this makes it much clearer
that the service is active.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-24 09:47:37 -07:00
Dirk Hohndel
420e64aae8 documentation: update package lists for Fedora/openSUSE
This has been tested on Fedora 33 and openSUSE Leap 15.2.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-23 21:01:43 -07:00
Dirk Hohndel
4801dcecf3 cleanup: remove outdated explicit libssh2 link
We used to need this when building our own libgit2 on older
distibutions. This shouldn't be needed anymore at all.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-23 20:48:15 -07:00
Berthold Stoeger
ad59f100ae cleanup: remove unused function intdup()
That was used by the old xml-params code, which was recently
replaced.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-23 18:17:02 -07:00
Berthold Stoeger
d508a16aca parser: replace params[] code by new xml_params struct
This fixes a load of memory holes, and makes the code
(hopefully) more readable.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-23 18:17:02 -07:00
Berthold Stoeger
b9b51ffd4e core: add a small helper-struct that keeps track of xml-parameters
The XML-parameter code is a mess. Ownership is unclear. Allocation
and freeing of strings is in different functions. Sometimes
only every second string is free()d, because keys are not copied.
But this is done inconsistently. The caller has to know how
many parameters the callee may add.

Instead, let's add a small helper-struct that uses C++ memory
management, but exports a C-API. The array for the XML-library
is generated on the fly.

This is only the implementation, the old code is not yet replaced.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-23 18:17:02 -07:00
Berthold Stoeger
ac3042b48b libdc: free value strings given by libdc's dc_parser_get_field()
Apparently libdc gives us copies of strings. The API is very
scary, because (at least according to my reading of the code),
the key/value pair may be stored in a cache. Thus on free()ing
the string in the cache becomes invalid and we must not access
it twice. Very obscure.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-23 18:13:44 -07:00
Berthold Stoeger
6b1be8c4f6 devices: use case-insensitive comparison for model
Recently, the sorting of the devices was changed to be
case-insensitive for models for consistency reasons. However,
then the equality-comparison should also be case-insensitive.

Break it out into its own function, to avoid that mistake
in the future.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-17 09:04:20 -07:00
Berthold Stoeger
c046742288 cleanup: rename clear_device_nodes() to clear_device_table()
For consistency with all the other clear_*_table functions
(dive, trip, dive_site, ...)

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-17 09:04:20 -07:00
Berthold Stoeger
ad608e48f5 filter: don't add to filter presets when importing dive sites
When importing dive-sites we would add to the global filter-preset
table. This data should be thrown away, just like the other tables
that might be imported.

This shows that we really should introduce a "struct divelog",
which collects all those tables into a single structure.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-17 09:04:20 -07:00
Berthold Stoeger
a7bbb6c1cc filter: remove filter_preset_table_t
We used a typedef "filter_preset_table_t" for the filter preset table,
because it is a "std::vector<filter_preset>". However, that is in
contrast to all the other global tables (dives, trips, sites) that we
have.

Therefore, turn this into a standard struct, which simply inherits
from "std::vector<filter_preset>". Note that while inheriting from
std::vector<> is generally not recommended, it is not a problem
here, because we don't modify it in any shape or form.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-17 09:04:20 -07:00
Berthold Stoeger
67aec56f8c filter: make filter_preset_table an opaque struct for C code
filter_preset_table_t was defined as "void" for C code.
However, that meant that any pointer could be passed as
such a table and such a table could be passed as any pointer,
without generating compiler warnings.

Indeed, we had a parameter-mixup that went unnoticed.

Therefore, make filter_preset_t an anonymous structure with
the name filter_preset instead.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-17 09:04:20 -07:00
Dirk Hohndel
3d7b2a2d7c cleanup: use correct printf format
This fixes a warning from the CodeQL scan.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-16 21:32:43 -07:00
Dirk Hohndel
6b7d7f9ee1 build-system: add GitHub action for openSUSE Leap 15.2
This way we test a Qt 5.15 build.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-16 21:32:43 -07:00
Dirk Hohndel
e57b7659cc build-system: add GitHub action for Ubuntu 20.10
This way we test a Qt 5.14 build.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-16 21:11:44 -07:00
Dirk Hohndel
6586438bf6 build-system: improve finding of libdivecomputer.a
On some systems it ends up in lib64 instead of lib.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-16 21:11:44 -07:00
Dirk Hohndel
86396e9904 build-system: fix libgit2 detection
Usually ldconfig isn't in the user's path.

Suggested-by: Cristian Ionescu-Idbohrn <cristian.ionescu-idbohrn@axis.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-16 20:23:37 -07:00
Berthold Stoeger
1d6c1db4a5 core: use case-insensitive comparison for device models
The code in core/libdivecomputer.c used string insensitive
comparison for device models, before being merged into core/device.c.

Let's reinstate that behavior, since it appears to be more logical.
On would assume that two different vendors will not use the same
model with different casing (and the same device-ids), so that
should be safe.

This uses strcoll to correctly sort unicode, which will hopefully
never be needed!

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-16 14:26:37 -07:00
Berthold Stoeger
0c769b04b7 cleanup: replace std::find_if by std::any_of
To search for devices with the same model, we used find_if().
However, that was only to check whether such a thing exists,
not to actually do something with said device.

Therefore, change this to std::any_of() to make it clear what
the purpose of the statement is.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-16 14:26:37 -07:00
Berthold Stoeger
8549f24c91 core: add device_table parameter to device table functions
Instead of accessing the global device table directly, add a parameter
to all device-table accessing functions. This makes all places in
the code that access the global device table grep-able, which is
necessary to include the device-table code in the undo system.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-16 14:26:37 -07:00
Berthold Stoeger
7b06349be5 core: remove call_for_each_dc()
The core now loops over the devices directly - no need for this
callback.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-16 14:26:37 -07:00
Berthold Stoeger
1e34e19c6d core: use C accessors in core/save-xml.c instead of callback
We now can loop over devices from C and check for selection.
So let's get rid of the last user of the call_for_all_devices()
callback.

Code readability improvement is not stellar, but one less
place where we shoe-horn user data through a void-pointer.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-16 14:26:37 -07:00
Berthold Stoeger
d93b261e89 core: factor out device_is_used_by_selected_dive() function
We have a callback for all devices with a twist: it can loop
over those devices that are used by a selected dive. This is
used for exporting a subset of the dive log.

Factor out the "is device used by selected dive" part of the
function and make it available to C. The goal is to make
the whole callback thing unnecessary and let C code loop
directly over the device list.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-16 14:26:37 -07:00
Berthold Stoeger
e8d3f75541 core: use C accessors in core/save-git.c instead of callback
Now we can simply loop over the list of devices. In this case,
it's not much more readable, but at least we don't have that
nasty pass user-data through "void *" pattern.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-16 14:26:37 -07:00
Berthold Stoeger
7aca64bfca cleanup: remove device::operator!=()
This was not used. Moreover, mark device::operator==() for removal.
This is used for detecting changes in the DiveComputerModel. This
can be removed once that is integrated into the undo system.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-16 14:26:37 -07:00
Berthold Stoeger
7415824a8c core: use C accessors in core/libdivecomputer.c instead of callback
Searching the proper device for the divecomputer was done via a
callback. Very hard to follow code. Since we can now access
"struct device" from C, obtain it directly via get_device_for_dc().

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-16 14:26:37 -07:00
Berthold Stoeger
74b8d13672 core: make get_device_for_dc() accessible from C
The function getDCExact() was used to search for a device structure
matching a divecomputer. Since C code can now access struct device,
we can export that function to C. Rename it to get_device_for_dc()
for consistency with naming of the core functions.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-16 14:26:37 -07:00