Commit graph

10740 commits

Author SHA1 Message Date
Lubomir I. Ivanov
f4bc0ca37b Use long instead of int when retrieving DIVE_DATE via gtk_tree_model_get
The type of the DIVE_DATE field is G_TYPE_LONG, so when accessing it we
have to pass gtk_tree_model_get() the proper "long *" pointer, rather
than an int.  On 64-bit platforms, passing a pointer to an int would
otherwise result in randomly overwriting another four bytes of stack.

Sadly, there are not much safety checks to warn if our passed variable
to the vararg list is of the correct type, which is unlike
gtk_tree_model_get_value(), which will report typed errors.

This solves a bug that may potentially result in undefined behaviour
on some x64 OS (e.g Ubuntu 12.04 x64).

Reported-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-09-19 18:00:38 -07:00
Linus Torvalds
dce08deb34 Use a 64-bit 'timestamp_t' for all timestamps, rather than 'time_t'
This makes the time type unambiguous, and we can use G_TYPE_INT64 for it
in the divelist too.

It also implements a portable (and thread-safe) "utc_mkdate()" function
that acts kind of like gmtime_r(), but using the 64-bit timestamp_t.  It
matches our original "utc_mktime()".

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-09-19 17:35:52 -07:00
Lubomir I. Ivanov
bf83aa2104 Check if trip is NULL before calling DIVE_TRIP
Other places have this check, but for this particular one a crash
can be reproduced:

./subsurface ./dives/*
log -> autogroup
log -> autogroup

Against d14932058f

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-19 14:07:14 -04:00
Dirk Hohndel
d14932058f Fix some of the problems reported by cppcheck
Thanks to Christian for running the static code analysis tool against
subsurface...

There were some false positives, a few style issues that I'll ignore for
now, and two actual potential bugs.

First: Don't check unsigned variables for < 0

This has been around for a while and we are lucky that while technically a
bug it still works as expected. Passing a negative idx simply turns it
into a very large unsigned integer which then fails the > dive_table.nr
test. So it still gets a NULL returned. A bug? Yes. Critical? No.

Mismatched allocation and free

This is an actual bug that potentially could cause issues. We allocate
memory with malloc and free it with g_free. Not good.

Reported-by: Cristian Ionescu-Idbohrn <cristian.ionescu-idbohrn@axis.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-18 20:25:45 -04:00
Dirk Hohndel
f73e5b7268 When deleting dives make sure that amount_selected stays consistent
This could cause a crash if deleting the last dive and manually adding a
new one.

Reported-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-18 19:37:03 -04:00
Henrik Brautaset Aronsen
f83625efa5 Proper placement for the file menu separator lines in MacOSX
After Lubomir's latest changes to the File menu, the separator
were a little off.

Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-18 19:20:44 -04:00
Dirk Hohndel
744b4e0c1c Prevent dive_from_path from dereferencing invalid iter
This fixes a bug that Lubomir reported in a different way from the patch
that he providede; I believe this to be more generic.

Reported-by: "Lubomir I. Ivanov" <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-18 19:13:59 -04:00
Lubomir I. Ivanov
7226a48a8c Call xmlCleanupParser only once - when we are done with libxml
Calling xmlCleanupParser in parse-xml.c:parse_xml_buffer()
caused massive memory corruption mostly affecting gtk's FileChooser
dialogs and the application menu.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-18 18:57:52 -04:00
Ivan Habunek
0cf3a11645 Cosmetic changes to the NSIS installer script
Removed redundant /oname settings when copying files. This is not required
since the file name is not changed.

Signed-off-by: Ivan Habunek <ivan.habunek@gmail.com>
2012-09-18 13:43:48 +02:00
Ivan Habunek
94bcb3fa36 Fixed permissions in NSIS installer
Windows Vista and later require admin privileges to install to the Program
Files folder. Updated RequestExecutionLevel accordingly.

Signed-off-by: Ivan Habunek <ivan.habunek@gmail.com>
2012-09-18 13:39:24 +02:00
Lubomir I. Ivanov
914488b796 Fixed a couple of memleaks in gtk-gui.c and info.c
Related to subsurface_default_filename() and g_path_get_basename().
Against 3835faa8fb.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-18 07:29:33 -04:00
Lubomir I. Ivanov
16bff5265e Added an entry "New" in the "File" menu
Currently doubles the functionality of "Close" (file_close).

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-18 07:20:13 -04:00
Dirk Hohndel
fc250493ca Fix crash when simply clicking OK in import dialog
Since the GSList is now only created if the user enters the file selection
dialog, opening the import dialog and then clicking OK without selecting
either a dive computer or a file would cause a crash.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-18 07:17:55 -04:00
Lubomir I. Ivanov
ac06d1f693 Generalized the "Import" dialog title
Renamed the title of the "Import" dialog to "Import", as there
are a couple of supported operations.

Removed the "Import:" text in the dialog body.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-18 07:12:33 -04:00
Lubomir I. Ivanov
21a8f3f325 Moved "Import" in a separate section in the "File" menu
Moved the entry bellow the standard file operations and above "Print".
Also placed it between separators and added the GTK_STOCK_GO_BACK icon.

Later on "Export" can be placed below "Import" using GTK_STOCK_GO_FORWARD.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-18 07:12:21 -04:00
Dirk Hohndel
3835faa8fb Merge branch 'defaultfile'
By now the default file code seems quite matured, so in preparation for
2.0 we'll bring it back into master.

I made a few small clean-ups during the merge, but the merge itself is
very much straight forward.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-17 21:44:28 -04:00
Dirk Hohndel
d7465129bb Make sure dive info is displayed correctly at start
Commit cdae2869d1dd ("Show the datafile name even with no dives") was a
little too aggressive in making sure that we show the correct window title
- we only should call show_dive_info(NULL) if there is indeed no dive in
the dive table - otherwise we display empty dive info at program start.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-17 21:03:30 -04:00
Dirk Hohndel
2cadc70e3d Simplify code in file_open as we now only open one file
This doesn't change functionality - it's just pointless to loop over a
list that is known to have only one element.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-17 21:03:30 -04:00
Dirk Hohndel
46d91acdff Don't close existing data file in file_open if user cancels
This logic seems to make much more sense - if the user hits 'OK' then the
old file is closed and the new one openened. Otherwise, leave things
unchanged.

Reported-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-17 21:03:30 -04:00
Dirk Hohndel
7148dea827 Once again improve existing filename handling
Several potential problems.
- we could end up dereferencing exiting_filename when it was NULL
- we could free the default_filename by mistake -
  subsurface_default_filename always needs to return a copy of it
- closing the existing file before opening a new one repopulated the
  existing_filename with the default filename - preventing the opened
  file to become the new existing filename

Also, make existing filename a const char * and make file_open have the
same sensible default folder behavior as the other file related functions.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-17 21:03:30 -04:00
Dirk Hohndel
fa2f1b6eb0 Fix potential crash when importing dives
If the last of the preexisting dives gets merged with a new dive we end up
dereferencing a freed pointer.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-17 21:03:30 -04:00
Dirk Hohndel
421366d0fb Correctly deal with empty XML files
Previously we could end up with a bogus dive with all zero data in it.

Adding dives/test24.xml to be able to test that we handle this case
correctly.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-17 21:03:30 -04:00
Dirk Hohndel
0d637c2fa9 Show the datafile name even with no dives
That's especially useful if starting without a filename and without an
existing default file - this way it's clear that Subsurface still
considers itself synced with the default file.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-17 21:03:30 -04:00
Dirk Hohndel
cc42debb88 Mark divelist unchanged after closing the datafile
This seems rather obvious - I'm surprised I didn't notice it earlier.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-17 21:03:30 -04:00
Dirk Hohndel
eddea0e5e3 Put creation of the file selector box filter into helper function
This avoids duplication of code.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-17 21:03:29 -04:00
Dirk Hohndel
ca696dd0cd 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>
2012-09-17 21:03:29 -04:00
Dirk Hohndel
dea8d47b69 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>
2012-09-17 21:03:29 -04:00
Dirk Hohndel
b2727ecfda 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>
2012-09-17 21:03:29 -04:00
Dirk Hohndel
d3bf8af7fe 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>
2012-09-17 21:03:09 -04:00
Dirk Hohndel
65d9d48845 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>
2012-09-17 21:03:03 -04:00
Dirk Hohndel
1771500078 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>
2012-09-15 04:44:00 -07:00
Dirk Hohndel
febae4d165 Changing Miika's code to avoid global iter
Two things I disliked in Miika's code in commit cbb5bd125b03:

Having an integer variable named "something_iter" with all the GtkTreeIter
around was really confusing.

And having the yearly_iter as a global variable instead of cleanly passing
it around really seemed suboptimal.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-14 10:13:29 -07:00
Miika Turkia
e7d4bbdd72 Improving the yearly statistics code
This will update the yearly statistics window (if open) whenever there
are changes to the dive list.

I also added a check not to open multiple statistics windows.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>

Reworded commit message

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-14 10:09:56 -07:00
Dirk Hohndel
b150c4fd41 Make sure all parts of the edit dialogs are using current_dive / edit_dive
While most of this problem was fixed in commit 18b3dca431a4 ("Fix a long
standing bug when editing dives"), it turns out that I missed a couple of
the equipment callbacks.

In the corner case of having an empty divelist (where therefore
current_dive == NULL) manually adding a dive and trying to add equipment
(cylinder or weightsystem) to it would crash subsurface as we were trying
to dereference current_dive.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-13 20:41:21 -07:00
Dirk Hohndel
e84cdf59bb make clean should remove subsurface.exe as well
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-13 14:43:34 -07:00
Dirk Hohndel
63c36e5e11 Mark divelist changed when modifying trips
This is just fixing an embarrassing oversight. Now we should prompt the
user about saving the file whenever something changes.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-13 11:45:21 -07:00
Dirk Hohndel
9f5d9bd94f 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>
2012-09-13 11:22:09 -07:00
Dirk Hohndel
3d4be85f35 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>
2012-09-13 10:53:30 -07:00
Dirk Hohndel
c74f58786d 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>
2012-09-13 10:46:09 -07:00
Ivan Habunek
52e35b3aa8 Minor improvements to the NSIS installer script
VIProductVersion requires to have the version number in x.x.x.x format
so I added a separate constant SUBSURFACE_VIPRODUCTVERSION for that
purpose. Also renamed VERSION to SUBSURFACE_VERSION for consistency.

As Lubomir suggested on the mailing list, the installer will now delete
any DLL files found in the target folder to prevent buildup of old
versions of libraries when upgrading subsurface.

Signed-Off-By: Ivan Habunek <ivan.habunek@gmail.com>

Cleaned up whitespace issues

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-13 09:39:31 -07:00
Ivan Habunek
791edd78b4 Minor fix for the NSIS installer script
Forgot to add "Uninstall.exe" to the uninstaller section, so the file and
the installation folder weren't being deleted on uninstall.

Signed-Off-By: Ivan Habunek <ivan.habunek@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-13 09:39:18 -07:00
Ivan Habunek
bccbdccdfa Added version info to NSI installer script.
Also bumped version number to 1.2 (current release).

Signed-Off-By: Ivan Habunek <ivan.habunek@gmail.com>

More whitespace cleanup

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-13 09:38:19 -07:00
Ivan Habunek
5cf89b4d28 Created a modern windows installer script
The existing windows installer looks very archaic and offers very few
configuration options. This script offers the following benefits:
* A modern appearence using NSIS Modern UI 2.0
* Shows the GPL license before install
* User can choose the target install folder
* Stores chosen installation folder in registry
* When installing a newer version on top of existing one, the existing
  installation folder is offered by default
* It is possible to opt out of creating start menu shortcuts

Additional bug fixes:
* Added iconv.dll which was missing from the installer
* Replaced all path separators with backwars slashes, so that the script
  works on both linux and windows

Signed-Off-By: Ivan Habunek <ivan.habunek@gmail.com>

Cleaned up whitespace

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-13 09:24:50 -07:00
Lubomir I. Ivanov
5dbf10a6d6 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>
2012-09-12 15:13:09 -07:00
Dirk Hohndel
1ae4b80027 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>
2012-09-12 09:18:56 -07:00
Dirk Hohndel
1afe36840d 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>
2012-09-11 20:52:54 -07:00
Dirk Hohndel
41d3a11ee3 Fix a long standing bug when editing dives
Calling edit from the context menu creates a combined editing widget that
contains both dive info and equipment. When editing cylinders or
weightsystems from that widget and confirming those edits with OK those
changes were already committed to the current_dive - regardless on which
dive the user clicked. Worse, even when the user clicked Cancel in the
edit widget, any changes to the equipment stayed in effect.

This had especially confusing consequences when editing multiple dives.

As a workaround this commit adds a global edit_dive variable. This fake
dive is edited by the secondary editing widgets and if the user accepts
changes with OK then they are copied over to the current dive (or all
selected dives in multi dive editing mode).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-11 13:37:06 -07:00
Lubomir I. Ivanov
be941e00b2 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>
2012-09-11 12:08:39 -07:00
Dirk Hohndel
2a9679dac6 Use glibio functions for mkdir
Suggested-by: Jef Driesen <jefdriesen@telenet.be>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-11 12:08:07 -07:00
Lubomir I. Ivanov
0fceb1c907 Better compatibility with older GTK and Cairo
divelist.c:
Replaced "gtk_tree_path_get_indices_with_depth()" with the coupled alternative:
	int depth = gtk_tree_path_get_depth(path);
	int *indices = gtk_tree_path_get_indices(path);
for compatibility GTK+ < 2.22

*:
Replaced all usage of "cairo_rectangle_int_t" with "cairo_rectangle_t"
for compatibility with Cairo < 1.10.

Both modification make building Subsurface possible on a fairly recent Debian
distribution, which reports to have the version of the abovementioned
libraries "up-to-date", yet they are slightly outdated.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-11 07:59:53 -07:00