The way I understand, the PASCAL pressure unit is used to parse
obscure dive logs. However, there is no support in the UI for
using Pa as pressure unit. Therefore remove reading / writing
this unit to git divelogs.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The get_*_unit() functions return the unit-name as set in
the preferences. Add versions with a "metric" parameter.
This will be used by the statistics code, which may in
the future allow for binning with alternative units.
All the unit-formatting functions should probably be moved
away from qthelper to their own source file.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This was only used by the filter, but will also be used
by the statistics module. To avoid duplicate translation
strings, move to a common place.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The start-selection widget will need icons with a transparent
background so that the icons don't stick out like a sore thumb.
So far the icons rendered by this function were only used by
the images on the profile and were perfectly rectangular.
Therefore there was no need for this.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Create a gastype enum, which describes the type of a gas.
For now: air, nitrox, normoxic, trimix and oxygen.
This probably should be made configurable.
The gas types will be used to bin gasses in the statistics
module.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The renderIcon() function was used by the thumbnailer to
render SVG-based icons. Move it to the global qthelper.cpp
so that it can also be used by the statistics module.
Add "SVG" to the name to emphasize what it is used for.
For consistency also move the renderSVGIconWidth() function,
which renders to a fixed width, to qthelper.cpp
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Weirdly, this function was declared in dive.h and defined in
subsurface-startup.c. Let's move declaration and definition to
more appropriate places, viz. subsurface-time.h and time.c.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This function was not used anywhere. Moreover, remove a few
unused includes from qthelper.h. Surprisingly, a number of users
of qthelper.h depend on these, so readd them at the appropriate
places.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Arguably, the number of filtered dives is a matter of the divefilter.
Let's move it there.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When removing dives, the UndoCommands would keep track of the
shown dives. When adding, they were calling into the filter
instead. Let's remove this asymmetry.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The shown_dives variable was reset by the dive_list code. Arguably,
the filter should keep track of the number of shown dives, so move
the resetting there. This means adding a new "reset()" member function
to the filter and call that instead of "updateAll()" when the core
data is reset.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Since switching to the mobile-models and removing grantlee,
DiveObjectHelper was demoted to a thin wrapper around string
formatting functions. The last user was removed in a previous
commit.
It was never a good idea, given QML's strange memory-management.
Let's remove it.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When editing a dive, a DiveObjectHelper of the unmodified dive
was created to compare the edited with the old values. Since
the DiveObjectHelper is used here only as a pointless wrapper
around the formatting functions, call these functions directly.
However, note that the code is in principle wrong since the
change to the mobile-models, which do not use the DiveObjectHelper.
The real fix would be to reload the data from the model to prevent
going out-of-sync with respect to the formatting routines!
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
With the removal of grantlee, this became pointless glue
code. Call the formatting functions directly.
Since the printing code was the only user of CylinderObjectHelper,
remove the whole thing.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
At this point (post grantlee), DiveObjectHelper is just pointless
glue code. Let's remove it from the printing code and call the
formatting functions directly. If necessary, move these functions
to core/string-format.cpp.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This was a weird helper object, needed for grantlee. Instead
of storing this object, loop over cylinders and dives directly.
The actual accessor function is unchanged and now generates
a DiveObjectHelper or DiveCylinderHelper for every variable
access. Obviously, this is very inefficient. However, this
will be replaced in future commits by direct calls to formatting
functions.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The mobile version of the list used string formatting functions
defined in DiveObjectHelper and declared in mobilelistmodels.h.
Very confusing. Move them to a separate source file where - in
the long run - all the string-formatting functions, which
are scattered all over the place, can be collected.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Recently (d16a9f118a) the tankinfo table was made dynamic, which
means that the default tankinfos are added programatically.
Thereby, the wrong function was used for AL* type of cylinders:
metric instead of imperial. Fix those.
Reported-by: Michael Andreen <harv@ruin.nu>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
A user complained about the default cylinders list. Provide
a preferences option to turn this off.
When changing the preferences, the tank-info model will be
completely rebuilt. Currently, this is a bit crude as this
will be done for any preferences change.
Suggested-by: Adolph Weidanz <weidanz.adolph@gmail.com>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
There was a tank info with an empty name. According to a comment,
this is needed for the "no cylinder" case. However, we now support
empty cylinder tables, so this is not needed anymore. Therefore,
remove it.
Make sure that the user can still enter the empty name, just in
case. But don't save the size and pressure in that case.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This is obviously a pure code-hygiene thing. But with the new
dynamic tank info table, this becomes trivial, so let's do it.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The list of known tank types were kept in a fixed size table.
Instead, use a dynamic table with our horrendous table macros.
This is more flexible and sensible.
While doing this, clean up the TankInfoModel, which was leaking
memory.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
So far, the PreferencesDialog emitted a settingsChanged signal.
This meant that models that listened to that signal had to
conditionally compile out the code for mobile or the connection
had to be made in MainWindow.
Instead, introduce a global signal that does this and move
the connects to the listeners to remove inter-dependencies.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Provide supported dive computer list on the command line
and actually call the cli download. Still not functional.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
This is of course not functional at all, but it gives a first idea of
what we will need to do in this code.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Right now this doesn't do a thing, but it gives us a nice target that
has far fewer dependencies and should contain enough parts to download
stuff from a divecomputer and then sync that with cloud storage.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
in_planner() is problematic, since it is uses desktop-only
application state. Since the cylinder-model already has
an appropriate inPlanner flag, use this instead.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
As we switched to the qmake based build we now bundle the translations
via the Qt resource system instead of explicitly as Android assets. This
adjusts the code that opens the translations accordingly.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
We don't support adding pictures and videos on mobile, so let's not
referernce the infrastrutcture that's needed for that.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
These are static functions, they cannot be used as a method on an object to
construct that object.
commit aa5f2e7c73 ("cleanup: replace deprecated sprintf()/vsprintf() calls")
introduced this bug in an ill-advised attempt to deal with a deprecation
warning.
This caused us to not print GPS coordinates in the UI.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Add a general dives-imported signal for those cases where we
want to fully rebuild models, notably, the completion models.
The divesAdded signals are too fine, because they are sent
per trip and we don't want to reload these models multiple
times per import.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When breathing pure oxygen and considering it not
narcotic, there is not maximal narcotic depth and
the formula divides by zero. So better, handle this
case separately.
Fixes#3080
Signed-off-by: Robert C. Helling <helling@atdotde.de>
The scope confusion between s (the for loop variable) and s (the function
argument) caused a crash in the s.split() on Windows.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Recently the QStrings were replaced by std::strings in device.cpp
so that they can be accessed from C-code. However, libstd being
modelled after C, constructing a std::string from a NULL pointer
leads to a crash.
Fix one case where this was overlooked.
Moreover, replace a null-pointer check by empty_string(), to
treat NULL and "" equally.
Reported-by: Salvador Cuñat <salvador.cunat@gmail.com>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Because of subsequent changes there is no clean way to just revert the changes
introduced in commit 8b36cf1051 ("desktop: offer different colors for info tab
titles"), so this manually removes the parts we don't need anymore.
This also restores a tooltip value that was inadvertantly removed in that
commit.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Add a preference option to set the color of the text on the information tab to
either MediumBlue, LightBlue or Black. The last two of these colors are meant
to enable areadable font contrast on displays with dark mode.
The choice is saved with the other preferences.
[Dirk Hohndel: this isn't really about dark mode, so changed many of the types
and variable names, changed the user visible texts, and
addressed some whitespace issues]
Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
When encountering a <weight> tag, we would parse into the last
weightsystem. However, we only create weightsystems when
encountering <weightsystem> tag. Therefore, this code would
either crash or overwrite the previous weightsystem.
Instead, create a new weightsystem for each <weight> tag.
Moreover, make sure that inside a <weightsystem> tag a
weightsystem actually exists. This should be the case,
but who knows...?
Reported-by: Nihal Gabr <gabr.nihal@gmail.com>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When dives were merged on import, they were not unregistered
from their dive site and trip before being deleted. Thus, these
tables had stale pointers, which would ultimate lead to crashes.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This used to be a copy of QSysInfo. However, once the requirement
was raised to Qt5.4, this was replaced by a subclass of the original
QSysInfo - which made the whole file mostly obsolete.
Just use QSysInfo directly where needed.
Only for windows.c, which can't call directly into Qt, keep the
isWin7Or8() helper function.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
For multiple-choice constraints we use a bit field of type
uint64_t. This means we theoretically support up to 64 items.
Currently use at most seven.
Coverity complained (correctly) that we use the expression
"1 << x" to generate the bitfields. However 1 is a 32-bit
literal on most platforms, which makes this undefined
behavior for x >= 32. Change the integer literal to 64-bit
1ULL.
Moreover, when detecting items with an index >= 64, don't
even attempt to set the according bit, since this is
undefined behavior and the compiler is free to do as it
pleases in such a case.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
If source files want to access preferences functions, they should
include pref.h themselves.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Nobody was using these return-code macros and the functions
do not exist since a long time.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
These flags are not dive-related, therefore move their declaration
to the appropriate header file. Likewise, move their definition
from parse-xml.c to subsurfacehelper.c
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
unregister_dive() and delete_single_dive are defined in
divelist.c, as they take an "index" argument into the global
divelist. Therefore, move their declarations to divelist.h.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Since dive.c is so huge, split out divecomputer-related functions
into divecomputer.[c|h], sample.[c|h] and extradata.[c|h].
This does not give huge compile time improvements, since
struct dive contains a struct divecomputer and therefore
dive.h has to include divecomputer.h. However, it make things
distinctly more clear.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The function
1) was misnamed: it determined the time of the first selcted dive.
2) had only one caller.
3) would crash if there was no selected dive.
Let's just fold the functionality into the caller. It's a one-liner
anyway.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In an effort to reduce the size of dive.h and dive.c, break out
the event related functions. Moreover event-names were handled
by the profile-code, collect that also in the new source files.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Desktop does not use mark_divelist_changed() anymore - all is done
via the undo machinery. Therefore move this function (and its
counterpart unsaved_changes()) to qmlmanager.cpp.
Ultimately, it probably should be removed from there as well, but
currently I don't dare to touch all the cloud-logic!
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The undo machinery will need a method to remove devices based
on their index instead of their name. Add it.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Add commands for deleting devices and editing device nicknames
to include the device-handling in the undo system.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Technically get_dive() could return a nullptr. The existing code made sure the
argument passed to get_dive() was one that always would result in a valid dive
pointer being returned. The new code is only slightly less efficient but allows
a static code analysis to easily see that we don't derefence NULL pointers here.
On some level this change is unnecessary. But it's also not wrong.
Fixes CID 354762
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The device nodes are created for all DCs, when importing the
dives. There is no point in creating only the device node for
the first DC in fixup_dive().
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In the specuial case of suunto, where we may add a device directly
instead of via dive->dc, add the device to the provided table.
The caller will then pass on the new device to the undo system.
This makes downloading finally really undoable (at least I
hope so). So far, the dives and dive sites were removed, but any
new device remained.
However, when setting the device-id via serial, we now have
to check both, the global and the downloaded list of devices.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In one weird case (suunto), the code in libdivecomputer.c
generates a device node directly instead of going the usual
way (setting the data in the dc-structure of the imported
dive). It is unclear to me whether that has to be that way,
as it depends on the chronological order of callbacks to
event_cb() and dive_cb().
Therefore add a device_table pointer to device_data_t
so that the downloader can add the device to this table. This
only adds the pointer, but does not yet use it in the
downloading code.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The same structure was defined as "struct dc_user_device_t"
and typedefed as "device_data_t". Unify this. Since there
are much more of the latter, remove the former.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
So far, we added a non-global device table to the parser states.
Now, create device nodes in that table instead of in the global
table. Thus, on undo of dive-import, the new device nodes will
be removed.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In analogy to the xml-parser add a device-table to git's parser-state.
Currently this is unused. In upcoming commits the git parser will
then be changed to add device nodes in this table instead of the
global device table. The long-term goal being to detach the
parsers from global state and to make dive-import fully undoable.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The function was misnamed in that it doesn't set the nickname
of a device. Instead, it adds all (unknown) devices of a
dive to the/a device-table. Let's call it appropriately.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Add a device_table parameters to Command::importTable() and
add_imported_dives(). The content of this table will be added
to the global device list (respectively removed on undo).
This is currently a no-op, as the parser doesn't yet fill
out the device table, but adds devices directly to the global
device table.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
To include the device code in the undo system, we need functions
to check for the existence of devices and to add or remove them.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
If we want to avoid the parsers to directly modify global data,
we have to provide a device_table to parse into. This adds such
a state and the corresponding function parameters. However,
for now this is unused.
Adding new parameters is very painful and this commit shows that
we urgently need a "struct divelog" collecting all those tables!
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The XML-parameter code is a mess. Ownership is unclear. Allocation
and freeing of strings is in different functions. Sometimes
only every second string is free()d, because keys are not copied.
But this is done inconsistently. The caller has to know how
many parameters the callee may add.
Instead, let's add a small helper-struct that uses C++ memory
management, but exports a C-API. The array for the XML-library
is generated on the fly.
This is only the implementation, the old code is not yet replaced.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Apparently libdc gives us copies of strings. The API is very
scary, because (at least according to my reading of the code),
the key/value pair may be stored in a cache. Thus on free()ing
the string in the cache becomes invalid and we must not access
it twice. Very obscure.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Recently, the sorting of the devices was changed to be
case-insensitive for models for consistency reasons. However,
then the equality-comparison should also be case-insensitive.
Break it out into its own function, to avoid that mistake
in the future.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
We used a typedef "filter_preset_table_t" for the filter preset table,
because it is a "std::vector<filter_preset>". However, that is in
contrast to all the other global tables (dives, trips, sites) that we
have.
Therefore, turn this into a standard struct, which simply inherits
from "std::vector<filter_preset>". Note that while inheriting from
std::vector<> is generally not recommended, it is not a problem
here, because we don't modify it in any shape or form.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
filter_preset_table_t was defined as "void" for C code.
However, that meant that any pointer could be passed as
such a table and such a table could be passed as any pointer,
without generating compiler warnings.
Indeed, we had a parameter-mixup that went unnoticed.
Therefore, make filter_preset_t an anonymous structure with
the name filter_preset instead.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The code in core/libdivecomputer.c used string insensitive
comparison for device models, before being merged into core/device.c.
Let's reinstate that behavior, since it appears to be more logical.
On would assume that two different vendors will not use the same
model with different casing (and the same device-ids), so that
should be safe.
This uses strcoll to correctly sort unicode, which will hopefully
never be needed!
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
To search for devices with the same model, we used find_if().
However, that was only to check whether such a thing exists,
not to actually do something with said device.
Therefore, change this to std::any_of() to make it clear what
the purpose of the statement is.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of accessing the global device table directly, add a parameter
to all device-table accessing functions. This makes all places in
the code that access the global device table grep-able, which is
necessary to include the device-table code in the undo system.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
We now can loop over devices from C and check for selection.
So let's get rid of the last user of the call_for_all_devices()
callback.
Code readability improvement is not stellar, but one less
place where we shoe-horn user data through a void-pointer.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
We have a callback for all devices with a twist: it can loop
over those devices that are used by a selected dive. This is
used for exporting a subset of the dive log.
Factor out the "is device used by selected dive" part of the
function and make it available to C. The goal is to make
the whole callback thing unnecessary and let C code loop
directly over the device list.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Now we can simply loop over the list of devices. In this case,
it's not much more readable, but at least we don't have that
nasty pass user-data through "void *" pattern.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This was not used. Moreover, mark device::operator==() for removal.
This is used for detecting changes in the DiveComputerModel. This
can be removed once that is integrated into the undo system.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Searching the proper device for the divecomputer was done via a
callback. Very hard to follow code. Since we can now access
"struct device" from C, obtain it directly via get_device_for_dc().
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The function getDCExact() was used to search for a device structure
matching a divecomputer. Since C code can now access struct device,
we can export that function to C. Rename it to get_device_for_dc()
for consistency with naming of the core functions.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Up to now, "struct device" and "struct device_table" were C++
only, because they used C++ strings for convenience. Since we
switched from QString to std::string, we can create accessors
for these structs. For the C code, we simply declare them as
opaque structs and give the full definition only for C++.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Since we converted from QString to std::string, let's also use
std::vector instead of QVector. We don't need COW semantics
and all the rigmarole. Let's try to keep Qt data structures
out of the core.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
struct device is a core data structure and therefore shouldn't use QString.
QString stores as UTF-16 (which is a very questionable choice in itself).
However, the real problem is that this puts us in lifetime-management
hell when interfacing with C code: The UTF-16 has to be converted to
UTF-8, but when returning such a string, this puts burden on the caller
who has to free it. In fact, instead of looping over devices from C-code
we had a callback that sent down temporary C-strings with qPrintable.
In contrast, std::string is guaranteed to store its data as
contiguous null-terminated and C-compatible strings. Therefore,
replace the QString by std::string. Keep the QString just in
one place that formats a hexadecimal number to avoid any
potential change.
The disadvantage of using std::string is that it will crash
when constructed with a NULL argument, consistent with C-style
functions such as strcmp, etc. Arguably, NULL is different
from the empty string even though we treat both as the same.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
empty_string() returns true for "". Thus, we can't simply overwrite
the pointer if empyt_string() returns true, but must free the string
regardless. The joys of C memory management!
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The last two parameters of the parse_dan_format() function were
mixed up: sites should come before filter_presets.
This should have caused crashes, for DAN files with dive sites.
I don't understand why this didn't cause compiler warnings.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Recently (c9b8584bd2) the sort criteria of the device-table
was changed from (model/id) to (id/model). However, that
messed with the detection of duplicate device names: there,
the code searched for the first element greater or equal
to (model / 0).
With the reversal of the sort criteria, this would now
always give the first element.
Therefore, do a simple non-binary search, which is much
more robust. The binary search was a silly and pointless
premature optimization anyway - don't do such things
if not necessary!
Since only one place in the code search for existence
for a model-name, fold the corresponding function into
that place.
Moreover, change the code to do a case-insensitive compare.
This is consistent with the dc_match_serial() code in
core/libdivecomputer.c, where matching models is
case-insensitive!
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The device table is accessed by core via a callback using
call_for_each_dc(). This sorts the table by device-id. It
is unclear whether this is needed - since currently all it
does is make sure that the devices have a fixed order in XML
and git log files.
In any case, this means that the table had to be copied and
sorted in call_for_each_dc(). Since the frontend now does
its own sorting, we can just keep the core table sorted
as it needs it. This in turn will ultimately make it possible
to replace the callback by a simple loop.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This version is compile-time checked and therefore less risky with
respect to refactoring.
Since the same three signals were connect()ed for three different
threads-objects, do this in a new function.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
These will be recalculated from the pressures in fixup_dive()
anyway.
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When merging cylinders pressures derived from samples were taken
as maximum of the start and minimum of the end pressure, which
makes sense, since we believe that this is the same cylinder.
However, for manually entered pressures, this was not done.
Moreover, when one dive had manual pressures and the other only
pressure from samples, the manual pressure was taken. However,
that could have been the wrong one, for example if the end
pressure was manually set for the cylinder of the first part of
the dive, but not the last.
Therefore, improve merging of manuall set pressures in two ways:
1) use maximum/minimum for start/end pressure
2) if the pressure of one cylinder was manually set, but not for
the other, complete with the sample pressure (if that exists).
Fixes#2884.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This was only set but never read. Therefore, remove it. Divecomputer
serial numbers are now handled via a string-based interface.
We can't remove the integer-based firmware number, because that is
still used by the OSTC firmware check in ConfigureDiveComputerDialog.
Let's not risk breaking that.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This dates from 2014 - this should be obsolete: we certainly don't
support such old libdivecomputer versions. Moreover, we bundle our
own anyway.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of just 'BT' or 'device name' (which is wrong in cases where we don't
use a device name in the first place, like USBHID), try to list the actual
transports that we will consider.
A big part of this patch is just moving code around so we don't need a forward
declaration of the static helper function.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Instead of just sending this to the user through the progress bar text, also
send things to stderr in verbose mode. That should make it easier to debug
situations where we fail to download from a dive computer.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Now, that we have this helper function that should have been
introduced long ago, we can make some more expressions
more idiomatic.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
We keep track of device, i.e. distinct dive computers with id in the core.
The corresponding code stuck out like a sore thumb. Firstly, because it
is C++. But more importantly, because it used inconsistent nameing conventions.
Notably it defined a "DiveComputerNode" when this is something very different
from "struct dive_computer", the latter being the dive-computer related
data of a single dive.
Since the whole thing is defined in "device.h" and the function to create
such an entry is called "create_device_node", call the structure "device".
Use snake_case for consistency with the other core structures.
Moreover, call the collection of devices "device_table" in analogy
with "dive_table", etc.
Overall, this should make the core code more consistent style-wise.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
core/device.c used to be a C file, which couldn't access the C++
divecomputer list directly. Therefore, instead of a simple loop,
searching for a matching DC was implemented via a callback with
void * user data parameter. Wild. Since the file is now C++, let's
just use direct access to the C++ data structures to make this
readable by mere humans.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
These are used to search for device nodes and were passed model
and device id (for the exact version). However, all callers used
them to search for the node corresponding to a specific struct
divecomputer, so let's just pass that instead to make the caller
site less complex.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Remove the declaration of helper functions needed only in
core/device.cpp. To this goal, turn the member functions
into free functions.
Cosmetics: turn the DiveComputer[Node|List] "class"es into
"struct"s, since all members were public anyway.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This adds filter constraints for numerical filtering for gas-mixes.
Currently, this does a "match any" kind of search, which means that
a dive is filtered if any of its cylinders matches.
We should also implement "all-of" and "none-of" modes for cylinder
filtering.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
There were helper functions to access O2 and He component fractions.
Add another one for N2. Indeed, this can be used in three cases, where
N2 was deduced indirectly.
Moreover, add a general accessor with a gas_component argument.
This will be used by the filter code to filter for gas components.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The deco-routines used an enum to pass around the inert gas
type. Make that globally available and make it include O2.
This will be used in a future commit to generalize access
of gas fractions.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
getDiveSelection() returns a vector of the selected dives.
Use that instead of looping over the dive table and checking
manually.
This removes a few lines of code.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The get_trip_date_string() formatted, as the name implies, the date
of a trip. It was passed a number of parameters and had only one
caller, which would also add the location if it existed.
Therefore, move all that logic into the helper function and
name it get_trip_string().
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Dirk reports that some Windows users have had odd corruption in the
commit messages in the cloud storage. They make no sense at all unless
there is some very weird Windows library bug.
The prime suspect is 'vsnprintf()' returning a negative error when the
target buffer is too small (rather than the proper "this is how much
space it would need"). That is a very traditional C library bug that I
thougth had been fixed everywhere, but there doesn't really seem to be a
lot of other likely causes.
So let's make our membuffer code be defensive against bad libraries that
return negative error numbers from vsnprintf.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Android can't scan for classic BT devices, so when BT support was first
added, we simply didn't use the discovery agent at all and relied on the
list of paired BT devices provided by Android.
This still worked fine for a lot of BLE devices that allowed 'bonding'
with the Android device - similar to pairing. But some BLE devices (like
the Shearwater Peregrine) don't support bonding and so our Android code
didn't see them at all.
With this commit we start a BLE only scan on Android to add to the list
of already paired devices.
Fixes: #2974
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
We certainly should log errors and the complete list of discovered
devices.
Also, it's good practice to set a specific search time (I picked three
minutes). This way we won't constantly scan and drain resources.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
We call the same helper from two spots. Once when we report the already
paired BT devices on Android, and once from the deviceDescovered signal
for the discovery agent. Let's make sure we can tell where the info came
from.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
So far we saved timestamps by their 64-bit value as decimal strings.
Change this to a user readable format. The parsing routine still
supports decimal numbers.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
To save datetime-based filter constraints to git or XML,
it is preferrable to use human-readable representations.
Therefore, add helper functions to format / parse timestamp_t
64-bit values in the "YYYY-MM-DD hh:mm:ss" format.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When importing a divelog, import filter presets. If there are
equal names, import only if the presets differ. In that case,
disambiguate the name. This made things a bit more complicated,
as comparison of filter presets had to be implemented.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The filter widget was caching whether the filter was active and
used that flag to calculate the "# dives shown" string. Move this
directly to the DiveFilter class to remove interdependencies and
to unify with mobile.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This is mostly copy and paste of other git loading code. Sadly,
it adds a lot of state to the parser-state. I wish we could pass
different parser states to the parser_* functions.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
On the mailing list it was decided that users might want to
move their filter presets across computers via the cloud.
Notably, in the future one might access statistics on mobile and
these might by controlled by filter presets.
The git save routines use the same string formatting as the
XML save routines. The string formatting is found in
core/filterconstraint.cpp. Thus, duplication of code and
inconsistencies should be minimized.
Each filter preset is saved into a file in the "02-Filterpresets"
folder in the root of the git repository.
Each file consists of one "name" line, zero or one "fulltext" line
and zero or more "constraint" lines.
The modes, types and the actual payload is controlled via attributes.
Thus, a preset file might look like this:
name "test"
fulltext mode="substring" query="clown"
constraint type="location" stringmode="starstwith" data="mafia"
constraint type="sac" rangemode="range" negate data="5000,10000"
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This is a bit painful: since we don't want to modify the filter
presets when the user imports (as opposed to opens) a log,
we have to provide a table where the parser stores the presets.
Calling the parser is getting quite unwieldy, since many tables
are passed. We probably should introduce a structure representing
a full log-book at one point, which collects all the things that
are saved to the log.
Apart from that, this is simply the counterpart to saving to XML.
The interpretation of the string data is performed by core
functions, not the parser itself to avoid code duplication with
the git parser.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The parse_* functions should probably be declared in parse.h.
Arguably, parse_xml_init() and parse_xml_exit() should be moved
to an init.h file, however that doesn't yet exist.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Declare the function in the header file corresponding to the source
file where the function is defined.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Users might want to move their presets with there log-file. Therefore,
save the presets to the log. The alternative would be to save them
to the preferences. However, on the mailinglist it was decided that
moving the presets to a mobile device is a wanted feature.
The XML saving code has a rather reasonable interface, therefore
this turned out to be pretty easy to implement.
The filter presets are saved into a
<filterpresets>
...
</filterpresets>
block
Each individual preset is saved into a
<filterpreset name='...'>
...
</filterpreset>
Block with a unique name attribute.
Each preset contains zero or one fulltext and zero or more constraint entries.
The type and mode(s) are controlled by attributes, the "payload" is saved in
the block. Note that all the formatting is done by functions in core/filterconstraint.c
and not the parser itself.
A preset in the XML file might look like this:
<filterpreset name='test1'>
<fulltext mode='startswith'>Train</fulltext>
<constraint type='planned'>0,0</constraint>
<constraint type='sac' range_mode='range' negate='1'>5000,10000</constraint>
</filterpreset>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Add undo commands to add / edit / delete filter presets.
These are styled after the other undo commands: On changes,
the UI is informed by DiveListNotifier signals. Editing is
a simple std::swap of values.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Add a rudimentary list of filter presets to the core. The list
is sorted by name. Access is provided via a C interface so that
the presets can be written to the git and XML logs. Internally,
the list is realized by a C++ vector for convenience (euphemism for
laziness).
Morover, a C++ interface is provided for the UI. Currently names of
the presets cannot be edited, since this would mean that the order
of the list changes. This may be implemented later if required.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Switch the mobile code to use the constraint-based filter. The one
thing that is still commented out is dive-site mode, since mobile
doesn't (yet) have a dive-site edit feature. And even if it had,
the dive list probably wouldn't be shown at the same time.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Replace the static filterwidget with a list of filterconstraints.
The first attempt of using a table widget failed, because Qt's
table delegates are dysfunctional. It's not that they are bad, they
just don't work at all.
Therefore, this code "simulates" a table in that on addition / deletion
of constraints it keeps track of the rows of all constraints so
that each constraint-widget can be associated with a row of the
constraint model.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Add a model that keeps track of a list of filter constraint and makes
them accessible from Qt. Sadly, this is mostly repetitive boiler-plate
code, but this is due to Qt's model/view-API, which is a perfect example
of how *not* to design a reasonable modern API.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Adds a filter constraint object to the core, which represents one
constraint the user can filter dives with. The plan is to write these
constraints to the XML and git logs. Therefore, this code is written
in C-style except when it comes to handling strings and dates, which
is just too painful in plain C.
There is one pointer to QStringList in the class, though when compiled
with C, this is simply transformed into a pointer to void. Granted,
that smells of an ugly hack. However it's more pragmatic than
self-flaggelation with C string and list handling.
A filter constraint is supposed to be a very general thing, which can
filter for strings, multiple-choice lists, numerical ranges and date
ranges.
Range constraints have a range mode: less-or-equal, greater-or-equal
or in-range. Text constraints have a string mode: startswith, substring
or exact.
All the data are accessed via setter and getter functions for
at least basic levels of isolation, despite being written with
a C-interface in mind.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
So far, the fulltext-query structure only saves an canonicalized
upper-cased version of the query. However, if we want to save the
fulltext query to the log (filter presets) or want to restore an old
fulltext query, we have to store the original query. We don't want
to confront the user with the mangled upper-cased version.
Therefore, also save the original version.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
To support the new filter code, add helper functions that turn timestamps
into year and day-of-week to core/time.c.
Internally, these functions simply call utc_mktime() to break down the
timestamp and then extract the wanted value. This may appear inefficient,
but testing shows that modern compilers are quite effective in throwing
away the unneeded calculations. FWIW in this respect clang10 outperformed
gcc10.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The cylinder model is used both in the planner and the
equipment tab. We have three preferences for the pO2 that
is used to compute MOD: In the planner, there is one for
the bottom part of the dive and another one for deco.
Those are set in the planenr UI. There is another value,
controlled in the Tec Prefernces. That one should be
used in the equipment tab rather than the one from
the planner.
Fixes#2984
Signed-off-by: Robert C. Helling <helling@atdotde.de>
I think we only have one dive computer that supports GPS data right now:
the Garmin Descent Mk1. It reports the dive coordinates as "GPS1" and
"GPS2" for the entry point and exit point respectively.
Often GPS1 is missing, because the dive computer may not have gotten a
GPS lock before the diver jumped into the water, so when that happens
we'll use GPS2 for the dive site location. But when GPS1 exists, we
should prefer that.
And that's what we already did in logic in dc_get_gps_location(), but
for the initial dive site created at download time, we just picked any
divecomputer reported string that started with "GPS". And since GPS2 is
reported after GPS1 by the Garmin Descent, it would end up overwriting
the entry point that we _should_ have preferred.
Add the same kind of "explicitly prefer GPS1" logic to the initial dive
download case as we already had elsewhere.
Reported-by: @brysconsulting
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
gcc complained about two constructs of the kind
remote_id && SSRF_INFO("...");
And while I am not a fan of excessive warnings, I must say
it has a point here. That's just code obfuscation. In fact,
it appears that the condition was wrong - the SSRF_INFO
should probably be invoked if remote_id is NULL. The way
it was written it would be invoked if it was *not* NULL.
Change both instances to unfancy if statements.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The water type strings were static and therefore passed through
gettextFromC::tr() before main(). One would hope to get a warning
in such a case, but this is not the case.
Therefore, use the QT_TRANSLATE_NOOP macro to register the strings
in Qt's translation system and translate the list when needed.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The clock is only valid in ascent. In each cycle of the
'critial volume algorithm' it re-initialized to the
bottom time at the beginning of deco. So the time spent
on bailout should be added to this bottom time.
Thanks to Coverty for spotting this.
Coverity-scan: CID-362079
Signed-off-by: Robert C. Helling <helling@atdotde.de>
When an undo command selected invisible dives, a current dive outside
of the list of selected dives was chosen. This could have the very
unfortunate effect that the current dive was set, though not selected.
From an UI point of view this meant that the dive was displayed, but
edits would not be registered.
Change the setClosestCurrentDive function to select the current dive.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
For Android the Qt Bluetooth code seems to work just fine. And for macOS
nothing appears to work right now, but at least the Qt implementation compiles
and links.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The Qt based implementation apparently got broken at some point and now fails
to connect to rfcomm dive computers like the Shearwater Petrel.
This uses the libdivecomputer rfcomm backend. Tested to work with bluez on
Linux as well as with the native Windows implementation.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
At least Shearwater Cloud seems to use multiple formats for sample time
recorded in the database. Sometimes the time is in seconds, sometimes in
milliseconds, and sometime it is something I have no idea about. Thus
switching to calculating the sample id myself and using sample interval
to calculate the actual sample time. Seems to be more reliable than
trying to guess what format Shearwater is using for this specific dive.
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
ExifTools (and probably other meta-data editors) modifies the
mvhd creation date, but leaves the individual creation dates
in the tracks unchanged. Therefore, use the mvhd atom.
Reported-by: Eric Tanguy <erictanguy2@orange.fr>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This extends the uuid matching to the low-level characteristics too, so
that we can ignore the McLean Extreme characteristics that aren't
interesting.
It also renames the uuid matching to be about a "uuid_list" rather than
being about the service we're matching, since we're now using it for
other uuid's than just services.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Silly typo with a missing 'i' in 'uuid' that happened when I wrote this
code originally, and that compiled fine thanks to the error being
duplicated with cut-and-paste to all relevant places.
Fix it now, since I'll extend the uuid matching to the actual
characteristics for the McLean Extreme.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
It turns out that contrary to what the documentation states, a few languages
are still only using the 'qt' translation. But those exist for all languages,
so we need to first search for the 'qtbase' translations, and only if that
fails do we try to load the 'qt' translations.
And even that will fail for languages in which Qt simply isn't localized (like
Dutch).
To make the code more readable, the check for 'US English' was moved earlier as
there is no point to look for a Qt translation for that (simply doesn't exist).
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
We were still using the 'qt' translations instead of 'qtbase' as we should have
been using since forever - it's a little unclear from reading the documentation
when in the Qt5 life cycle this happened, but definitely several years ago.
These are the strings used in situations where Qt already provides us with text
(e.g., the entries in the 'Subsurface' menu on Mac, or the button labels in
many dialogs).
Additionally we didn't try hard enough to find those translations in cases
where they are bundled with the app; so basically all scenarios except for
Linux distro specific packages or 'build from source' on macOS or Linux were
not going to work, even after addressing the qt->qtbase conversion.
But of course the developers pretty much all fall into those last two
categories. Still, I cannot believe we never fixed this in all those years...
To make it more obvious if we still aren't finding the Qt translations this
commit also makes that warning be shown in all cases, not just when running in
verbose mode.
Fixes#2954
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The logic to retrieve gas changes from Shearwater cloud database is
detecting only when the O2/He chnages. This change will grab the initial
gas. (Problem was only shown when there was a gas changee in the log, so
cingle cylinder dives were working fine.)
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Gas change is done to the cylinder we just found and not the last
cylinder. Also switching the variable name to index as we are actually
using that value outside the loop.
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Shearwater apparently stores correct pressures nowadays, so getting rid
of a hack to import double pressures.
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
This will ignore the gas changes that would be caused by Shearwater
cloud saving rows with 0 values in them.
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
A sample log I received contains a lot of rows with 0 values in it. This
will ignore the obviously bogus ones. (However, we might miss the first
sample if that is recorded at time 0.)
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
core/device.h was declaring a number of functions that were related
to divecomputers (dcs): creating a fake dc for manually entered dives
and registering / accessing dc nicknames. On could argue whether
these should be lumped together, but it is what it is.
However, part of that was implemented in C++/Qt code in a separate
core/divecomputer.cpp file. Some function therein where only
accessible to C++ and declared in core/divecomputer.h.
All in all, a big mess. Let's simply combine the files and
conditionally compile the C++-only functions depending on
the __cplusplus define.
Yes, that means turning device.c into device.cpp. A brave soul
might turn the C++/Qt code into C code if they whish later on.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The functions matchDC() and matchModel() were never implemented.
Remove their declarations.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The function *looks* like it is a dive function. However, in reality
it implicitly works on the global device list. Therefore, it is
thematically more aptly located in device.h with the other device
functions.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The SAC factor is only used for minimal gas calculations which
don't make sense in the CCR context.
Additionally, make bailout stop for at least minimum switch
time or problem solving time.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
In a previous commit, auto-filling of weight based on type was
changed to be only performed if the user hadn't already set a
weight, by testing for weight=0.
However, when the user edited the type and tabbed back and forth,
that counted as an edit and therefore the weight would not
change anymore.
To refine this, introduce an "auto_filled" flag to the weightsystem,
which is set if the weight is automatically filled and cleared if
the weight is edited. Update the weight if it was zero *or* auto-filled.
The flag is not saved to disk, but that should be acceptable. If the
user saves and reloads, we can assume that they meant the weight
to be set to the default value.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The function was called on a freshly copied dive, which has its git cache
invalidated automatically in copy_dive().
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
delete_divecomputer had legacy code, which
1) invalidated the git dive cache
2) made sure that the dive computer was not displayed anymore
However, both callers called on a freshly copied dive, which
has its dive cache invalidated in copy_dive() and can't be
the currently displayed dive. Therefore, this code is dead
code and can be removed.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
There is a number_of_computers() function which does
the same thing with two exceptions:
1) checks for null-dive
2) returns an unsigned int
Replace calls to count_divecomputers() by calls to number_of_computers().
In one case, the return type makes a different - add a cast to int there.
Ultimately, we should probably change the dc_number to signed int
throughout the code.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This helper function is not used outside taxonomy.c anymore.
Let's hide this implementation detail.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of getting the index and using that to access values, use
the taxonomy_get_value() helper function. Two places are affected:
1) reverse geo-lookup
2) location filter delegate
The behavior of reverse geo-lookup is changed slightly: now an
empty string is likewise recognized as missing "TC_ADMIN_L3".
Before, only a missing category was interpreted as such.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This is the counter-part to taxonomy_set_value(). Let taxonomy_get_country() be the
first user of the function. If a category doesn't exist, return NULL.
Small addition: make taxonomy_get_countr() take a const argument.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
get_dive_country() was essentially a reimplementation of taxonomy_get_country().
Let's just use the already existing function.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of recoding the "search for category" loop, reuse the already
existing functionality.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The alloc_taxonomy()/free_taxonomy() interface was exceedingly strange.
The former gave a "struct taxonomy", the latter took a "struct taxonomy_data".
To make things worse, is appears as if the names "taxonomy" and "taxonoma_data"
are reversed: the latter contains the former.
In any case, the alloc_taxonomy() call is not needed anymore from outside
taxonomy.c, as these memory-management details are now hidden in accessor
functions. Therefore, make the function local to taxonomy.c. Moreover,
rename it to "alloc_taxonomy_table()" and let it take a "taxonomy_data"
structure for symmetry with "free_taxonomy()".
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of manipulating the taxonomy structures directly, use the
taxonomy_set_category() function. This improves encapsulation and
gives us the possibility to improve the taxonomy data structures.
This concerns three places:
1) git parser
2) XML parser
3) reverse geo-lookup
This improves the XML parser code slightly: The parser assumes that
the value-attribute comes last (after origin and category). While
it still does that, it now at least generates a warning if it encounters
a value-attribute without origin- or category-attribute.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
These functions were taking a const char *, yet taking ownership
of the value. Moreover, taking ownership of strings is rather
unusual in C-style APIs. Let's copy the string instead.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Setting a taxonomy category was cumbersome: the caller had to
make sure that the category-table was allocated. Introduce
a helper function to make that simpler.
Make taxonomy_set_country() the first caller of the new function,
since it is just a special case with category = TC_COUNTRY.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When overwriting a country, the old string was not freed. Fix this.
Contains an unrelated coding-style fix: use braces if code block
contains more than one line.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This adds a common macro to convert salinity (which is
given as a density in terms of g per 10l) to a specific
weight with units of mbar / mm = bar / m that is used
to translate between pressures and depths.
The weired factor of 10 (from the unusual unit of salinity)
is included in the macro. It is there for historical reasons,
as it goes back to 05b55542c8 from 2012 where it was introduced
in code for downloading from Uemis dive computers.
Now, salinity appears in too many places to easily remove
this unconventional factor of 10 everywhere without breaking
to many things (including various dive computer downloads).
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Some remote dive sites have no populated places (towns, cities)
nearby. For such sites, we now fall back to looking up
unpopulated place names, such as the reef or island name.
Also some code refactorisation:
the actual network access is now encapsulated in its own
function removing some duplicated code handling in the
reverseGeoLookup function and making it more readable.
Furthermore, reverseGeoLookup() was completely refactored as
most of its functionality was due to legacy requirements; the
current code-base only calls this function from a single
location and only with an empty taxonomy_data object. This
makes the function more focussed and much simpler and more
readable.
Finally, a resource leak in reverseGeocde introduced in
4f3b26f9b6 was fixed.
Signed-off-by: Michael Werle <micha@michaelwerle.com>
Dives for the seac action computer are imported by the seacsync
program into two tables in an sqlite3 database.
The dive information is read from the headers_dive table.
The dive_data table is then queried for each dive to get samples.
The seac action computer is the only current supported computer
by the seacsync program. It only supports two gas mixes, so the
parser will toggle between two cylinders whenever it detects a
change in the active O2 mix.
Dive start time is stored in UTC with a timezone offset.
A helper function to read this was added to qthelper.
Default cases have been added to some switch statements
to assist in future development for other dive types and
salinity.
Example database has been added to ./dives/TestDiveSeacSync.db
Signed-off-by: James Wobser <james.wobser@gmail.com>