aboutsummaryrefslogtreecommitdiffstats
path: root/qthelper.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'qthelper.cpp')
-rw-r--r--qthelper.cpp67
1 files changed, 64 insertions, 3 deletions
diff --git a/qthelper.cpp b/qthelper.cpp
index acb1e103a..b26bdf467 100644
--- a/qthelper.cpp
+++ b/qthelper.cpp
@@ -1,6 +1,10 @@
#include "qthelper.h"
+#include "helpers.h"
#include "gettextfromc.h"
#include "statistics.h"
+#include "subsurfacewebservices.h"
+#include "usersurvey.h"
+#include "membuffer.h"
#include <exif.h>
#include "file.h"
#include <QFile>
@@ -8,6 +12,16 @@
#include <QDir>
#include <QDebug>
#include <QSettings>
+#include <QStandardPaths>
+#include <QJsonDocument>
+#include <QJsonArray>
+#include <QJsonObject>
+#include <QNetworkReply>
+#include <QNetworkRequest>
+#include <QNetworkAccessManager>
+#include <QUrlQuery>
+#include <QEventLoop>
+
#include <libxslt/documents.h>
#define translate(_context, arg) trGettext(arg)
@@ -31,7 +45,7 @@ QString weight_string(int weight_in_grams)
return (str);
}
-QString printGPSCoords(int lat, int lon)
+extern "C" const char *printGPSCoords(int lat, int lon)
{
unsigned int latdeg, londeg;
unsigned int latmin, lonmin;
@@ -39,7 +53,7 @@ QString printGPSCoords(int lat, int lon)
QString lath, lonh, result;
if (!lat && !lon)
- return QString();
+ return strdup("");
lath = lat >= 0 ? translate("gettextFromC", "N") : translate("gettextFromC", "S");
lonh = lon >= 0 ? translate("gettextFromC", "E") : translate("gettextFromC", "W");
@@ -54,7 +68,7 @@ QString printGPSCoords(int lat, int lon)
result.sprintf("%u%s%02d\'%06.3f\"%s %u%s%02d\'%06.3f\"%s",
latdeg, UTF8_DEGREE, latmin / 1000000, latsec / 1000000, lath.toUtf8().data(),
londeg, UTF8_DEGREE, lonmin / 1000000, lonsec / 1000000, lonh.toUtf8().data());
- return result;
+ return strdup(result.toUtf8().data());
}
static bool parseCoord(const QString& txt, int& pos, const QString& positives,
@@ -165,6 +179,7 @@ bool parseGpsText(const QString &gps_text, double *latitude, double *longitude)
pos == gps_text.size();
}
+#if 0 // we'll need something like this for the dive site management, eventually
bool gpsHasChanged(struct dive *dive, struct dive *master, const QString &gps_text, bool *parsed_out)
{
double latitude, longitude;
@@ -193,6 +208,7 @@ bool gpsHasChanged(struct dive *dive, struct dive *master, const QString &gps_te
dive->longitude.udeg = longudeg;
return true;
}
+#endif
QList<int> getDivesInTrip(dive_trip_t *trip)
{
@@ -283,6 +299,26 @@ picture_load_exit:
return;
}
+extern "C" const char *system_default_directory(void)
+{
+ static char filename[PATH_MAX];
+
+ if (!*filename) {
+ enum QStandardPaths::StandardLocation location;
+#if QT_VERSION >= 0x050400
+ location = QStandardPaths::AppDataLocation;
+#else
+ location = QStandardPaths::DataLocation;
+#endif
+ QString name = QStandardPaths::standardLocations(location).first();
+ QDir dir(name);
+ dir.mkpath(name);
+ // Why no "dir.encodeName()"? Crazy Qt
+ strncpy(filename, QFile::encodeName(name), PATH_MAX-1);
+ }
+ return filename;
+}
+
extern "C" char *get_file_name(const char *fileName)
{
QFileInfo fileInfo(fileName);
@@ -340,3 +376,28 @@ void selectedDivesGasUsed(QVector<QPair<QString, int> > &gasUsedOrdered)
}
qSort(gasUsedOrdered.begin(), gasUsedOrdered.end(), lessThan);
}
+
+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", UserSurvey::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());
+ }
+}