summaryrefslogtreecommitdiffstats
path: root/divelist.c
AgeCommit message (Collapse)Author
2012-12-04Merge trips without modifying the GTK treeGravatar Lubomir I. Ivanov
This patch does 4 small divelist.c changes in the following order of importance: 1) In find_trip_by_time() now there is a check if a trip is actually found before looking at the "when" flag. 2) Make remember_tree_state() slighly safer. If for example we have recently deleted a trip from the linked list, it may still exist in the GTK tree model, thus we want to check when calling find_trip_by_time() if there is an actual match before setting the "expanded" flag for a trip. 3) When merging two trips in merge_trips_cb(), only use the tree model to retrieve the timestamps (DIVE_DATE) and then find matching trips with find_matching_trip(). Once we have pointers to the two trips to be merged, move dives from one to another iterating with add_dive_to_trip(). 4) In merge_trips_cb() - remember the tree state, repopulate the tree and restore tree state, since now we are not adding/removing rows directly. tesdsad Reported-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-26Simplify tripflags: remove tripflag_names[]Gravatar Linus Torvalds
This removes the tripflag name array, since it's not actually useful. The only information we ever save in the XML file is whether a dive is explicitly not supposed to ever be grouped with a trip ("NOTRIP"), and everything else is implicit. I'm going to simplify the trip flags further (possibly removing it entirely - like I did for dive trips already), and don't like having to maintain the tripflag_names[] array logic. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-26Remove 'tripflag' from dive tripsGravatar Linus Torvalds
Both dives and dive trips have the same 'tripflag' thing, but they are used very differently. In particular, for dive trips, the only case that has any meaning is the TF_AUTOGEN case, so instead of having that trip flag, replace it with a bitfield that says whether the trip was auto-generated or not. And make the one-bit bitfields explicitly unsigned. Signed bitfields are almost always a mistake, and can be confusing. Also remove a few now stale macros that are no longer needed now that we don't do the GList thing for dive list handling, and our autogen logic has been simplified. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-26Clarify (and fix) dive trip auto-generationGravatar Linus Torvalds
This makes the dive trip auto-generation a separate pass from the showing of the dive trips, which makes things much more understandable. It simplifies the code a lot too, because it's much more natural to generate the automatic trip data by walking the dives from oldest to newest (while the tree model wants to walk the other way). It gets rid of the most annoying part of using the gtk tree model for dive trip management, but some still remains. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-26Remove 'when_from_file' field from dive tripGravatar Linus Torvalds
It had become a write-only field (apart from some now useless debugging) when simplifying the remove_autogen_trips() function. So remove it. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-26Rewrite 'remove_autogen_trips()' without the gtk tree model walkingGravatar Linus Torvalds
I'm trying to remove (or at least simplify) the gtk tree model usage for our trip handling, but I'm doing it in small chunks. The goal is to just do all our trip handling logic explicitly using our own data structures, and use the gtk tree model purely for showing the end result. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-26Associate each dive trip with the dives in that tripGravatar Linus Torvalds
We already kept a count of dives per trip in order to figure out when there are no more dives left and the trip needs to be freed. Now we explicitly keep track of the list of dives associated with the trip too, which simplifies the "find the time of the trip" logic. We may want to sort it in time, but for now this is mainly about trying to keep track of the divetrip relationships explicitly. I want to move away from the whole "use the gtk tree model to keep track of things" approach. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-23Move events and samples into a 'struct divecomputer'Gravatar Linus Torvalds
For now we only have one fixed divecomputer associated with each dive, so this doesn't really change any current semantics. But it will make it easier for us to associate a dive with multiple dive computers. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-23Allocate dive samples separately from 'struct dive'Gravatar Linus Torvalds
We used to avoid some extra allocations by just allocating the dive samples as part of the 'struct dive' allocation itself, but that ends up complicating things, and will make it impossible to have multiple different sets of samples (for multiple dive computers). So stop doing it. Just allocate the dive samples array separately. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-21Make sure there are no invisible selected dives after import / downloadGravatar Dirk Hohndel
Prior to this commit, gtk often decided to collapse the trip with the selected dive after the user imported or downloaded additional dives. Since Subsurface tracks dives as being selected even after gtk collapses a trip (which clears all selection state as far as gtk is concerned) this could lead to the strange situation that the user could click on a new dive to select it without unselecting the already selected dive - and suddenly edit or delete did things that were entirely unwanted. With this change we explicitly save and then restore the tree state around import and download operations. This ensures that the same dive(s) stay selected and trips stay expanded and therefore avoids the issues described here. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-19Fix silly thinko in recent changes to "Delete dive" codeGravatar Linus Torvalds
Commit 38c79d149db0 ("Simplify and clean up dive trip management") simplified the code a bit *too* much, and removed the check for "dive->selected". As a result, trying to delete a dive resulted in *all* dives being deleted. Oops. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-11Be stricter about when we allow merging of divesGravatar Linus Torvalds
If the surface interval between two dives is more than half an hour, don't try to call it a single dive. Just the dive profile will be looking ridiculous. Things like tank refills etc could also be a good thing to check (again, the dive profile would look ridiculous), but the cylinder pressure going up a small amount is actually normal (ie cylinder warming up in warmer water on the surface). So I don't know what the proper limit for that would be. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-11Add special download modes to force updates from the divecomputerGravatar Dirk Hohndel
This will hopefully not be something we need often, but if we improve support for a divecomputer (either in libdivecomputer or in our native Uemis code or even in the way we handle (and potentially discard) events), then it is extremely useful to be able to say "re-download things from the divecomputer and for things that were not edited in Subsurface, don't try to merge the data (which gives BAD results if for example you fixed a bug in the depth calculation in libdivecomputer) but instead simply take the samples, the events and some of the other unedited data straight from the download". This commit implements just that - a "force download" checkbox in the download dialog that makes us reimport all dives from the dive computer, even the ones we already have, and an "always prefer downloaded dive" checkbox that then tells Subsurface not to merge but simply to take the data from the downloaded dive - without overwriting the things we have already edited in Subsurface (like location, buddy, equipment, etc). This, as a precaution, refuses to merge dives that don't have identical start times. So if you have edited the date / time of a dive or if you have previously merged your dive with a different dive computer (and therefore modified samples and events) you are out of luck. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-11Fix selection and trip expansion logic after merging divesGravatar Linus Torvalds
This just makes sure that the merged dive is properly selected, and that we've saved the trip tree state so that the dive list repaints nicely and with the newly merged dive selected after the merge. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-11Support merging of two adjacent divesGravatar Linus Torvalds
This introduces the notion of merging two disjoint dives: you can select two dives from the dive list, and if the selection is exactly two dives, and they are adjacent (and share the same dive trip), we support the notion of merging the dives into one dive. The most common reason for this is an extended surface event, which made the dive computer decide that the dive was ended, but maybe you were just waiting for a buddy or a student at the surface, and you want to stitch together two dives into one. There are still details to be sorted out: my Suunto dive computers don't actually do surface samples at the beginning or end of the dive, so when you stitch two dives together, the profile ends up being this odd "a couple of feet under water between the two parts of the dive" thing. But that's an independent thing from the actual merging logic, and I'll work on that separately. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-11Merge branch 'pressure'Gravatar Dirk Hohndel
Make depth to absolute pressure conversions consistent.
2012-11-11Add depth to mbar helper functionGravatar Dirk Hohndel
This ensures that we use consistent math to get the absolute pressure at a certain depth. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-11Simplify and clean up dive trip managementGravatar Linus Torvalds
This adds a couple of helper functions to manage dive trips ("add_dive_to_trip()" and "remove_dive_from_trip()") and makes those functions do the trip statistics maintenance (trip beginning times, number of dives, etc). This was needed because the dive merge cases for multiple dive computers showed some rather nasty special cases: especially if the new dive information has been loaded into an XML file with trips auto-generated, merging several of these kinds of xml files with multiple dives in several overlapping trips would completely confuse our previous code. In particular, auto-generated trips that had the exact same date as previous trips (because they were generated from the same dive computer) really confused the code that used the trip timestamp to manage the trips. Adding the helper functions allows us to get the general case right without having to have each piece of code that handles trip information having to bother about all the odd rules. It will eventually also allow us to make the dive trip data structures more logical: right now the dive trip list is largely designed around the odd gtk model handling, rather than some more higher-level conceptual relationship with the actual dives. But for now, this keeps all the data structures unchanged, and just modifies them using the new helper functions. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-09Fix dive trip merging logicGravatar Linus Torvalds
We used to have very spotty logic for picking the dive trip when merging two dives. It turns out that that spotty logic almost never really matters, because in practice you'll never hit the situation of merging two dives with different dive trips, but it *can* happen. In particular, it happens when you use multiple dive computers, and end up loading the dives from one computer on top of the dives of your other computer. If the clocks of the dive computers was set sufficiently close to each other, the dive merging logic will kick in and you may now have slightly different times for the dives that get merged, and the trip merging logic got *really* confused. The trip management also depends on the trip dates being updated correctly when the dives associated with a trip are updated (whether added or removed), and the trip merging code did none of that. This fixes it all up. Hopefully correctly. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-05Repair broken Add Dive menu itemGravatar Henrik Brautaset Aronsen
Lubomir's commit aec904b612cbee57f8bb5c3289a120b69c9ade24 broke the Add Dive menu item: The Edit Dive dialogue didn't show up after the initial dialogue. Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-24Added confirmation dialog when deleting dives and tripsGravatar Lubomir I. Ivanov
divelist.c: Show a "Yes/No" confirmation dialog when performing delete/remove operations for dives and trips. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-19Use subsurface_os_feature_available() to check for unicode stars supportGravatar Lubomir I. Ivanov
Mainly affecting older Windows (such as XP), which do not have a more fully featured unicode fonts installed, such as Arial Unicode MS. With this patch we do a runtime check of the OS version in a couple of places and if the OS is old, we use the asterix character and spaces instead of the unicode star characters. Linux and OSX should be unaffected by this change unless subsurface_os_feature_available() returns FALSE for UTF8_FONT_WITH_STARS at some point. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-19Translate "air"Gravatar Henrik Brautaset Aronsen
Translate the "air" text in the divelist. Suggested-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-17Increase various stack buffer sizes to accommodate for locale stringsGravatar Lubomir I. Ivanov
Example: For some strings such as the "Trip title" the buffer of 60 bytes was not enought for certain languages. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-17Handle dates and a "calculated plural" in translationsGravatar Dirk Hohndel
This looks like a massive commit mainly because of the line number changes in the .po files. That sadly hides what really happened here: - the places where we manually build dates have now been localized - the one place where we did the English "calculated plural" has been modified so that it now can be correctly translated (in English this just adds an 's' to the noun if the number is != 1 - in other languages this tends to be much more complicated) I then updated the two German translations to take advantage of the new constructs. And while I was at it, I changed the translation Trip->Gruppe to Trip->Reise as that seemed much more appropriate. I also fixed another error in the German translation where I translated "dive time" as "Startzeit" - but in the context it was "Dauer". Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-11Get divelist headers localized, tooGravatar Dirk Hohndel
This fixes an oversight in commit 881a2df83616 ("Conversion to gettext to allow localization") - string literals that are marked with N_ need to be converted when the corresponding variables are used at runtime. This was missed for the divelist headers. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-11Conversion to gettext to allow localizationGravatar Dirk Hohndel
This is just the first step - convert the string literals, try to catch all the places where this isn't possible and the program needs to convert string constants at runtime (those are the N_ macros). Add a very rough first German localization so I can at least test what I have done. Seriously, I have never used a localized OS, so I am certain that I have many of the 'standard' translations wrong. Someone please take over :-) Major issues with this: - right now it hardcodes the search path for the message catalog to be ./locale - that's of course bogus, but it works well while doing initial testing. Once the tooling support is there we just should use the OS default. - even though de_DE defaults to ISO-8859-15 (or ISO-8859-1 - the internets can't seem to agree) I went with UTF-8 as that is what Gtk appears to want to use internally. ISO-8859-15 encoded .mo files create funny looking artefacts instead of Umlaute. - no support at all in the Makefile - I was hoping someone with more experience in how to best set this up would contribute a good set of Makefile rules - likely this will help fix the first issue in that it will also install the .mo file(s) in the correct place(s) For now simply run msgfmt -c -o subsurface.mo deutsch.po to create the subsurface.mo file and then move it to ./locale/de_DE.UTF-8/LC_MESSAGES/subsurface.mo If you make changes to the sources and need to add new strings to be translated, this is what seems to work (again, should be tooled through the Makefile): xgettext -o subsurface-new.pot -s -k_ -kN_ --add-comments="++GETTEXT" *.c msgmerge -s -U po/deutsch.po subsurface-new.pot If you do this PLEASE do one commit that just has the new msgid as changes in line numbers create a TON of diff-noise. Do changes to translations in a SEPARATE commit. - no testing at all on Windows or Mac It builds on Windows :-) Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-09Add trip above adds all consecutive selected dives to the new tripGravatar Dirk Hohndel
Before this commit we had the odd behavior that if we right clicked in the middle of a group of selected dives, the trip was added above the dive we clicked on, not above the group. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-02Fixed potential, rare corruption of unicode charactersGravatar Lubomir I. Ivanov
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>
2012-10-01Fix memory leaks related to dive_trip->locationGravatar Lubomir I. Ivanov
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>
2012-10-01Destroy the divelist (tree) before calling gtk_main_quit()Gravatar Lubomir I. Ivanov
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>
2012-10-01Fixed memory leaks specific to divelist.cGravatar Lubomir I. Ivanov
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>
2012-09-29Fix a number of obvious memory leaksGravatar Dirk Hohndel
Just the result of cppcheck and valgrind... Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-29Clear the display widgets when deleting all dives in the listGravatar Lubomir I. Ivanov
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>
2012-09-28Redo the delete dive codeGravatar Dirk Hohndel
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>
2012-09-24Update the trip's "when" flag after deleting a dive from itGravatar Lubomir I. Ivanov
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>
2012-09-23Added the functionality to delete selected (multiple) divesGravatar Lubomir I. Ivanov
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>
2012-09-22Added different delete label when right clicking multiple drivesGravatar Lubomir I. Ivanov
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>
2012-09-20Only select last dive by default if no other dives are selectedGravatar Dirk Hohndel
After deleting a dive the dive list is recreated. If there are still dives selected we should select the last dive as well. If there isn't any dive selected, then the last dive is as good a default as any, I guess. Reported-by: "Lubomir I. Ivanov" <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-20Removed obsolete debug messageGravatar Dirk Hohndel
We now handle this case correctly, so don't alert the user to something that isn't an issue at all. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-20Convert the divelist debug helpers to the new time functions as wellGravatar Dirk Hohndel
This makes things consistent. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-20Merge branch 'divetrip-rewrite' of git://github.com/torvalds/subsurfaceGravatar Linus Torvalds
Merge the dive trip rewrite by Dirk Hohndel. This just merges the dive trip changes with the timestamp handling changes. There were multiple small data conflicts, along with some newly added 'time_t' cases in the dive trip handling that needed to be converted to 'timestamp_t' along the way. * 'divetrip-rewrite' of git://github.com/torvalds/subsurface: Convert FIND_TRIP into function Partial rewrite of the dive trip code Check if trip is NULL before calling DIVE_TRIP
2012-09-20FIND_TRIP: don't cast a timestamp to a pointerGravatar Linus Torvalds
The pointer size may not be large enough to contain a timestamp, so make FIND_TRIP() just pass the pointer to the timestamp instead. And use an inline function instead of macros with casts. That gets us proper type safety while at it, so that we get a warning if somebody doesn't pass the expected "timestamp_t *". Plus the code actually looks simpler and way more straightforward. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-09-20Convert FIND_TRIP into functionGravatar Dirk Hohndel
This helps us deal with the issue that the g_list convenience functions don't allow us to easily compare 64bit values on 32bit architectures. And since these convenience functions are truly trivial in nature, it seemed easier to simply implement our own logic here. In the process I moved all the dive_trip_list helper functions into the same spot in divelist.c Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-19Fix the incorrect data type for DIVE_DATE accessesGravatar Linus Torvalds
This is the same bugfix that Lubomir did in the master branch, but now on top of the new 64-bit timestamp_t model. So now we also remove the comment about the year 2038 problem, because it's not true any more. We do all the date handling in a 64-bit integer. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-09-19Partial rewrite of the dive trip codeGravatar Dirk Hohndel
This introduces a new data structure for dive trips - reuseing the struct dive just got way too messy. The dive_trip_t datastructure now allows the code to remember if the trip was auto generated or if its time stamp changed when dives where added to the trip during auto generation. The algorithm also distinguishes between dives that were intentionally added to a trip (either in an XML file or by adding them to trip in the UI) and dives that were added to trips via autogen. Saving dives that were added to trips via autogen makes that assignment "intentional". With this partial rewrite several of the oddities of the old code should be resolved - especially turning autogen on and off again should get the divelist back to the previous stage. Also, when dives are merged during file open or import we now try to pick the correct tripflag (instead of just ignoring the tripflag completely and resetting it to TF_NONE by mistake). Finally, the dive trip debugging code got more verbose and is trying harder to detect issues at the earliest time possible. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-19Use a 64-bit 'timestamp_t' for all timestamps, rather than 'time_t'Gravatar Linus Torvalds
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-19Check if trip is NULL before calling DIVE_TRIPGravatar Lubomir I. Ivanov
Other places have this check, but for this particular one a crash can be reproduced: ./subsurface ./dives/* log -> autogroup log -> autogroup Against d14932058f191de2a Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-18Fix some of the problems reported by cppcheckGravatar Dirk Hohndel
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-18When deleting dives make sure that amount_selected stays consistentGravatar Dirk Hohndel
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>