Commit graph

2198 commits

Author SHA1 Message Date
Berthold Stoeger
eb55ffde16 cleanup: split uiLanguage() in two functions
The uiLanguage() function was used for two purposes: to initialize
the language related preferences and to read the current language.
To make things more easy to follow, split this function in two:
one for initializing, one for getting the current language.

Moreover, don't return the current locale in an out-parameter
as there is already a function to do that [getLocale()].

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-22 12:01:09 -07:00
Berthold Stoeger
2dca7d0ce5 locale: store locate to preferences after fixing up mac-weirdness
In uiLanguage() the preferences fields are initialized and there
is fixup for a MacOS indiosyncrasy. For some reason the uncorrected
value is written to the preferences. Let's store the corrected
value instead.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-22 12:01:09 -07:00
Berthold Stoeger
621d00d891 cleanup: don't call uiLanguage() in qPref::loadSync()
uiLanguage() initializes the language fields from the preferences
values. It is unclear why this function is called in qPref::loadSync()
*before* the fields are loaded from disk. It can only initialize to
the default values anyway. After qPref::loadSync() uiLanguage()
is called again so that everything can be initialized with the
correct perferences values.

Remove the first call. If things break, let's fix them in a sensible
way.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-22 12:01:09 -07:00
Berthold Stoeger
2db7d5cc23 Revert "core: use set_lang_locale to modify prefs.locale.lang_locale"
This reverts commit 573a4a5e2d.

The commit broke setting the language in the desktop preferences:
Instead of setting the locale in the prefs struct, the locale
is set via qPrefLanguage. However, that saves the default language
(extracted from the system) to disk. Now when the language is
read from the preferences, we get that default value.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-21 21:06:36 -07:00
Berthold Stoeger
f4f15039ac Ignore invalid dives in statistics
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-20 15:20:44 -07:00
Berthold Stoeger
0d78fe45c3 Core: consider invalid flag when adding dives
Adding dives uses the number of the last dive to create a new
dive number. Ignore invalid dives.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-20 15:20:44 -07:00
Berthold Stoeger
95b60d1b18 Filter: hide invalid dives
Hide invalid dives if prefs.display_invalid_dives is false.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-20 15:20:44 -07:00
Berthold Stoeger
4e47cdfa2c Undo: implement invalidate-dive command
Connect command to context menu.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-20 15:20:44 -07:00
Berthold Stoeger
329641fdcd Core: introduce invalid flag for dives
Implement reading/writing the flag from/to XML/git.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-20 15:20:44 -07:00
Dirk Hohndel
eb76bdb3e3 cleanup: fix mis-spelling of UCT in comments as well
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-19 08:41:19 -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
2da7b6d0f5 cleanup: remove record_dive() function
No user left.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-17 16:50:20 -07:00
Berthold Stoeger
ed3e68c36a git: load into arbitrary dive tables
The git parser loads into the global dive table, even if it
is called indirectly via parse_file(). However, parse_file()
may be given a different table. Fix this by extending the
git parser state.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-17 16:50:20 -07:00
Berthold Stoeger
4bd217299a mobile/edit: don't add dive site twice to table
When editing a dive on mobile we might have to create a new
dive site. That site is added to the global dive site table
in the undo command. However, the code in QMLManager created
the dive site with create_dive_site*() functions, which already
adds it to the table. The undo command then added the dive
site again leading to a hang of the application.

To solve this problem, create new alloc_dive_site*()
functions that do the same as create_dive_site*()
but do not add it to the table.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-17 14:05:24 -07:00
Berthold Stoeger
71f573da2a git: return strdup()ed empty string on error in pop_cstring
The pop_cstring() function is used by the git parser to
duplicate a quoted string. On error, it returns an empty
string literal. Since the caller expects a copied string
and takes ownership of that string, it will ultimately
be freed.

Concrete example: a log with erroneous cylinder data was opened
getting such an empty string literal as description. On closing or
syncing with the cloud, the dive is freed, leading to a free
of the string literal -> crash.

Return a copy of the empty string instead.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-16 10:57:12 -07:00
Dirk Hohndel
2265a27912 android/usb: better memory management
Instead of relying on the std::vector staying unchanged and not freeing
its members, instead keep a copy of the object in our DCDeviceData class.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-16 07:58:20 -07:00
Dirk Hohndel
0b72495413 android/usb: simply restart the download after receiving permission
If the user tries to download from a device that he hasn't given the app
permission to read from, Android will pop up a dialogue asking for that
permission. With this after giving the permission we continue (well,
technically, restart) the download which is likely the expected behavior.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-16 07:58:20 -07:00
Christof Arnosti
87e12029f9 android/usb: remove "autoselect driver" option for unknown VID/PIDs
Signed-off-by: Christof Arnosti <charno@charno.ch>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-16 07:58:20 -07:00
Dirk Hohndel
ec3a968df9 android/usb: pass in the UsbDevice when downloading
This finally allows us to download from not just the first device, but specifically
the device that the user picks.

Passing the object through a void pointer is not nice - but since this traverses
C code other solutions (like passing an index into the list) seemed even worse.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-16 07:58:20 -07:00
Dirk Hohndel
b0eccec8ed android/usb: pass the usbDevice for intent handling
Instead of creating a string with all the object information, simply pass
the actual object to the C++ code.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-16 07:58:20 -07:00
Dirk Hohndel
c19e3bd5ba android/usb: remove alternative way of scanning for devices
We now always create a list of usb devices that doesn't list a driver
for known devices, and adds multiple entries with each of the drivers
for devices that are unknown to us.

This removes some debugging output in the ..._open() function as well.

This could be combined with Christof's earlier commit.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-16 07:58:20 -07:00
Dirk Hohndel
c81854ca21 android/usb: add helper to recognize chipsets known to us
This will allow us to know when we can guess the driver.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-16 07:58:20 -07:00
Dirk Hohndel
c2077992ff android/usb: guess the actual manufacturer and product
For a small number of dive computers we can actually figure out the
real information which we can then later show to the user.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-16 07:58:20 -07:00
Christof Arnosti
ce7d4d1ca6 usb-serial-for-android: More fields in device descriptor
As discussed in issue #2657, there are now more fields about the usb
device information in android_usb_serial_device_descriptor.

Additionally, the user-facing string now makes more sense:
"vendor [<bus# as integer>:<dev# as integer>]"
Where vendor is as reported by android, but shortened to 16 characters.

Examples:
FTDI [1:2]
Silicon Labs [1:4]

Signed-off-by: Christof Arnosti <charno@charno.ch>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-16 07:58:20 -07:00
Christof Arnosti
344f7861b4 usb-serial-for-android: Use correct format spezifier for size_t
Signed-off-by: Christof Arnosti <charno@charno.ch>
2020-03-16 07:58:20 -07:00
Christof Arnosti
a34a81d120 android usb serial: Prepare device / driver select
This commit contains the serial_android_usb part of the changes proposed
in issue #2657.

What's implemented:
- A data structure that contains all the data that can be used to
  describe an usb device (including user-facing string).
- A function to get a list of all attached usb devices (optionally with
  selectable driver class).
- Changes in the serial_android_usb_open-function and in the Java part
  to use the information about the usb device and optionally selected
  driver when connecting.

This commit keeps compatibility with the current UI-Code in the case
that only one USB-Device is connected. If two devices are connected,
only the first one is tried.

There are still some small things to do:
- Change the user-facing string to something more descriptive.
- Parts which aren't uesd anymore when the UI-Part is implemented are
  simply marked as obsolete (to keep compatibility for now).

But generally it seems to work.

[Dirk Hohndel: some white space / coding style adjustments]

Signed-off-by: Christof Arnosti <charno@charno.ch>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-16 07:58:20 -07:00
Linus Torvalds
5e89d81d9d iostream: fix incorrect rfcomm error case when writing
This is the exact same case as the previous commit, just for the writing
side.

Once again, it's the subsurface rfcomm iostream code that can return
DC_STATUS_SUCCESS with a byte count of zero when something goes wrong
with the write.

And once again, our libdivecomputer iostream code didn't try to be
robust and protect itself from that case.

The fix is equivalent, although slightly simpler, since the write side
doesn't have the whole timeout issue.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-03-14 11:34:46 -07:00
Linus Torvalds
4ee4bbdb58 iostream: fix incorrect rfcomm error case when reading
We had two independent bugs here, both of which needed to fire for this
to cause a problem.  This fixes both of them.

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

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

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

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

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

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

to prevent future wincing when reading the source code.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

For now, compile only on desktop.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

which is obviously wrong.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Fixes #2037

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2020-02-06 08:46:52 -08:00
Berthold Stoeger
317ee2f104 Dive site: inform map of selection in DiveFilter::setFilterDiveSite
When starting / changing the dive-site filter, inform the map of
the changed dive site selection by calling
	MapWidget::instance()->selectionChanged();
This fixes a bug, where on clicking dive sites in the dive site
tab the dive sites from the *previous* click were highlighted.

Perhaps the selectionChanged() call should be put into the
setSelected() call. But the data flow between the different
parts of the dive-site and map code are so convoluted that I
don't want to risk anything!

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-02-04 02:17:36 +01:00
Berthold Stoeger
9ed886e4be Cleanup: lower-case filenames in core/subsurface-qt/
We tend to use lower-case filenames. Let's do it for these files
as well. Simple search & replace.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-02-04 02:16:46 +01:00
Lubomir I. Ivanov
e69f5c4e28 core/qtserialbluetooth.cpp: use QEventLoop for polling
The Qt docs here:
https://doc.qt.io/qt-5/qbluetoothsocket.html#details
and here:
https://doc.qt.io/qt-5/qabstractsocket.html#waitForReadyRead

say that waitForReadyRead() does not work for QBluetoothSocket
and that it's flaky on Windows for the underlying QAbstractSocket.

Use a QEventLoop and a QTimer to poll the readyRead() signal.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2020-01-27 09:51:31 -08:00
Linus Torvalds
aceb8a547f rfcomm: make Windows use QtBluetooth too
Windows had it's own direct socket implementation for rfcomm (ie legacy
BT), while all the other platforms used QtBluetooth.

This makes Windows do the same thing.  Hopefully modern Qt libraries now
work well enough on the Windows platform for this to work, but I can't
test it.

We can make a test build that Windows people can try, though.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-01-27 09:51:31 -08:00
Linus Torvalds
9543f53150 Update to new libdivecomputer version
Jef has changed the libdivecomputer iostream layer and extended it in
two different ways:

 - iostram's now have a 'poll()' method, which does what the name
   implies: waits for data to be available with a timeout.

 - iostreams now have a 'ioctl()' method, which can be used to implement
   miscellaneous operations. Right now the two ones that you can do are
   "set latency" (this replaces the old 'set_latency()' method) and "get
   BLE name" (this replaces our 'get_name()' method that was never part
   of the upstream libdivecomputer interfaces)

Neither of these is all that complicated, and the transition is fairly
obvious.

HOWEVER.

I have absolutely no idea how to do 'poll()' on Windows sockets, and I
have no intention of figuring it out.  We use a direct socket interface
to implement the (non-BLE) RFCOMM bluetooth serial protocol, and I'm not
sure why Windows is so special here.  I suspect - but cannot test - that
we should just switch the Windows RFCOMM implementation over to the use
the same QtBluetooth code that we use on other platforms.

I assume that the Windows Bluetooth support was originally not
sufficiently good for that, but these days we depend on Qt doing BLE for
us even on Windows, so presumably FRCOMM works too.

That would be a nice cleanup, and would make 'poll()' work on RFCOMM
under Windows too.  However, since I can't test it, I've not done that,
but instead just made the Windows RFCOMM 'poll()' method always return
success.  That may or may not get the thing limping along.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-01-27 09:51:31 -08:00
Dirk Hohndel
2268b6b212 code cleanup: QLatin1Literal is deprecated in Qt 5.14
Simply replace it with QLatin1String. There is a tiny performance penalty,
but none of that code would care.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-26 16:49:42 -08:00
willemferguson
ff18de053f Parse GPX dive coordinates: Qt XML framework
This replaces the C-code XML parsing with a Qt infrastructure.
QXmlStreamReader is used to parse the GPX file.

It also takes into account comments by @neolit123

Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
2020-01-25 23:25:33 +02:00
Dirk Hohndel
ee5a156498 core: move GPX parsing into core
This shouldn't be part of the desktop UI code; there's still the issue that we
really shouldn't hand code XML parsing, but I'll leave that for later.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-24 09:51:02 -08:00
jan Iversen
77352751fa core/settings: removed unnecessary if
prefs.unit_system is set at the top, so no need to set it again.

Signed-off-by: jan Iversen <jan@casacondor.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-20 09:55:57 -08:00
jan Iversen
ed4e7e3fc4 core/settings: correct signal error
prefs.unit = x  needs to be after the setters are called, otherwise the setter
will not do anything, and result in an inconsistency between the values stored
on disk and in prefs.units.

Signed-off-by: jan Iversen <jan@casacondor.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-20 09:55:57 -08:00
jan Iversen
6e06550631 core/settings:: remove string functions for units
Remove string version of unit_system, duration_units, length, pressure,
temperature, vertical_speed_time, and volume, including tests and make signals
strongly typed in C++

Signed-off-by: jan Iversen <jan@casacondor.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-20 09:55:26 -08:00
jan Iversen
13b2b9f19c core/settings: allow signals to be strongly typed in C++
Register enums to allow them to be used in signal handlers instead of int.

Signed-off-by: jan Iversen <jan@casacondor.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-20 09:49:49 -08:00
jan Iversen
c93b76eee6 mobile-widgets: make cloud_verification_status type proof in QML.
Add CLOUD_STATUS enum to interface.

Add cloud_verifification_status variable to interface, and make
it strongly typed in QML.

using backend.cloud_verification_status = 1 will fail but
backend.cloud_verification_status = backend.CS_UNKNOWN is correct.

Added note to the original definitions of the enums that they have been
duplicated.

Signed-off-by: jan Iversen <jan@casacondor.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-18 17:35:04 -08:00
jan Iversen
fdc2fd35bf mobile-widgets: add pure interface for passing values to QML
Add a header file that contains a duplicate of the enums,
that are needed in QML in one class.
the unit enums are added imidiatly, since they are needed
or will be neede shortly in Settings and DivePlannerSettings

This class will also contain Q_PROPERTY and signal/slot for
variables used in QML. This is done to allow e.g.

deco_mode qPrefUnits::planner_deco_mode()
void qPrefUnits::set_planner_deco_mode(deco_mode)
as strongly typed in C++
and
DECO_MODE planner_deco_mode()
void set_planner_deco_mode(DECO_MODE)
as strongly typed in QML
Remark: wrong assignments gives errors in QML

The advantage over using strings or the value directly is that
QML detects typos and flags them as errors/warnings.

It is important to note that the class may only contain
a) a function call to the implementation
b) a reference to a global variable e.g. prefs.

Added note to the original definitions of the enums that they
have been duplicated.

Signed-off-by: jan Iversen <jan@casacondor.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-18 17:31:58 -08:00
jan Iversen
008f350dec core/settings: remove PrefClearDC because not used.
PrefClearDC was registred with the wrong object, but also
is not used.

Remove registration.

Signed-off-by: jan Iversen <jan@casacondor.com>
2020-01-17 08:51:04 -08:00
jan Iversen
36b2014183 core/settings: correct copy/paste error.
The registration for several Pref* point at wrong C++ object,
correct the paste error.

Signed-off-by: jan Iversen <jan@casacondor.com>
2020-01-17 08:51:04 -08:00
Dirk Hohndel
e1cd055111 code cleanup: add empty table structures
It seemed to make sense to combine all three types in one commit.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-10 02:37:03 +09:00
Dirk Hohndel
70cabb968c code cleanup: use explicit zero_location
Again, several different ways to achieve the same thing.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-10 02:37:03 +09:00
Dirk Hohndel
247194e839 code cleanup: use gasmix_air for zero initialized gas
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-10 02:37:03 +09:00
Dirk Hohndel
c81693d023 code cleanup: consistently initialize zero duration_t
There were three different ways (two of which generated warnings) in a single
source file.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-10 02:37:03 +09:00
Dirk Hohndel
cef30619d0 code cleanup: introduce empty_cylinder constant
This deals with the issue of initializing structs in C++.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-10 02:37:03 +09:00
Dirk Hohndel
daf3821fcc code cleanup: replace created() with birthTime() for Qt >= 5.10
We still support Qt5.9 for now, so we need the version check as birthTime() wasn't
available in 5.9.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-10 02:37:03 +09:00
willemferguson
d2cf58e07e core: read and write the user-specified salinity
Both XML and git storage are added.

Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-06 07:00:34 +09:00
willemferguson
ebabbfb457 desktop UI: create the UI components for editing the salinity.
The user may modify the salinity by selecting a water type from the combobox.
The new datum does not replace the existing salinity value but is stored in a
separate variable within the dive structure. If the dc-based salinity is
overwritten, there is an exclamation mark next to the modified salinity value
to indicate that the salinity has been overwritten. The dc-derived salinity can
always be recovered by selecting the "use dc" option in the combobox.

Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-06 07:00:34 +09:00
willemferguson
732d5a9fbd desktop UI: add preference for making salinity editable
Create a checkbox in the Preferences: General screen that enables or disables
editing of the salinity data. This preference is saved with all the other
preferences.

Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-06 07:00:34 +09:00
Robert C. Helling
95a0a0f5a6 Fix get_divemode logic
Commit dbb504 tried to prevent an uninitialized dc pointer
from being dereferenced. But I screwed up the logic always
setting the event pointer to NULL. This fixes this error.

Reported-by: willemferguson@zoology.up.ac.za
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2020-01-05 04:15:42 +09:00
jan Iversen
347a002923 core/settings: qPrefUnit, secure original signal gets emitted
When using the string setters, the original signal should still be emitted.

Change to call original setter in string setter.

Signed-off-by: Jan Iversen <jan@casacondor.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-04 10:56:55 -08:00
jan Iversen
1d58d11676 core/settings: force sending of signal when unit type changes
When changing between METRICS <-> IMPERIAL, all type signals are emitted.

This may cause double sending of some signals, but all signals will be emitted
at least once.

Signed-off-by: jan Iversen <jan@casacondor.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-04 10:56:55 -08:00
jan Iversen
fdff61f6af core/settings: change measurements when changing metric/imperial
When switching between imperial/metric it is important to change the single
measurements as well (e.g. METER <-> FEET).

Signed-off-by: Jan Iversen <jan@casacondor.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-04 10:56:55 -08:00
jan Iversen
14db760044 core/settings: split "normal" version of unit_system
All unit functions have a string version and a normal version, except
unit_system.

Make a non string version of unit_system.

Signed-off-by: Jan Iversen <jan@casacondor.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-04 10:56:55 -08:00
Dirk Hohndel
9be028659e tests: fix TestQPrefLog
There were several issues with these tests, including checking
the value argument against bool values even if the underlying
preference isn't bool.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-12-29 12:31:43 -08:00
jan Iversen
fc7aec5402 core/settings: make qPrefUnit accesable from QML
Use string literals to communicate with QML.

Instead of passing arounds enum/int value, it seems easier to pass string literals to QML and have that code respond to those

Signed-off-by: Jan Iversen <jani@apache.org>
2019-12-27 04:03:25 +09:00
jan Iversen
573a4a5e2d core: use set_lang_locale to modify prefs.locale.lang_locale
Do not set prefs.locale_lang_locale directly, but do it
indirectly through qPrefLanguage::set_lang_locale(),
to ensure the file plist is consistent with prefs.

the difference (prefs. contra plist) cause surprises
when restarting mobile (and playing with language).

Signed-off-by: Jan Iversen <jani@apache.org>
2019-12-27 03:41:20 +09:00
willemferguson
6212bb6721 Preferences UI: final cleanup
This commit does some final cleaning up to the code, mostly deleting
white space and comments.

Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-12-25 02:57:42 +09:00
willemferguson
b6c3cdb20c Preferences UI: add dive log tab
This adds a tab for dive log - related preferences.
A suitable test programs is still required.

Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-12-25 02:57:42 +09:00
willemferguson
b24caa4e2d Preferenced UI: add dive download tab
Add a preferences tab for dive download, allowing resetting the
buttons representing download connections in the Download panel.

Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-12-25 02:57:42 +09:00
willemferguson
2ac279d129 Pereferences UI: add media tab
Remove the preference settings dealing with thumbnails (currently under
General preferences and Profile preferences) and put them in a newly-created
Media preference tab.

Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-12-25 02:57:42 +09:00
willemferguson
3e853e37a5 Preferences UI: create new equipment tab
Remove the "Show unused cylinders" checkbox (Profile tab) and the
"Set default cylinder" qTextEdit box (General tab) and put them in a
separate and new Equipment tab. This sounds like a simple task but,
as can be seen from the files changed, was actually a complex matter.
Adapt the existing test programs (General and TechDetails) for creating
a test program that tests parts of the Equipment tab.

Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-12-25 02:57:42 +09:00
jan Iversen
7751ec1c78 build-system: move plannerShared to backend-shared
WARNING: multi directory commit, needed to secure it builds.

move the core/plannerShared.* to backend-shared.

update CMakeLists.txt to include backend-shared lib in link process.

update ios project to reflect new directory

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-24 08:44:23 +09:00
jan Iversen
9c52aaf043 build-system: move exportfuncs to backend-shared
WARNING: multi directory commit, needed to secure it builds.

move the core/exportfuncs.* to backend-shared.

update backend-shared/CMakeLists.txt to generate backend-shared lib

update CMakeLists.txt to include backend-shared lib in link process.

update ios project to reflect new directory

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-24 08:44:23 +09:00
jan Iversen
7181b7bcd1 core: correct include in exportfuncs
change include "dive.h" to "core/dive.h", in order to prepare
the file to moved away from core.

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-24 08:44:23 +09:00
jan Iversen
f291e5e2d8 core: add convert between meter/feet to plannerShared
qPrefDiveplanner contains settings for ascent and descent in a neutral format.
diveplanner desktop uses a macro UNIT_FACTOR to convert between UI values and
qPref values.

In order not to dublicate these calculation (in C++ and QML) a set of shared
functions are made. The functions are identical to the calculations in diveplanner
desktop.

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-24 06:30:57 +09:00
jan Iversen
c0069d6aee core: add plannerShared class
Add a plannerShared class, whose purpose is to contain shared
functions between mobile and desktop

This class is the inner workings of the diveplanner not the UI

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-24 06:30:57 +09:00
jan Iversen
bf7954ebe7 core: remove LOG_STP from mobile
LOG_STP is on longer providing the data needed, since a lot of the startup
is indirectly in QML, furthermore using the xcode project and running profiler
gives much more detailed information

Signed-off-by: Jan Iversen <jani@apache.org>
2019-12-13 07:04:00 -05:00
jan Iversen
820d9bcd56 core: divehare avoid race problem.
Do reply->readAll() before reply-deleteLater()

With UI deleteLater() seems to happen after the function exist,
but with QML it causes problems.

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-12 10:10:01 -05:00
jan Iversen
aefe87112a core: divehare change slot names
change slot names from slot_* to *Slot

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-12 10:10:01 -05:00
jan Iversen
8ff19b6d54 core/settings: qPrefCloudStorage, correct diveshare_uid naming
The variable in Q_PROPERTY was wrongly named diveshare_userid

change diveshare_userid to diveshare_uid

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-12 10:10:01 -05:00
jan Iversen
85e6e90559 core: uploadDiveLogsDE::prepareDives no longer need to be public
Integration into desktop-widgets is complete.

Move prepareDives() from public to private

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-12 10:10:01 -05:00
jan Iversen
cb252f39d7 core: corrected timeout and error text problem in uploadDiveLogsDE
incorrectly stopped timer before the upload was started.

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-11 12:36:43 -05:00
jan Iversen
5a4128a8f2 core: add uploadStatus signal to uploadDiveLogsDE
The uploadStatus signal can be used to inform the user about
the process e.g.
- preparing zip file
- starting actual upload

It is a suplement to uploadProgress, that only informs about
the network part.

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-11 12:36:43 -05:00
jan Iversen
10ab833d7d core: make uploadDiveLogsDE slots workable for desktop
Secure that the slots/signals in uploadDiveLogsDE, which are without
UI, can be used in DivelogsDeWebServices (to add the UI part).

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-11 12:36:43 -05:00
jan Iversen
fa8acc0f40 core: rename slot in uploadDiveLogsDE
The difference between slot names and signal names was to insignificant
e.g. uploadFinish (signal) uploadFinished (slot).

Change slot names to slot_<name> should clear any confusion.

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-11 12:36:43 -05:00
jan Iversen
d9f637a815 core: make prepareDives public in uploadDiveLogsDE
prepareDives needs to be public, in order to be used in
subsurfacewebservices.

"friend" is another option, but that gives subsurfacewebservices
too much freedom.

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-11 12:36:43 -05:00
jan Iversen
49e6330399 core: make shared prepareDives identical to desktop prepare_dives_for_divelogs
In order to replace DivelogsDeWebServices::prepare_dives_for_divelogs with
uploadDiveLogsDE::prepareDives, first step is to make the functions identical.

amount_selected is not maintained for mobile, add #ifdef SUBSURFACE_MOBILE

Add comment, to make code more readable

add white line to make code more readable

change to use variable ds (created a couple of lines earlier

Avoid "goto" by adding close code

Remove label and close code (it was only called in 1 place)

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-11 12:36:43 -05:00
jan Iversen
738d3057da core: correct QString arg problem
use report_error directly, instead of making a QString first,
argument syntax are different (%s vs. %1)

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-11 12:36:43 -05:00
jan Iversen
976b2fc2a7 core: add timeout.stop() if upload successful
Stop timeout not only in case of errors, but also in
positive case.

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-11 12:36:43 -05:00
jan Iversen
eb08f17a03 core: add upload divelogs.de class
The implementation is based on class DivelogsDeWebServices in
desktop-widgets but without the UI entanglement

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-11 12:36:43 -05:00
jan Iversen
42939ab7f8 core/settings: extend qPrefCloudStorage with divelogsde user info
Add divelogsde_userid and divelogsde_password to
qPrefCloudStorage to be used in Export.qml

Extending qPrefCloudStorage is more logical than adding QSettings
(and securing the same behaviour) outside qPref.

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-11 12:36:43 -05:00
jan Iversen
fc740f6369 core: change uploadFinish() to include html
diveshareexport wants to show the HTML received
in a positive response, so signal cannot be
compatible with diveLogsDE

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-11 11:08:51 -05:00
jan Iversen
e3416fa152 core: copy doUpload from desktop-widgets to core
Add DiveShareExportDialog::do_upload() to
uploadDiveShare::do_upload(), while cleaning it from
UI.

Add signal connections as used in uploadDiveLogsDE

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-11 11:08:51 -05:00
jan Iversen
0a01072deb core/settings: extend qPrefCloudStorage with diveshare uid/private
Add diveshare/uid and diveshare/private to qPrefCloudStorage
to be used in Export.qml as well as diveshareexportdialog

Extending qPrefCloudStorage is more logical than adding QSettings
(and securing the same behaviour) outside qPref.

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-11 11:08:51 -05:00
jan Iversen
e8e425edd8 core: add upload dive-share.com class
This is the framework that mobileExecutable needs, all
prepared to move functionality from desktop-widgets
(current implementation) into a shared version.

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-11 11:08:51 -05:00
Berthold Stoeger
358fddd24e Filter: send filterReset via signal
The old code called directly into the DiveListModel. Instead,
send a signal and hook into the signal from the model. This
will allow us to remove the DiveListModel::instance() function.

This, in turn, is a step towards supporting multiple models
at the same time. However, currently the model manually
sets the hidden_by_filter flag in the core and therefore
only one active model is supported at a time.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-10 18:45:30 -08:00
Berthold Stoeger
f4f9ba9263 Selection: provide convenience function for single-dive selection
Currently, selecting a single dive or deselecting all dives was
quite awkward: One had to pass in a single-dive vector and the
dive itself (as current dive). Provide a convenience function
that selects a single dive or deselects all dives if null is
passed in.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-07 10:23:44 -08:00
jan Iversen
90b8ccb705 core/settings: remove Q_PROPERTY warning in qPref headers
Q_PROPERTY contains an internal ";", making clang produce a warning
when ending the line with a ;

Remove ; at the end of Q_PROPERTY lines.

Signed-off-by: Jan Iversen <jani@apache.org>
2019-12-05 11:48:26 -08:00
jan Iversen
653a2baf11 core/settings: make qPref* constructors private
Signed-off-by: Jan Iversen <jani@apache.org>
2019-12-05 11:48:26 -08:00
jan Iversen
54f8217eec core/settings: make qPrefGeocoding functions static
Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-05 11:48:26 -08:00
jan Iversen
d0dcc7b32a core: correct cloudstorage.cpp to use static qPrefCloudStorage functions.
qPrefCloudStorage set/get functions are static.

remove creation of qPrefCloudStorage instance, reference
static functions.

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-05 11:48:26 -08:00
Berthold Stoeger
e114522a44 Cleanup: set description to null in free_[weightsystem|cylinder]
Currently, the caller is responsible for not reusing a freed
weightsystem / cylinder or resetting the description field to
null. This is very unfriendly. Set the description field to null,
because that allows us to call free_* repeatedly on the same
object. Use the new behavior to make the weightsystem model code
a bit cleaner.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-05 10:14:25 -08:00
Berthold Stoeger
72c6b83866 Undo: make weight editing undoable
Implement the EditWeight undo command. Since there is common code
(storage of the old weight), this creates a common base class for
RemoveWeight and EditWeight. The model calls directly into the undo
command, which is somewhat unfortunate as it feels like a layering
violation. It's the easy thing to do for now.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-05 10:14:25 -08:00
Berthold Stoeger
ab99ca85f1 Cleanup: use free_weightsystem function instead of explicit free
Instead of freeing internal data of the weightsystem structure,
call the free_weightsystem function (which has to be made extern
at first). This makes things more future-proof, should the
weightsystem struct ever be extended.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-05 10:14:25 -08:00
Berthold Stoeger
dc67876c79 Cleanup: introduce empty_weightsystem constant
To make things more future-proof, introduce an empty_weightsystem
constant. Replace explicit aggragate initialization of empty
weightsystems by this constant.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-05 10:14:25 -08:00
Berthold Stoeger
b3f530bfb9 Undo: make weight-deletion an undoable action
This one is a bit more complicated than weight adding, because the
multiple-dive case is not well defined. If multiple dives are selected,
this implementation will search for weights that are identical to the
weight deleted in the currently shown dive. The position of the weight
in the list is ignored.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-05 10:14:25 -08:00
Berthold Stoeger
147a36647c Undo: make adding of weights an undoable action
Introduce an AddWeight undo command. This is modelled after the
numerous dive-edit undo commands. The redo and undo actions are
connected to the WeightModel via two new signals, weightAdded
and weightRemoved.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-05 10:14:25 -08:00
jan Iversen
ed1264ce49 core: add dive_site export for mobile in Exportfuncs
DiveFilter is not available in Mobile, so another solution
is needed.

Use "for_each_dive_site" to loop over dive sites instead.

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-05 10:11:42 -08:00
Berthold Stoeger
755f185cfc Selection: move selection of "first" dive to core
The DiveListView has a function to select the first dive. Move
this to the core to be able to call it from all parts (not only
desktop) of the code.

Currently, this has a (small?) UI regression: when filtering dives
and no selected dive is visible anymore, the old code would select
the first dive in the list. The new code selects the newest dive,
which might not be the first if some sort-criterion is active.

To revert to the old behavior, it will be necessary to move the
sorting function likewise to the core.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-04 13:00:23 +01:00
Berthold Stoeger
ae753f4c4d Cleanup: remove superfluous includes from core/divelist.c
Most of these haven't been used in a long time.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-04 13:00:23 +01:00
Berthold Stoeger
4b1a3a1a6e Selection: move selection functions from divelist.c to selection.c
Since we now have a selection.c translation unit, put the selection-
related functions there.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-04 13:00:23 +01:00
Berthold Stoeger
7787bfbf9e Selection: move commands/command_private.* to core/selection.*
The file command_private.cpp had functions concerning selections
only. To make these functions accessible from outside the undo
machinery, turn it into a part of the core-library. Currently,
only C++ functions are exported. We might think about also
exporting a C interface.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-04 13:00:23 +01:00
jan Iversen
4e690119ef core: add shared export functions (copy from desktop-widgets)
desktop-widgets/divelogexportdialog.* contains both the desktop
dialog as well as the "real" export functions.

Create a class to be shared between desktop and mobile

Copy the export functions 1-1 from divelogexportdialog.* of course
changing class names.

saveProfile is highly dependent on the UI, so the implementaion will
be done in each UI directory (desktop-widgets, mobile-widgets).

Remark this commit just add the copied functions, in order to secure
nothing is broken.

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-03 21:30:39 -08:00
willemferguson
7c024f12d2 Desktop: add export to html
Add the export of environmental parameters in star widgets to .html format. The
dive rating is always shown both in the condensed as well as in the expanded
view. The other five environmental variables are only shown in the expanded
view. Only those star widgets with a rating are shown: if a star widget has not
been rated in the UI, then it is assumed unrated and is not indicated in the
expanded view.

Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-12-03 20:37:57 -08:00
willemferguson
9006e3d102 Desktop: add additional star widgets to Information tab
Provide file I/O for those star widgets that are enabled. The values of the
widgets can be stored to and read from either xml or git.

Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-12-03 20:37:57 -08:00
willemferguson
6d7f26f4bf Desktop: add additional star widgets to Information tab
Connect the UI to the underlying dive structure. Enable proper initialisation
and management of star widgets while Information tab is active. Enable undo for
the addtional star widgets.

Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-12-03 20:37:57 -08:00
willemferguson
7dc8a9850d Desktop: handle environmental states in Information tab
Create a preference setting on the General Settings page. The setting is saved
with the other preferences.

Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-12-03 20:37:57 -08:00
Robert C. Helling
33e49637ec Add current GF to infobox
As per request from users on scubaforum.com, this adds
the current gradient factor to the deco information of
the infobox. Up to now, this information was only
graphically represented in the pressure bar graph
and the heatmap. This gives a numerical value.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-11-28 12:23:04 -08:00
jan Iversen
624bd9e7ec core: add --testqml flag to mobileExecutable
Add flag to subsurface_mobile (only when compiling for desktop)
to allow using qml files from disk instead of resources.

This allows testing qml changes with just restarting subsurface_mobile.

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-11-26 09:44:13 -08:00
Dirk Hohndel
c36513a9f3 Core: don't prevent some OSTC models from being recognized
The code seemed to do something really reasonable by picking one of the
supported OSTC versions - except that the one it picked didn't support
BT/BLE and therefore our logic of recognizing dive computers on iOS
failed.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-11-22 16:53:29 -08:00
Dirk Hohndel
2fb9367afe Translations: try to be smarter when picking the right locale
I was reminded to do this when a user in French speaking Switzerland reasonably
suggested that fr_FR would be a much better fallback than en_US in their
situation.

Fixes: #2388

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-11-20 21:17:39 -08:00
Berthold Stoeger
9f573df971 Dive list: update selection after clearing model
When clearing the model the selection is cleared. Send the according
signal.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-19 21:13:40 -08:00
Berthold Stoeger
3003c6e1ee Filter: move recalculation of filter from FilterModel to TripModel
The way this was accessed via Qt's model semantics was horrible.
This gives arguably more readable code, since we don't have to
shoehorn things through QVariants.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-19 21:13:40 -08:00
Berthold Stoeger
9ffafbc326 Filter: move num_shown logic from model to core
Since the number of shown dives is stored in the core, let's also
keep it updated there.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-19 21:13:40 -08:00
Berthold Stoeger
b76f207158 Filter: split out filter from model
Split out the actual filtering from the MultiFilterSortModel.
Create a DiveFilter class that does the actual filtering.
Currently, mobile and desktop have their own version of this
class, though ultimately we may want to merge them.

The idea here is that the trip-model and undo-commands have
direct access to the filter-function and thus can take care
of keeping track of the number of shown dives, etc.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-19 21:13:40 -08:00
Berthold Stoeger
6d6d10f03a Filter: move calculation of shown dives to undo command
The filter-model was catching dives-added / dives-deleted signals
from the models to keep track of the number of shown dives.

To simplify the data flow, do this directly in the undo-command.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-19 21:13:40 -08:00
Berthold Stoeger
2d09819ddf Filter: move number of shown dives to core
We mark hidden/shown dives in the core but store the number
of shown dives in the MultiFilterSortModel. Move this datum
to the core for improved locality.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-19 21:13:40 -08:00
Robert C. Helling
c2d5de207d Check if all required bytes were read
Fixes CID 350077

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-11-16 12:34:30 -08:00
Robert C. Helling
dbb504429d Don't acces null dive computer
Fixes CID 350111

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-11-16 12:34:30 -08:00
Robert C. Helling
143da031ce Use the actual error number
According to the man page, fopen and fclose return
the error number in the global variable errno.

Fixes CID 350115

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-11-16 12:34:30 -08:00
Robert C. Helling
f370446236 Initialize cylider field properly
This fixes another thing Coverty found. I am not 100% sure
I understand the semantics of cylinder_t.manually_added
but looking at other instance I guess true is the correct
value for a cylinder from a csv file for a Poseidon
rebreather.

Fixes CID 350734

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-11-16 12:34:30 -08:00
Robert C. Helling
28db9ede41 Don't access uninitialized deco_structure
Coverty found that in the export functions, we initialize
the planner deco state with NULL and then possibly later
access its content. This makes sure, we don't do that.

Let's see if this makes Coverty happy or I missed somehting
else.

Fixes CID 350736
Fixes CID 350735

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-11-16 12:34:30 -08:00
Berthold Stoeger
12c7c5ea96 Cleanup: move clearing of current_dive into clear_dive_file_data()
It makes no sense to have a non-NULL current_dive once all dives
have been deleted. Therefore, clear current_dive implicitly in
clear_dive_file_data() and don't depend on the caller performing
this.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-16 08:29:53 -08:00
Berthold Stoeger
065559c3d8 Core: set gas use to zero if no values are given
In get_gas_used() the use was left uninitialized if there are neither
user- nor computer-supplied values. This gives random SACs in the UI.
Initialize to 0.

Fixes #2376.

Reported-by: Stefan Fuchs <sfuchs@gmx.de>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-16 09:23:39 +01:00
Berthold Stoeger
b850384100 Profile: fix pressure scale
The determination of minimum pressure in calculate_max_limits_new()
in profile.c was wrong for a long time. Since the loop went over all
cylinders (even unused ones), the minimum pressure was always zero.

Since we loop only over used cylinders, the minimum pressure was
initialized to the lowest starting pressure of any cylinder.

If there were no events with pressure change, the minimum pressure
stayed unchanged, resulting in a funky scaling.

Instead, let's initialize the minimum pressure to the lowest ending
pressure.

Reported-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-12 07:00:37 +01:00
Berthold Stoeger
80f123ce2a Parser: set timestamp to zero if parsing failed
When parsing of a timestamp failed (shouldn't happen) set the
timestamp to zero. This should give less unpredictable results
and silence a compiler warning.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
794066b236 Cylinders: access cylinders with get_cylinder()
Instead of accessing the cylinder table directly, use the get_cylinder()
function. This gives less unwieldy expressions. But more importantly,
the function does bound checking. This is crucial for now as the code
hasn't be properly audited since the change to arbitrarily sized
cylinder tables. Accesses of invalid cylinder indexes may lead to
silent data-corruption that is sometimes not even noticed by
valgrind. Returning NULL instead of an invalid pointer will make
debugging much easier.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
52d8d89f73 Mobile: optimize cylinderList() function
The cylinderList() function collects all cylinder descriptions.
Instead of adding all cylinders, then sort, then removed duplicates,
keep a sorted list and only add non-existing elements. Find
existing elements by a binary search.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
6a1e2cd8c2 Desktop: support no-cylinders in dive information tab
The tab was crashing if there were no cylinders because
1) per_cylinder_mean_depth() would access non-existing cylinders.
2) TabDiveInformation::updateProfile() would access a non-existing
   mean.

Fix both of these crash conditions by checking whether the dive
actually has cylinders.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
2d637f2528 Cleanup: replace unsigned by signed parameter in two helper functions
In getFormattedWeight() and getFormattedCylinder(), the indexes
were passed as unsigned ints. This makes no sense as the only
callers were using signed ints. Change the parameters to signed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
c26e922802 Cleanup: return cylinder from add_empty_cylinder()
As a convenience, return the cylinder from add_empty_cylinder()
to spare the caller from the nasty expression to fetch the
last cylinder.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
8df3705152 Cleanup: return cylinder from cylinder_start() in parser
Most callers of this function accessed the newly generated cylinder
immediately after calling this function. Thus, for convenience,
return the added cylinder. This avoids a number of verbose expressions.

On the flip side, cylinder_start() now has to be cast to
function returning void in a the "nesting" function table.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
7c9f46acd2 Core: remove MAX_CYLINDERS restriction
Instead of using fixed size arrays, use a new cylinder_table structure.
The code copies the weightsystem code, but is significantly more complex
because cylinders are such an integral part of the core.

Two functions to access the cylinders were added:
get_cylinder() and get_or_create_cylinder()
The former does a simple array access and supposes that the cylinder
exists. The latter is used by the parser(s) and if a cylinder with
the given id does not exist, cylinders up to that id are generated.

One point will make C programmers cringe: the cylinder structure is
passed by value. This is due to the way the table-macros work. A
refactoring of the table macros is planned. It has to be noted that
the size of a cylinder_t is 64 bytes, i.e. 8 long words on a 64-bit
architecture, so passing on the stack is probably not even significantly
slower than passing as reference.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
4355ce3924 Cleanup: move copy_cylinder_types() from dive.c to equipment.c
Thus, future callers will not have to include the monster dive.h
include if they just want to copy cylinders.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
860807bf92 Core: create copy_cylinder_type() function
Move the loop body of copy_cylinder_types() into its own function.
When using variable sized arrays, this loop will have to treat two
cases (overwrite cylinder and add new cylinder), so that makes things
more clear.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
f2bcc240c4 Core: dynamically allocate cylinder maps in merge_cylinders()
merge_cylinders() used three bitmaps to identify cylinders used in
the first and second dive and matched cylinders. Even though nobody
will use more than 32 (or 64!) cylinders, replace these with
dynamically allocated bool-arrays for consistency with the rest
of the code.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
371a5fd66b Core: dynamically allocate gases array
When calculating per-cylinder mean depths, bitfields were used to
keep track of "used" and "known" cylinders. Even though no sane
person will use more than 32 cylinders, turn this into dynamically
allocated arrays of bool for consistency with the rest of the code.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
05a5a06fd3 Profile: dynamically allocate gases array
To calculate sac rates, an array of used gases for every point on the
profile was used. This was implemented using unsigned int bitfields.

While nobody sane will ever use 32 or even 64 cylinders, for consistency
with the rest of the code, also change this to use dynamically
allocated arrays.

But allocate only once per shown profile, not once per sample.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
00289cd222 Profile: dynamically allocate plot pressure data
All accesses to the pressure data were converted to use functions.
Therefore it is now rather trivial to dynamically allocate the
pressure array and just change the functions.

The only thing to take care of is the idiosyncratic memory
management. Make sure to free and copy the buffer in the
appropriate places.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
7c6a904bbf Profile: use pressure data functions in save_profiles_buffer
The save_profiles_buffer() function was accessing the pressure
data directly. Instead, use the already existing funcions to
make transition to dynamically allocated pressure data more
seamless.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
4c9532dc51 Profile: use pressure data functions in fill_missing_tank_pressures
The pressure data was directly accessed in fill_missing_tank_pressures().
Use the already existing functions so that the structures can be adapted
easily.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
7e1425796d Profile: turn INSERT_ENTRY macro into helper function
The only apparent reason that this was a macro is that it automatically
increased the "index" and "entry" counts. But incrementing these explicitly
seems reasonable.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
2fd4cb5fe1 Profile: pass index instead of pointer to set_plot_pressure_data
Another plot-pressure-related function whose argument is converted
to an index.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
fe6d3c8c38 Profile: switch pressure-accessing functions to indexes
Continue with replacing pointers to struct plot_data entries
by indexes. Thus the pressure data can be kept in its own
array and can by dynamically sized.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
4724c88533 Profile: change get_plot_pressure to take index instead of pointer
The goal here is to make it possible to detach the pressure related
data from the plot_info structure. Thus, the pressure related data
can be allocated independently depending on the number of cylinders
per dive.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
16bdbc54b9 Cylinders: dynamically allocate cylinder arrays
Dynamically allocate cylinder arrays in C code. This is a tiny
step in removing the MAX_CYLINDERS limitation.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
11467fa326 Core: dynamically allocate the result of get_gas_used()
get_gas_used() returns the volume of used gases. Currently,
an array with MAX_CYLINDERS is passed in. If we want to make the
number of cylinders dynamic, the function must use an arbitrarilly
sized array.

Therefore, return a dynamically allocated array and free it
in the caller.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00