Commit graph

17892 commits

Author SHA1 Message Date
Berthold Stoeger
f4ee893424 cleanup: replace get_trip_date_string() by get_trip_string()
The get_trip_date_string() formatted, as the name implies, the date
of a trip. It was passed a number of parameters and had only one
caller, which would also add the location if it existed.
Therefore, move all that logic into the helper function and
name it get_trip_string().

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-03 10:01:13 -07:00
Berthold Stoeger
06c35026d6 desktop: fix paging through dive list with page-up key, etc
In the dive list we have horrible code, which intercepts all events
to save the selection before/after the event. This was necessary
because we couldn't get Qt's selection data flow under control.

This means intercepting all events that can change the selection.
The page-up, page-down, home and end keys were forgotten. Add these
cases.

Fixes #2957.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-02 11:10:28 -07:00
Linus Torvalds
d8f35711ff membuffer: be defensive about bad C library vsnprintf implementations
Dirk reports that some Windows users have had odd corruption in the
commit messages in the cloud storage.  They make no sense at all unless
there is some very weird Windows library bug.

The prime suspect is 'vsnprintf()' returning a negative error when the
target buffer is too small (rather than the proper "this is how much
space it would need").  That is a very traditional C library bug that I
thougth had been fixed everywhere, but there doesn't really seem to be a
lot of other likely causes.

So let's make our membuffer code be defensive against bad libraries that
return negative error numbers from vsnprintf.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-10-01 13:43:21 -07:00
Linus Torvalds
5f79ceef5e Update libdivecomputer to fix Garmin GPS recording
The Garmin Descent parser had a bug that would re-use possibly stale GPS
locations between dives (and in theory other data fields too, although
in practice I think only GPS data was ever leaked between dives).

This updates libdivecomputer to a fixed version.

Reported-by: @brysconsulting
Link: https://github.com/subsurface/subsurface/issues/2980
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-09-30 22:08:03 -07:00
Dirk Hohndel
4608beaee4 Android BLE discovery: use discovery agent
Android can't scan for classic BT devices, so when BT support was first
added, we simply didn't use the discovery agent at all and relied on the
list of paired BT devices provided by Android.

This still worked fine for a lot of BLE devices that allowed 'bonding'
with the Android device - similar to pairing. But some BLE devices (like
the Shearwater Peregrine) don't support bonding and so our Android code
didn't see them at all.

With this commit we start a BLE only scan on Android to add to the list
of already paired devices.

Fixes: #2974

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-09-30 16:40:41 -07:00
Dirk Hohndel
5b48585092 bluetooth discovery: report more information about progress
We certainly should log errors and the complete list of discovered
devices.

Also, it's good practice to set a specific search time (I picked three
minutes). This way we won't constantly scan and drain resources.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-09-30 16:40:41 -07:00
Dirk Hohndel
ca23147228 bluetooth discovery: differentiate discovered and paired devices
We call the same helper from two spots. Once when we report the already
paired BT devices on Android, and once from the deviceDescovered signal
for the discovery agent. Let's make sure we can tell where the info came
from.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-09-30 16:40:41 -07:00
Dirk Hohndel
3a9d895ccf documentation: release tasks
I think I'm the only one using this list, but it makes sense to
have it in the repo

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-09-30 16:40:41 -07:00
Berthold Stoeger
7337ff386b cleanup: rename FilterWidget2 to FilterWidget
The name "FilterWidget2" is historical and has no meaning anymore,
since the current version has little to nothing to do with the
"second" version of the widget.

Rename the class and source files accordingly.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-29 16:14:31 -07:00
Berthold Stoeger
068194b2e5 CHANGELOG.md update concerning new filter system
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-29 16:14:31 -07:00
Berthold Stoeger
76cf251e59 filter: avoid unnecessary filter recalculations when loading set
When loading a stored filter set, we would get numerous
constraintChanged signals, which caused filter recalculations.
Use the ignoreSignal flag to prevent these.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-29 16:13:03 -07:00
Berthold Stoeger
cd27e36b8f filter: add modified flag
When editing the filter, the modified flag is set and shown to the
user. After saving / loading / clearing the filter, the flag is
reset. This simulates (probably badly) a usual load/save interface.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-29 16:13:03 -07:00
Berthold Stoeger
1ed61aeabf filter: show currently selected preset in a text field
This provides some visual feedback on the currently selected preset.
Update when changing selection or clearing the filter.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-29 16:13:03 -07:00
Berthold Stoeger
e1c44a0a4d filter: save timestamps in user-readable format
So far we saved timestamps by their 64-bit value as decimal strings.
Change this to a user readable format. The parsing routine still
supports decimal numbers.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-29 16:13:03 -07:00
Berthold Stoeger
cccd242a36 filter: when clearing the filter unselect the current filter preset
It makes no sense to have the a filter preset selected after
clearing the filter.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-29 16:13:03 -07:00
Berthold Stoeger
d064f78608 filter: when a filter preset is selected, suggest its name on save
The goal here is to let the user edit already existing sets and
save them using their old name. This is a stop-gap measure until
we get a proper filter-set editing interface.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-29 16:13:03 -07:00
Berthold Stoeger
8f898477cb core: add helper functions to format / parse timestamps
To save datetime-based filter constraints to git or XML,
it is preferrable to use human-readable representations.
Therefore, add helper functions to format / parse timestamp_t
64-bit values in the "YYYY-MM-DD hh:mm:ss" format.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-29 16:13:03 -07:00
Berthold Stoeger
f9721fce4b filter: implement importing of filter presets
When importing a divelog, import filter presets. If there are
equal names, import only if the presets differ. In that case,
disambiguate the name. This made things a bit more complicated,
as comparison of filter presets had to be implemented.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-29 16:13:03 -07:00
Berthold Stoeger
631be569fe cleanup: forward declare QHideEvent and QShowEvent
Don't include the respective header files in filterwidget2.h

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-29 16:13:03 -07:00
Berthold Stoeger
38b686687f cleanup: move shown-text calculation from filter widget to core
The filter widget was caching whether the filter was active and
used that flag to calculate the "# dives shown" string. Move this
directly to the DiveFilter class to remove interdependencies and
to unify with mobile.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-29 16:13:03 -07:00
Berthold Stoeger
68fffc2672 filter: add completer for save-filter-preset dialog
Thus, the user can easily overwrite already existing settings.
Not perfect, but the easy solution for now.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-29 16:13:03 -07:00
Berthold Stoeger
1fcf4f891d filter: implement loading of filter presets from git repositories
This is mostly copy and paste of other git loading code. Sadly,
it adds a lot of state to the parser-state. I wish we could pass
different parser states to the parser_* functions.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-29 16:13:03 -07:00
Berthold Stoeger
3bfd448b59 filter: implement saving of filter presets to git repositories
On the mailing list it was decided that users might want to
move their filter presets across computers via the cloud.
Notably, in the future one might access statistics on mobile and
these might by controlled by filter presets.

The git save routines use the same string formatting as the
XML save routines. The string formatting is found in
core/filterconstraint.cpp. Thus, duplication of code and
inconsistencies should be minimized.

Each filter preset is saved into a file in the "02-Filterpresets"
folder in the root of the git repository.

Each file consists of one "name" line, zero or one "fulltext" line
and zero or more "constraint" lines.

The modes, types and the actual payload is controlled via attributes.
Thus, a preset file might look like this:

name "test"
fulltext mode="substring" query="clown"
constraint type="location" stringmode="starstwith" data="mafia"
constraint type="sac" rangemode="range" negate data="5000,10000"

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-29 16:13:03 -07:00
Berthold Stoeger
41cf83583d filter: load filter presets from XML files
This is a bit painful: since we don't want to modify the filter
presets when the user imports (as opposed to opens) a log,
we have to provide a table where the parser stores the presets.
Calling the parser is getting quite unwieldy, since many tables
are passed. We probably should introduce a structure representing
a full log-book at one point, which collects all the things that
are saved to the log.

Apart from that, this is simply the counterpart to saving to XML.
The interpretation of the string data is performed by core
functions, not the parser itself to avoid code duplication with
the git parser.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-29 16:13:03 -07:00
Berthold Stoeger
cef15c978d cleanup: move function declarations from dive.h to parse.h
The parse_* functions should probably be declared in parse.h.
Arguably, parse_xml_init() and parse_xml_exit() should be moved
to an init.h file, however that doesn't yet exist.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-29 16:13:03 -07:00
Berthold Stoeger
4a78f5798a includes: move declaration of set_filename() from dive.h to qthelper.h
Declare the function in the header file corresponding to the source
file where the function is defined.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-29 16:13:03 -07:00
Berthold Stoeger
448bc5600b filter: implement saving of presets to XML file
Users might want to move their presets with there log-file. Therefore,
save the presets to the log. The alternative would be to save them
to the preferences. However, on the mailinglist it was decided that
moving the presets to a mobile device is a wanted feature.

The XML saving code has a rather reasonable interface, therefore
this turned out to be pretty easy to implement.

The filter presets are saved into a
<filterpresets>
 ...
</filterpresets>
block

Each individual preset is saved into a
 <filterpreset name='...'>
    ...
 </filterpreset>
Block with a unique name attribute.

Each preset contains zero or one fulltext and zero or more constraint entries.
The type and mode(s) are controlled by attributes, the "payload" is saved in
the block. Note that all the formatting is done by functions in core/filterconstraint.c
and not the parser itself.

A preset in the XML file might look like this:

 <filterpreset name='test1'>
  <fulltext mode='startswith'>Train</fulltext>
  <constraint type='planned'>0,0</constraint>
  <constraint type='sac' range_mode='range' negate='1'>5000,10000</constraint>
 </filterpreset>

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-29 16:13:03 -07:00
Berthold Stoeger
142f76374c filter: add filter preset table
Add a table view that shows all presets and a button to delete
old presets. When clicking on an item, load the preset.
When the filter is reset, deselect any item.

Change the preset-loading code: instead of simply loading the
preset, select the preset in the table. Thus, it will be loaded
implicitly.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-29 16:13:03 -07:00
Berthold Stoeger
c6bd2a7ffb filter: connect load filter preset functionality to ui
Add a button to the filter preset widget that allows the
user to load a previously saved filter preset.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-29 16:13:03 -07:00
Berthold Stoeger
51959d0feb filter: connect DiveListNotifier signals to filter preset model
Thus, the model is kept up to date if filter presets are changed
by undo commands.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-29 16:13:03 -07:00
Berthold Stoeger
581eb1f563 filter: create a primitive "create filter preset" dialog
The dialog asks the user for a name and warns if the name
already exists, i.e. an old filter preset will be overwritten.
Possibly, this should contain an auto-completion facility in
the case that the user wants to overwrite old presets.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-29 16:13:03 -07:00
Berthold Stoeger
2f5223035a filter: add filter preset undo commands
Add undo commands to add / edit / delete filter presets.
These are styled after the other undo commands: On changes,
the UI is informed by DiveListNotifier signals. Editing is
a simple std::swap of values.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-29 16:13:03 -07:00
Berthold Stoeger
536fc05dd6 filter: add (very primitive) filterpresetmodel
Implement a trivial model to provide the filter preset names
to the UI. Sadly, for now this features the QWidget/QML
column / name dichotomy. However, in this simple case that
shouldn't be too much of an issue.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-29 16:13:03 -07:00
Berthold Stoeger
937fdb500b filter: add primitive filter presets
Add a rudimentary list of filter presets to the core. The list
is sorted by name. Access is provided via a C interface so that
the presets can be written to the git and XML logs. Internally,
the list is realized by a C++ vector for convenience (euphemism for
laziness).

Morover, a C++ interface is provided for the UI. Currently names of
the presets cannot be edited, since this would mean that the order
of the list changes. This may be implemented later if required.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-29 16:13:03 -07:00
Berthold Stoeger
634e26cbce filter: unify desktop and mobile filters
Switch the mobile code to use the constraint-based filter. The one
thing that is still commented out is dive-site mode, since mobile
doesn't (yet) have a dive-site edit feature. And even if it had,
the dive list probably wouldn't be shown at the same time.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-29 16:13:03 -07:00
Berthold Stoeger
6c443ba841 filter: connect new filtercode to filterwidget2
Replace the static filterwidget with a list of filterconstraints.
The first attempt of using a table widget failed, because Qt's
table delegates are dysfunctional. It's not that they are bad, they
just don't work at all.

Therefore, this code "simulates" a table in that on addition / deletion
of constraints it keeps track of the rows of all constraints so
that each constraint-widget can be associated with a row of the
constraint model.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-29 16:13:03 -07:00
Berthold Stoeger
c0af74ba88 filter: add a filter constraint widget
This add a widget that represents a single filter constraint. Since
filter constraints are very general, the widget has to consider a
number of cases:
- numerical ranges
- star-widget ranges
- string lists
- multiple choice lists
Moreover, it supports units, which must be updated when the preferences
change.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-29 16:13:03 -07:00
Berthold Stoeger
af9d379a41 filter: add filter constraint model
Add a model that keeps track of a list of filter constraint and makes
them accessible from Qt. Sadly, this is mostly repetitive boiler-plate
code, but this is due to Qt's model/view-API, which is a perfect example
of how *not* to design a reasonable modern API.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-29 16:13:03 -07:00
Berthold Stoeger
634152ae43 filter: add filter constraint object to the core
Adds a filter constraint object to the core, which represents one
constraint the user can filter dives with. The plan is to write these
constraints to the XML and git logs. Therefore, this code is written
in C-style except when it comes to handling strings and dates, which
is just too painful in plain C.

There is one pointer to QStringList in the class, though when compiled
with C, this is simply transformed into a pointer to void. Granted,
that smells of an ugly hack. However it's more pragmatic than
self-flaggelation with C string and list handling.

A filter constraint is supposed to be a very general thing, which can
filter for strings, multiple-choice lists, numerical ranges and date
ranges.

Range constraints have a range mode: less-or-equal, greater-or-equal
or in-range. Text constraints have a string mode: startswith, substring
or exact.

All the data are accessed via setter and getter functions for
at least basic levels of isolation, despite being written with
a C-interface in mind.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-29 16:13:03 -07:00
Berthold Stoeger
0b7ba19775 fulltext: remember original query
So far, the fulltext-query structure only saves an canonicalized
upper-cased version of the query. However, if we want to save the
fulltext query to the log (filter presets) or want to restore an old
fulltext query, we have to store the original query. We don't want
to confront the user with the mangled upper-cased version.
Therefore, also save the original version.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-29 16:13:03 -07:00
Berthold Stoeger
0f4154bacc core: add functions to core/time.c
To support the new filter code, add helper functions that turn timestamps
into year and day-of-week to core/time.c.

Internally, these functions simply call utc_mktime() to break down the
timestamp and then extract the wanted value. This may appear inefficient,
but testing shows that modern compilers are quite effective in throwing
away the unneeded calculations. FWIW in this respect clang10 outperformed
gcc10.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-29 16:13:03 -07:00
Robert C. Helling
efdc875aa3 Use correct pO2 when computing MOD in equipment tab
The cylinder model is used both in the planner and the
equipment tab. We have three preferences for the pO2 that
is used to compute MOD: In the planner, there is one for
the bottom part of the dive and another one for deco.
Those are set in the planenr UI. There is another value,
controlled in the Tec Prefernces. That one should be
used in the equipment tab rather than the one from
the planner.

Fixes #2984

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2020-09-29 15:46:55 -07:00
Linus Torvalds
a7ca27d071 Prefer "GPS1" for divecomputer download dive site resolution
I think we only have one dive computer that supports GPS data right now:
the Garmin Descent Mk1.  It reports the dive coordinates as "GPS1" and
"GPS2" for the entry point and exit point respectively.

Often GPS1 is missing, because the dive computer may not have gotten a
GPS lock before the diver jumped into the water, so when that happens
we'll use GPS2 for the dive site location.  But when GPS1 exists, we
should prefer that.

And that's what we already did in logic in dc_get_gps_location(), but
for the initial dive site created at download time, we just picked any
divecomputer reported string that started with "GPS".  And since GPS2 is
reported after GPS1 by the Garmin Descent, it would end up overwriting
the entry point that we _should_ have preferred.

Add the same kind of "explicitly prefer GPS1" logic to the initial dive
download case as we already had elsewhere.

Reported-by: @brysconsulting
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-09-29 14:35:57 -07:00
Berthold Stoeger
eb22c0205e cleanup: remove unnecessary includes in divelistview.cpp
Most of these became unnecessary when including media in the
undo system.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-29 14:12:56 -07:00
Jason Bramwell
5c7a0027db Update INSTALL to correct PCLinuxOS packagelist
PCLinuxOS package list was stale, it contained a typo and also had missing
packages.

Signed-off-by: Jason Bramwell <jb2cool@gmail.com>
2020-09-29 11:54:59 -07:00
Dirk Hohndel
7547e90b41 gps: remove unused member function
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-09-29 16:25:44 +02:00
Dirk Hohndel
2a3a58a3c7 build-system: update OBS spec file
Just trying to keep things in sync with what we actually use in the automated
builds.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-09-28 11:19:21 -07:00
Dirk Hohndel
63cc2d864f build-system: document how to create a Windows installer
These are the instructions that I use at this point.

Removed a long obsolete script - it's been many, many years since that last was
useful (it was still using qmake to try to build Subsurface)

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-09-28 10:38:08 -07:00
Dirk Hohndel
6835f03bae mobile: update version to 3.0.16
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-09-28 10:24:08 -07:00
Dirk Hohndel
a469dfa348 mobile/dive-list: correctly update view when changing dive date
If the dive timestamp changes, the dive could move in the dive list. But the
current dive actually doesn't change (it's still the same dive, right?). Yet
we need to update the dive list as well as the shown dive (especially if this
is after adding a dive, which is first inserted with the current time and then
updated with whatever the user enters).

Fixes: #2971

Suggested-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-09-27 14:16:18 -07:00