summaryrefslogtreecommitdiffstats
path: root/divelist.c
AgeCommit message (Collapse)Author
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>
2012-09-18Prevent dive_from_path from dereferencing invalid iterGravatar Dirk Hohndel
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-13Mark divelist changed when modifying tripsGravatar Dirk Hohndel
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-11Better compatibility with older GTK and CairoGravatar Lubomir I. Ivanov
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-10Improve trip assignment for new divesGravatar Dirk Hohndel
When first trying to deal with this I opted to go with a two pass appoach which seemed easy as it used existing infrastructure, but turned out to run into a couple of odd corner cases that would have been really ugly to deal with. So I threw this code away and am instead doing this in a single pass, carefully checking as we go if there is an appropriate trip we can use. To me the new code is much easier to read and seems much cleaner. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-07Implement delete dive optionGravatar Dirk Hohndel
With this we can delete a dive from the context menu. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-07Make "create trip above" also add on selected divesGravatar Dirk Hohndel
This makes things more consistent with the merge with trip above option - if multiple dives are selected then the consecutive set of selected top level dives below the dive on which a user right-clicked are all added to the newly created trip. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-07Handle new dives correctly if trips existGravatar Dirk Hohndel
There is an interesting issue when adding new dives into a dive list with existing trips. Since fill_dive_list walks the list backwards and trips are determined by the timestamp of the first dive in a trip, it is non-trivial to know when a dive is added if it should be part of an existing trip or not. Let's say when we see the dive we can also see a trip entry that starts four days earlier. Without looking forward in the list of dives we cannot tell if this is a multi-day trip that this dive would fit into, or if there is a break of more than tree days (our current trip threshold). Instead this commit adds a second scan of the dives in chronological order that does the right thing for new dives. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-06Merge one or more dives with the trip aboveGravatar Dirk Hohndel
Yet another trip manipulation function. The dive we are on (or that dive and the selected dives below it) are merged into the trip directly above. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-05Avoid duplicate dive_trip entriesGravatar Dirk Hohndel
When inserting a trip into the dive_trip_list we already check for duplicate trips, but we still kept the additional dive_trip around. With this change we instead replace it with the existing one. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-05More trip manipulations: remove selected dives from tripGravatar Dirk Hohndel
There are a few obvious trip manipulations on multiple dives that haven't been implemented, yet. This commit handles the case when we have multiple dives selected and right click on one of them. It now removes all of those dives from their trips (instead of just the one that we clicked on). Still todo is the inverse operation. Select a group of consecutive dives and turn them into a trip. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-03Add ability to merge trip with trip belowGravatar Dirk Hohndel
Miika suggested this - we should be able to merge with the trip below and not just the trip above (oh, and call them "above/below" instead of "previous"). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-03Use the infrastructure for moving dives in more placesGravatar Dirk Hohndel
Instead of using our generic helper function the code in remove_from_trip_cb tried to implement the special case - and got it wrong. This fixes yet another crash that Henrik found. Reported-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-03Fix crash when removing the first dive of a tripGravatar Dirk Hohndel
The update_trip_timestamp function can indeed get called with no children present, just before that trip is then removed. So instead of adding complicated special cases, this just bails out of the function. Reported-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-03Fix copy_tree_node to no longer overwrite dive durationGravatar Dirk Hohndel
Cut and paste error when creating this function. Reported-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-02Add autogen menu commandGravatar Dirk Hohndel
This adds the ability to auto create trips from the menu. It's a toggle entry (and while at it, we made the zoom toggle a toggle entry as well). We can therfore switch back and forth between auto generated trips. There is one bug. Assume you have no trips. You manually create a trip from some dives out of a group of trips that autogen would turn into a trip. Now you turn on autogen and this trip gets expanded with all the dives that would normally be grouped together. If you turn off autogen again, all those dives are still part of the remaining (initially manually created) trip. Working around this issue seemed a lot more work than the likelihood of anyone running into it seemed worth. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-02Fix a crash when changing sort columnGravatar Dirk Hohndel
We were using the tree model to check the selection, even though the active model is the list model after switching to a different sort column. To make things clearer I renamed the access macros to be more consistent. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-01Allow modification and edits of tripsGravatar Dirk Hohndel
Now that we can load and store trips we needed to add the capability to manipulate those trips as well. This commit allows us remove a dive from a trip via a right click operation on the dive list. The commit also adds code to split a trip into two, to merge two trips and to create a new trip out of a top level dive. To make all that useful this commit changes the right-click on the dive list to identify and act on the record we are actually on (instead of acting on the selection). The right-click menu ("context menu") changes depending which divelist entry the mouse pointer is on - so different operations are offered, depending on where you are. We also add simplistic editing of location and notes for a trip (but the notes are never displayed so far). To make our lives easier this commit adds a link from the dive to the dive trip it is part of. This allowed to hugely simplify the auto trip generation algorithm (among other things). The downside of this change is that there are now three different ways in which we express the relationship of dives and trips: in the dive_trip_list, in the tree_model, and with these pointers. Somehow this screams that I should rethink my data structures... Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-01Clean up macros and auxiliary functionsGravatar Dirk Hohndel
In preparation for the next stage of the trips handling this commit makes the macros used to access trips (and some frequently used variables for the tree and list models) more consistent. This also changes the way we display un-grouped dives in the dive list, i.e. dives that are not part of a dive trip. Their dive number is now printed bold. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-01Store time_t as long valueGravatar Dirk Hohndel
The tree_storage only provided enough space for an int for DIVE_DATE. But at least on 64bit Linux, an int is 32bit yet a time_t is 64bit. Until 2038 this only causes issues in some odd situations, after 2038 this would be an obvious bug. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>