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>
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>
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>
Use truth values with gboolean

Just a little cosmetic oversight

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
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>
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>
Add the 'Print only selection' checkbox in the print options

With this commit, if few dives are selected by default it will
only print the selected dives but in the option panel there is
a checkbox that allows to print all dives and not only the
selection.

Signed-off-by: Pierre-Yves Chibon <pingou@pingoured.fr>
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>
Correctly initialize the toggle state of the autogroup menu entry

If we move to Linus' tri-state variable we need to separate those two
items, anyway. But for now this fixes the obvious bug.

Reported-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
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>
Correct the trip related test dives

They still had the old "date only" format, but the code now relies on date
and time being both set.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
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>
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>
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>
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>
Merge branch 'trip3' of git://git.hohndel.org/subsurface

Pull trip manipulation branch from Dirk Hohndel:
 "I have added yet more of the requested features.

  I am not aware of any outstanding bugs or crashes (except for the Gtk
  problem that causes the import to crash for some people on Ubuntu and
  MacOS - but as I mentioned earlier, that bug has been around as long
  as the import file selector box)."

* 'trip3' of git://git.hohndel.org/subsurface:
  Avoid duplicate dive_trip entries
  More trip manipulations: remove selected dives from trip
  Add ability to merge trip with trip below
  Use the infrastructure for moving dives in more places
  Correct the trip related test dives
  Fix crash when removing the first dive of a trip
  Correctly initialize the toggle state of the autogroup menu entry
  Fix copy_tree_node to no longer overwrite dive duration
  Add autogen menu command
  Fix a crash when changing sort column
  Use truth values with gboolean
  Allow modification and edits of trips
  Clean up macros and auxiliary functions
  Store time_t as long value
Merge branch 'print_selection' of http://ambre.pingoured.fr/cgit/subsurface

Pull print selection checkbox update from Pierre-Yves Chibon.

Instead of implicitly always printing selected dives if there are more
than one, this makes it print them if the checkbox is selected.

* 'print_selection' of http://ambre.pingoured.fr/cgit/subsurface:
  Add the 'Print only selection' checkbox in the print options