When pasting (or undoing paste) the cylinders or weights may change.
Send the appropriate signals and update the models accordingly.
Currently, this means copying from current dive to displayed dive,
but hopefully we can get rid of "displayed_dive" in the not so
distant future.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Remove a few cases of
void fun() {
...
}
While touching these functions, fix a few other whitespace
coding style violations.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Taglists were only copied in dive.c using the STRUCTURED_LIST_COPY
macro. Export that functionality in a function. This will be
needed for undo of dive-pasting.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The dive list was not updated automatically when an edit command was
executed. There was already a signal to do that, viz. divesChanged().
But that signal worked by-trip and didn't have a dive-field specifier.
The edit-commands used the divesEdited() signal that isn't by-trip
but has a dive-field specifier.
Unify these two signals to be by-trip and with dive-field specifier.
This needs common code to generate the by-trip list that is moved to
a command_private.h header.
Since there might now be multiple signals (one per trip) actually
check in the main-tab whether the current trip is affected to
avoid multiple update of fields. This has the positive(?) effect
of not doing any update if the current dive isn't changed.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This was a bit different from the other editing commands:
1) Only the current dive is edited not all selected dives.
Therefore, create a function that turns the current dive
into a one-element list.
2) The profile has to be replot. Here, likewise, create a
function to do that.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This one is a bit more tricky. There are two modes: set dive site
and set newly created dive site. This is realized using an OO model
with derived classed. Quite convoluted - but it seems to work.
Moreover, editing a dive site is not simply setting a value,
but the list of dives in a dive site has to be kept up to date.
Finally, we have to inform the dive site list of the changed
number of dives. Therefore add a new signal diveSiteDivesChanged.
To send only one signal per dive site, hook into the undo() and
redo() functions and call the functions of the base class there.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
To keep the UI in a consistent state, update the notes field if
it is changed by an undo command. To that purpose, add a new
signal to diveListNotifier with a list of dives and a field-id
as payload.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This one was rather trivial, as there is no actual merging
done. Quite simply, a number of dive sites are removed and
their dive added to a different dive site.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Implement an undo command that edits the name of a dive site.
Connect it to the dive site table, so that names can be edited
directly in the table.
Send signals on undo / redo so that the dive site table and
the dive site edit widget can be updated.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Introduce two DiveListNotifier signals which are sent by
the undo commands if dives are added to / removed from the
core.
The signal has the dive site and the index in the global
dive site table as payload. Thus, the model has only to
remove the appropriate rows.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Turn the table functions of the dive site handling into macros
as was already used for dives and dive trips. This has the effect
that the table is kept sorted by UUID.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
dive- and trip-table functions are generated in dive.c by macros.
Move this macros to a new "core/table.h" header file.
Thus, these functions can be used for other tables (e.g. dive site)
and the trip function can be moved to a separate translation unit
(divelist.c being quite large already).
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The other dive- and trip-table functions were already autogenerated.
Let's do the same for these two.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
For consistency with remove_dive(). Moreover, swap parameter order
in remove_dive() so that both functions use the same parameter order.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Add a new signal to DiveListNotifier. Send signal if dives are
added or removed and therefore the dive count of a dive site
changes. The dive sites are collected and the signal is sent
at the end of the command.
Add code to update the table view.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
1) The second parameter (selected_only) was always false. Therefore,
remove it.
2) Simplify the function by simply returning the reference count.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of setting dive->dive_site directly, call the
add_dive_to_dive_site() and unregister_dive_from_dive_site()
functions. In the parser this turned out to be a bit tricky.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Add a dive site table to each dive site to keep track of dives
that have been added to a dive site. Add two functions to add
dives to / remove dives from dive sites.
Since dive sites now contain a dive table, the order of includes
had to be changed: "divesite.h" now includes "dive.h" and not
vice-versa. This caused some include churn.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The function is defined in qthelper.c and thus not all users
of dive.h have to suck in the xslt headers.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Move the declaration of these functions to "file.h" and "parse.h"
according to the translation unit they are defined in. Thus, not
all users of "dive.h" have to suck in "sqlite3.h".
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Since the UUID will be overwritten on save and is only used on save
and load, set it only on save or load. For other created dive sites,
leave the UUID field uninitialized.
This means that the UUID will change between saves. Let's see how
the git saver handles that.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
We absolutely want to avoid dive site with the same UUID.
But that could happen when reimporting a log where the
dive sites diverged.
Therefore, on adding a dive site to a table, change the UUID
if it already exists. Since dives are associated to dive
sites with pointers, this should have no negative impact.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The code used dive site uuids, which are not really used anymore.
The only caller of this function does certainly not use a copy,
so let's compare pointers instead.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
As opposed to dive trips, dive sites were always directly added
to the global table, even on import. Instead, parse the divesites
into a distinct table and merge them on import.
Currently, this does not do any merging of dive sites, i.e. dive
sites are considered as either equal or different. Nevertheless,
merging of data should be rather easy to implement and simply
follow the code of the dive merging.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
To extend the undo system to dive sites, the importers and downloaders
must not parse directly into the global dive site table. Instead,
pass a dive_site_table argument to parse into.
For now, always pass the global dive_site_table so that this commit
should not cause any functional change.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
To enable undo of dive site functions, it is crucial to work
with different dive site tables. Therefore add a dive site table
parameter to dive site functions. For now, always pass the global
dive site table. Thus, this commit shouldn't alter any functionality.
After this change, a simple search for dive_site_table reveals all
places where the global dive site table is accessed.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-return the result instead of storing in a parameter, we now know that the list
contains only those results that are generated in the function
-allocate the result with the correct length right from the start
-do not iterate over keys of a map and then do a map lookup to get the value but
use an iterator that gives us both right from the start
-remove one call alltogether as the results were not used there
Signed-off-by: Rolf Eike Beer <eike@sf-mail.de>
See https://www.kdab.com/goodbye-q_foreach/
This is reduced to the places where the container is const or can be made const
without the need to always introduce an extra variable. Sadly qAsConst (Qt 5.7)
and std::as_const (C++17) are not available in all supported setups.
Also do some minor cleanups along the way.
Signed-off-by: Rolf Eike Beer <eike@sf-mail.de>
This is only in Qt 5.7 and therefore can't be used in Qt 5.5 and 5.6
builds. Moreover, we can't simply reuse Qt's version owing to
licensing concerns.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When merging two dives into a longer one, merge the dive computer
extra_data list too.
We just pick all the extra-data (but avoid entirely duplicate key/value
entries).
Note that this can cause confusing extra-data, in that both dives migth
have things like "battery percentage at beginning/end of dive" keys, and
if the values are different, you'll now get *both* of those values, but
that's better than randomly just taking one of them.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Allow splitting out a dive computer into a distinct dive. This
is realized by generating a base class from SplitDive.
This turned out to be more cumbersome than expected: we don't
know a-priori which of the split dives will come first. Since
the undo-command saves the indices where the dives will be insert,
these have to be calculated. This is an premature optimization,
which makes more pain than necessary. Let's remove it and
simply determine the insertion index when executing the command.
Original code by Linus Torvalds <torvalds@linux-foundation.org>.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This introduces a csv file that contains the data from
the structs defined in profile.c, in particular all
deco information computed for the dive profle (including
NDL, TTS, ceilings, surface GFs etc).
Signed-off-by: Robert C. Helling <helling@atdotde.de>
QPref has only static functions. There seems to be no point in
instantiating a singleton of this object. Remove the instance()
method and remove the Q_OBJECT macro.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
These two member functions were never used, but cause frequent
recompilation of the qPref.cpp file. Remove them for now until
their usefulness becomes evident.
These were the only functions tested in test_qPref.qml. Therefore
remove this test-file.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This import is based on one sample I received. It was exported from some
Mares software. Imported data is somewhat limited, but we do get the
depth and temperature profiles. (I would love to receive some more
sample logs to validate the import and to enhance the data we are
grabbing.)
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
to display the deco parameters at the surface,
in particular tissue saturation and heat map.
Suggeted-by: Matthias Heinrichs <info@heinrichsweikamp.com>
Signed-off-by: Robert C. Helling <helling@atdotde.de>
-avoid object copies
-use some more bullet proof C++11 constructs
-avoid using a QRegExp, simple string matches are faster
Signed-off-by: Rolf Eike Beer <eike@sf-mail.de>
The oldest version tested on TravisCI is Qt 5.5, which is also what is in
Ubuntu 16.04. Drop all the older cruft, noone should use that anymore.
Signed-off-by: Rolf Eike Beer <eike@sf-mail.de>
add_to_string() frees the original string that is passed in. This
should therefore not be of "const char *" type, as the contents
of the string *will* be modified (or more precisely: destroyed).
Same for the congener smtk_concat_str().
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
printGPSCoords() returned a newly allocated C-style string. Most
callers simply made a QString out of it and freed the C-style string.
This is paradoxical, as printGPSCoords internally works with QStrings
and converts them to C-style on return.
Therefore, let printGPSCoords() return a QString and create a
printGPSCoordsC() wrapper for the two C-callers.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The printGPSCoords() function returns a copied C-style string. Since
the owndership is transferred to the caller, the correct return type
is "char *" instead of "const char *".
Thus a number of casts when calling free can be removed.
Moreover a number of callers didn't free the string and thus were
leaking memory. Fix them. Ultimately we might want two versions
of the function: one for QString, one for C-style strings.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The complicated setup with the AddressRole is unnecessary. All we want to be
able to do is get the index of a specific text in the list. In hindsight I am
puzzled why I implemented this in such a complex fashion.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
All these aren't actually things that need fixing, they are observations about
the code.
Given that LGTM.com reports FIXME comments as Alerts, let's change the ones
that aren't about things that need fixing to something more harmless.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
To test single bits, datatrak.c would transform bytes into
malloc()ed char[8] buffers. Instead, simply introduce a function
to test individual bits. This should make it distinctly easier for
the compiler to optimize away.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
It's a drop in the bucket, but let's remove some unnecessary
global variables. With one exception these variables were only
used in one function anyway. The other one can be passed as a
parameter.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Having a parameter representing a location with the same name as a global
variable representing our locale is confusing.
Found via LGTM.com
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
While in the specific calculations here there isn't really a risk that float
might overflow, it seems odd to cast to float in order to assign to double.
This caused an Alert via LGTM.com
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Added stats_t structures to summarize dive statistics by depth and
by temperature.
Process each dive to add the dive stats to the proper depth and
temperature bucket. Buckets are defined using constants
STATS_MAX_DEPTH, STATS_DEPTH_BUCKET, STATS_MAX_TEMP, and
STATS_TEMP_BUCKET which are defined in statistics.h
Signed-off-by: Doug Junkins <junkins@foghead.com>
Owing to a variable reuse in a nested loop, importing dive logs
with new trips could lead to an infinite loop. Use a fresh index "j".
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Since ff9506b21b the downloaders don't
add dives to a new trip and therefore the tripTable field of
DownloadFromDCThread became pointless. Remove it.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Since ff9506b21b the downloaders don't
add dives to a new trip and therefore the trip field of dc_user_device_t
became pointless. Remove it.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Since ff9506b21b the downloaders don't
add dives to a new trip, but the import code does. Remove the
code in the Uemis downloader that would remove a dive from the trip.
The code has been broken recently anyway (instead of testing for trip,
it tested for the notrip flag, which make no sense whatsoever).
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Some of the functions declarations were not in 'extern "C"',
despite being C functions. This worked only because they weren't
called from C++. Nevertheless, it seems like a dangerous proposition
to have the same function declared once as C and once as C++.
Therefore, always put them in extern "C" (if compiling in C++ mode,
evidently).
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In the XML and git savers, unchanged webservice-dive sites were
deleted. Since the webservice is not functional anymore, remove
this code.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This function was defined in divelist.c, whereas it's better located
in divesite.c. Move it.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The function dive_set_geodata_from_picture() is only used in
dive.c. Make it local to that translation unit.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
And offer an option to show all devices in the settings. This is intentionally
not stored in the preferences as this should never be needed. We don't support
BT or BLE dive computers that we don't recognize. This is a last resort in case
a new firmware were to change the name or some other weird issue causes us not
to recognize a dive computer - and that should be fixed instead of worked
around.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
By default we'll only show devices that we believe to be dive computers,
but the user can override that with the recently introduced check box.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The thumbnails were fetched in the background to achieve a
snappier UI. The problem with that is that on LaTeX etc.
export only placeholder thumbnails were shown.
Therefore, implement a synchronous mode. This only tries
to fetch cached thumbnails or calculate thumbnails for
images. Videos and remote files are not supported.
Fixes#1963
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The info box can get longish. Offer the user to turn
off display of deco information (surface GF and
individual ceilings).
Signed-off-by: Robert C. Helling <helling@atdotde.de>
The most recent firmware of Shearwater computers shows this.
This is a measure of absolute amout of tissue loadings in an
easy to digest unit. Therefore it is useful to have.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
At least on a Mac we can get here without a discoveryAgent if BT is off,
so don't derefence the NULL pointer in that case.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
While in theory the DEVINFO event should give us the correct detected
product, it's also possible that the code that usually detects the
product gave up and returns an unknown model.
Try to have the message reflect that situation more accurately.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
process_imported_dives() takes four boolean parameters. Replace these
by flags. This makes the function calls much more descriptive. Morover,
it becomes easier to add or remove flags.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Since process_imported_dives() can add dives to a newly generated
trip, this need not be done in the downloading code. This makes
data flow distinctly simpler, as no trip table and no add-new-trip
flag has to be passed down to the libdivecomputer glue code.
Moreover, since now the trip creation is done at the import step
rather than the download step, the latest status of the "add to
new trip" checkbox will be considered.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
If this flag is set, dives that are not assigned to a trip will
be assigned to a new trip. This flag is set if the user checked
"add to new trip" in the download dialog of the desktop version.
Currently this is a no-op as the dives will already have been
added to a new trip by the downloading code. This will be removed
in a subsequent commit.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The logic in process_imported_dives() was faulty: Dives are merged
trip-wise in a loop. But if only autogenerated trips were supposed
to be merged, the trip would not be added.
Change the logic to always add the trip if it is not merged. To make
the loop easier to read, factor out the merge-trip-into-existing-trips
logic into a separate function.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Since recent commits, dive-trips are not added directly to the core,
but into separate trip tables (see ec37c71f5e).
These commits did not finish the work for the download-from-dc
case.
Add an extra trip_table field to device_data_t. If trips are created
(user selected "Download into new trip"), the trip will be created
in that table.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Commit 4d06ddd723 removed deletion of
unused dive sites on save. The corresponding variables were not
removed leading to compiler warnings. Remove the variables too.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When no real name is set in /etc/passwd the username ends
up being ",,,". Git does not like that. Actually, only the
part before the first comma is the name, the rest is office
and phone number. We don't want those.
Before we only testing for the username being a NULL pointer.
Reported-by: Keith Grimes
Signed-off-by: Robert C. Helling <helling@atdotde.de>
This adds a checkbox for rebreather modes of the planner
that force the ascent to be in OC mode. Before, one had
to add a one minute last segment with the mode change but
this is not practical when manually searching for the
maximal bottom time given gas reserves.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Split the process_imported_dives() function in two:
1) process_imported_dives() processes the dives and generates
a list of dives and trips to be added and removed.
2) add_imported_dives() calls process_imported_dives() and
does the actual removal / addition of dives and trips.
The goal is to split preparation and actual work, to
make dive import undo-able.
The code adds extra checks to never merge into the same
dive twice, as this would lead to a double-free() bug.
This should in principle never happen, as dives that
compare equal according to is_same_dive() are merged
in the imported-dives list, but perhaps in some pathologival
corner-cases is_same_dive() turns out to be non-transitive.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The installment of the divelist-undo system has made it unnecessary
to adopt the uniq-id of the merged-into dive. On the contrary, we
want to avoid two dives with the same dive-id in the divelist at
all costs, since get_divenr() still uses the id and thus may fetch
the wrong dive.
Therefore, don't copy the dive-id on merge.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When importing log-files we generally want to merge trips. But
when downloading and the user chose "generate new trip", that
new trip should not be merged into existing trips.
Therefore, add a "merge_all_trips" parameter to process_imported_dives().
If false only autogenerated trips [via autogroup] will be merged.
In the future we might want to let the user choose if trips
should be merged when importing log-files.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The old way of merging log-files was not well defined: Trips
were recognized as the same if and only if the first dives
started at the same instant. Later dives did not matter.
Change this to merge dives if they are overlapping.
Moreover, on parsing and download generate trips in a separate
trip-table.
This will be fundamental for undo of dive-import: Firstly, we
don't want to mix trips of imported and not-yet imported dives.
Secondly, by merging trip-wise, we can autogroup the dives
in the import-data to trips and merge these at once. This will
simplify the code to decide to which trip dives should be
autogrouped.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In the future we want to download trips into a distinct trip-table
instead of the global trip-table to allow for undo of import.
Therefore add a trip_table argument to DiveImportedModel::repopulate()
and a trip_table member to DiveImportedModel. To correctly set these,
add a DownloadThread::trips() function, which currently simply returns
the global trip table.
Finally, make "struct trip_table *" a Q_METATYPE, so that the corresponding
arguments can be passed from QML.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
To allow parsing into arbitrary trip_tables, add the corresponding
parameter to the parsing functions and the parser state. Currently,
all callers pass the global trip_table so there should be no change
in functionality. These arguments will be replaced in subsequent commits.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Currently trips are added to the global trip table. If we want to
make dive-import undoable, we should be able to parse trips of a
log-file into a distinct table. Therefore, add a trip_table
parameter to
- insert_trip()
- create_and_hookup_trip_from_dive()
- autogroup_dives()
- unregister_trip()
- remove_dive_from_trip()
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Currently, all trips are kept in a linked list. Replace the list
by a table in analogy to dive_table. Use this to keep the trip_table
sorted as suggested by dump_trip_list(). When inserting a trip into
the table do that after adding the dives, to avoid warnings coming
out of dump_trip_list().
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In 64e6e435f8 the trip->when field
was replaced by a function. This forgot to adapt dump_trip_list(),
which is only compiled if DEBUG_TRIP is defined. Fix the function.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Rename
- dive_get_insertion_index() -> dive_table_get_insertion_index()
- unregister_dive_from_table() -> remove_from_dive_table()
- get_idx_in_table() -> get_idx_in_dive_table()
- sort_table() -> sort_dive_table()
This will make it more straight-forward to generate these functions
from macros.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This function was not used outside of divelist.c, therefore make it
local. Moreover rename it to add_to_divetable so that the name
is generic and can be generated by a macro.
Moreover, remove the special case idx = -1, which would determine
the insertion index. Instead let the single caller who used this
feature do this.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Currently autogroup_dives() groups all dives in the global dive
list. Add a table parameter so that dives in any table can be
grouped. Thus it will be possible to pre-group dives on import,
which will be used for undo of import.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
After loading or importing, the caller usually called autogroup()
to autogroup dives if so wished by the user. This has already led
to bugs, when autogroup() was forgotten.
Instead, call autogroup() directly in the process_loaded_dives()
and process_imported_dives() functions. Not only does this prevent
forgetting the call - it also means that autogrouping can be
changed without changing every caller.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Unused dive sites were deleted on save. This clashed with the undo
system in the following scenario:
1) Delete single-use dive site.
2) Save (dive site deleted)
3) Undo (reference to freed dive site)
Therefore, as a quick-fix, keep the referenced dive site around.
Note that this also means that empty dive sites must not be
deleted, as it might refer to a dive in the undo system. Instead
only clear references to empty dive sites in the global dive
table. Factor this functionality out, as it was common to the
XML and git savers.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The starTimestamp is 4 hours apart on 2 different DCs within the sample
log. DiveDate on the dive_logs table seems to be correct, but must be
converted from human readable format.
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Seems that Shearwater cloud stores sample rate into the database and
it is not constant within the log.
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
This works to some extent to part of a sample log I received. However,
still quite a bit more work is needed.
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
I encountered this while implementing Shearwater Cloud import, but it
makes sense to increase the size for dive id for Shearwater Desktop as
well.
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
wcslen() returns the number of characters in a wchar_t string.
In the case of WideCharToMultiByte() an estimate for the size of
the utf8 buffer is needed. Using wcslen() is incorrect for such a buffer,
because for any non-ASCII character the estimate will be off by 1 byte.
Call the following instead to obtain the proper UTF8 buffer size
for the conversation:
WideCharToMultiByte(CP_UTF8, 0, utf16, -1, NULL, 0, NULL, NULL);
Also fix some missing "\n" in fprintf() calls.
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
After upgrading to Qt 5.12.0, download over BT from a DC did not work
any more. On the console the message "Connecting to port is not
supported (Uuid required)". Linus noticed earlier that we do rather
strange processing in this part of the code related to selecting port 1
or port 5. This all seems not needed (any more), but broader testing is
advised. This being stripped from the code, the mentioned error from Qt
persisted. That is strange in itself, as we did not reference port
numbers any more.
Step 2 in this commit is actually using an uuid to the call to
connectToService. Choosing an uuid seems relatively straightforward as
we can use the same one we already use for Android. That is the default
BT RFCOMM Serial Port Profile uuid. Interestingly, when changing to this
uuid we run immediately in a Qt runtime error telling us "QDBusPendingReply:
type ManagedObjectList is not registered with QtDBus.". For these 2
unexpected Qt messages, QTBUG-72742 was made. Studying the Qt source
code at this point reveals a possible workaround. Simply create a local
QBluetoothLocalDevice object, which, behind the scenes registers the Qt
internal ManagedObjectList with QtDBus.
In the meantime, Qt agrees that QTBUG-72742 is valid, and that a fix is
to be expected in a future version. At that point in time, the
declaration of the QBluetoothLocalDevice can be deleted again.
In the end, interfacing over BT works again.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
This is an attempt to fix issue #1896. While this seems a Qt issue in
combination with very specific Android devices, this might be a fix. Do
not check for a very specific state of the local BT controller, but just
check if it is powered on.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
In commit 6bf4120dbb the trip-flags
were replaced by a simple boolean. This made the was_autogen
parameter to the remove_dive_from_trip() and unregister_dive_from_trip()
functions unused. Remove these parameters.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Just like with the Aqualung i770R in 7697003498 this name follows the
pattern of a model number in ASCII encoding, followed by the serial
number of the device.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
To make data flow more clear, unglobalize the downloadTable object.
Make it a subobject of DownloadThread. The difficult part was making
this compatible with QML, because somehow the pointer to the
download-table has to be passed to the DiveImportedModel. Desktop would
simply pass it to the constructor. But with objects generated in QML
this is not possible. Instead, pass the table in the repopulate()
function. This seems to make sense, but for this to work, we have to
declare pointer-to-dive-table as a Q_METATYPE. And this only works
if we use a typedef, because MOC removes the "struct" from "struct
dive_table". This leads to compilation errors, because dive_table is
the symbol-name of the global dive table! Sigh.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
DCDeviceData was using that weird pattern where the instance
variable was set in the constructor. There is no apparent
reason to do so, therefore convert to a "normal" singleton.
Access that directly in QMLManager instead of saving it in
a member variable first.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The simplified filter-widget doesn't present lists of existing values
with counts. Thus, a whole slew of count_dives_with_*() functions
can be removed.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
These two functions were called in different contexts:
- unregister_dive(): from the undo-commands to remove the dive
from the global dive table, but not delete it. The dive was
already removed from its trip.
- delete_single_dive(): from non-undo code. Most of it not in
use and removed in a sibling-commit. Here, the dive is supposed
to be removed from its trip and a new selection is calculated.
delete_single_dive() calls unregister_dive(), which removes the
dive from its trip. Move remove_dive_from_trip() from the former
to the latter and make both functions independent. Instead
of deleting the dive explicitly in delete_single_dive(), call
the delete_dive_from_table() function.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
All callers of add_dive_to_trip() work on freshly generated dives,
with one exception, that was redundant anyway. Therefore it is not
necessary to remove the dive from a potential previous trip. Move the
responsibility of removing the dive from a trip to the caller,
respectively remove the redundant call. Add a warning message in the
case that trip is set.
Background: On import (either download or file-import) we might not
want to add trips to the global trip-list. For example to enable undo
of import but more generally to detangle that data flow. Thus,
add_dive_to_trip() should not mingle with the global trip-list,
which it has to do if a trip is deleted because the old dive was
removed.
Analysis of the add_dive_to_trip() callers:
1) core/dive.c
pick_trip():
called on freshly generated merged dive.
finish_split():
called on two freshly generated split dives.
2) core/divelist.c
create_and_hookup_trip_from_dive():
called on freshly downloaded dive in dive_cb().
called on freshly downloaded dive in record_uemis_dive().
autogroup_dives():
called on dive from get_dives_to_autogroup(), which only
finds dives that are outside of trips.
combine_trips():
unused - removed in sibling commit.
try_to_merge_into():
this call was actually erroneous - dive was already added
to trip in try_to_merge(). Remove call.
3) core/libdivecomputer.c
dive_cb():
called on freshly downloaded dive.
4) core/uemis_downloader.c
record_uemis_dive():
called on freshly downloaded dive.
5) core/load_git.c
create_new_dive():
called on freshly allocated dive.
6) core/parse.c
dive_end():
called on freshly parsed dive.
7) desktop-widgets/command_divelist.cpp
DiveListBase::addDive():
called on dive which is newly added to core.
moveDiveToTrip():
called on dive that was removed from trip a few lines above.
8) mobile-widgets/qmlmanager.cpp
QMLManager::undoDelete():
called on dive where divetrip was reset in the previous line.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In 302f6adb79 dive-splitting was made
undo-able. To this goal, the dive-splitting functions were split in
two types: Those that operate directly on the divelist and those that
only allocate the dives. The former are not in use anymore, therefore
remove them. Since only the latter remain, remove the "_dont_insert"
appendix of the name.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In 014c04f8bd merging dives was included
in the undo-system. This made the merge_two_dives() function caller-less.
Remove it.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In f427226b3b autogrouping / removal
of autogrouping was moved into the undo-machinery. This made the
remove_autogen_trips() function caller-less. Remove it.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In f427226b3b a combine_trips_create()
function was introduced that combined trips without deleting the old
trips. This was necessary for making combine-trips function undo-able.
The old combine_trips() function is not used anymore. Therefore remove
it. Rename the combine_trips_create() function to combine_trips() as
no differentiation is needed anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Currently, when selecting "Load media files even if time does not
match the dive time", the media are added to *all* selected dives.
Instead add it to the closest dive.
This seems like the less surprising behavior. Of course now if the
user really wants to add a media file to multiple dives, they will
have to do it manually.
To avoid a messy interface, this is solved by moving the iterate-
over-selected-dives loop to the core. Thus, a helper-function can
be made local to its translation unit.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
EMPTY_DIVE_STRING used to be a string-literal representing missing
information ("--"). In 6985c123d4 it
was replaced by the actual empty string. Using a literal to represent
the empty string seems a bit pointless, therefore remove it completely.
Notably:
QString(EMPTY_DIVE_STRING) -> QString()
if (temp.isEmpty()) temp = EMPTY_DIVE_STRING; -> noop
if (s == EMPTY_DIVE_STRING) -> if (s.isEmpty())
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In dive.h there was a redundant 'extern "C"' block defined inside
another 'extern "C"' block. Remove.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Desktop used the hidden_in_filter flag in struct dive, mobile
used its own vector plus a new showndives member in struct dive_trip.
Unifiy these to use the same core-facility, viz. hidden_by_filter.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
These functionality was used by the desktop filter. To unify desktop
and mobile, move it into two new functions in divelist.c
Since one of them is the only caller of is_same_day() move that
likewise into divelist.c and make it of static linkage.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
QML's ListView uses the "section" property to test if items belong to the
same section. Apparently, this must be a string and therefore we can't
pass e.g. a dive-trip object. Therefore a specially formatted string
was passed in, which was guaranteed to be unique (contained the dive-trip
pointer value) and the fully formatted trip-title and short-date.
The disadvantage of that approach is that the formatting is performed for
every dive and not every trip. Perhaps not a problem now, but it makes
it for example necessary to cache the number of filtered dives.
To be more flexible, pass in only the pointer value formatted as
hexadecimal string and provide a function to convert that string
back to a trip-pointer (in the form of a QVariant, so that it can
be passed to QML). Moreover provide two functions for formatting the
title and the short-date.
The three new functions are members of DiveListSortModel. This might not
be the perfect place, but it is easy to reach from the DiveListView.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The DiveObjectHelper::trip() function was
1) Misnamed: it returned the *location* of the trip
2) Not used outside of DiveObjectHelper
Remove it.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Just as we did for pointer to struct dive_site, make pointers to
struct dive and struct dive_trip "Qt metatypes". This means that
they can be passed through QVariants without taking a detour via
void *.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Implement the protocol in Erik Baker's document
"Oxygen Toxicity Calculations". This code uses a
third-order polynomial approximation of Baker's
equation 2. Provision is made for
PSCR and CCR dive logs and dive plans. In the
case of dive logs, the values of o2 sensors are
used if there are data from such sensors. For CCR
only the data from the first O2 sensor is used even if
there are more than one sensor. This is a potential
weakness, but this function is probably NOT the
place to calculate mean o2 values accross all sensors
and to emulate voting logic to reject info from
aberrant sensors.
Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Robert C. Helling <helling@atdotde.de>
In 64e6e435f8 the when field of struct
trip was removed. Accordingly it was not read from git repositories.
This produced a large amount of user-visible error messages.
Reinstate the trip-date and time parsing functions, but ignore
the value.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Commit 6b283e598a replaced the linked
list of dives in a trip by a table. Embarassingly, on dive deletion
the index of the dive in the table was compared for "!= 0" instead
of ">= 0". Thus, the first dive of a trip wouldn't be deleted, which
ultimately led to a crash, as different parts of the code were now
in disagreement over whether the trip is empty or not.
Fix the comparison.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The only remaining use of the tripflag was to mark dives that
were removed explicitly from a trip, i.e. shouldn't be autogrouped.
Therefore replace the enum by a simple boolean.
Currently, there is no way of unsetting the notrip flag. But this
shouldn't result in a user-visible change.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The distinction between ASSIGNED_TRIP and IN_TRIP was used to
prefer non-autogenerated trips on merging of dives. But owing
to bit rot this seem to have worked only partially anyway:
The IN_TRIP field was set in create_and_hookup_trip_from_dive()
and immediately overwritten in add_dive_to_trip() called
in the next line.
Instead, use the trip->autogen flag to check for priority and
remove the ASSIGNED_TRIP flag alltogether.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Since upgrading to gcc 8.2 it produces noisy warnings about
potentially truncated strings. It doesn't recognize that
filenr can never become >4000. So clamp it down explicitly.
Do this by adding a function that does the assembly of the
filename path. Adding unnecessary code to silence compiler warnings
is dubious, but in this case it might be reasonable.
Fix a second instance by increasing the stack-allocated buffer
to 32 bytes. Hopefully nobody has more divespots than would
fit in a 9-decimal digit number!
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When adding the dive to its trip before having filled out "when", the
dive gets added at the first position (when=0), which is usually not
correct. Instead, add the dive to its trip when all fields are correctly
filled out.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The when field gives the time of the first dive. Instead of keeping
this field in sync, replace it by a function that determines the time
of the first dive.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
To make sorting more controlled, move all sorting functions into
the core. For this, introduce a "dive_or_trip" structure, which
represents a top-level item. Adapt the DiveTripModel accordingly.
There are now three sorting functions:
1) dive_less_than
2) trip_less_than
3) dive_or_trip_less_than
These should be used by all sorting code. By moving them to a
single place, the mess can hopefully be cleaned up.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
As a step towards proper sorting, introduce a trip_less_than()
function in core. It simply sorts by the first dive, which should
be unique as dives may belong to only one trip.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The dives of each trip were kept in a list. Replace this by a
struct dive_table. This will make it significantly easier to
keep the dives of a trip in sorted state.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Up to now, dives were added to the global dive table with
add_single_dive(). Split out the funtionality to add a dive to
an arbitrary dive in the add_dive_to_table_function(). The
difference compared to record_dive_to_table is that dives
are added at a specific position or the sort-criterion given
by dive_less_than(). This will allow to use a dive tabe for trips
instead of a linked list.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
There were two versions of the insert_trip() function: one
would merge trips if a trip with the same date already existed,
the other wouldn't. The latter was introduced with the dive-list
undo work.
The problem is that the "date" of a trip (i.e. the first dive)
seems ill-defined as this is a volatile value. Moreover in
the context of making dive-import undoable this is a very
dangerous notion, as the caller needs control over when the dives
are added to a trip.
Therefore, unify these two functions and never merge trips.
The decision on merging dives now has to made by the caller.
This will be implemented in a future commit.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The Cressi specific PID was not used
when serial_ftdi_open_device tried
to open the device.
Reported-by: Daniel Krupp
Signed-off-by: Daniel Krupp <daniel.krupp@gmail.com>
The DiveTripModel places dives after trips in chronologically
ascending mode if the dive and the trip start at the same instant.
But in the core the sort order was undefined. This could lead
to a discrepancy. Therefore, implement the same sort-criterion
in the core code.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Update table of maximum oxygen exposure durations, used in CNS calulations.
This table shows the official NOAA maximum O2 exposure limits
(in seconds) for different PO2 values. It also gives
slope values for linear interpolation for intermediate PO2 values
between the tabulated PO2 values in the 1st column.
Top & bottom rows are inserted that are not in the NOAA table:
(1) For PO2 > 1.6 the same slope value as between
1.5 & 1.6 is used. This exptrapolation for PO2 > 1.6 likely
gives an underestimate above 1.6 but is better than the
value for PO2=1.6 (45 min). (2) The NOAA table only
tabulates values for PO2 >= 0.6. Since O2-uptake occurs down to
PO2=0.5, the same slope is used as for 0.7 > PO2 > 0.6.
This gives a conservative estimate for 0.6 > PO2 > 0.5. To
preserve the integer structure of the table, all slopes are
given as slope*10: divide by 10 to get the valid slope.
The columns below are:
po2 (mbar), Maximum Single Exposure (seconds), single_slope,
Maximum 24 hour Exposure (seconds), 24h_slope */
Then update Calculations of the CNS for a single dive -
this only takes the first divecomputer into account.
The previous version of the code did a table lookup and
used the max O2 exposure for the next-higher PO2 category.
This gave a shorter max O2 exposure time and a higher CNS
contribution for a specific dive segment, resulting in a
slightly conservative value of CNS, often some 2 - 3 % too high.
This code does an interpolation for PO2 values inbetween
PO2 entries in the lookup table and therefore results in a more
accurate maximum O2 exposure time for that PO2.
The maximum O2 exposure duration for each segment
is also calculated based on the mean depth of the two
samples (start & end) that define each segment. The CNS
contribution of each segment is found by dividing the
time duration of the segment by its maximum exposure duration.
The contributions of all segments of the dive are summed to
get the total CNS% value. This is a partial implementation
of the proposals in Erik Baker's document "Oxygen Toxicity Calculations" */
Overall, this PR does not radically alter the existing CNS calculation,
it only makes it more accurate and more consistent by doing
interpolation and by using mean segment depth to find PO2.
Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
Adapt get_trip_date_string() to use the same logic as get_dive_date_string():
Use the static "loc" object to translate date. Before, the trip
date was shown in C locale.
Reported-by: Philippe Massart <philippe@philmassart.net>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
There was a stray semi-colon on the beginning of a line in
DiveObjectHelper.cpp. Remove it.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Usage of the flags expanded, selected and fixup was removed some
time ago. Remove the flags too.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
For unrecognized locales we use en_US by default. It makes much more sense for
South Africa to use en_GB.
Reported-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
And fix a crash very similar to the previous commit. When trying to
save (to git) with an empty dive site, ssrf crashes.
Again, add a simple guard to prevent this.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
With the fixed sematics of get_gasmix to return the new gasmix for
the time of a gas switch (added comments to make this clear), in the
OTU calculation we need the previous gasmix for the interval up to the
current time.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
This fixes a subtle bug introduced in 5c4569247a which
unified two functions finding the gasmix at a given time
during the dive. There was a slight difference, though:
Does a gaschange exactly at that time count or not? For
the planner to work, the answer has to be in the affirmative.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Now that struct dive_site * is a proper Q_METATYPE it is not
necessary anymore to pass dive-sites as opaque uintptr_t types.
Simply pass a QVariants or directly via dive_site *.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
There was this ugly pattern of passing pointers-to-dive_site via
a QVariant of void * type. This is of course inherently unsafe.
Pass these pointers using their proper types instead. This makes
it necessary to register them in Qt's meta-type system. Doing so,
fixes a bug: QML couldn't call into updateDiveSiteCoordinates()
because it didn't know the type and thus the coordinates of
the moved flag were not reflected in the divesite-dialog.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Replace the UUID reference of struct dive by a pointer to dive_site.
This commit is rather large in lines, but nevertheless quite simple
since most of the UUID->pointer work was done in previous commits.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
MapWidgetHelper::reloadMapLocations() used an array of uuids to
add dive sites to the map only once. Replace this by an array
of pointers. This is a small piece of a larger effort to remove
dive site UUIDs.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Replace UUIDs by pointers to dive-site in mobile code. In both
cases, the value is transported via a QVariant. The function
getCoordinatesForUUID(), which was only used from mobile, can
be replaced by a getCoordinatesFor() function taking a variant
supposed to contain a dive-site pointer. Likewise, the variant
of the centerOnDiveSite function is now supposed to wrap a
pointer-to-divesite.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Another small step in removing dive-site UUIDs: use a pointer
instead of a UUID in the "uemis_helper" structure.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of passing uuids, pass a pointer to the dive site.
This is small step in an effort to remove uuids.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of passing a uuid, pass a pointer to the dive site.
This is small step in an effort to remove uuids.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of passing a uuid, pass a pointer to the dive site.
This is small step in an effort to remove uuids.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of passing a uuid, pass a pointer to the dive site.
This is small step in an effort to remove uuids.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This changes more of the dive-site interface to return pointers
instead of UUIDs. Currently, most call sites directly extract
UUIDs afterwards. Ultimately, the UUIDs will be generally replaced
by pointers, which will then simplify these callers.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The uemis downloader uses a cache for location to divesite id.
Trivially, the divesite-uuid can be replaced by a pointer. This
is a tiny step to remove divesite UUIDs.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
As a first step in removing dive-site uuids, change the interface
of the get_dive_site_*() functions to return pointers instead
of uuids. This makes code a bit more complicated in places where
the uuid is extracted afterwards (needed NULL check). Nevertheless,
these places should disappear once pointers instead of uuids are
stored in the dive-structures.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Including ssrf-version.h in an include file that a lot of files depend on
caused a ton of unnecessary recompiles with every commit. This should reduce
that problem.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The reverseGeoLookup() function defined in qthelper.cpp has long
ago moved to its own compilation unit. It is not even defined in
the headers anymore. Remove it and the now unnecessary <QNetwork*>
includes.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When creating a trip header (as it is used in the mobile app right now), we need
to show the number of dives shown, not the total number of dives in that trip.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
We assume that any dive that gets added to a trip initially gets shown. The
filter logic then needs to make sure it adjusts this number (which then makes
it easy to tell the user how many dives of that trip are visible with the
current filter).
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This feels a bit like cheating, but if we need to be able to make modifications
to the underlying dive and only have the helper object (for example inside of a
view model), doing everything through the helper object can turn into a real
performance issue.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
With this we can make it configurable if the search should include the notes field
and if the search should be case sensitive or not.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Otherwise we could match the end of one string and the beginning of the next,
so having a buddy name Linus and a dive master named Alvin would be matched
by USA.
Also add Notes to the full text search (I had forgotten those earlier).
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
A static variable was used to collect two parts of the location
string. Instead, explicitly store these two parts in two different
strings and concetenate them. One fewer variable and the program
flow is thus hopefully more clear.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Introduce a parser_state structure, which describes (most) of the
global parser state. Create such a structure in the entry routines
to the parser and pass it down to the individual functions. The
parser state is initialized and freed with the init_parser_state()
and free_parser_state() functions.
The main benefits are:
1) Isolation of parser state.
2) Keeping the global name space tidy.
3) Prevent memory leaks which could happen in truncated files by
freeing all the parser state after parse.
A somewhat controversial point might be that the individual
parsing functions are split in those that need parser-state and
those that don't. This means that there are now two versions of
the MATCH macro, viz. one for the former and one for the latter.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This is consistent with most other free_*() functions in the core
code and will make cleanup of parser state less verbose.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Export the free_picture() function from dive.c. The parser may need
this in case of truncated files to free its temporary resources.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Recently, the subsurface webservice was removed. Remove the corresponding
code in the parser. This removes a static variable, which was used
to generate unique dive-site ids.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The variables country and city used in divinglog_place()
were never freed. Free them when the pointers are reset.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The utf8_string() function is used to extract whitespace-trimmed
strings. The function would happily overwrite the pointer to
the old string, which could therefore leak (suppose an XML has
redundant attributes).
Therefore preemtively free the string output parameter. This makes
it of course necessary to only pass in NULL-initialized pointers
or pointers to owned string.
The code survives the current set of parser-tests.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of having people treat latitude and longitude as separate
things, just add a 'location_t' data structure that contains both.
Almost all cases want to always act on them together.
This is really just prep-work for adding a few more locations that we
track: I want to add a entry/exit location to each dive (independent of
the dive site) because of how the Garmin Descent gives us the
information (and hopefully, some day, other dive computers too).
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
The deco parameters need special treatment to wire them up to the
underlying deco model code. And with the new preferences setup this
is a lot of boilerplate.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
On parsing of dive computer extra data, key/value pairs are stored
in global state. They are added to the dive computer with
add_extra_data(), which makes a copy of the string. The local
copies of the strings are never freed.
free() the strings after storing them. The data still leaks in case
of unfinished parsing of extra_data tags, but this will be
taken care of in a subsequent commit.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
delete_current_divecomputer() had some duplicate code to release
dive-computer resources. Use the free_dc_contents() function instead.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The serial and fw_version strings of struct divecomputer were copied
by pointer. This worked because they were never freed or modified.
Instead, do a deep copy of the strings and free them when appropriate.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
On dive computer copy, the extra data (a list of key/value pairs)
was simply copied as a pointer. This worked because the list was
never freed nor modified. Copy and free the list on dive computer
copy and free, respectively.
This made it necessary to move the STRUCTURE_LIST_* macros up in
the dive.c file.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In commit e5dca8228e a fixed order
of the arguments to merge_dives() was introduced: first dive old,
second dive downloaded. This made the dl variable, which pointed
to the downloaded dive useless. One instance was forgotten, which
led to a null-dereference.
Remove.
Reported-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
xml_parsing_units stores the units of the currently parsed XML
file. It is not used outside of parse-xml.c. Therefore, make
it of static linkage and remove the declaration from dive.h.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
sanitize_cylinder_type(), which is indirectly called from fixup_dive(),
had ft^3 -> mliter conversion code, which was executed on the
condition "xml_parsing_units.volume == CUFT".
But nowhere in the code base would xml_parsing_units.volume ever be
set to non-metric. Moreover, xml_parsing_units reflects the units
of the latest parsed XML file, but fixup_dive() is called in numerous
contexts not related to XML parsing. Therefore, the whole piece of
code seems highly questionable.
Remove this code.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Dive site data was collected in "cur_dive_site", which was then
merged into an existing or a new dive site. But only the struct
dive_site pointed to by "cur_dive_site" and the taxonomy data
were freed, not the textual data such as name or description.
Therefore, split out the approrpriate free-ing from the
delete_dive_site() function and call that instead of a simple
free().
A similar situation occured for dives that would not be added
to the dive-table because they were deemed incomplete. Use
free_dive() here instead of a simple free() too.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
I incorrectly thought that 'ci_pointing_to_guiding_tissue' was the only
missing initialization, because that is the only one valgrind pointed at.
... that is, until I started looking at a few more dives, which showed
that there were other parts tht weren't initialized either, like
double tolerated_by_tissue[16];
double tissue_inertgas_saturation[16];
double crushing_onset_tension[16]; // total inert gas tension in the t* moment
so just make sure to clear the whole data structure, to avoid any random
behavior due to uninitialized deco state.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
In select_dive(), the selected dive would only be made the
current dive, if it wasn't previously selected. If multiple
dives were selected and the user clicked on one of them which
is not the current dive, then the current dive would be
deselected and thus not be the current dive anymore. The
only remaining dive would not be made the current dive,
because it was already selected. End result: null dive shown.
Therefore, always make the selected dive the current dive,
even if it is already selected.
Fixes#1792
Reported-by: Jan Mulder <jlmulder@xs4all.nl>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
copy_dc_renumber() is an internal function to copy dive computers
and renumber the cylinders. Since only the structure was copied,
in the case of multi-dc dives, the merged dives shared the same
computer. If one of them was freed, use-after-free crashes would happen.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This was used to track whether we had selected the native BT mode in the
download dialog. But the information is redundant as we can tell from the
device name whether this is a BT/BLE download or not.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
process_imported_dives() might delete the currently selected
dives. This could lead to use-after-free problems. Therefore,
reset the currently selected dive to the last dive.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
On dive import, dives to be added may be merged into already
existing dives. In such a case, the dive to be added is deleted.
Before doing so, it must be removed from the trip is belongs to
to avoid corruption of the trip-list.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
On merging make a deep copy of the picture list, to avoid a use-after-free
crash after the orginal dive is deleted.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In commit 8c2383b495 dive merging was
changed to not modify the original dive. On import, dives were then
merged and the original deleted. The merge_weightsystem_info() was
not adapted accordingly (deep copy of string instead of pointer),
leading to a use-after-free crash.
Resolve this by doing a deep copy.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of calling free() on all dives, call free_dive() which also
frees additional allocated data, not only the dive struct.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
There were two declaration of clear_table(), one in dive.h and one
in parse.h. The definition was in parse.c. Since the parser doesn't
even use the function, move the function and its declaration to
divelist.[ch] and remove the redundant declaration in dive.h.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This variable was only used in the divinglog_dive() function. There,
it was initialized right at the beginning and therefore there seems
to be no point in conserving its value across function-calls.
Make the variable local and remove the global version.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Comits f427226b3b and 43c3885249 of the undo series introduced 2 calls
of autogroup_dives() without checking the autogroup global boolean.
This is a bug. An import from DC (for example) then triggers an
autogrouping, the divelist is autogrouped, and the UI button
is off.
This commit solves this. I've chosen for a guard in the autogroup_dives()
that now is a no-op when called when the user did not select autogrouping.
In additon, simplified the other calls to this function, as we do
not need to check before calling any more.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
The dive-site-edit widget uses a copy of the to-be-edited site
to compare with old values. Generally, this seems overkill
(the original dive-site can be used for such a comparison).
But one place where it can't simply be removed is the taxonomy,
because the widget needs a place to store the unsaved data.
Change the code to use an explicit taxonomy structure instead
of the one provided in the copy. This should ultimately allow
removal of the latter.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The global object displayed_dive_site is used a a backing-store
by the dive-site-edit widget. All external accesses were removed,
therefore make the object local to the widget.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The global object "displayed_dive_site" is used to store the
old dive site data for the edit-dive-site widget. The fields
of the widget were initialized from this object in the show
event. Therefore the object was updated in numerous parts of
the code to make sure that it was up-to-date. Instead, move
the initialization of the object to the function that also
initiatlizes the fields. Call this function explicitly before
showing the widget.
This makes the data-fow distinctly easier to understand.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The name seems crazy until you realize that FQ is 0x4651 which is the model
number of the i770R. And the six digits are the serial number of the device.
Still crazy, but at least now you understand WHY.
Thanks to Jef for decoding that.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This makes no sense, but apparently we need to start a fresh scan in order to be able
to talk to a different BLE dive computer on the Mac.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
On macOS, we cannot connect to a BT/BLE device until we have scanned it. Right
now this just sits quietly and waits, which given how long this can take is
rather unsatisfying and might look like Subsurface is hung.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Since we trigger a scan even without the dialog to pick the right
device, we need to remember all devices that we find.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Instead of only starting the scan when explicitly asked to do so in the BT
dialog, create the discovery agent when the download dialog opens, since on
macOS we cannot connect to a device without having scanned for it first.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The reverseGeoLookup() fetches dive-site data via GPS coordinates.
The coordinates and the result were passed via the global
"displayed_dive_site" object. To make data-flow more clear,
pass data as in and out parameters instead.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
By making reply a std::unique_ptr<>, the function can be quit
from any point and the reply will be freed. This is valid according
to Qt's documentation as we're not deleting during signal processing.
This commit fixes a leak: reply was overwritten with the address of
a new object without freeing the old object.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
According to Qt's docs, the QNetworkAccessManager is supposed
to be a long-living object. Therefore, don't create one on
every geo-lookup, but a single object for all geo-lookups.
By making the object function-local it is only initiaized
on first use. Morover this limits the amount of concurrent
geo lookups.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>