Commit graph

887 commits

Author SHA1 Message Date
Berthold Stoeger
7bd860f2b7 Cleanup: Use QString as parameter for [get|save]BtDeviceInfo()
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>
2018-02-26 08:52:34 +01:00
Stefan Fuchs
d9c0df0142 Correctly suppress display of ICD table if prefs.show_icd is false
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-02-25 02:04:30 +02:00
Stefan Fuchs
b5b5d619be For prefs option show_icd add missing call for loading
Add the missing call to load the prefs option show_icd in function
SettingsObjectWrapper::load()

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-02-25 02:04:30 +02:00
Stefan Fuchs
4d377926e0 Whitespace cleanup in core/divelogexportlogic.cpp
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-02-24 11:45:17 -08:00
Stefan Fuchs
862e121532 Correct comments for struct temperature_t value range
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-02-24 11:45:17 -08:00
Stefan Fuchs
ca4ccadcc4 Use duration_t for total_sac_time in struct stats_t
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-02-24 11:45:17 -08:00
Stefan Fuchs
95a23cf470 Use temperature_t for temperatures in struct stats_t
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>
2018-02-24 11:45:17 -08:00
Stefan Fuchs
f08e24d65b Exit add_plan_to_notes() in plannernotes.c always via label finished
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>
2018-02-22 21:48:46 +02:00
Robert C. Helling
818ab36b24 Indicate direction of transition in verbatim plan
Replace "Transition to" by "Ascent to" or "Descend to"

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-02-20 14:29:31 +01:00
Berthold Stoeger
5c248d91cd Coding-style: remove superfluous parentheses
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>
2018-02-17 19:38:52 -08:00
Berthold Stoeger
d5d830eac0 Cleanup: Save hash from filename-to-hash map to git repository
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>
2018-02-17 11:06:30 -08:00
Berthold Stoeger
e880948d73 Cleanup: return copied string from hashstring()
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>
2018-02-17 11:06:30 -08:00
Berthold Stoeger
9ca7cf0f1e Cleanup: remove outdated TODO item
report_error() automatically pushes error messages. No need for a
separate signal.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-02-12 11:11:34 -08:00
Berthold Stoeger
7fedc5931a Cleanup: remove declaration of get_error_string()
This function was removed in #8f81a22e7f26729cc2f4902ba7db8f696314539f.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-02-12 11:11:34 -08:00
Lubomir I. Ivanov
2b4115d712 dump_tissues: fix missing 'struct deco_state' argument
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>
2018-02-12 07:48:34 +01:00
Robert C. Helling
920aa613c9 Add a preference to turn on ICD warnings
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-02-10 10:26:34 +01:00
Berthold Stoeger
fe133e2cca Cleanup: unserialize loading of pictures
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>
2018-02-07 09:44:43 +01:00
Berthold Stoeger
4c84c0baf1 Cleanup: remove unused typedef
The type SHashedFilename defined in core/imagedownloader.h was not
used anywhere.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-02-07 09:44:43 +01:00
Berthold Stoeger
9986ce25d7 Cleanup: Make local helpers and variables of static linkage
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>
2018-02-07 09:44:43 +01:00
Oliver Schwaneberg
eb38a64149 Do not remove seconds from duration input field
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>
2018-02-04 13:40:02 -08:00
Stefan Fuchs
b5ce06c8b9 Free various struct membuffer in different functions
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-02-02 11:29:55 -08:00
Willem Ferguson
5416fc7afb Print icd data only when it is really needed
Reduce the impact and visibility of icd calculations by writing
the data to the planner output only in cases where gas switches
involve:

1) ascent
2) helium is used as part of breathing gas
3) gas switch results in an increase in partial pressure of nitrogen.

Coding change:

1) The code for writing the header of the icd table as well as
   the inclusion of the data in the planner output is made
   conditional on the above three requirements. This involves
   moving the code that writes the table header into the
   function that writes an icd data item to buffer.
2) Manipulation of a boolean variable that controls writing
   of the table header to buffer and that also determines
   whether any icd results should be inluded in the planner
   results.
3) Reorganise comments so that there are not multiple tabs between
   the code and the start of a comment.

Correct type and insert braces where important

Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-02-02 13:14:09 +01:00
Jan Mulder
494ad26540 mobile cleanup: restyle construction of locationlist
See also e6e1473e6. The construction of the locationlist
was not the same as the 3 previous lists, and it needs
the inclusion of a new model file (divelocationmodel.cpp)
in the mobile app. In addition, as the mobile app is mainly
interested in a simple stringList (model) to populate a HintsText
field (or maybe later a combobox), this stringlist is added
to the model, to easy interfacing with QML.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-01-31 14:48:14 +01:00
Jan Mulder
83259008e7 mobile cleanup: unduplicate code and do not loop over dives (3)
See e6e1473e6. Exact same commit but here for the
list of divemaster. The careful reader will spot a
small addition to the clearDetailsEdit() QML function.
Two more field are cleared.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-01-31 14:48:14 +01:00
Jan Mulder
572fc47071 mobile cleanup: unduplicate code and do not loop over dives (2)
See e6e1473e6. Exact same commit but here for the
list of buddies.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-01-31 14:48:14 +01:00
Jan Mulder
fed2c5b6a1 mobile cleanup: unduplicate code and do not loop over dives (1)
This is the first of a set of commits that are (very) similar.
It appeared that a number of more or less static lists, which are
constructed by a loop over all dives in the logbook, were executed
when changing focus to a next dive. For example, the in this
commit addressed list of used dive suits.

What was wrong was that the suitList was linked to a dive. There
is only a need to construct the list of used suits when data is
changed (and obviously, once on startup of the app). Further, it
appeared that a lot of code was duplicated and that we can use
(in this case) the same code from the desktop completionmodels.cpp.

Basically, this commit involves the following changes:
- include completionmodels.cpp in mobile and desktop (so move
it from the desktop only category to the generic category).
- remove double code from DiveObjectHelper.cpp
- Do not differentiate in the init phase and the normal refresh
of the list
- the per dive logic is now only the getting of a previously
constructed list (in init or update of the divelist).

There are no visible changes in the UI, other than a better
performance when scrolling over dive details.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-01-31 14:48:14 +01:00
Oliver Schwaneberg
728e007c5c uemis: code refactoring
- Variable max_deleted_seen had no effect and is removed.
- Results of read/write operations are evaluated to assert success
  and to prevent compiler warnings.

Signed-off-by: Oliver Schwaneberg <oliver.schwaneberg@gmail.com>
2018-01-31 14:47:47 +01:00
Berthold Stoeger
8f81a22e7f Make report_error() reentrant
Remove the global error buffer and pass the error string directly
to the frontend. The frontend is then responsible for accumulating
errors.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-31 14:47:26 +01:00
Oliver Schwaneberg
5a9faf2fea uemis: Fix mapping of object_ids to dive numbers
When performing a factory reset to an uemis, the object_ids within the divelog
will not be reset. Nevertheless, the dive numbers are reset to 1.
So, the first log will have a positive offset n to the first dive number.
The uemis-downloader used the object_id from the logs as a start point for
getDive, if dives were already synced before. This causes the sync to stall.
I prevent this by subtracting the lowest object_id from the requested before
using it as dive number.

Signed-off-by: Oliver Schwaneberg <oliver.schwaneberg@gmail.com>
2018-01-31 14:46:30 +01:00
Oliver Schwaneberg
8accd08715 uemis: speed up synchronisation of same divesites
uemis-downloader downloads the dive spot for each dive, even if the same
location was already downloaded before within the ongoing synchronization run.
I modified the function "get_uemis_divespot" to remember all requested
divespot_ids and their mapping to uuids.

New helper functions:
    - static void erase_divespot_mapping()
    - static void add_to_divespot_mapping(int divespot_id,
                                          uint32_t dive_site_uuid)
    - static bool is_divespot_mappable(int divespot_id)
    - static uint32_t get_dive_site_uuid_by_divespot_id(int divespot_id)
    The memory leak is removed through the call of erade_divespot_mapping().

Signed-off-by: Oliver Schwaneberg <oliver.schwaneberg@gmail.com>
2018-01-27 12:23:47 -08:00
Robert C. Helling
c6d626c618 Limit recreational dives to 6 hours
Otherwise, with large gradient factors, one can have infinite NDL
which result in an infinite loop when no gas is set.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-01-26 07:04:45 +01:00
Willem Ferguson
b9ac89574e Planner: print icd information at 0.1 resolution
The gas fractions (in %) are now printed at a resolution of 0.1%
and not at 0.01% as previously.

The string in the info box that provides icd data is reformatted
so that the info-box is as narrow as possible.

Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-01-24 22:03:42 +01:00
Jan Mulder
2c8693f468 Do not add double ConnectionList items
Refuse to add a ConnectionList row, when the row is already
there. This, obviously, prevents double items.

Fixes: #1069

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-01-24 16:19:09 +01:00
Robert C. Helling
c89cfcccbe Only give ICD warning if pN2 increases
as otherwise there are warning on the descent.

The ICD line in the info box is generated for all
gas switches with decreasing He content.

Also change the presentation in the info box to align it
with the notes.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-01-21 15:24:46 +01:00
Stefan Fuchs
c866b82f35 Planner notes min gas: Remove incorrect line wrap inside printf string
With old code the tabs at the start of the second line were incorrectly
added to the string.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-01-21 09:56:35 +01:00
Stefan Fuchs
81e9b230ca Planner notes ICD: Format HTML with DIV, do table title differently
In the planner notes format the HTML for different sections with
div tags.

Put the table title for the ICD table outside the table because then the
alignment looks a little bit nicer.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-01-21 09:56:35 +01:00
Stefan Fuchs
d3bcf02bbc Planner notes ICD: Coding style change only
Avoid the need for a char array for the "old_gas_name" by passing
two pointers to the gasmixes to the add_icd_entry function and
calling helper function gasname() there twice.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-01-21 09:56:35 +01:00
Stefan Fuchs
e408e32ed6 Planner notes ICD: Print correct runtime for gaschange
If a gaschange happens at the beginning of a segment, currently the
wrong runtime (end of segment time) is printed in the ICD table.

This is corrected here.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-01-21 09:56:35 +01:00
Willem Ferguson
f2fe389abd Move function isobaric_counterdiffusion()
Move the above function from plannernotes.c to dive.c so that
it is available to be called from the dive log part of the
software, and not only from the planner. The following was done:

1) Edit the comment above the code to make it more accurate
2) Move the structure icd_data to dive.h
3) Create an external reference in dive.h for the above function
4) Copy the body of isobaric_counterdiffusion() to dive.c

Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-01-20 10:10:09 +01:00
Willem Ferguson
f072f78c29 Implement ICD calculations in planner output
This patch implements the calculation and printing of icd parameters
in the dive planner output. It does:
1) icd parameters are calculated following the rule-of-fifths for
   OC trimix dives. For each gas change on the ascent that involves
   helium, the change in gas composition as well as the change in
   partial pressures are shown. If rule-of-fifths is exceeded, a
   warning message is prinetd.
2) An independent function is provided that in principle enables
   calculation of icd paramaters outside of the context of the
   dive planner.

Further updates to icd calculations

These changes respond to #1047. Code style conventions have been
improved. The ICD table is now also printed when the planner is
set to verbatim mode. The code that created the html icd results
has been moved to a function. This does not make the code more
efficient (many parameters passed) but it makes the code more clean.

Free a new dynamic variable (old_gas_name)

Stylistic changes to new code in plannernotes.c

Changes in comments to explain some of the changes I made.
Preparation of comments and functioning of isobaric_counterdiffusion()
and its dependent data structure for possible transfer to dive.c
and dive.h after finalisation and merging of the present PR.
Smaller stylistic changes to conform to our coding rules.

The several comments and suggestions during github review
(@atdotde, @leolit123, @sfuchs79) are incorporated.

Fixed up mis-aligned comments and text descriptions by replacing
tab characters with space characters, thereby hard-forcing
alignment of indented lines of text.

Remove parameter *dive from function isobaric_counterdiffusion().

Improve a few constructs to conform to our style rules.

Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-01-19 19:43:16 +02:00
Willem Ferguson
9a8bab21c9 Improve profile display in planner
This patch allows the planner to save the last manually-entered
dive planner point of a dive plan. When the plan has been saved
and re-opened for edit, the time of the last-entered dive planner
point is used to ensure that dive planning continues from the same
point in the profile as was when the original dive plan was saved.
Mechanism:

1) In dive.h, create a new dc attribute dc->last_manual_time
   with data type of duration_t.
2) In diveplanner.c, ensure that the last manually-entered
   dive planner point is saved in dc->last_manual_time.
3) In save-xml.c, create a new XML attribute for the <divecomputer>
   element, named last-manual-time. For dive plans, the element would
   now look like:
   <divecomputer model='planned dive' last-manual-time='31:17 min'>
4) In parse-xml.c, insert code that recognises the last-manual-time
   XML attribute, reads the time value and assigns this time to
   dc->last_manual_time.
5) In diveplannermodel.cpp, method DiveplannerPointModel::loadfromdive,
   insert code that sets the appropriate boolean value to dp->entered
   by comparing newtime (i.e. time of dp) with dc->last_manual_time.
6) Diveplannermodel.cpp also accepts profile data from normal dives in
   the dive log, whether hand-entered or loaded from dive computer. It
   looks like the reduction of dive points for dives with >100 points
   continues to work ok.
The result is that when a dive plan is saved with manually entered
points up to e.g. 10 minutes into the dive, it can be re-opened for edit
in the dive planner and the planner re-creates the plan with manually
entered points up to 10 minutes. The rest of the points are "soft"
points, shaped by the deco calculations of the planner.

Improvements: Improve code for profile display in dive planner

This responds to #1052.
Change load-git.c and save-git.c so that the last-manual-time is
also saved in the git-format dive log.

Several stylistic changes in text for consistent C source code.

Improvement of dive planner profile display:

Do some simplification of my alterations to diveplannermodel.cpp

Two small style changes in planner.c and diveplannermodel.cpp
as requested ny @neolit123

Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-01-19 12:38:11 +02:00
Berthold Stoeger
7594e7ca7f Unify username handling of remote git repositories
The username was extracted from https:// urls but not from ssh://
urls. Unify this by extracting the username from any remote url.
This is done with regard to unifying the file handling in the
frontend.

For this approach to work, the credential callback of the ssh://
transport had to be adapted. It now also supports username/password
in addition to private-key authentication.

Currently, the only way the user can use the username/password
authentication is by deleting a potential public key.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-19 09:45:08 +02:00
Berthold Stoeger
5a767ce964 Support non-https:// repositories for saving
On saving to a remote git repository, the transport was set to https://,
which broke saving to ssh:// repositories. Instead determine the
transport from the remote url.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-19 09:45:08 +02:00
Berthold Stoeger
cec642b4d2 Create local cache and push to remote for any remote repository
This used to be done only for cloud repositories.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-19 09:45:08 +02:00
Berthold Stoeger
0b0eacce30 Check cloudserver availability only for cloud repositories
The check used to be done for any https:// repository.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-19 09:45:08 +02:00
Berthold Stoeger
b188f00587 Factor out counting of authentication attempts into function
Moreover, make the maximum number of authentication attempts a
const variable.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-19 09:45:08 +02:00
Jan Mulder
88658bd9e3 Use different preference file for mobile
This is a change mainly for developers working on both mobile and
desktop application. As the current setup is that all preferences
are stored in one file (Subsurface.conf), for both mobile and desktop,
the unwary developer might get confused that the things tested on
mobile-on-desktop are not working on mobile-on-device. As we share
a lot of code between the desktop and the mobile code, also
our fairly extensive set of preferences play a significant role
in the inner workings of our applications.

So, this commit introduces an own preferences file for mobile
(on desktop) resulting in the preferences between the plain
desktop apllication now invisible to the mobile-on-desktop
application and vise versa. Making the mobile-on-desktop a
much more realistic test plaform for mobile development.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-01-19 09:39:07 +02:00
Oliver Schwaneberg
af89698d64 Checking for ACK for getDive.
get_matching_dive does not check if the DC wrote an acknowledgement for the requested dive.
As result, the sync stalls if dive number 0 is not available.

Signed-off-by: Oliver Schwaneberg <oliver.schwaneberg@gmail.com>
2018-01-19 09:27:32 +02:00
Jan Mulder
65caddb294 code cleanup: translators are not global
Un-globalize unused global variables.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-01-18 17:36:31 +02:00
Berthold Stoeger
2d24dceafa Use format_string() in core/git_access.c
Since this helper-function exists, we might just use it. A subtle
reuse of a buffer (string of second use was known to be shorter than
string of first use) was replaced by a separate allocation.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-17 21:45:48 +02:00