Commit graph

17986 commits

Author SHA1 Message Date
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
Berthold Stoeger
c4bfecce1b core: add C struct device and struct device_table accessors
Up to now, "struct device" and "struct device_table" were C++
only, because they used C++ strings for convenience. Since we
switched from QString to std::string, we can create accessors
for these structs. For the C code, we simply declare them as
opaque structs and give the full definition only for C++.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-16 14:26:37 -07:00
Berthold Stoeger
4a50badb57 cleanup: use std::vector in struct device_table
Since we converted from QString to std::string, let's also use
std::vector instead of QVector. We don't need COW semantics
and all the rigmarole. Let's try to keep Qt data structures
out of the core.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-16 14:26:37 -07:00
Berthold Stoeger
fd8bd9d5c7 cleanup: use std::string in struct device
struct device is a core data structure and therefore shouldn't use QString.
QString stores as UTF-16 (which is a very questionable choice in itself).
However, the real problem is that this puts us in lifetime-management
hell when interfacing with C code: The UTF-16 has to be converted to
UTF-8, but when returning such a string, this puts burden on the caller
who has to free it. In fact, instead of looping over devices from C-code
we had a callback that sent down temporary C-strings with qPrintable.

In contrast, std::string is guaranteed to store its data as
contiguous null-terminated and C-compatible strings. Therefore,
replace the QString by std::string. Keep the QString just in
one place that formats a hexadecimal number to avoid any
potential change.

The disadvantage of using std::string is that it will crash
when constructed with a NULL argument, consistent with C-style
functions such as strcmp, etc. Arguably, NULL is different
from the empty string even though we treat both as the same.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-16 14:26:37 -07:00
Berthold Stoeger
4e479677a0 cleanup: fix tiny memory hole in device.cpp
empty_string() returns true for "". Thus, we can't simply overwrite
the pointer if empyt_string() returns true, but must free the string
regardless. The joys of C memory management!

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-16 14:26:37 -07:00
Dirk Hohndel
485ac4b58f build-system/macOS: remove Qt SQL plugins and suppress some errors
Technically with this the app might be ready for AppStore inclusion. I don't see myself
spending the energy on that, TBH.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-16 14:19:59 -07:00
Miika Turkia
1a646a2e5c Duration is in seconds
The dive duration is given in seconds in the Shearwater cloud database.
(At least nowadays.)

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2020-10-16 14:15:50 -07:00
Dirk Hohndel
0aaa654433 build-system: switch to current libhidapi
A few years ago the upstream for libhidapi changed - it became part of the
libusb GitHub org. Switching to the latest version appears to fix some odd
problems with talking to the Suunto Eon Steele/Core dive computers on macOS (at
least I can no longer reproduce the problem after switching to the current
version).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-16 14:14:50 -07:00
Dirk Hohndel
967473a1cd build-system: add GitHub scanning
Enable the newly re-imagined Semmel based CodeQL scanning.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-16 14:14:05 -07:00
Berthold Stoeger
23dc56e9cc parser: fix parsing of DAN files
The last two parameters of the parse_dan_format() function were
mixed up: sites should come before filter_presets.

This should have caused crashes, for DAN files with dive sites.
I don't understand why this didn't cause compiler warnings.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-16 13:57:00 -07:00
Berthold Stoeger
2e5913d2ba core: fix detection of duplicate device names
Recently (c9b8584bd2) the sort criteria of the device-table
was changed from  (model/id) to (id/model). However, that
messed with the detection of duplicate device names: there,
the code searched for the first element greater or equal
to (model / 0).

With the reversal of the sort criteria, this would now
always give the first element.

Therefore, do a simple non-binary search, which is much
more robust. The binary search was a silly and pointless
premature optimization anyway - don't do such things
if not necessary!

Since only one place in the code search for existence
for a model-name, fold the corresponding function into
that place.

Moreover, change the code to do a case-insensitive compare.
This is consistent with the dc_match_serial() code in
core/libdivecomputer.c, where matching models is
case-insensitive!

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-13 16:26:42 -07:00
Berthold Stoeger
ff6c1a34ad cleanup: remove unused function is_default_dive_computer()
The last actual user was apparently removed back in 2013(!):
34db6dc2be

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-13 20:15:41 +02:00
Dirk Hohndel
39ab754406 Update translations from Transifex
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-13 09:15:13 -07:00