Commit graph

1501 commits

Author SHA1 Message Date
Berthold Stoeger
5d3967ce84 Dive site: un-globalize displayed_dive_site
The global object displayed_dive_site is used a a backing-store
by the dive-site-edit widget. All external accesses were removed,
therefore make the object local to the widget.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-13 21:41:41 -04:00
Berthold Stoeger
954820aa81 Dive site: explicitly init displayed_dive_site on show widget
The global object "displayed_dive_site" is used to store the
old dive site data for the edit-dive-site widget. The fields
of the widget were initialized from this object in the show
event. Therefore the object was updated in numerous parts of
the code to make sure that it was up-to-date. Instead, move
the initialization of the object to the function that also
initiatlizes the fields. Call this function explicitly before
showing the widget.

This makes the data-fow distinctly easier to understand.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-13 21:41:41 -04:00
Dirk Hohndel
7697003498 core: recognize Aqualung i770R over BLE
The name seems crazy until you realize that FQ is 0x4651 which is the model
number of the i770R. And the six digits are the serial number of the device.
Still crazy, but at least now you understand WHY.

Thanks to Jef for decoding that.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-10-12 10:10:06 -07:00
Dirk Hohndel
c8fec97695 Bluetooth: add helper to separate BT name and address
And restructure the existing "isBtAddress()" function in the process.
Also add more tests.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-10-12 08:22:44 -07:00
Dirk Hohndel
7512a6e915 Bluetooth: restart scan for different device on macOS
This makes no sense, but apparently we need to start a fresh scan in order to be able
to talk to a different BLE dive computer on the Mac.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-10-12 08:22:44 -07:00
Dirk Hohndel
497c1248d4 Bluetooth: wait until we actually have device info
On macOS, we cannot connect to a BT/BLE device until we have scanned it. Right
now this just sits quietly and waits, which given how long this can take is
rather unsatisfying and might look like Subsurface is hung.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-10-12 08:22:44 -07:00
Dirk Hohndel
9491c96103 Bluetooth: start discovery if address isn't already known
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-10-12 08:22:44 -07:00
Dirk Hohndel
2954bc5f22 Bluetooth: move declaration and make variable file scoped
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-10-12 08:22:44 -07:00
Dirk Hohndel
a5416b9bea Bluetooth: remember all data during a scan on macOS
Since we trigger a scan even without the dialog to pick the right
device, we need to remember all devices that we find.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-10-12 08:22:44 -07:00
Dirk Hohndel
2ba3eab319 Bluetooth: discovery should always scan on macOS as well
Instead of only starting the scan when explicitly asked to do so in the BT
dialog, create the discovery agent when the download dialog opens, since on
macOS we cannot connect to a device without having scanned for it first.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-10-12 08:22:44 -07:00
Dirk Hohndel
0cfd76740b core: helper function to recognize BT/BLE addresses
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-10-12 08:22:44 -07:00
Berthold Stoeger
ad57871a2c Geo lookup: don't pass arguments / result via global object
The reverseGeoLookup() fetches dive-site data via GPS coordinates.
The coordinates and the result were passed via the global
"displayed_dive_site" object. To make data-flow more clear,
pass data as in and out parameters instead.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:25:02 -07:00
Berthold Stoeger
04ad9c885d Geo lookup: make the reply a managed-pointer
By making reply a std::unique_ptr<>, the function can be quit
from any point and the reply will be freed. This is valid according
to Qt's documentation as we're not deleting during signal processing.

This commit fixes a leak: reply was overwritten with the address of
a new object without freeing the old object.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:25:02 -07:00
Berthold Stoeger
cb2f09a8e3 Geo lookup: make the QNetworkAccessManager a static object
According to Qt's docs, the QNetworkAccessManager is supposed
to be a long-living object. Therefore, don't create one on
every geo-lookup, but a single object for all geo-lookups.

By making the object function-local it is only initiaized
on first use. Morover this limits the amount of concurrent
geo lookups.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:25:02 -07:00
Berthold Stoeger
ce8199cdfd Cleanup: remove ReverseGeoLookupThread
Fetching the taxonomy from GPS coordinates was implemented in
a QThread. But the only access to the main function was a
direct call to run(). Thus, the thread was *never* started.
The function call was always asynchronous [it was using an
event loop though, so the UI doesn't hang]. Notably this
means that the signals connected to the thread would never
fire. And the spinner would never be activated.

Thus:
1) Turn the thread into a simple function.
2) Remove the spinner.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:25:02 -07:00
Berthold Stoeger
f836b9ae97 Dive list: unify sorting in core and Qt-model
Ultimately, we want to use a single dive-list and not replicate
it in the Qt-model code. To this goal, let's start with using
the same sort function.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:22:27 -07:00
Berthold Stoeger
8c2383b495 Undo: don't modify source-dives on merge
For undo, it is crucial that commands don't modify existing dives.
Unfortunately, dive merging would write into the data-structures
of the to-be-merged dives. To prevent it from doing so, make the
input dives const-pointers.

This led to a whole cascade of functions that had to take const
and significant churn.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:22:27 -07:00
Berthold Stoeger
7067e33596 Undo: select dives after add, remove, merge, split dive commands
Select the proper dives after the add, remove, split and merge
dives commands on undo *and* redo. Generally, select the added
dives. For undo of add, remember the pre-addition selection.
For redo of remove, select the closest dive to the first removed
dive.

The biggest part of the commit is the signal-interface between
the dive commands and the dive-list model and dive-list view.
This is done in two steps:
1) To the DiveTripModel in batches of trips. The dive trip model
   transforms the dives into indices.
2) To the DiveListView. The DiveListView has to translate the
   DiveTripModel indexes to actual indexes via its QSortFilterProxy-
   model.

For code-reuse, derive all divelist-changing commands from a new base-class,
which has a flag that describes whether the divelist changed. The helper
functions which add and remove dives are made members of the base class and
set the flag is a selected dive is added or removed.

To properly detect when the current dive was deleted it
became necessary to turn the current dive from an index
to a pointer, because indices are not stable.

Unfortunately, in some cases an index was expected and these
places now have to transform the dive into an index. These
should be converted in due course.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:22:27 -07:00
Berthold Stoeger
23db0ba68d Dive list view: replace signal-magic by flag
In DiveListView, we have a very fundamental problem: When
On the one hand, we get informed of user-selection in the
DiveListView::selectionChanged() slot. This has to set the
correct flags in the C-backend.

On the other hand, sometimes we have to set the selection
programatically, e.g. when selecting a trip. This is done
by calling QItemSelectionModel::select().

But: this will *also* call into the above slot, in which
we can't tell whether it was a user interaction or an
internal call. This can lead to either infinite loops or
very inefficient behavior, because the current dive
is set numerous times.

The current code is aware of that and disconnects the
corresponding signal. This is scary, as these signals are
set internally by the model and view. Replace this
by a global "command executing" flag in DiveListNotifier.
The flag is set using a "marker" class, which resets the flag
once it goes out of scope (cf. RAII pattern).

In DiveListView, only process a selection if the flag is not
set. Otherwise simply call the QTreeView base class, to reflect
the new selection in the UI.

To have a common point for notifications of selection changes,
add such a signal to DiveListNotifier. This signal will be
used by the DiveListView as well as the Command-objects.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:22:27 -07:00
Berthold Stoeger
0d98da5261 Dive list: remember selected dives
Don't delesect dives, when unregistering them from the backend.
If a previously selected dive is added, select it in the dive-list.
For this purpose introduce a SELECTED_ROLE to query the DiveTripModel
for selected dives.

Unfortunately, when adding multiple selected dives, current_dive_changed
is called for each of them, making this very slow. This will have
to be fixed in subsequent commits.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:22:27 -07:00
Berthold Stoeger
63b65a7e20 Undo: implement autogrouping of trips in DiveAdd
If the autogroup flag is set, search for appropriate trips in
DiveAdd() and add the dive to this trip. If no trip exists, add
a new trip.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:22:27 -07:00
Berthold Stoeger
ec7d85835f Dive list: implement proper Qt-model semantics for DiveTripModel
Previously, each dive-list modifying function would lead to a
full model reset. Instead, implement proper Qt-model semantics
using beginInsertRows()/endInsertRows(), beginRemoveRows()/
endRemoveRows(), dataChange().

To do so, a DiveListNotifer singleton is generatated, which
broadcasts all changes to the dive-list. Signals are sent by
the commands and received by the DiveTripModel. Signals are
batched by dive-trip. This seems to be an adequate compromise
for the two kinds of list-views (tree and list). In the common
usecase mostly dives of a single trip are affected.

Thus, batching of dives is performed in two positions:
- At command-level to batch by trip
- In DiveTripModel to feed batches of contiguous elements
  to Qt's begin*/end*-functions.

This is conceptually simple, but rather complex code. To avoid
repetition of complex loops, the batching is implemented in
templated-functions, which are passed lambda-functions, which
are called for each batch.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:22:27 -07:00
Berthold Stoeger
6ac4ddbeed Core: introduce insert_trip_dont_merge() function
insert_trip() adds a trip to the backend, but merges trips if
there exists a trip with the same date. This is a disaster
for the MergeTrips command, because this command adds a new
trip and removes the previous two. Of course if the added trip
is merged, this cannot work.

Therefore, add an insert_trip_dont_merge() function, which
adds the trip, but doesn't merge.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:22:27 -07:00
Berthold Stoeger
f427226b3b Undo: make diverse trip-related operations undo-able
AddDivesToTrip, CreateTrip, AutogroupDives, RemoveAutogenTrips
and MergeTrips basically all did the same thing as RemoveDivesFromTrip,
which was already implemented. Thus, factor our the common functionality
and hook it up to make all these functions undo-able.

Don't do the autogroup-call everytime the dive-list is rebuilt
(that would create innumberable undo-actions), but only on dive-load /
import or if expressly asked by the user [by switching the autogroup
flag].

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:22:27 -07:00
Berthold Stoeger
014c04f8bd Undo: implement rudimentary support for undo of dive-merging
For this, an output-parameter was added to the backend merge_dives()
function. When non-zero, instead of adding the merged dive to
the preferred trip, the preferred trip is returned to the caller.

Since the new UndoObject, just like the delete-dives UndoObject,
needs to remove/readd a set of dives, the corresponding functionality
was split-off in a helper function.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:22:27 -07:00
Berthold Stoeger
302f6adb79 Undo: implement rudimentary support for undo of dive-splitting
For this, the core functionality of the split_dive() and
split_dive_at_time() functions were split out into new
split_dive_dont_insert() and split_dive_at_time_dont_insert(),
which do not add the new dives to the log. Thus, the undo-command
can take ownership of these dives, without having to remove them
first.

The split-dive functionality is temporarily made desktop-only
until mobile also supports "UndoObjects".

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:22:27 -07:00
Berthold Stoeger
12df9faaa2 Undo: implement undo of manual dive-creation
Play manual addition of dives via an UndoCommand. Since this does in
large parts the same thing as undo/redo of dive deletion (just the
other way round and only a single instead of multiple dive), factor
out the functions that add/delete dives and take care of trips.

The UI-interaction is just mindless copy&paste and will have to
be adapted.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:22:27 -07:00
Berthold Stoeger
403dd5a891 Undo: fix multi-level undo of delete-dive and remove-dive-from-trip
The original undo-code was fundamentally broken. Not only did it leak
resources (copied trips were never freed), it also kept references
to trips or dives that could be changed by other commands. Thus,
anything more than a single undo could lead to crashes.

Two ways of fixing this were considered
1) Don't store pointers, but unique dive-ids and trip-ids.
   Whereas such unique ids exist for dives, they would have to be
   implemented for trips.
2) Don't free objects in the backend.
   Instead, take ownership of deleted objects in the undo-object.
   Thus, all references in previous undo-objects are guaranteed to
   still exist (unless the objects are deleted elsewhere).

After some contemplation, the second method was chosen, because
it is significantly less intrusive. While touching the undo-objects,
clearly separate backend from ui-code, such that they can ultimately
be reused for mobile.

Note that if other parts of the code delete dives, crashes can still
be provoked. Notable examples are split/merge dives. These will have
to be fixed later. Nevertheless, the new code is a significant
improvement over the old state.

While touching the code, implement proper translation string based
on Qt's plural-feature (using %n).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:22:27 -07:00
Jan Mulder
8034af5ad5 QML UI: do not try to download from DC with empty vendor/product
Disable the Download button when one of the fields vendor, product,
connection is not filled in. The app will crash when trying.
In addition, make the underlying core code to actual download
more safe by checking this, and silently fail instead of crash.
And, yes, this is a double fix in this scenario, but the core code
is used in more places, so better safe than sorry.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-10-10 06:27:21 -07:00
Jocke
0f588f5227 Substring match BT address
Since a known DC will have the name prepended to the BT/BLE addresss
we need to substring match the BT address.

Signed-off-by: Joakim Bygdell <j.bygdell@gmail.com>
2018-10-09 21:04:23 -07:00
Jocke
c70225f575 Mobile RememberDCs: save device address
By saving the device address together with the vendor and product we fix the 
corner case where a user with two DCs would not get quick select buttons if they
where the same vendor and model.

Signed-off-by: Joakim Bygdell <j.bygdell@gmail.com>
2018-10-09 21:04:23 -07:00
Jocke
636505f818 BT OSTC 3 should be reported as OSTC Plus
Report BT/BLE capable OSTC 3/3+ as OSTC PLus as it is required to get a 
functional download.

Signed-off-by: Joakim Bygdell <j.bygdell@gmail.com>
2018-10-09 21:04:23 -07:00
Berthold Stoeger
50e42bffa1 Dive sites: don't add dummy entries to LocationInformationModel
The LocationInformationModel added two dummy sites to the front
of the list (add new dive site). This was never used - desktop
uses its own model, mobile only extracts the list of dive site
names with a custom function. Remove this functionality.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-09 21:00:44 -07:00
Jan Mulder
91c8a2fa5c Prefs: add bool preference cloud_auto_sync [1/3]
With removal of the git_local_only from the preferences (see
ae653703a5), the users choice, in the mobile app, was not
stored any more in between sessions. This resulted in issue
1725.

So, in order to store that user preference, we need a new
preference. This is added here, but its not yet hooked up
in the app yet. This deals only with the preference handling.
And adapted tests are included.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-10-09 10:03:21 -07:00
Dirk Hohndel
1c8b73b36f libdivecomputer: remove ifdefs for ancient versions
We bundle our version of libdivecomputer and don't expect Subsurface to work
with a different version, certainly not with something older than 0.5.

I kept the checks for SAMPLE_EVENT_STRING and DC_FIELD_STRING and DC_SAMPLE_TTS
because maybe there's a situation where being able to compile with a current
upstream version is useful.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-10-08 23:06:09 +03:00
Linus Torvalds
d2d9821170 Fix warning about unused variables
Commit 810903bdb9 ("Import: pass a dive table to process_imported_dives()")
introduced the variables

        struct dive *old_dive, *merged;

into process_imported_dives(), but never used them.  It seems to be an
artifact of having split the function to use the try_to_merge_into()
helper function (that has those same variable names and _does_ use
them), but forgetting the original variables from the pre-split case.

Gcc understandably warns about it:

  core/divelist.c: In function ‘process_imported_dives’:
  core/divelist.c:1351:26: warning: unused variable ‘merged’ [-Wunused-variable]
    struct dive *old_dive, *merged;
                            ^~~~~~
  core/divelist.c:1351:15: warning: unused variable ‘old_dive’ [-Wunused-variable]
    struct dive *old_dive, *merged;
                 ^~~~~~~~

and the trivial fix is to just remove that line that declares the stale
and unused variables.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-10-08 00:10:29 +03:00
Linus Torvalds
7618240009 ftdi: make the timeout be based on actual real time
bperrybap reported on github that the ftdi timeouts can be excessive:

  "the timeout period while waiting for read data to be 10x or even 100x
   longer than it should be when there are read issues on the data cable
   particularly when using Android and USB OTG cables. i.e. a 5 second
   read timeout for not receiving data can be as long as 7 minutes"

and the reason is that the code at one point tried to use the regular
"gettimeofday()" to handle timeouts, but that doesn't exist in Windows.

We already have Windows-specific code to sleep for a number of
milliseconds in "ftdi_serial_sleep()", let's just extend that same
concept and add a "ftdi_serial_get_msec()" that returns the number of
msec's since some arbitrary point in time.

On Windows, that's just "GetTickCount()", and in sane environments it's
just a trivial wrapper around gettimeofday() to turn sec/usec into msec.

NOTE! The actual msec value doesn't have any meaning.  Only the
difference between two calls to ftdi_serial_get_msec() is meaningful.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-10-08 00:10:29 +03:00
Linus Torvalds
9e3a22c522 qt-ble: add 'get_name()' function to expose the BLE name to libdivecomputer
Some divecomputer backends (ok, right now really only the Aqualung i770R
and i300C) want to know the bluetooth name of the dive computer they
connect to, because the name contains identifying information like the
serial number.

This just adds the support for that to our Qt BLE code.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-10-08 00:10:29 +03:00
Berthold Stoeger
424558cf89 Leak fix: free taxonomy data in delete_dive_site()
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-07 23:40:37 +03:00
Berthold Stoeger
df16866292 Statistics: only consider selected dives in HTML export statistics
If only selected dives were exported into HTML, the statistics would
nevertheless cover all dives. A counter-intuitive behavior. Fix by
adding a selected_only flag to calculate_stats_summary().

Reported-by: Jan Mulder <jlmulder@xs4all.nl>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-07 17:50:51 +03:00
Berthold Stoeger
b61f6f66d8 Statistics: un-globalize stats_selection
The statistics of the selected dives were calculated
a) into a global objects and
b) at a completely different place than where they're used.

There's no plausible reason for either. There fore render
into a caller-provided structure at the place of use.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-07 17:50:51 +03:00
Berthold Stoeger
97991e2b9f Statistics: remove global state / calculate only when needed
Statistics were calculated into global variables every time the
current dive was changed.

Calculate statistics only when needed and into a structure
provided by the caller.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-07 17:50:51 +03:00
Berthold Stoeger
90b019bc8d Core: remove dive->downloaded flag
This flag had two distinct uses:
 - signal that dives were downloaded, not imported
 - use to mark imported dives

Both are not used anymore, therefore remove the flag.
The uemis downloaded misused the flag to mark deleted
dives. Instead misuse the "hidden_by_filter" flag.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-06 19:47:06 -07:00
Berthold Stoeger
6dc1dcaea5 Import: pass "downloaded" parameter to process_imported_dives()
process_imported_dives() is more efficient for downloaded than for
imported (from a file) dives, because it checks only the divecomputer
of the first dive.

This condition is checked via the "downloaded" flag of the first
dive. Instead, pass an argument to process_imported_dives().

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-06 19:47:06 -07:00
Berthold Stoeger
e5dca8228e Import: remove dive->downloaded logic
Dive importing is now performed via a distinct table which is
merged into the main dive table. Thus, it is known which of the
dive is new and which is old. This information can now be
implicitely encoded in the parameter-position of merge_dive()
[i.e. pass old as first and new as second dive].

This makes marking of downloaded dives via a flag unnecessary.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-06 19:47:06 -07:00
Berthold Stoeger
ab14889563 Core: remove preexisting field from struct dive_table
Dives are now in all cases imported via distinct dive_tables.
Therefore the "preexisting" marker is useless. Remove.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-06 19:47:06 -07:00
Berthold Stoeger
810903bdb9 Import: pass a dive table to process_imported_dives()
Dives were directly imported into the global dive table and then
merged in process_imported_dives(). Make this interface more flexible,
by passing an independent dive table.

The dive table of the to-be-imported dives will be sorted and merged.
Then each dive is inserted in a one-by-one manner to into the global
dive table.

This actually introduces (at least) two functional changes:
1) If a new dive spans two old dives, it will only be merged to the
   first dive. But this seems like a pathological case, which is of
   dubious value anyway.
2) Dives unrelated to the import will not be merged. The old code
   would happily merge dives that were not even close to the
   newly imported dives. A surprising behavior.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-06 19:47:06 -07:00
Berthold Stoeger
c32e71e64d Dive information: fix surface interval calculation
The old surface interval calculation had fundamental issues:

1) process_all_dives(), which calculates the statistics over *all*
   dives was used to get the pointer to the previous dive.
2) If two dives in the table had the same time, one of those would
   have been considered the "previous" dive.
3) If the dive, for which the surface interval is calculated is
   not yet in the table, no previous dive would be determined.

Fix all this by creating a get_surface_interval() function and
removing the "get previous dive" functionality of process_all_dives().
Remove the process_all_dives() call from TabDiveInformation::updateData().

Reported-by: Jan Mulder <jlmulder@xs4all.nl>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-07 05:41:48 +03:00
Linus Torvalds
cd55344410 qt-ble: add support for libdivecomputer 'set_timeout()' function
Because some BLE operations can be very slow (device and service
discovery etc), we have some rather excessive default timeout for BLE
(currently set to 12 seconds).

But once we actually have started doing IO, that long timeout can be a
big performance problem, when the libdivecomputer backend has support
for retry and packet loss.

For that reason, libdivecomputer has a 'set_timeout()' function that
allows the divecomputer backend to say how quickly it expects the dive
computer to answer before the backend will start resending packets.

Let's just implement that for the actual IO side of BLE too.  The
default timeout value remains the general BLE timeout, and this only
affects the actual IO phase, but it improves things enormously for the
case where there is packet loss at that point.

For example, on the Aqualung i770R, the timeout for packet loss ends up
now being just one second rather than the full 12 seconds of default BLE
timeout.  Which gets the retry going much faster.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-10-06 19:38:28 -07:00
Linus Torvalds
88f4c06b99 qt-ble: add support to wait for descriptor write completion
When we enable notifications, we actually want to make sure to wait for
that write to have completed before we start communicating with the
device, because otherwise we might lose notification events.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-10-06 19:38:28 -07:00
Linus Torvalds
ec532b8f59 qt-ble: move basic uuid filtering back to service discovery
In commit 30fb7bf35c ("qt-ble: set up infrastructure for better
preferred service choice") I moved the service filtering from the
addService() callback into the "select_preferred_service()" function
that picks the right service for the device.

That was nice for debugging, since it meant that we showed the details
of _all_ services, but it also meant that we ended up starting service
discovery on _all_ services, whether they looked at all interesting or
not.

And that can make the BLE device discovery process quite a bit slower.

The debugging advantage is real, but honestly, service discovery can
generally be better done with specialized tools like the Nordic nRF app,
so the debugging advantage of just listing all the details of all the
services is not really worth the discovery slowdown in general.

So move the basic "filter by uuid" back to the service discovery phase,
and don't bother starting service detail discovery for the services that
we can dismiss immediately just based on the service UUID.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-10-06 19:38:28 -07:00
Linus Torvalds
ebee0c4c24 Fix error handling for libdivecomputer import
The error handling was incorrect for the case where we successfully
opened the libdivecomputer iostream in divecomputer_device_open(), but
the dc_device_open() call failed.

When the dc_device_open() failed, we would (correctly) not do the
dc_device_close() but we would _also_ not do the dc_iostream_close() to
close the underlying file descriptor, which is wrong.

Normally this isn't all that noticeable, partly because the common case
is that dc_device_open() succeeds if you actually do have a dive
computer connected, but also because most of the time it just leaked a
file descriptor or something like that.

However, particularly for the POSIX serial device case, libdivecomputer
does a

	ioctl(device->fd, TIOCEXCL, NULL)

call to make serial opens exclusive.  This is what we want - but if we
then fail at closing the serial file descriptor, we won't be able to
retry the import at all because now the next open will fail with EBUSY.

So the error handling was incorrect, and while it doesn't usually matter
all that much, it can be quite noticeable particularly when you have
transient errors.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-10-06 19:38:14 -07:00
Berthold Stoeger
420aab9454 Cleanup: don't produce no-dives error message in libdivecomputer.c
If no dives were downloaded in do_libdivecomputer_import(), an
error message would be produced. To check for downloaded dives,
the function would access the global downloadTable instead of
the actual table the dives are imported to (at the moment the
same - but the interface allows for a different table).

Move the error-creation to the caller to avoid this situation.
An alternative option would be to check the actual table the
dives were supposed to be downloaded to. But from a program-logic
point of view "no dives" does not seem like an error condition.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-05 04:09:02 +03:00
Berthold Stoeger
8a18396104 Cleanup: don't access downloadTable directly in Uemis-downloader
The Uemis downloader determines the dive-number to be downloaded
by either checking the download-table [interrupted connection] or
the global dive table [fresh download].

The downloadTable is passed in the device data structure, but
in the function to determine the latest dive, the global
downloadTable is accessed directly [thus supposing that this
table was passed in device data].

Instead, use the table from device data to avoid funny surprises
should we change to a non-global download table.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-05 04:07:22 +03:00
Berthold Stoeger
9788d73d48 Import: remove unnecessary processing of dives in DAN import
On DAN-file import after each dive except the first, the dive-list
was processed. This seem bogus and inefficient. An artefact from
old code? In any case, remove.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-04 07:37:28 +02:00
Dirk Hohndel
79d0185c62 Bluetooth: use_random_address helper isn't needed on Windows
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-10-01 15:55:19 -07:00
Jocke
a8953da02d Mobile download from DC: show the correct DC rather than the latest
Since we now keep track of up to 4 DCs we don't want to display the last used one
but rather the one that is connected.

Signed-off-by: Joakim Bygdell <j.bygdell@gmail.com>
2018-10-01 06:32:41 -07:00
Dirk Hohndel
0422cd3662 Bluetooth: don't use random addresses on Windows
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-30 08:09:37 -07:00
Dirk Hohndel
1f59629a76 Bluetooth: use standard Qt code on Windows
We shouldn't need our hand crafted code anymore.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-30 08:09:37 -07:00
Berthold Stoeger
d3d06bc580 Cleanup: split out free_dive() function from delete_single_dive()
Currently, we can only delete dives that are indexed in the main
dive table. In the future, we will have to delete dives outside
of this table (e.g. for undo). Therefore, split out the free_dive()
function from delete_single_dive(), which takes an index into
the main dive table.

In the process, adopt the dive freeing-code from clear_dive(),
which frees more data than the code in delete_single_dive().
This potentially fixes a memory-leak.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-09-29 15:24:08 -07:00
Berthold Stoeger
574065b314 Cleanup: reinstate override modifiers
This reverts commit 1c4a859c8d,
where the override modifiers were removed owing to the noisy
"inconsistent override modifiers" which is default-on in clang.

This warning was disabled in 77577f717f,
so we can reinstate the overrides.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-29 15:23:25 -07:00
Dirk Hohndel
7c320854b3 Bluetooth: turn on logging earlier
This way we should get logging output for the discovery phase as well.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-29 14:16:37 -07:00
Berthold Stoeger
32a4ce6169 Parser: parse text-based files into arbitrary table
In d815e0c947 a dive_table pointer
was added to the parsing functions to allow parsing into tables
other than the global dive table. This will be necessary for undo of
import and implementation a cleaner interface. A few cases, notably
CSV and proprietary formats were forgotten.

Implement parsing into arbitrary tables also for these cases.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-09-28 15:06:00 -07:00
Berthold Stoeger
3137fbe973 Cleanup: remove redundant prototypes from dive.h
A few of these prototypes were already in import-csv.h.
Put them in an 'extern "C" { ... }' block.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-09-28 07:47:39 -07:00
Berthold Stoeger
2e6df623bb Cleanup: Make add_sample_data() local to translation unit
This function in parse_csv.c was not used anywhere. Make
it of static linkage.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-09-28 07:47:39 -07:00
Linus Torvalds
890d4c3d64 qt-ble: allow reading of partial packet data
The existing BLE dive computers treat BLE as the packetized protocol it
is, and read whole packets at a time.

However, the Mares BlueLink backend treats it as just a basic "serial
over BLE" transport, and for historical reasons reads the reply packets
in smaller chunks.

This allows that kind of IO behavior, where if the divecomputer backend
reads just a part of a packet, we'll split the packet, return the part
the user asked for, and push back the leftover packet onto the received
packet queue.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-09-26 12:13:20 -07:00
Linus Torvalds
8426024b76 Allow XML sample times to have hh:mm:sec format
We traditionally only allow samples to have a time format of 'mm:ss', so
if you have a dive over an hour, you would just have a minutes field
larger than 60 minutes.

But Matthew Critchley is trying to import some dives from his VMS
Redbare CCR, and the sample timestamp format he has is of the type
'hh:mm:ss'.

That could be fixed by a xslt translation, but there's no real reason
why we couldn't just support that format too.

Reported-by: Matthew Critchley <matthew.s.critchley@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-09-26 12:13:20 -07:00
Linus Torvalds
05fe19a23f qt-ble: add BLE packet debugging code
This is perhaps overly verbose, but the timing details helped figure out
some EON Core download issues, and it's nice to see when things actually
happen.

It's also good to see when the data actually enters our queues, and when
we read and write the packets.  That might help debug the issues Fabio
is seeing with the Mares Bluelink.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-09-25 16:41:13 -07:00
Linus Torvalds
0ba105d2a7 qt-ble: only connect the signals to the preferred service
We used to just find all services and connect the characteristics change
signal etc to them all, but we really only care about the actual
preferred service that we'll be using.

So move the qt ble signal connection to after we've selected the
preferred service that we will actually be enabling notifications on and
do the writes to.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-09-25 16:41:13 -07:00
Berthold Stoeger
cc4f48be3f Metadata: rudimentary support for XMP metadataa in MP4-based videos
XMP is a media-metadata standard based on XML which may be used
across a variety of media formats. Some video-processing software
writes XMP data without updating the native metadata fields.
Therefore, we should aim at reading XMP metadata and give priority
of XMP data over native fields.

Pros:
	- Support for *all* common media formats.
Cons:
	- XML (complex, verbose, chaotic).
	- Does not even come close to fulfilling its promise of being
	  well defined (see below).

Implement a simple XMP-parser using libxml2. Connect the XMP-parser to
the existing Quicktime/MP4 parser.

First problem encountered: According to the spec, XMP data supposed
to be put in the 'XMP_' atom. But for example exiftools instead
writes an 'uuid' atom with a special 16-byte uid. Implement both,
more options will probably follow.

Second problem: two versions of recording the creation date were found
  1) The content of a <exif:DateTimeOriginal> tag.
  2) The xmp::CreateDate attribute of a <rdf:Description> tag.

Here too, more versions are expected to surface and will have
to be supported in due course (with an obvious priority problem).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-09-25 14:59:14 -07:00
Jan Mulder
5480d08d15 cleanup: do not compare doubles like this
Cleanup another possibly dangerous compare of doubles.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-09-25 16:01:39 +02:00
Dirk Hohndel
619289074b qPref: don't compare doubles for equality
This is a much safer way to do this.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-25 15:58:17 +02:00
Dirk Hohndel
617019bc6b qPref: add mobile_scale preference
We use that in the mobile app to scale the whole app, as all sizes there
are relative to the default font.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-25 15:58:17 +02:00
Linus Torvalds
1b16d570a1 qt-ble: re-organize how we pick the GATT characteristics to read and write
We used to just blindly pick "first" and "last" characteristic from the
preferred service, and that was stupid but happened to work for the dive
computers we supported.  Note that for some of them, "first" and "last"
was actually the *same* characteristic, since it could be a single one
that supported both.

However, this first/last hack definitely doesn't work for the Mares
BlueLink BLE dongle, and it's really all pretty wrong anyway.

So re-organize the code to actually look at the properties of the
characteristics.  I don't have a BlueLink to test with, but my EON Core
and Shearwater Perdix AI are still happy with this, and the code
conceptually makes a lot more sense.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-09-24 17:12:58 -07:00
Dirk Hohndel
02fc78570e macOS: always list 'FTDI' as a serial connection
We now link against the user space FTDI driver.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-24 18:51:21 +02:00
Jan Mulder
1f0a6019da cleanup: remove more GPS webservice code
And remove some includes and defines that are not used any more after
removal of the GPS webservice code.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-09-24 07:20:25 -07:00
Jan Mulder
fc812ea130 core: fix connect call
Fix multiple run-time errors in connect call introduced in 504e912512.
1) Set the proper signature of the signal. 2) make the used slot
a real slot (so move it to the proper section in the header) and
3) set the proper signature for the slot.

Highly unlikely that normal users notice the runtime errors and
possibly unwantend behavior, as this all deals with the subtile GPS
service update threshold.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-09-24 07:20:25 -07:00
Linus Torvalds
30fb7bf35c qt-ble: set up infrastructure for better preferred service choice
We used to just pick the first non-standard service we found (with a
special case for the Heinrichs Weikamp dive computers that have an
actual registered standard service).

We then waited for that service to finish discovery, and started using
it.

This changes the logic to wait for _all_ services to finish discovery,
and then after that we pick the one we like best.  Right now the rule
for picking a preferred service is the same one we had before, but the
difference is that we now have the full discovery data, so we *could* do
something better.

Plus this makes our debug messages a lot more legible, when we don't
have the mix of overlapping service discovery with the actual IO we do
to the preferred service.

NOTE! This doesn't much matter for most of the dive computers that we
currently support BLE for.  They don't tend to have a lot of odd
services.

But at least both the Mares BlueLink and the Garmin Descent both have
multiple services and it's not obvious which one to use, and this will
make it not only easier to debug those, it will make it easier to pick
the right preferred service descriptor to use.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-09-23 17:29:05 -07:00
Linus Torvalds
594f13eeaf qt-ble: use the WAITFOR() macro rather than open-coding wait loops
This is not only much clearer (and smaller code), but it also lowers the
latency for the waiting, since we don't always wait for the full 100ms.

Get rid of the now unused "waitfor()" function that just unconditionally
waited for 100ms.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-09-23 17:29:05 -07:00
Berthold Stoeger
35b8a4f404 Core: split process_dives() in post-import and post-load versions
process_dives() is used to post-process the dive table after loading
or importing. The first parameter states whether this was after
load or import.

Especially in the light of undo, load and import are fundamentally
different things. Notably, that latter should be undo-able, whereas
the former is not. Therefore, as a first step to make import undo-able,
split the function in two versions and remove the first parameter.

It turns out the the load-version is very light. It only sets the
DC nicknames and sorts the dive-table. There seems to be no reason
to merge dives.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-09-23 11:50:53 -07:00
Dirk Hohndel
0ae57cfe92 Mobile/remember DCs: try to match device names
We only store the address part of the connection name, so don't try to find an
exact match, try to find the sub-string.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-23 11:49:30 -07:00
Dirk Hohndel
413b05ab89 Desktop/remember DCs: move non-UI-specific code into the core layer
This way we can use the same functionality from the mobile UI as well.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-23 11:49:30 -07:00
Dirk Hohndel
77a5c9ac65 qPref: add ability to remember recently used dive computers
This does feel clumsy and complicated. This is a lot of special case
handling and a lot of boilerplate for something that really should be
quite simple.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-23 11:49:30 -07:00
Berthold Stoeger
9c8deef477 Trivial: un-static function-local buffer
In visit_on_node() in core/parse-xml.c the name is extracted into
a static buffer. There seems to be no need for this being static,
as the name is only passed to the entry() function which (hopefully)
does not store a reference to the name anywhere.

If it does, this would need a *big* *fat* comment.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-09-22 14:44:34 -07:00
Linus Torvalds
d2b8088cd8 Actually create a UUID when creating a dive site during download
The existing code creates a deterministic ID (not exactly "unique") in order to
help us avoid merge conflicts in git-storage mode. But as a side effect, if we
re-download the same dive twice from a dive computer that supports GPS (right
now only the Garmin Descent Mk1) we are guaranteed to create the same dive site
uuid when we do this. So when we download a dive - whether we will actually
*use* that dive later or not - we will be filling in the dive site information
with the data we got from the dive computer.

... and in the process we will be overwriting any data that was filled in
manually. The name of the dive site, but also possibly even the GPS of the dive
site (maybe the user decided to edit that using the map, because while the
automatically downloaded GPS data was "correct", maybe the user wanted to
change it to be the actual under-water location using the satellite data,
rather than the place where you started the dive or where you surfaced).

In order to avoid this collision, this patch just makes the libdivecomputer
download not use the dive time, but "time of download" for the dive site time,
and thus effectively generate a new uuid for every download.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-22 14:17:24 -07:00
Berthold Stoeger
21b1550739 Dive media: on import read metadata only once
On import of dive media, the timestamp is read from the
metadata to check if the image belongs to the selected dives.
The pictures are then listed in a dialog.

Currently, the metadata is read twice if images are outside
of a dive: once in picture_check_valid() and if it turns
out that the picture is not valid again in picture_get_time()
to display the proper timestamp.

Even though metadata-extraction is reasonably fast, this is
a bit of an embarrassment.

Instead, read the timestamps only once in the constructor of
the dialog and from then on only used these timestamps. Keep
the timestamps in a QVector. Rename the picture_check_valid()
function to picture_check_valid_time() and pass a timestamp
instead of a filename.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-09-19 14:44:34 -07:00
Berthold Stoeger
92deb7aa70 Cleanup: make surface sample in merge_one_sample() non-static
The merge_one_sample() function adds a sample to the destination
dive if dives are merged. For long periods between samples at surface
depths, it adds a surface interval.

To decrease the number of global objects, make the sample structure
non-static. Of course, initialization of an on-stack structure is
slower. Therefore move it into the corresponding if. Thus, the
structure will be initialized only once per surface-interval.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-09-19 14:43:54 -07:00
Jocke
148bc8fbf1 Mobile: always update the preferences when set_unit_system is called
Unit_system is read from git storage but units are set from locale when the
app starts. To prevent a miss-match between unit and unit_system we have to
always update the preferences variable when set_unit_system is called so that
the user doesn't end up with imperial units when the preferences say metric.

Signed-off-by: Joakim Bygdell <j.bygdell@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-19 14:41:34 -07:00
Anton Lundin
1da9235cdf Always return status from ftdi_open when called
Using dc_serial_open as a fallback to ftdi_open is just wrong, and will
never work, just mask the real error and introduce read herrings.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
2018-09-16 08:09:24 -07:00
Robert C. Helling
afe363fa85 Optional anonymization upon export
Add a checkbox that triggers replacement of all English characters by
x's in notes, buddy, dive guide and (while we are at it) suit.

This is ment for people sharing logs for debugging that are concious
about privacy issues. It leaves the lenth of strings in tact as well
as special charcters as those might be needed to track down a particular
parsing problem.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-09-13 08:16:54 -07:00
jan Iversen
504e912512 core: connect qPref..::time_thresholdChanged to setGpsTimeThreshold
Automate calling of setGpsTimeThreshold when qPref..::time_threshold changes
and thus avoiding the need to call setGpsTimeThreshold directly.

Signed-off-by: Jan Iversen <jani@apache.org>
2018-09-12 20:18:32 -07:00
Lubomir I. Ivanov
f8e9fb72f1 serial_ftdi: use Sleep() on Win32
Windows doesn't have nanosleep() unless libwinpthread is used.

Since the nanosleep() usage in serial_ftdi_sleep():
- does not break in case of EINTR
- has input in milliseconds
the WINAPI Sleep() should be a good alternative.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2018-09-12 17:18:47 -07:00
Berthold Stoeger
31f1af07c2 Planner: fix display of "overlapping dives" message
1) Add a missing <div>

2) More importantly: recognize html content via <div>-tags instead of
   <table>-tags.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-09-12 14:17:55 -07:00
Anton Lundin
ecbfea3568 DLF import: Remove old debug print
Signed-off-by: Anton Lundin <glance@acc.umu.se>
2018-09-12 14:14:14 -07:00
Anton Lundin
8c848021b3 DLF import: Decode all sensors, when we got them.
Signed-off-by: Anton Lundin <glance@acc.umu.se>
2018-09-12 14:14:14 -07:00
Anton Lundin
015bd43c25 DLF import: Set initial gas as first cylinder
Signed-off-by: Anton Lundin <glance@acc.umu.se>
2018-09-12 14:14:14 -07:00
Anton Lundin
1ad872ac5f DLF import: Name dive site
The UI doesn't behave all that nice without name on the dive site.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
2018-09-12 14:14:14 -07:00
Anton Lundin
1dc8beced3 DLF import: Decode device configuration into extra strings
These save a lot of different info about the computer, so decode them
into extra strings.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
2018-09-12 14:14:14 -07:00
Anton Lundin
fa196fdab0 DLF import: Create separate solenoid open/close events
Signed-off-by: Anton Lundin <glance@acc.umu.se>
2018-09-12 14:14:14 -07:00
Dirk Hohndel
428af68e64 BLE: add Teric to list of auto-detected Shearwater computers
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-12 14:00:49 -07:00
Miika Turkia
3bd574ea89 DLF import: record starting battery level
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2018-09-12 05:31:29 -07:00
Miika Turkia
37e417c28a DLF import: use battery_end in preparation
Prepare for recording both start and end pressures.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2018-09-12 05:31:29 -07:00
jan Iversen
7e243fe363 core/settings: correct UserSurvey -> userSurvey in qPrefDisplay
QML is quite special, the variables needs to start with lower case in C++
and are used starting with upper case in QML

Signed-off-by: Jan Iversen <jani@apache.org>
2018-09-11 17:25:00 -07:00
jan Iversen
7129ad92a4 core/settings: optimize base_url functions.
Remove unused variable and create of QString.

Signed-off-by: Jan Iversen <jani@apache.org>
2018-09-11 17:25:00 -07:00
jan Iversen
178c01baf5 core/settings: use instance() in qPref macros
use instance() instead of <class>::instance()

Signed-off-by: Jan Iversen <jani@apache.org>
2018-09-11 17:25:00 -07:00
jan Iversen
a037578015 core/settings: change bestmixend to int, to allow qml to work
depth_t is a good struct in C, but bad in QML.

Signed-off-by: Jan Iversen <jani@apache.org>
2018-09-11 17:25:00 -07:00
jan Iversen
c0b78d69d9 core/settings: correct wrong emit in qPrefFacebook
Signed-off-by: Jan Iversen <jani@apache.org>
2018-09-11 17:25:00 -07:00
jan Iversen
2385f48c6a core/settings ... : remove qPref* includes in qPref.h
reduce number of includes by removing qPref* includes in qPref.h

Signed-off-by: Jan Iversen <jani@apache.org>
2018-09-11 17:25:00 -07:00
jan Iversen
684e334fb6 core: declare cloud_status in qPrefCloudStorage
qml declaration of cloud_status (defined in pref.h) does not
belong in qPref.h but in qPrefCloudStorage

Signed-off-by: Jan Iversen <jani@apache.org>
2018-09-11 17:25:00 -07:00
jan Iversen
4d57b52062 core/tests: change short to int in pref.h
Simplify structure preferences by removing short. Update test cases to not
do (int).

Signed-off-by: Jan Iversen <jani@apache.org>
2018-09-11 17:22:58 -07:00
jan Iversen
d0edc29636 core,tests: change qml register function
In order to address the C++ object directy in qml, a different
registration is needed.

qmlRegisterType, registers the C++ class, allowing qml code to inherit
from it and make qml objects. This is needed for graphical elemnets
like profile and map

setContentProperty, registers the C++ object, thus allowing signals to be
catched.

Signed-off-by: Jan Iversen <jani@apache.org>
2018-09-11 17:22:58 -07:00
jan Iversen
a71afd31ee core: add auto registration to qPref*
Instead of having all register calls in subsurface-helper.cpp let
qPref.cpp handle all qPref registration, since they also need to be
different

update subsurface-helper and testqml accordingly.

Signed-off-by: Jan Iversen <jani@apache.org>
2018-09-11 17:22:58 -07:00
jan Iversen
7940e45c4c core/settings: add missing empty line.
Standard is to have 1 empty line between functions

correct missing static in qPrefGeocoding.h

Signed-off-by: Jan Iversen <jani@apache.org>
2018-09-11 17:22:58 -07:00
jan Iversen
c72add5721 core/setting: change *_changed to *Changed for the sake of QML.
QML demands signals to be of the form
<name>Changed

Changing all of qPref

REMARK: this commit is not compileable, since it only change qPref and not
the rest of the system

Signed-off-by: Jan Iversen <jani@apache.org>
2018-09-11 17:22:58 -07:00
Jan Mulder
740fcce338 cleanup[6/6]: remove actual preferences
And finnaly, get rid of the definition in the overall struct.
And one usage of the preferences was still around.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-09-11 15:38:20 -07:00
Jan Mulder
19e8fa4eaf Cleanup[5/6]: remove unused preferences
Remove all the code to handle the preferences itself.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-09-11 15:38:20 -07:00
Jan Mulder
bb0ac5f778 cleanup[4/6], mobile: remove superfluous code from gpslocation
Despite the fast that this code is sitting in core, its used mainly
from mobile. In 987e221f8e, the buttons to interact with the GPS
webservice were deleted from the UI.  Now, delete all the code that
was used under these buttons.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-09-11 15:38:20 -07:00
Jan Mulder
cc72a606bb cleanup[3/6]: do not save the userid any more
Do not save the to be deleted prefences any more.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-09-11 15:38:20 -07:00
Jan Mulder
3c8506e1b8 cleanup[2/6]: remove set_userid()
This code is not used any more.

Signed-off-by: Jan Mlder <jlmulder@xs4all.nl>
2018-09-11 15:38:20 -07:00
Jan Mulder
226161ee44 cleanup[1/6]: do not set userid/save_userid_local from storage
This the first of a set of cleanups related to the removal of 2
preferences: save_userid_local and userid. The commits are
ordered so that a sane running state remains, should a
bisect ever lands here.

Here, just read a git or XML logbook including the to be removed
preferences, as existing users can have this data sitting around.
The only thing done here is not to store the possibly read data
for the mentioned preferences.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-09-11 15:38:20 -07:00
Dirk Hohndel
619a52635a prefs: use correct way to set the cloud storage password preference
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-10 16:26:49 -07:00
Dirk Hohndel
2b3f6c607b prefs: cloud_new_password is not a preference
It's a mamber of the cloud storage authentication class, used to hold the
proposed new password until the backend has accepted it.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-10 16:26:49 -07:00
Dirk Hohndel
ae653703a5 prefs: git_local_only is not a preference
It's the current state of the app, so it should be a global variable, not a
preference.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-10 16:26:49 -07:00
Berthold Stoeger
6e4a253896 Profile: fix SAC calculation for air dives
Commit f5b11daffd changed gasmix
arguments and return values to be passed by value instead of
using pointers.

Notably, get_gasmix() is fed a default-value and returns a
new value. In the old code, NULL was passed in in a first
loop iteration and non-NULL was always returned in the first
iteration. Thus, an equality comparison of passed-in an
returned gasmix would always fail in the first loop iteration.

The new code passed in air as default. Now if air was also
returned, then the matching gases were not calculated in
calculate_sac(). To revert to the old behavior, pass in
an invalid gasmix.

Moreover, give names to the invalid and air gasmixes.

Reported-by: tormento <turment@gmail.com>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-09-10 14:23:59 -07:00
Alexander Wilms
12d75001a0 Set desktop file name to avoid a broken icon under KDE Wayland
Signed-off-by: Alexander Wilms <f.alexander.wilms@gmail.com>
2018-09-09 18:44:40 -07:00
Miika Turkia
3c9897d247 DLF import: document deco event
These are Deco N2 Low/High and Deco He Low/High events. They all appear
to be recorded at the same time, different events at same second.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2018-09-09 12:26:45 -07:00
Miika Turkia
dac90e3fde DLF import: comment measured He
Measured He is documented (in comment). Will need information if all
measurements are needed or just start/end. First case would be added to
dive prifle, possibly cluttering it, second would be extra data.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2018-09-09 12:26:45 -07:00
Miika Turkia
aae2403ddd DLF import: Record battery status
This will record the ending battery status to extra data. Would need
info from CCR divers whether this suffices or if we should record also
the starting volatage or even every single reading.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2018-09-09 12:26:45 -07:00
jan Iversen
ee6b5643b5 core/settings: only sync values that are actually changed
Add a variable reflecting the current_state to all DISK_* macros, in order to
check if the original variable in struct preferences is changed.

Only save to disk if actually changed

[Dirk Hohndel: merged Jan's commit and renamed the variable and adjusted the
               commit message... but fundamentally the commit is still what Jan
               wrote, so he should get the credit]

Signed-off-by: Jan Iversen <jani@apache.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-07 14:37:18 -07:00
Dirk Hohndel
2ecbea3d24 qPref: use helper function to ensure key/name grouping
We had a couple of instances of names being incorrectly merged with their
group, this should handle that better. It's a bit of a big hammer to use, but
it seems to work (and it makes it easy to then git grep for cases that don't
use the new helper function.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-07 14:37:18 -07:00
Berthold Stoeger
2bd0c2143e Cleanup: constify get_units()
get_units() returns a pointer to the units struct in the preferences.
Callers should not modify the preferences via this struct, therefore
make the return value point to const.

This is a small step in constifying the global preferences structure.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-09-07 11:03:30 -07:00
Jan Mulder
2635673c3a Preferences: more missing /
subsurface_webservice_uid ends up in the wrong group due missing
/. Notice that this does not fix the issues I mentioned in #1648.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-09-07 07:39:35 -07:00
Linus Torvalds
56a77f0fa3 Garmin devices - like Shearwater - want random BLE addressing
We had a special-case for the Shearwater case, let's just make it
slightly more generic and add Garmin to the list of vendors that want a
random BLE address rather than a static one.

The Bluez model of having to state this explicitly - but not giving the
information to the user - is completely broken and this is all very
annoying, credit goes to Wojciech Więckowski for pointing this out.

Of course, right now we don't actually know how to parse the BLE stream
from the Garmin Descent, but with this (and some libdivecomputer
hackery) I actually get connected and start receiving data.  That we
then can't parse, but that's hopefully just a libdivecomputer update
away.

Pointed-out-by: Wojciech Więckowski <xplwowi@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-06 18:35:18 -07:00
jan Iversen
c03c2b5fd7 core/settings: add missing / in default_filename
Signed-off-by: Jan Iversen <jani@apache.org>
2018-09-06 17:14:54 -07:00
jan Iversen
12fc3f1747 Revert "core/tests: add loadFromCloud var to qPrefCloudStorage"
This reverts commit b7a1bb670c.

Signed-off-by: Jan Iversen <jani@apache.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-06 17:14:48 -07:00
Dirk Hohndel
e71b049498 qPref: only save settings that aren't the default
This brings us back to the previous behavior.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-06 16:13:44 -07:00
Linus Torvalds
5c2bca048f libdivecomputer: allow a "zero depth" deco stop depth
That just means that we're not in deco, the same way as giving a nonzero
NDL value does.  But if you don't have NDL, this is a much more
convenient way of saying "not in deco".

The Garmin Descent gives us stop information, but not necessarily NDL,
and really wants this.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-09-03 13:29:40 -07:00
Linus Torvalds
faea11e4fb libdivecomputer: add support for DC_SAMPLE_TTS if it exists
libdivecomputer didn't use to have a TTS sample value, but we're adding
one, so add conditional support for it if it exists.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-09-03 13:29:40 -07:00
Lubomir I. Ivanov
6af67f541d core/windows.c: write logs to the user path
Writing logs to the path where the executable is located,
might not be possible if the current user doesn't have
permissions to write there.

Obtain the user path and write the log files to the
user path instead - e.g.:
c:\users\myuser\appdata\roaming\subsurface\subsurface_*.log

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2018-09-03 13:29:03 -07:00
Lubomir I. Ivanov
c47b6b672f code/windows.c: add method for converting from utf16 to utf8
Modify the funcion system_default_path_append() to
both receive and return wchar_t types.

Remove fallback in system_default_path_append()
as this is now redundant.

Add a function utf16_to_utf8() and use that
in places where system_default_path_append() needs
to be converted to utf8.

Move both utf16_to_utf8*() and utf8_to_utf16*()
near the top of the file.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2018-09-03 13:29:03 -07:00
Berthold Stoeger
19f7b5279a Cleanup: silence clang missing braces warning in core/color.cpp
C++11 initializer lists should be passed via {{ ... }}.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-09-01 11:31:18 -07:00
Berthold Stoeger
59a68fe9b5 Parser: split out name-comparison from match() function
The match() function in parse-xml.c calls a very specific callback,
which doesn't take a context-parameter. To be able to call other
callbacks, split out the actual name-comparison.

Moreover, remove the "plen" parameter, as this was called with
strlen(pattern) in all cases anyway. Replace the old logic which
potentially accessed a byte beyond the end of name with a simply
classical C-style loop.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-30 13:32:09 -07:00
Berthold Stoeger
2de8e70ab0 Parser: move match() into core/parse-xml.c
The match() function compares a pattern with a name with
a twist: The name may either end in '\0' or '.'. If pattern
and name match, a parsing function is called on a buffer and
a destination value. The result of the parsing is not checked.

This seems awfully XML-specific and therefore move the function
from the general parse.c to the specialized parse-xml.c unit
and make it of local linkage.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-30 13:32:09 -07:00
jan Iversen
1515b9496b core/settings: add missing load_* call in qPrefDisplay
Signed-off-by: Jan Iversen <jani@apache.org>
2018-08-30 05:36:36 -07:00
jan Iversen
cf2ffdc432 core/settings: add README
Add simple explanation of how the program flow is.

Signed-off-by: Jan Iversen <jani@apache.org>
2018-08-30 05:36:36 -07:00
Linus Torvalds
f59679320a parse "GPS" string fields and turn them into dive sites when downloading
Dive computers that do GPS can report their GPS data as one or more
string fields, and if the first tree letters of the description is
"GPS", then we'll take the string and turn it into a dive site for that
dive.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-08-29 21:40:19 -07:00
Dirk Hohndel
4bb72160a6 core: fix typo in preference name
In commit 1bc361b2ea ("core/tests: add uuidString to qPrefUpdateManager") a
typo was introduced for the preference name.

Reported-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-08-28 12:11:16 -07:00
Linus Torvalds
80fe8fb331 Add support for opening a DC_TRANSPORT_USBSTORAGE stream
This is part of the whole "let's support the notion of dive computers
being exported as USB storage devices" push.

With an older libdivecomputer, we'll just fall back on failing the
operation, but we still want to support the generic notion of
DC_TRANSPORT_USBSTORAGE since we have our own internal Uemis downloader.
That one won't ever get to the open phase, since it's caught earlier.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-08-27 22:11:05 -07:00
Linus Torvalds
270e9eccad Make device enumeration use the device transport data
This removes some special-case code for Uemis, replacing it with simply
passing in the device transport information.

This makes device enumeration work for the Garmin Descent (if it is
listed by libdivecomputer as a USB storage device, that is).

I don't actually do any of the libdivecomputer parsing yet, and only
have a stub for the Garmin Descent, but now the directory selection
works with that stub. The actual download obviously does not.

[Dirk Hohndel: removed obsolete FIXME from code]

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-08-27 22:10:38 -07:00
Linus Torvalds
bb067b6ee4 Treat the "GARMIN" mount point exactly like the "UEMISSDA" one
The logic for finding a mount point for the Garmin FIT devices is
basically exactly the same as for the UEMISSDA, even if the rest of the
sequence is not the same.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-08-27 22:09:44 -07:00