Commit graph

257 commits

Author SHA1 Message Date
Dirk Hohndel
6dc247ff78 Fix deco calculations to correctly use GF values and add CC support
The old implementation was broken in several ways.

For one thing the GF values are percentages, so they should normally be
0 < GF < 1 (well, some crazy people like to go above that).

With this most of the Bühlmann config constants were wrong.

Furthermore, after we adjust the pressure tolerance based on the gradient
factors, we need to convert this back into a depth (instead of passing
back the unmodified depth - oops).

Finally, this commit adds closed circuit support to the deco calculations.

Major progress and much more useful at this stage.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-04 11:13:14 -08:00
Dirk Hohndel
75b970f7ac Intercept all events to the GF fields in the property dialog
This seems like a strange way to capture the FOCUS_CHANGE event, but
manually trying to register a callback for it fails. Yet registering a
callback for every event and then filtering for FOCUS_CHANGE in the
callback works. Go figure.

But with this commit you can actually change the GF settings in the
preferences dialog and once you tab out of the entry field the change gets
immediately applied - nice to play with the effects of changing GF values.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-04 11:12:32 -08:00
Dirk Hohndel
f93f578eca Merge branch 'deco2'
Bringing in the first attempts to do our own deco calculations
2013-01-03 21:58:46 -08:00
Lubomir I. Ivanov
fc882f574f Improvements to select_prev_dive() and select_next_dive()
There were some minor problems when moving the selection
cursor around:

1) If the selection was larger than 1, it was possible
for the selection to get "stuck" in the middle of the list.

This patch approaches this by always calling
gtk_tree_selection_unselect_all() before
gtk_tree_selection_select_iter(), or simply always making
sure we have one selected iterator when navigating with the keys.

2) When there was a single top level dive before the first trip
it wasn't possible to navigate trough the child dives of said
trip in both directions.

The patch attempts to fix this by having the hunks/checks:
if (idx < 0) {

(idx is of a trip) performed regardless of other conditions.

*** Note: testing was done by importing all test*.xml
dives with auto-group on.

[Dirk Hohndel: adjusted the patch to also fix on_key_press to only grab
               the key if no modifier key is pressed; otherwise this
	       breaks shift-cursor-keys for selecting multiple dives.]

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-03 21:52:30 -08:00
Dirk Hohndel
9cd18c43aa Make GF values configurable
There are a couple of issues with this commit:

GtkEntry should emit the 'changed' signal when it is modified (so that
changes in the preferences get applied right away) - but that doesn't
appear to be working consistently.

Also, this doesn't appear to affect the deco of any dives that I try it
with. So my guess is something is wrong with the underlying deco
algorithm. That's diappointing.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-03 21:41:35 -08:00
Dirk Hohndel
5ba250bd48 Use gradient factors in deco calculation
Usually dive computers show the ceiling in terms of the next deco stop -
and those are in 3m increments. This commit also adds the ability to chose
either the typical 3m increments or the smooth ceiling that the Bühlmann
algorithm actually calculates.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-03 20:44:37 -08:00
Dirk Hohndel
aab67e2a5b Add configurable visualization of calculated ceiling
This is on top of the deco information reported by the dive computer (in a
different color - currently ugly green). The user needs to enable this via
the Tec page of the preferences.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-03 20:43:19 -08:00
Dirk Hohndel
6f8e9bcff3 Rewrite the nickname replacement function
This function had a couple of bugs. Two different off by one errors and on
top of that it was matching only the deviceid instead of model and
deviceid.

So I simply rewrote it to match against the full pattern and take a much
more straight forward approach to replacing the entry for the divecomputer
under consideration. If the new nickname is entry this implementation
allocates one extra byte - but that didn't seem worth the extra code to
fix it.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-03 12:33:48 -08:00
Dirk Hohndel
a319d66c4a Use old style (pre gtk-2.22) keysyms
And include the compatibility header to build on newer versions.

Reported-by: Salvador Cuñat <salvador.cunat@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-02 13:01:02 -08:00
Dirk Hohndel
a58d470bad Remove autogroup from the preferences and store per file instead
Having two spots to toggle autogroup had always been a clear sign of
insanity. The inconsistent ludicrous semantic of when we remembered the
state of autogroup was even worse.

This finally gets rid of that disaster and drops the autogroup setting
from the preferences and makes it instead a per file property. When you
save a file, it saves the state of the autogroup toggle. This seems much
more useful - you may have files where you want to create trips by
default. And others, where you don't.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-01 17:29:38 -08:00
Dirk Hohndel
030d0c1294 Make sure remember_dc has its own copy of the model string
When called from the parser the model string is freed right after passing
it to remember_dc. So we need to get our own copy.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-01 17:27:33 -08:00
Dirk Hohndel
8fa81a5577 Add ability to remove a divecomputer from our data structures
Right now this isn't used but it will be needed for the yet to be written
UI to manage our divecomputer database.

This commit also fixes an oversight in the remember_dc function. Updates
to nicknames weren't committed to the config.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-01 13:30:20 -08:00
Dirk Hohndel
8f364d0094 Use the Left and Right keys to switch between divecomputers
The existing code had the somewhat retarded Ctrl-C binding for displaying
the next divecomputer and no way to go back to the previous one. With this
commit we use our keyboard grab to map Left and Right to previous and next
divecomputer. Much nicer.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-01 10:20:22 -08:00
Dirk Hohndel
91ca0d2cf6 First step towards grabbing keys and handling them ourselves
This commit steals the cursor up and down keys away from gtk so regardless
where gtk thinks the focus may be, we can still use the keys to change
between dives.

In the current UI design where all editing happens in separate windows
this works as expected, as we only grab the keys for the main window. If
we manage to re-enable in-place editing then we need to make sure that
this doesn't cause problems (as gtk uses up/down for the ability to change
drop down selections in combo boxes or values in spin buttons. So we must
make sure that we stop stealing these keys once we start editing something
(in which case simply switching to the next/prev dive wouldn't be a good
thing, anyway).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-01 08:24:42 -08:00
Dirk Hohndel
df0ea07292 Fix nickname saving in XML file to deal with utf8 characters
This makes the whole code much cleaner and simpler.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-30 20:27:01 -08:00
Linus Torvalds
3b136f23ee Make add_dc_to_string() skip redundant entries
There is no point writing out divecomputer nicknames that do not exist
(or that match the dive computer model), so don't.

Also, make the function to do this static to save-xml.c, which is the
only user (I initially didn't _find_ the function to create the XML
string because it was illogically hidden in gtk-gui.c), and change the
calling convention to be more direct (pass in a string and return a
result, rather than modify a "pointer to string").

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-28 09:04:59 -08:00
Dirk Hohndel
3872921ffe Divecomputer entries with deviceid 0 should be ignored for nicknames
Those only come from a number of development versions of Subsurface that
didn't include the deviceid in the divecomputer entry. There is no way of
telling different dive computers (of the same model) apart, so assigning a
nickname to such an entry then creates incorrect output when loading an
XML file from someone else (e.g. Linus and I both have a Uemis SDA and
both may have entries for our own SDA with deviceid 0; then the nickname
Subsurface shows for any Uemis SDA entry with a deviceid of 0 depends on
whether I last loaded his XML file or mine; that makes no sense).

This should only affect the develoers who stored XML files with one of the
development version of Subsurface that didn't store deviceids.

Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-28 06:36:47 -08:00
Dirk Hohndel
f6fb882337 Fix incorrect memory access in nickname handling
There was one code path where we didn't strdup the nickname - and this got
triggered when parsing XML files with divecomputerid entries for dive
computers that were already in the config. The nickname is then replaced
with the nickname from the parser - and that memory is later reused...

We should cleanup that nickname, anyway, and that also takes care of
making sure we have our own copy.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-27 21:41:12 -08:00
Dirk Hohndel
e726c9d65c Add settings section to XML file format and store dive computer IDs
We only store the model/deviceid/nickname for those dive computers that
are mentioned in the XML file. This should make the XML files nicely
selfcontained.

This also changes the code to consistently use model & deviceid to
identify a dive computer. The deviceid is NOT guaranteed to be collision
free between different libdivecomputer backends...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-26 16:46:21 -08:00
Dirk Hohndel
1bd6f72d31 Different is different from the same (fix silly bug in nickname handling)
Trying to simplify the API for nickname handling I went a bit too far. We
indeed need to different API calls, one that returns an entry in the
nicknamelist for the deviceid that we have. And one that looks if there is
an entry for a different deviceid but the same model that we have.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-23 09:06:23 -08:00
Dirk Hohndel
06cd494a2f Next improvement of the nickname code
Now it is able to replace nicknames for existing entries (which will be
needed by the yet to be written UI).

This commit fixes a couple issues with the previous code:
- a potential SIGSEGV with malformed config entries
- missing closing parenthesis in the dialog box text

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-22 21:38:07 -08:00
Lubomir I. Ivanov
8639e14835 Make it possible to translate strings containing subscript "2"
The "Tec settings" dialog contains some strings with the
subscript "2" character, which have to be translated. While
the "2" is part of the string xgettext doesn't seem to recognize
such. To trick it we use a temporary buffer and c-format:

sprintf(utf8_buf, _("Show pO%s graph"), UTF8_SUBSCRIPT_2);
button = gtk_check_button_new_with_label(utf8_buf);

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-22 20:21:51 -08:00
Lubomir I. Ivanov
ba223798d3 Free some nickname related memory in gtk-gui.c
init_ui():
We add the char pointer "conf_copy" and free it afterwards, since
once "next_token" is changed it no longer points to the allocated heap
location the mapper returned.

[Dirk Hohndel: original patch rewritten to have better variable names and
 to match the recent changes to this code]

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-22 20:19:51 -08:00
Dirk Hohndel
50aa6d1afa Imrpove the nickname handling
We now store the model information together with the deviceid and nickname
in order to be able to check if we have a record for any dive computer
with the same model (as that now triggers our nickname dialog).

This changes the format of the config entries for nicknames - the best
solution might be to just delete those and start again.

What is still missing is the code to store the nicknames in the XML file.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-22 20:14:34 -08:00
Dirk Hohndel
8d2abc05f6 Remove nickname from divecomputer data structure
Having it there with the model information seemed to make sense but on
second thought it's the wrong spot to keep that information, especially
since we were storing it in the XML file in every single dive.

This change removes the nickname member from the divecomputer and makes
the rest of the code reasonably self consistent. It does not add much of
the new code for the new design to handle nicknames.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-21 20:58:47 -08:00
Linus Torvalds
d8fd8b2099 Add a "View next dive computer" menu item
This adds the capability to actually view all your dive computers, by
adding a menu item under "Log"->"View"->"Next DC" to show the next dive
computer.

Realistically, if you actually commonly use this, you'd use the
accelerator shortcut.  Which right now is Ctrl-C ("C for Computer"),
which is probably a horrible choice.

I really would want to have nice "next/prev dive" accelerators too,
because the cursor keys don't work very well with the gtk focus issues.
Being able to switch between dives would also make the "just the dive
profile, maam" view (ctrl-2) much more useful.

The prev/next dive in the profile view should probably be done with a
keyboard action callback, which also avoids some of the limitations of
accelerators (ie you can make any key do the action).  Some gtk person,
please?

Anyway, this commit only does the dive computer choice thing, and only
using the accelerators.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-17 08:29:39 -10:00
Lubomir I. Ivanov
5c65ed2390 Clear associated tooltip texts when calling expose_event()
In gtk-gui.c:expose_event(), right before clearing the list of tooltips,
we also want to free memory for the associated texts for each one of them.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-16 15:57:25 -10:00
Lubomir I. Ivanov
5c58e1f868 Fixed some memory leaks related to subsurface_get_conf()
In gtk-gui.c:init() we retrieve the configuration values
for PO2, PN2, PHE thresholds but have to also free the values
once done parsing with sscanf().

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-16 15:57:11 -10:00
Lubomir I. Ivanov
28cc67c9a1 Fixed a couple of memory leaks related to the download dialog
In render_dc_vendor() and render_dc_product(), there is
no need to allocate memory for the texts that are about to
be added in the combo box trees. Most GTK widgets seem to make
copies of the passed text to them, using g_strdup() and
automatically release said memory when a widget is destroyed.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-16 15:56:58 -10:00
Lubomir I. Ivanov
92c15238b6 Make sure that the user entered nickname is never truncated
If the sizes of the two char buffers in set_dc_nickname() (nickname)
and remember_dc() (buffer) are at least twice the size of the allowed
maximum number of characters (sizeof(gunichar) = 2) set by
gtk_entry_set_max_length() for the user nickname,
no truncation will accur then calling snprintf() and cleanedup_nickname()
on said buffers.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-16 07:45:08 -10:00
Lubomir I. Ivanov
be9d924cf8 Reserve enough memory when storing a DC's nickname
in gtk-gui.c:
The input text field in set_dc_nickname() has a limit of 68 unicode
characters, which are 136 bytes. In remember_dc(), to make sure
that this nickname, the deviceid (4 bytes) and also the extra
characters (",{}") always fit wihout truncation (from snprintf) in the
allocated stack buffer, we increase the size of the buffer to 256 bytes.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-15 19:53:07 -10:00
Dirk Hohndel
371ace39b5 Fix possible crash in nickname code
Silly typo, but this is the better solution, anyway.

Reported-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>`
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-14 07:34:14 -10:00
Dirk Hohndel
713a4fcff6 Add the ability to set a nickname for a dive computer
We maintain a list of dive computers that we know about (by deviceid) and
their nicknames in our config. If the user downloads dive from a dive
computer that we haven't seen before, we give them the option to set a
nickname for that dive computer. That nickname is displayed in the profile
(and stored in the XML file, assuming it is not the same as the model).

This implementation attempts to make sure that it correctly deals with
utf8 nicknames.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-13 21:33:30 -10:00
Dirk Hohndel
aba65736eb Change the empty product model to be index 0
A vendor of -1 indicates that we should have no product selection in the
dive download dialog. Having the empty product model be the last made it
hard to keep the correct index for that empty model around (and we got it
wrong by default).

With this change the product models are offset by one, so the unset vendor
(-1) turns into index 0 which is where we now store the empty model.

Reported-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-12 07:25:28 -08:00
Dirk Hohndel
597a3677e9 Ensure default dive computer strings can be freed
We don't want to directly use the strings returned to us from
libdivecomputer.

Fixes bug 34

Reported-by: Sergey Starosek <sergey.starosek@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-12 07:24:07 -08:00
Dirk Hohndel
91577f11b5 Merge branch 'cns' into cns-merge
I foolishly changed visible_columns in both the (ill-named) cns branch and
master...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>

Conflicts:
	divelist.c
	gtk-gui.c
	profile.c
2012-12-11 13:09:48 -08:00
Dirk Hohndel
39f80a1e0f Display maximum CNS in the divelist
We either pick the CNS reported by the dive computer at the end of the
dive, or the maximum of that and the CNS values in the samples, if any.

As usual, this column in the dive list defaults to off and it is
controlled by a setting in the tec page of the preferences.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-10 21:18:48 -08:00
Dirk Hohndel
286020a2d1 Fix incorrect index for dive computer list
I don't understand how this ever worked...

Fixes ticket 32

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-10 11:11:18 -08:00
Dirk Hohndel
0ae16899de Don't draw tooltips if no profile is displayed
This fixes ticket 33

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-10 11:02:33 -08:00
Dirk Hohndel
7cf1960336 Apply preference changes right away
This allows you to open the preference dialog, play with settings and see
their effect right away. Press OK and you keep them, press Cancel and you
are back to the previous state. As it should be.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-10 10:52:25 -08:00
Dirk Hohndel
92c0d8c516 Move global variables covered by Preferences into one structure
Now we can simply remember the state of all the preferences at the
beginning of preferences_dialog() and restore them if the user presses
'Cancel'.

Fixes #21

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-10 10:26:06 -08:00
Dirk Hohndel
c9a03db480 Consistent Quit behavior on the Mac
We were responding to the wrong Quit signal on MacOS. The one we picked
was the one that basically told us "it's too late to stop me, I'm
quitting". I switched this to the one asking "should I prevent the app
from quitting" and now we can indeed cancel the Quit, regardless which
method was used to close the app.

Also removes to unused variables.

Fixes #22

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-09 15:23:33 -08:00
Dirk Hohndel
8185159566 Make changes to some of the preference immediately visible
This is just a small part of the solution to the bigger problem with the
preferences.

See ticket 21

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-08 13:58:27 -08:00
Dirk Hohndel
0fcdd011f5 Fix off by one error
We increment i twice - which causes us to access memory past the end of
the allocated array.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-07 20:01:05 -08:00
Dirk Hohndel
407d4dd4aa Fix embarrassing cut and paste bugs
The previous commit 871d7ae0cdf5 "Add option to make ceiling visually
stand out more in the profile" contained not one but two stupid cut and
paste bugs. I cannot begin to explain how this could have worked when I
first tested it.

Reported-by: Jan Schubert <Jan.Schubert@GMX.li>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-07 12:55:11 -08:00
Dirk Hohndel
a0f28aa422 Add option to make ceiling visually stand out more in the profile
While having the background "come down" seemed like a good visualization
of the ceiling, some divers appear to prefer something more dramatic. This
adds an option to the Tec Settings to have the ceiling shown in red
instead of the default background color.

Suggested-by: Jan Schubert <Jan.Schubert@GMX.li>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-07 11:39:15 -08:00
Dirk Hohndel
3d80d9283d Sort the divecomputers alphabetically and have fixed width dropdown
Instead of just taking the vendors and products for the supported
divecomputers in the order libdivecomputer provides them to us we sort
them as we add them to our list of lists. While doing this we also track
the longest product name and try to make sure that the combobox for the
product is set to a fixed width that's wider then the longest product
name.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-07 10:12:10 -08:00
Dirk Hohndel
d5da3c9a95 Prevent crash when no default device is set
We were dereferencing the default device, even if not set.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-05 21:19:30 -08:00
Dirk Hohndel
9904272d2f Split dive computer selection into seperate vendor and product combo boxes
The length of that combo box got increasingly insane as libdivecomputer
supported more and more models. To make this more scalable we now have two
combo boxes. One with just the vendors and a second one with the products
depending on the vendor selected.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-05 21:05:30 -08:00
Dirk Hohndel
dcb6574dc4 Improve deco handling and add NDL support
This commit changes the code that was recently introduced to deal with
deco ceilings. Instead of handling these through events we now store the
ceiling (which in reality is the deepest deco stop with all known dive
computers) and the stop time at that ceiling in the samples.

This also adds support for NDL (non stop dive limit) which both dive
computers that appear to give us ceiling / deco information appear to
give us as well (when the diver isn't in deco).

If the mouse hovers over the profile we now add support for displaying the
NDL, the current deco obligation and (if we are able to tell from the
data) whether we are at a safety stop.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-04 21:05:26 -08:00