Commit graph

2022 commits

Author SHA1 Message Date
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
Linus Torvalds
4ee4bbdb58 iostream: fix incorrect rfcomm error case when reading
We had two independent bugs here, both of which needed to fire for this
to cause a problem.  This fixes both of them.

The first bug was that our rfcomm code would return DC_STATUS_SUCCESS
with a zero-sized read when a timeout happened, or when the rfcomm
socket had disconnected.  That makes absolutely no sense.  We should
return DC_STATUS_TIMEOUT on timeout, and DC_STATUS_IO if the socket has
disconnected without any data.

The fix to this is to make the whole rfcomm iostream read logic much
simpler: there's no need to loop at all for partial results, because the
libdivecomputer iostream side will do the loop for us (and handle
partial results much better: it knows if the target backend can handle
those partial results or not).

The second bug was in our libdivecomputer iostream read() function,
which reacted very badly to this bad return value.  This updates our
libdivecomputer branch to one that is more careful about things.

Reported-by: linuxcrash <albin@mrty.ch>
Debugged-by: Jef Driesen <jef@libdivecomputer.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-03-14 11:34:46 -07:00
Berthold Stoeger
7387b10b29 cleanup: remove current_dive parameter from divesSelected signal
The diveListNotifier.divesSelected() signal is used to inform the
models of a selection change. It sent the current dive as a second
parameter. This is redundant, because the only sender of the signal
sets current_dive just before sending the signal. Remove the
parameter, which appears to be an artifact.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-12 07:09:01 -07:00
Robert C. Helling
285fa8acbc Grammar: replaces 'indexes' by 'indices'
Grammar-nazi ran

git grep -l 'indexes' | xargs sed -i '' -e 's/indexes/indices/g'

to prevent future wincing when reading the source code.

Unfortunatly, Qt itself is infected as in
QModelIndexList QItemSelection::indexes() const

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2020-03-11 08:26:30 -07:00
Christof Arnosti
cb28158b9a Add timestamps to libdivecomputer.log
Since I learned while trying to implement this that getting sub-second
resolution time in portable C99 is hard (especially for someone who is
used to the comfort of std::chrono and Howard Hinnants date library) the
timer-implemetation from libdivecomputer is now copied to the subsurface
source.

Signed-off-by: Christof Arnosti <charno@charno.ch>
2020-03-10 17:42:54 -07:00
Dirk Hohndel
e766423300 Android: stop trying to list only FTDI based serial DCs
Thanks to the new USB serial implementation also that complex special-casing
is no longer needed. This should do the right thing now.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-10 13:27:43 -07:00
Dirk Hohndel
8ce4e10ccb cloud storage: add list of changes made to commit messages
This should make it easier to figure out what operations lead to the commit
that is written to git.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-10 09:25:57 -07:00
Dirk Hohndel
160d2ab071 core: make command texts available for C code
Create a C string (which the caller needs to free) with the executed commands
in this session.

The detour via the callback allows us to not make the corelib depend on the
commands, which is nice for tests, export-html, and smtk2ssrf.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-10 09:25:57 -07:00
Dirk Hohndel
0cd275af67 core/trip handling: add helper function to get trip from id
In the QML code we pass ids around. I had assumed that there already was a reverse
lookup function, but I wasn't able to find it. So I added it.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-10 09:25:57 -07:00
Berthold Stoeger
ef2f65fd27 mobile/filter: use signal to reload filter
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-10 09:25:57 -07:00
Berthold Stoeger
857e591a59 mobile: remove dive::collapsed
This was used by the old dive-list to mark collapsed entries.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-10 09:25:57 -07:00
Berthold Stoeger
b6f821886b mobile: unify download code on mobile and desktop
Use the undo-command for importing dives also on mobile. This should make the
whole disconnect-model shenigans unnecessary.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-10 09:25:57 -07:00
Berthold Stoeger
c8ec2f5b1c mobile: use undo-command to apply gps fixes
The goal is to send the signal for the correct dives / divesites
and thus not having to reload the whole model.

Right now the mobile UI does not yet catch the diveSiteChanged signals.

[Dirk Hohndel: small fix to ensure that we trigger a save to storage]

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-09 12:41:57 -07:00
Berthold Stoeger
89047b3541 GPS fixes: split collecting GPS fixes into own function
This finishes the spliting of the GPS fix application:
One function for collecting the fixes, one for application.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-09 12:41:57 -07:00
Berthold Stoeger
5808a57e48 cleanup: use QStringLiterals in core/gpslocation.cpp
Not that this would make any noticeable difference, but out of
principle, let's use Qt's string-literal macro for string-literals.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-09 12:41:57 -07:00
Berthold Stoeger
8f043138ba GPS fixes: collect fixes first, apply later
Make the application of the GPS fixes in two runs: first
collect dives and fixes, then apply the fixes. This will
simplify turning the application of GPS fixes into an
undo-command.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-09 12:41:57 -07:00
Dirk Hohndel
e5c62f0858 Android: don't list devices with unsupported transport
We know that we cannot support native USB, USB HID, IRDA, and USB
storage on Android.

On the flip side, don't try to force the long broken FTDI download.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-09 12:40:44 -07:00
Christof Arnosti
b15b9c6cd0 usb-serial-for-android: Implement timeout-handling
Since the Android USB stack and subsequently the usb-serial-for-android
driver have problems with read-timeouts, the read-timeout is now
implemented in AndroidSerial.java. Also, DC_STATUS_TIMEOUT is returned
if there are less bytes returned than expected.

Different chipsets seem to behave differently with
usb-serial-for-android. On CP210x the read blocks until there is some
data here, but on FTDI the chip seems to return whatever is currently in
the buffer (so 0 bytes if the buffer is empty). This different behaviour
should be mitigated by the changes by this commit.

Signed-off-by: Christof Arnosti <charno@charno.ch>
2020-03-08 11:22:55 -07:00
Christof Arnosti
6e38f85ba7 usb-serial-for-android: Implementation
Implement the libdivecomputer API in Java and create C/JNI translation
layer.

[Dirk Hohndel: whitespace harmonization - yes, some of this is Java,
               this still makes it much easier to read for me;
               also changed the FTDI conditional compilation to make
               sure we can still use that for mobile-on-desktop if
               necessary]

Signed-off-by: Christof Arnosti <charno@charno.ch>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-07 12:34:43 -08:00
Christof Arnosti
6ffb1e3129 serial-usb-for-android: Display all Serial computers
Signed-off-by: Christof Arnosti <charno@charno.ch>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-07 12:34:43 -08:00
Dirk Hohndel
97e26fd51b mobile: allow disabling BT support from the command line
This is a quick hack to reduce the noise in the log file when chasing other
bugs. Maybe this should not be enabled on release builds, but right now I don't
think the harm that having this in would do.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-06 10:00:13 +01:00
Berthold Stoeger
2a97934db4 Cleanup: Move stringToList to core/qthelper.cpp
The same code was used in desktop and undo commands. Let's unify.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-06 10:00:13 +01:00
Berthold Stoeger
62adc24d15 Core: don't return invalid cylinders from explicit_first_cylinder()
For reasons which I don't yet understand, when plotting a dive
whose first cylinder is not cylinder 0 and then plotting a dive
with only one cylinder, it can happen that for the latter
explicit_first_cylinder() returns an erroneous value.

This is due to the way in which we copy the dive to be plotted
to displayed_dive.

For now, make sure that no invalid cylinder is returned to avoid
crashes. This will have to be changed anyway, since this is very
fundamentally not thread-safe and inefficient.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-06 10:00:13 +01:00
Berthold Stoeger
8a0eecfd5e cleanup: make version_printed variable static and local to function
The version_printed variable is used to print version information
only once. It was a global variable, but never used outside of
its function. Therefore, move it into the function and make it
static. Since this is a plain old datatype (POD), it makes no
no difference whatsoever whether the static variable is in block
scope or not. Indeed, it is initialized in the data segment). Well,
we are in C mode and therefore everything has to be POD by definition.
I tested this on gcc and clang.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-05 11:07:32 +01:00
Berthold Stoeger
4cff23ef7a mobile: remove filter settings
These are not used anymore.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-01 10:21:44 -08:00
Berthold Stoeger
c1e33aac21 filter: implement searching for tags and people in mobile filter
Implement tag- and people-filtering in the mobile version of
DiveFilter. As opposed to the desktop version, this has no
different modes: it always searches "startswith" and "all of".
I.e. all of the search strings must match and a tag / person
is considered as matching if it starts with the search term.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-01 10:21:44 -08:00
Berthold Stoeger
f3a3d93b85 filter: remove diveContainsText()
This function checked a dive for a search string. Its functionality
was replaced by a fulltext index.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-01 10:21:44 -08:00
Berthold Stoeger
fd7dd5421b filter: implement full-text filtering in mobile version of DiveFilter
In analogy to the desktop version, use the fulltext index in
DiveFilter. This code is not yet executed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-01 10:21:44 -08:00
Berthold Stoeger
e754b2df84 filter: remove DiveFilter::updateDiveStatus from class
This function did not access any class members and was not used
outside the tranlation unit. Let's make it local (i.e. static)
to the translation unit.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-01 10:21:44 -08:00
Berthold Stoeger
5bbc0fdb58 filter: compile fulltext index on mobile
The code is not used yet.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-01 10:21:44 -08:00
Berthold Stoeger
2bd4c6f6ec filter: connect fulltext filter to frontend
There are now three filter modes:
1) Dive site
2) Fulltext
3) Normal

When doing a fulltext search, get the dives that match the
fulltext filter and then apply the other filters on that list.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-01 10:21:44 -08:00
Berthold Stoeger
d3f6e032cc filter: index/unindex dives on loading or clearing logs
When loading dive data, populate the fulltext index. When clearing
dive data, free the fulltext index. When deleting a dive, remove it
from the fulltext index.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-01 10:21:44 -08:00
Berthold Stoeger
6434ad2628 filter: add fulltext filtering code
Add code that indexes all words of a dive and provides searching
for words.

A query is represented by the FullTextQuery class, which can be
initialized by assigning a string to it. It is basically a list
of words.

The result of a search is stored in the FullTextResult class,
which is a list of dives.

The actual indexing and searching is implemented in the FullText
class. However, this class is not exported because the interface
is partially accessible to C. Notably, the reloading of the
fulltext index is done from the C core.

Currently, the indexing and searching is totally unoptimized.
In a ~4000 dives test-log searches typically took single-digit
ms times. There is ample room for optimization (e.g. when
searching for multiple words, chose the words with few dives
first and when down to a few dives, check them individually).

The words of each dive are tokenized and uppercased and
cached with the dive. A pointer to these words is stashed
in the dive structure.

For now, compile only on desktop.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-01 10:21:44 -08:00
Berthold Stoeger
41aae1aebe filter: move StringMode out of FilterData
The FilterData struct has the enum StringMode, which describes how
strings are searched (substring, startswith, exact). To make it
more generally accessible, remove it from the class. Since it is
an "enum class", the values don't pollute the global namespace anyway.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-01 10:21:44 -08:00
Berthold Stoeger
ee553e059d Filter: move actual filtering loop to core/divefilter.cpp
The DiveFilter class defined the showDive() function to test
whether a dive should be filtered or not. This was used in
DiveTripModel to loop over all dives or all dives affected by
an editing action.

This restricts us in how we do filtering: We can't use indexes
that give us directly the result. To make the filtering more
flexible, move the actual loops that do the filtering to
the DiveFilter class.

The undo-commands likewise called directly the showDive()
function to check whether newly added dives are shown.
Use the new interface here as well.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-02-22 15:18:31 -08:00
Dirk Hohndel
24543a0099 core: fix incorrect changes in divelogs.de export
This is complete nonsense and should never have been merged.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-02-17 10:50:51 -08:00
Linus Torvalds
6df46a25a3 Add Cressi BLE name filtering for bluetooth discovery
.. and update the libdivecomputer submodule to have them marked as BLE
capable.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-02-16 12:52:56 -08:00
Linus Torvalds
66a2b2e133 load-git: fix up any corrupted modechange event names
Because of the multiple string confusion, we'd get the names wrong for
modechange events.  If we then made other changes to the dive and saved
the end result back, they'd now be wrong in the git cloud storage too.

Fix it up manually by just noticing that there's a 'divemode' string on
the event line, which can only happen with modechange events.

Maybe we should report the fixup? This just silently fixes it (but only
for the git save format).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-02-15 10:12:35 +01:00
Linus Torvalds
a9112e6e05 load-git: clean up string handling during parsing
We had some fairly obscure rules for how strings were parsed, and it
actually caused bugs when the same line had multiple strings in it.

That normally doesn't happen, and the cases where it was _supposed_ to
happen had special cases for it (divecomputer ID lines, and tag lines).

But by mistake, we had introduced a case of that for the event line
handling in commit b9174332d ("Read and write divemode changes (xml and
git)"), and nobody realized that the divemode string addition meant that
"oops, now it's corrupting the event name".  An event line could look
like this:

     event 40:00 type=8 divemode="OC" name="modechange"

where we now had both that "OC" and "modechange" strings, and the code
to pick the name just picked the first string.  So we'd end up
effectively mis-parsing the above line as

     event 40:00 type=8 divemode="OC" name="OC"

which is obviously wrong.

The dive mode didn't really need to be a string in the first place
(there is nothing to quote, and no spaces in it), but hey, here we are.
We can't just magially fix the existing broken saves.

So make it more straightforward to handle strings in the git format line
parser.  We still stash the different decoded strings together in one
special memory buffer, but now the parser helpers automatically untangle
it as they traverse the key value pairs.

This is still overly subtle code, and it doesn't fix the cases where
we've saved the wrong data back. That comes later.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-02-15 10:12:35 +01:00
Dirk Hohndel
9245962d3d mobile/gps: make sure updated GPS data are saved
If we change the gps location of a dive that didn't have a dive site associated
before (which is the normal case when a dive was just downloaded from a dive
computer), a new dive site is created with that GPS fix and added to the dive.
We need to mark that dive as changed in order for the changes to be saved to
storage.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-02-13 14:01:57 -08:00
Berthold Stoeger
a07d8cf5ea Filter: implement starts-with and exact modes
Currently, we do substring search. Implement starts-with and
exact mode (for example when search for "Cave vs. Cavern" tags).
For each textual search criterion add a combo-box.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-02-11 20:29:05 -08:00
Jason Bramwell
caabf1b888 Correcting typos of the word celsius
Corrected typo of the word celsius in three files:
core/import-csv.c
core/divefileter.h
mobile-widgets/qml/Settings.qml

These were spelled as celcius but corrected these to celsius.
The 'core files were just comments but the mobile-widgets file would be
'active' code.

Reported by: tormento <turment@gmail.com>
Signed-off-by: Jason Bramwell <jb2cool@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-02-09 12:45:55 -08:00
Berthold Stoeger
8391d926c7 Cleanup: remove const bool parameters and return types
These just make no sense. Since the value is copied, it
has no meaning to the caller whether the function can
change the value (and vice versa for return types).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-02-09 12:13:18 -08:00
Berthold Stoeger
1f03a8be81 Cleanup: remove erroneous comments
Remove two erroneous comments stating that a function-local
QSettings variable should not be static because it is initialized
too early. Scoped static variables are initialized when execution
first hits the statement.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-02-08 14:00:44 -08:00
Dirk Hohndel
9069f3364d core/settings: add new preference to limit number of columns on mobile
The idea is that in portrait mode we can force the display to be single column (which
makes sure that the profile in dive display mode is nice and big).

This commit only implements the preference variable that we need for that.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-02-08 13:58:54 -08:00
Berthold Stoeger
f7c73f1987 mobile/summary: implement firstDiveDate and lastDiveDate
Instead of transporting the global first and last dive date
in the dive summary, calculate it in an external function.
Since we already have time and date functions in qthelper.cpp
implement those functions there. Provide a stub in QMLInterface
so that QML can access these standalone functions.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-02-08 10:29:36 -08:00
Berthold Stoeger
cf1e3524a1 Gps coordinates: be more graceful when parsing coordinates
Some Wikipedia pages use special (non-ASCII) unicode symbols for
representing the " and ' separators. Before parsing, replace these
by the ASCII symbols to enable copy & paste from Wikipedia (and
other sources?).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-02-06 08:50:22 -08:00
Berthold Stoeger
e5487f86a6 Coding style: remove braces around single-line if blocks
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-02-06 08:50:22 -08:00
Berthold Stoeger
1bebf55737 Coding style: move & from type to variable
Trivial white-space cleanup according to coding style document.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-02-06 08:50:22 -08:00
Miika Turkia
90b0e38ed8 CSV import: fix importing ampersand character
As we do XSLT parsing for the CSV import, ampersand characters need to
be encoded with &amp; for the parsing to succeed.

Fixes #2037

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2020-02-06 08:46:52 -08:00