Commit graph

219 commits

Author SHA1 Message Date
Anton Lundin
950638ec1c Replace cylinder_is_used with is_cylinder_used
is_cylinder_used uses get_cylinder_index as underlaying function that
does the right thing with with respect on how to find the closest
matching cylinder, and handles both types of gaschange events correctly.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-17 08:28:21 -07:00
Dirk Hohndel
598102c351 Convert ternary "?:" into if for translation tools to work
It seems the translation tools don't like the ?: in the argument - can't
blame them. So use an explicit if clause instead.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-16 09:35:48 -07:00
Dirk Hohndel
4eec911d3a Planner: even with broken plans, don't divide by 0
This fixes the crash in #623, but not the other oddities.

See #623

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-15 03:14:15 -07:00
Dirk Hohndel
74616cdddf Rename event: correctly replace event with new one
I don't like that the event structure includes the variable length array.
That really makes it a pain to change the name of an event (on the flip
side, freeing events is easier I guess).

Anyway, to correctly rename an event we need to actually remove the event
from the correct dc and then add a new event with the new name. The
previous code was insane (it only worked if the new name was of smaller or
equal length, otherwise it had a beautiful buffer overflow).

And of course we need to do this both for the current_dive and the
displayed_dive.

Fixes #616

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-12 12:56:03 -07:00
Dirk Hohndel
f9b18b9bfb Remove event: don't compare pointers, compare events
This used to work because we actually displayed the current_dive. Now with
displayed_dive the pointers are of course different! So we need to compare
the actual events instead.

See #616

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-12 12:21:05 -07:00
Anton Lundin
a12976086e Fix potential division by zero
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-10 13:26:30 -07:00
Anton Lundin
1a8e8be3a9 Fix potential leak of newdc in make_first_dc()
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-10 13:25:12 -07:00
Dirk Hohndel
a8a8bcd86a Add helper functions to ensure we have sane tag lists
There should never be empty or duplicate tags on those lists.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-10 09:42:28 -07:00
Dirk Hohndel
f297d9f91e Fix picture loading
Signed vs unsigned comparisons are such a pain. Since we want offsets to
be +/- 30 minutes around the dive we need to allow negative offsets - but
duration_t was defined as uint32_t.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-08 12:29:06 -07:00
Dirk Hohndel
d97c49ba39 When copying dives, make copies of samples/events in first DC
We carefully copied the dive computers and their samples and events, but
only for the second and later DCs. For the first DC we simply copied the
pointers but not what they were pointing at. So when the copied dive was
freed, those pointers in the original went to freed memory.

Not good.

Fixes #599

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-06 11:23:25 -07:00
Dirk Hohndel
47f9f59c1a UI restructure: add clone_dive helper
This is kind of the inverse to copy_dive(). Instead of duplicating all the
data that the dive points to, it moves it to a new struct dive and zeroes
out the old one so there are no two sets of pointers to these data.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-03 13:34:27 -07:00
Dirk Hohndel
2cfe97e4dd Add a "smart strdup" helper named copy_string()
If the string is non-NULL, copy it, otherwise return NULL.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-03 09:37:55 -07:00
Dirk Hohndel
cd65c8512d UI restructure: add helper function to copy and clear a dive
This way we can safely copy around dives (specifically, copy the dive to
be displayed / edited into the displayed_dive).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-03 09:37:43 -07:00
Dirk Hohndel
a221a6e9f5 UI restructure: use a global variable to hold the dive we show / edit
There is massive confusion about what we display when and where and which
dive structure (or pointer to a dive structure) contains which information
at which stage. This is the first step towards restructuring all of this.

This creates a global variable displayed_dive which at any point in time
should be what is displayed on screen (both in the profile and in the
maintab). It removes the editedDive concept from MainTab.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-02 11:56:36 -07:00
Dirk Hohndel
1d09ce2ce2 Picture loading: only add the pictures to "reasonable" dives
If the picture has a timestamp that was within 30 minutes of the start and
finish of the dive, we take it. Otherwise we don't.

If the timestamps of the images are off, the time shift dialog allows the
user to fix this.

And with this patch the user can select all the dives of a trip and all
the pictures they took on the trip and the "right thing" will happen.

Fixes #578

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-01 09:29:19 -07:00
Dirk Hohndel
2b59765da3 Allow the user to delete a dive computer from a dive
This can't be the only dive computer, of course. Goes nicely with the
ability to reprder them.

Fixes #551

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-11 13:56:33 -07:00
Dirk Hohndel
a26719c541 Picture handling: switch to stronger typed offset
Also change the on file XML to be even easier to read by making it a
duration as well (which gets us '32:34 min' instead of un-typed seconds).
This is backwards compatible, it will happily read what was written with
the previous commit).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-09 09:38:50 -07:00
Robert C. Helling
125ddd955c Display liters with script el
Use script ell instead of 'l' for liters to avoid confusion with digit 1.
Let's hope that this glyph is available in the common fonts, otherwise
we'll have to revert it.

[Dirk Hohndel: split commit into two]

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-08 20:25:33 -07:00
Dirk Hohndel
1604299a5b Picture handling: change data structure to store offset instead timestamp
It makes no sense to store a 64bit time stamp with every picture. Even the
32bit offset (in seconds) from the dive start is WAY overkill. But
switching to that makes the code much more simple in a number of spots.
And makes what is saved to the XML file easier to read, too.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-08 17:17:49 -07:00
Dirk Hohndel
a55411c558 Picture handling: keep picture list sorted
And simplify the list handling algorithm.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-08 12:42:51 -07:00
Dirk Hohndel
543f3ac584 Picture handling: don't add the same picture more than once
It confuses us elsewhere (the model suddenly doesn't match the list of
pictures as the model doesn't reflect the duplicate pictures).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-08 12:42:51 -07:00
Dirk Hohndel
e7ecb690ed Picture handling: adjust timestamp after it's set
We need to first parse the exif and then adjust the timestamp.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-08 12:42:51 -07:00
Dirk Hohndel
5bc5cae6dc Planner: only copy cylinders that were used in the template dive
This was only semi-implemented the first time around. Now we really only
copy the ones that are indeed used.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-03 23:09:12 -07:00
Dirk Hohndel
d211bc55be When calculating the maximum of unsigned values, use unsigned variable
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-03 17:06:59 -07:00
Willem Ferguson
eaf6d56487 CCR code: Change to sample structure
1) All the variables in the sample structures are strongly typed
2) Two additional types were declared in units.h:
     o2pressure_t
     bearing_t
3) The following variables were added:
     diluentpressure
     o2setpoint
     o2sensor[3]
4) Changes to a number of files were made to chanf
     sample->po2 to sample->po2.mbar
     bearing to bearring.degrees

Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-03 17:05:25 -07:00
Tomaz Canabrava
f53b5c4d3f Fix linked list corruption, move code to C.
The picture list is a single linked list where the pictures have a node to
their next element. When adding the same picture to two dives, things got
way way wrong and crashes were appearing.

This will replicate the information (filename, latitude and longitude) for
each dive that has the picture, BUT it still tries to save as much as
possible on the actual pixmap.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-03 16:39:06 -07:00
Dirk Hohndel
b249370ffe Not all C compilers like uint
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-03 00:10:39 -07:00
Tomaz Canabrava
d95d1735b5 Break picture handling code from C++ to C.
This commit breaks the loading of images that were done in the divelist
into smaller bits. A bit of code refactor was done in order to correct the
placement of a few methods.

ShiftTimesDialog::EpochFromExiv got moved to Exif::epoch dive_add_picture
is now used instead of add_event picture_load_exif_data got implemented
using the old listview code.  dive_set_geodata_from_picture got
implemented using the old listview code.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-02 23:59:29 -07:00
Tomaz Canabrava
dfac5e93c4 Add a FOR_EACH_PICTURE macro and the code for picture_count.
Add the FOR_EACH_PICTURE macro and the code for picture count.
This uses C99 - but I will keep it like this and wait for dirk
to scream at me.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-02 23:57:51 -07:00
Tomaz Canabrava
cfa51c6526 Add stubs for the main methods that will operate on pictures.
add, remove, get count, and picture_load_exif_data.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-02 23:57:16 -07:00
Dirk Hohndel
28093ae957 Remove is_air() and convert its users to gasmix
Also make gasname() and get_gas_string() global functions (which allows us
to delete code elsewhere).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-01 20:57:11 -07:00
Dirk Hohndel
c539c8f861 Remove the .used member of the cylinder structure
Instead calculate this information on the fly, taking into account all
dive computers on the dive in questions.

There is one wrinkle to this - previously we abused the '.used' member to
make sure that a manually added cylinder didn't disappear the moment it
was added (think of the workflow: you add a cylinder, then you add a gas
change to that cylinder -> right after you add it it is unused and would
not be shown).

I am thinking that we might have to add the "manually_added" property to
the properties that we store in XML / git.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-01 12:43:40 -07:00
Dirk Hohndel
1a04013453 Encapsulate the horrid gas encoding in gas change events
We should never pass permille values around as integers. And we shouldn't
have to decode the stupid value in more than one place.

This doesn't tackle all the places where we access O2 and He "too early"
and should instead keep passing around a gaxmix. But it's a first step.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-01 12:07:29 -07:00
Dirk Hohndel
56395b3894 Don't assume that pressures are always positive
When planning a dive, the dive could use more gas than is in the cylinder.
So getting a negative end pressure is a useful indication to the user that
there plan might not be a good one.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-29 13:18:13 -07:00
Dirk Hohndel
cfe865dd0c Merge branch 'atdotde'
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>

Conflicts:
	qt-ui/diveplanner.cpp
	qt-ui/models.cpp
2014-05-26 08:23:22 -07:00
Robert C. Helling
04b6b6aaf9 Use get_o2() and get_he() instead of accessing permilles directly
This gets rid of problems with air.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-26 08:12:32 -07:00
Tomaz Canabrava
ef4705070f Create a 'remove_event' function that removes an event.
The logic of removing the event was in the UI, and this makes
the code harder to test because we need to take into account
also the events that the interface is receiving, instead of
only relying on the algorithm to test.

so, now it lives in dive.h/.c and a unittest is easyer to make.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-22 07:28:27 +09:00
Linus Torvalds
7821b87983 Use the last 'diveid' when merging dives for one dive computer
When we merge two dives into the same dive because a divecomputer had
incorrectly considered it two separate dives (due to surface time within
the dive) we should pick the dive ID from the later dive to be the
diveid of the resulting merged dive.  Otherwise we might re-download the
(now merged) partial dive.

This is a rather unusual special case, but it actually hit me with the
Uemis on my last dive in Palau: Chandelier Cave has multiple surface
points where you can spend time admiring the cave above water, and the
Uemis (but not my Suunto's) decided that the dive was actually four
short dives back-to-back.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-20 14:16:00 +09:00
Anton Lundin
05d9cc409c Migrate code to for_each_dive and for_each_dc
[Dirk Hohndel: this overlapped with my commit 09e7c61fee ("Consistently
	       use for_each_dive (and use it correctly)") so I took the
	       pieces that I had missed]

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-20 11:51:40 +09:00
Dirk Hohndel
a117428ff4 Add ability to make a dive computer the first dive computer of a dive
If a dive has multiple dive computers we enable a special context menu
when the user right-clicks on the dive computer name AND is not already
showing the first dive computer. In that case we offer to make the
currently shown dive computer the first one.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-19 20:12:59 +09:00
Dirk Hohndel
b36c8f07c7 Assign the uniq dive ID the moment a dive is allocated
Previously we only did this when we did fixup_dive(), but that way we
can't reference dives "early" in their life cycle (e.g., right after they
got downloaded).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-19 20:12:59 +09:00
Dirk Hohndel
818542eeca Don't merge divecomputers if we know they are different
When merging dives, if we know for sure that the dive computers are
different, don't merge them into one (by interleaving the data), but
instead keep both as separate dive computers in the same dive.

This fixes a bug when due to a faulty download the same dive from two dive
computers looks quite different. They don't get merged automatically
(which is fine - they are quite different), but when manually merging
them, we of course want one dive with two dive computers, not one dive
with one merged dive computer.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-14 13:08:06 +09:00
Tomaz Canabrava
c86d055db7 Do not check for null before free.
C specs says that we can safelly free a NULL pointer, so there's no reason
to check if it's null before freeing it.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-13 09:26:50 +09:00
Tomaz Canabrava
9e8c0c9366 Prefix a method with 'dive_' because it should work only with dives
I'll probably add prefixes to functions to make it easier to find method
via autocomplete from the grep or interface helpers, do you wanna know all
the functions that works with a dive?  ask for the completion for dive_,
do you wanna know all the functions that works with a divelist? ask for
the completions on divelist_ or run grep -rIs divelist_ on the header
files.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-11 01:57:41 -07:00
Anton Lundin
96f707abfe Remove unnecessary include from dive.c
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-08 14:58:01 -07:00
Robert C. Helling
c3a3c1a1e7 Planner: Implement ascend rate according to GUE standard procedures
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-08 12:28:09 -07:00
Dirk Hohndel
6545855b65 Fix standard cylinder names
We need to pass the size as an integer.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-05 14:52:13 -07:00
Dirk Hohndel
0be8512ab0 Add small helper to determine if dive computer has HR data
Currently unused, but requested for a future feature.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-25 07:19:18 -07:00
Tomaz Canabrava
9598462830 Removed the globals 'userid' and 'save_userid_local' variables
This is a preferences setting, it should belong to the preferences
structure.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-17 08:37:31 -07:00
Gehad
8ca4437624 Add current time and adjusted time to gui when adjusting dive's timestamp
This patch adds the current dive time and the adjusted time to the time
shift window. I added a function to dive.c to get the timestamp of the
first selected dive.

This will view the time of the first selected dive only even when multi
dives are selected but it does change the times for multiple dives
properly.

Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-21 21:26:09 -07:00