Commit graph

39 commits

Author SHA1 Message Date
Berthold Stoeger
6a07ccbad2 Use helper function empty_string() instead of manual checks
For code consistency, substitute boolean expressions:
 s && *s     -> !empty_string(s)
 s && s[0]   -> !empty_string(s)
 !s || !*s   ->  empty_string(s)
 !s || !s[0] ->  empty_string(s)

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-11 06:07:13 +01:00
Berthold Stoeger
59526e948a Remove cloud_background_sync preferences option
The preferences flag cloud_background_sync used to be used heavily in
the mobile code, but is not used there anymore. Now, it is accessed
only in one place, but does not do what it actually says: If it is off,
the remote storage is not synced on save (but will be synced on next
load).

Syncing on save can also be prevented by unchecking the "Cloud online"
menu checkbox. Since the latter seems more logical and general
(support for non-cloud remote git repositories), remove the cloud_background_sync
option.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-06 10:46:07 -08:00
Berthold Stoeger
fd5a521b94 Sync with any remote git repository
Sync with remote git repository, even if this isn't the cloud storage.
There seems to be no point in remote git repositories if they aren't
synced.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-06 10:46:07 -08:00
Dirk Hohndel
50571dfab3 Cleanup: avoid memory leak
Coverity CID 208298

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-26 15:57:45 -08:00
Dirk Hohndel
42db44510d Cleanup: avoid memory leak
Coverity CID 208333

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-26 14:17:54 -08:00
Jan Mulder
6e411cc67d core: fix commit 46004c39e2 for real (erroneous quotes)
Unfortunately, in my commit 48d9c8eb6e, I fixed only half of
the problems related to the functionality introduced by Stefan in
commit 46004c39e2. The lonely m (that was fixed) caused
a parsing error, but forgotten where the single quotes around
the depth value. These quotes simply causes the new functionality
not to work. Again, the fix is simple: do not erroneously save
quotes. And as the new functionality is pretty obscure
(replanning a non-planned dive, and manually entering a gas switch
depth), another bug that could go unnoticed for years.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-12-20 15:39:54 +01:00
Jan Mulder
48d9c8eb6e core: fix git storage save (regression 4.7.4 -> 4.7.5)
Commit 46004c39e2 introduces a new field in the logbook outputs
(depth of a cylinder). While in XML the depth unit is stored with a space
between value and unit (m), in our git storage, the unit m is without
space. As the git storage parser uses a space to separate individual
key/value pairs, the erroneously saved space results in parsing warnings
when opening the logbook.

The unwanted space is normally saved just after download of a new dive
from the dive computers, so all desktop-git-storage uses are affected,
and more worrying, mobile beta users.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-12-18 15:22:50 +01:00
Stefan Fuchs
46004c39e2 Store and load the planner related depth info of a cylinder in logfile
Store cylinder.depth in XML files and in git storage.
This info is in fact the gas switch depth of a specific gas/cylinder
in the planner.
This change avoids the need of typing in a user specific depth value
again when replanning an existing planned dive.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-11-27 11:49:08 -08:00
Stefan Fuchs
adbc71f9da Init every struct sample with default values
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-11-13 20:50:10 -08:00
Jan Mulder
8d0361ff77 Do not save dive sites that are not used
As it is not possible to delete dive sites from the logbook, we
need to make sure that we never save sites that are not tied to
any dive. With this change, unused site that are currently in
the logbook will also be removed, so it will also clear up
(wrong) historical data.

Supposed to fix #786

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-11-08 14:07:36 +01:00
Dirk Hohndel
6852c3b039 git save: create a better commit message for initial commit
When we create an empty repo we should simply state that in the commit message.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-10-26 20:44:02 +02:00
Dirk Hohndel
1be4435175 git save: don't save the git_id if just creating empty repo
Otherwise the following call to do_git_save will potentially have incorrect information
about the cache validity of the dives in the divelist.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-10-26 20:44:02 +02:00
Dirk Hohndel
bd54e94606 git save: remove redundant 'subsurface' from commit message
The user agent string already contains the (correctly capitalized) program name.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-10-26 20:44:02 +02:00
Dirk Hohndel
5269f8ce40 git storage: print the actual error
It seems silly to not show what git told us went wrong.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-10-26 20:44:02 +02:00
Dirk Hohndel
6ec7d2d877 Move error reporting into its own source file
This doesn't really seem to belong in save_git.c.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-10-26 14:37:38 +02:00
Dirk Hohndel
21d78121ad Don't add separate country field, use taxonomy
The more I looked at the code that added the country to the dive site,
the more it seemed redundant given what we have with the taxonomy.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-10-04 08:05:09 -07:00
Tomaz Canabrava
f9a36132ad [Divesite] Load / Save divesite country on git
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-10-02 09:52:39 -07:00
Miika Turkia
d7c89a79f8 Do not save duration if it is zero
See #561
2017-09-11 07:19:57 -07:00
Dirk Hohndel
0813d2168a Remove some unused variables
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-08-26 12:14:46 -07:00
Linus Torvalds
efc5f4d9ab Add support for loading and saving multiple pressure samples
This does both the XML and the git save format, because the changes
really are the same, even if the actual format differs in some details.
See how the two "save_samples()" routines both do the same basic setup,
for example.

This is fairly straightforward, with the possible exception of the odd

     sensor = sample->sensor[0];

default in the git pressure loading code.

That line just means that if we do *not* have an explicit cylinder index
for the pressure reading, we will always end up filling in the new
pressure as the first pressure (because the cylinder index will match the
first sensor slot).

So that makes the "add_sample_pressure()" case always do the same thing it
used to do for the legacy case: fill in the first slot. The actual sensor
index may later change, since the legacy format has a "sensor=X" key value
pair that sets the sensor, but it will also use the first sensor slot,
making it all do exactly what it used to do.

And on the other hand, if we're loading new-style data with cylinder
pressure and sensor index together, we just end up using the new semantics
for add_sample_pressure(), which tries to keep the same slot for the same
sensor, but does the right thing if we already have other pressure values.

The XML code has no such issues at all, since it can't share the cases
anyway, and we need to have different node names for the different sensor
values and cannot just have multiple "pressure" entries. Have I mentioned
how much I despise XML lately?

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-25 22:05:32 -07:00
Linus Torvalds
f2a6a76b3e Fix up o2 pressure sensor handling at load time
Because of how we traditionally did things, the "o2pressure" parsing
depends on implicitly setting the sensor index to the last cylinder that
was marked as being used for oxygen.

We also always defaulted the primary sensor (which is used for the
diluent tank for CCR) to cylinder 0, but that doesn't work when the
oxygen tank is cylinder 0.

This gets that right at file loading time, and unifies the xml and git
sample parsing to make them match. The new defaults are:

 - unless anything else is explicitly specified, the primary sensor is
   associated with the first tank, and the secondary sensor is
   associated with the second tank

 - if we're a CCR dive, and have an explicit oxygen tank, we associate
   the secondary sensor with that oxygen cylinder.  The primary sensor
   will be switched over to the second cylinder if the oxygen cylinder
   is the first one.

   This may sound backwards, but matches our traditional behavior where
   the O2 pressure was the secondary pressure.

This is definitely not pretty, but it gets our historical files working
right, and is at least reasonably sensible.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-21 16:34:33 -07:00
Linus Torvalds
ea31800f61 git save format: don't save redundant sample information
When we load sample data from a git save-file, we always default to
using the state from the previous sample (except for the special case of
cylinder pressure where an empty value does not mean "same", but
"interpolate", see core/load-git.c: new_sample()).

But the corollary to that is that it's always redundant to save sample
data that hasn't changed since the previous sample.

For some reason, the rbt, bearing and heartrate sample data didn't
follow that rule, and instead saved with lots of extra reduncancy.

(The alternative would be to clear those samples at load time, and make
them act like the pressure data, but it would appear that all these
three values may as well just have the normal "if no change, don't save
them" semantics).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-21 16:33:45 -07:00
Linus Torvalds
1e38d9239a Start cleaning up sensor indexing for multiple sensors
This is a very timid start at making us actually use multiple sensors
without the magical special case for just CCR oxygen tracking.

It mainly does:

 - turn the "sample->sensor" index into an array of two indexes, to
   match the pressures themselves.

 - get rid of dive->{oxygen_cylinder_index,diluent_cylinder_index},
   since a CCR dive should now simply set the sample->sensor[] indices
   correctly instead.

 - in a couple of places, start actually looping over the sensors rather
   than special-case the O2 case (although often the small "loops" are
   just unrolled, since it's just two cases.

but in many cases we still end up only covering the zero sensor case,
because the CCR O2 sensor code coverage was fairly limited.

It's entirely possible (even likely) that this migth break some existing
case: it tries to be a fairly direct ("stupid") translation of the old
code, but unlike the preparatory patch this does actually does change
some semantics.

For example, right now the git loader code assumes that if the git save
data contains a o2pressure entry, it just hardcodes the O2 sensor index
to 1.

In fact, one issue is going to simply be that our file formats do not
have that multiple sensor format, but instead had very clearly encoded
things as being the CCR O2 pressure sensor.

But this is hopefully close to usable, and I will need feedback (and
maybe test cases) from people who have existing CCR dives with pressure
data.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-21 16:33:19 -07:00
Linus Torvalds
11a0c0cc70 Unify sample pressure and o2pressure as pressure[2] array
We currently carry two pressures around for all the samples and plot
info, but the second pressure is reserved for CCR dives as the O2
cylinder pressure.

That's kind of annoying when we *could* use it for regular sidemount
dives as the secondary pressure.

So start prepping for that instead: don't make it "pressure" and
"o2pressure", make it just be an array of two pressure values.

NOTE! This is purely mindless prepwork.  It literally just does a
search-and-replace, keeping the exact same semantics, so "pressure[1]"
is still just O2 pressure.

But at some future date, we can now start using it for a second sensor
value for sidemount instead.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-20 17:32:54 -07:00
Dirk Hohndel
2b01ab7d50 Clean up git storage update messages
Translate all of them, but also remove some redundant or possibly
misleading messages. These are now seen by users, not just developers
trying to debug the code.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-18 01:00:30 -07:00
Dirk Hohndel
b2b51c833a QML UI: redesign the user notification
The old system of cloud access updates with fake percentages just wasn't
helpful. Even worse, it hid a lot important information from the user.
This should be more useful (but it will require that we localize the
messages sent from the git progress notifications and make them more
'user ready').

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-17 23:22:37 -07:00
Dirk Hohndel
6399eaf271 Add SPDX header to core C files
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-04-29 13:32:55 -07:00
Dirk Hohndel
2182f00177 Reduce default verbosity
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-04-22 12:38:59 -07:00
Lubomir I. Ivanov
bcad5ddd38 Only enable -Wmissing-field-initializers for Clang
The following pragma is Clang specific:

It produces a warning:
warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas]

Only enable it for Clang by checking the __clang__ macro.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-03-12 09:18:59 -07:00
Joakim Bygdell
0277d5aacc Merge informational_prefs into git_prefs
There is no need to have two variables for the same purpose.

[Dirk Hohndel: changed to keep the two separate functions as otherwise
               we no longer parse existing repos successfully]

Signed-off-by: Joakim Bygdell <j.bygdell@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-02-05 12:29:51 -08:00
Joakim Bygdell
d4dbd0bee7 Save profile settings to git
In order to streamline the view between desktop and mobile we need to save
selected profile related settings to git.

Signed-off-by: Joakim Bygdell <j.bygdell@gmail.com>
2017-02-05 11:59:47 -08:00
Linus Torvalds
7c8073e7ea Add proper line ending for unit line in git save format
The imperial and metric unit formats already had this, but the
personalized one missed the newline at the end.

It shouldn't really matter, since it's the last line of the file, but it
is not right.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-07-21 20:00:04 +09:00
Linus Torvalds
84166a4ee7 Extend time parsing to before 1970
It turns out that we are starting to have users that have logs that go
back that far. It won't be common, but let's get it right anyway.

NOTE! With us now supporting dates earlier in 1900, this also makes
"utc_mktime()" always add the "1900" to the year field.  That way we
avoid ever using the fairly ambiguous two-digit shorthand.

It didn't use to be all that ambiguous when we knew that any two-digit
number less than 70 had to be 2000+.  Now that we support going back to
earlier in the last centiry, that certainty is eroding.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-29 09:07:17 -07:00
Dirk Hohndel
a1ec0d6724 git storage: only sync with remote if git_local_only isn't set
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-08 12:29:17 -07:00
Dirk Hohndel
922c945f5a QML UI: more hacking around with git progress reporting
I gave up on the magic numbers and instead report simply linear progress.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-05 23:39:54 -07:00
Dirk Hohndel
a1332ce361 Simplify git tracking of git tree creation
With Linus' changes to the tree creation saving the dives is no longer
the dominant part of that process, so simplify the output (which also
removes the hacky buggy code to show the percentages that is of course
totally bogus).

(apparently a couple of white space cleanups snuck into this patch)

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-05 21:23:48 -07:00
Linus Torvalds
eff4059802 Start using the actual cylinder data for gas switch events
Now that gas switch events always have indices into the cylinder table,
start using that to look up the gas mix from the cylinders rather than
from the gas switch event itself.  In other words, the cylinder index is
now the primary data for gas switch events.

This means that now as you change the cylinder information, the gas
switch events will automatically update to reflect those changes.

Note that on loading data from the outside (either from a xml file, from
a git/cloud account, or from a dive computer), we may or may not
initially have an index for the gas change event.  The external data may
be from an older version of subsurface, or it may be from a
libdivecomputer download that just doesn't give index data at all.

In that case, we will do:

 - if there is no index, but there is explicit gas mix information, we
   will look up the index based on that gas mix, picking the cylinder
   that has the closest mix.

 - if there isn't even explicit gas mix data, so we only have the event
   value from libdivecomputer, we will turn that value into a gasmix,
   and use that to look up the cylinder index as above.

 - if no valid cylinder information is available at all, gas switch
   events will just be dropped.

When saving the data, we now always save the cylinder index, and the gas
mix associated with that cylinder (that gas mix will be ignored on load,
since the index is the primary, but it makes the event much easier to
read).

It is worth noting we do not modify the libdivecomputer value, even if
the gasmix has changed, so that remains as a record of the original
download.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-04 22:37:18 -07:00
Linus Torvalds
e0824ef9f3 Make gas change events always have a cylinder index
In commit df4e26c875 ("Start sanitizing gaschange event information")
back about a year and a half ago, I started sanitizing the gas switch
event data, allowing gas switches to be associated with a particular
cylinder index rather than just the gas mix that is switched to.

But that initial step only _allowed_ a gas switch event to be associated
with a particular cylinder, the primary model was still to just specify
the mix.

This finally takes the next step, and *always* associates a gas switch
event with a particular cylinder.  Instead of then looking up the
cylinder by trying to match gas mixes at runtime, subsurface now looks
it up when loading the dive initially as part of the dive fixup code.

The switch event still has an a separate gas mix associated with it, but
this patch also starts preparing for entirely relying on the gas mix in
the cylinder itself, by starting to pass in not just the event but also
the dive pointer to the routines that look up gas mix details.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-04 22:37:18 -07:00
Dirk Hohndel
7be962bfc2 Move subsurface-core to core and qt-mobile to mobile-widgets
Having subsurface-core as a directory name really messes with
autocomplete and is obviously redundant. Simmilarly, qt-mobile caused an
autocomplete conflict and also was inconsistent with the desktop-widget
name for the directory containing the "other" UI.

And while cleaning up the resulting change in the path name for include
files, I decided to clean up those even more to make them consistent
overall.

This could have been handled in more commits, but since this requires a
make clean before the build, it seemed more sensible to do it all in one.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-04 22:33:58 -07:00
Renamed from subsurface-core/save-git.c (Browse further)