Commit graph

131 commits

Author SHA1 Message Date
Anton Lundin
508f930660 Document found leaks
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-12-18 08:34:00 -08:00
Anton Lundin
236b1d08ed When (re)planning use prefs.decopo2 for mod
Use our the decopo2 from preferences for mod/switchdepth calculations
when re-planning a dive or planning a dive based on a previous dive.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-12-04 16:27:27 -06:00
Dirk Hohndel
8d766e13e2 Make sure we always have copies of equipment descriptions
Having pointers copied around that might get freed elsewhere could be a
problem.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-14 13:45:54 -08:00
Dirk Hohndel
7d89f5d7ee Add standard double cylinders
Fixes #689

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-08-05 08:05:07 -07:00
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
912560f928 Planner: don't track cylinder pressure if working pressure is 0
The pressure graph will go from 0 to negative - one could make a weak
argument that this would at least tell you how much pressure you'd need in
the cylinder to start with, but that's kinda lame.

Fixes #615

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-16 23:04:30 -07:00
Dirk Hohndel
9d97426e8e Planner: reset deco gas used member
Otherwise every recalculation will continue to incorrectly increase the
deco gas used value.

Fixes #598

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-05 07:49:06 -07:00
Dirk Hohndel
cc86d68c86 Planner: don't set cylinder start and end pressure when adding dive
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-04 11:40:02 -07:00
Robert C. Helling
1b7abab9b9 Show ascent gas consumption separately in planner
In the worst gase you have to provide gas for your buddy during all the
ascent. So you should have the amount of gas used in ascent as a reserve.
This patch makes the planner notes display that value separately.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-01 07:05:01 -07:00
Dirk Hohndel
7f3efbdc98 Make gas mod be reasonable for users of imperial units as well
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-25 21:41:58 +08:00
Robert C. Helling
65c5d6815c Make pO2 settings functional in planner
Spin boxes for pO2 are now hooked up to preference values. Adding new
cylinders (or changing their fo2) computes the MOD accordin to the current
value of decopo2. Note that chaning the limits for deco pO2 does _not_
automatically update the switch depth of all cylinders as those might have
been manually entered.

Furthermore, MOD has now to option of rounding to multiples of a given
depth. That is used for the automatic switch depth which are now always
multiples of 3m (so that EAN50 is switched to at 21m rather than 22m).

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-25 21:07:10 +08:00
Joakim Bygdell
81b268d4ba Add ALU7 to common cylinders
Fixes #562

Signed-off-by: Joakim Bygdell <j.bygdell@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-25 16:57:23 +08:00
Henrik Brautaset Aronsen
21916d67de Use that pretty ℓ in the equipment list as well
Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-23 06:47:47 +08: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
2a871d7fe5 Planner: track gas used even if we don't have a real cylinder
We tracked gas used by simulating a dive with a cylinder - but for that we
need a cylinder size and working pressure. If the user just enters a gas
but no cylinder data (likely in order to figure out how much gas is used
so that she then can pick a big enough cylinder), we didn't show any gas
consumption.

It kinda sucks to add another member to the cylinder structure, but this
seemed far more reasonable then some other, global structure that
independently tracks gas usage. This just seemed to make sense.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-01 10:16:59 -07:00
Dirk Hohndel
4dfe12e508 Planner: make sure all cylinders have a sane depth
When copying cylinders from an existing dive, the mod of the cylinder
might not be set. Assume a conservative 1.4 pO2 and fill in those data.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-30 09:10:35 -07:00
Dirk Hohndel
d054e8c457 Planner: track gas consumption in cylinders and samples
This commit is a little bigger than I usually prefer, but it's all
somewhat interconnected.

- we pass around the cylinders throughout the planning process and as we
  create the plan we calculate the gas consumption in every segment and
  track this both in the end pressure of the cylinder and over time in
  the samples
- because of that we no longer try to calculate the gas consumption after
  being done planning; we just use what we calculated along the way
- we also no longer add gases during the planning process - all gases
  have to come from the list of cylinders passed in (which makes sense
  as we should only use those gases that the user added in the UI or
  inherited from a the selected dive (when starting to plan with a dive
  already selected)

With this patch I think we are close do being able to move all of the
planning logic back into the planner.c code where it belongs. The one
issue that still bothers me is that we are juggling so many dive
structures and then keep copying content around. It seems like we should
be able to reduce that.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-29 14:43:24 -07:00
Dirk Hohndel
0c836ebc47 Simplify string comparison
This is based on Linus' idea on the mailing list.
Treat NULL strings and empty strings as identical.

Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-06 14:15:59 -07:00
Dirk Hohndel
76e6420f6b Massive automated whitespace cleanup
I know everyone will hate it.
Go ahead. Complain. Call me names.
At least now things are consistent and reproducible.
If you want changes, have your complaint come with a patch to
scripts/whitespace.pl so that we can automate it.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-27 20:09:57 -08:00
Anton Lundin
33391a77e9 Convert the C code to using stdbool and true/false
Earlier we converted the C++ code to using true/false, and this converts
the C code to using the same style.

We already depended on stdbool.h in subsurfacestartup.[ch], and we build
with -std=gnu99 so nobody could build subsurface without a c99 compiler.

[Dirk Hohndel: small change suggested by Thiago Macieira: don't include
               stdbool.h for C++]

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-16 09:34:50 +07:00
Dirk Hohndel
90ff8e672b Update tank model with custom tanks used in XML files
Fixes #377

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-28 14:56:01 -08:00
Dirk Hohndel
193d20c479 Next step towards working translations
This may seem like a really odd change - but with this change the Qt tools
can correctly parse the C files (and qt-gui.cpp) and get the context for
the translatable strings right.

It's not super-pretty (I'll admit that _("string literal") is much easier
on the eye than translate("gettextFromC", "string literal") ) but I think
this will be the price of success.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-09 22:51:59 -07:00
Dirk Hohndel
054406b420 Remove even more code and declarations
There's lots more stuff that can go.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-07 13:43:17 -07:00
Dirk Hohndel
34db6dc2be Delete code and files that are no longer used
Most of this is Gtk related, some of it is helpers that we don't need
anymore. I love the diffstat.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-06 17:32:50 -07:00
Dirk Hohndel
4d3e74a236 Trying to switch to Qt translation
This compiles and looks about right, but it doesn't appear to work, yet.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-06 10:42:32 -07:00
Dirk Hohndel
4b12f28ca4 First steps towards removing glib dependencies
- remove the build flags and libraries from the Makefile / Configure.mk
- remove the glib types (gboolean, gchar, gint64, gint)
- comment out / hack around gettext
- replace the glib file helper functions
- replace g_ascii_strtod
- replace g_build_filename
- use environment variables instead of g_get_home_dir() & g_get_user_name()
- comment out GPS string parsing (uses glib utf8 macros)

This needs massive cleanup, but it's a snapshot of what I have right now, in
case people want to look at it.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-06 10:41:44 -07:00
Tim Wootton
c478ea30cb Added 3L Pony tanks to the list of default tanks in equipment.c
Signed-off-by: Tim Wootton <tim@tee-jay.demon.co.uk>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-02 14:53:48 -07:00
Benjamin
01acf2aa88 Add AL40 to list of standard tanks
Fixes #191 on the bug tracker list

Signed-off-by: Benjamin Fogel <nystire@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-02 08:53:21 -07:00
Dirk Hohndel
e7fd45c7ef Change ws_info and tank_info types
This is correct C. But debuggers in C++ mode are broken and can't display
the global variables. While I hate having to do this change, I hate not
being able to debug my software because of broken tools even more.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-09-10 11:44:49 -07:00
Dirk Hohndel
e91ac60f49 Fill ws_info structure and use it when entering weight systems
The code to initialize the weight systems from the last datafile loaded
had not been brought over from the Gtk version.

We now correctly update the data structure when loading file (but not yet
when editing values).

Most likely the same needs to be done for the tanks as well.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-09-10 11:42:26 -07:00
Dirk Hohndel
ecbcd4db47 Enable the weightsystem info and move the declarations to dive.h
Having the tank_info declared in models.cpp seemed unintuitive.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-23 21:33:19 -07:00
Dirk Hohndel
56c58bdd24 Actually remove cylinders and weightsystems from the data structures
The UI had only stubbed this code out. This adds the implementation of the
helpers and calls them.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-22 10:12:15 -07:00
Dirk Hohndel
19586081ed Correctly use the weightsystem_none / cylinder_none helpers
Plus a couple of minor formatting changes

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-21 11:29:21 -07:00
Dirk Hohndel
f3f7bf51fa Merge branch 'Qt'
After the 3.1 release it is time to shift the focus on the Qt effort - and
the best way to do this is to merge the changes in the Qt branch into
master.

Linus was extremely nice and did a merge for me. I decided to do my own
merge instead (which by accident actually based on a different version of
the Qt branch) and then used his merge to double check what I was doing.

I resolved a few things differently but overall what we did was very much
the same (and I say this with pride since Linus is a professional git
merger)

Here's his merge commit message:

    This is a rough and tumble merge of the Qt branch into 'master',
    trying to sort out the conflicts as best as I could.

    There were two major kinds of conflicts:

     - the Makefile changes, in particular the split of the single
       Makefile into Rules.mk and Configure.mk, along with the obvious Qt
       build changes themselves.

       Those changes conflicted with some of the updates done in mainline
       wrt "release" targets and some helper macros ($(NAME) etc).

       Resolved by largely taking the Qt branch versions, and then editing
       in the most obvious parts of the Makefile updates from mainline.

       NOTE! The script/get_version shell script was made to just fail
       silently on not finding a git repository, which avoided having to
       take some particularly ugly Makefile changes.

     - Various random updates in mainline to support things like dive tags.

       The conflicts were mainly to the gtk GUI parts, which obviously
       looked different afterwards.  I fixed things up to look like the
       newer code, but since the gtk files themselves are actually dead in
       the Qt branch, this is largely irrelevant.

       NOTE! This does *NOT* introduce the equivalent Qt functionality.
       The fields are there in the code now, but there's no Qt UI for the
       whole dive tag stuff etc.

    This seems to compile for me (although I have to force
    "QMAKE=qmake-qt4" on f19), and results in a Linux binary that seems to
    work, but it is otherwise largely untested.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-17 22:01:41 -07:00
Dirk Hohndel
63c0c7921b Avoid reading an uninitialized variable when adding new cylinders
If mbar = 0 then *p would not be set, but the variable was then used in
the calling function.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-15 22:32:08 -07:00
Dirk Hohndel
98414ac9a9 Fix compiler warnings
Doing this on Arch Linux with gcc 4.8.0 helped find one real bug.

The rest are simply changes to make static functions externally visible
(as they are kept around to eventually become helpers used by Qt) which
for now avoids the warnings.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-03 14:21:13 -07:00
Dirk Hohndel
8677721e85 Remove the majority of the Gtk related code
- rip all Gtk code from qt-gui.cpp
- don't compile Gtk specific files
- don't link against Gtk libraries
- don't compile modules we don't use at all (yet)
- use #if USE_GTK_UI on the remaining files to disable Gtk related parts
- disable the non-functional Cochran support while I'm at it

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-03 11:37:09 -07:00
Tomaz Canabrava
115ee47bfc Added the code that will load and populate the Tank Info
Added the code that will load and populate the Tank Info
ComboBox that`s used by the user to select the Cylinder
description.

Code curerntly implements more than the GTK version since
the GTK version of it was a plain-list, this one is a
table based model that can be used in ListViews ( like
we use now in the ComboBox ) but also in TableViews
( if there`s a need in the future to see everything
that`s catalogued in the Tank Info struct. )

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-15 17:34:44 -07:00
Tomaz Canabrava
92397a2bad Started the real code on the Qt Interface.
1 - Open File already open files, it tries to not break the Gtk version,
    but some methods on the GTK version still need to be called inside Qt
    because the code is too tight-coupled.

2 - Close file already close files, same comments for the open file dialog
    applies here.

3 - The code for adding new cylinders in the cylinder dialog is done,
    already works and it's integrated with the system.  There's a need to
    implement the edit and delete now, but it will be easyer since I'm
    starting to not get lost on the code.

4 - Some functions that were used to convert unities have been moved to
    convert.h ( can be changed later, put there because it's easyer to
    find something that converts in a convert.h =p ) because they were
    static functions that operated in the GTK version but I need those
    functions in the Qt version too.

[Dirk Hohndel: lots and lots of whitespace and coding style changes]

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-13 14:08:16 -07:00
Dirk Hohndel
8a5792d473 Manually add gas changes to a dive
Create a little widget that lists all the gases / tanks we know about and
allow the user to pick one of them.

Turns out that add_event only added events at the end of the list - but we
treat that list as chronologically sorted. So I fixed that little
mis-feature as well.

This does raise the question whether we need the inverse operation
(removing a gas change). And if there are other things that we should be
able to manually edit, now that we have the infrastructure for this neat
little context menu...

See #60 -- this doesn't address all of the issues mentioned there, but at
least deals with the 'headline' of the feature request...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-03-17 20:04:25 -07:00
Dirk Hohndel
0129192958 Try to capture some more potential buffer overflows caused by localization
A couple of these could clearly cause a crash just like the one fixed by
commit 00865f5a1e1a ("equipment.c: Fix potential buffer overflow in
size_data_funct()").

One would append user input to fixed length buffer without checking.

We were hardcoding the (correct) max path length in macos.c - replaced by
the actual OS constant.

But the vast majority are just extremely generous guesses how long
localized strings could possibly be.

Yes, this commit is likely leaning towards overkill. But we have now been
bitten by buffer overflow crashes twice that were caused by localization,
so I tried to go through all of the code and identify every possible
buffer that could be affected by this.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-03-03 20:18:23 -08:00
Lubomir I. Ivanov
b0df54071e equipment.c: Fix potential buffer overflow in size_data_funct()
strcpy() with buffer[10], could overflow on most languages.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-03-03 15:33:24 -08:00
Dirk Hohndel
6ce4d29f49 Clear statistics and equipment when no dive is selected
This all seems very strange forward.

The reason for the check whether the stats_w widget has been populated is
that at the very beginning, when the UI is still being assembled, a first
call to switch_page() happens as the notebook pages are assembled. At that
point the stats_w widget is still empty which tells us that we aren't
ready to display anything.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-18 17:00:18 -08:00
Dirk Hohndel
e3a8ed5183 Massive cleanup
Mostly coding style and whitespace changes plus making lots of functions
static that have no need to be extern. This also helped find a bit of code
that is actually no longer used.

This should have absolutely no functional impact - all changes should be
purely cosmetic. But it removes a bunch of lines of code and makes the
rest easier to read.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-30 08:31:53 +11:00
Linus Torvalds
77ece3fccb Clean up gtk combo box handling
This cleans up our handling of combo boxes and all the duplicated
completion logic, and simplifies the code.

In particular, we get rid of the deprecated GtkComboBoxEntry.  While it
made some things easier, it made other things harder.  Just using
GtkComboBox and setting that up correctly ends up being simpler, and
also makes the logic work with gtk-3.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-28 13:17:44 -08:00
Linus Torvalds
41027c2843 Make subsurface compile with -DGSEAL_ENABLE
This forces us to use the proper gtk accessor functions.  It may not be
worth it if people actually do the Qt conversion, but if we want to try
gtk3 at some point, this might help.

This all came about because I was trying to explain on G+ what an
immense pain this all was to even figure out, if you don't actually know
gtk at all.  Google and the gtk migration guide are almost useless, and
the gtk2 documentation itself actually uses the fields directly without
any accessor functions in several places.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-28 07:54:55 -08:00
Jan Schubert
90d3c5614a Centralising and redefining values as integers
This patch centralizes the definition for surface pressure, oxygen in
air, (re)defines all such values as plain integers and adapts calculations.

It eliminates 11 (!) occurrences of definitions for surface pressure and
also a few for oxygen in air.

It also rewrites the calculation for EAD, END and EADD using the new
definitons, harmonizing it for OC and CC and fixes a bug for EADD OC
calculation.

And finally it removes the unneeded variable entry_ead in gtk-gui.c.

Jan

Signed-off-by: Jan Schubert <Jan.Schubert@GMX.li>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-14 20:12:40 -08:00
Linus Torvalds
868a2cc090 Split up preference data structure definition into 'pref.h'
.. and rename the badly named 'output_units/input_units' variables.

We used to have this confusing thing where we had two different units
(input vs output) that *look* like they are mirror images, but in fact
"output_units" was the user units, and "input_units" are the XML parsing
units.

So this renames them to be clearer.  "output_units" is now just "units"
(it's the units a user would ever see), and "input_units" is now
"xml_parsing_units" and set by the XML file parsers to reflect the units
of the parsed file.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-10 20:30:32 -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