summaryrefslogtreecommitdiffstats
path: root/core
AgeCommit message (Collapse)Author
2020-04-07core: split out create_gas_change_event() from add_gas_change_event()Gravatar Berthold Stoeger
For undo, we want to create gas change events without adding them immediately to the dive computer. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07cleanup: move add_gas_switch_event to dive.cGravatar Berthold Stoeger
Since all the other event-functions are also defined there. Ultimately, we should probably move them to their own event.c translation unit. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07undo: implement renaming of eventsGravatar Berthold Stoeger
There is a slight complexity here owing to the fact that the profile works on a copy of the current dive: We get a copy of the event and have to search for the original event in the current dive. This could be done in the undo command. Nevertheless, here we do it in the profile so that when in the future the profile can work on a non-copied dive we can simply remove this function. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07undo: replot profile if event changedGravatar Berthold Stoeger
Add a DiveListNotifer::eventsChanged signal, which is emitted when the events changed. This is very coarse, at it doesn't differentiate between signal addition / editing / deletion. We might want to be finer in the future. Catch the signal in the profile-widget to replot the dive if this is the currently displayed dive. Reuse the cylindersChanged() slot, but rename it to the now more appropriate profileChanged(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07core: add remove_event_from_dc() functionGravatar Berthold Stoeger
We have a remove_event() function that 1) frees the event 2) works on the current divecomputer 3) compares the events because the profile has copies of events However, for undo commands 1) we want to keep the event so that we can readd it later 2) we have to work on arbitrary divecomputers 3) we don't work with copies of events Therefore, create a new remove_event_from_dc() function that does all that. Moreover, make the event argument to remove_event() const to (slightly) point out the difference in the API. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07core: split add_event() in two partsGravatar Berthold Stoeger
add_event() creates and adds an event from the given parameters. For undo, we want to do these separately, therefore split this function in two parts: create_event() and add_event_to_dc(). Keep the add_event() function for convenience. Moreover, keep the remember_event() call in there, so that undo-commands can call remember_event() once, not on every undo/redo action. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07cleanup: use SAMPLE_EVENT_BOOKMARK in add_event() callsGravatar Berthold Stoeger
In two cases we were passing the magic value 8 instead of the symbolic SAMPLE_EVENT_BOOKMARK. Use the symbolic version instead. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07undo: reorder cylinders on remove-cylinder undo/redoGravatar Berthold Stoeger
The cylinders in the events must be reordered if we remove a cylinder. To avoid duplication of code, move the reordering function into qthelper.cpp, though it might not be ideal there. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07undo: add cylinder undo commands by copy & pasteGravatar Berthold Stoeger
Do a simple copy & paste followed by a simple search & replace to generate cylinder undo commands from weight undo commands. Obviously, this is still missing the necessary code to keep the dive-data consistent after cylinder editing. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07cleanup: move fill_default_cylinder from planner.c to equipment.cGravatar Berthold Stoeger
Moreover, move the declaration from dive.h to equipment.h. The result is a) more consistent and b) more logical. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07core: add create_new_cylinder() functionGravatar Berthold Stoeger
Turn the code in CylindersModel that creates a new cylinder for addition into its own function to avoid code duplication. This will be used from the undo commands. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07core: introduce set_cylinder() functionGravatar Berthold Stoeger
We have a set_weightsystem() function. For symmetry, introduce a set_cylinder() function so that we can more-or-less copy&paste the weightsystem undo code for cylinder undo. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07core: make free_cylinder() globalGravatar Berthold Stoeger
The cylinder undo commands will keep a copy of a cylinder and therefore need the ability to free a cylinder object. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07core: introduce clone_cylinder() functionGravatar Berthold Stoeger
We have a clone_weightsystem function. For symmetry, introduce a clone_cylinder() function so that we can more-or-less copy&paste the weightsystem undo code for cylinder undo. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-04core/fulltext: give progress update while populating indexGravatar Dirk Hohndel
Especially with large dive logs this will prevent the user from thinking that the app is hung. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-04-04core: add additional notification callbackGravatar Dirk Hohndel
Especially on slower devices with a large dive list the startup time has become really long. This callback allows us to give the user an idea of what the app is doing during that time. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-04-04cleanup: copy saved_git_id, don't use local bufferGravatar Berthold Stoeger
In an attempt to reduce the number of global variables, don't use a local buffer to store the currently loaded git-id. The git-id itself is still a global variable, which in the future can hopefully be encapsulated in a "struct File" or similar. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-24cleanup: fix unitialized valueGravatar Dirk Hohndel
Fixes CID 355179 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-22translations: use German translation for non-Swiss German localesGravatar Dirk Hohndel
Unless a German speaker explicitly asks for the Swiss localization, give them the German localization. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-22cleanup: don't allocate translators on heapGravatar Berthold Stoeger
This is pointless bike-shedding: instead of allocating the QTranslators on the heap an assigning them to a variable at translation-unit scope, we can simply generate them as static objects. That makes 1) two fewer lines of code 2) the translator-resources are properly released when the application closes. Not that either of these points would make *any* difference. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-22cleanup: remove memory leak in initUiLocale()Gravatar Berthold Stoeger
The prefs.locale.lang_locale field was overwritten without free()ing the old value. Not that the function would be called numerous times, but as a matter of principle... Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-22cleanup: split uiLanguage() in two functionsGravatar Berthold Stoeger
The uiLanguage() function was used for two purposes: to initialize the language related preferences and to read the current language. To make things more easy to follow, split this function in two: one for initializing, one for getting the current language. Moreover, don't return the current locale in an out-parameter as there is already a function to do that [getLocale()]. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-22locale: store locate to preferences after fixing up mac-weirdnessGravatar Berthold Stoeger
In uiLanguage() the preferences fields are initialized and there is fixup for a MacOS indiosyncrasy. For some reason the uncorrected value is written to the preferences. Let's store the corrected value instead. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-22cleanup: don't call uiLanguage() in qPref::loadSync()Gravatar Berthold Stoeger
uiLanguage() initializes the language fields from the preferences values. It is unclear why this function is called in qPref::loadSync() *before* the fields are loaded from disk. It can only initialize to the default values anyway. After qPref::loadSync() uiLanguage() is called again so that everything can be initialized with the correct perferences values. Remove the first call. If things break, let's fix them in a sensible way. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-21Revert "core: use set_lang_locale to modify prefs.locale.lang_locale"Gravatar Berthold Stoeger
This reverts commit 573a4a5e2da9531fbaa9e82da57131edc691a851. The commit broke setting the language in the desktop preferences: Instead of setting the locale in the prefs struct, the locale is set via qPrefLanguage. However, that saves the default language (extracted from the system) to disk. Now when the language is read from the preferences, we get that default value. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-20Ignore invalid dives in statisticsGravatar Berthold Stoeger
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-20Core: consider invalid flag when adding divesGravatar Berthold Stoeger
Adding dives uses the number of the last dive to create a new dive number. Ignore invalid dives. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-20Filter: hide invalid divesGravatar Berthold Stoeger
Hide invalid dives if prefs.display_invalid_dives is false. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-20Undo: implement invalidate-dive commandGravatar Berthold Stoeger
Connect command to context menu. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-20Core: introduce invalid flag for divesGravatar Berthold Stoeger
Implement reading/writing the flag from/to XML/git. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-19cleanup: fix mis-spelling of UCT in comments as wellGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-19cleanup: remove unnecessary includeGravatar Berthold Stoeger
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-17cleanup: remove record_dive() functionGravatar Berthold Stoeger
No user left. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-17git: load into arbitrary dive tablesGravatar Berthold Stoeger
The git parser loads into the global dive table, even if it is called indirectly via parse_file(). However, parse_file() may be given a different table. Fix this by extending the git parser state. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-17mobile/edit: don't add dive site twice to tableGravatar Berthold Stoeger
When editing a dive on mobile we might have to create a new dive site. That site is added to the global dive site table in the undo command. However, the code in QMLManager created the dive site with create_dive_site*() functions, which already adds it to the table. The undo command then added the dive site again leading to a hang of the application. To solve this problem, create new alloc_dive_site*() functions that do the same as create_dive_site*() but do not add it to the table. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-16git: return strdup()ed empty string on error in pop_cstringGravatar Berthold Stoeger
The pop_cstring() function is used by the git parser to duplicate a quoted string. On error, it returns an empty string literal. Since the caller expects a copied string and takes ownership of that string, it will ultimately be freed. Concrete example: a log with erroneous cylinder data was opened getting such an empty string literal as description. On closing or syncing with the cloud, the dive is freed, leading to a free of the string literal -> crash. Return a copy of the empty string instead. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-16android/usb: better memory managementGravatar Dirk Hohndel
Instead of relying on the std::vector staying unchanged and not freeing its members, instead keep a copy of the object in our DCDeviceData class. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-16android/usb: simply restart the download after receiving permissionGravatar Dirk Hohndel
If the user tries to download from a device that he hasn't given the app permission to read from, Android will pop up a dialogue asking for that permission. With this after giving the permission we continue (well, technically, restart) the download which is likely the expected behavior. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-16android/usb: remove "autoselect driver" option for unknown VID/PIDsGravatar Christof Arnosti
Signed-off-by: Christof Arnosti <charno@charno.ch> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-16android/usb: pass in the UsbDevice when downloadingGravatar Dirk Hohndel
This finally allows us to download from not just the first device, but specifically the device that the user picks. Passing the object through a void pointer is not nice - but since this traverses C code other solutions (like passing an index into the list) seemed even worse. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-16android/usb: pass the usbDevice for intent handlingGravatar Dirk Hohndel
Instead of creating a string with all the object information, simply pass the actual object to the C++ code. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-16android/usb: remove alternative way of scanning for devicesGravatar Dirk Hohndel
We now always create a list of usb devices that doesn't list a driver for known devices, and adds multiple entries with each of the drivers for devices that are unknown to us. This removes some debugging output in the ..._open() function as well. This could be combined with Christof's earlier commit. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-16android/usb: add helper to recognize chipsets known to usGravatar Dirk Hohndel
This will allow us to know when we can guess the driver. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-16android/usb: guess the actual manufacturer and productGravatar Dirk Hohndel
For a small number of dive computers we can actually figure out the real information which we can then later show to the user. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-16usb-serial-for-android: More fields in device descriptorGravatar Christof Arnosti
As discussed in issue #2657, there are now more fields about the usb device information in android_usb_serial_device_descriptor. Additionally, the user-facing string now makes more sense: "vendor [<bus# as integer>:<dev# as integer>]" Where vendor is as reported by android, but shortened to 16 characters. Examples: FTDI [1:2] Silicon Labs [1:4] Signed-off-by: Christof Arnosti <charno@charno.ch> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-16usb-serial-for-android: Use correct format spezifier for size_tGravatar Christof Arnosti
Signed-off-by: Christof Arnosti <charno@charno.ch>
2020-03-16android usb serial: Prepare device / driver selectGravatar Christof Arnosti
This commit contains the serial_android_usb part of the changes proposed in issue #2657. What's implemented: - A data structure that contains all the data that can be used to describe an usb device (including user-facing string). - A function to get a list of all attached usb devices (optionally with selectable driver class). - Changes in the serial_android_usb_open-function and in the Java part to use the information about the usb device and optionally selected driver when connecting. This commit keeps compatibility with the current UI-Code in the case that only one USB-Device is connected. If two devices are connected, only the first one is tried. There are still some small things to do: - Change the user-facing string to something more descriptive. - Parts which aren't uesd anymore when the UI-Part is implemented are simply marked as obsolete (to keep compatibility for now). But generally it seems to work. [Dirk Hohndel: some white space / coding style adjustments] Signed-off-by: Christof Arnosti <charno@charno.ch> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-14iostream: fix incorrect rfcomm error case when writingGravatar Linus Torvalds
This is the exact same case as the previous commit, just for the writing side. Once again, it's the subsurface rfcomm iostream code that can return DC_STATUS_SUCCESS with a byte count of zero when something goes wrong with the write. And once again, our libdivecomputer iostream code didn't try to be robust and protect itself from that case. The fix is equivalent, although slightly simpler, since the write side doesn't have the whole timeout issue. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-03-14iostream: fix incorrect rfcomm error case when readingGravatar Linus Torvalds
We had two independent bugs here, both of which needed to fire for this to cause a problem. This fixes both of them. The first bug was that our rfcomm code would return DC_STATUS_SUCCESS with a zero-sized read when a timeout happened, or when the rfcomm socket had disconnected. That makes absolutely no sense. We should return DC_STATUS_TIMEOUT on timeout, and DC_STATUS_IO if the socket has disconnected without any data. The fix to this is to make the whole rfcomm iostream read logic much simpler: there's no need to loop at all for partial results, because the libdivecomputer iostream side will do the loop for us (and handle partial results much better: it knows if the target backend can handle those partial results or not). The second bug was in our libdivecomputer iostream read() function, which reacted very badly to this bad return value. This updates our libdivecomputer branch to one that is more careful about things. Reported-by: linuxcrash <albin@mrty.ch> Debugged-by: Jef Driesen <jef@libdivecomputer.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-03-12cleanup: remove current_dive parameter from divesSelected signalGravatar Berthold Stoeger
The diveListNotifier.divesSelected() signal is used to inform the models of a selection change. It sent the current dive as a second parameter. This is redundant, because the only sender of the signal sets current_dive just before sending the signal. Remove the parameter, which appears to be an artifact. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>