Commit graph

59 commits

Author SHA1 Message Date
Dirk Hohndel
5048a695aa mobile: turn GpsLocation into a regular singleton construct
Simply move the initialization of the logging function into its own method and
call that in the QMLManager constructor.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-01-02 12:47:15 -08: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
7acb229b4a mobile/location-service: stop using broken adjustment function
gettimezoneoffset() returns incorrect values when called with a time_t.
Since we only accept the value here if it is within 5 minutes of 'now',
using the current timezone offset is a fair approximation.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-07-11 11:57:54 -07:00
Dirk Hohndel
9d2449c5c3 mobile/location-service: fix timezone issue in GPS timestamps
For some reason we suddenly started logging the GPS fixes in UTC instead
of local time. Which caused the matching algorithm to fail (unless you
happened to be diving in UTC). Unclear what broke this, but this seems
like an easy enough fix, since the GPS fix being reported is by
definition "right around now". So using gettimezoneoffset() with the
current time seems "good enough".

I don't know when gettimezoneoffset() with an argument got broken, TBH.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-07-11 11:47:43 -07:00
Berthold Stoeger
8f80129bac cleanup: create common QDateTime -> timestamp conversion function
In analogy to the timestamp -> QDateTime conversion, create a
common function.
1) For symmetry with the opposite conversion.
2) To remove numerous inconsistencies.
3) To remove use of the deprecated QDateTime::toTime_t() function.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-22 12:31:06 -07:00
Berthold Stoeger
f63485b444 cleanup: move timestampToDateTime() to qthelper.cpp
Move this function from maintab.cpp to qthelper.cpp. Since the
functionality was used in numerous places, use the helper function
there as well. This removes a number of inconsistencies. For example,
sometime setTimeSpec(Qt::UTC) was called, even though the
QDateTime object was already created with that time spec.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-22 12:31:06 -07:00
Berthold Stoeger
95284c026e cleanup: move dive_table from dive.h to divelist.h
This allows us to decouple dive.h and divelist.h, a small step in
include disentangling.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-01 09:42:31 -07:00
Berthold Stoeger
70fef60b5c cleanup: remove unnecessary include
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-19 00:25:13 +01: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
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
Dirk Hohndel
bf6a644fc6 Mobile: provide better tracking of applied GPS fixes
Also reset the page stack to make sure we don't end up with stale data.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-10-26 11:38:26 -07:00
Dirk Hohndel
fb26f6b0fa Avoid duplicate debug output from GPS module
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-10-02 08:04:49 -07:00
Dirk Hohndel
9ae7040a91 Revert the singleton PR
It turns out that this isn't working the way it was intended to.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-09-27 16:26:58 -07:00
Berthold Stoeger
400b218f76 Cleanup: remove GpsLocation::instance() function
The last user was removed in 8576edd8d6.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-25 13:35:30 -07:00
Berthold Stoeger
f20d6187f0 Cleanup: remove GpsLocation::hasInstance()
This function was not used anywhere.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-25 13:35:30 -07:00
Berthold Stoeger
5da09a21bb Cleanup: move error reporting function declarations to errorhelper.h
Move the declarations of the "report_error()" and "set_error_cb()"
functions and the "verbose" variable to errorhelper.h.
Thus, error-reporting translation units don't have to import the
big dive.h header file.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-08 16:26:30 -07:00
Berthold Stoeger
8f119dcf72 Cleanup: remove includes from qthelper.h
To reduce interdependencies, remove the dive.h and divelist.h
includes in qthelper.h

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-18 05:42:55 -07:00
Berthold Stoeger
e2df38d868 Dive site: add dive site ref-counting
Instead of setting dive->dive_site directly, call the
add_dive_to_dive_site() and unregister_dive_from_dive_site()
functions. In the parser this turned out to be a bit tricky.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
c22fd9f4fd Dive sites: prepare for dive site ref-counting
Add a dive site table to each dive site to keep track of dives
that have been added to a dive site. Add two functions to add
dives to / remove dives from dive sites.

Since dive sites now contain a dive table, the order of includes
had to be changed: "divesite.h" now includes "dive.h" and not
vice-versa. This caused some include churn.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
31291b1c56 Dive site: set UUID only on save or load
Since the UUID will be overwritten on save and is only used on save
and load, set it only on save or load. For other created dive sites,
leave the UUID field uninitialized.

This means that the UUID will change between saves. Let's see how
the git saver handles that.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
f6e7bdc5ef Dive site: add dive site table parameter to dive site functions
To enable undo of dive site functions, it is crucial to work
with different dive site tables. Therefore add a dive site table
parameter to dive site functions. For now, always pass the global
dive site table. Thus, this commit shouldn't alter any functionality.

After this change, a simple search for dive_site_table reveals all
places where the global dive site table is accessed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
40a3e562b0 Cleanup: provide printGPSCoords in C and C++ versions
printGPSCoords() returned a newly allocated C-style string. Most
callers simply made a QString out of it and freed the C-style string.
This is paradoxical, as printGPSCoords internally works with QStrings
and converts them to C-style on return.

Therefore, let printGPSCoords() return a QString and create a
printGPSCoordsC() wrapper for the two C-callers.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-03-27 13:58:15 +01:00
Berthold Stoeger
04593e8ec4 Cleanup: fix printGPSCoords signature and leaks
The printGPSCoords() function returns a copied C-style string. Since
the owndership is transferred to the caller, the correct return type
is "char *" instead of "const char *".

Thus a number of casts when calling free can be removed.

Moreover a number of callers didn't free the string and thus were
leaking memory. Fix them. Ultimately we might want two versions
of the function: one for QString, one for C-style strings.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-03-24 21:57:13 -07:00
Berthold Stoeger
724055f0af Dive site: replace dive->dive_site_uuid by dive_site
Replace the UUID reference of struct dive by a pointer to dive_site.
This commit is rather large in lines, but nevertheless quite simple
since most of the UUID->pointer work was done in previous commits.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-29 00:09:31 +00:00
Berthold Stoeger
d3a7c5448f Dive site: return pointer to dive_site in create_dive_site_*()
This changes more of the dive-site interface to return pointers
instead of UUIDs. Currently, most call sites directly extract
UUIDs afterwards. Ultimately, the UUIDs will be generally replaced
by pointers, which will then simplify these callers.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-29 00:09:31 +00:00
Linus Torvalds
28e3413ff6 Add 'location_t' data structure
Instead of having people treat latitude and longitude as separate
things, just add a 'location_t' data structure that contains both.

Almost all cases want to always act on them together.

This is really just prep-work for adding a few more locations that we
track: I want to add a entry/exit location to each dive (independent of
the dive site) because of how the Garmin Descent gives us the
information (and hopefully, some day, other dive computers too).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-10-21 19:55:09 +03: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
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
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
Berthold Stoeger
36b9e5e31e Cleanup: fold core/helpers.h into core/qthelper.h
helpers.h included qthelper.h and all functions declared in helpers.h
were defined in qthelper.h. Therefore fold the former into the latter,
since the split seems completely arbitrary.

While doing so, change the return-type of get_dc_nichname from
"const QString" to "QString".

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-06-04 08:50:10 -07:00
jan Iversen
a312e53f0c core: Change Q_UNUSED to no parameter name
C++ permits use of parameters without name, which signals unused

Signed-off-by: Jan Iversen <jani@apache.org>
2018-05-21 12:48:04 -07:00
Dirk Hohndel
ea83b5ed37 Core: remove dive.h from files that don't need it
Of course, quite a few of them indirectly get it through other header
files.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-05-14 10:13:39 -07:00
Dirk Hohndel
40755987ed Qt: don't use member function that requires Qt 5.8
This should have been caught by our build check, but it turns out that
that one isn't correctly reflected in its Travis status.

Oops.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-04-15 14:46:56 -07:00
Dirk Hohndel
1de4321ca1 GPS: untangle the timestamp comparison
And calculate the correct time since last fix.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-04-14 13:38:19 -07:00
Dirk Hohndel
ca3be8f376 GPS: add signal to show that a new fix has been acquired
This way if we don't have a current enough position we can wait for a
current fix to be acquired.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-04-14 13:37:44 -07:00
Dirk Hohndel
82a3d2be95 QML UI: better debug messages for getting current location
Also, show GPS refresh interval in seconds; it's confusing if this is
reported in ms.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-04-14 13:37:44 -07:00
Berthold Stoeger
2105d3c7d0 Cleanup: consistently use toUtf8() instead of toLocal8Bit()
These do the same, since the text-codex is set to UTF-8 on startup.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-14 13:55:36 +02:00
Jan Mulder
0bb1a82127 GpsLocation::clearGpsData() is only used in SUBSURFACE_MOBILE
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-01-10 16:45:42 +01:00
Jan Mulder
37e98a8d89 Use correct date format
A very very trival fix, for a mysterious issue. When loading
GPS fix data from the server, the string date was parsed with
the format "yyy-M-d". And no, the "yyy" is no typo here, but
was the reason that data from the read from server got a
1/1/1970 data. And when a user decided to upload that data
to the server again, we ended up with 2 copies of the
GPS fix. One with correct data (as originally saved), and
one new with the bogus date.

In order to het rid of those weird 1/1/1970 GPS fixes, users
will have to remove them by hand.

Fixes: #567

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-12-25 19:47:57 +01:00
Berthold Stoeger
28ae35e7df Make QMap<> access in deleteGpsFix() more idiomatic
To access a QMap<> entry, the value() function is used with a sentinel
as default value. If the sentinel is returned, the code assumes that
the searched for entry doesn't exist.

Make this code more idiomatic by using an iterator and testing for
end().

This fixes a compiler warning, because only one of the elements of
the sentinel was initialized, but the remaining elements were
copied. Harmless, because the code would exit early if it found
the sentinel. Still not nice.

While redoing this function, the entry-not-found message was improved
(adding of function name, space between massage and timestamp) and
elevated from debug to warning level.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-21 00:04:30 +01:00
Jan Mulder
3479c9e197 applying gps fixes: group repetitive code under a macro
See 2182167b53. Keep the dupicated code in sync.

Originally-by: Salvador Cuñat <salvador.cunat@gmail.com>
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-12-13 05:07:15 -08:00
Jan Mulder
ee9531f76e Do not prefer gps fixes just for being into dive time
See commit 6f42ab46da. Unfortunately, this code is duplicated
(and an obvious candidate for code cleanup). So replicate the mentioned
commit here. In fact, the mentioned issue #666 talkes about the mobile
app, and the fix was only done for the desktop.

Originally-by: Salvador Cuñat <salvador.cunat@gmail.com>
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-12-13 05:07:15 -08:00
Lubomir I. Ivanov
56e755b711 Use lrint() for all degrees_t related rounding
In certain places the '(int)' cast is used, while in other the
llrint() or lrint() functions. Make the conversation from degrees
in the 'double' form to the 'int' degrees_t consistent using lrint().

lrint() is the function which should give the best results,
because it accepts a 'double' and results in a 'long'
even if degrees_t is 'int'. If the truncation from 'long' to 'int'
is discarding some of the precision then the next step
would be to turn degrees_t into a 64bit signed integer type.

Possible fix for #625.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-10-09 13:38:58 +03:00
Stefan Fuchs
7713c7e607 Use helper function dive_endtime() where apropriate
Calculating dive.when + dive.duration doesn't always give the correct
endtime of a dive especially when a dive has surface interval(s) in
the middle.
Using the helper function dive_endtime() fixes this issue.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-10-01 23:55:37 +03:00
Jan Mulder
fd03621a4b Mobile: honour location service time threshold
Independ of the settings, the threshold to reset the GPS data was
hard coded to 5 minutes. Now, honour the entered (and updated during
a session) time to refresh the GPS data in the location service.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-07-25 22:12:19 +09:00
Dirk Hohndel
38af1f2ab9 Check if we have an instance before dereferencing it
If we don't have a GPS service userid in the preferences and the GpsLocation class
isn't instantiated, this would cause a crash.

Fixes #367

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-05-06 11:12:07 -07:00