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>
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>
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>
- 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>
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>
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>
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>
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>
- 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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
.. 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>
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>
When we fill the cylinder information in an imperial unit world, a
working pressure of zero is a special case, and forces us to use the
actual physical size of the cylinder in liter, despite the fact that
we normally would use cuft.
However, we compare that value against zero in a 'double', and in
between going through the gtk spinbutton logic, the zero we have
filled in then gets read out as some very tiny epsilon value from the
gtk spinbuttons (typically in the 10**-317 range). This causes us to
think that the zero isn't actually a zero, because gtk has done odd
things with it.
Fix this by calculating the millibar value (as an integer) first, and
check that *integer* against zero. Any crazy epsilon values will have
been rounded away, and our logic works again.
There's a good reason why subsurface does everything using integers
(ie the afore-mentioned "convert to integer millibar" etc) and doesn't
use floating point for any core data structures, only for conversion.
FP rounding and inexact behavior can be really subtle.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The buttons didn't actually do anything when clicked, but this still
was inconsistent behavior.
Reported-by: Pierre-Yves Chibon <pingou@pingoured.fr>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Originally I used the colloquial term "bar" for the weight bar that you
can attach to a backplate (usually when diving twins in a tec
environment). This of course causes an odditity for translations as this
word "bar" is a homonym for the weight system and the pressure unit -
which throws off translations.
Instead of switching to a context-based translation I instead went with a
better term: "backplate weight". This of course now needs to be
translated, so I updated the .po files (and added German translations for
the two flavors of German).
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
- fix two missing strings in equipment.c (thanks to Tommi Saviranta for
pointing this out)
- add context for the translations of the Yearly/monthly statistics. The code
for this ended up being incredibly ugly, but the gettext infrastructure
really clashed with the way this is implemented. What I have now at least
works (tested with the German translation)
- merge the new strings into all the po files. The non-German translations need
to be updated. Make sure you remove the "# , fuzzy" lines or the current
Makefile will ignore those additions.
- some minor cleanup of the po files (many listed the wrong language, all of
them copied my incorrect use of PACKAGE (instead of saying "Subsurface").
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This is just the first step - convert the string literals, try to catch
all the places where this isn't possible and the program needs to convert
string constants at runtime (those are the N_ macros).
Add a very rough first German localization so I can at least test what I
have done. Seriously, I have never used a localized OS, so I am certain
that I have many of the 'standard' translations wrong. Someone please take
over :-)
Major issues with this:
- right now it hardcodes the search path for the message catalog to be
./locale - that's of course bogus, but it works well while doing initial
testing. Once the tooling support is there we just should use the OS
default.
- even though de_DE defaults to ISO-8859-15 (or ISO-8859-1 - the internets
can't seem to agree) I went with UTF-8 as that is what Gtk appears to
want to use internally. ISO-8859-15 encoded .mo files create funny
looking artefacts instead of Umlaute.
- no support at all in the Makefile - I was hoping someone with more
experience in how to best set this up would contribute a good set of
Makefile rules - likely this will help fix the first issue in that it
will also install the .mo file(s) in the correct place(s)
For now simply run
msgfmt -c -o subsurface.mo deutsch.po
to create the subsurface.mo file and then move it to
./locale/de_DE.UTF-8/LC_MESSAGES/subsurface.mo
If you make changes to the sources and need to add new strings to be
translated, this is what seems to work (again, should be tooled through
the Makefile):
xgettext -o subsurface-new.pot -s -k_ -kN_ --add-comments="++GETTEXT" *.c
msgmerge -s -U po/deutsch.po subsurface-new.pot
If you do this PLEASE do one commit that just has the new msgid as
changes in line numbers create a TON of diff-noise. Do changes to
translations in a SEPARATE commit.
- no testing at all on Windows or Mac
It builds on Windows :-)
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Looks like a GtkEntryCompletion object created with
gtk_entry_completion_new() should be unreferenced after usage
(e.g. post gtk_entry_set_completion())
In info.c:get_combo_box_entry_text(), moved the free(..) line outside,
so that we can free regardless.
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This is the same issue as 882cb159a4 (although now we
don't have "Import XML Files" within a dialog). It applies when
in the "Dive info" dialog.
There is some sort of a GTK bug on Ubuntu 12.04 with GTK 2.24.10 that
prevents us from using the gtk_window_set_accept_focus() and similar
API to make the window behind fully inactive.
The proposed portable solution is to completely disable the background
window (NOTE: unless its the main window), disabling child controls
(gtk_widget_set_sensitive) and making the top window "transient for" or
putting it on top (gtk_window_set_transient_for).
Still we do not want to hide the background window titlebar with
gtk_window_set_decorated(), which makes it still clickable.
Make this change to older code in gtk-gui.c as well.
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
The "cylinders_equal()/copy_cylinders()" functions were buggered, and
only checked (and copied) the cylinder type. That was on purpose, since
you do want to be able to change the type of a cylinder without changing
the gasmix of the cylinder.
HOWEVER, the reverse is also true: you may want to change the gasmix of
a cylinder without changing the type.
So it's not that the type of the cylinder is special - it's that the
type and the gasmix should be considered separately.
Do that properly for the equipment editing case.
Reported-by: Ďoďo <dodo.sk@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
If we have no explicit cylinder info at all (it's normal air, no size or
working pressure information, and no beginning/end pressure information),
we don't save the cylinders in question because that would be redundant.
Such non-saved cylinders may still show up in the equipment list because
there may be implicit mention of them elsewhere, notably due to sample
data, so not saving them is the right thing to do - there is nothing to
save.
However, we missed one case: if there were other cylinders that *did* have
explicit information in it following such an uninteresting cylinder, we do
need to save the cylinder information for the useless case - if only in
order to be able to save the non-useless information for subsequent
cylinders.
This patch does that. Now, if you had an air-filled cylinder with no
information as your first cylinder, and a 51% nitrox as your second one,
it will save that information as
<cylinder />
<cylinder o2='51.0%' />
rather than dropping the cylinder information entirely.
This bug has been there for a long time, and was hidden by the fact that
normally you'd fill in cylinder descriptions etc after importing new
dives. It also used to be that we saved the cylinder beginning/end
pressure even if that was generated from the sample data, so if you
imported from a air-integrated computer and had samples for that cylinder,
we used to save it even though it was technically redundant.
We stopped saving redundant air sample information in commit 0089dd8819
("Don't save cylinder start/end pressures unless set by hand").
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Removed start and end in save_cylinder_info(). These two variables are no
longer used.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Thanks to Christian for running the static code analysis tool against
subsurface...
There were some false positives, a few style issues that I'll ignore for
now, and two actual potential bugs.
First: Don't check unsigned variables for < 0
This has been around for a while and we are lucky that while technically a
bug it still works as expected. Passing a negative idx simply turns it
into a very large unsigned integer which then fails the > dive_table.nr
test. So it still gets a NULL returned. A bug? Yes. Critical? No.
Mismatched allocation and free
This is an actual bug that potentially could cause issues. We allocate
memory with malloc and free it with g_free. Not good.
Reported-by: Cristian Ionescu-Idbohrn <cristian.ionescu-idbohrn@axis.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
By now the default file code seems quite matured, so in preparation for
2.0 we'll bring it back into master.
I made a few small clean-ups during the merge, but the merge itself is
very much straight forward.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
While most of this problem was fixed in commit 18b3dca431a4 ("Fix a long
standing bug when editing dives"), it turns out that I missed a couple of
the equipment callbacks.
In the corner case of having an empty divelist (where therefore
current_dive == NULL) manually adding a dive and trying to add equipment
(cylinder or weightsystem) to it would crash subsurface as we were trying
to dereference current_dive.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Calling edit from the context menu creates a combined editing widget that
contains both dive info and equipment. When editing cylinders or
weightsystems from that widget and confirming those edits with OK those
changes were already committed to the current_dive - regardless on which
dive the user clicked. Worse, even when the user clicked Cancel in the
edit widget, any changes to the equipment stayed in effect.
This had especially confusing consequences when editing multiple dives.
As a workaround this commit adds a global edit_dive variable. This fake
dive is edited by the secondary editing widgets and if the user accepts
changes with OK then they are copied over to the current dive (or all
selected dives in multi dive editing mode).
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
When figuring out which cylinders to change in a multi-dive edit, we
already ignored the beginning and end pressures. But it turns out to make
more sense to also ignore the Nitrox / Helium settings.
Imagine you do a number of dives - for some reason your dive computer
records the wrong cylinder size in the downloaded logfile (like my uemis
does all the time). Dives will likely have different Nitrox percentage,
but you should still be able to simply fix the cylinder size for all dives
at once.
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
I lied in the commit message for commit 0468535524a3 ("When editing multiple
files, don't override existing equipment entries"); the changes there did
not parallel the logic for the string entries. Now I think it does.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
I missed one instance where a callback function needed to be passed the widget
index w_idx in the signal_connect function. It got passed a pointer to the
model instead which of course blew up when trying to dereference the array with
that "index".
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Pull dive-trip grouping from Dirk Hohndel:
"This turned into an updated pull request for the tree2 branch where I
implemented the date based grouping - but is actually a very different
topic: this adds the ability to edit multiple dives (and fixes some
issues with the dive editing overall). The reason for that is that it
reuses some of the infrastructure that I implemented in the tree2
branch for tracking the selected dives. More details in the commit
messages."
* 'tree2' of git://git.hohndel.org/subsurface:
Switch from date based to dive trip based grouping
Redo dive editing
Fix selecting and unselecting summary items
Apply sort functions to the correct model, don't select summary entries
Maintain selected rows when switching between list model and tree model
Create duplicate list model so sorting by columns works again
Improve tree model implementation
Allow date based grouping