Commit graph

142 commits

Author SHA1 Message Date
Dirk Hohndel
78c5aa9f07 Change behavior for the existing filename
Previously we always picked the last file that was openend as the file
name to save to. That seems counterintuitive when importing files or when
opening multiple files. Especially if Subsurface was executed without a
file on the command line and we are using the default file.

Now we only remember a file name if it was the first one to ever be
openend or if it was used in save-as.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-10 12:27:00 -07:00
Dirk Hohndel
b73f29fea3 First cut of adding a default file name
The default file name is OS specific and tries to follow the customs on
each of the OSs. It can be configured through the preferences dialog.

On MacOS we get a strange warning which appears to be a well documented
Gtk bug on MacOS.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-09 17:38:01 -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
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
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
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
Dirk Hohndel
21fd73515f Ignore Nitrox/He seetings when editing cylinders for multiple dives
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>
2012-08-26 12:29:58 -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
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
Dirk Hohndel
c26c370c2b Correct multi-edit equipment update logic
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>
2012-08-18 08:28:52 -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
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
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
Dirk Hohndel
39f606350b Fill the list of weightsystems from data in existing dives
This was simply an omission in the current implementation. All the
plumbing was there but never got hooked up with the fixup_dive function as
intended.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-08-06 14:03:24 -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
Linus Torvalds
80b0c09733 Add a few more conversion helper functions to dive.h
Convert feet to mm, psi to mbar, and F to mkelvin.  We do this elsewhere
too, but I'm going to need it for the Cochran CSV files, so let's do the
helpers now.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-06-19 20:06:59 -07:00
Linus Torvalds
725e4582d9 Don't close config file when changing preferences
On Linux and MacOS the subsurface_close_conf() doesn't really close the
config file (it flushes writes on MacOS), but on Windows it does
actually close the registry hkey.

Which is bad, if you change the settings multiple times - we assume that
the config file is open the whole time.

So add a "subsurface_flush_conf()" function, and call *that* when
changing configuration parameters.  And call the close function only at
the very end.

Alternatively, maybe we should just open the config file separately
every time. I don't much care, maybe somebody else does.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-05-02 10:03:48 -07:00
Linus Torvalds
1cbe2444cc Add the ugliest 'delete dive' model ever
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>
2012-04-02 19:19:01 -07:00
Linus Torvalds
81fddfa67e Merge branch 'weight' of git://subsurface.hohndel.org/subsurface
Pull weight management from Dirk Hohndel:
 "This is the fifth or sixth version of this code, I'm begining to lose
  track.  I still struggle with the balance between code duplication and
  unnecessary indirectness and complexity.  Maybe I'm just not finding
  the right level of abstraction.  Maybe I'm just trying too hard.

  The code here is reasonably well tested.  Works for me :-)

  It can import DivingLog xml files with weight systems and correctly
  parses those.  It obviously can read and write weight systems in its
  own file format.  It adds a KG/lbs unit default (and correctly stores
  that).

  The thing I still worry about is the code in equipment.c.  You'll see
  that I tried to abstract things in a way that weight systems and
  cylinders share quite a bit of code - but there's more very similar
  code that isn't shared as my attempts to do so turned into ugly and
  hard to read code.  It always felt like trying to write C++ in C..."

* 'weight' of git://subsurface.hohndel.org/subsurface:
  Add weight system tracking

Fix up some trivial conflicts due to various renaming of globals and
simplification in function interfaces.
2012-03-23 21:07:53 -07:00
Dirk Hohndel
854bd0269c Add weight system tracking
- supports multiple weight systems per dive
- supports multiple weight system types
- supports import of weight as tracked by DivingLog

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-03-24 11:44:27 +09:00
Linus Torvalds
4d10bc017a Split up file reading from 'parse-xml.c' into 'file.c'
We're going to eventually import non-xml files too, so let's begin
splitting the logic up.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-01-26 13:00:45 -08:00
Dirk Hohndel
1d6903c65a Oddly, finishing a sample doesn't require a sample
So let's not pass it around

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-01-05 08:16:50 -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
Linus Torvalds
9b1ea2ae6d Use common helper function for the "no cylinder info" case
Miika fixed the statistics code that didn't properly check for the "no
cylinder info" case - this cleans it up and just uses the helper
function in equipment.c.

Rename the helper to be slightly better named while at it.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-12-09 09:52:59 -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
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
0089dd8819 Don't save cylinder start/end pressures unless set by hand
Keep the sample pressure start/end data separate from the overall
cylinder start/end data - and clean the overall cylinder start/end data
if it matches the samples exactly to avoid the redundancy.

This breaks all the SAC calculations etc, which expect the cylinder
pressures to always be in the cylinder data.  I'll fix that up
separately.

The reason for this is that we really want to keep the manually entered
data separate: the pressure plotting doesn't need the confusion, and
considers end-point data (with interpolation) very different from sample
data.  Also, we do not want to pollute the xml save-file with data that
is computed.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-11-09 08:13:17 -08:00
Miika Turkia
350462949d Use XSLT file to open JDiveLog logs
Open JDiveLog files by translating them to subsurface format using XSLT.
These files are identified by the name of the first element (JDiveLog)
and transform is applied to only these.

The XSLT feature is compiled in only if libxslt is installed. The
transformation files are installed globally in Linux under
/usr/share/subsurface/xslt. Windows and OSX still need appropriate Makefile
changes and testing.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-11-05 13:24:53 -07:00
Linus Torvalds
55352a051c Merge branch 'add-info-stats-page' of git://github.com/dirkhh/subsurface
* 'add-info-stats-page' of git://github.com/dirkhh/subsurface:
  Add Info & Stats page to the notebook
  Even more places with pressure and volume conversions
  Further cleanup of pressure and volume conversions
  Use unit functions to get column headers, add unit function for pressure
  More consistency improvements
  Add new helper function to get temperature and unit
2011-11-02 12:39:55 -07:00
Dirk Hohndel
619ab9e828 Add Info & Stats page to the notebook
This provides the relevant information for the currently selected dive
plus a bunch of statistics over all dives in the dive_table.

The visual design has lots of room for improvement
- right now the different fields change size
- it might be nice to have a more modern look for the entries
- the O2/He field is odd - for most divers the He value will
  always be 0, so maybe we should only show He if there's at least one
  dive that uses He? Also, we simply do a comma separated list of gases
  for all the tanks used

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-11-02 12:27:12 -07: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
5698057951 Further cleanup of pressure and volume conversions
I'm amazed at how many spots we were doing conversions - some of them
subtly different than others.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-11-01 21:00:46 -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
18b8247cb3 Add new helper function to get temperature and unit
Designed along the lines of get_depth_units - except we don't define a
specific number of digits to show.

Use this in the one spot we need it right now in profile.c

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-11-01 19:52:12 -07:00
Linus Torvalds
e4bfb65972 Fix 'init_ui()' so that it can change argc/argv
That's what gtk_init() does with gtk-specific arguments.  IOW, if you do
things like

   subsurface --g-fatal-warnings dives.xml

to get a real abort on gtk warnings, gtk_init needs to be able to
actually change argc/argv.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-11-01 17:09:15 -07:00
Dirk Hohndel
2101f37c1b Use Registry on Windows to store preferences
No change at all to non-Windows builds.

Everything seems to work with preferences - but only tested on Win7

Remaining issue: displaying an icon (or the logo in the About dialog)

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-10-28 18:46:53 -07:00
Dirk Hohndel
98efa0794a Add menu item and dialog to select which events to display
Right now they are displayed in one hbox which doesn't work if you have
many events - but the code itself works and correctly toggles the events
on and off.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-10-25 02:51:16 -07:00
Dirk Hohndel
5ca49b0460 Remember the event names as we encounter them
First step to being able to filter the events that we display in the
profile. We could (in theory) walk all the dives in the divelist when we
need this data, but it seems much more convenient to have them in an array
in one place.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-10-25 01:05:08 -07:00
Linus Torvalds
bbe7f06189 Add completions to the dive location, buddy and divemaster entries
This way you can just type the first few characters of a location you've
been to before, and it will show you a list of possible completions.
Same for buddies and divemasters (which take the completions from a list
of people you've used before).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-10-23 09:47:19 +03:00
Linus Torvalds
f9cb526c96 Add cylinder data to cylinder model as we record each dive
This way the cylinder model list will contain all the different
cylinders that we have ever seen, rather than only containing the models
that we have *edited*.

That makes it much more practical to add new dives with the same
cylinders that we've used before, because now those cylinders will show
up as cylinder models even if we haven't looked and edited the old dives
first.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-10-22 18:12:30 +03:00
Dirk Hohndel
dbdd42b31f Add XML file import back and treat open and import differently
Open (or adding a file name on the command line) means that this is just
one of the files that you consider part of your dive history. So dives
don't get automagically numbered and the dive_list is not considered
"changed" just because another file was opened.

Import (or adding a file on the command line after --import) means that
you are importing the content of this file to your dive history. So if the
imported file has un-numbered dives that are newer than everything else,
those get correctly renumbered. And importing marks the dive_list as
changed.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-10-05 13:36:17 -07:00
Linus Torvalds
d6c2236b8a Automatically renumber new dives when they are "obvious".
When importing (or reading xml from files) new dives, we now renumber
them based on preexisting dive data, *if* such re-numbering is obvious.

NOTE! In order to be "obvious", there can be no overlap between old and
new dives: all the new dives have to come at the end.  That's what
happens with a normal libdivecomputer import, since we cut the import
short when we find a preexisting dive.

But if any of the new dives overlap the old dives in any way, or already
have been numbered separately, the automatic renumbering is not done,
and you need to do a manual renumber.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-10-05 08:31:31 -07:00
Dirk Hohndel
c15f798a85 Remove the ability to 'Import' .SDA files
We can instead 'Open' these files as they are just bastardized XML files.

This gets us back to a more consistent point where 'Import' gets data
directly from the dive computer (and hopefully soon we will add the
ability to load a dive directly from a uemis SDA to libdivecomputer),
and 'Open' loads a file from the filesystem of the computer we are
running on (this last sentence phrased so awkwardly as the uemis Zurich
SDA is a computer and presents a file system when connected via USB - it
just doesn't have the dive data in an accessible format in that file
system).

As a bonus we get to throw away quite a bit of code (the uemis specific
file handling, mini-XML parser with helper functions, the file open dialog
in the importer). Yay!

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-10-03 08:34:56 -07:00
Linus Torvalds
2a8f7ab78f Merge branch 'otu-tracking-v2' of git://github.com/dirkhh/subsurface
* 'otu-tracking-v2' of git://github.com/dirkhh/subsurface:
  Make OTU column invisible by default
  Add OTU to divelist
  Calculate OTUs for every dive

Fix up trivial conflicts in dive.h (due to dive event handling also
adding a field to the dive structure)
2011-09-27 10:46:42 -07:00
Linus Torvalds
3a77eb8510 Start handling dive events
Parse them, save them, take them from libdivecomputer.

This doesn't merge them or show them in the profile yet, though.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-22 18:02:54 -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
Linus Torvalds
d94fb7ca6b Merge branch 'quit-handling' of git://github.com/dirkhh/subsurface
* 'quit-handling' of git://github.com/dirkhh/subsurface:
  Use the last (or only) filename on command line as default for saving
  Show the "save changes" dialog before the main window is destroyed
  Check for changes at regular 'quit' events as well
  Catch changes to the info of the current dive when quitting
  Tracking changes to tanks is trivial
  Simplistic first attempt to get changes saved when quitting subsurface
2011-09-21 12:28:20 -07:00
Linus Torvalds
515a917152 Add helper function for doing depth unit calculations
.. and use it for printing too.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-21 12:12:54 -07:00
Dirk Hohndel
a817f4b547 Use the last (or only) filename on command line as default for saving
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-09-21 11:35:20 -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
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
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
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
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
Dirk Hohndel
89fe2c723f Show tank / nitrox / air consumption information in the info_frame
Even though we go down to an 8pt font the info_frame changes size when the
air info is added. I don't like this but want to see how Linus would like
this resolved before going overboard.

Minor tweaks to the formating (we don't need two decimals when printing
the liters of air consumed).

This patch does NOT remove the plot of the air information in the profile
graph. I think we want to remove that once we like the text where it is,
but I wanted to do one thing at a time.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-09-16 15:45:14 -07:00
Linus Torvalds
5804c2970e Support gps coordinates for the location info
Sadly, no way to show them yet.  But it would be nice to let people
enter them (and it would be doubly nice to have a dive computer that
does it at the surface), and then perhaps just do the "point browser at
google maps" thing.

Saving/parsing tested by hand-feeding the location of Enenui (Molokini
Crater) from google maps by hand into my divelog.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-15 18:16:07 -07:00
Linus Torvalds
c6b13fad5a Add divemaster/buddy field and text entry
I have it in some of my notes, and Dirk seems to fill that in too, so
let's just show it, save it, and allow editing of it..

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-13 14:58:06 -07:00
Linus Torvalds
42f627b8b1 Libdivecomputer: start actually importing the dive data
So this actually reports the dive data that libdivecomputer generates.
It doesn't import special events etc, but neither do we for the xml
importer.

It is also slow as heck, since it doesn't try to do the "hey, I already
have this dive" logic and always imports everything, but the basics are
definitely there.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-12 13:25:05 -07:00
Linus Torvalds
aa416e3c96 Abstract out dive/sample allocation a bit
We're going to start to want to allocate dives and samples for the
libdivecomputer import too, so let's clean things up a bit for that.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-12 12:56:34 -07:00
Linus Torvalds
afffcdbc0d Avoid using type 'gasmix_t': use 'struct gasmix' instead
libdivecomputer already uses 'gasmix_t' for its own gasmix thing.  I
don't like th eway we step on each others name spaces, but hey, might as
well just use 'struct gasmix' and avoid the typedef.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-12 09:47:55 -07:00
Linus Torvalds
0c4e1697db Be more careful about unit changes
When we change units, we need to flush any currently active dive
information in the old units, and then carefully reload it in the new
units.

Otherwise crazy stuff happens - like having current cylinder working
pressure values that are in PSI because that *used* to be the output
unit, but then interpreting those values as BAR, because we changed the
units.

Also, since we now properly import working pressure from Diving Log,
stop importing the (useless) cylinder description.  The Diving Log
cylinder descriptions are things like "Alu" or "Steel".  We're better
off just making up our own.

Finally, since Diving Log has cylinder size in metric, make sure that we
do the "match standard cylinder sizes" *after* we've done all the
cylinder size conversions to proper units.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-11 15:49:50 -07:00
Linus Torvalds
1cc62d5811 Fix up dive number naming
Use "dive->number" instead of "dive->nr". And make the XML match too.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-11 15:49:17 -07:00
Linus Torvalds
6538e5bba0 Save and restore a "dive number"
Some people want to know how many dives they have under their belt, so
let's save and restore the dive number if it exists.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-11 11:36:33 -07:00
Linus Torvalds
88dc170af6 Declare 'update_dive()' properly
Avoid a compiler warning..

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-10 15:26:51 -07:00
Linus Torvalds
067506038a Rename 'cylinder.c' as 'equipment.c'
Make it about general equipment management, and start hooking up
functions to show new equipment information when changing dives (and to
flush changes to equipment information for the previously active dive).

Nothing is hooked up yet, and it's now showing just one (really big)
cylinder choice, so this is all broken.  But it should make it possible
to at least get somewhere some day.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-09 17:10:17 -07:00
Linus Torvalds
c4d5ebb069 Do output unit conversion in the dive info window too
This should take care of it all, unless I missed some case.

Now we should just save the default units somewhere, and I should do the
divelist update much cleaner (instead of re-doing the divelist entirely,
it should just repaint it - now we lose the highlited dive etc).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-07 09:35:45 -07:00
Linus Torvalds
05857e0a05 Start "output unit management" support
This doesn't actually *do* anything yet, but it introduces the notion of
output units, and allows you to pick metric or imperial.

Of course, since the output doesn't currently care, the units you pick
are irrelevant.  But just wait..

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-06 19:07:17 -07:00
Nathan Samson
11becb8750 Report errors when opening files
Signed-off-by: Nathan Samson <nathansamson@gmail.com>
2011-09-05 22:15:30 +02:00
Linus Torvalds
5f79a804b9 Sanitize and fix cylinder pressure overview
Doing per-dive cylinder start/end pressures is insane, when we can have
up to eight cylinders.  The cylinder start/end pressure cannot be per
dive, it needs to be per cylinder.

This makes the save format cleaner too, we have all the cylinder data in
just one place.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-05 09:12:54 -07:00
Linus Torvalds
e58fa7b9b5 Parse uemis cylinder data
This is some seriously crazy stuff.  Instead of making sense as a
divelog, the uemis xml makes more sense as a "dive computer settings
dump".

And I guess I can see why they'd do that.  But it makes parsing it just
incredibly annoying.  The thing is more of a "these are the
configurations I support as a dive computer thing" than a "this was the
tank you were diving with".

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-04 14:56:01 -07:00
Linus Torvalds
aab4d593bd Generate date string for the dive list dynamically
.. and sort based on the 'time_t' value itself.

This allows us to use a more compact date format that doesn't need to
sort alphabetically, because sorting by date is always based on the date
value.  So we can use just a two-digit year, and skip the seconds, to
keep the column narrow, while still sorting correctly.

Also, "Depth" is a nice header string, but it is wider than the column
itself, which makes the whole column wider than necessary.  So put the
units in the header instead of in the string, keeping things narrow.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-04 12:19:20 -07:00
Linus Torvalds
0917436729 Add placeholder for cylinder type description
So we don't want to save working pressure, but cylinder type knowledge
would be lovely and useful.  And we can probably make a good initial
guess, or at least let people fill it in later.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-04 11:34:50 -07:00
Linus Torvalds
b176daf6d6 Do better cylinder information management
Instead of just tracking gasmix, track the size and workng pressure of
the cylinder too.

And use "cylinder" instead of "tank" throughout.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-03 20:31:18 -07:00
Linus Torvalds
1e75ceac0d Add various dive fixups, and show pressure (if any) in the plot
Now the dive profile plot *really* needs some units.  The pressure is
just a random line otherwise.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-03 13:19:26 -07:00
Linus Torvalds
5f05173e79 Do a dive de-dup pass
If given multiple dives at the same time, just de-dup the dives.  This
happens when you've dumped the whole dive-computer several times, and
some dives show up in multiple dumps.

When de-duping, try to avoid dropping data.  So if one dive has notes
attached to it, and the other one does not, pick the notes from the dive
that does have them.  Obvious stuff like that.

The sample merge is also written so that it should be possible to merge
two dives. Which we don't actually do yet.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-02 16:40:28 -07:00
Linus Torvalds
22fcef2ec7 Save and parse notes and locations
It's pretty rough, but it seems to work.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-01 19:56:04 -07:00
Linus Torvalds
1155ad3f0f Add ability to 'save' dives
This just generates another xml file.  Don't get me wrong: I still don't
like xml, but this way we can save in the same format we load things
from.  Except the save-format is a *lot* cleaner than the abortion that
is Suunto or libdivecomputer xml.

Don't bother with some crazy xml library crap for saving. Just do it!

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-01 16:27:52 -07:00
Linus Torvalds
d5e42d485e gasmix: stop tracking nitrogen percentages
The only thing you can do with that thing is screw things up (like
libdivecomputer did).  There's no value in tracking the "filler" gas,
since you can always just calculate it from the gases that actually
matter.

So just track Oxygen and Helium - and make sure they have sane values.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-01 16:26:11 -07:00
Linus Torvalds
9741913124 Start parsing gas mixes
The suunto xml is just completely crazy.  What's the helium percentage
companion to "o2pct"? Would it be "hepct"? No. It's "hepct_0".

Ok, so they didn't number the first o2pct, which could be seen as sane:
that's the only mix value that should always exist.  And they clearly
started their indexing with 0.  So with multiple mixes, you'd then
expect "o2pct_1" and "hepct_1", right?

Wrong! Because XML people are crazy, the second O2 mix percentage is
obviously "o2pct_2".  So the O2 percentages are one-based, with an
implicit one.  But the He percentages are zero-based with an explicit
zero.  So the second mix is "o2pct_2" and "hepct_1".

I'd like to ask what drugs Suunto people are on, but hey, it's a Finnish
company.  No need to ask.  Vodka explains everything.  LOTS AND LOTS OF
VODKA.

In comparison, the libdivecomputer output is nice and sane, and uses a
'gasmix' node.  Of course, now we have so many different XML nesting
nodes to check that I just made it an array of different noces.  That
also allows me to mark the suunto case, so that we only do the "check
for crazy alcoholic xml entries" when it's a suunto file.

The "type of file" thing is probably a good idea for deciding on default
units too. Some day.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-01 13:32:52 -07:00
Linus Torvalds
00d798854a Start cleaning up dive accessors
I'm going to add a menu to import (and eventually export) dives, and so
we'd like to be able to start out with no dives at all.  Right now we
croak if that happens - it's not like the code has been written with
actual end users in mind.

So start cleaning things up.  First make the 'current_dive' macro work
right even for invalid dives.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-08-31 16:33:20 -07:00
Linus Torvalds
8e95ded57b Split up profile frame generation into its own file.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-08-31 10:20:46 -07:00
Linus Torvalds
3aa02ccba9 Generate a default name for a dive, if it doesn't have one already
The name is a string containint date, time, depth and length.  So it's
useful even with nothing else going on.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-08-30 20:54:43 -07:00
Linus Torvalds
5c4cc39c56 Start moving some of the non-parsing stuff out of 'parse.c'
Create a 'main.c' with the main routine and argument "parsing" etc.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-08-30 18:40:25 -07:00
Linus Torvalds
f3a338a9af Split up dive data structure declarations into 'dive.h'
The dive parser should eventually be just a part of the program, not the
whole thing. So start preparing for that.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-08-30 18:23:59 -07:00