diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2015-02-23 09:09:48 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-02-23 09:31:08 -0800 |
commit | ddc01e39e7486434c6b814358ab4c77ea92c0776 (patch) | |
tree | 400ca390cff8070e5736eeeaf5d3f913b7d58b0a /divesitehelpers.cpp | |
parent | 62999c866f993bacadbbcad8aaf9a191f440dd1a (diff) | |
download | subsurface-ddc01e39e7486434c6b814358ab4c77ea92c0776.tar.gz |
Move helper functions around
We had a ton of helper functions in qt-gui.cpp which really didn't make
much sense. So I moved them all into qthelper.cpp.
Also moved the UserAgent helper that didn't belong in the UpdateHandler to
begin with - that's a generic helper used in many places...
With this we can successfully build using cmake again.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'divesitehelpers.cpp')
-rw-r--r-- | divesitehelpers.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/divesitehelpers.cpp b/divesitehelpers.cpp new file mode 100644 index 000000000..b29ca3faa --- /dev/null +++ b/divesitehelpers.cpp @@ -0,0 +1,41 @@ +// +// infrastructure to deal with dive sites +// +#include "divesite.h" +#include "helpers.h" +#include "usersurvey.h" +#include "membuffer.h" +#include <QJsonDocument> +#include <QJsonArray> +#include <QJsonObject> +#include <QNetworkReply> +#include <QNetworkRequest> +#include <QNetworkAccessManager> +#include <QUrlQuery> +#include <QEventLoop> + +extern "C" void reverseGeoLookup(degrees_t latitude, degrees_t longitude, uint32_t uuid) +{ + QNetworkRequest request; + QNetworkAccessManager *rgl = new QNetworkAccessManager(); + request.setUrl(QString("http://open.mapquestapi.com/nominatim/v1/reverse.php?format=json&accept-language=%1&lat=%2&lon=%3") + .arg(uiLanguage(NULL)).arg(latitude.udeg / 1000000.0).arg(longitude.udeg / 1000000.0)); + request.setRawHeader("Accept", "text/json"); + request.setRawHeader("User-Agent", getUserAgent().toUtf8()); + QNetworkReply *reply = rgl->get(request); + QEventLoop loop; + QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); + loop.exec(); + QJsonParseError errorObject; + QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll(), &errorObject); + if (errorObject.error != QJsonParseError::NoError) { + qDebug() << errorObject.errorString(); + } else { + QJsonObject obj = jsonDoc.object(); + QJsonObject address = obj.value("address").toObject(); + qDebug() << "found country:" << address.value("country").toString(); + struct dive_site *ds = get_dive_site_by_uuid(uuid); + ds->notes = add_to_string(ds->notes, "countrytag: %s", address.value("country").toString().toUtf8().data()); + } +} + |