Commit graph

1100 commits

Author SHA1 Message Date
jan Iversen
ce358fdb68 core: qPref private add macros to replace disk* functions
Use a private QSettings variable, instead of declaring it each time

Add macros to handle full disk* functions

Signed-off-by: Jan Iversen <jani@apache.org>
2018-07-07 09:44:06 -07:00
jan Iversen
e5dace2233 core: copy Display from SettingsObjectWrapper to qPref as its own class
copy Display from SettingsObjectWrapper to qPref as its own class
file. Update Display to use a common load/sync scheme.

Update set/get functions to follow common name scheme:
- get function have same name as in struct preferences
- set function have set_<name in struct preferences>
- signal function have <name in struct preferences>_changed

one class one .h/.cpp is the C++ idiom. Having load/sync of each
variable in 1 functions (in contrast to the distributed way SettingsObjectWrapper
handles it) secures the same storage name is used. Having the set/get/load/sync
functions grouped together makes it easier to get an overview.

REMARK: this commit are made to show the use of the low level LOADSYNC macros, which will
be used for special cases. This class is NOT linked into the live system.

Signed-off-by: Jan Iversen <jani@apache.org>
2018-07-07 09:44:06 -07:00
jan Iversen
55c3afc075 core: pref.h rename showDeveloper to show_developer
change to use same name pattern as other variables.

Signed-off-by: Jan Iversen <jani@apache.org>
2018-07-07 09:44:06 -07:00
Dirk Hohndel
cd5eed4605 git storage: avoid warning about "Unmatched action 'hash'"
In commit f3ef38ca0d ("Dive pictures: remove hashes") we removed picture
hashes, but removing them from the git parser causes an ugly red warning when
opening an existing cloud storage repo. With this patch we just silently ignore
the hash.

Fixes #1473

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-07-07 07:35:45 -07:00
Dirk Hohndel
03bc40194d core: don't crash on merge of non-existing dive site
While we shouldn't have a dive that references a dive site that doesn't exist,
if we do, we shouldn't crash. And a dive site that doesn't exist is most
definitely 'empty'.

Reported-by: Benjamin Fogel <nystire@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-07-06 22:40:18 -07:00
Dirk Hohndel
63297562e6 iOS: find translations again
commit ec0511e824 ("ios: concentrate build dirs") moved the translations around
without updating the way they are accessed, causing our release 2.1.0 on iOS to
not be localized.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-07-03 14:58:00 -07:00
Robert C. Helling
072e404af5 Allow to split dives with more than one dive computer
Only the first computer is taken into account to find
surface intervals. All further dive computers are split
according to time.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-07-03 14:47:15 -07:00
Robert C. Helling
00f4fa0d1d Profile context menu entry to split a dive
Allow the user to manually split a dive in two.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-07-03 14:47:15 -07:00
Robert C. Helling
8697f7a84d Include cylinder pressures upon force_fixup()
Try to recompute cylinder start and end pressures from sample
data.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-07-03 14:47:15 -07:00
Berthold Stoeger
57c01f7a66 Translations: unify gettextFromC::tr() and QObject::tr()
There were two catch-all classes for translations outside of class
context. gettextFromC was used exclusively from C, but C++ used
both, gettextFromC and QObject. Some of the string were even present
in both. Therefore, unify to gettextFromC throughout the code base.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-07-04 05:33:31 +08:00
jan Iversen
2f95141330 core: remove double definition of enum cloud_storage_status
Remove cloud_storage_status from qmlprefs.h.
usage to qPref::

enum cloud_storage_status is not used from C, but only from C++, and
having the same structure defined multiple times is a maintenance
challenge.

Signed-off-by: Jan Iversen <jani@apache.org>
2018-07-04 05:32:30 +08:00
jan Iversen
d02a03983d core: add qPref.h_and qPrefprivate.h
add 2 header files and 1 cpp file (qPrefPrivate does not have an implementation)

The rewrite/consoliadation of SettingsObjectWrapper, qmlmanager, qmlpref and planner
needs a place to put common private parts (qPrefPrivate) and 1 common class (qPref).

Signed-off-by: Jan Iversen <jani@apache.org>
2018-07-04 05:32:30 +08:00
jan Iversen
6c9c2168e1 core: sort CMakeLists.txt
sort .c and .cpp files in CMakeLists.txt

The .c and .cpp files in CMakeLists.txt had no obvious sequence,
sorting it at least gives one understandable sequence

Signed-off-by: Jan Iversen <jani@apache.org>
2018-07-04 05:32:30 +08:00
jan Iversen
889a0bb67a core/profile: move PP_GRAPHS_ENABLED from pref.h
PP_GRAPHS_ENABLED is only used in profilewidget2.cpp
make local to profilewidget.cpp

Signed-off-by: Jan Iversen <jani@apache.org>core/profile: move PP_GRAPHS_ENABLED from pref.h
2018-07-04 05:32:30 +08:00
jan Iversen
36d7f6eafb core: sort struct preferences
sort prefs, making it possible to find variables
add a few missing variables

Signed-off-by: Jan Iversen <jani@apache.org>
2018-07-04 05:32:30 +08:00
Berthold Stoeger
09fd5c40d1 Dive pictures: implement FindMovedImagesDialog
Move the find-moved-images functions into a new translation unit
and present the user with the identified matches before applying
them.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-07-04 02:27:36 +08:00
Berthold Stoeger
f3ef38ca0d Dive pictures: remove hashes
In the last commits, the canonical-to-local filename map was made
independent from the image hashes and the location of moved images
was based on filename not hashes. The hashes are now in principle
unused (except for conversion of old-style local filename lookups).

Therefore, remove the hashes in this commit. This makes addition
of images distinctly faster.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-07-04 02:27:36 +08:00
Berthold Stoeger
0646b41275 Dive pictures: find moved pictures based on filename
Users might have edited their pictures. Therefore, instead of identifying
pictures by the hash of the file-content, use the file path. The match
between original and new filename is graded by a score. Currently, this
is the number of path components that match, starting from the filename.
Camparison is case-insensitive.

After having identified the matching images, write the caches so that they
are saved even if the user doesn't cleanly quit the application.

Since the new code uses significantly less resources, it can be run in a
single background thread. Thus, the multi-threading can be simplified.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-07-04 02:27:36 +08:00
Berthold Stoeger
08962cb38d Dive pictures: index local file name by canonical filname
The connection canonical filename to local filename was done via
two maps:
  1) canonical filename -> hash
  2) hash -> local filename
But the local filename was always queried from the canonical filename.
Therefore, directly index the former with the latter.

On startup, convert the old map to the new one.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-07-04 02:27:36 +08:00
Dirk Hohndel
988d6682f2 Correctly recognize more OSTC variants as BLE
Some OSTC 2 and OSTC Plus variants show 'OSTC+ xxxxx' as BLE name and we
recognized this as OSTC 3 (but that one doesn't support BLE). With this
we recognize these models as OSTC 2 (which is identical from a download
perspective to the OSTC Plus) and both of those support BLE.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-07-02 09:24:30 -07:00
Linus Torvalds
90569e0ee6 Use (and update) dive computer times when merging and splitting dives
When we split a dive in two, we keep the dive computer ID for the dive,
but we should update the actual _time_ of the split dive to match the
split.

And when we look for "are these the exact same dives", we should check
not only that the dive computer dive ID matches, but also that the dive
computer time matches, so that we don't consider two parts of a dive
that has been split to be obviously the same dive.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-07-02 08:38:31 -07:00
Linus Torvalds
3209b490dd Use proper sample pointer when deciding to split dives
The dive splitting was completely wrong, because we checked the time of
the previous sample by doing

	sample[i - 1].time.seconds

which is entirely wrong.  The 'sample' variable is the *current* sample,
so the time of the previous sample is simply

	sample[-1].time.seconds

Alternatively, we could have started from the first sample, and done

	dc->sample[i - 1].time.seconds

but mixing the two concepts up just gets you a random sample pointer
that is likely not a valid sample at all, and obviously does not have
the right time at all.

As a result, dive splitting was pretty much random.  Sometimes it worked
purely by mistake, because the rest of the logic was right (ie we _had_
found the right point where we reached the surface in the dive etc, the
"previous sample time" was simply used to decide if the surface interval
was sufficient to split the dive up).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-07-02 08:36:53 -07:00
jan Iversen
f86dd889bf core: remove prefs-macros.h where unused
move #include prefs-macros from SettingsObjectWrapper.h to SettingsObjectWrapper.cpp
include dive.h directly (only part of prefs-macros.h used) in preference classes

Signed-off-by: Jan Iversen <jani@apache.org>
2018-07-01 22:06:28 +02:00
Berthold Stoeger
1a5e54e5eb Dive pictures: render icons with white instead of transparent background
The SVG icons for failed / still-loading pictures were rendered with an
alpha channel. This lead to strange behavior when hovering over the
icon in the profile plot: When hitting a "hole" the icon would be
minimized again.

Therefore, render the SVGs onto a white background.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-06-28 21:58:29 +08:00
Stephen Goodall
b492df6ffc Add Cressi Giotto, Newton and Drake to list of devices
Adding Cressi Giotto, Newton and Drake to the list of devices
that can be selected on Android devices.

Signed-off-by: Stephen Goodall <stephen.goodall88@googlemail.com>
2018-06-28 11:52:24 +08:00
Dirk Hohndel
314b08c78f QML UI: go back to always saving libdivecomputer logfile
This got disabled as unintended (I hope) side effect of commit
807571a588 ("core: update deviceData default from qml").

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-06-27 16:01:12 -07:00
Stephen Goodall
26871df84d Add Cressi Leonardo to list of devices
Adding Cressi Leonardo to the list of devices that can be selected
on Android devices.

Signed-off-by: Stephen Goodall <stephen.goodall88@googlemail.com>
2018-06-28 01:43:26 +08:00
Berthold Stoeger
db0dd54c37 Localization: make cache thread safe and robust against use-after-free
The old trGettext() was not thread-safe and the returned C-strings
could be freed in the case of empty translations strings. Therefore:

1) Introduce a mutex protecting access to the cache.

2) Never change existing entries, even if the translation string is empty.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-06-24 20:31:14 +02:00
Berthold Stoeger
879cb73b8b Localization: remove gettextFromC::instance()
There were a handfull instances of the kind
1) gettextFromC::instance()->tr(...)
2) gettextFromC::instance()->trGettext(...)

1) is pointless, as tr is a static function.

All instances of 2) were likewise pointless, because trGettext()
returns a C-string, which was then immediately converted to a
QString.

Thus, replace both constructs by gettextFromC::tr(...).

After this change there was only one user of gettextFromC::instance()
left, viz. the C-interface funtion trGettext(). Therefore, remove
gettextFromC::instance() and do all the caching / translating
directly in the global trGettext().

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-06-24 20:31:14 +02:00
Berthold Stoeger
61b8add590 Localization: don't go via C-string in qthelper.cpp
The purpose of the gettextFromC class is twofold:
1) It provides a static storage of C strings if the C part needs
a translation and doesn't want to deal with memory-management.
2) It severs as a catch-all class for translations that do not come
from a proper class (i.e. from helper functions).

The second case was used a few times in qthelper.cpp. By using the
trGettext() function, a cached C-string was obtained. But in every
single instance, this C-string was then back-converted into a QString.
Therefore, use the gettextFromC::tr() function directly, which
returns a QString. Not only is the resulting code simpler - this also
avoids superfluous caching of translation strings.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-06-24 20:31:14 +02:00
Robert C. Helling
8406cbf187 Fix interpretation of dive mode changes upon replan
... by taking into acount that dive planner points refer
to the sement before the waypoint (while change mode
events are concerned with the future of a waypoint).

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-06-24 09:35:55 +02:00
Robert C. Helling
4157365c96 Make planner notes divemode aware...
... and fix a problem with setpoint changes shown in the wrong line

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-06-24 09:35:55 +02:00
Berthold Stoeger
c65617661a Dive pictures: fix loading of remote images without local version
Owing to the recent churn in imagedownloader.cpp, some of the
code was bogus.

Notably, in f60343eebb the code
was changed such that always the local filename was used to access
the images. Yet, the old code remained, which after failure tried
again to access the local picture. This second access can obviously
be removed completely.

More seriously, after failing to load the local version, no
attempt was made to fetch the image via canonical filename. This
could produce the following sequence of events:
  - Import remote image
  - Delete thumbnail and local cache of image
  - Image loading would fail

Therefore, first try to load using local file-location. If
that fails, load using the canonical file-location. To do
so, split the file-access code in two functions. The code
should now be distinctly easier to follow.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-06-22 00:26:02 +03:00
Dirk Hohndel
5377706aca FTDI support: try ftdi_open first if the device name is 'ftdi'
It makes no sense to have the OS try (and fail) to open that device name.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-06-21 16:16:29 +09:00
Dirk Hohndel
b7619553fd core: print the correct message code for download failures
We filled in the missing information and then printed the wrong string.
This fixes that and also makes the strings slightly easier to understand.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-06-21 16:15:48 +09:00
Dirk Hohndel
05a00f31e9 mobile: better message regarding logfiles
On mobile those area always created and available for simple cut and paste.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-06-21 15:49:23 +09:00
Anton Lundin
dcb663e407 Revert "cleanup: remove empty function"
This broke our hook to plumb in our usb open function into libusb, so
this broke ftdi based downloads.

This reverts commit e4530cd5ef.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
2018-06-21 06:28:39 +09:00
Linus Torvalds
98bd303d93 qt-ble: purge pending read data when writing
This should never happen, since our interface is bassically synchronous,
but it could happen with delayed replies that came in just after we
decided to re-transmit a command.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-06-20 16:38:04 +09:00
Linus Torvalds
21d6531e45 qt-ble: improve responsiveness of waiting for bluetooth data
Our model of waiting for 100ms before re-checking if we got a packet
over BLE resulted in potentially horrendously bad latency for received
packets.

That isn't just a possible performance issue, it actually seems to cause
IO errors with my Suunto EON Core.  I'm not entirely sure why, but it
might simply be some timing interaction, particularly since the IO
errors seemed to primarily happen when the dive computer itself was also
busy updating the screen (ie if you pressed buttons on the dive computer
to switch to compass mode, for example).

So replace the silly hardcoded 100ms "waitFor()" function with a
WAITFOR() macro that checks the provided expression every time through
the loop, which gets us a much lower latency (we basically check every
ten milliseconds).

The macro is not beautiful, but it WorksForMe(tm).

This makes a huge difference to the reliability of the download for me,
and might matter for some other dive computers too.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-06-20 16:38:04 +09:00
Lubomir I. Ivanov
9e58e6f0e6 equipment: use MAX_TANK_INFO in equipment.c
MAX_TANK_INFO is defined in dive.h but is not
used in add_cylinder_description() or when
allocating 'tank_info'.

Use MAX_TANK_INFO instead of the literal 100.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2018-06-20 09:30:58 +09:00
Lubomir I. Ivanov
06a870c232 equipment: sanitize 'ws_info' loop limits
Instead of a constant or a macro for the maximum
number of 'ws_info' elements the 100 literal was used.

Define MAX_WS_INFO in dive.h and use it everywhere.

Also clamp loops that iterate `ws_info' to MAX_WS_INFO.
Prevents potential out-of-bounds reading, similarly to
the previous commit about 'tank_info'.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2018-06-20 09:30:58 +09:00
Lubomir I. Ivanov
769aca9e95 equipment: sanitize 'tank_info' loop limits
In a number of places the global 'tank_info' array
is being iterated based on a 'tank_info[idx].name != NULL'
condition.

This is dangerous because if the user has added a lot of tanks,
such loops can reach 'tank_info[MAX_TANK_INFO]'. This is an
out of bounds read and if the 'name' pointer there happens to be
non-NULL, passing that address to a peace of code that tries
to read it (like strlen()) would either SIGSEGV or have undefined
behavior.

Clamp all loops that iterate 'tank_info' to MAX_TANK_INFO.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2018-06-20 09:30:58 +09:00
Dirk Hohndel
a5380bb741 core: add free_samples helper
And use it in the UI and planner code.

See #1411

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-06-20 09:27:11 +09:00
jan Iversen
cabc5859fd core: use num in alloc_samples
When num > dc->alloc_samples we whould allocate space for num

Signed-off-by: Jan Iversen <jani@apache.org>
2018-06-20 07:59:07 +09:00
Berthold Stoeger
3932c97af7 libdc interface: remove debug messages
Don't spill supported transports as error message to the user.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-06-18 06:25:40 +09:00
Berthold Stoeger
1f654050fa Dive computers: turn QMultiMap into sorted vector
The list of known dive computers was stored in a multi-map indexed
by the device name. Turn this into a sorted QVector. Thus, no
map-to-list conversion is needed in the device editing dialog,
which distinctly simplifies the code.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-06-17 06:53:13 +09:00
Berthold Stoeger
8e8cd7a8d9 Cleanup: remove eplicit constructors and unused member variable
Remove the explicit constructor in DiveComputerNode: Just use
classical C-style struct initialization. Moreover, remove the
empty constructor and destructor of DiveComputerList.

The variable DiveComputerList::dcWorkingMap was unused. Remove.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-06-17 06:53:13 +09:00
Stefan Fuchs
0bc9edf855 Fix an error around translation of dive modes in the UI
This fixes an mistake introduced in
3d1072f886

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-06-17 06:36:20 +09:00
Miika Turkia
076419d757 DM5 import: support for larger sample size
Suunto has updated SampleBlob to use 30 byte blobs. This adds support
for the increased size. Note that this only parses the same fields we
have parsed before. (Currently I have no idea what the increased size is
used for.)

Note also that I do not currently have data with the new format so I
only tested this still works with old data.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2018-06-15 17:45:33 -07:00
jan Iversen
54db1309a0 core: make prefs-macros compile safe.
add {} in each macro to secure it works as a single statement,
to avoid problems like
  if (1)
      GET_TEXT();

Signed-off-by: Jan Iversen <jani@apache.org>
2018-06-15 14:11:57 -07:00