aboutsummaryrefslogtreecommitdiffstats
path: root/core/divesitehelpers.cpp
AgeCommit message (Collapse)Author
2020-09-06cleanup: use taxonomy_get_value() instead of taxonomy_get_index()Gravatar Berthold Stoeger
Instead of getting the index and using that to access values, use the taxonomy_get_value() helper function. Two places are affected: 1) reverse geo-lookup 2) location filter delegate The behavior of reverse geo-lookup is changed slightly: now an empty string is likewise recognized as missing "TC_ADMIN_L3". Before, only a missing category was interpreted as such. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-06cleanup: use taxonomy_set_category() functionGravatar Berthold Stoeger
Instead of manipulating the taxonomy structures directly, use the taxonomy_set_category() function. This improves encapsulation and gives us the possibility to improve the taxonomy data structures. This concerns three places: 1) git parser 2) XML parser 3) reverse geo-lookup This improves the XML parser code slightly: The parser assumes that the value-attribute comes last (after origin and category). While it still does that, it now at least generates a warning if it encounters a value-attribute without origin- or category-attribute. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-05[Bug #2934] Geo Lookup - support for remote dive sitesGravatar Michael Werle
Some remote dive sites have no populated places (towns, cities) nearby. For such sites, we now fall back to looking up unpopulated place names, such as the reef or island name. Also some code refactorisation: the actual network access is now encapsulated in its own function removing some duplicated code handling in the reverseGeoLookup function and making it more readable. Furthermore, reverseGeoLookup() was completely refactored as most of its functionality was due to legacy requirements; the current code-base only calls this function from a single location and only with an empty taxonomy_data object. This makes the function more focussed and much simpler and more readable. Finally, a resource leak in reverseGeocde introduced in 4f3b26f9b6296273e37ec317bc68f32f94f546dc was fixed. Signed-off-by: Michael Werle <micha@michaelwerle.com>
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>
2019-08-08Cleanup: move error reporting function declarations to errorhelper.hGravatar Berthold Stoeger
Move the declarations of the "report_error()" and "set_error_cb()" functions and the "verbose" variable to errorhelper.h. Thus, error-reporting translation units don't have to import the big dive.h header file. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Undo: use QUndoStack::isClean() to determine unsaved changesGravatar Berthold Stoeger
Properly implement the unsaved-changes flag(s). Since we currently have two kinds of changes, there are two flags: 1) dive_list_changed in divelist.c marks non-undoable changes. This flag is only cleared on save or load. 2) QUndoStack::isClean() is used to determine the state of undoable changes. Every time the user returns to the state where they saved, this flag is cleared. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11Geo lookup: don't pass arguments / result via global objectGravatar Berthold Stoeger
The reverseGeoLookup() fetches dive-site data via GPS coordinates. The coordinates and the result were passed via the global "displayed_dive_site" object. To make data-flow more clear, pass data as in and out parameters instead. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11Geo lookup: make the reply a managed-pointerGravatar Berthold Stoeger
By making reply a std::unique_ptr<>, the function can be quit from any point and the reply will be freed. This is valid according to Qt's documentation as we're not deleting during signal processing. This commit fixes a leak: reply was overwritten with the address of a new object without freeing the old object. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11Geo lookup: make the QNetworkAccessManager a static objectGravatar Berthold Stoeger
According to Qt's docs, the QNetworkAccessManager is supposed to be a long-living object. Therefore, don't create one on every geo-lookup, but a single object for all geo-lookups. By making the object function-local it is only initiaized on first use. Morover this limits the amount of concurrent geo lookups. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11Cleanup: remove ReverseGeoLookupThreadGravatar Berthold Stoeger
Fetching the taxonomy from GPS coordinates was implemented in a QThread. But the only access to the main function was a direct call to run(). Thus, the thread was *never* started. The function call was always asynchronous [it was using an event loop though, so the UI doesn't hang]. Notably this means that the signals connected to the thread would never fire. And the spinner would never be activated. Thus: 1) Turn the thread into a simple function. 2) Remove the spinner. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-06-04Cleanup: fold core/helpers.h into core/qthelper.hGravatar Berthold Stoeger
helpers.h included qthelper.h and all functions declared in helpers.h were defined in qthelper.h. Therefore fold the former into the latter, since the split seems completely arbitrary. While doing so, change the return-type of get_dc_nichname from "const QString" to "QString". Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-05-14Core: introduce new subsurface-string headerGravatar Dirk Hohndel
First small step to shrinking dive.h. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-03-14Cleanup: introduce copy_qstring() functionGravatar Berthold Stoeger
strdup(qPrintable(s)) and copy_string(qPrintable(s)) were such common occurrences that they seem worthy of a short helper-function. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-06Remove unused urlsGravatar Jan Mulder
They are unused, and a relic from earlier plans. Just remove. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-10-16Reverse geo lookup string for http://api.geonames.org correctedGravatar Stefan Fuchs
Language selection should now work again with string "lang=xx". Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-10-04White space and clarifying bracesGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-10-04Whitespace changeGravatar Dirk Hohndel
This is just the indentation change for the code that was inside the loop before. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-10-04Simplify the geo reverse lookup functionGravatar Dirk Hohndel
We never actually create a list of dive sites for which we call the reverse lookup service, it's always just displayed_dive_site. So make this all much simpler and just go straight for that. This commit removes a loop, but doesn't change the indentation of the code inside the loop to make it easier to see what was changed. That whitespace change will be in my next commit. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-10-04fixup taxonomy typeGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-06Make compile with Qt developer buildsGravatar Alex Blasche
subsurface/core/divesitehelpers.cpp: In member function 'virtual void ReverseGeoLookupThread::run()': subsurface/core/divesitehelpers.cpp:128:12: error: invalid use of incomplete type 'class QDebug' qDebug() << "no reverse geo lookup; geonames returned\n" << fullReply; ^ Signed-off-by: Alex Blasche <alexander.blasche@qt.io>
2017-04-29Add SPDX header to remaining core filesGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-04Move subsurface-core to core and qt-mobile to mobile-widgetsGravatar Dirk Hohndel
Having subsurface-core as a directory name really messes with autocomplete and is obviously redundant. Simmilarly, qt-mobile caused an autocomplete conflict and also was inconsistent with the desktop-widget name for the directory containing the "other" UI. And while cleaning up the resulting change in the path name for include files, I decided to clean up those even more to make them consistent overall. This could have been handled in more commits, but since this requires a make clean before the build, it seemed more sensible to do it all in one. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>