Do not use default filename as default for "Save as"

This may sound counterintuitive but it actually makes sense.
If you have a default filename that's the name of you "normal working
file". If you want "Save as" something, that by definition is NOT your
normal working file but a subset or an experiment or something. And you
most definitely do NOT want to overwrite your default file with that.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
git save: don't crash if the last dive isn't in a trip

The git save tries to generate a nice commit message based on the most
recent dive, but stupidly didn't check whether that dive was in a trip
or not, and unconditionally used the trip pointer to see if there was a
trip location.

Which works well enough if you always generate trips, but is an
unmitigated disaster otherwise.  Oops.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Don't merge divecomputers if we know they are different

When merging dives, if we know for sure that the dive computers are
different, don't merge them into one (by interleaving the data), but
instead keep both as separate dive computers in the same dive.

This fixes a bug when due to a faulty download the same dive from two dive
computers looks quite different. They don't get merged automatically
(which is fine - they are quite different), but when manually merging
them, we of course want one dive with two dive computers, not one dive
with one merged dive computer.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Mark new dives "downloaded" when importing new dives

We used to do this just for dive computer downloads, but we should do it
for all imports, so that merging new import data always does the
expected thing: any new dive computers will be added to the end of the
list of preexisting dives, rather than the other way around.

(Of course, if you set the "prefer downloaded" flag, that reverses this
logic, and makes the newly imported dive computer data be the primary
dive computer.  That flag is currently only exported for dive computer
downloads, not for imports).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
git load: initialize dive computer timestamp and duration from dive

We don't save the dive computer timestamp and duration if they match the
dive timestamp and duration.  But that means that on loading, we need to
default the dive computer time/duration to the dive one.  If they
differ, the loading of the divecomputer file will then override the
default timestamp/duration.

This mainly matters if a later dive merge then changes the timestamp of
the dive: the dive computer timestamp needs to have been set correctly
and not change.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
git save: add list of dive computers to the commit message

This makes it much more obvious what is going on when you save in
between importing multiple dive computers, since the last dive
description otherwise stays the same.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Improve the tag widget to allow us to tab to the next field

If the last key that went in ended a tag and the next key is a tab -
deliver that to the TabWidget instead so we can navigate between input
fields.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Divecomputer download: try to offer only those devices that make sense

If the user selects a Uemis divecomputer, don't show serial devices.
If the user selects a serial divecomputer, don't show the Uemis
filesystem.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Download from dive computer: Fix the broken selection of devices

The old code was completely bogus - it's confused about what the variable
'i' is counting.

This also let's us select the Uemis mount point by default if that's the
only valid "device" that we found.

Compile tested on Windows, untested on Mac.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Change get_dive_by_diveid to get_dive_by_uniq_id

The original name was a really bad choice as we have a 'diveid' as part of
struct divecomputer - and that is not the diveid that is being used here.
Instead we use the 'id' member of struct dive which holds the "unique ID"
for this dive.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Assign the uniq dive ID the moment a dive is allocated

Previously we only did this when we did fixup_dive(), but that way we
can't reference dives "early" in their life cycle (e.g., right after they
got downloaded).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Fix selection after downloading dives from the dive computer

If we successfully download dives, the old selection should be cleared and
the one of the newly downloaded dives should be selected. I decided to
pick the last dive downloaded, which for most dive computers (but for
example not for the Uemis SDA) will be the first or earliest of the dives.

That seems much more intuitive than keeping the previous selection around.

Of course this is harder than it should be because of the way we track
selections and because we need a consistent dive list model in order to
change the selection.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Add new helper function that looks up the index of a dive by its uniq ID

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Make the code easier to read

This uses the new helper function from commit fc4f133f19d0 ("Add new
helper function that looks up the index of a dive by its uniq ID") to make
the logic implemented in commit 122593a63a46 ("Fix selection after
downloading dives from the dive computer") much saner to read.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Show the dive computer number (if a dive has more than one)

For most users this is no change at all. For the few who download from
multiple dive computers this now shows them which of them is the primary
dive computer.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Add ability to make a dive computer the first dive computer of a dive

If a dive has multiple dive computers we enable a special context menu
when the user right-clicks on the dive computer name AND is not already
showing the first dive computer. In that case we offer to make the
currently shown dive computer the first one.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Remove unused variables

These were leftover in commit 90638180d21a ("Use the used flag on
cylinders in get_dive_gas").

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Dive list: add context menu function to renumber dive(s)

No attempt is made to ensure that what the user does is sane. So this can
result in duplicate numbers, non-consecutive numbers, non-monotonous
numbers, whatever floats the users boat.

You can renumber a single dive or all selected dives (with a starting
number given that is applied to the oldest selected dive and then for each
newer selected dive that number is incremented by one).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Consistently use for_each_dive (and use it correctly)

The way the macro is written there is no need to test the dive against
NULL before dereferencing.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>