aboutsummaryrefslogtreecommitdiffstats
path: root/dive.h
AgeCommit message (Collapse)Author
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-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-25Improve on divecomputer data handlingGravatar Linus Torvalds
This simplifies the vendor/product fields into just a single "model" string for the dive computer, since we can't really validly ever use it any other way anyway. Also, add 'deviceid' and 'diveid' fields: they are just 32-bit hex values that are unique for that particular dive computer model. For libdivecomputer, they are basically the first word of the SHA1 of the data that libdivecomputer gives us. (Trying to expose it in some other way is insane - different dive computers use different models for the ID, so don't try to do some kind of serial number or something like that) For the Uemis Zurich, which doesn't use the libdivecomputer import, we currently only set the model name. The computer does have some kind of device ID string, and we could/should just do the same "SHA1 over the ID" to give it a unique ID, but the pseudo-xml parsing confuses me, so I'll let Dirk fix that up. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-25Add basic divecomputer info setup with xml parsing and savingGravatar Linus Torvalds
This also knows how to save and restore multiple dive computers in the XML data, but there's no way to actually *create* that kind of information yet (nor do we display it). Tested by creating fake XML files with multiple dive computers by hand so far. The dive computer information right now contains (apart from the sample and event data that we've always had): - the vendor and product name of the dive computer - the date of the dive according to the dive computer (so if you change the dive date manually, the dive computer date stays around) Note that if the dive computer date matches the dive date, we won't bother saving the redundant information in the XML file. 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-21Fix "prefer download" behaviorGravatar Dirk Hohndel
When this was first implemented the assumption was that a downloaded dive that is to be merged with an existing dive would have the same time stamp. But as Linus pointed out even back then, this does fail if a dive has been merged with a download from a different dive computer before (think: download from computer a, then download same dive from b, then improve something in the parsing from computer a and try to redownload; the time stamp could have changed). This commit also fixes a silly omission in the merge_dives() function (which ended up ALWAYS prefering the downloaded dive) and finally implements the necessary changes to mark dives downloaded from a Uemis SDA as well. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-12Extract salinity for Uemis SDA and improve depth calculationGravatar Dirk Hohndel
THe Uemis SDA allows the user to set it up for salt water and fresh water use. We should take this into consideration for the water pressure to depth conversion. 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-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-11Prepare to merge non-overlapping divesGravatar Linus Torvalds
This just re-organizes the dive merging code so that we expose a new "merge_dives(a, b, offset)" function that merges two dives together into one with the samples (and events) of 'b' at the specified offset after 'a'. We'll want to use this if a dive computer has decided that the dive ended (due to a pause at the surface), but we really want to just turn the two computer dives into one long one with an extended surface swim. No functional changes, but some independent cleanups due to the trip simplifications. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-11Trim the dive to exclude surface time at beginning and endGravatar Dirk Hohndel
We don't change any of the samples, we just don't plot (or consider for dive time / mean calculations) the samples at the beginning or end of the dive that are less than a certain threshold under water. Right now that's an arbitrary 75cm which seems to Do The Right Thing(tm) for the dives I tried this with - but I'm happy to look at other values if this causes problems for people with dive computers I do not have access to. 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-10Add support for obtaining salinity from libdivecomputerGravatar Dirk Hohndel
This requires a patched libdivecomputer that can return salinity of the water the dive was conducted in. Experimental patches exist that implement this for the OSTC. The code is designed so that it simply defaults to salt water if libdivecomputer doesn't include the feature. The patch also fixes the dive merge code to merge two other recent additions to the dive structure (surface_pressure and visibility). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-10Fix default filename handling errorsGravatar Linus Torvalds
The default filename handling is broken in two different ways: (a) if we start subsurface with a non-existing file, we warn about the inability to read that file, and then we exit without setting the default filename. This is broken because it means that if the user (perhaps by mistake, by pressing ^S) now saves the file, he will overwrite the default filename, even though that was *not* the file we read, and *not* the file that subsurface was started with. So just set the default filename even for a failed file open. The exact same logic is true of a failed parse of an XML file that we successfully opened. We do *not* want to leave the old default filename in place just because the XML parsing failed, and possibly then overwriting some file that was never involved with that failure in the first place. So just get rid of all the logic to push the filename saving into the XML parsing layer, it has zero relevance at that point. (b) if we do replace the default filename with a NULL file, we need to set that even if we cannot do a strdup() on the NULL. This fixes both errors. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-10Merge branch 'ceiling-plot'Gravatar Dirk Hohndel
This enables plotting the ceiling in deco dives and also adds the necessary code to the uemis importer. The only other dive computer this has been tested with the OSTC and that needs a libdivecomputer patch in order to provide the deco/ceiling information to Subsurface. Fixes #5
2012-11-10Improve logic handling eventsGravatar Dirk Hohndel
We now throw away redundant events, just as we throw away other redundant data coming from the dive computer. Events are considered redundant if they are less than 61 seconds apart and identical. This also improves the display of the remaining events in the profile as we now show the value of the event, if it is present (for example for a deco event we show the duration of the deepest stop). Finally, for events that define a range (so they set the beginning flag and assume and end flag some time later) we no loger show the triangle but assume that some other code handles visualizing them (as happens for the ceiling events). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-10Use correct surface pressure to detect ceiling with Uemis ZurichGravatar Dirk Hohndel
The dive data contains the surface pressure prior to the dive, and that is what we need to compare p_amb_tol to, not the standard 1013mbar. 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-28Add support for visibility tracking and allow manual entry air tempGravatar Dirk Hohndel
Turns out we had a data field for visibility as a length unit - but never used it. I can never guess how much visibility we actually had on a dive - but I think most everyone can assign a rating between abysmal (zero stars, "I couldn't read my dive computer even right in front of my mask" - trust me, I had some of those dives) to amazing ("five stars, I could see farther than I though possible" - and I had one or two of those, too). So I changed this to an integer and am re-using the star infrastructure we have for the overall dive rating. When displaying this I was dismayed that we are running out of space in the "Dive Notes" notbook. So I moved this to the "Dive Info" notebook. This is not consistent and not logical. I think we need to revisit the notebooks and think about what we want to display where. While adding the infrastructure to manually enter the visibility I went ahead and added the ability to manually enter the air temperature as well (that was one of the things missing in the previous commit). Fixes #7 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-19Added a function to check if specific OS features are availableGravatar Lubomir I. Ivanov
linux.c, macos.c, windows.c now contain subsurface_os_feature_available() that can accept an enum type os_feature_t defined in dive.h. The function can be useful to check if a specific global feature is available on a certain OS version. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-18Find translation files on Linux after Subsurface was installedGravatar Dirk Hohndel
So far we only looked in the a local subdirectory, but once Subsurface has been installed, we don't need to change the search path for translation files anymore. Fixes #2 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-15Merge branch 'gettext'Gravatar Dirk Hohndel
Bring all the localization changes into master in preparation for Subsurface 2.1
2012-10-15Support for gettext in MacOSX application bundleGravatar Henrik Brautaset Aronsen
The MacOSX applications bundle needs to be told where to bind the text domain from. Also copy the gettext .mo files in the install-macosx target. [Dirk Hohndel: minor change in main(): move the path declaration to the beginning of the function] Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-11Improve on the DivingLog importer a bitGravatar Linus Torvalds
This adds a few fields that we parse, but more importantly it also tries to dynamically decide if the sample temperatures and pressures are in imperial or metric units. Dirk suspects that DivingLog generally always does everything in metric, and the reason why he has crazy sample data in imperial units (both for pressure and temperature) may be due to a bug in the early Uemis importer for DivingLog. Which would actually make a lot more sense than DivingLog really being so insane on purpose. Anyway, Dirk's brother Jurgen seems to have everything in metric units, which would be much saner. Maybe we should throw away the support for insane DivingLog files entirely, since it is possible that the only use ever of the possible source of that bug was Dirk's use of the Uemis importer. But for now, we end up just guessing. Current guesses: - water temperature is below 32 dgC, so 32+ degrees is in Fahrenheit. - tank pressures are below 400 bar, so higher values than that must be psi. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-09A file that we import should never become the default file we save toGravatar Dirk Hohndel
Only files that are opened should be considered r/w. Files that are imported should be treated as if they were r/o. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-04Provide a method to use unicode command line arguments on WindowsGravatar Lubomir I. Ivanov
For unicode command line characters Windows uses UTF-16, while Glib and GTK use UTF-8. To solve that we retrieve the command line via __wgetmainargs() and use g_utf16_to_utf8() to convert each argument. The used method should support wildcards passed as arguments (e.g. *.xml). Two new, OS abstracted functions appear in linux.c (NOP), macos.c (NOP), windows.c: subsurface_command_line_init(...) subsurface_command_line_exit(...) which are being called in main() 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-26Merge branch 'uemis-native'Gravatar Dirk Hohndel
This brings in the code to download dive information directly from a Uemis Zurich dive computer. The implementation contains a major hack that hooks the uemis code into the same data structures used to setup libdivecomputer. This gives the best result for the user, but is not something that I like as a long term solution as it relies on internal libdivecomputer data structures.
2012-09-26Add the ability to create a log file for debugging outputGravatar Dirk Hohndel
Especially when asking non-developers for help debugging a problem it can be extremely useful to have debugging output not go to the console but to a log file instead. This just adds the infrastructure to create (and close) such a file. No changes to the debug output are made. All this is of course #ifdef'ed out. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-24Update cylinder info properlyGravatar Linus Torvalds
The "cylinders_equal()/copy_cylinders()" functions were buggered, and only checked (and copied) the cylinder type. That was on purpose, since you do want to be able to change the type of a cylinder without changing the gasmix of the cylinder. HOWEVER, the reverse is also true: you may want to change the gasmix of a cylinder without changing the type. So it's not that the type of the cylinder is special - it's that the type and the gasmix should be considered separately. Do that properly for the equipment editing case. Reported-by: Ďoďo <dodo.sk@gmail.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-09-21Fix missing save of (almost empty) cylinder informationGravatar Linus Torvalds
If we have no explicit cylinder info at all (it's normal air, no size or working pressure information, and no beginning/end pressure information), we don't save the cylinders in question because that would be redundant. Such non-saved cylinders may still show up in the equipment list because there may be implicit mention of them elsewhere, notably due to sample data, so not saving them is the right thing to do - there is nothing to save. However, we missed one case: if there were other cylinders that *did* have explicit information in it following such an uninteresting cylinder, we do need to save the cylinder information for the useless case - if only in order to be able to save the non-useless information for subsequent cylinders. This patch does that. Now, if you had an air-filled cylinder with no information as your first cylinder, and a 51% nitrox as your second one, it will save that information as <cylinder /> <cylinder o2='51.0%' /> rather than dropping the cylinder information entirely. This bug has been there for a long time, and was hidden by the fact that normally you'd fill in cylinder descriptions etc after importing new dives. It also used to be that we saved the cylinder beginning/end pressure even if that was generated from the sample data, so if you imported from a air-integrated computer and had samples for that cylinder, we used to save it even though it was technically redundant. We stopped saving redundant air sample information in commit 0089dd8819b7 ("Don't save cylinder start/end pressures unless set by hand"). Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Removed start and end in save_cylinder_info(). These two variables are no longer used. 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-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-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-18Call xmlCleanupParser only once - when we are done with libxmlGravatar Lubomir I. Ivanov
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-17Merge branch 'defaultfile'Gravatar Dirk Hohndel
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-17Once again improve existing filename handlingGravatar Dirk Hohndel
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-17Display current filename in windows titleGravatar Dirk Hohndel
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-11Fix a long standing bug when editing divesGravatar Dirk Hohndel
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-11Use glibio functions for mkdirGravatar Dirk Hohndel
Suggested-by: Jef Driesen <jefdriesen@telenet.be> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>