Commit graph

362 commits

Author SHA1 Message Date
Dirk Hohndel
b94a93d061 During multi-dive deco calculations don't look at dives from other trips
Previously the code in init_decompression() would mindlessly walk back the
dive_table until it found a gap of at least 48h and take all those dives
into consideration when calculating tissue saturation. This goes horribly
wrong if you load dives from two divers into the same data file.

With this commit things will still turn out correctly, as long as the
dives are in separate trips in for each of the divers. So with this I can
load both Linus' and my divelog and things stay sane even on our shared
dive trips.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-13 19:37:41 -08:00
Linus Torvalds
6a10700ca5 Add default filename and divelist font to prefs structure
.. and add the usual logic to not save the default values.

This also simplifies the initial system-specific setup of both of these:
since we have defaults for all the preferences that get set up at
startup, we can just initialize those defaults to the system-specific
fonts then and there.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-11 17:46:00 -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
Linus Torvalds
88313f1077 Clean up duplicated depth interpolation
We have several places where we interpolate the depth based on two
samples and the time between them. Some of them use floating point, some
of them don't, some of them meant to do it but didn't.

Just use a common helper function for it. I seriously doubt the floating
point here really matters, since doing it in integers is not going to
overflow unless we're interpolating between two samples that are hours
apart at hundreds of meters of depth, but hey, it gives that rounding to
the nearest millimeter. Which I'm sure matters.

Anyway, we can probably just get rid of the rounding and the floating
point math, but it won't really hurt either, so at least do it
consistently.

The interpolation could be for other things than just depth, but we
probably don't have anything else we'd want to interpolate. But make the
function naming generic just in case.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-09 16:17:57 -08:00
Robert C. Helling
67d59ff018 Rewrite of the deco code
o) Instead of using gradient factors as means of comparison, I now use
   pressure (as in: maximal ambient pressure).

o) tissue_tolerance_calc() now computes the maximal ambient pressure now
   respecting gradient factors. For this, it needs to know about the
   surface pressure (as refernce for GF_high), thus gets *dive as an
   argument. It is called from add_segment() which this also needs *dive
   as an additional argument.

o) This implies deco_allowed_depth is now mainly a ambient-pressure to
   depth conversion with decorations to avoid negative depth (i.e. no deco
   obliation), implementation of quantization (!smooth => multiples of 3m)
   and explicit setting of last deco depth (e.g. 6m for O2 deco).

o) gf_low_pressure_this_dive (slight change of name), the max depth in
   pressure units is updated in add_segment. I set the minimal value in
   buehlmann_config to the equivalent of 20m as otherwise good values of
   GF_low add a lot of deco to shallow dives which do not need deep stops
   in the first place.

o) The bogus loop is gone as well as actual_gradient_limit() and
   gradient_factor_calculation() and large parts of deco_allowed_depth()
   although I did not delete the code but put it in comments.

o) The meat is in the formula in lines 147-154 of deco.c. Here is the
   rationale:

   Without gradient factors, the M-value (i.e the maximal tissue pressure)
   at a given depth is given by ambient_pressure / buehlmann_b + a.

   According to "Clearing Up The Confusion About "Deep Stops" by Erik C.
   Baker (as found via google) the effect of the gradient factors is no
   replace this by a reduced affine relation (i.e. another line) such that
   at the surface the difference between M-value and ambient pressure is
   reduced by a factor GF_high and at the maximal depth by a factor
   GF_low.

   That is, we are looking for parameters alpha and beta such that

   alpha surface + beta = surface + gf_high * (surface/b + a - surface)

   and

   alpha max_p + beta = max_p + gf_low * (max_p/b + a - max_p)

   This can be solved for alpha and beta and then inverted to obtain the
   max ambient pressure given tissue loadings. The result is the above
   mentioned formula.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-08 08:59:20 -08:00
Linus Torvalds
c2bc6633ec Improve dive trip sort comparison function
We do want to compare "loose" dives too, but we need to be a bit
careful, and always use the trip date as the primary sort key for any
dives that are not in the same trip.

Reported-and-tested-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-07 14:55:42 -08:00
Dirk Hohndel
be9be189f7 Display dive profile of the dive we plan, as we plan it
As the user enters data into the entry fields, that data is validated and
as soon as there is enough data we start constructing a dive profile,
including the final ascent to the surface, including required deco stops,
etc.

This commit still has some serious issues.

- when data is input that doesn't validate, we just print a warning to
  stdout - instead we need to change the backgroundcolor of the input
  field or something.
- when we switch to the last dive in order to show the profile we don't
  actually search for the last dive - we just show the first one in the
  tree. This works for the default sort order but is of course wrong
  otherwise

I'm sure there are many other bugs, but I want to push it out where it is
right now for others to be able to take a look.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-06 22:15:03 -08:00
Dirk Hohndel
cca847791a First stab at simplistic dive planning
This comes with absolutely no gui - so the plan literally needs to be
compiled into Subsurface. Not exactly a feature, but this allowed me to
focus on the planning part instead of spending time on tedious UI work.

A new menu "Planner" with entry "Test Planner" calls into the hard-coded
function in planner.c. There a simple dive plan can be constructed with
calls to plan_add_segment(&diveplan, duration, depth at the end, fO2, pO2)

Calling plan(&diveplan) does the deco calculations and creates deco stops
that keep us below the ceiling (with the GFlow/high values currently
configured). The stop levels used are defined at the top of planner.c in
the stoplevels array - there is no need to do the traditional multiples of
3m or anything like that.

The dive including the ascents and deco stops all the way to the surface
is completed and then added as simulated dive to the end of the divelist
(I guess we could automatically select it later) and can be viewed.

This is crude but shows the direction we can go with this. Envision a nice
UI that allows you to simply enter the segments and pick the desired
stops.

What is missing is the ability to give the algorithm additional gases that
it can use during the deco phase - right now it simply keeps using the
last gas used in the diveplan.

All that said, there are clear bugs here - and sadly they seem to be in
the deco calculations, as with the example given the ceiling that is
calculated makes no sense. When displayed in smooth mode it has very
strange jumps up and down that I wouldn't expect. For example with GF
35/75 (the default) the deco ceiling when looking at the simulated dive
jumps from 16m back up to 13m around 14:10 into the dive. That seems very
odd.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-04 23:56:55 -08:00
Dirk Hohndel
1b22ac16f2 Clean up DEBUG code
It's still a mess (and the symbols aren't used consistently), but it's a
tiny bit more logical...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-04 11:56:43 -08:00
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
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
2c33603256 Consider previous dives when calculating deco
This also initializes the N2 tissue saturations to correct numbers
(setting them to zero was clearly silly).

With this commit we walk back in the dive_table until we find a surface
intervall that's longer than 48h. Or a dive that comes after the last one
we looked at; that would indicate that this is a divelist that contains
dives from multiple divers or dives that for other reasons are not
ordered. In a sane environment one would assume that the dives that need
to be taken into account when doing deco calculations are organized as one
trip in the XML file and so this logic should work.

One major downside of the current implementation is that we recalculate
everything whenever the plot_info is recreated - which happens quite
frequently, for example when resizing the window or even when we go into
loup mode. While this isn't all that compute intensive, this is an utter
waste and we should at least cache the saturation inherited from previous
dives (and clear that number when the selected dive changes). We don't
want to cache all of it as the recreation of the plot_info may be
triggered by the user changing equipment (and most importantly, gasmix)
information. In that case the deco data for this dive does indeed have to
be recreated. But without changing the current dive the saturation after
the last surface intervall should stay the same.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-03 20:45:20 -08:00
Salvador Cuñat
8dbe3528b4 Limit to 4 the number of cylinders shown in the data frame
For dives with more than 4 cylinders, the frame got very crowded and we
needed a magnifier to see the numbers.
If we used more than four tanks, let's put the info in another frame, if not, print
the OTUs, the maxcns and the weight sytem in the new frame.
There is still room for two more short data.

Changed naming of nitrox and trimix mixes.

Changed cylinder description.

There are issues with the size of some translations.

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-02 13:03:45 -08:00
Linus Torvalds
b900a21165 Fix mixed dive/trip tree model grouping
In commit 96db56f89c ("Allow overlapping (and disjoint) dive trips")
I allowed dives to be part of arbitrary dive trips regardless of date,
which meant that the divelist tree model code needed to find the right
parent for a dive as it was inserted.

That code stupidly assumed that the top level of the dive list tree
containted *only* trips, which is not at all the case. It happens to
be true if you group all your dives into divetrips (the common case
for autogroup=1, which real users do tend to have), but now that Dirk
made the autogrouping be a per-xml-file setting, it became much easier
to trigger the "mixed trips and non-trip dives" case, and that showed
the stupid bug with the test dives.

So instead of just blindly iterating to the 'n'th entry, search for
the actual entry that is the dive trip we want to associate a dive
with.

Reported-by: Lubomir Ivanov <neolit123@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-02 10:26:30 -08:00
Linus Torvalds
bc16f06536 Keep the selected dive visible in the divelist
This patch makes the divelist behave more as you would expect it as you
scroll up and down through its entries.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-01 17:33:11 -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
Linus Torvalds
d720e133d8 First step in cleaning up cylinder pressure sensor logic
This clarifies/changes the meaning of our "cylinderindex" entry in our
samples. It has been rather confused, because different dive computers
have done things differently, and the naming really hasn't helped.

There are two totally different - and independent - cylinder "indexes":

 - the pressure sensor index, which indicates which cylinder the sensor
   data is from.

 - the "active cylinder" index, which indicates which cylinder we actually
   breathe from.

These two values really are totally independent, and have nothing
what-so-ever to do with each other. The sensor index may well be fixed:
many dive computers only support a single pressure sensor (whether
wireless or wired), and the sensor index is thus always zero.

Other dive computers may support multiple pressure sensors, and the gas
switch event may - or may not - indicate that the sensor changed too. A
dive computer might give the sensor data for *all* cylinders it can read,
regardless of which one is the one we're actively breathing. In fact, some
dive computers might give sensor data for not just *your* cylinder, but
your buddies.

This patch renames "cylinderindex" in the samples as "sensor", making it
quite clear that it's about which sensor index the pressure data in the
sample is about.

The way we figure out which is the currently active gas is with an
explicit has change event. If a computer (like the Uemis Zurich) joins the
two concepts together, then a sensor change should also create a gas
switch event. This patch also changes the Uemis importer to do that.

Finally, it should be noted that the plot info works totally separately
from the sample data, and is about what we actually *display*, not about
the sample pressures etc. In the plot info, the "cylinderindex" does in
fact mean the currently active cylinder, and while it is initially set to
match the sensor information from the samples, we then walk the gas change
events and fix it up - and if the active cylinder differs from the sensor
cylinder, we clear the sensor data.

[Dirk Hohndel:  this conflicted with some of my recent changes - I think
		I merged things correctly...]

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-30 20:44:47 -08:00
Linus Torvalds
96db56f89c Allow overlapping (and disjoint) dive trips
We used to have the rule that a dive trip has to have all dives in it in
sequential order, even though our XML file really is much more flexible,
and allows arbitrary nesting of dives within a dive trip.

Put another way, the old model had fairly inflexible rules:

 - the dive array is sorted by time

 - a dive trip is always a contiguous slice of this sorted array

which makes perfect sense when you think of the dive and trip list as a
physical activity by one person, but leads to various very subtle issues
in the general case when there are no guarantees that the user then uses
subsurface that way.

In particular, if you load the XML files of two divers that have
overlapping dive trips, the end result is incredibly messy, and does not
conform to the above model at all.

There's two ways to enforce such conformance:

 - disallow that kind of behavior entirely.

   This is actually hard.  Our XML files aren't date-based, they are
   based on XML nesting rules, and even a single XML file can have
   nesting that violates the date ordering.  With multiple XML files,
   it's trivial to do in practice, and while we could just fail at
   loading, the failure would have to be a hard failure that leaves the
   user no way to use the data at all.

 - try to "fix it up" by sorting, splitting, and combining dive trips
   automatically.

   Dirk had a patch to do this, but it really does destroy the actual
   dive data: if you load both mine and Dirk's dive trips, you ended up
   with a result that followed the above two technical rules, but that
   didn't actually make any *sense*.

So this patch doesn't try to enforce the rules, and instead just changes
them to be more generic:

 - the dive array is still sorted by dive time

 - a dive trip is just an arbitrary collection of dives.

The relaxed rules means that mixing dives and dive trips for two people
is trivial, and we can easily handle any XML file.  The dive trip is
defined by the XML nesting level, and is totally independent of any
date-based sorting.

It does require a few things:

 - when we save our dive data, we have to do it hierarchically by dive
   trip, not just by walking the dive array linearly.

 - similarly, when we create the dive tree model, we can't just blindly
   walk the array of dives one by one, we have to look up the correct
   trip (parent)

 - when we try to merge two dives that are adjacent (by date sorting),
   we can't do it if they are in different trips.

but apart from that, nothing else really changes.

NOTE! Despite the new relaxed model, creating totally disjoing dive
trips is not all that easy (nor is there any *reason* for it to be
easty).  Our GUI interfaces still are "add dive to trip above" etc, and
the automatic adding of dives to dive trips is obviously still based on
date.

So this does not really change the expected normal usage, the relaxed
data structure rules just mean that we don't need to worry about the odd
cases as much, because we can just let them be.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-30 19:40:15 -08:00
Linus Torvalds
e862f7c343 Allow sorting dives by date - without the dive trips in the dive list
We used to enable dive trips whenever we sorted by date, which can be
a bit annoying. Sometimes you really just want to sort all your dives
by date, without necessarily seeing the trip data.

So this changes the default sort to be the "dive number" table, and
then does *not* actually sort by the dive number, but instead enables
the trips, and then sorts the result by date. So the "dive number"
column - which used to be non-sortable - becomes semantically
equivalent to the old date column sorting.

And now sorting by date makes it act like sorting by depth or any
other attribute - we hide the dive trip tree, and just show the plain
list of dives (sorted by date, obviously).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-28 22:35:55 -08:00
Lubomir I. Ivanov
596b13e310 Free trip notes memory when deleting a trip
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-28 08:59:42 -08:00
Lubomir I. Ivanov
906fd400e7 Small changes in the memory management when dive-merging
This patch makes a couple of modifications:
1) divelist.c:delete_single_dive() now tries to free all memory associated
with a dive, such as the string values for divemaster, location, notes &
etc.

2) dive.c:merge_text(), now always makes a copy in memory for the returned
string - either combined or one of the two which are passed
to the function.

The reason for the above two changes is that when (say) importing the same
data over and over, technically a merge will occur for the contained dives,
but mapped pointers can go out of scope.

main.c:report_dives() calls try_to_merge() and if succeeds the two dives
that were merged are deleted from the table. when we delete a dive,
we now make sure all string data is cleared with it, but also in the actual merge
itself, which precedes, copies of the merged texts are made (with merge_text()),
so that the new, resulted dive has his own text allocations.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-27 08:08:59 -08:00
Dirk Hohndel
720d4c65e8 Fix crash when trip info changes across remember/restore tree state
Interesting crash. Importing a file gets us to a stage where we have a
trip tree note with a date that doesn't exist as trip date. That's clearly
bogus. And in import_files() we assume that all is still fine and try to
restore the old expanded / selected state for the various trips.

There is clearly a bigger issue here, this patch at least prevents the
actual crash from happening by making sure the pointer is non-NULL before
dereferencing it.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-26 19:44:01 -08:00
Lubomir I. Ivanov
b10ebbda61 Fix some small memory leaks related to gtk_tree_model_get_path()
From the GTK docs on gtk_tree_model_get_path():
"Returns a newly-created GtkTreePath referenced by iter.
This path should be freed with gtk_tree_path_free()."

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-22 20:15:00 -08:00
Dirk Hohndel
eb3e879030 Correctly calculate OTUs when pO2 is recorded in the samples
This will normally happen for CCR dives with a set pO2. The old
calculations was only valid for OC dives.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-20 17:42:10 -08:00
Dirk Hohndel
2f9960f20b Deal with some trip issues when editing dive timestamps
The idea behind editing timestamps had of course been the typical "oops, I
forgot to set my time correctly" which shifts a dive (or a few of them) by
a few hours but keeps the overall order of dives the same).

But reasonable people might argue that they can envision a scenario where
more dramatic changes are being made. And we need to deal with the impact
this has on dive trips.

Here we handle a couple of simple cases:
- this is the only dive in a trip; just update the trip
  (this can still cause problems if the new time is in the middle of an
  existing trip).
- this dives moves before the start of the trip it is in; let's remove it
  from that trip (this response is a bit simplistic - but as I tried to
  say, I don't expect this to be a common use case; and removing it at
  least doesn't lead to entirely unexpected behavior).
- this dive moves past the end of this trip into the range of a different
  trip (in this case we remove the dive from the current trip and allow it
  to interrupt the trip it is moving into).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-15 21:01:29 -10: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
febcbd6325 Add the ability to edit the date/time of a dive
This can cause some fun unintended side effects - especially when the dive
is part of a trip and the new date/time moves this into a different trip.
Instead, trips get split and the overall result is consistent, but a bit
unexpected.

But since this is designed to help people right after a dive import in
case the clock on the dive computer was wrong, my guess is this won't ever
be a problem for actual users.

Fixes ticket 18

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-10 13:23:55 -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
936d289cb7 Fix insert_trip to correctly deal with trips that start at the same time
The existing code did not move the dives that are part of the second trip
to the first trip (and forgot to keep the 'better' notes as well).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-06 13:04:37 -08:00
Lubomir I. Ivanov
b435166dc3 Merge trips without modifying the GTK tree
This patch does 4 small divelist.c changes in the following
order of importance:

1) In find_trip_by_time() now there is a check if a trip is actually found
before looking at the "when" flag.

2) Make remember_tree_state() slighly safer. If for example we have recently
deleted a trip from the linked list, it may still exist in the GTK tree model,
thus we want to check when calling find_trip_by_time() if there is an actual
match before setting the "expanded" flag for a trip.

3) When merging two trips in merge_trips_cb(), only use the tree model
to retrieve the timestamps (DIVE_DATE) and then find matching trips with
find_matching_trip(). Once we have pointers to the two trips to be merged,
move dives from one to another iterating with add_dive_to_trip().

4) In merge_trips_cb() - remember the tree state, repopulate the tree and
restore tree state, since now we are not adding/removing rows directly.
tesdsad

Reported-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-04 21:21:28 -08:00
Linus Torvalds
6fe52ee19e Simplify tripflags: remove tripflag_names[]
This removes the tripflag name array, since it's not actually useful.
The only information we ever save in the XML file is whether a dive is
explicitly not supposed to ever be grouped with a trip ("NOTRIP"), and
everything else is implicit.

I'm going to simplify the trip flags further (possibly removing it
entirely - like I did for dive trips already), and don't like having to
maintain the tripflag_names[] array logic.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-26 21:44:51 -07:00
Linus Torvalds
3f197336aa Remove 'tripflag' from dive trips
Both dives and dive trips have the same 'tripflag' thing, but they are
used very differently.  In particular, for dive trips, the only case
that has any meaning is the TF_AUTOGEN case, so instead of having that
trip flag, replace it with a bitfield that says whether the trip was
auto-generated or not.

And make the one-bit bitfields explicitly unsigned.  Signed bitfields
are almost always a mistake, and can be confusing.

Also remove a few now stale macros that are no longer needed now that we
don't do the GList thing for dive list handling, and our autogen logic
has been simplified.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-26 21:44:04 -07:00
Linus Torvalds
ffa3fd551c Clarify (and fix) dive trip auto-generation
This makes the dive trip auto-generation a separate pass from the
showing of the dive trips, which makes things much more understandable.
It simplifies the code a lot too, because it's much more natural to
generate the automatic trip data by walking the dives from oldest to
newest (while the tree model wants to walk the other way).

It gets rid of the most annoying part of using the gtk tree model for
dive trip management, but some still remains.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-26 09:30:27 -08:00
Linus Torvalds
85f0749c85 Remove 'when_from_file' field from dive trip
It had become a write-only field (apart from some now useless debugging)
when simplifying the remove_autogen_trips() function.

So remove it.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-26 09:28:34 -08:00
Linus Torvalds
544a8b9d77 Rewrite 'remove_autogen_trips()' without the gtk tree model walking
I'm trying to remove (or at least simplify) the gtk tree model usage for
our trip handling, but I'm doing it in small chunks.  The goal is to
just do all our trip handling logic explicitly using our own data
structures, and use the gtk tree model purely for showing the end
result.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-26 09:27:54 -08:00
Linus Torvalds
ba3e6bcc51 Associate each dive trip with the dives in that trip
We already kept a count of dives per trip in order to figure out when
there are no more dives left and the trip needs to be freed.  Now we
explicitly keep track of the list of dives associated with the trip too,
which simplifies the "find the time of the trip" logic.

We may want to sort it in time, but for now this is mainly about trying
to keep track of the divetrip relationships explicitly.  I want to move
away from the whole "use the gtk tree model to keep track of things"
approach.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-26 09:27:24 -08:00
Linus Torvalds
25b4fee655 Move events and samples into a 'struct divecomputer'
For now we only have one fixed divecomputer associated with each dive,
so this doesn't really change any current semantics.  But it will make
it easier for us to associate a dive with multiple dive computers.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-23 19:36:27 -08:00
Linus Torvalds
a9786564c2 Allocate dive samples separately from 'struct dive'
We used to avoid some extra allocations by just allocating the dive
samples as part of the 'struct dive' allocation itself, but that ends up
complicating things, and will make it impossible to have multiple
different sets of samples (for multiple dive computers).

So stop doing it. Just allocate the dive samples array separately.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-23 19:33:39 -08:00
Dirk Hohndel
d872a5c8aa Make sure there are no invisible selected dives after import / download
Prior to this commit, gtk often decided to collapse the trip with the
selected dive after the user imported or downloaded additional dives.
Since Subsurface tracks dives as being selected even after gtk collapses a
trip (which clears all selection state as far as gtk is concerned) this
could lead to the strange situation that the user could click on a new
dive to select it without unselecting the already selected dive - and
suddenly edit or delete did things that were entirely unwanted.

With this change we explicitly save and then restore the tree state around
import and download operations. This ensures that the same dive(s) stay
selected and trips stay expanded and therefore avoids the issues described
here.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-21 13:53:36 -08:00
Linus Torvalds
d166e34fed Fix silly thinko in recent changes to "Delete dive" code
Commit 38c79d149d ("Simplify and clean up dive trip management")
simplified the code a bit *too* much, and removed the check for
"dive->selected".

As a result, trying to delete a dive resulted in *all* dives being
deleted.

Oops.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-19 12:02:09 -08:00
Linus Torvalds
b304562fa8 Be stricter about when we allow merging of dives
If the surface interval between two dives is more than half an hour,
don't try to call it a single dive.  Just the dive profile will be
looking ridiculous.

Things like tank refills etc could also be a good thing to check (again,
the dive profile would look ridiculous), but the cylinder pressure going
up a small amount is actually normal (ie cylinder warming up in warmer
water on the surface).  So I don't know what the proper limit for that
would be.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-11 15:09:00 +01:00
Dirk Hohndel
fe4f13f184 Add special download modes to force updates from the divecomputer
This will hopefully not be something we need often, but if we improve
support for a divecomputer (either in libdivecomputer or in our native
Uemis code or even in the way we handle (and potentially discard) events),
then it is extremely useful to be able to say "re-download things
from the divecomputer and for things that were not edited in Subsurface,
don't try to merge the data (which gives BAD results if for example you
fixed a bug in the depth calculation in libdivecomputer) but instead
simply take the samples, the events and some of the other unedited data
straight from the download".

This commit implements just that - a "force download" checkbox in the
download dialog that makes us reimport all dives from the dive computer,
even the ones we already have, and an "always prefer downloaded dive"
checkbox that then tells Subsurface not to merge but simply to take the
data from the downloaded dive - without overwriting the things we have
already edited in Subsurface (like location, buddy, equipment, etc).

This, as a precaution, refuses to merge dives that don't have identical
start times. So if you have edited the date / time of a dive or if you
have previously merged your dive with a different dive computer (and
therefore modified samples and events) you are out of luck.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-11 14:29:26 +01:00
Linus Torvalds
ba5079a489 Fix selection and trip expansion logic after merging dives
This just makes sure that the merged dive is properly selected, and
that we've saved the trip tree state so that the dive list repaints
nicely and with the newly merged dive selected after the merge.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-11 11:15:47 +01:00
Linus Torvalds
8514ec8723 Support merging of two adjacent dives
This introduces the notion of merging two disjoint dives: you can select
two dives from the dive list, and if the selection is exactly two dives,
and they are adjacent (and share the same dive trip), we support the
notion of merging the dives into one dive.

The most common reason for this is an extended surface event, which made
the dive computer decide that the dive was ended, but maybe you were
just waiting for a buddy or a student at the surface, and you want to
stitch together two dives into one.

There are still details to be sorted out: my Suunto dive computers don't
actually do surface samples at the beginning or end of the dive, so when
you stitch two dives together, the profile ends up being this odd "a
couple of feet under water between the two parts of the dive" thing.

But that's an independent thing from the actual merging logic, and I'll
work on that separately.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-11 10:48:14 +01:00
Dirk Hohndel
4c3dfee446 Merge branch 'pressure'
Make depth to absolute pressure conversions consistent.
2012-11-11 10:00:45 +01:00
Dirk Hohndel
e167108c76 Add depth to mbar helper function
This ensures that we use consistent math to get the absolute pressure at a
certain depth.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-11 08:50:56 +01:00
Linus Torvalds
38c79d149d Simplify and clean up dive trip management
This adds a couple of helper functions to manage dive trips
("add_dive_to_trip()" and "remove_dive_from_trip()") and makes those
functions do the trip statistics maintenance (trip beginning times,
number of dives, etc).

This was needed because the dive merge cases for multiple dive
computers showed some rather nasty special cases: especially if the
new dive information has been loaded into an XML file with trips
auto-generated, merging several of these kinds of xml files with
multiple dives in several overlapping trips would completely confuse
our previous code.

In particular, auto-generated trips that had the exact same date as
previous trips (because they were generated from the same dive
computer) really confused the code that used the trip timestamp to
manage the trips.

Adding the helper functions allows us to get the general case right
without having to have each piece of code that handles trip
information having to bother about all the odd rules. It will
eventually also allow us to make the dive trip data structures more
logical: right now the dive trip list is largely designed around the
odd gtk model handling, rather than some more higher-level conceptual
relationship with the actual dives.

But for now, this keeps all the data structures unchanged, and just
modifies them using the new helper functions.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-11 05:17:00 +01:00
Linus Torvalds
7f515eb7e5 Fix dive trip merging logic
We used to have very spotty logic for picking the dive trip when
merging two dives. It turns out that that spotty logic almost never
really matters, because in practice you'll never hit the situation of
merging two dives with different dive trips, but it *can* happen.

In particular, it happens when you use multiple dive computers, and
end up loading the dives from one computer on top of the dives of your
other computer. If the clocks of the dive computers was set
sufficiently close to each other, the dive merging logic will kick in
and you may now have slightly different times for the dives that get
merged, and the trip merging logic got *really* confused.

The trip management also depends on the trip dates being updated
correctly when the dives associated with a trip are updated (whether
added or removed), and the trip merging code did none of that.

This fixes it all up. Hopefully correctly.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-09 21:46:56 +01:00
Henrik Brautaset Aronsen
37e3ade2e2 Repair broken Add Dive menu item
Lubomir's commit aec904b612 broke the Add
Dive menu item:  The Edit Dive dialogue didn't show up after the initial
dialogue.

Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-05 09:05:02 -08:00
Lubomir I. Ivanov
117008a007 Added confirmation dialog when deleting dives and trips
divelist.c:
Show a "Yes/No" confirmation dialog when performing delete/remove
operations for dives and trips.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-24 10:32:25 -07:00
Lubomir I. Ivanov
55f08bfeab Use subsurface_os_feature_available() to check for unicode stars support
Mainly affecting older Windows (such as XP), which do not have a more
fully featured unicode fonts installed, such as Arial Unicode MS.

With this patch we do a runtime check of the OS version in a couple of
places and if the OS is old, we use the asterix character and spaces instead
of the unicode star characters.

Linux and OSX should be unaffected by this change unless
subsurface_os_feature_available() returns FALSE for UTF8_FONT_WITH_STARS
at some point.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-19 21:14:15 -07:00
Henrik Brautaset Aronsen
021544c19f Translate "air"
Translate the "air" text in the divelist.

Suggested-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-19 08:29:42 -07:00
Lubomir I. Ivanov
557a835765 Increase various stack buffer sizes to accommodate for locale strings
Example:
For some strings such as the "Trip title" the buffer of 60 bytes was not
enought for certain languages.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-17 15:08:23 -07:00
Dirk Hohndel
dbae888abc Handle dates and a "calculated plural" in translations
This looks like a massive commit mainly because of the line number changes
in the .po files. That sadly hides what really happened here:

- the places where we manually build dates have now been localized
- the one place where we did the English "calculated plural" has been
  modified so that it now can be correctly translated (in English this
  just adds an 's' to the noun if the number is != 1 - in other languages
  this tends to be much more complicated)

I then updated the two German translations to take advantage of the new
constructs. And while I was at it, I changed the translation Trip->Gruppe
to Trip->Reise as that seemed much more appropriate.
I also fixed another error in the German translation where I translated
"dive time" as "Startzeit" - but in the context it was "Dauer".

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-17 01:25:49 -07:00
Dirk Hohndel
d4a3ecedb0 Get divelist headers localized, too
This fixes an oversight in commit 881a2df83616 ("Conversion to gettext to
allow localization") - string literals that are marked with N_ need to be
converted when the corresponding variables are used at runtime. This was
missed for the divelist headers.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-11 22:03:10 +09:00
Dirk Hohndel
99846da77f Conversion to gettext to allow localization
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>
2012-10-11 10:03:03 +09:00
Dirk Hohndel
856e10ddb2 Add trip above adds all consecutive selected dives to the new trip
Before this commit we had the odd behavior that if we right clicked in the
middle of a group of selected dives, the trip was added above the dive we
clicked on, not above the group.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-09 16:32:05 +09:00
Lubomir I. Ivanov
5468f19a05 Fixed potential, rare corruption of unicode characters
In divelist.c:get_string(), when truncating the string to a maximum
of 60 characters (to be shown in the divelist), make sure we are
counting in guinchar (sizeof usually 2) instead of gchar (sizeof usually 1).
Use Glib functions such as g_utf8_strlen() and g_utf8_strncpy() to do that.

This patch fixes the potential problem when truncating a UTF-8 string
by calculating its length using strlen() in bytes.

For char = 1 byte, if the length returned by strlen() is an odd number
this means there is at least one single byte length character in there.

But also if the same string has a UTF-8 character at exactly the truncate
position minus x(probably 1) bytes, we are going to split the bytes
forming said UTF-8 char resulting in an incorrect string.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-02 10:11:16 -07:00
Lubomir I. Ivanov
fa5afc697e Fix memory leaks related to dive_trip->location
When creating a new dive_trip from a dive, we should probably
always copy the location via strdup(). However we then have to take
care of the de-allocation in divelist.c:delete_trip()
and gtk-gui.c:file_close().

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-01 20:56:17 -07:00
Lubomir I. Ivanov
cfefa0206d Destroy the divelist (tree) before calling gtk_main_quit()
Added new function dive_list_destroy() in divelist.c

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-01 20:55:28 -07:00
Lubomir I. Ivanov
7f01b91c99 Fixed memory leaks specific to divelist.c
move_dive_between_trips() always returns a pointer to a new
allocated memory block of size = GtkTreeIter. Lets free said memory
when no longer needed in the caller functions.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-01 20:53:52 -07:00
Dirk Hohndel
24c6197c10 Fix a number of obvious memory leaks
Just the result of cppcheck and valgrind...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-29 20:58:26 -07:00
Lubomir I. Ivanov
3e3e632e1f Clear the display widgets when deleting all dives in the list
After calling dive_list_update_dives() in delete_selected_dives_cb(),
if the selection length is zero, we can clear the display widgets
not to show information of a deleted dive.

[Dirk Hohndel: please watch your whitespace - you once again added a bunch
	       of empty lines that really didn't help the code...
	       I removed them]

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-29 08:27:03 -07:00
Dirk Hohndel
7f5ecb5bb7 Redo the delete dive code
The existing code (both my first single dive delete and then Lubomir's
multi dive delete code) had way too many issues and was just painfully
inefficient.

This new code takes a radically different approach and mostly ignores the
Gtk tree model (as that gets recreated after a delete, anyway) and instead
is linear time on the number of dives in the list. It does do its best to
maintain the existing selection and the expand state of tree model (the
latter isn't possible if we have switched to the list model).

Many thanks to "Lubomir I. Ivanov" <neolit123@gmail.com> for his work on
this - this commit actually contains a few lines out of one of the patches
that he wrote.

Reported-by: "Lubomir I. Ivanov" <neolit123@gmail.com>
Tested-by: "Lubomir I. Ivanov" <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-28 16:23:59 -07:00
Lubomir I. Ivanov
9036f3f80e Update the trip's "when" flag after deleting a dive from it
Both gtk_tree_selection_selected_foreach() and
gtk_tree_selection_get_selected_rows() are problematic.

gtk_tree_selection_get_selected_rows is not compatible with older GTK,
while gtk_tree_selection_selected_foreach() should not be used to
modify the tree. A workaround to is allocate memory and store what
is returned from the gtk_tree_selection_selected_foreach() callback
function as a GtkTreeIter array. Once done iterate trought the array
and pass the values to delete_single_dive().

A bit excesive, but it is not certain how safe is modifying the tree
while in the "_foreach" loop, even if it only shows a warning.

On the other hand the GTK source shows gtk_tree_selection_get_selected_rows()
to be a rather complicated and slow method.

Inside delete_single_dive(), once a dive is no longer part of "dive_table"
and if the dive was part of a trip, remove the dive from the tree
(gtk_tree_store_remove()) and call update_trip_timestamp().

The struct type "tree_selected_st" and tree_selected_foreach() are
reusable.

Reported-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2012-09-24 03:41:18 +03:00
Lubomir I. Ivanov
4d9abf6e8e Added the functionality to delete selected (multiple) dives
Moved portion of the code from delete_dive_cb() to a function called
delete_single_dive(), that directly accepts a GtkTreeIter pointer.

Added the function delete_selected_dives_cb(), which is called
when calling "Delete dives" from the combo box for the selected dives.

The above function iterates trought the selection calling
delete_selected_foreach(), which on its own calls delete_single_dive().

The "for-each" API in this case looks much prettier C code wise,
however we do potentially create an extra jump and also
do not have anything but the redirection:
delete_selected_foreach() -> delete_single_dive()

Probably slighly slower than using gtk_tree_selection_get_selected_rows(),
performance wise, but less C code.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2012-09-23 01:18:25 +03:00
Lubomir I. Ivanov
6458057599 Added different delete label when right clicking multiple drives
When clicking multiple dives in the list, check if more than one
are selected and if so show the text "Delete dives".

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2012-09-22 23:31:55 +03:00
Dirk Hohndel
529a72e6b4 Only select last dive by default if no other dives are selected
After deleting a dive the dive list is recreated. If there are still dives
selected we should select the last dive as well. If there isn't any dive
selected, then the last dive is as good a default as any, I guess.

Reported-by: "Lubomir I. Ivanov" <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-20 15:35:43 -07:00
Dirk Hohndel
7e8a476010 Removed obsolete debug message
We now handle this case correctly, so don't alert the user to something
that isn't an issue at all.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-20 13:33:00 -07:00
Dirk Hohndel
4b42c54357 Convert the divelist debug helpers to the new time functions as well
This makes things consistent.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-20 13:08:50 -07:00
Linus Torvalds
e8578ad9c9 Merge branch 'divetrip-rewrite' of git://github.com/torvalds/subsurface
Merge the dive trip rewrite by Dirk Hohndel.

This just merges the dive trip changes with the timestamp handling
changes.  There were multiple small data conflicts, along with some
newly added 'time_t' cases in the dive trip handling that needed to be
converted to 'timestamp_t' along the way.

* 'divetrip-rewrite' of git://github.com/torvalds/subsurface:
  Convert FIND_TRIP into function
  Partial rewrite of the dive trip code
  Check if trip is NULL before calling DIVE_TRIP
2012-09-20 12:30:58 -07:00
Linus Torvalds
6d16a15196 FIND_TRIP: don't cast a timestamp to a pointer
The pointer size may not be large enough to contain a timestamp, so make
FIND_TRIP() just pass the pointer to the timestamp instead.

And use an inline function instead of macros with casts.  That gets us
proper type safety while at it, so that we get a warning if somebody
doesn't pass the expected "timestamp_t *".  Plus the code actually looks
simpler and way more straightforward.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-09-20 11:08:15 -07:00
Dirk Hohndel
a8e2fd10c7 Convert FIND_TRIP into function
This helps us deal with the issue that the g_list convenience functions
don't allow us to easily compare 64bit values on 32bit architectures. And
since these convenience functions are truly trivial in nature, it seemed
easier to simply implement our own logic here.

In the process I moved all the dive_trip_list helper functions into the
same spot in divelist.c

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-20 13:00:26 -04:00
Linus Torvalds
d66d376d20 Fix the incorrect data type for DIVE_DATE accesses
This is the same bugfix that Lubomir did in the master branch, but now
on top of the new 64-bit timestamp_t model.  So now we also remove the
comment about the year 2038 problem, because it's not true any more.  We
do all the date handling in a 64-bit integer.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-09-19 21:44:54 -07:00
Dirk Hohndel
c804c4e02e Partial rewrite of the dive trip code
This introduces a new data structure for dive trips - reuseing the struct
dive just got way too messy.

The dive_trip_t datastructure now allows the code to remember if the trip
was auto generated or if its time stamp changed when dives where added to
the trip during auto generation.

The algorithm also distinguishes between dives that were intentionally
added to a trip (either in an XML file or by adding them to trip in the
UI) and dives that were added to trips via autogen. Saving dives that were
added to trips via autogen makes that assignment "intentional".

With this partial rewrite several of the oddities of the old code should
be resolved - especially turning autogen on and off again should get the
divelist back to the previous stage.

Also, when dives are merged during file open or import we now try to pick
the correct tripflag (instead of just ignoring the tripflag completely and
resetting it to TF_NONE by mistake).

Finally, the dive trip debugging code got more verbose and is trying
harder to detect issues at the earliest time possible.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-19 23:49:56 -04:00
Linus Torvalds
dce08deb34 Use a 64-bit 'timestamp_t' for all timestamps, rather than 'time_t'
This makes the time type unambiguous, and we can use G_TYPE_INT64 for it
in the divelist too.

It also implements a portable (and thread-safe) "utc_mkdate()" function
that acts kind of like gmtime_r(), but using the 64-bit timestamp_t.  It
matches our original "utc_mktime()".

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-09-19 17:35:52 -07:00
Lubomir I. Ivanov
bf83aa2104 Check if trip is NULL before calling DIVE_TRIP
Other places have this check, but for this particular one a crash
can be reproduced:

./subsurface ./dives/*
log -> autogroup
log -> autogroup

Against d14932058f

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-19 14:07:14 -04:00
Dirk Hohndel
d14932058f Fix some of the problems reported by cppcheck
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>
2012-09-18 20:25:45 -04:00
Dirk Hohndel
f73e5b7268 When deleting dives make sure that amount_selected stays consistent
This could cause a crash if deleting the last dive and manually adding a
new one.

Reported-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-18 19:37:03 -04:00
Dirk Hohndel
744b4e0c1c Prevent dive_from_path from dereferencing invalid iter
This fixes a bug that Lubomir reported in a different way from the patch
that he providede; I believe this to be more generic.

Reported-by: "Lubomir I. Ivanov" <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-18 19:13:59 -04:00
Dirk Hohndel
63c36e5e11 Mark divelist changed when modifying trips
This is just fixing an embarrassing oversight. Now we should prompt the
user about saving the file whenever something changes.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-13 11:45:21 -07:00
Lubomir I. Ivanov
0fceb1c907 Better compatibility with older GTK and Cairo
divelist.c:
Replaced "gtk_tree_path_get_indices_with_depth()" with the coupled alternative:
	int depth = gtk_tree_path_get_depth(path);
	int *indices = gtk_tree_path_get_indices(path);
for compatibility GTK+ < 2.22

*:
Replaced all usage of "cairo_rectangle_int_t" with "cairo_rectangle_t"
for compatibility with Cairo < 1.10.

Both modification make building Subsurface possible on a fairly recent Debian
distribution, which reports to have the version of the abovementioned
libraries "up-to-date", yet they are slightly outdated.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-11 07:59:53 -07:00
Dirk Hohndel
38d49bf041 Improve trip assignment for new dives
When first trying to deal with this I opted to go with a two pass appoach
which seemed easy as it used existing infrastructure, but turned out to
run into a couple of odd corner cases that would have been really ugly to
deal with.

So I threw this code away and am instead doing this in a single pass,
carefully checking as we go if there is an appropriate trip we can use.
To me the new code is much easier to read and seems much cleaner.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-10 11:04:58 -07:00
Dirk Hohndel
d0867a79d4 Implement delete dive option
With this we can delete a dive from the context menu.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-07 13:09:29 -07:00
Dirk Hohndel
42bff28e47 Make "create trip above" also add on selected dives
This makes things more consistent with the merge with trip above option -
if multiple dives are selected then the consecutive set of selected top
level dives below the dive on which a user right-clicked are all added to
the newly created trip.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-07 10:58:36 -07:00
Dirk Hohndel
b49b081bb9 Handle new dives correctly if trips exist
There is an interesting issue when adding new dives into a dive list with
existing trips. Since fill_dive_list walks the list backwards and trips
are determined by the timestamp of the first dive in a trip, it is
non-trivial to know when a dive is added if it should be part of an
existing trip or not. Let's say when we see the dive we can also see a
trip entry that starts four days earlier. Without looking forward in the
list of dives we cannot tell if this is a multi-day trip that this dive
would fit into, or if there is a break of more than tree days (our current
trip threshold).

Instead this commit adds a second scan of the dives in chronological order
that does the right thing for new dives.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-07 10:12:31 -07:00
Dirk Hohndel
6ddf0e1d22 Merge one or more dives with the trip above
Yet another trip manipulation function. The dive we are on (or that dive
and the selected dives below it) are merged into the trip directly above.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-06 12:43:57 -07:00
Dirk Hohndel
4679f4fbbc Avoid duplicate dive_trip entries
When inserting a trip into the dive_trip_list we already check for
duplicate trips, but we still kept the additional dive_trip around.

With this change we instead replace it with the existing one.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-05 13:54:22 -07:00
Dirk Hohndel
6d0af91398 More trip manipulations: remove selected dives from trip
There are a few obvious trip manipulations on multiple dives that haven't
been implemented, yet. This commit handles the case when we have multiple
dives selected and right click on one of them. It now removes all of those
dives from their trips (instead of just the one that we clicked on).

Still todo is the inverse operation. Select a group of consecutive dives
and turn them into a trip.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-05 13:31:56 -07:00
Dirk Hohndel
b9d74580d0 Add ability to merge trip with trip below
Miika suggested this - we should be able to merge with the trip below and
not just the trip above (oh, and call them "above/below" instead of
"previous").

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-03 20:51:09 -07:00
Dirk Hohndel
70d254ab84 Use the infrastructure for moving dives in more places
Instead of using our generic helper function the code in
remove_from_trip_cb tried to implement the special case - and got it
wrong. This fixes yet another crash that Henrik found.

Reported-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-03 20:46:09 -07:00
Dirk Hohndel
1f252fedd1 Fix crash when removing the first dive of a trip
The update_trip_timestamp function can indeed get called with no children
present, just before that trip is then removed. So instead of adding
complicated special cases, this just bails out of the function.

Reported-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-03 10:30:48 -07:00
Dirk Hohndel
f4f5536bad Fix copy_tree_node to no longer overwrite dive duration
Cut and paste error when creating this function.

Reported-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-03 08:09:45 -07:00
Dirk Hohndel
f6e8903a52 Add autogen menu command
This adds the ability to auto create trips from the menu. It's a toggle
entry (and while at it, we made the zoom toggle a toggle entry as well).
We can therfore switch back and forth between auto generated trips.

There is one bug. Assume you have no trips. You manually create a trip
from some dives out of a group of trips that autogen would turn into a
trip. Now you turn on autogen and this trip gets expanded with all the
dives that would normally be grouped together. If you turn off autogen
again, all those dives are still part of the remaining (initially manually
created) trip. Working around this issue seemed a lot more work than the
likelihood of anyone running into it seemed worth.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-02 21:50:43 -07:00
Dirk Hohndel
22ff8df880 Fix a crash when changing sort column
We were using the tree model to check the selection, even though the
active model is the list model after switching to a different sort column.

To make things clearer I renamed the access macros to be more consistent.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-02 21:46:48 -07:00
Dirk Hohndel
c3debc10fd Allow modification and edits of trips
Now that we can load and store trips we needed to add the capability to
manipulate those trips as well.

This commit allows us remove a dive from a trip via a right click
operation on the dive list.

The commit also adds code to split a trip into two, to merge two trips and
to create a new trip out of a top level dive.

To make all that useful this commit changes the right-click on the dive
list to identify and act on the record we are actually on (instead of
acting on the selection).

The right-click menu ("context menu") changes depending which divelist
entry the mouse pointer is on - so different operations are offered,
depending on where you are.

We also add simplistic editing of location and notes for a trip (but the
notes are never displayed so far).

To make our lives easier this commit adds a link from the dive to the dive
trip it is part of. This allowed to hugely simplify the auto trip
generation algorithm (among other things). The downside of this change is
that there are now three different ways in which we express the
relationship of dives and trips: in the dive_trip_list, in the tree_model,
and with these pointers.  Somehow this screams that I should rethink my
data structures...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-01 21:29:05 -07:00
Dirk Hohndel
a5f894d1d3 Clean up macros and auxiliary functions
In preparation for the next stage of the trips handling this commit makes
the macros used to access trips (and some frequently used variables for
the tree and list models) more consistent.

This also changes the way we display un-grouped dives in the dive list,
i.e. dives that are not part of a dive trip. Their dive number is now
printed bold.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-01 20:45:34 -07:00
Dirk Hohndel
ca16f438ac Store time_t as long value
The tree_storage only provided enough space for an int for DIVE_DATE. But
at least on 64bit Linux, an int is 32bit yet a time_t is 64bit. Until 2038
this only causes issues in some odd situations, after 2038 this would be
an obvious bug.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-01 20:41:03 -07:00
Dirk Hohndel
688ac57c7b Stop tracking the number of dives in a dive trip
Gtk tracks this for us as the number of children of the treeview node.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-08-29 22:01:06 -07:00
Linus Torvalds
c89f88378a Merge branch 'trips' of git://git.hohndel.org/subsurface
Merge the initial 'track trips explicitly' code from Dirk Hohndel.

Fix up trivial conflicts in save-xml.c due to the new 'is_attribute'
flag.

* 'trips' of git://git.hohndel.org/subsurface:
  Fix an issue with trips that have dives from multiple input files
  Some simple test dives for the trips code
  First cut of explicit trip tracking
2012-08-27 15:36:27 -07:00
Dirk Hohndel
9cf961249e Fix an issue with trips that have dives from multiple input files
The existing code didn't handle the case of different trips for the same
date coming from different sources. It also got confused if the first dive
processed (which is, chronologically, the last dive) happened to be a
"NOTRIP" dive.

This commit adds a bit of debugging infrastructure for the trip handling,
too.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-08-27 15:29:40 -07:00
Dirk Hohndel
e315abf645 First cut of explicit trip tracking
This code establishes the explicit trip data structures and loads and
saves them in the XML data. No attempts are made to edit / modify the
trips, yet.

Loading XML files without trip data creates the trips based on timing as
before. Saving out the same, unmodified data will create 'trip' entries in
the XML file with a 'number' that reflects the number of dives in that
trip. The trip tag also stores the beginning time of the first dive in the
trip and the location of the trip (which we display in the summary entries
in the UI).

The logic allows for dives that aren't part of a dive trip. All other
dives simply belong to the "previous" dive trip - i.e. the dive trip with
the latest start time that is earlier or equal to the start time of this
dive.

This logic significantly simplifies the tracking of trips compared to
other approaches that I have tried.

The automatic grouping into trips now is an option that defaults to off
(as it makes changes to the XML file - and people who don't want this
feature shouldn't have trips added to their XML files that they then need
to manually remove).

For now you have to select this option, then exit the program and start it
again. Still to do is to trigger the trip generation at run time.

We also need a way to mark dives as not part of trips and to allow options
to combine trips, split trips, edit trip location data, etc.

The code has only had some limited testing when opening multiple files.

The code is known to fail if a location name contains unquoted special
characters like an "'".

This commit also fixes a visual inconsistency in the preferences dialog
where the font selector button didn't have a frame around it that told you
what this option was about.

Inspired-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-08-27 14:32:24 -07:00
Linus Torvalds
666538ec77 Add helper 'for_each_dive()' dive iterator
It's an easy thing to do, but the for-loop ends up being pretty ugly, so
hide it behind the macro.

It would be even prettier with one of the (few) useful C99 features:
local for-loop variables.  However, gcc needs special command line
options, and other compilers may not do it at all. So instead of doing

   #define for_each_dive(_x) \
      for (int _i = 0; ((_x) = get_dive(_i)) != NULL; _i++)

we require that the user declare the index iterator too, and the use
syntax becomes

   for_each_dive(idx, dive) {
	... use idx/dive here ...
   }

And hey, maybe somebody actually will want to use the index, so maybe
that's not all bad.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-08-21 15:51:34 -07:00
Linus Torvalds
e46688d694 Fix single-dive editing oddity
The multi-dive case does fine, but the single-dive case (used when
adding a dive, for example) was somewhat confused between the dive index
(which is the location in the dive array) and the dive number.

Fix this by just passing the dive pointer instead (where NULL means to
use the current dive selection).

Reported-by: Jacco van Koll <jacco.van.koll@gmail.com>
Root-caused-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-08-21 15:37:38 -07:00
Linus Torvalds
5726a50d89 Improve group selection semantics
Now that the last commit tried to avoid changing the child selections if
the selected group partially matched, we should always [un]select all
children when we actually decide to change something.

Before, it would try to minimize selection damage by stopping
[un]selecting when it hit a child that already matched the selection,
but since we minimize damage differently, the all-or-nothing approach is
better, and gets us sane behavior when the group is collapsed.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-08-20 06:45:56 -07:00
Linus Torvalds
5322b4aac1 Avoid changing selection status when collapsing/expanding groups
This tries to avoid the problem mentioned in commit972669d6363c ("Rework
dive selection logic"), where a selection of dives hidden by collapsing
the group gets forgotten about by gtk.  It does so by always marking the
group selected when it is collapsed with any selected children.

We also avoid selecting new children when a group is selected that
already has at least *some* children selected already.  This way we do
minimal damage to existing selections when working with dive group
selections.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-08-20 06:27:04 -07:00
Linus Torvalds
972669d636 Rework dive selection logic
This completely changes how we keep track of selected dives: instead of
having an array listing the selection ("selectiontracker") or trusting
the gtk selection information, just save the information about whether a
dive is selected in the dive itself.

That makes it trivial to keep track of the state of selection across
group collapse/expand events, or when changing the tree view model.  It
also ends up simplifying the code and logic in other ways.

HOWEVER, it does currently (re-)introduce an annoying oddity with gtk:
if you collapse a dive trip that has individual selections, gtk will
forget those selections ("out of sight, out of mind"), and when you do
*new* selections, the old hidden ones remain.

So there's some games required to make gtk do sane things.  We may need
to either explicitly drop selections when collapsing trips, or make sure
the group entry gets selected when collapsing a group that has
selections in it. Or something.

There may be other issues introduced by this too.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-08-20 05:48:07 -07:00
Linus Torvalds
38f92f780a divelist: add 'Expand all' and 'Collapse all' menu items
This adds the ability to expand/collapse all the dive groupings in the
divelist from the divelist right-click context menu.

Should we perhaps add it to the top 'Dive' menu too?

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-08-18 20:06:04 -07:00
Linus Torvalds
c5be77093a Improve divelist group header information
This shows the number of dives in the grup in the divelist header field,
and also picks the location from the first dive that *had* a location,
so that if any dive in the group has a valid location, the group will
have a location.

It also makes double-clicking a dive group expand/collapse that group.

Requested-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-08-18 11:41:11 -07:00
Linus Torvalds
d2d4364afc Merge branch 'fixes' of git://git.hohndel.org/subsurface
Pull dive selection fixes from Dirk Hohndel.

This hopefully fixes the common cases.  Dirk is cursing gtk.  We may
need some gtk selection guru to explain things.

* 'fixes' of git://git.hohndel.org/subsurface:
  Another selection fix
  More fiddling with the selection
2012-08-17 16:14:20 -07:00
Dirk Hohndel
9e9ba73b3d Another selection fix
The corner cases are getting more and more artificial. Without this patch,
the following can happen:
Select one or more dives in an (expanded) dive trip. Now collapse that
trip with the little triangle. Select a different trip. The previously
selected dive(s) are still part of the selection (as you can see, for
example, in the statistics tab).

With this patch the scenario above works as intended (all the dives in the
new trip are selected), but we have another corner case:
Just as before, select one or more dives in an expanded dive trip.
Collapse that trip and ctrl-click on another trip. Now you lose the
originally selected dives.

Frankly, if you ctrl-click to add more dives to your selection - just
don't collapse the trips the dives are in?

As this new corner case seems even more artificial than the previous one,
I consider this patch an improvement. But fundamentally I am just battling
all the ways in which gtk's selection handling is messed up. When I get
the selection call back I cannot tell if this is a new selection or an
incremental selection (i.e., a shift-click or ctrl-click).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-08-17 15:08:50 -07:00
Dirk Hohndel
bc1ff9a121 More fiddling with the selection
As expected, this is pretty subtle to get right. But with this change the
code becomes simpler and more straight forward, I think. If the dives in a
group are collapsed, we don't even try to make gtk keep track of their
selection status - we explicitly do so ourselves. This avoids the
artificial expand / collapse around our attempt to force gtk to allow us
to select children that are hidden. But if a dive is expanded, then we
trust gtk to get things right.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-08-17 14:26:43 -07:00
Linus Torvalds
d0e27c6c53 Merge branch 'misc-fixes' of git://github.com/DataBeaver/subsurface
Pull miscellaneous fixes, mostly UI stuff from Mikko Rasa.

Both this and the pull from Pierre-Yves Chibon created a "Save As" menu
entry and logic.  As a result, there were a fair number of conflicts,
but I tried to make the end result somewhat reasonable.  I might have
missed some semantic conflict, though.

Series-acked-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>

* 'misc-fixes' of git://github.com/DataBeaver/subsurface:
  Add a separate "Save as" entry to the menu
  Changes to menu icons
  Improved depth info for dives without samples
  Divide the panes evenly in view_three
2012-08-17 10:57:24 -07:00
Linus Torvalds
6fdeeb8c9f Merge branch 'tree2' of git://git.hohndel.org/subsurface
Pull selection tracking fixes from Dirk Hohndel:
 "I just gave up on gtk tracking our selection.  Way too much pain.  The
  implementation below has seen some testing with the debugging code
  enabled and seems to work - but it needs more banging onto it, I'm
  sure.

  Ideally I'd like to leave the debug code in, ask people on the mailing
  list to play with it and report any inconsistencies.  After that I'll
  be happy to remove it again."

* 'tree2' of git://git.hohndel.org/subsurface:
  Stop relying on gtk to track which dives are selected
2012-08-16 20:39:49 -07:00
Dirk Hohndel
7cf0f6d5e1 Stop relying on gtk to track which dives are selected
We spend way too much effort trying to get gtk to manage the dives that
are selected. The straw that broke the camel's back is that gtk forces us
to expand any nodes that we want to select - so selecting a summary entry
for a dive trip forced us to expand all the dives in the dive trip. Which
as Linus pointed out really sucked from a user experience.

So instead we now completeley ignore gtk's weird idea of what is selected
and what isn't and simply track things ourselves. We still need to play
some games with gtk to make sure that the correct rows are SHOWN as
selected, but still, the overall code seems much cleaner.

This commit contains a bunch of debugging code that is ifdef'ed out -
this is extremely useful to make sure I didn't mess anything up, but
eventually I'll want to remove that again as it just looks ugly in the
code.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-08-16 16:47:49 -07:00
Dirk Hohndel
f6dfb0094c Fix right click edit in Dive Notes area for multiple dives
This fixes the bug that triggered the SIGSEGV that Linus worked around
earlier. I had forgotten to update this call path to the
edit_multi_dive_info function.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-08-16 12:51:32 -07:00
Linus Torvalds
9b72217f79 Merge branch 'tree2' of git://git.hohndel.org/subsurface
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
2012-08-16 10:46:30 -07:00
Linus Torvalds
91e7dcc555 Merge branch 'suit' of git://git.hohndel.org/subsurface
Pull exposure suit tracking from Dirk Hohndel.

* 'suit' of git://git.hohndel.org/subsurface:
  Add exposure protection tracking
2012-08-16 10:28:10 -07:00
Dirk Hohndel
e6ecddfa3d Switch from date based to dive trip based grouping
Linus HATED the date based grouping - too much wasted space visually
("three levels of grouping are way too much") and asked for dive trip
based grouping instead.

This is a quick change to do just that, with an assumption that no
dive in 3 days means it's a new trip.

This also changes the summary entry to display a location for the trip,
for now we pick the location of the (chronologically) first dive of the
trip.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-08-16 04:31:21 -07:00
Dirk Hohndel
621761233b Redo dive editing
This commit addresses two issues:

We now can add / edit / delete equipment from the edit dive dialog

We now can edit multiple dives at once

The latter feature has some interesting design constraints:
It picks the 'selected_dive' as the one to start the edit from - so if
this dive already has some information filled in, that information needs
to be overwritten before it is stored in all of the dives. Similarly, only
changes to the cylinders or weightsystems are recorded. Also, the notes
field is not editable in the multi dive edit mode (as that didn't seem
useful).

The workflow seems to work best if using the multi-edit right after
importing new dives from a dive computer. The user then can select all the
new dives and only needs to edit things like location, divemaster, buddy,
weights, etc. once.

This commit will create some obvious conflicts with the commit that adds
exposure protection tracking. It was implemented on top of the tree_view
changes as it reuses some of the infrastructure for tracking the selected
dives.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-08-15 15:32:36 -07:00
Dirk Hohndel
e8ec3df371 Add exposure protection tracking
For simplicity and shortness, throughout subsurface exposure protection is
simply referred to as "suit".

Add the fields to the data structures, add the column to the dive_list
and the preferences dialog (once again with it being turned invisible by
default). Support loading and saving of the suit information.

Display the suit information in the Dive Info pane (this may be a bit
controversial as people could argue this should be in the Equipment pane)
and allow editing of the suit info, with our usual support for completion
and drop down lists to pick from.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-08-14 17:16:00 -07:00
Lubomir I. Ivanov
307240d6f6 Fixed a small memory leak in divelist.c
In fill_one_dive(), cylinder and location strings are obtained via
get_string(), which needs to allocated a litte bit of memory.

After passing the two pointers ('cylinder' and 'location') as arguments
to gtk_list_store_set() it is safe to release them.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2012-08-14 14:51:35 -07:00
Dirk Hohndel
822b6409d7 Fix selecting and unselecting summary items
The dive list now seems to behave intuitively.

In order to do this we had to intercept the select function in addition to
having a selection-changed callback. That way we can simulate the
multi-level selection and unselection that was missing.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-08-14 13:22:31 -07:00
Dirk Hohndel
5ba89c13ac Apply sort functions to the correct model, don't select summary entries
We only set up the column specific sort functions for the default (tree)
model, which caused us to not sort correctly in the list model.

This commit also somewhat cleans up the handling of selecting summary
lines in the tree model, which includes the very first selection made at
program start (which happens to be the very last dive).

But it still doesn't work the way I expect it to work (i.e., the correct
row is not highlighted). Fundamentally I would prefer clicks on the
summary lines to instead select (or as ctrl-click, possibly deselect) all
the dives under that summary entry. Still TODO.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-08-14 12:43:16 -07:00
Dirk Hohndel
dc9d0e23e5 Maintain selected rows when switching between list model and tree model
We keep track of the DIVE_INDEX of all selected dives and simply re-select
those dives after changing model (date based sort or sort by other
column).

There are a few TODOs left. We lose the sort direction (ascending /
descending) when switching models. We also don't correctly deal with the
user selecting summary rows in the tree model.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-08-14 12:43:16 -07:00
Dirk Hohndel
27a505e579 Create duplicate list model so sorting by columns works again
One major downside of the switch to a tree model is that sorting by
columns other than date was broken - it would sort the entries within each
date which is not all that useful.

After playing with some Gtk trickery that would allow us to filter out
those rows it quickly became clear that the much easier solution is to
simply maintain TWO models (and therefore two storages). This causes some
overhead and requires some careful tracking of all changes, but it turned
out to be rather straight forward to do.

dive_list now has three model related members:
 model     - current model displayed (which is one of the following two)
 treemodel - the tree model
 listmodel - the list model

One side effect is that the callbacks no longer can pass the model around
(as this could have changed since the callback was registered), but that
seems only a minor drawback and was easily addressed.

The implementation in this commit still has a couple of obvious flaws:
when switching back from the list model to the tree model all the
expansion state of the rows is lost and we end up with just a list of the
different years visible. Also, selections aren't maintained when switching
models.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-08-14 12:43:15 -07:00
Dirk Hohndel
5f1e41de43 Improve tree model implementation
We now support three hierarchy levels: day, month, and year. Each
indicated by a negative DIVE_INDEX for -1 to -3. This allows a nice
compact overview when doing date based sorting (the default).

As indicated in the previous commit, things still go wrong with sorting by
other columns as the entries are only sorted within each day, not globally
across the whole dive list.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-08-14 12:42:54 -07:00
Dirk Hohndel
1f3813eb3d Allow date based grouping
This is the very first rough cut. It switches things over to a tree model
so we can have date based summary nodes.

It uses a DIVE_INDEX of -1 for summary nodes to easily tell them apart
from actual dives. All the data functions are changed so the summary
nodes only show the date they cover.

The commit also adds a couple of debug functions to be able to easily peek
into the model from the debugger.

Lots of things left to do. There is no longer a first dive selected when
starting subsurface. Sorting by columns other than date is messed up. We
almost certainly want month and year summary entries as well.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-08-13 13:04:56 -07:00
Dirk Hohndel
3c542b5a41 Don't print a total weight of 0 in the weight column
For consistency with the rest of the dive_list we should interpret "no
weight systems recorded" as "no information" and therefore print nothing
instead of printing a total weight of "0" for these dives.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-08-10 13:43:16 -07:00
Dirk Hohndel
19621bf481 Add total weight column to divelist
This adds the total weight carried on the dive in different weight systems
to the divelist. The column is by default not shown, which can be changed
in the preferences. The column is sortable.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-08-07 11:24:40 -07:00
Mikko Rasa
d8c8ada6c7 Changes to menu icons
It's customary for menu bars to not have icons.

Some items were lacking icons when there's perfectly good stock icons
available.  I was a bit torn between the "new" and "add" icons for the
"add dive" item, since what it really does is create a new dive, but
the "add" icon is an uninteresting sheet of paper in the default icon
theme so I decided to use the "add" icon.

Signed-off-by: Mikko Rasa <tdb@tdb.fi>
2012-07-31 21:12:21 +03:00
Linus Torvalds
162b36f4a5 Make it possible to do "Add Dive" from just the main dive menu
No need for right-clicks.  It's inconvenient on lots of laptops etc, so
allow just using the Dive menu as an alternative.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-06-27 18:09:26 -07:00
Linus Torvalds
e3bdfc2dc3 Rough "Add new dive" infrastructure in the divelist
Do a right-click to get a menu with the "Add dive" entry.  Should do
delete too, but that's for later.

What's also apparently for later is to make this *useful*.  It's the
butt-ugliest time entry field ever, and there's no way to set depth for
the dive either.  So this is more of a RFC than anything truly useful.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-06-27 13:11:54 -07:00
Miika Turkia
9933ccd7cf Show statistics of selected dives
If at least 2 dives are selected, show statistics of these dives on
Overall Stats. Otherwise, show the statistics of all dives. Temperature
is also added to the shown statistics.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>

Minor change to avoid adding statistics.h (moved the global variable and
external function declaration to display-gtk.h).
Another minor change to the text displayed for the "Stats" notebook page.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-03-16 12:12:19 -07:00
Dirk Hohndel
c544226334 Avoiding some potentially confusing name space clashes
We have local variables or function arguments with the same names as
function static variables (or in one case, function arguments).

While all the current code was correct, it could potentially cause
confusion when chasing bugs or reviewing patches. This should make things
clearer.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-01-05 08:55:18 -08:00
Henrik Brautaset Aronsen
16b6df559f Define O2 permille for air in one spot
Having the O2 permille defined once is more readable.

Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
2011-12-31 17:15:59 +01:00
Henrik Brautaset Aronsen
2175226580 Display OTU for dives using air
Zero o2 means 20.9% o2, which can be confusing...

Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
2011-12-31 17:00:36 +01:00
Linus Torvalds
11495bbb2b Use an ellipsis for Nitrox O2% ranges
The plain dash may look a bit too much like a trimix specification.  Is
the ellipsis better? Maybe.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-12-18 18:33:56 -08:00
Linus Torvalds
d3f1a30364 divelist: show/sort nitrox dive oxygen percentage as a range
If you are diving multiple nitrox cylinders, we now show them as a range
instead of just the max.  We'll still sort by max O2 (and for the same
max, by min O2).

So now with trimix dives, we'll show the bottom gas (we assume that
"highest He percentage" is that bottom gas), for nitrox dives we'll show
the range of Oxygen percentage, and for all-air dives we'll show just
"air".

For simple nitrox dives (only a single mix), we'll obviously show just
that single percentage.  This should hopefully conclude the whole "show
multiple cylinders in dive list" mess.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-12-12 09:20:22 -08:00
Linus Torvalds
51176cb089 Make the dive gas record the single highest mix
.. using the regular sorting rules: sort by Helium content first, Oxygen
content second.  Air always sorts last (even behind the theoretical
hypoxic Nitrox that nobody sane would use).

This is what Don Kinney implies would be the natural thing for a trimix
diver.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-12-11 21:28:18 -08:00
Linus Torvalds
8cca540444 Add capability of custom sorts to divelist columns
.. and use this for the nitrox column, which can now be more complex
than just a single number.

The rule for the "nitrox" column is now:

 - we look up the highest Oxygen and Helium mix for the dive

   (Note: we look them up independently, so if you have a EAN50 deco
   bottle, and a 20% Helium low-oxygen bottle for the deep portion, then
   we'll consider the dive to be a "50% Oxygen, 20% Helium" dive, even
   though you obviously never used that combination at the same time)

 - we sort by Helium first, Oxygen second.  So a dive with a 10% Helium
   mix is considered to be "stronger" than a 50% Nitrox mix.

 - If Helium is non-zero, we show "O2/He", otherwise we show just "O2"
   (or "air").  So "21/20" means "21% oxygen, 20% Helium", while "40"
   means "Ean 40".

 - I got rid of the decimals.  We save them, and you can see them in the
   dive equipment details, but for the dive list we just use rounded
   percentages.

Let's see how many bugs I introduced.  I don't actually have any trimix
dives, but I edited a few for (very limited) testing.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-12-11 14:38:58 -08:00
Linus Torvalds
4df81487fe Make sure to update divelist O2 information after editing
The divelist airmix display is kind of broken: it only looks at the
first cylinder, and it only looks at Oxygen content, not Helium.

But at least we can make sure to update it when somebody edits the
cylinder information, instead of leaving it extra broken.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-12-11 12:18:10 -08:00
Linus Torvalds
f078bc04e1 Make the cylinder table columns unsortable
They were never intended to be sortable, but using common code with the
dive list picked up that "sort by index" thing by mistake.

If we really want to be able to sort cylinders by O2 percentage (which
really doesn't seem to make much sense, considering that you usually
have just one or two cylinders) we will need to also handle the case of
editing the (differently sorted) cylinder table.  Which we don't do now.

Reported-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-12-11 11:40:17 -08:00
Miika Turkia
6131dbc74c Round the maximum depth on dive list
Round maximum depth on dive list to get consistent data between the dive
list and dive info.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-12-09 09:58:03 -08:00
Dirk Hohndel
52748412ff Fix some issues with star rating code
To waste less space in the tree view heading we simply put a star in the
heading instead of "Rating".

We now treat "zero stars" to mean "not rated" and don't store that value
in the XML file.

Rating is no longer a top level tag in the dive entry but instead a
property of the dive tag.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-12-07 20:49:22 -08:00
Dirk Hohndel
af290d5eb2 Add typical 0 to 5 star rating for dives
This works ok-ish, but doesn't allow us to click on the stars and edit
them in the divelist, which a user might expect to be able to do - in
most "star rating UIs" you simply click on the n-th star to set that
rating. Here you need to edit the dive and pick the rating from a drop
down menu.

Minor oddity: you can actually (if you force it) write anything you want
into the star rating. But anything that isn't one of the predefined
strings simply results in a zero star rating.

Overall the UI feels a bit... forced. But I think this is quite useful
anyway.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-12-07 15:11:06 -08:00
Dirk Hohndel
b577484998 Exclude surface intervals from sac rate calculation
We assume every sample with a depth of less than 10cm to be on the
surface.

This does not impact our interpolated pressures (one could assume that the
diver is not breathing from the regulator when on the surface - but
without air integration that's just an assumption).

It also doesn't change our tank pressure coloring by sac rate as that
always uses the momentary sac rate. Technically speaking this might impact
the actual colors printed (as those are relative to the total sac on the
dive which may go up due to this change).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-11-21 13:23:13 -08:00
Linus Torvalds
1efcf4538b Make double-clicking on the dive list bring up the dive editor
Now that the dive info window is read-only, we need to edit the dives
some other way.  We bring up a dive info edit dialog when you
double-click on the dive list entry for that dive.

I do want to have an "edit" button or keyboard shortcut or something
too, though.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-11-19 10:11:56 -05:00
Linus Torvalds
160745c545 Merge branch 'sacplot' of git://github.com/dirkhh/subsurface
* 'sacplot' of git://github.com/dirkhh/subsurface:
  Color pressure plot according to current SAC rate
  Fix minor coding standard issues introduced by my last commit
2011-11-17 18:38:46 -02:00
Linus Torvalds
1268e0d225 Show dives "latest-first" by default
You can still order them by date by just setting the sort order on the
date column, but normally you'd be more interested in the most recent
dives.

I tried to just scroll down to the last ones automatically instead, but
gtk makes that *really* hard to do.  If you do it in the natural place
for it, the scroll bar wll show up later and then cover up the last
entry anyway.  So you'd have to do some crazy expose event thing or
something.  Which may be the right thing to do eventually anyway, but
not worth the pain right now.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-11-16 16:30:34 -02:00
Linus Torvalds
7930567c27 Show more of the dive location in the dive list
Randomly picked up to 60 characters.  But maybe we should just get rid
of the limit entirely.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-11-16 16:29:38 -02:00
Dirk Hohndel
4891fa812f Fix minor coding standard issues introduced by my last commit
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-11-13 15:51:34 -02:00
Dirk Hohndel
97a1dd6830 Make sure SAC and OTU get recalculated after cylinder info was changed
Also fixed minor coding style issues (prevent useless code from being
executed).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-11-13 15:29:07 -02:00
Linus Torvalds
c32cff2c6b Fix up air use calculations for new pressure handling
Make sure that we calculate air use by using the proper start/end
pressures, with the manually set ones being used preferentially over any
possible sample data.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-11-09 08:16:49 -08:00
Dirk Hohndel
485b02937d Even more places with pressure and volume conversions
Amazing at how many spots we are re-implementing the wheel.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-11-01 21:34:06 -07:00
Dirk Hohndel
b26ca781b8 Use unit functions to get column headers, add unit function for pressure
Finally getting more consistent overall in how we convert between the
different units and how we decide which units to display.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-11-01 20:13:14 -07:00
Dirk Hohndel
a487f6c931 More consistency improvements
Treat SAC and OTU consistently:
- SAC is now a member of struct dive
- it's calculated / populated at the same time with a helper function with
  consistent API

Create get_volume_units function that returns volumes (e.g. used in SAC
rates) based on preferred units - make sure we have these conversions just
once in the code.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-11-01 19:58:19 -07:00
Dirk Hohndel
11b62a149b Disable sorting by dive number
This is based on Linus idea and code - just adding it to my UI branch in
case he didn't actually add it to his code...

It makes no sense to sort by dive number - every sane person will have
dive numbers be chronological; so they can sort by date instead.

But removing this option wastes less space and makes the dive list look
much better

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-10-23 14:38:33 -07:00
Dirk Hohndel
bf13c14d16 Make columns for temperature, cylinder, and nitrox optional
Just like SAC and OTU these can now be turned on and off through the
preferences.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-10-23 13:36:37 -07:00
Dirk Hohndel
b091916249 Show dive number in dive list
Make sure that renumbering the divelist correctly shows up on the display.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-10-23 09:09:00 -07:00
Dirk Hohndel
19a1693f58 Allow multiple selections in the dive list
At this point we don't do anything with this - the commit just provides
the infrastructure changes so that this becomes possible. Subsurface
behaves the same if exactly one dive is selected and simply keeps the last
selected dive if zero or more than one dives are selected.

The goal is to be able to select multiple dives and then do actions on
them. For example pick a tank used for all of them. Or edit the location
or (yet to be implemented) other equipment data like weight carried.
And also to be able to merge multiple dives.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-10-20 20:59:13 -07:00
Linus Torvalds
8d82c57e46 Split up generic code to generate a gtk tree view column
We used to do this just for the dive list, but the new cylinder view
will want to do a lot of the same boilerplate gtk stuff, so make it a
bit more generic and move it to gtk-gui.c.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-10-02 13:05:12 -07:00
Dirk Hohndel
0aad4d6094 Add preference option to chose if SAC and/or OTU should be in divelist
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-09-27 10:16:40 -07:00
Dirk Hohndel
dc2a0c1909 Make OTU column invisible by default
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-09-26 16:05:24 -07:00
Dirk Hohndel
d5c86ebe3d Add OTU to divelist
and change OTUs to be tracked as int, not double

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-09-22 16:29:49 -07:00
Dirk Hohndel
a93641b722 Calculate OTUs for every dive
The calculation assumes that the cylinderindex in each sample tells us
which PO2 the dive was breathing at that time. This needs to be verified
with dives where there is an actual gas switch.

No idea where to display them, yet. Far fewer people will care about this
than care about SAC - does this still rate a spot in the dive_list?
I guess I could make it part of the dive_info - but it's not editable.
It doesn't seem to fit with the equipment page (even though this is the
one editable field that is related - nitrox %)

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-09-22 16:26:38 -07:00
Dirk Hohndel
99859dad54 Minor change to the alignment of the divelist columns
Just seems to look nicer this way. And actually implements consistent
alignment management for the columns to begin with.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-09-22 12:25:44 -07:00
Linus Torvalds
50fd8191f9 Put the location last in the dive list
The whole auto-expansion of an entry in the middle thing really doesn't
work very well in gtk. Give up on it.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-22 11:02:28 -07:00
Linus Torvalds
4c113ee016 Put the default focus on the dive list at startup
This is some crazy stuff.  Apparently the only sane way to do this is by
hooking into the "realize" callback for the dive list widget.

Whatever. Dirk did the googling to figure this all out.

Suggested-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-22 10:28:57 -07:00
Linus Torvalds
68b666f50a Fix up some minor whitespace issues
Dirk clearly isn't as anal as I am about pretty whitespace.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-22 08:21:32 -07:00
Linus Torvalds
2df6149080 Select the first dive after filling the dive list
We should always strive to have a dive selected, so pick the first one
(that was how the dive list logic worked anyway, it just wasn't truly
selected at the tree-view level, so it wasn't *visibly* the selected
dive).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-22 08:19:34 -07:00
Linus Torvalds
e11523110b Make the dive list searching act on the location
It used to be "index 0" which originally was the date string, but not
only has that changed (it's now just the dive index), it's kind of
pointless to search for a date string.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-22 08:17:23 -07:00
Linus Torvalds
7f6d13f866 In divelist maxdepth column, only show depth unit
Show "m" or "ft" instead of "max/m" vs "max/ft".  The column really
doesn't want to be that wide.  The column header is already the widest
part of it even with this short name (due to the sort order arrow
thing).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-22 08:11:12 -07:00
Dirk Hohndel
f459c2ec22 Simplistic first attempt to get changes saved when quitting subsurface
Track whether things changed in the global dive_list

So far this actually works if changing dive info (but only if dive
selected was changed after the dive info was changed).

We are not tracking changes to the cylinder information, yet.

also remove the duplicate static dive_list

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-09-21 11:28:36 -07:00
Linus Torvalds
957aaf619f Fix up printing some more
Use the actual degree sign for temperatures (°F and °C), and make sure
everything uses the proper "set_source_rgb[a]()" wrappers to set the
colors.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-20 17:56:56 -07:00
Linus Torvalds
f627dde023 Fix divelist sorting
That was stupid.  The divelist column generation cleanup (commit
d3feb78df5: "Make helper function for creating TreeView columns in the
dive list") had a but too much copy-paste going on, and didn't always
have the right column indexes..  t still *looked* right, but sorting
didn't work at all.

Reported-by: Chris Lewis <chrislewis915@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-20 14:10:28 -07:00
Dirk Hohndel
682135838f Separate out the UI from the program logic
The following are UI toolkit specific:
gtk-gui.c   - overall layout, main window of the UI
divelist.c  - list of dives subsurface maintains
equipment.c - equipment / tank information for each dive
info.c      - detailed dive info
print.c     - printing

The rest is independent of the UI:
main.c i    - program frame
dive.c i    - creates and maintaines the internal dive list structure
libdivecomputer.c
uemis.c
parse-xml.c
save-xml.c  - interface with dive computers and the XML files
profile.c   - creates the data for the profile and draws it using cairo

This commit should contain NO functional changes, just moving code around
and a couple of minor abstractions.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-09-20 12:48:56 -07:00
Linus Torvalds
6ea5132463 Make the divelist font configurable
Instead of the hardcoding to "Sans 8", allow people to set it in the
preferences.

Also, make the unit choice be a frame in the preferences dialog instead.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-20 11:24:15 -07:00
Linus Torvalds
15e3b5f441 Merge branch 'for-linus' of git://github.com/dirkhh/subsurface
* 'for-linus' of git://github.com/dirkhh/subsurface:
  Attempt to get the location column to resize in a sensible way
  Minor tweaks to column headers

[ Fixed up minor semantic merge conflict due to the change to make
  'dive_list' internal to divelist.c ]
2011-09-20 10:09:56 -07:00
Linus Torvalds
9cf8d98711 Make 'struct DiveList' entirely internal to divelist.c
Passing it around is just annoying, and we only ever have one.  Let's
not burden all the users with the silly thing.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-20 10:06:24 -07:00
Dirk Hohndel
2db85596e5 Attempt to get the location column to resize in a sensible way
Previously the SAC column was the one that expanded which is silly

We also used to cut the location off at 16 characters

Now we try to make the location the one that expands and allow up to 40
characters, but there's something broken, still. If you manually shrink
the location column to its minimum size then subsequently resizing the
window gets the desired behavior. But if you don't manually resize the
location column it doesn't shrink correctly for windows that are smaller
than the space we need for all columns to fully display (instead we get a
horizontal scrollbar)

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-09-20 09:57:38 -07:00
Dirk Hohndel
43960a70a6 Minor tweaks to column headers
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-09-20 09:56:46 -07:00
Linus Torvalds
3a6c1f767d Reinstate the main window title
It got removed by some of my overly aggressive cleanup in commit
fefcbf125e ("Remove dive info frame") because the dive info frame
initialization also initialized the main window title..

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-19 22:09:47 -07:00
Linus Torvalds
d064044833 Hacky hard-coded font for dive list entries
This really is too wrong for words, but I do think the dive list may
look better with a smaller font.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-19 22:01:55 -07:00
Linus Torvalds
d3feb78df5 Make helper function for creating TreeView columns in the dive list
Let's not repeat the boiler-plate code more than necessary.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-19 21:39:15 -07:00
Linus Torvalds
61ebee05dc Add cylinder description to dive list
And I *really* would want to make the dive list be a ComboBox or
something like that, rather than a ListView.  I need to really
understand those things, though.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-19 20:06:54 -07:00
Linus Torvalds
9285d512db Turn the rest of the duplicate string fields to use render functions
So instead of having a depth field (in mm) for sorting, and the text
field that contains the same thing in text, we now have all the fields
we use in "native" format, and we just render them as text dynamically.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-19 19:13:36 -07:00
Linus Torvalds
2a45f6dbc3 Use renderer function for divelist depth field too
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-19 18:52:23 -07:00
Linus Torvalds
fa2a6fb763 Use a renderer function on the date field
Instead of creatign an extra column containing the date text, use a
renderer function to create the text dynamically.

Just the date right now, but we'll do them all this way.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-19 18:44:47 -07:00
Linus Torvalds
6279d743c4 Oops, fix typo. EAN, not EAD
Typo turned EAN (Enriched Air Nitrox) to EAD.  Which does mean something
too, just to confuse people - but while it's still nitrox-related, it's
entirely the wrong thing (Equivalent Air Depth).  I don't think anybody
would ever care to see *that*. With computers, why would you care?

Anyway, Dirk noticed it, and suggested I just use O2% instead.  It's not
like EAN is all that readable either.

Reported-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-19 16:58:46 -07:00
Linus Torvalds
87e8ff9c3e Update the divelist when dive info changes
This flushes the dive changes to the dive list, the way the old dive
info frame would update as you update dive fields.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-19 16:41:56 -07:00
Linus Torvalds
dfacb5e124 Add air usage calculations to dive list
Hey, now you can sort your dives by how good your SAC is.  Which sounds
more useful than it probably actually is.  But maybe you can see
patterns in what makes your SAC suck..

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-19 16:11:38 -07:00
Linus Torvalds
53ac61f235 Add location to divelist too
Sure, it's visible elsewhere, but this way you can search and sort for
it, and see several entries at once.  So again, having it visible in the
dive list is a good thing.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-19 15:52:42 -07:00
Linus Torvalds
7dca1cb78e Clean up divelist generation some more
.. and make the date string much more readable, now that we aren't
actually size-constrained any more.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-19 15:39:29 -07:00
Linus Torvalds
e9d2890134 Start filling in temperature and nitrox data in dive list
Still more to go, but it's slowly fleshing out..

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-19 13:32:10 -07:00
Linus Torvalds
de721d9810 Add temp/nitrox/sac entries to divelist
This doesn't really fill them, it just adds them to the possible
entries.  I'll get to it later.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-19 12:56:37 -07:00
Linus Torvalds
96005d20ea Make the divelist column naming clearer
Currently we use random hard-coded integers, and it's not always clear
what is going on.  Make it much more explicit with an enumeration of the
different divelist columns.

And change the column order to make it more logical, and make sure we
actually catch all uses while at it.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-19 12:25:16 -07:00
Linus Torvalds
7bbcf2fabd Update the dive units without destroyng and rebuilding the dive list
Just iterate over the dive list entries, updating them one by one.

This avoids the "selection destroyed" when the dive units are changed.
And it's cleaner anyway.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-07 12:05:44 -07:00