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>
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>
Implement Close menu option that allows closing the data file

This requires some helper routines that allow us to clear out all the
widgets.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Fix silly folder permission bug

I forgot to give the user execute permission on the folder that subsurface
might create to store the datafile in.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Change the definition of "dive table changed"

We only ask to save changes if the dive table was changed. Yet we didn't
consider the dive table changed if it was initially empty. So starting
with an empty file and making changes we were quitting without saving.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Use glibio functions for mkdir

Suggested-by: Jef Driesen <jefdriesen@telenet.be>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Inline g_list_free_full for better compatibility

Replaced g_list_free_full with the inlined alternave:
g_list_foreach(dive_trip_list, (GFunc)free, NULL);
g_list_free(dive_trip_list);

once again my version on debian 6.0.x has libraries up-to-date yet outdated.
i guess i have to suggest against API which has the "Since <some ver>"
text and <some ver> is fairly recent on documentation webpages.

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

I took only one hunk from the patch that Lubomir sent - the rest I
implemented differently in the previous commit.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Fix memory handling error on MacOS

We are not allowed to free a string that we get back from the config APIs. So
strdup it instead to be compatible with Linux in that respect.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Make sure Subsurface receives Quit / Command-Q callback on Mac

As usual, things work slightly different on Mac. Quartz delivers some (but not
all) accelerator notifications differently. Command-Q and Subsurface->Quit now
work on Mac as well.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
various small fixes to the defaultfile model

1) For safety reasons we no longer remove the default directory after
creating it. This prevents an access error (on windows) and also a couple
of small exploits that could have been possible, resulting in undefined
behaviour.

2) Once "default_filename" is allocated keep it until the value has to change.
The value is finaly released once the program is ready to close.

3) When picking a new default file, grab the new string directly from the
GSList.

4) When storing the new default file from the preferences dialog, make sure
we also update "existing_filename" if needed.

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

Fixed some whitespace issues, made commit message and one of the comments
in the code somewhat clearer.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Fix memory leaks and one potential NULL dereference

Always make sure to clear the memory allocated at the "existing_filename"
pointer when setting it to a new address or NULL.

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

Lifted these changes from a larger commit. The other changes I'll
reimplement in the next commit.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Prevent the preferences dialog from getting focus with file selector open

The idea is based on Lubomir's code but the implementation is radically
different. Instead of having the preferences dialog be referenced by a
global variable we simply look up the appropriate ancestor of the current
widget.

Inspired-by: "Lubomir I. Ivanov" <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Use glib file and pathname functions

My silly reimplementation of these functions was broken on Windows,
anyway. This is much cleaner.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Don't show an error if we can't load the default file

The user may not have created it, yet.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Display current filename in windows title

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>
File Open now closes the previous file, first

This is a pretty significant semantic change - Open used to act more like
Import; you added more dives to the divelist. With this change it instead
acts more like the traditional File->Open in that it closes the previous
file, first.

The diff hides the minimalistic nature of the change - it seemed cleaner to
move the file_open function around than to do a forward declaration of
file_close.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Move Import menu entry back to File menu

This should make things more consistent, especially now that "Open"
actually does just that and no longer behaves almost like "Import".

The downside is that the import from a dive computer is now in the File
menu as well and no longer in the Log menu, where Linus originally had
moved it to in commit 3cace090989b.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The Open menu entry should open just one file

The single file that is our new data file (and the file that we'll change
if it was modified).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Reimplement the GtkFileChooserButton for import

One of the limitations of GtkFileChooserButton is that it only allows one
file to be chosen (so that it can display that file name in the button
after the file chooser dialog finishes). Since in the import dialog we
never want to show the button with the filename(s) filled in but want to
directly execute the import once files have been selected, I reimplemented
the button to simply open a multi file chooser when clicked and to then
run the import function if one or more file names were selected.

This does appear to require some more code but gets us a much more useful
and consistent implementation.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Put creation of the file selector box filter into helper function

This avoids duplication of code.

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