Redo the delete dive code

The existing code (both my first single dive delete and then Lubomir's
multi dive delete code) had way too many issues and was just painfully
inefficient.

This new code takes a radically different approach and mostly ignores the
Gtk tree model (as that gets recreated after a delete, anyway) and instead
is linear time on the number of dives in the list. It does do its best to
maintain the existing selection and the expand state of tree model (the
latter isn't possible if we have switched to the list model).

Many thanks to "Lubomir I. Ivanov" <neolit123@gmail.com> for his work on
this - this commit actually contains a few lines out of one of the patches
that he wrote.

Reported-by: "Lubomir I. Ivanov" <neolit123@gmail.com>
Tested-by: "Lubomir I. Ivanov" <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
close directory after reading entries

otherwise the filedescriptor keeps open which prevents a
smooth unmounting as long as subsurface is open

Signed-off-by: Martin Gysel <me@bearsh.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Clear the display widgets when deleting all dives in the list

After calling dive_list_update_dives() in delete_selected_dives_cb(),
if the selection length is zero, we can clear the display widgets
not to show information of a deleted dive.

[Dirk Hohndel: please watch your whitespace - you once again added a bunch
	       of empty lines that really didn't help the code...
	       I removed them]

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Set a default size to the "Edit Trip Info" window

Debian and Ubuntu's distributed Gtk decide to make the window
tiny (completely hiding the Notes section). To prevent that we "put"
a default size of 400x300px to the window, which is proportionally OK
compared to the main window's default size.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Correctly handle merging dives that are part of a trip

If we have already created a dive_trip structure we need to also copy the link.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Keep the "Add/Edit Cylinder & Weight" dialogs on top

This is the same issue as 882cb159a46d5d9dbd0 (although now we
don't have "Import XML Files" within a dialog). It applies when
in the "Dive info" dialog.

There is some sort of a GTK bug on Ubuntu 12.04 with GTK 2.24.10 that
prevents us from using the gtk_window_set_accept_focus() and similar
API to make the window behind fully inactive.

The proposed portable solution is to completely disable the background
window (NOTE: unless its the main window), disabling child controls
(gtk_widget_set_sensitive) and making the top window "transient for" or
putting it on top (gtk_window_set_transient_for).

Still we do not want to hide the background window titlebar with
gtk_window_set_decorated(), which makes it still clickable.
Make this change to older code in gtk-gui.c as well.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Merge branch 'delmulti' of git://github.com/neolit123/subsurface
Counting is hard

When updating the "You have usnaved change..." string I didn't pay
attention and missed the fact that we used it's hard coded length above to
allocate a large enough buffer.

Thanks you, Valgrind.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Fix a number of obvious memory leaks

Just the result of cppcheck and valgrind...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Better fix for one of the memory leaks

The return value of subsurface_get_conf is a const void * - so we shouldn't
just assign it to a variable where we know it will be changed. Instead we
duplicate the string and free the original one. A little less efficient but
cleaner.

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

Third attempt to get this trivial memory leak fix right.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
New XML format for saving dives

This patch makes the trips nest, and it also fixes the fact that you never
saved the trip notes (you could edit it, but saving would throw it away).

I did *not* change the indentation of the dives, so the trip stuff shows
up the the beginning of the line, at the same level as the <dive> and
<dives> thing. I think it's fairly readable xml, though, and we haven't
really had proper "indentation shows nesting" anyway, since the top-level
"<dives>" thing also didn't indent stuff inside of it.

Anyway, the way I wrote it, it still parses your old "INTRIP" stuff etc,
so as far as I know, it should happily read the old-style XML too. At
least it seemed to work with your xml file that already had the old-style
one (I haven't committed my divetrips, exactly because I didn't like the
new format).

It always saves in the new style, though.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Fixed some small memory leaks

Looks like a GtkEntryCompletion object created with
gtk_entry_completion_new() should be unreferenced after usage
(e.g. post gtk_entry_set_completion())

In info.c:get_combo_box_entry_text(), moved the free(..) line outside,
so that we can free regardless.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Add packaging files for MacOS

I couldn't figure out how the current packaging infrastructure was supposed to
work, but with not too much work I could get the more standard gtk-mac-bundler
to do what I wanted, so I added the support files needed for that and a little
README on how to use them.

The subsurface.sh and subsurface.bundle files are based on the launcher.sh
and gtk-demo.bundle files from the gtk-mac-bundler release which is under GPLv2.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Fixed memory leaks specific to divelist.c

move_dive_between_trips() always returns a pointer to a new
allocated memory block of size = GtkTreeIter. Lets free said memory
when no longer needed in the caller functions.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Destroy the divelist (tree) before calling gtk_main_quit()

Added new function dive_list_destroy() in divelist.c

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Fix memory leaks related to dive_trip->location

When creating a new dive_trip from a dive, we should probably
always copy the location via strdup(). However we then have to take
care of the de-allocation in divelist.c:delete_trip()
and gtk-gui.c:file_close().

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
fixup_dive(): move the add_* calls before a possible return

In dive.c:fixup_dive() it would be better to call functions
like add_people() and add_location() before the possible return
in the "if (end < 0)" branch.

This prevents a partial auto-complete list in "Dive Info"
combo boxes.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Fixed potential, rare corruption of unicode characters

In divelist.c:get_string(), when truncating the string to a maximum
of 60 characters (to be shown in the divelist), make sure we are
counting in guinchar (sizeof usually 2) instead of gchar (sizeof usually 1).
Use Glib functions such as g_utf8_strlen() and g_utf8_strncpy() to do that.

This patch fixes the potential problem when truncating a UTF-8 string
by calculating its length using strlen() in bytes.

For char = 1 byte, if the length returned by strlen() is an odd number
this means there is at least one single byte length character in there.

But also if the same string has a UTF-8 character at exactly the truncate
position minus x(probably 1) bytes, we are going to split the bytes
forming said UTF-8 char resulting in an incorrect string.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Rename Import XML File menu entry

Renamed to "Import XML File(s)", since we can import more than one file.

H

From 8f9b11d940d903316dcf4d023e327f365e4f4ccb Mon Sep 17 00:00:00 2001
From: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Date: Tue, 2 Oct 2012 11:38:56 +0200
Subject: [PATCH] Rename Import XML File menu entry

Renamed to "Import XML File(s)", since we can import more than one file.

Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>