PictureEntry was defined as class in imagedownloader.h and
as struct in divepicturemodel.h
A class has a vptr in front, so the difference is real at least
for the clang compiler.
Signed-off-by: Jan Iversen <jani@apache.org>
interpolate, rel_mbar_to_depth, gas_mod and
gas_mnd returns int but uses
a function that returns long, causing clang to
warn about conversion loss due to implicit conversion.
Adding a cast, shows that it is correct.
Signed-off-by: Jan Iversen <jani@apache.org>
lbs_to_grams and to_feet returns int but uses
a function that returns long, causing clang to
warn about conversion loss due to implicit conversion.
Adding a cast, shows that it is correct.
Signed-off-by: Jan Iversen <jani@apache.org>
When creating the ICD-notes the membuffer was not '\0'-terminated,
leading to output of stale data.
Reported-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
There is a space character missing in the xml generated by the
present code. Insert a space character.
Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
If loading of an image failed, we tried to see if we find a
canonical filename in the cache. There's no point in rereading
the picture if the canonical and the original filename are
the same.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The recently committed refactoring of the dive-picture code introduced
a severe bug:
If an image couldn't be loaded from disk owing to an invalid file, the
filename was interpreted as an url and loaded in the background. This
succeeded, because the file actually exists. After download, the file
would then still be invalid and the whole thing restarted, leading to
an infinity loop.
To fix this, do two things:
1) Don't even try to download local files.
2) If interpreting a downloaded file fails, don't try the downloading
business again.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
...as the usuage is not anymore about a computer but
a momentary dive mode. Rename the end indicator as well.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
The bailout events in the planner are not saved correctly.
My oversight. This commits corrects the bug
Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
Ensure that calls to add_segment() all have a appropriate divemode
for that part of the dive plan. In the case of plan(), the existing
variable 'divemode' was directly passed to add_segment. For the
functions interpolate_transition() and trial_ascent(), the divemode
was obtained by including it in the parameter list of the function
and divemode supplied by the calling function.
Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
Add a divemode column to the planner model and a
corresponding field to struct divepoint and fill it
in the corresponding functions.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Under some conditions get_current_divemode() (in dive.c) returns an
erroneous divemode. This happens when there are several events at
the very beginning of the dive, as can happen in some CCR dive logs.
This commit fixes that bug.
Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
Replaced a rather cumbersome function that that did the above. Upon
the suggestion of Robert Helling who proposed a much shorter way,
this new function replaced the previous ones. This necessitated
changes to divelist.c, profile.c and plannernotes.c, as well as
dive.c/h.
Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
Replaced a rather cumbersome function that that did the above. Upon
the suggestion of Robert Helling who proposed a much shorter way,
this new function replaced the previous ones. This necessitated
changes to divelist.c, profile.c and plannernotes.c, as well as
dive.c/h.
Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
This provides for reading of divemode change events from dive logs
and for writing them to dive logs. This applies to xml and git
divelogs. Divemode change events have the following structure:
event->name = "modechange"
event->value = integer corresponding to enum dive_comp_type (dive.c),
reflecting the type of divemode change (OC, CCR, PSCR, etc).
In the dive log file, the event value is written as a string that
corresponds to each of the enum values, e.g.
<event name='modechange' divemode='OC' />
This xml is also read from the dive log file and translated to an
appropriate value of event->value.
The file diveeventitem.cpp was udated to reflect this new way of
dealing with divemode change events.
Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
Function peek_next_divemodechange() is redundant if get_next_divemodechange()
has one additional parameter. Calls to get_next_divemodechange() were
updated in divelist.c, plannernotes.c and profile.c.
Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
I removed the special event type that has been used for bailout events.
Bailout events are now just bookmarks with a specific name "e.g. OC,
CCR, PSCR). This removes a case where a segmentation error occurred
when trying to remove a bailout event from the dive profile.
Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
This is the second step for implementing bailout. The indirect
calls to fill_pressures through add_segment() (in deco.c) are
addressed. Bailout is now fully implemented in the dive log but
not in the dive planner.
1) The parameters to add_segment() are changed to take a
divemode as the second last parameter, and not a *dive.
2) Call to add_segment() in profile.c and in divelist.c are
adapted. In divelist.c some calls to add_segment were left
using dc-> divemode instead of possible bailout. This appears
tp be the most appropriate route.
3) The functions get_divemode_from_time() and get_next_divemodechange()
in dive.c have had some small changes.
4) The calls to get_segment(0 in planner.c were changed to reflect
the new parameter list, but not updated to reflect bailout. This
is the next step.
Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
This is a first step to interpret bailout events.
1) The event structures have a new attribute: divemode.
Currently interpreted dive modes are OC, CCR, PSCR.
2) When doing fill_pressures(), the calculation is aware
of divemode. When divemode is OC (==bailout), then
the appropriate calculations of gas pressures are done.
3) Two new functions get_next_divemodechange() and
get_divemode_at_time() are created to find divemode
changes in the events linked list and to determine
the dive mode at any point during the dive.
4) fill_pressures gets a small amendment to facilitate
the correct calculations, depending on divemode.
The cases where fill_pressures() is used *outside the planner*
are changed. The result is that, for dives with bailout, the
correct gas pressures are shown on the dive profile. The
deco for bailout dives is not yet correct. This is the
next step.
Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
This is only used by one caller and there doesn't appear to be a reason
to inline it in the first place.
Suggested-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Instead of generating one ImageDownloader object per image to be
downloaded and running every image download in a separate worker
thread, use one global ImageDownloader object owned by the UI thread.
The images are downloaded using event based IO (as probably was the
intention of the QNetworkManager class).
User-visible change: after download from the internet, the thumbnail
is shown without having to change dives.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Import a camera icon from the KDE breeze theme, which is licensed
under the LGPL. Use this icon to display not-yet-loaded images
in the photos tab and the profile.
Source: https://github.com/KDE/breeze-icons
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The size of the to-be-created thumbnails was passed from DivePictureModel
to Thumbnailer. This became more and more bothersome, because the size
had to be stored with the request. Calling from Thumbnailer into
DivePictureModel was not an option, since this is not linked to all tests.
Therefore, move these functions to the Thumbnailer class.
Since the maximum thumbnail size is now known to the thumbnailer, the
dummy and failure images can be precalculated, which makes switching
between dives faster.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Create a new class, which performs all thumbnailing code.
This is mostly code reshuffling. Thumbnails are extracted
either from a cache or thumbnail calculation is started in
a worker thread.
Since getHashedImage() is called from a worker thread it
makes no sense to call subfunctions in yet another worker
thread. Remove these calls.
In contrast to the previous code, on error the background
thread produces a failure image, but it is not yet shown.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In imagedownloader.cpp the only thing we need from the picture struct
is the filename. Therefore, use QStrings instead of the picture struct.
This simplifies memory management.
Remove the clone_picture() function, which is not needed anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
SHashedImage was a subclass of QImage, which fetched the image according
to the filename hashes. Turn this into a function, as this is much more
idiomatic and flexible.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
On startup, convert an old-style thumbnailHash to individual
thumbnail files. Show a modal progress bar while doing so.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The old code loaded all thumbnails into memory at once. This does
not scale to logs with thousands of pictures. Therefore, save
the pictures to individual files and only load the currently
needed pictures.
Currently, this will make changing switching between dives slower,
because the thumbnails are loaded from disk. In the future, it
is planned to do this in a background thread without blocking
the user interface.
A notable difference to the old code: Thumbnails are now indexed
by the image-hash (i.e. the content of the raw image) and not
by the filename of the image. Thus, different paths to the same
image should only be saved once.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Detection isn't required, but it makes things easier. For the Mares dive
computers we only see the Bluelink, so we can't tell which dive computer is
connected to it. We guess "Quad", but the user can pick a different one.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
When generating fake profiles for manually entered dives, fake_dc() and
plan() used different final ascent rates of 5 m/min and 4.5 m/min,
respectively. This led to dives that were 6 seconds longer than entered
by the user and to confusion. See #554.
Therefore, use the same ascent rate taken from the preferences field
flag.ascratelast6m in both cases.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
1) The connection for the display of CCR-setpoint o2SetpointGasItem
was erroneous, being connected to partialpressuregasSettings. It
is now correctly connected to technicalDetailsSettings.
2) The colour of the setpoint graph is changed from PO2_ALERT (red) to
an orange colour in order to show setpoint in red only when it
exceeds 1.6. This emphasises the visibility of red parts of the
gas pressure graphs whenever gas limits are exceeed.
Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
By not filling out this value, entering of manual dives was broken
for dive lengths starting with a digit 5 or higher.
Fixes#1211
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
fake_dc() used to return a statically allocated dc with statically
allocated samples. This is of course a questionable practice in
the light of multi-threading / resource ownership. Once these
problems were recognized, the parameter "alloc" was added. If set
to true, the function would still return a statically allocated
dc, but heap-allocated samples, which could then be copied in
a different dc.
All in all an ownership nightmare and a recipie for disaster.
The returned static dc was only used as a pointer to the samples
anyway. There are four callers of fake_dc() and they all have access
to a dc-structure without samples. Therefore, change the semantics
of fake_dc() to fill out the passed in dc. If the caller does
not care about the samples, it can simply reset the sample number
to zero after work.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This function looks for the last gas change before a
given time. We should initialize it with a gaschange
event as we might later use this event to read a
gasmix from it.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
This commit allows plotting the OC-equivalent pO2 graph for PSCR
dives. This happens in both the cases where there is no external
O2-monitoring AND when there is external pO2 monitoring. The
calculations are only done for PSCR dives and is achieved as
follows:
1) Within plot-info create a pressure-t called OC_pO2 in
profile.h and populate this variable with the open-circuit
pO2 values in profile.c.
2) Create a new partialPressureGasItem ocpo2GasItem in
profilewidget2.h and, in profilewidget2.cpp, initialise it
to read the plot-info OC_pO2 values and enable its
display by using the setVisible method. The
diveplotdatamodel was also touched in order to achieve
this.
3) Create a pref button that controls the display of OC-pO2 for SCR dives
4) Change the colour of the OC-pO2 grpah to orange
5) Change the connection of the crr_OC_pO2 signal to be appropriate
6) rename the OC_pO2 attribute to scr_OC-pO2
Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
The previous code would not add the non-LE address for dual stack
devices. Unfortunately, even with this fix we still don't get the
correct result for the dual stack Shearwater Petrel 2 that I have
for testing as Android incorrectly reports it as a BLE-only device.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Only filter against the hard coded list if no other supported transports
are available for a dive computer.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
For example, even on platforms that support libusb, libdivecomputer
might be compiled without such support.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
If the user specified bluetooth, we really should pick bluetooth, not
probe and possibly fall back to something else.
We should also honor the users choice of BLE vs classic BT.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
In firmware version 2.97 the setting 0x38, SETPOINT FALLBACK, has bin
obsoleted and we get a error when trying to write to it.
This removes this setting.
Signed-off-by: Anton Lundin <glance@acc.umu.se>
On Android we still need to do more filtering as only some of the USB
divecomputers are supported. But on iOS this takes care of it without
the hard coded list.
Additionally, if built without BT or BLE support, the corresponding dive
computers are no longer shown (e.g. Perdix AI on Windows).
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This opportunistically uses a cache of 'fingerprints' for already
downloaded dives.
As we download data from a dive computer, we save the fingerprint and
dive ID of the most recent dive in a per-divecopmputer fingerprint cache
file.
The next time we download from that dive computer, we will load the
cache file for that dive computer if it exists, verify that we still
have the dive that is referenced in that cachefile, and if so use the
fingerprint to let libdivecomputer potentially stop downloading dives
early.
This doesn't much matter for most dive computers, but some (like the
Scubapro G2) are not able to download one dive at a time, and need the
fingerprint to avoid doing a full dump. That is particularly noticeable
over bluetooth, where a full dump can be very slow.
NOTE! The fingerprint cache is a separate entity from the dive log
itself. Unlike the dive log, it doesn't synchronize over the cloud, so
if you download using different clients (say, your phone and your
laptop), the fingerprint cache entries are per device.
So you may still end up downloading dives you already have, because the
fingerprint code basically only works to avoid duplicate downloads on
the same installation.
Also, note that we only have a cache of one single entry per dive
computer and downloader, so if you download dives and then don't save
the end result, the fingerprint will now point to a dive that you don't
actually have in your dive list. As a result, next time you download,
the fingerprint won't match any existing dive, and we'll resort to the
old non-optimized behavior.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This creates a new libdivecomputer_device_open() helper, and makes
downloading and configuration use it to open the dive computer device
using the proper protocol.
The IRDA case was tested by Sébastien Dugué - I had initially left it
undone believing that "nobody uses IRDA".
Reported-and-tested-by: Sébastien Dugué <sebastien.dugue.subsurface@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This converts our old custom IO model to the new model that
libdivecomputer introduced. This is partly based on Jef's rough patch
to make things build, with further work by me.
The FTDI code is temporarily disabled here, because it will need to be
integrated with the new way of opening devices.
The ble_serial code goes away entirely, since now libdivecomputer knows
about BLE transport natively, and doesn't need to have any serial
wrapper around it.
Signed-off-by: Jef Driesen <jef@libdivecomputer.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Remove a semicolon after Q_OBJECT and a few others after the closing
braces of while loops.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This should have been caught by our build check, but it turns out that
that one isn't correctly reflected in its Travis status.
Oops.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Up until now we just reused the macos.c file for convenience, hard coding a
specific file path that may or may not work on iOS. Instead get the preferred
path from Qt and for this we need to be able to call into Qt, so this needs to
be a C++ file.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Technically, these aren't BLE, these are just the three devices that
are supported by the Mares Bluelink Pro Bluetooth download dongle.
While we are at it, admit that this code is no longer automatically
created but instead maintained by hand.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Identify segements that fullfill the folllowing criteria for
the leading compartment:
He is off-gasing while N2 is on-gasing
Overall there is on-gasing
Add a line to the info box for those segments
Signed-off-by: Robert C. Helling <helling@atdotde.de>
The planner notes were constructed using a sequence of
len += snprintf(buf, buflen - len, ...);
calls. This will fail once len > buflen, because the second parameter
of snprintf is unsigned. Note that snprintf returns the number of
bytes that would have been written if it weren't truncated.
Fix this by using membuffer with put_format()/put_string() and
asprintf_loc().
Fixes#1155.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
get_dive_date_c_string() and get_current_date() return copied strings.
Make this explicit by returning non-const pointers.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Move duplicate code, which reads '*' arguments from va_list into
parse_fmt_int() function. To pass pointers-to-va_list, the va_list
has to be copied first.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
qthelper.cpp is already quite voluminous. Move the recently
introduced localized versions of (v)snprintf() and put_format()
into their own translation unit.
Moreover, adopt C-style semantics for asprintf_loc(). This function
will be used to remove fixed-size buffers in core/plannernotes.c.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Previous taglist_get_tagstring signature/implementation did not allow
handling of cases where inputted buffer could not contain all tags.
New implementation allocates buffer based on pre-computed size allowing to
insert all tags in the returned string.
Added get_taglist_string in qthelper to handle conversion to QString
Added TestTagList with tests for taglist_get_tagstring
Signed-off-by: Jeremie Guichard <djebrest@gmail.com>
Same as default branch, but as 0x01 appears to be converted from DM4 to
DM5, let's just be explicit about it.
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Currently the best guess of sampleBlob format. Unfortunately there seems
to be some version of DM that stores the temperature in different
location that I have not been able to figure out yet. Note that some
version of DM does not utilize sampleBlob but specific blobs for each
value (temperature, pressure, ...).
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Parse MP4s and related video files and extract the creation timestamp
from the "mdhd" (media header) atom.
Introduce helper function templates to extract arbitrary-length
unsigned integers in big-endian format from file or memory.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Thus, metadata has to be only read once and the picture_load_exif_data()
function can be removed.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
To ease trouble-shooting of the picture thumbnailer add a number
of debug- and info-messages.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Correct a bug in finding the minimum heartrate.
Use the minimum and maximum heartrate value to set min/max and
tic distance for the heartrate axis in the profile.
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
This is a preparation for supporting videos. Some video formats may
not possess such meta data, or we may not yet be able to parse them.
In such a case, use the file creation date.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This is a preparation for video support. We don't want to read a whole
potentially multi-GB file into memory just to detect that it isn't a
JPEG. Especially since at the moment EXIF metadata are parsed twice,
once for GPS, once for timestamp.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
strdup(qPrintable(s)) and copy_string(qPrintable(s)) were such common
occurrences that they seem worthy of a short helper-function.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Replace constructs of the kind
s.toUtf8().data(),
s.toUtf8().constData(),
s.toLocal8Bit().data(),
s.toLocal8Bit.constData() or
qUtf8Printable(s)
by
qPrintable(s).
This is concise, consistent and - in principle - more performant than
the .data() versions.
Sadly, owing to a suboptimal implementation, qPrintable(s) currently
is a pessimization compared to s.toUtf8().data(). A fix is scheduled for
new Qt versions: https://codereview.qt-project.org/#/c/221331/
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Make arguments to set_informational_units(), set_git_prefs(),
set_userid(), dive_remove_picture() and update_event_name()
"const char *" for consistency with the rest of core/dive.c.
This will allow replacing toUtf8().data() with the constData()
version in a subsequent commit.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This was only done explicitly for Windows. Other platforms were
implicitly supposed to be UTF-8.
Suggested-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
So because I merged with upstream libdivecomputer, and it no longer does
the "halfduplex emulation" thing in the IO layer, and instead does it in
the only Suunto backend that needed it, that also affected our custom IO
layer in subsurface.
Sure, I could have left a dummy interface and left subsurface with some
ugly dead code, but it's really better to just get rid of the code.
So when Dirk pulls in the libdivecomputer updates from
https://github.com/torvalds/libdc-for-dirk.git Subsurface-branch
this patch to remove the halfduplex code in subsurface is also needed.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Stefan Fuchs <sfuchs@gmx.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
PSCR dives with o2 sensors are more like CCR dives. The math is exactly
the same, its just a different diluent and a different po2.
Signed-off-by: Anton Lundin <glance@acc.umu.se>
This introduces a fixup function that walks all the samples and
populates the no_o2sensors if its zero and supposed to be something
else.
There is a bug somewhere which Willem hit, causing this to never be set.
Reported-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Anton Lundin <glance@acc.umu.se>
In the if case above, we already conclude its a OC dive, but its cleaner
to actually pass the current mode instead of a hard coded value.
This also makes the code less prune to future bugs.
Signed-off-by: Anton Lundin <glance@acc.umu.se>
The map widget on the mobile version requires that
a dive object from a model has a dive_site uuid.
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Consistently do not use a space between value and unit.
Consistently do not use a space between "name:" and value.
Add "/min" for SAC rate.
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
The hash field in the picture-structure was in principle non-operational.
It was set on loading, but never actually changed. The authoritative
hash comes from the filename->hash map.
Therefore, make this explicit by removing the hash field from the
picture structure.
Instead of filling the picture structure on loading, add the
hash directly to the filename->hash map. This is done in the
register_hash() function, which does not overwrite old entries.
I.e. the local hash has priority over the save-file. This
policy might be refined in the future.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Passing of QStrings and QByteArrays was inconsistent in qthelper.cpp.
Unify to passing const-references. Passing by value is no big deal, since
QString and QByteArray do copy-on-write "optimization". Nevertheless, let's
keep it as consistent and effective as possible.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
learnHash() was always called in conjunction with add_hash(). The
pattern was that a local filename and a hash were connected in
the hash-to-filename and the filename-to-hash maps. Then, the
original picture-filename or url were registered in the filename-to-hash
map.
This commit changes learnHash() to take three parameters (original-filename,
local-filename and hash) and do all of the above. The new code is
simpler because no dummy picture struct has to be generated in
DiveListView::loadImageFromURL().
The tests were extended to check for all hash<->filename associations.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
learnHash() is called either on a local picture structure
[DiveListView::loadImageFromURL()] or on a cloned picture structure
[ImageDownloader::saveImage()]. In neither case the picture structure
is passed to the frontend. Therefore, storing the new hash in the
picture struct is not necessary.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
hashPicture() calls hashFile(), which calls add_hash(). add_hash()
updates the filename-to-hash and hash-to-filename maps. Therefore,
there is no point in calling learnHash() in hashPicture(), which
updates the filename-to-hash map.
Note that learnHash() updates the picture-struct with the new hash,
but since hashPicture() works on a cloned picture-struct, which
is free()d in hashPicture(), these changes are lost anyway.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
updateHash() and hashPicture() did the same thing, with the exception
that hashPicture() marked the dive list as changed if a hash changed.
This seems like a good idea in any case, therefore always use
hashPicture().
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
If loading from hash failed in the saveImage() slot(!) it would
recurse into loadFromUrl(), which would generate a new network
reply. Very scary and a (small) wonder that it worked.
Let's try to make this all more explicit.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The QNetworkAccessManager is only used in the load() function. No
point in it being a subobject.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
1) Destroying the QNetworkManager seems like a bug: this was a
subobject of ImageDonwloader. It's mysterious how this didn't
crash.
2) Instead of calling deleteLater() on the reply object, simply
delete it after completion.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
A cloned picture struct would not be freed if the filename was already
in the queued-for-download set.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This changes the numeric format of many values printed to the UI to
reflect the correct numeric format of the selected locale:
- dot or comma as decimal separator
- comma or dot as thousands separator
In the Qt domain the `L` flag is used case specific mostly
in qthelper.cpp.
Then the helper functions get_xxx_string() are used more consistently.
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
Replace snprintf() and put_format() by snprintf_loc() and
put_format_loc(), respectively to localize formatting of
integers and floats.
Acked-by: Stefan Fuchs <sfuchs@gmx.de>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Replace snprintf() and put_format() by snprintf_loc() and
put_format_loc(), respectively to localize formatting of
integers and floats.
Acked-by: Stefan Fuchs <sfuchs@gmx.de>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit introduces functions:
- QString asprintf_loc(const char *cformat, ...);
- int snprintf_loc(char *dst, size_t size, const char *cformat, ...);
- put_format_loc(struct membuffer *, const char *fmt, ...);
and their va_arg equivalents, which use Qt's QString::arg() formatting
options to render the strings.
The snprintf_loc() function takes care not to truncate multi-byte
UTF-8 encodings. Thus, on overflow, the resulting string might be
shorter than size-1.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Add a combo box for water types with defaults for fresh water, sea water
and the EN 13319. All values taken from units.h, where EN 13319 was added
beforehand.
Custom values can be entered through a spinbox.
Also changed "Salinity" in TapDiveInformation.ui to "Water type".
Translation required!
Signed-off-by: Oliver Schwaneberg <oliver.schwaneberg@gmail.com>
Change the strategy when to allow cylinder removal from a dive:
- Not remove when cylinder has gas switch events, in any other cases
allow removal
- Remove this whole "cylinder with same gas" thing being a criteria
for cylinder removal
When removing a cylinder which has corresponding pressure info in
samples, also remove this pressure info from the samples.
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
Since all qt-helpers are defined in qthelper.cpp, there seems to be
no reason to have two include files. By unifying the two files,
duplication and inconsistencies are removed. The C++-only part is
simply compiled away with #ifdefs.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Each callsite of saveBtDeviceInfo() has a QString, which is converted
to a C-string, passed and immediately converted back. Remove these
conversions by taking a reference to QString directly.
getBtDeviceInfo() is not as clear. Here, the callsite has a C-string
handed down from libdivecomputer. Nevertheless, pass a reference of
QString here as well. Firstly, for reasons of symmetry. Secondly,
to avoid multiple conversions in the getBtDeviceInfo() functions.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Use struct temperature_t for temperatures in struct stats_t and
use get_temperature_string() when printing these temperatures for
statistics and HTML export.
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
Replace an early "return" in add_plan_to_notes() with a "goto finished;"
This was the initial idea of doing it plus it fixes a potential memory
leak (missing free for icdbuffer).
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
Mostly replace "return (expression);" by "return expression;" and one
case of "function((parameter))" by "function(parameter)".
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This unifies behavior of XML & git saving. Now, in both cases, the
picture hash is extracted from the filename-to-hash map instead of
using the picture structure.
This seems more robust, because the picture structure is not necessarily
updated by learnHash(). The latter may operate on a copy of the picture
structure.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The following statement in the hashstring() function:
return hashOf[QString(filename)].toHex().data();
returns data of the temporary QByteArray generated by toHex().
Thus, the caller will access released memory, which could lead to
data corruption.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
With DECO_CALC_DEBUG != 0, divelist.c and profile.c have calls
to dump_tissues() without passing a 'struct deco_state' argument.
Fixes#1105
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
The images to load are kept in a set to avoid multiple loading of
the same picture. The set was protected with a mutex.
Problem: the mutex was not released before loading the picture,
effectively serializing the loading of pictures.
Therefore unlock the mutex once the set is updated.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In core/imagedownloader.cpp the helpers cloudImageUrl() and loadPicture()
are made of static linkage.
The global variables queuedPictures and pictureQueueMutex were moved
into the loadPicture() function, because they are used only there.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This change deals with issue #554.
If you enter a dive duration manually, the cell renderer cuts the seconds
away when the changes are saved. I added the helper "render_seconds_to_string"
as a counterpart to "parseDurationToSeconds". The helper keeps the seconds,
if not null. The rendering of the cell is done at two places in the code,
so I think it is cleaner to add a dedicated method for it.
Signed-off-by: Oliver Schwaneberg <oliver.schwaneberg@gmail.com>