Divide the panes evenly in view_three

There was a note by Linus that he doesn't know how to get the size, so
I'm fixing that.

Signed-off-by: Mikko Rasa <tdb@tdb.fi>
Improved depth info for dives without samples

This calculates a mean depth for the dive with a fixed ascent/descent
rate and an assumption that all of the bottom time is at the maximum
depth.  It's not much, but it allows some derived values such as SAC to
make more sense.

The depth profile for such dives is now also generated with the same
assumptions instead of putting the samples at fixed percentages of the
dive duration.

Signed-off-by: Mikko Rasa <tdb@tdb.fi>
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>
Add a separate "Save as" entry to the menu

The "Save" entry will now automatically save over the last used file.  If
no filename has been set, then that entry will also prompt the user for a
filename.

The filename is set when saving as well, so the next save will use the
same filename.

Signed-off-by: Mikko Rasa <tdb@tdb.fi>
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>
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>
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>
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>
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>
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>
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>
Fixed another memory leak

We need to free the string that gtk_tree_mode_get returns to us.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
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>
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>
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>
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
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
Avoid SIGSEGV when editing multiple dives

The multi-dive editing is broken if you right-click on the dive
text-fields (instead of the divelist).  This just avoids the SIGSEGV, it
doesn't really fix the editing.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
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>
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>