aboutsummaryrefslogtreecommitdiffstats
path: root/core
AgeCommit message (Collapse)Author
2019-01-09Core: keep trips in table(s)Gravatar Berthold Stoeger
Currently, all trips are kept in a linked list. Replace the list by a table in analogy to dive_table. Use this to keep the trip_table sorted as suggested by dump_trip_list(). When inserting a trip into the table do that after adding the dives, to avoid warnings coming out of dump_trip_list(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-09Core: fix dump_trip_list() functionGravatar Berthold Stoeger
In 64e6e435f82801f4f440ef5b1caf58a91a7c9929 the trip->when field was replaced by a function. This forgot to adapt dump_trip_list(), which is only compiled if DEBUG_TRIP is defined. Fix the function. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-09Core: macroize dive_table functionsGravatar Berthold Stoeger
Generate dive table functions by macros so that they can be reused for trip tables. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-09Core: Rename functions to more generic namesGravatar Berthold Stoeger
Rename - dive_get_insertion_index() -> dive_table_get_insertion_index() - unregister_dive_from_table() -> remove_from_dive_table() - get_idx_in_table() -> get_idx_in_dive_table() - sort_table() -> sort_dive_table() This will make it more straight-forward to generate these functions from macros. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-09Cleanup: Make add_dive_to_table local to divelist.cGravatar Berthold Stoeger
This function was not used outside of divelist.c, therefore make it local. Moreover rename it to add_to_divetable so that the name is generic and can be generated by a macro. Moreover, remove the special case idx = -1, which would determine the insertion index. Instead let the single caller who used this feature do this. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-09Dive list: add table parameter to autogroup_dives()Gravatar Berthold Stoeger
Currently autogroup_dives() groups all dives in the global dive list. Add a table parameter so that dives in any table can be grouped. Thus it will be possible to pre-group dives on import, which will be used for undo of import. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-09Core: move autogroup() into divelist.cGravatar Berthold Stoeger
After loading or importing, the caller usually called autogroup() to autogroup dives if so wished by the user. This has already led to bugs, when autogroup() was forgotten. Instead, call autogroup() directly in the process_loaded_dives() and process_imported_dives() functions. Not only does this prevent forgetting the call - it also means that autogrouping can be changed without changing every caller. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-08Filter for logged/planned divesGravatar Robert C. Helling
Add filter for dives having a planned dive computer or a logged dive computer. Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-01-08Helper function to determined planned divesGravatar Robert C. Helling
... to reduce code duplication. Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-01-07Dive sites: don't delete unused dive sites on saveGravatar Berthold Stoeger
Unused dive sites were deleted on save. This clashed with the undo system in the following scenario: 1) Delete single-use dive site. 2) Save (dive site deleted) 3) Undo (reference to freed dive site) Therefore, as a quick-fix, keep the referenced dive site around. Note that this also means that empty dive sites must not be deleted, as it might refer to a dive in the undo system. Instead only clear references to empty dive sites in the global dive table. Factor this functionality out, as it was common to the XML and git savers. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-07Merge branch 'shearwater_cloud' of https://github.com/mturkia/subsurfaceGravatar Dirk Hohndel
2019-01-03Use state structure for sample rate infoGravatar Miika Turkia
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2019-01-01Use correct value for PO2Gravatar Miika Turkia
averagePPO2 appears to be correct value instead of currentPPO2SetPoint. Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2018-12-31Grab correct setpoint on Shearwater cloud importGravatar Miika Turkia
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2018-12-30Use different time field as it seems to be more correctGravatar Miika Turkia
The starTimestamp is 4 hours apart on 2 different DCs within the sample log. DiveDate on the dive_logs table seems to be correct, but must be converted from human readable format. Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2018-12-29Sample rate varies between divesGravatar Miika Turkia
Seems that Shearwater cloud stores sample rate into the database and it is not constant within the log. Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2018-12-29Initial support for Shearwater CloudGravatar Miika Turkia
This works to some extent to part of a sample log I received. However, still quite a bit more work is needed. Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2018-12-29Shearwater import: dive id might be large than intGravatar Miika Turkia
I encountered this while implementing Shearwater Cloud import, but it makes sense to increase the size for dive id for Shearwater Desktop as well. Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2018-12-29windows.c: fix wrong usage of wcslen() for utf8 conversationGravatar Lubomir I. Ivanov
wcslen() returns the number of characters in a wchar_t string. In the case of WideCharToMultiByte() an estimate for the size of the utf8 buffer is needed. Using wcslen() is incorrect for such a buffer, because for any non-ASCII character the estimate will be off by 1 byte. Call the following instead to obtain the proper UTF8 buffer size for the conversation: WideCharToMultiByte(CP_UTF8, 0, utf16, -1, NULL, 0, NULL, NULL); Also fix some missing "\n" in fprintf() calls. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2018-12-27Core: fix BT on Linux, workaround Qt bug on 5.12.0Gravatar Jan Mulder
After upgrading to Qt 5.12.0, download over BT from a DC did not work any more. On the console the message "Connecting to port is not supported (Uuid required)". Linus noticed earlier that we do rather strange processing in this part of the code related to selecting port 1 or port 5. This all seems not needed (any more), but broader testing is advised. This being stripped from the code, the mentioned error from Qt persisted. That is strange in itself, as we did not reference port numbers any more. Step 2 in this commit is actually using an uuid to the call to connectToService. Choosing an uuid seems relatively straightforward as we can use the same one we already use for Android. That is the default BT RFCOMM Serial Port Profile uuid. Interestingly, when changing to this uuid we run immediately in a Qt runtime error telling us "QDBusPendingReply: type ManagedObjectList is not registered with QtDBus.". For these 2 unexpected Qt messages, QTBUG-72742 was made. Studying the Qt source code at this point reveals a possible workaround. Simply create a local QBluetoothLocalDevice object, which, behind the scenes registers the Qt internal ManagedObjectList with QtDBus. In the meantime, Qt agrees that QTBUG-72742 is valid, and that a fix is to be expected in a future version. At that point in time, the declaration of the QBluetoothLocalDevice can be deleted again. In the end, interfacing over BT works again. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-12-23Bluetooth: all states other than HostPoweredOff qualify as validGravatar Jan Mulder
This is an attempt to fix issue #1896. While this seems a Qt issue in combination with very specific Android devices, this might be a fix. Do not check for a very specific state of the local BT controller, but just check if it is powered on. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-12-23Cleanup: remove unused parameter was_autogenGravatar Berthold Stoeger
In commit 6bf4120dbbf7be1b9267e0e86f3948b77870ea71 the trip-flags were replaced by a simple boolean. This made the was_autogen parameter to the remove_dive_from_trip() and unregister_dive_from_trip() functions unused. Remove these parameters. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-12-21core: recognize Oceanic Pro Plus X over BLEGravatar Dirk Hohndel
Just like with the Aqualung i770R in 7697003498 this name follows the pattern of a model number in ASCII encoding, followed by the serial number of the device. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-12-17Import: unglobalize downloadTableGravatar Berthold Stoeger
To make data flow more clear, unglobalize the downloadTable object. Make it a subobject of DownloadThread. The difficult part was making this compatible with QML, because somehow the pointer to the download-table has to be passed to the DiveImportedModel. Desktop would simply pass it to the constructor. But with objects generated in QML this is not possible. Instead, pass the table in the repopulate() function. This seems to make sense, but for this to work, we have to declare pointer-to-dive-table as a Q_METATYPE. And this only works if we use a typedef, because MOC removes the "struct" from "struct dive_table". This leads to compilation errors, because dive_table is the symbol-name of the global dive table! Sigh. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-12-17Cleanup: make DCDeviceData a "normal" singletonGravatar Berthold Stoeger
DCDeviceData was using that weird pattern where the instance variable was set in the constructor. There is no apparent reason to do so, therefore convert to a "normal" singleton. Access that directly in QMLManager instead of saving it in a member variable first. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-12-17Core: remove count_dives_with_*() functionsGravatar Berthold Stoeger
The simplified filter-widget doesn't present lists of existing values with counts. Thus, a whole slew of count_dives_with_*() functions can be removed. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-12-17Show average max depth in yearly statisticsGravatar Robert C. Helling
this was requested in #1854 and I think this suggestion makes sense Fixes #1854 Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-12-14Cleanup: detangle unregister_dive() and delete_single_dive()Gravatar Berthold Stoeger
These two functions were called in different contexts: - unregister_dive(): from the undo-commands to remove the dive from the global dive table, but not delete it. The dive was already removed from its trip. - delete_single_dive(): from non-undo code. Most of it not in use and removed in a sibling-commit. Here, the dive is supposed to be removed from its trip and a new selection is calculated. delete_single_dive() calls unregister_dive(), which removes the dive from its trip. Move remove_dive_from_trip() from the former to the latter and make both functions independent. Instead of deleting the dive explicitly in delete_single_dive(), call the delete_dive_from_table() function. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-12-14Core: don't remove dive from trip in add_dive_to_trip()Gravatar Berthold Stoeger
All callers of add_dive_to_trip() work on freshly generated dives, with one exception, that was redundant anyway. Therefore it is not necessary to remove the dive from a potential previous trip. Move the responsibility of removing the dive from a trip to the caller, respectively remove the redundant call. Add a warning message in the case that trip is set. Background: On import (either download or file-import) we might not want to add trips to the global trip-list. For example to enable undo of import but more generally to detangle that data flow. Thus, add_dive_to_trip() should not mingle with the global trip-list, which it has to do if a trip is deleted because the old dive was removed. Analysis of the add_dive_to_trip() callers: 1) core/dive.c pick_trip(): called on freshly generated merged dive. finish_split(): called on two freshly generated split dives. 2) core/divelist.c create_and_hookup_trip_from_dive(): called on freshly downloaded dive in dive_cb(). called on freshly downloaded dive in record_uemis_dive(). autogroup_dives(): called on dive from get_dives_to_autogroup(), which only finds dives that are outside of trips. combine_trips(): unused - removed in sibling commit. try_to_merge_into(): this call was actually erroneous - dive was already added to trip in try_to_merge(). Remove call. 3) core/libdivecomputer.c dive_cb(): called on freshly downloaded dive. 4) core/uemis_downloader.c record_uemis_dive(): called on freshly downloaded dive. 5) core/load_git.c create_new_dive(): called on freshly allocated dive. 6) core/parse.c dive_end(): called on freshly parsed dive. 7) desktop-widgets/command_divelist.cpp DiveListBase::addDive(): called on dive which is newly added to core. moveDiveToTrip(): called on dive that was removed from trip a few lines above. 8) mobile-widgets/qmlmanager.cpp QMLManager::undoDelete(): called on dive where divetrip was reset in the previous line. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-12-14Cleanup: remove split_dive_*() functionsGravatar Berthold Stoeger
In 302f6adb79681da3fe53336f1e4c7525f46fd47d dive-splitting was made undo-able. To this goal, the dive-splitting functions were split in two types: Those that operate directly on the divelist and those that only allocate the dives. The former are not in use anymore, therefore remove them. Since only the latter remain, remove the "_dont_insert" appendix of the name. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-12-14Cleanup: remove merge_two_dives() functionGravatar Berthold Stoeger
In 014c04f8bd30740e7711f3b3a01619fd27b5b613 merging dives was included in the undo-system. This made the merge_two_dives() function caller-less. Remove it. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-12-14Cleanup: remove remove_autogen_trips() functionGravatar Berthold Stoeger
In f427226b3b605523bc8285dbdaaa7f6993af6e6a autogrouping / removal of autogrouping was moved into the undo-machinery. This made the remove_autogen_trips() function caller-less. Remove it. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-12-14Cleanup: remove combine_trips() functionGravatar Berthold Stoeger
In f427226b3b605523bc8285dbdaaa7f6993af6e6a a combine_trips_create() function was introduced that combined trips without deleting the old trips. This was necessary for making combine-trips function undo-able. The old combine_trips() function is not used anymore. Therefore remove it. Rename the combine_trips_create() function to combine_trips() as no differentiation is needed anymore. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-12-13Dive media: add media to closest diveGravatar Berthold Stoeger
Currently, when selecting "Load media files even if time does not match the dive time", the media are added to *all* selected dives. Instead add it to the closest dive. This seems like the less surprising behavior. Of course now if the user really wants to add a media file to multiple dives, they will have to do it manually. To avoid a messy interface, this is solved by moving the iterate- over-selected-dives loop to the core. Thus, a helper-function can be made local to its translation unit. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-11-24Cleanup: remove EMPTY_DIVE_STRINGGravatar Berthold Stoeger
EMPTY_DIVE_STRING used to be a string-literal representing missing information ("--"). In 6985c123d412d3223618247e2fcc733cd99bb842 it was replaced by the actual empty string. Using a literal to represent the empty string seems a bit pointless, therefore remove it completely. Notably: QString(EMPTY_DIVE_STRING) -> QString() if (temp.isEmpty()) temp = EMPTY_DIVE_STRING; -> noop if (s == EMPTY_DIVE_STRING) -> if (s.isEmpty()) Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-11-23Cleanup: remove redundant 'extern "C"' in dive.hGravatar Berthold Stoeger
In dive.h there was a redundant 'extern "C"' block defined inside another 'extern "C"' block. Remove. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-11-23Filter: use hidden_by_filter also on mobileGravatar Berthold Stoeger
Desktop used the hidden_in_filter flag in struct dive, mobile used its own vector plus a new showndives member in struct dive_trip. Unifiy these to use the same core-facility, viz. hidden_by_filter. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-11-23Core: move is-single-day-trip and count-shown functions into coreGravatar Berthold Stoeger
These functionality was used by the desktop filter. To unify desktop and mobile, move it into two new functions in divelist.c Since one of them is the only caller of is_same_day() move that likewise into divelist.c and make it of static linkage. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-11-23Mobile: don't format trip heading for all divesGravatar Berthold Stoeger
QML's ListView uses the "section" property to test if items belong to the same section. Apparently, this must be a string and therefore we can't pass e.g. a dive-trip object. Therefore a specially formatted string was passed in, which was guaranteed to be unique (contained the dive-trip pointer value) and the fully formatted trip-title and short-date. The disadvantage of that approach is that the formatting is performed for every dive and not every trip. Perhaps not a problem now, but it makes it for example necessary to cache the number of filtered dives. To be more flexible, pass in only the pointer value formatted as hexadecimal string and provide a function to convert that string back to a trip-pointer (in the form of a QVariant, so that it can be passed to QML). Moreover provide two functions for formatting the title and the short-date. The three new functions are members of DiveListSortModel. This might not be the perfect place, but it is easy to reach from the DiveListView. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-11-23Cleanup: remove DiveObjectHelper::trip() functionGravatar Berthold Stoeger
The DiveObjectHelper::trip() function was 1) Misnamed: it returned the *location* of the trip 2) Not used outside of DiveObjectHelper Remove it. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-11-23Cleanup: make "struct dive *" and "struct dive_trip *" Qt metatypesGravatar Berthold Stoeger
Just as we did for pointer to struct dive_site, make pointers to struct dive and struct dive_trip "Qt metatypes". This means that they can be passed through QVariants without taking a detour via void *. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-11-22Improve OTU calculationsGravatar willemferguson
Implement the protocol in Erik Baker's document "Oxygen Toxicity Calculations". This code uses a third-order polynomial approximation of Baker's equation 2. Provision is made for PSCR and CCR dive logs and dive plans. In the case of dive logs, the values of o2 sensors are used if there are data from such sensors. For CCR only the data from the first O2 sensor is used even if there are more than one sensor. This is a potential weakness, but this function is probably NOT the place to calculate mean o2 values accross all sensors and to emulate voting logic to reject info from aberrant sensors. Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za> Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-11-21Git parser: don't produce user-visible error on git parsingGravatar Berthold Stoeger
In 64e6e435f82801f4f440ef5b1caf58a91a7c9929 the when field of struct trip was removed. Accordingly it was not read from git repositories. This produced a large amount of user-visible error messages. Reinstate the trip-date and time parsing functions, but ignore the value. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-11-21Core: fix crash concerning removal of dives from tripsGravatar Berthold Stoeger
Commit 6b283e598a3a08c6133d66b5d5617370296e7d0e replaced the linked list of dives in a trip by a table. Embarassingly, on dive deletion the index of the dive in the table was compared for "!= 0" instead of ">= 0". Thus, the first dive of a trip wouldn't be deleted, which ultimately led to a crash, as different parts of the code were now in disagreement over whether the trip is empty or not. Fix the comparison. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-11-20Core: replace tripflag by notrip booleanGravatar Berthold Stoeger
The only remaining use of the tripflag was to mark dives that were removed explicitly from a trip, i.e. shouldn't be autogrouped. Therefore replace the enum by a simple boolean. Currently, there is no way of unsetting the notrip flag. But this shouldn't result in a user-visible change. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-11-20Core: remove ASSIGNED_TRIP trip flagGravatar Berthold Stoeger
The distinction between ASSIGNED_TRIP and IN_TRIP was used to prefer non-autogenerated trips on merging of dives. But owing to bit rot this seem to have worked only partially anyway: The IN_TRIP field was set in create_and_hookup_trip_from_dive() and immediately overwritten in add_dive_to_trip() called in the next line. Instead, use the trip->autogen flag to check for priority and remove the ASSIGNED_TRIP flag alltogether. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-11-20Core: remove two unused macrosGravatar Berthold Stoeger
The UNGROUPED_DIVE and DIVE_IN_TRIP were never used. Remove them. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-11-19Uemis downloader: free ans_path on errorGravatar Berthold Stoeger
In a few instances, the ans_path was not freed on error. Fix them. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-11-19Warnings: silence new gcc warnings in uemis-downloader.cGravatar Berthold Stoeger
Since upgrading to gcc 8.2 it produces noisy warnings about potentially truncated strings. It doesn't recognize that filenr can never become >4000. So clamp it down explicitly. Do this by adding a function that does the assembly of the filename path. Adding unnecessary code to silence compiler warnings is dubious, but in this case it might be reasonable. Fix a second instance by increasing the stack-allocated buffer to 32 bytes. Hopefully nobody has more divespots than would fit in a 9-decimal digit number! Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-11-18Parser: add dive to trip at end of dive-parsingGravatar Berthold Stoeger
When adding the dive to its trip before having filled out "when", the dive gets added at the first position (when=0), which is usually not correct. Instead, add the dive to its trip when all fields are correctly filled out. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>