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
I did a global search-and-replace to make all "time_t" users use the
internal subsurface 64-bit "timestamp_t" type instead, but we have one
case that still uses the system time functions: the use of "localtime()"
in the dive_time_widget().
Everywhere else we always just use UTC for all our time handling, and we
don't really ever care about the local timezone etc. However, for the
dive time widget, we initialize the calendar widget to the current time,
which obviously does want to take the local timezone into account, so
there we end up using the whole system time handling code.
So that one should continue to use time_t, even if it might have the
year-2038 problem. We also don't care about the fact that it's not
thread-safe, since this is just initializing the widget which definitely
doesn't happen threaded.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
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>
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>
Related to subsurface_default_filename() and g_path_get_basename().
Against 3835faa8fb.
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
By now the default file code seems quite matured, so in preparation for
2.0 we'll bring it back into master.
I made a few small clean-ups during the merge, but the merge itself is
very much straight forward.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This seems to make sense since we have a pretty strong concept of the "active
file" that we are working on.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Calling edit from the context menu creates a combined editing widget that
contains both dive info and equipment. When editing cylinders or
weightsystems from that widget and confirming those edits with OK those
changes were already committed to the current_dive - regardless on which
dive the user clicked. Worse, even when the user clicked Cancel in the
edit widget, any changes to the equipment stayed in effect.
This had especially confusing consequences when editing multiple dives.
As a workaround this commit adds a global edit_dive variable. This fake
dive is edited by the secondary editing widgets and if the user accepts
changes with OK then they are copied over to the current dive (or all
selected dives in multi dive editing mode).
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
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>
Pull a few buglet fixes from Mikko Rasa.
Some trivial conflicts due to changes in the dive selection logic, and
using the new "for_each_dive()" helper.
* git://git.tdb.fi/ext/subsurface:
Check if multi-dive editing is actually needed
Fix an off-by-one error in buffer allocation
The previous commit was a patch from Lubomir, which also had some
whitespace fixes (to go with some new whitespace bugs to replace them)
in it.
I removed the whitespace changes from that patch (don't mix whitespace
fixes with other fixes, unless they are on the same lines!) but decided
to look for other whitespace issues, and this is the result.
I left the non-C files alone, some of the spec and script files also
have whitespace at the end of lines etc.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
When figuring out which cylinders to change in a multi-dive edit, we
already ignored the beginning and end pressures. But it turns out to make
more sense to also ignore the Nitrox / Helium settings.
Imagine you do a number of dives - for some reason your dive computer
records the wrong cylinder size in the downloaded logfile (like my uemis
does all the time). Dives will likely have different Nitrox percentage,
but you should still be able to simply fix the cylinder size for all dives
at once.
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
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>
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>
Context menu callbacks always invoke edit_multi_dive_info(-1) instead of
edit_dive_info. Since -1 means "all selected", it was impossible to edit
dive notes through the context menus. This commit makes the function
check if multiple dives are actually selected.
Signed-off-by: Mikko Rasa <tdb@tdb.fi>
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>
We now pick one hour after the end of the currently selected dive as the
default starting time for the new dive to be added. If multiple dives
(or no dives) are selected, we default to current time as before.
The "one hour after the end" is just a random (but not unreasonable)
assumption for the surface time if you add multiple dives.
Suggested-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
I lied in the commit message for commit 0468535524a3 ("When editing multiple
files, don't override existing equipment entries"); the changes there did
not parallel the logic for the string entries. Now I think it does.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
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
Linus' code dropped the const qualifier from the start rating. While
fixing this I stared some more at get_combo_box_entry_text and realized
that the existing code could potentially change the "old" pointer and then
pass it to free(). Tsk-tsk-tsk.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Commit 2f773b97e0 ("multi-dive editing: don't change already set data
for other dives") didn't get the multi-dive editing quite right: even if
one of the dives in the list of changed dives has an empty field, we
should *not* fill it with the edit data unless that edit data was
actually changed.
So compare the new data with the original master data, and if they
match, do nothing.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
When editing multiple dives at the same time, don't change fields that
have already been set for a dive, unless the old field contents match
the currently selected ("master") dive.
So when you edit multiple dives, you can set the dive master or buddy
(or suit etc) for all of them in one go, but if one of them already has
that field set, it won't be modified just because you set the other
ones.
Acked-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
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>
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>
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
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>
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>
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>
I still suspect that using spinbuttons for the time handling is the
wrong way, and I'm a bit surprised the Calendar widget doesn't have a
mode where you can see/set the time too.
But this makes things at least minimally prettier, and initializes the
time entries to the current time (which is obviously not what anybody
really wants, but looks a lot better than defaulting to "midnight" or
some other random time that *also* won't be what anybody actually
wants).
I think this might be something we can live with, although I hope
somebody with good taste comes along and say "don't use spinbuttons, do
this: xyzzy" and makes things look better yet.
Also, I have this suspicion that I should put the time/depth/duration
stuff to the right of the calendar. Most displays are wider than they
are tall, so tall and skinny dialogs are bad especially if you have
limited vertical pixels. I still have flashbacks to my netbook-using
days, hating applictions that did that.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Christ, if you look up "Ugly dialog" on Wikipedia, I think it has a
picture of this "New dive" thing. Or it should have.
But it kind of works. Although with only a "max depth" entry, you can't
currently set average depths etc, so SAC-rates etc cannot be calculated
for these kinds of dives.
And the dive numbering is wrong. We do auto-number new dives that get
added at the end, but we do it as we add them, so when you *edit* the
dive information (before it has been added) the dive number shows up as
"#0".
So there's certainly room for improvement here.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
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>
We used to not properly update the dive info until we switched to
another dive when we edited it. This should fix it.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This interface works the same way the "edit dive" menu item does: it's a
text entry meny item on the dive text entries (ie buddy/divemaster/notes
sections). Except you pick the "Delete" entry rather than the "Edit"
entry.
It kind of works, but it really is a pretty horrible interface. I'll
need to add a top-level dive menu entry for just deleting all selected
dives instead. And it would be good to be able to get a drop-down menu
from the divelist instead of having to do it from the dive text entries,
which is just insane.
But that requires gtk work. I'm not quite ready to get back into that.
Thus the "exact same insane interface as the explicit 'Edit' mode".
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
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>
Packing it next to the divemaster/buddy information may work great on a
big screen with lots of pixes, but it makes the minimum window size way
wide for a small screen. So don't do it.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Henrik Aronsen points out that we've not made it possible to edit the He
percentages for trimix diving. It's easy enough to do, I just didn't
have any dives that needed it myself. So here goes.
Reported-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
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>
This way, when you have a new dive that you just imported from your dive
computer, you can just double-click on the dive and fill out all the
relevant information: location, notes, buddies and cylinder info.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
It's pretty basic information, and might be hidden behind the dialog
especially on a small screen.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
It just pops up the dive info edit box. This way you can be in the dive
info tab, and not have to go to the dive list just to double-click on
the dive.
This thing still needs some polish, but it's now usable.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
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>
We always keep the focus on the dive list, so that the random gtk focus
handling doesn't suddenly randomly make us edit the combo boxes when the
cursor up/down keys start changing them instead of the dive list.
This means that dive location, notes and buddy/divemaster aren't
editable at all any more, but I'll fix that by making a separate dive
edit popup window.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Lubomir's solution to fill them with a newline doesn't work. Well, it
may work on some versions of gtk, but on mine it just results in an ugly
box for the control character '000a' that tries to show the newline.
So this is a third approach: if we reset the text to empty, first set it
to space (to clear it), and then set it to empty. That seems to work on
at least one version of gtk, and doesn't have the problem with the space
*remaining* when you cut-and-paste something into the combo box.
Let's see if it breaks anything else, but at worst it should be no worse
than the old "set it to space" approach - iow the combo box might
remember the space, but at least not some random data from the previous
dive that it happened to show.
Lovely gtk bugs.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Passing -1 to gtk_combo_box_set_active, seems not to work as the gtk
documentation explains; there might be a bug in the library or some
special case that is not explained.
could be related to:
http://mail.gnome.org/archives/gtk-devel-list/2004-March/msg00170.html
passing \n seems to "trick" the cell renderer to clear the entry
completely. This is a temporary solution.
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>