aboutsummaryrefslogtreecommitdiffstats
path: root/core/taxonomy.c
AgeCommit message (Collapse)Author
2020-09-06cleanup: make taxonomy_index_for_category() local to taxonomy.cGravatar Berthold Stoeger
This helper function is not used outside taxonomy.c anymore. Let's hide this implementation detail. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-06cleanup: create taxonomy_get_value() functionGravatar Berthold Stoeger
This is the counter-part to taxonomy_set_value(). Let taxonomy_get_country() be the first user of the function. If a category doesn't exist, return NULL. Small addition: make taxonomy_get_countr() take a const argument. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-06cleanup: use taxonomy_index_for_category() in taxonomy_set_category()Gravatar Berthold Stoeger
Instead of recoding the "search for category" loop, reuse the already existing functionality. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-06cleanup: make alloc_taxonomy local to taxonomy.cGravatar Berthold Stoeger
The alloc_taxonomy()/free_taxonomy() interface was exceedingly strange. The former gave a "struct taxonomy", the latter took a "struct taxonomy_data". To make things worse, is appears as if the names "taxonomy" and "taxonoma_data" are reversed: the latter contains the former. In any case, the alloc_taxonomy() call is not needed anymore from outside taxonomy.c, as these memory-management details are now hidden in accessor functions. Therefore, make the function local to taxonomy.c. Moreover, rename it to "alloc_taxonomy_table()" and let it take a "taxonomy_data" structure for symmetry with "free_taxonomy()". Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-06cleanup: copy string in taxonomy_set_[country|category]Gravatar Berthold Stoeger
These functions were taking a const char *, yet taking ownership of the value. Moreover, taking ownership of strings is rather unusual in C-style APIs. Let's copy the string instead. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-06cleanup: add helper function to set taxonomy categoryGravatar Berthold Stoeger
Setting a taxonomy category was cumbersome: the caller had to make sure that the category-table was allocated. Introduce a helper function to make that simpler. Make taxonomy_set_country() the first caller of the new function, since it is just a special case with category = TC_COUNTRY. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-06cleanup: leak fix in taxonomy_set_country()Gravatar Berthold Stoeger
When overwriting a country, the old string was not freed. Fix this. Contains an unrelated coding-style fix: use braces if code block contains more than one line. 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>
2018-10-13Dive site: use own copy of taxonomy in dive-site-edit widgetGravatar Berthold Stoeger
The dive-site-edit widget uses a copy of the to-be-edited site to compare with old values. Generally, this seems overkill (the original dive-site can be used for such a comparison). But one place where it can't simply be removed is the taxonomy, because the widget needs a place to store the unsaved data. Change the code to use an explicit taxonomy structure instead of the one provided in the copy. This should ultimately allow removal of the latter. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-10-07Fix two bugs in taxonomy_set_countryGravatar Dirk Hohndel
The random coincidence that this code actually ended up working in my tests is weird. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-10-05Prevent crash when adding country to dive siteGravatar Dirk Hohndel
We need to make sure that the taxonomy information has been allocated before assigning values to it... Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-10-04White space and clarifying bracesGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-10-04Add taxonomy helper functionsGravatar Dirk Hohndel
Right now we just want direct access to the country, I assume we'll add more like this in the future. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-04-29Add SPDX header to remaining core filesGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-04-26Correct divesite geocoding translationGravatar Jan Mulder
See https://github.com/Subsurface-divelog/subsurface/issues/345. The menues where not translated. The basis of this error is a simple typo in core/taxonomy.c where the classname was mis-spelled in the QT_TRANSLATE_NOOP. In addition, to pull and translate the strings from C code, the normal tr() does not work, and the functionality from the gettextfromc class is used. Fixes: #345 Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
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>