Keep the "OK" button in "Import" disabled until a DC is selected

Only call report_dives() for GTK_RESPONSE_ACCEPT in the same dialog.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
More cosmetic changes in the "Import" dialog

Renamed the XML button and titles slightly.
Generalized the dialog topmost text to "Choose what to import:".

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Make sure windows behind forward dialogs are truly inactive

There are possible bugs when targeting GTK 2.24.10.

When opening the "import XML files" file selector from the "import" dialog
on Ubuntu 12.04, even with gtk_window_set_accept_focus() setting FALSE
to the parent ("import"), it is still possible to click the title bar
and buttons, causing actions. This can trigger undefined behaviour -
e.g. opening multiple "import XML files" dialogs.

While on Windows the situation is more acceptable, on Ubuntu it is also
possible to click the [x] button on the title bar of the parent window,
which will close the parent dialog _with_ the current forward dialog.

Multiple proposed methods in the GTK documentation seem not to function
as expected, such as: gtk_window_set_modal() and gtk_window_set_accept_focus().
Passing the correct parent on dialog creation doesn't seems to help either.

The same problem occurs when selecting a default file from the preferences
dialog.

The proposed portable solution in this patch is to completely disable
the background windows by hiding the titlebar (gtk_window_set_decorated),
disabling child controls (gtk_widget_set_sensitive) and making the window
"transient for" or putting it on top (gtk_window_set_transient_for).

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Separate the "Import" menu entry into two menu entries in "File" and "Log"

New entries with icons and shortcut keys in the menus.

"Import XML File" is now using CTRL + I.
Reserve CTRL + E for "Export XML File" if possible.

"Download From Dive Computer" is using CTRL + D and
a GTK_STOCK_GO_DOWN icon.
Added separator below this entry in the "Log" menu.

Note: menu entry callbacks are NULL at this stage.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Remove the XML file selection from the DC download dialog

Renamed "import_dialog" to "download_dialog" and also focused the download
dialog strictly on dive computer functionality. Removed the file button
and "filenames" checks from "download_dialog".

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Activate the new separate "Import XML File" functionality

Renamed the function pick_import_files() to import_files()
and added a declaration in "display-gtk.h". The declaration is "extern"
for consistency with download_dialog().

Since the new dialog is a real child off "main_window", we no longer need
some of the calls to gtk_widget_set_sensitive(), gtk_window_set_decorated()
to disable the parent, which previously was the old "Import" combined dialog.

Once the file list is retrieved, attempt to import each file and update
the list via report_dives().

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>

Minor changes to file select box title

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Fix missing save of (almost empty) cylinder information

If we have no explicit cylinder info at all (it's normal air, no size or
working pressure information, and no beginning/end pressure information),
we don't save the cylinders in question because that would be redundant.

Such non-saved cylinders may still show up in the equipment list because
there may be implicit mention of them elsewhere, notably due to sample
data, so not saving them is the right thing to do - there is nothing to
save.

However, we missed one case: if there were other cylinders that *did* have
explicit information in it following such an uninteresting cylinder, we do
need to save the cylinder information for the useless case - if only in
order to be able to save the non-useless information for subsequent
cylinders.

This patch does that. Now, if you had an air-filled cylinder with no
information as your first cylinder, and a 51% nitrox as your second one,
it will save that information as

  <cylinder />
  <cylinder o2='51.0%' />

rather than dropping the cylinder information entirely.

This bug has been there for a long time, and was hidden by the fact that
normally you'd fill in cylinder descriptions etc after importing new
dives. It also used to be that we saved the cylinder beginning/end
pressure even if that was generated from the sample data, so if you
imported from a air-integrated computer and had samples for that cylinder,
we used to save it even though it was technically redundant.

We stopped saving redundant air sample information in commit 0089dd8819b7
("Don't save cylinder start/end pressures unless set by hand").

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Removed start and end in save_cylinder_info(). These two variables are no
longer used.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Added different delete label when right clicking multiple drives

When clicking multiple dives in the list, check if more than one
are selected and if so show the text "Delete dives".

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Added the functionality to delete selected (multiple) dives

Moved portion of the code from delete_dive_cb() to a function called
delete_single_dive(), that directly accepts a GtkTreeIter pointer.

Added the function delete_selected_dives_cb(), which is called
when calling "Delete dives" from the combo box for the selected dives.

The above function iterates trought the selection calling
delete_selected_foreach(), which on its own calls delete_single_dive().

The "for-each" API in this case looks much prettier C code wise,
however we do potentially create an extra jump and also
do not have anything but the redirection:
delete_selected_foreach() -> delete_single_dive()

Probably slighly slower than using gtk_tree_selection_get_selected_rows(),
performance wise, but less C code.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Make sure memory for default_dive_computer_device is allocated

When calling gtk-gui.c:set_default_dive_computer_device(), first
free memory at default_dive_computer_device and then use strdup().

This fixed a case, where after selecting a device for the first time
in the "Download" dialog, then pressing "OK" followed by "Cancel"
(after a device error) the device text is garbled the next time the
dialog is opened.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Use the name "Subsurface" in the "About" dialog

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Prevent a warning when showing the "About" dialog

gtk-gui.c:about_dialog():
Before assigning a pixel buffer to "logo" check if "image"
has a GTK_IMAGE_PIXBUF storage type.

Prevents the following message if the icon file is missing:
Gtk-CRITICAL **: gtk_image_get_pixbuf: assertion

The message that the file is missing is still shown.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Update the trip's "when" flag after deleting a dive from it

Both gtk_tree_selection_selected_foreach() and
gtk_tree_selection_get_selected_rows() are problematic.

gtk_tree_selection_get_selected_rows is not compatible with older GTK,
while gtk_tree_selection_selected_foreach() should not be used to
modify the tree. A workaround to is allocate memory and store what
is returned from the gtk_tree_selection_selected_foreach() callback
function as a GtkTreeIter array. Once done iterate trought the array
and pass the values to delete_single_dive().

A bit excesive, but it is not certain how safe is modifying the tree
while in the "_foreach" loop, even if it only shows a warning.

On the other hand the GTK source shows gtk_tree_selection_get_selected_rows()
to be a rather complicated and slow method.

Inside delete_single_dive(), once a dive is no longer part of "dive_table"
and if the dive was part of a trip, remove the dive from the tree
(gtk_tree_store_remove()) and call update_trip_timestamp().

The struct type "tree_selected_st" and tree_selected_foreach() are
reusable.

Reported-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Update cylinder info properly

The "cylinders_equal()/copy_cylinders()" functions were buggered, and
only checked (and copied) the cylinder type.  That was on purpose, since
you do want to be able to change the type of a cylinder without changing
the gasmix of the cylinder.

HOWEVER, the reverse is also true: you may want to change the gasmix of
a cylinder without changing the type.

So it's not that the type of the cylinder is special - it's that the
type and the gasmix should be considered separately.

Do that properly for the equipment editing case.

Reported-by: Ďoďo <dodo.sk@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Merge branch 'delmulti' of github.com:neolit123/subsurface

This brings in Lubomir's latest version of the code. This allows deleting
multiple selected dives from the divelist.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Add the ability to create a log file for debugging output

Especially when asking non-developers for help debugging a problem it can
be extremely useful to have debugging output not go to the console but to
a log file instead.

This just adds the infrastructure to create (and close) such a file. No
changes to the debug output are made.

All this is of course #ifdef'ed out.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
First implementation of native Uemis downloader

This includes one major hack that uses a private data structure from
libdivecomputer to allow us to show the Uemis Zurich as one computer the
user can import from.

Once the user has chosen the Uemis we don't use libdivecomputer but our
own downloader. Just like in the libdicecomputer case this runs in its own
thread and updates the import dialog with progress information.

The code also keeps track of the last dive that has been downloaded from a
Uemis computer so we only import new dives on subsequent downloads. And
since the Uemis Zurich gives us its device id, we make this a "per
divecomputer" property for people who dive with multiple Uemis Zurich
computers.

This uses the debugfile infrastructure to allow easily collecting
debugging output - especially on Windows where by default console output
is lost.

Known limitations: when the Uemis runs out of space (it uses its
filesystem for communication with the host computer) we have no graceful
way to reset things. This is why the code doesn't try to download ALL
dives on the computer but instead download them in increments of ten
dives. This clearly needs to be addressed once I understand how to reset
the device.

The Cancel button of the import dialog isn't correctly hooked up, yet.
I still need to figure out how to gracefully shut down a download without
potentially hanging the device.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Fix stupid packing error on Windows

I guess no one has ever tried to import Uemis dive data under Windows.

The glib-2 libraries for Windows (at least the ones that are part of the
mingw package, but my guess is this is true for all of them), force the
whole program to be compiled with Windows packing rules for structures.
That broke the structure we use for decoding Uemis binary data.

This commit changes the data structure to no longer use unaligned 16bit
values but instead two 8bit values and assemble them in the actual code.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Merge branch 'uemis-native'

This brings in the code to download dive information directly from a Uemis
Zurich dive computer.

The implementation contains a major hack that hooks the uemis code into
the same data structures used to setup libdivecomputer. This gives the
best result for the user, but is not something that I like as a long term
solution as it relies on internal libdivecomputer data structures.
Much improved handling of out of memory errors in the Uemis downloader

Instead of trying to figure out in the GUI code whether to call the
downloader again, the logic was moved into the downloader itself. It now
attempts to deal cleverly with running out of space on the dive computer
filesystem - and in return is able to process the maximum number of dives
(instead of just ten or so at a time).

Even on partial reads before a failure we are able to collect the data
that was completely transferred and report those dives.

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