aboutsummaryrefslogtreecommitdiffstats
path: root/core/qthelper.cpp
AgeCommit message (Collapse)Author
2021-07-23cleanup: replace membuffer by membufferpp in C-codeGravatar Berthold Stoeger
Thus, the membuffer data is automatically freed when going out of scope - one thing less to worry about. This fixes one use-after-free bug in uploadDiveLogsDE.cpp and one extremely questionable practice in divetooltipitem.cpp: The membuffer was a shared instance across all instances of the DiveToolTipItem. Remves unnecessary #include directives in files that didn't even use membuffer. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-04-19cloudstorage: create consistent local directory namesGravatar Dirk Hohndel
With the new names for the cloud server we'd get different local cache directory names depending on which server gets used. In order to avoid that, normalize the name before generating the hash that determines the local directory name. Additionally, the old code had an extra '/' in the URL, due to the way the URL was assembled. Again, to match the existing hash for people upgrading from older Subsurface versions, add that to our normalized name as well. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-04-19cloudstorage: some cleanup of cloud url handlingGravatar Dirk Hohndel
We know the preference is never empty, so stop testing for this. But don't maintain two different preferences with basically the same content. Instead add the '/git' suffix where needed and keep this all in one place. Simplify the extraction of the branch name from the cloud URL. Also a typo fix and a new comment. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-02-17desktop: fold ApplicationState into MainWindowGravatar Berthold Stoeger
The application state is a desktop-only thing. The mobile UI also has its application state, but that is something completely different. The last remaining user of the application state was to flag whether the planner is active. Since this has all been unglobalized, the ApplicationState structure can be moved from core to the desktop UI. And there it can be made local to the MainWindow class. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-02-17planner: pass in_planner down to TemplateLayoutGravatar Berthold Stoeger
The TemplateLayout prints different dives depending on whether the planner is active. Instead of accessing a global variable, pass the status down from the MainWindow. That's all quite convoluted, since there are multiple layers involved. On the positive side, the in_planner() function has now no users an can be removed. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-02-17planner: pass in_planner argument to decoMode()Gravatar Berthold Stoeger
To remove reliance on global state, pass an "in_planner" argument to decoMode(). Thus, calls to in_planner() can be removed. This is a more-or-less automated change. Ultimately it would probably be better to pass the current deco-mode to the affected functions instead of calling decoMode() with an in_planner parameter. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10profile: pass dive to DiveHandlerGravatar Berthold Stoeger
The DiveHandler shows a context menu where a cylinder can be chosen. This indirectly accesses the global displayed_dive variable. Remove this in a step to make the profile reentrant. The code was quite ominous: instead of simply generating the list of cylinders, a global model was reset and then accessed with Qt's cumbersome model/view API. All this trampling over global state can be removed by simply making the function that generates the list globally accessible. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-01core: add get_*_unit functions with explicit unit systemGravatar Berthold Stoeger
The get_*_unit() functions return the unit-name as set in the preferences. Add versions with a "metric" parameter. This will be used by the statistics code, which may in the future allow for binning with alternative units. All the unit-formatting functions should probably be moved away from qthelper to their own source file. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-01core: add "transparent" parameter to renderSVGIconGravatar Berthold Stoeger
The start-selection widget will need icons with a transparent background so that the icons don't stick out like a sore thumb. So far the icons rendered by this function were only used by the images on the profile and were perfectly rectangular. Therefore there was no need for this. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-01core: move renderSVGIcon() to qthelper.cppGravatar Berthold Stoeger
The renderIcon() function was used by the thumbnailer to render SVG-based icons. Move it to the global qthelper.cpp so that it can also be used by the statistics module. Add "SVG" to the name to emphasize what it is used for. For consistency also move the renderSVGIconWidth() function, which renders to a fixed width, to qthelper.cpp Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-29cleanup: remove getDivesInTrip() in qthelper.cppGravatar Berthold Stoeger
This function was not used anywhere. Moreover, remove a few unused includes from qthelper.h. Surprisingly, a number of users of qthelper.h depend on these, so readd them at the appropriate places. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-03build-system: start adding a headless buildGravatar Dirk Hohndel
Right now this doesn't do a thing, but it gives us a nice target that has far fewer dependencies and should contain enough parts to download stuff from a divecomputer and then sync that with cloud storage. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-11-17core: fix incorrect QString::asprintf/vasprintf usageGravatar Dirk Hohndel
These are static functions, they cannot be used as a method on an object to construct that object. commit aa5f2e7c73 ("cleanup: replace deprecated sprintf()/vsprintf() calls") introduced this bug in an ill-advised attempt to deal with a deprecation warning. This caused us to not print GPS coordinates in the UI. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-27cleanup: refactor subsurfacesysinfo.cppGravatar Berthold Stoeger
This used to be a copy of QSysInfo. However, once the requirement was raised to Qt5.4, this was replaced by a subclass of the original QSysInfo - which made the whole file mostly obsolete. Just use QSysInfo directly where needed. Only for windows.c, which can't call directly into Qt, keep the isWin7Or8() helper function. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-26cleanup: SkipEmptyParts syntax has changedGravatar Dirk Hohndel
Sadly, the new enum has only been available since Qt 5.14, so this is a rather ugly replacement. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-26cleanup: replace deprecated sprintf()/vsprintf() callsGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-23cleanup: remove unused function intdup()Gravatar Berthold Stoeger
That was used by the old xml-params code, which was recently replaced. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-23parser: replace params[] code by new xml_params structGravatar Berthold Stoeger
This fixes a load of memory holes, and makes the code (hopefully) more readable. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-03cleanup: use getDiveSelection() to loop over selected divesGravatar Berthold Stoeger
getDiveSelection() returns a vector of the selected dives. Use that instead of looping over the dive table and checking manually. This removes a few lines of code. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-03cleanup: replace get_trip_date_string() by get_trip_string()Gravatar Berthold Stoeger
The get_trip_date_string() formatted, as the name implies, the date of a trip. It was passed a number of parameters and had only one caller, which would also add the location if it existed. Therefore, move all that logic into the helper function and name it get_trip_string(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-21translations: initialize water type strings at run timeGravatar Berthold Stoeger
The water type strings were static and therefore passed through gettextFromC::tr() before main(). One would hope to get a warning in such a case, but this is not the case. Therefore, use the QT_TRANSLATE_NOOP macro to register the strings in Qt's translation system and translate the list when needed. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-04Implement Seac SeacSync databaser parser.Gravatar James Wobser
Dives for the seac action computer are imported by the seacsync program into two tables in an sqlite3 database. The dive information is read from the headers_dive table. The dive_data table is then queried for each dive to get samples. The seac action computer is the only current supported computer by the seacsync program. It only supports two gas mixes, so the parser will toggle between two cylinders whenever it detects a change in the active O2 mix. Dive start time is stored in UTC with a timezone offset. A helper function to read this was added to qthelper. Default cases have been added to some switch statements to assist in future development for other dive types and salinity. Example database has been added to ./dives/TestDiveSeacSync.db Signed-off-by: James Wobser <james.wobser@gmail.com>
2020-08-16core/localized-parsing: correctly handle group and decimal separatorGravatar Dirk Hohndel
We are usually showing pressures with localized group separator. And we made a total mess out of things when then re-parsing those values. This caused us to ignore start and end pressures in Subsurface-mobile when those were entered in psi and included a group separator: 2,900psi was turned into 2.900psi which we then rounded to 0 mbar. This fixes the problem by asking Qt to do the right thing instead of doing stupid separator magic. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-07-11helper functions: remove timestamp argument from gettiemzoneoffset()Gravatar Dirk Hohndel
The last user of that argument has been removed. (a random whitespace fix snuck in with this) Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-05-22cleanup: create common QDateTime -> timestamp conversion functionGravatar Berthold Stoeger
In analogy to the timestamp -> QDateTime conversion, create a common function. 1) For symmetry with the opposite conversion. 2) To remove numerous inconsistencies. 3) To remove use of the deprecated QDateTime::toTime_t() function. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-22cleanup: remove unused libc-structures from get_trip_date_string()Gravatar Berthold Stoeger
This must be an artifact from before using Qt's datetime functions. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-22cleanup: move timestampToDateTime() to qthelper.cppGravatar Berthold Stoeger
Move this function from maintab.cpp to qthelper.cpp. Since the functionality was used in numerous places, use the helper function there as well. This removes a number of inconsistencies. For example, sometime setTimeSpec(Qt::UTC) was called, even though the QDateTime object was already created with that time spec. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-22cleanup: set long and short date formats in independent branchesGravatar Berthold Stoeger
The short and long date formats where initialized in a common if-branch. However, inside the if-branch the code rechecked which of the two should be initialized. This could make sense if there was some common code between the two, but there wasn't. Therefore, make this two independent branches to avoid one nesting-level. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-07cleanup: invert control-flow when resetting the core structuresGravatar Berthold Stoeger
To reset the core data structures, the mobile and desktop UIs were calling into the dive-list models, which then reset the core data structures, themselves and the unrelated locationinformation model. The UI code then reset various other things, such as the TankInformation model or the map. . This was unsatisfying from a control-flow perspective, as the models should display the core data, not act on it. Moreover, this meant lots of intricate intermodule-dependencies. Thus, straighten up the control flow: give the C core the possibility to send a "all data reset" event. And do that in those functions that reset the core data structures. Let each module react to this event by itself. This removes inter-module dependencies. For example, the MainWindow now doesn't have to reset the TankInfoModel or the MapWidget. Then, to reset the core data structures, let the UI code simply directly call the respective core functions. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06planner: remove Bühlmann factor cacheGravatar Berthold Stoeger
The Bühlmann factors were cached in a thread-safe hashmap. It seemed somewhat dubious that entering a critical section and doing a hash-lookup would be significantly faster than a simple exp() call. Indeed, in a very cache friendly test (16 entries, tight loop) calling the factor() function 32 000 000 times from a different translation units we get: - with cache: 604 ms - without cache: 266 ms Therefore, remove the cache. Given that 32 000 000 calls take only 266 ms, it appears not sensible to try to optimize this function anyway. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-05cleanup: capitalize use dcGravatar Monty Taylor
It was suggested in a review of a previous patchset that we should capitalize the use of "use dc" to "Use DC" - but if we were going to do that we should do it everywhere, not just in the one place. This is the followup to do that. Signed-off-by: Monty Taylor <mordred@inaugust.com>
2020-05-05cleanup: Change Salty to BrackishGravatar Monty Taylor
In the code, the difference between SALTYWATER and SALTWATER is hard to see. More importantly, in the UI - Brackish is the word for water that has more salt that freshwater but less salt that seawater. The docs already use the word to clarify what is meant.
2020-05-05Grantlee: Add salinity and water type to grantlee variablesGravatar Monty Taylor
These can be useful in a printed divelog, especially if the log entry is also showing weight and exposure suit. Signed-off-by: Monty Taylor <mordred@inaugust.com>
2020-05-01cleanup: move declaration of utc_mk* functions to new subsurface-time.h headerGravatar Berthold Stoeger
No point in slurping in all of dive.h for translation units that only want to do some time manipulation without ever touching a dive. Don't call the header "time.h", because we don't want to end up in a confusion with the system header of the same name. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-01cleanup: move dive_table from dive.h to divelist.hGravatar Berthold Stoeger
This allows us to decouple dive.h and divelist.h, a small step in include disentangling. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-27cleanup: remove unused function get_divepoint_gas_string()Gravatar Berthold Stoeger
The last user was removed way back in commit 9fbd11744f1bfffbc6973e0f9483ae1630dd8722. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-24cleanup: move get_dc_nickname from qthelper.cpp to divecomputer.cppGravatar Berthold Stoeger
1) qthelper is already huge. 2) set_dc_nickname et al. is already there. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-11Merge pull request #2643 from bstoeger/cylinder4Gravatar Dirk Hohndel
First steps of cylinder-editing undo
2020-04-10media: move picture function from dive.c to picture.cGravatar Berthold Stoeger
Currently, move only those functions that do not access dive structures. 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-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-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-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-10core: make command texts available for C codeGravatar Dirk Hohndel
Create a C string (which the caller needs to free) with the executed commands in this session. The detour via the callback allows us to not make the corelib depend on the commands, which is nice for tests, export-html, and smtk2ssrf. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-06Cleanup: Move stringToList to core/qthelper.cppGravatar Berthold Stoeger
The same code was used in desktop and undo commands. Let's unify. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-01filter: remove diveContainsText()Gravatar Berthold Stoeger
This function checked a dive for a search string. Its functionality was replaced by a fulltext index. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-02-08mobile/summary: implement firstDiveDate and lastDiveDateGravatar Berthold Stoeger
Instead of transporting the global first and last dive date in the dive summary, calculate it in an external function. Since we already have time and date functions in qthelper.cpp implement those functions there. Provide a stub in QMLInterface so that QML can access these standalone functions. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-02-06Gps coordinates: be more graceful when parsing coordinatesGravatar Berthold Stoeger
Some Wikipedia pages use special (non-ASCII) unicode symbols for representing the " and ' separators. Before parsing, replace these by the ASCII symbols to enable copy & paste from Wikipedia (and other sources?). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>