summaryrefslogtreecommitdiffstats
path: root/divelist.c
AgeCommit message (Collapse)Author
2012-12-28Allow sorting dives by date - without the dive trips in the dive listGravatar Linus Torvalds
We used to enable dive trips whenever we sorted by date, which can be a bit annoying. Sometimes you really just want to sort all your dives by date, without necessarily seeing the trip data. So this changes the default sort to be the "dive number" table, and then does *not* actually sort by the dive number, but instead enables the trips, and then sorts the result by date. So the "dive number" column - which used to be non-sortable - becomes semantically equivalent to the old date column sorting. And now sorting by date makes it act like sorting by depth or any other attribute - we hide the dive trip tree, and just show the plain list of dives (sorted by date, obviously). Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-28Free trip notes memory when deleting a tripGravatar Lubomir I. Ivanov
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-27Small changes in the memory management when dive-mergingGravatar Lubomir I. Ivanov
This patch makes a couple of modifications: 1) divelist.c:delete_single_dive() now tries to free all memory associated with a dive, such as the string values for divemaster, location, notes & etc. 2) dive.c:merge_text(), now always makes a copy in memory for the returned string - either combined or one of the two which are passed to the function. The reason for the above two changes is that when (say) importing the same data over and over, technically a merge will occur for the contained dives, but mapped pointers can go out of scope. main.c:report_dives() calls try_to_merge() and if succeeds the two dives that were merged are deleted from the table. when we delete a dive, we now make sure all string data is cleared with it, but also in the actual merge itself, which precedes, copies of the merged texts are made (with merge_text()), so that the new, resulted dive has his own text allocations. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-26Fix crash when trip info changes across remember/restore tree stateGravatar Dirk Hohndel
Interesting crash. Importing a file gets us to a stage where we have a trip tree note with a date that doesn't exist as trip date. That's clearly bogus. And in import_files() we assume that all is still fine and try to restore the old expanded / selected state for the various trips. There is clearly a bigger issue here, this patch at least prevents the actual crash from happening by making sure the pointer is non-NULL before dereferencing it. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-22Fix some small memory leaks related to gtk_tree_model_get_path()Gravatar Lubomir I. Ivanov
From the GTK docs on gtk_tree_model_get_path(): "Returns a newly-created GtkTreePath referenced by iter. This path should be freed with gtk_tree_path_free()." Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-20Correctly calculate OTUs when pO2 is recorded in the samplesGravatar Dirk Hohndel
This will normally happen for CCR dives with a set pO2. The old calculations was only valid for OC dives. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-15Deal with some trip issues when editing dive timestampsGravatar Dirk Hohndel
The idea behind editing timestamps had of course been the typical "oops, I forgot to set my time correctly" which shifts a dive (or a few of them) by a few hours but keeps the overall order of dives the same). But reasonable people might argue that they can envision a scenario where more dramatic changes are being made. And we need to deal with the impact this has on dive trips. Here we handle a couple of simple cases: - this is the only dive in a trip; just update the trip (this can still cause problems if the new time is in the middle of an existing trip). - this dives moves before the start of the trip it is in; let's remove it from that trip (this response is a bit simplistic - but as I tried to say, I don't expect this to be a common use case; and removing it at least doesn't lead to entirely unexpected behavior). - this dive moves past the end of this trip into the range of a different trip (in this case we remove the dive from the current trip and allow it to interrupt the trip it is moving into). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-11Merge branch 'cns' into cns-mergeGravatar Dirk Hohndel
I foolishly changed visible_columns in both the (ill-named) cns branch and master... Signed-off-by: Dirk Hohndel <dirk@hohndel.org> Conflicts: divelist.c gtk-gui.c profile.c
2012-12-10Display maximum CNS in the divelistGravatar Dirk Hohndel
We either pick the CNS reported by the dive computer at the end of the dive, or the maximum of that and the CNS values in the samples, if any. As usual, this column in the dive list defaults to off and it is controlled by a setting in the tec page of the preferences. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-10Add the ability to edit the date/time of a diveGravatar Dirk Hohndel
This can cause some fun unintended side effects - especially when the dive is part of a trip and the new date/time moves this into a different trip. Instead, trips get split and the overall result is consistent, but a bit unexpected. But since this is designed to help people right after a dive import in case the clock on the dive computer was wrong, my guess is this won't ever be a problem for actual users. Fixes ticket 18 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-10Move global variables covered by Preferences into one structureGravatar Dirk Hohndel
Now we can simply remember the state of all the preferences at the beginning of preferences_dialog() and restore them if the user presses 'Cancel'. Fixes #21 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-06Fix insert_trip to correctly deal with trips that start at the same timeGravatar Dirk Hohndel
The existing code did not move the dives that are part of the second trip to the first trip (and forgot to keep the 'better' notes as well). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
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>