aboutsummaryrefslogtreecommitdiffstats
path: root/divelist.c
AgeCommit message (Collapse)Author
2013-05-11Require libzip, xslt and osm-gps-map in all buildsGravatar Henrik Brautaset Aronsen
Conditional inclusion of libzip, xslt and osm-gps-map just makes testing more cumbersome, since testers might lack Subsurface features without knowing. Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-03Fix compiler warningsGravatar Dirk Hohndel
Doing this on Arch Linux with gcc 4.8.0 helped find one real bug. The rest are simply changes to make static functions externally visible (as they are kept around to eventually become helpers used by Qt) which for now avoids the warnings. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-03Remove the majority of the Gtk related codeGravatar Dirk Hohndel
- rip all Gtk code from qt-gui.cpp - don't compile Gtk specific files - don't link against Gtk libraries - don't compile modules we don't use at all (yet) - use #if USE_GTK_UI on the remaining files to disable Gtk related parts - disable the non-functional Cochran support while I'm at it Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-02Move gas string computation into core logic codeGravatar Dirk Hohndel
This is now a helper called from the Gtk UI code (and will soon be used by the Qt UI code). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-24Call the get_date functions with timestamp_t instead of struct tmGravatar Dirk Hohndel
This is the much more natural way to use this function, now that I look at it... Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-24Split report_dives into UI and logic and move to divelist filesGravatar Dirk Hohndel
Functionality is unchanged, except we now have a nice process_dives function that deals with all the logic and that gets called from report_dives from the Gtk code. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-23Add a simple table-based cns calculationsGravatar Anton Lundin
For dives where divecomputers haven't provided us with a cns, we calculate our cns accumulated during that dive based on a simple table. We also check if we did a dive in the prior 12 ours and grab the cns from it and calculate how much of that still affects us. [Dirk Hohndel: a couple of small changes: remove unnecessary check of cns values in the samples of the first dive computer, changed the way we determine the 'previous dive' and used the end time of that previous dive for the decay calculation] Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-21Move creation of dive and dive trip date string into helper functionsGravatar Dirk Hohndel
This allows this code to easily be shared by Gtk and Qt UI. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-18Move creation of dive and dive trip date string into helper functionsGravatar Dirk Hohndel
This allows this code to easily be shared by Gtk and Qt UI. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-18Delay Qt ui constructionGravatar Amit Chaudhuri
The Qt ui will need to read the dive_table to populate widgets with dives. Gtk functionality in init_ui is required to parse the dives. Split init_ui to allow parsing to proceed and complete before Qt ui mainwindow constructor is called. Play with qDebug()'s printf style (Thiago!) Signed-off-by: Amit Chaudhuri <amit.k.chaudhuri@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-10Fix selection handling for invalid divesGravatar Dirk Hohndel
This is the downside of having to track our own selection state. We now have a class of dives that potentially isn't known to Gtk as we aren't adding them to the TreeView. So we need to make sure that their selection state is consistent by deselecting them (either when they are marked as invalid OR when we change preferences to no longer show invalid dives). And because Gtk sends out another set of selection events when clearing the TreeView (not sure why), we also need to make sure that their selection state isn't reset to selected by mistake when the divelist is recreated. A bit of a pain, but it seems to work now and be consistent. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-09Add a simple table-based cns calculationsGravatar Anton Lundin
For dives where divecomputers haven't provided us with a cns, we calculate our cns accumulated during that dive based on a simple table. We also check if we did a dive in the prior 12 ours and grab the cns from it and calculate how much of that still affects us. [Dirk Hohndel: a couple of small changes: remove unnecessary check of cns values in the samples of the first dive computer, changed the way we determine the 'previous dive' and used the end time of that previous dive for the decay calculation] Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-07Continue to separate Gtk related code from core logic: divelistGravatar Dirk Hohndel
Move some more logic out of the divelist-gtk.c file. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-07Separate Gtk related code from core logic: divelistGravatar Dirk Hohndel
This is simplistic & brute force: any function that touches Gtk related data structures is moved to divelist-gtk.c, everything else stays in divelist.c. Header files have been adjusted so that this still compiles and appears to work. More thought is needed to truly abstract this out, but this seems to be a good point to commit this change. Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-06Continue to separate Gtk related code from core logic: divelistGravatar Dirk Hohndel
Move some more logic out of the divelist-gtk.c file. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-06Separate Gtk related code from core logic: divelistGravatar Dirk Hohndel
This is simplistic & brute force: any function that touches Gtk related data structures is moved to divelist-gtk.c, everything else stays in divelist.c. Header files have been adjusted so that this still compiles and appears to work. More thought is needed to truly abstract this out, but this seems to be a good point to commit this change. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-03-24Export dives to UDDF fileGravatar Miika Turkia
This patch implements exporting dives from Subsurface to UDDF format. Events and cylinder info are the most remarkable things still missing from the export. Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-03-20divelist.c: Fix an 'implicit declaration' warningGravatar Lubomir I. Ivanov
close() should be included from unistd.h, instead of fcntl.h for better portability. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-03-18Correctly handle first gas when deciding if gas is usedGravatar Robert C. Helling
Gas with index 0 is assumed to be the first gas only if there is no gaschage event in the first 30 seconds of the dive. [Dirk Hohndel: minor formatting change in a logical expression] Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-03-18Take only used gases into account when showing gas in divelistGravatar Robert C. Helling
Here is a patch that restricts the gases listed in the divelist to those that are actually used. I seem to have the indentation now under control but I am not sure about the logic: 1) First gas (with index 0) is always used. 2) If there is a gas switch event, the new gas is also used (determined by walking the list of dive computers and then the list of events). Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-03-15Use a generic 64bit int typeGravatar Dirk Hohndel
The zip_int64_t type appears to be missing with mingw so it breaks my cross builds - and this is clearly equivalent. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-03-13First simplistic implementation of a divelogs.de uploadGravatar Dirk Hohndel
This has no user interface and hardcodes a testing username / password. But it can successfully create a DLD file (thanks to Miika and Lubomir) and then uses libsoup to upload that to the server. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-03-12DLD upload: Avoid using open_memstream() and non-portable functionsGravatar Lubomir I. Ivanov
patch contains: - replacement for open_memstream() - storage of the temporary zip file in the OS temporary directory - replacement usage of mktemp() with g_mkstemp() patch based on work by Miika Turkia. [Dirk Hohndel: as suggested by Miika I commented out the deletion of the DLD file] Acked-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-03-10.DLD generation for uploading to divelogs.deGravatar Miika Turkia
This generates a .DLD file of selected dives to be uploaded to divelogs.de. The actual upload functionality along with sensible user interface is still to be implemented. However, the resulting file from this patch is tested to work (as far as I can tell) using upload API of divelogs.de. Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-03-03Saving individual dives should not change the exiting filenameGravatar Dirk Hohndel
The current data file is not the same as the file to which individual dives were saved. Reported-by: Jan Schubert <Jan.Schubert@GMX.li> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-03-03Try to capture some more potential buffer overflows caused by localizationGravatar Dirk Hohndel
A couple of these could clearly cause a crash just like the one fixed by commit 00865f5a1e1a ("equipment.c: Fix potential buffer overflow in size_data_funct()"). One would append user input to fixed length buffer without checking. We were hardcoding the (correct) max path length in macos.c - replaced by the actual OS constant. But the vast majority are just extremely generous guesses how long localized strings could possibly be. Yes, this commit is likely leaning towards overkill. But we have now been bitten by buffer overflow crashes twice that were caused by localization, so I tried to go through all of the code and identify every possible buffer that could be affected by this. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-27When manually adding a dive allow user to set avg depth as wellGravatar Dirk Hohndel
So far we only allowed setting the max depth. This changes the layout of the entry widget and makes our helper function create_date_time_widget return the hbox in which it positions the time entry. I plan to reuse this later when allowing to edit the duration as well as the start date and time under certain circumstances. This is a small part of a feature request; see #75 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-25Take incompressibility of gas into account at higher pressuresGravatar Linus Torvalds
This creates a helper function called "gas_volume()" that takes the cylinder and a particular pressure, and returns the estimated volume of the gas at surface pressure, including proper approximation of the incompressibility of gas. It very much is an approximation, but it's closer to reality than assuming a pure ideal gas. See for example compressibility at http://en.wikipedia.org/wiki/Compressibility_factor Suggested-by: Jukka Lind <jukka.lind@iki.fi> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-24Use the improved duration and average depth for everythingGravatar Linus Torvalds
The code was written to get the SAC rate correct, but we probably do want to have the duration and mean depth of the dive always be shown for the non-surface-time. So move the code from the sac-rate calculation to the generic dive fixup part. This makes the dive list and statistics all show the duration as the under-water duration, which is not necessarily the same as "difference between beginning and end of dive". Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-24Correctly calculate SAC rate in the presense of surface eventsGravatar Linus Torvalds
This assumes that you are not breathing your cylinders while at the surface, which may or may not be correct, but is usually the right thing. Regardless, we're better off giving a conservative (higher) SAC rate estimate for a diver that breathes his cylinder at the surface too than giving an artificially low one because the diver ended up using his snorkel and we didn't take that into account. NOTE! This basically calculates a better duration and average depth than the ones we end up showing in the dive list. Maybe we should actually show this "no-surface-time" duration and average depth instead of the ones we do show? That's a separate question, though. Added a test-case for the surface case to the sac-test.xml dives. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-24Fix up SAC calculations for ATM/bar confusionGravatar Linus Torvalds
We even documented that we did SAC in bar*l/min, but the "S" in SAC stands for "Surface". So we should normalize SAC rate to surface pressure, not one bar. It's a tiny 1% difference, and doesn't actually matter in practice, but it's noticeable when you want to explicitly test for SAC-rate by creating a test-dive that averages exactly 10m. Suddenly you don't get the round numbers you expect. [ Side note: 10m is not _exactly_ one extra atmosphere according to our calculations, but it's darn close in sea water: the standard salinity of 1.03 kg/l together with the standard acceleration of 9.81m/s^2 gives an additional pressure of 1.01 bar, which is within a fraction of a percent of one ATM. Of course, divers have likely chosen that value exactly for the math to come out that way, since the true average salinity of seawater is actually slightly lower ] So here's a few test-dives, along with the SAC rate fixup to make them look right. (There's also a one-liner to dive.c that makes the duration come out right if the last sample has a non-zero depth, and the previous sample did not: one of my original test-dives did the "average 10m depth" by starting at 0 and ending at 20m, and dive.c got a tiny bit confused about that ;) [ The rationale for me testing our SAC rate calculations in the first place was that on snorkkeli.net user "Poltsi" reported that our SAC rate calculations differ from the ones that Suunto DM4 reports. So I wanted to verify that we did things right. Note that Poltsi reported differences larger than the difference of BAR/ATM, so this is not the cause. I'll continue to look at this. ] Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-20Unref the two GtkTreeStore instances when destroying the divelistGravatar Lubomir I. Ivanov
Even if these exists for the heap lifespan, we can call: g_object_unref(dive_list.treemodel); g_object_unref(dive_list.listmodel); in divelist.c:dive_list_destroy() Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-20Fixed a memory leak in the divelist when moving with the keyboardGravatar Lubomir I. Ivanov
There were some small leaks before here, related to gtk_tree_iter_copy(), but there is another one in select_next_dive(): nextiter = gtk_tree_iter_copy(iter); This now requires a SJ near the epilog where we do the memory cleanup. Lets call this similar label consistently "free_iter" between select_prev_dive and select_next_dive. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-20Indicate to the user a default divelist sorting orderGravatar Lubomir I. Ivanov
Each time subsurface starts there is supposedly no sorting order (or divelist column) specified by the UI, yet the actual column is '#' (or dive number column), since its the *only* column which allows trips to be visible. If the user selects a different sorting order then he has no idea which column was the one who had the trips visible. "Where did all those 'trip' things go?" This can be a bit confusing... Lets provide indication by calling gtk_tree_view_column_set_sort_indicator(). Also call gtk_tree_view_column_set_sort_order() to specify a descending order. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-20Preserve keyboard focus when changing sorting order in the divelistGravatar Lubomir I. Ivanov
When the user changes the dive list sorting order via clicking on different column titles, using gtk_widget_grab_focus() gives keyboard focus back to the list itself (not staying on the column titles), which gives a hint that the list itself has focus index of 0 and is reset each time the widget receives this type of "initial" focus. Acked-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-19Fix tracking of selected dives across sort column changesGravatar Dirk Hohndel
With commit 800b0482f39e ("When switching sort order, scroll the dive list to the current dive") we introduced an unwanted new behavior. When changing sort columns we could lose all selections except for the main "selected_dive". This was caused by the call to gtk_tree_view_set_cursor on the selected_dive which unselected all other dives. As a side-effect this also fixed another bug that was introduced by the same change: shift-cursor-up and -down now works again to select multiple dives with the keyboard. But fixing that bug unearthed a different issue. Our code that restored the selection state of the tree model oddly decided to mark a divetrip as selected if its first child was selected. The bug above masked that by immediately unselecting the trip again, but now that this was fixed the problem was immediately obvious: we would start with both the first trip and the first dive in that trip selected (well, since we are in reverse order it's actually the chronologically last trip and last dive...). Instead we now use the remembered state of the trip to determine whether it should be expanded or selected. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-19Obviate the need for explicit 'remember_tree_state/restore_tree_state' callsGravatar Linus Torvalds
Instead, just keep track of the expanded state of trips as we get the gtk callbacks for the state changes (which we need to track anyway for the selection logic), and automatically restore the state whenever we re-create the divelist. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-19Remember non-expanded state in 'remember_tree_state()' tooGravatar Linus Torvalds
The 'remember_tree_state()' thing is meant to remember if a dive trip is expanded or not, but it missed the "or not" part. IOW, it never cleared the expanded flag, it only ever set it. As a result, if you were doing multiple operations on the divelist tree (testing all the recent gtk-model removal, for example) the dive trips would end up expanding more and more, even if you collapsed things by hand in between operations. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-19Rewrite "merge_dive_into_trip_above()" using our own data structuresGravatar Linus Torvalds
This does the moving of dives into the trip above without the complexity of the gtk data structures, and instead just recreates the whole divelist afterwards. As usual, this simplifies things a lot, and the less gtk-specific code we have, the better. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-19Don't do "insert_trip_before" using the gtk data structuresGravatar Linus Torvalds
.. use our own data structures instead, and regenerate the gtk ones after having successfully created the new trip. This simplifies the code enormously, and also makes it much more generic. You can now create a new trip from any arbitrary set of selected dives (it used to be that the "multiple selected dives" case worked, but only for some very specific special cases of selected dives). Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-19Fix find_trip_by_idx() over-zealous cleanupGravatar Linus Torvalds
Commit bcf1f8c4feb9 ("Don't do "remove_from_trip" by walking the gtk data structures") made find_trip_by_idx() only work for negative indexes (positive indexes are dives), but when it removed the unnecessary test for negativity, the statement inside it should have been kept as unconditional, rather than removed with the test. Oops. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-19Don't do "remove_from_trip" by walking the gtk data structuresGravatar Linus Torvalds
They are complicated and confusing. Just use our own data structures and re-generate the gtk ones from them. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-19Don't do "remove_trip()" by walking the gtk data structuresGravatar Linus Torvalds
They are complicated and confusing. Just use our own data structures and re-generate the gtk ones from them. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-19Use the divetrip index to look up divelist trip entriesGravatar Linus Torvalds
We used to look up dive trips by their date, but these days we always create a dynamic index for a dive trip when we insert it into the divelist model, so we can use that to unambiguously match up dive trips with the dive model entries. That means that we don't get confused if we have two trips with the exact same time, which happens when you load all the test-dives, for example. Reported-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-18When only a dive trip is selected, select all the dives in the tripGravatar Linus Torvalds
This does a final pass after all the selection logic, and notices if we have dive trips that are selected, but that have no dives in them selected. In that case, we assume that the user wanted to select all dives in that trip. NOTE! This still allows a range selection that selects the dive trip entry and a few dives under the trip. If a trip has any dives selected in it, we leave that manual selection alone. So this new logic really only triggers on the case where somebody selected *just* the trip. Note: unselecting the trip still leaves the dives under it selected, because having a dive trip that isn't selected have all the dives under it be selected is normal, and we can't recognize that as some kind of special event. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-09Replace deprecated gdk_pixbuf_unref with g_object_unrefGravatar Dirk Hohndel
This appears to be the better API call to do this (according to online documentation and compiler warnings on Linux). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-09Fixed a memory leak related to the satelite iconGravatar Lubomir I. Ivanov
divelist.c:get_gps_icon_for_dive() In all callers of the function use gdk_pixbuf_unref() to release the returned GdkPixbuf (but also check for NULL). Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-09Fixed some memory leaks in divelist.c related to gtk_tree_iter_copy()Gravatar Lubomir I. Ivanov
divelist.c: get_iter_from_idx() goes trought the tree model and calls iter_has_index(), until a match is found. when the match is found we use gtk_tree_iter_copy() to make a copy of the iterator. This means that the caller of get_iter_from_idx() has to take care the de-allocation using gtk_tree_iter_free(). Also take care of the eventual: parent = gtk_tree_iter_copy(...) allocation in select_prev_dive(), select_next_dive() Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-09Finish removing accesses to first divecomputer instead of diveGravatar Dirk Hohndel
This adds watertemp and airtemp to the dive, populates them in fixup and uses them elsewhere in the code. WARNING: as a sideeffect we now edit the airtemp in the dive, but we never display this in the DIve Info notebook (as that always displays the data from the specific selected divecomputer). This is likely to cause confusion. It's consistent behavior, but... odd. This brings back the desire to have a view of "best data available" for a dive, in addition to the "per divecomputer" view. This would also allow us to consolidate the different pressure graphs we may be getting from different divecomputers (consider the case where you dive with multiple air integrated computers that are connected to different tanks - now we could have one profile with all the correct tank pressure plots overlayed - and the best available (or edited) data in the corresponding Dive Info notebook. This commit also fixes a few remaining accesses to the first divecomputer that fell through the cracks earlier and does a couple of other related cleanups. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-09Move duration to dive structure and replace accessor functionGravatar Dirk Hohndel
When starting on this quest to stop using the first divecomputer instead of data for the whole dive in commit eb73b5a528c8 ("Duration of a dive is the maximum duration from all divecomputers") I introduced an accessor function that calculates the dive duration on the fly as the maximum of the durations in the divecomputers. Since then Linus and I have added quite a few of the variables back to the dive data structure and it makes perfect sense to do the same thing for the duration as well and simply do the calculation once during fixup. This commit also replaces accesses to the first divecomputer in likely_same_dive to use the maxdepth and meandepth of the dive (those two slipped through the cracks in the previous commits, it seems). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>