summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2017-10-02 23:16:14 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-10-04 08:05:09 -0700
commit09b02aae4e4059adca8a9094301e06f116bf4a3e (patch)
tree482dffd0b1b6a71867acae0f953284205919fee1 /core
parentff26ffe0d078a891cbc52afa7ffb59943644ad82 (diff)
downloadsubsurface-09b02aae4e4059adca8a9094301e06f116bf4a3e.tar.gz
Simplify the geo reverse lookup function
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>
Diffstat (limited to 'core')
-rw-r--r--core/divesitehelpers.cpp42
1 files changed, 4 insertions, 38 deletions
diff --git a/core/divesitehelpers.cpp b/core/divesitehelpers.cpp
index 822defdcb..64d3bc149 100644
--- a/core/divesitehelpers.cpp
+++ b/core/divesitehelpers.cpp
@@ -19,14 +19,6 @@
#include <QEventLoop>
#include <QTimer>
-struct GeoLookupInfo {
- degrees_t lat;
- degrees_t lon;
- uint32_t uuid;
-};
-
-QVector<GeoLookupInfo> geo_lookup_data;
-
ReverseGeoLookupThread* ReverseGeoLookupThread::instance() {
static ReverseGeoLookupThread* self = new ReverseGeoLookupThread();
return self;
@@ -37,8 +29,6 @@ ReverseGeoLookupThread::ReverseGeoLookupThread(QObject *obj) : QThread(obj)
}
void ReverseGeoLookupThread::run() {
- if (geo_lookup_data.isEmpty())
- return;
QNetworkRequest request;
QNetworkAccessManager *rgl = new QNetworkAccessManager();
@@ -53,11 +43,10 @@ void ReverseGeoLookupThread::run() {
request.setRawHeader("User-Agent", getUserAgent().toUtf8());
connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
- Q_FOREACH (const GeoLookupInfo& info, geo_lookup_data ) {
- struct dive_site *ds = info.uuid ? get_dive_site_by_uuid(info.uuid) : &displayed_dive_site;
+ struct dive_site *ds = &displayed_dive_site;
// first check the findNearbyPlaces API from geonames - that should give us country, state, city
- request.setUrl(geonamesURL.arg(uiLanguage(NULL)).arg(info.lat.udeg / 1000000.0).arg(info.lon.udeg / 1000000.0));
+ request.setUrl(geonamesURL.arg(uiLanguage(NULL)).arg(ds->latitude.udeg / 1000000.0).arg(ds->longitude.udeg / 1000000.0));
QNetworkReply *reply = rgl->get(request);
timer.setSingleShot(true);
@@ -134,7 +123,7 @@ void ReverseGeoLookupThread::run() {
reply->abort();
}
// next check the oceans API to figure out the body of water
- request.setUrl(geonamesOceanURL.arg(uiLanguage(NULL)).arg(info.lat.udeg / 1000000.0).arg(info.lon.udeg / 1000000.0));
+ request.setUrl(geonamesOceanURL.arg(uiLanguage(NULL)).arg(ds->latitude.udeg / 1000000.0).arg(ds->longitude.udeg / 1000000.0));
reply = rgl->get(request);
connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
timer.start(5000); // 5 secs. timeout
@@ -182,29 +171,6 @@ void ReverseGeoLookupThread::run() {
clear_reply:
reply->deleteLater();
- }
- rgl->deleteLater();
-}
-
-void ReverseGeoLookupThread::lookup(dive_site *ds)
-{
- if (!ds)
- return;
- GeoLookupInfo info;
- info.lat = ds->latitude;
- info.lon = ds->longitude;
- info.uuid = ds->uuid;
-
- geo_lookup_data.clear();
- geo_lookup_data.append(info);
- run();
-}
-extern "C" void add_geo_information_for_lookup(degrees_t latitude, degrees_t longitude, uint32_t uuid) {
- GeoLookupInfo info;
- info.lat = latitude;
- info.lon = longitude;
- info.uuid = uuid;
-
- geo_lookup_data.append(info);
+ rgl->deleteLater();
}