summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/gpslocation.cpp213
-rw-r--r--core/gpslocation.h4
2 files changed, 0 insertions, 217 deletions
diff --git a/core/gpslocation.cpp b/core/gpslocation.cpp
index e0d3e3a10..3336fe70c 100644
--- a/core/gpslocation.cpp
+++ b/core/gpslocation.cpp
@@ -207,45 +207,6 @@ void GpsLocation::status(QString msg)
(*showMessageCB)(qPrintable(msg));
}
-QString GpsLocation::getUserid(QString user, QString passwd)
-{
- qDebug() << "called getUserid";
- QEventLoop loop;
- QTimer timer;
- timer.setSingleShot(true);
-
- QNetworkAccessManager *manager = new QNetworkAccessManager(qApp);
- QUrl url(GET_WEBSERVICE_UID_URL);
- QString data;
- data = user + " " + passwd;
- QNetworkRequest request;
- request.setUrl(url);
- request.setRawHeader("User-Agent", getUserAgent().toUtf8());
- request.setRawHeader("Accept", "text/html");
- request.setRawHeader("Content-type", "application/x-www-form-urlencoded");
- reply = manager->post(request, data.toUtf8());
- connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
- connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
- connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
- this, SLOT(getUseridError(QNetworkReply::NetworkError)));
- timer.start(10000);
- loop.exec();
- if (timer.isActive()) {
- timer.stop();
- if (reply->error() == QNetworkReply::NoError) {
- QString result = reply->readAll();
- status(QString("received ") + result);
- result.remove("WebserviceID:");
- reply->deleteLater();
- return result;
- }
- } else {
- status("Getting Web service ID timed out");
- }
- reply->deleteLater();
- return QString();
-}
-
int GpsLocation::getGpsNum() const
{
return m_trackers.count();
@@ -470,177 +431,3 @@ void GpsLocation::postError(QNetworkReply::NetworkError)
{
status(QString("error when sending a GPS fix: %1").arg(reply->errorString()));
}
-
-void GpsLocation::getUseridError(QNetworkReply::NetworkError)
-{
- status(QString("error when retrieving Subsurface webservice user id: %1").arg(reply->errorString()));
-}
-
-void GpsLocation::deleteFixesFromServer()
-{
- QEventLoop loop;
- QTimer timer;
- timer.setSingleShot(true);
-
- QNetworkAccessManager *manager = new QNetworkAccessManager(qApp);
- QUrl url(GPS_FIX_DELETE_URL);
- QList<qint64> keys = m_trackers.keys();
- while (!m_deletedTrackers.isEmpty()) {
- gpsTracker gt = m_deletedTrackers.takeFirst();
- QDateTime dt = QDateTime::fromTime_t(gt.when, Qt::UTC);
- QUrlQuery data;
- data.addQueryItem("login", prefs.userid);
- data.addQueryItem("dive_date", dt.toString("yyyy-MM-dd"));
- data.addQueryItem("dive_time", dt.toString("hh:mm"));
- status(data.toString(QUrl::FullyEncoded).toUtf8());
- QNetworkRequest request;
- request.setUrl(url);
- request.setRawHeader("User-Agent", getUserAgent().toUtf8());
- request.setRawHeader("Accept", "text/json");
- request.setRawHeader("Content-type", "application/x-www-form-urlencoded");
- reply = manager->post(request, data.toString(QUrl::FullyEncoded).toUtf8());
- connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
- connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
- connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
- this, SLOT(postError(QNetworkReply::NetworkError)));
- timer.start(10000);
- loop.exec();
- if (timer.isActive()) {
- timer.stop();
- if (reply->error() != QNetworkReply::NoError) {
- QString response = reply->readAll();
- status(QString("Server response:") + reply->readAll());
- }
- } else {
- status("Deleting on the server timed out - try again later");
- m_deletedTrackers.prepend(gt);
- break;
- }
- reply->deleteLater();
- status(QString("completed deleting gps fix %1 - response: ").arg(gt.idx) + reply->readAll());
- }
-}
-
-void GpsLocation::uploadToServer()
-{
- // we want to do this one at a time (the server prefers that)
- QEventLoop loop;
- QTimer timer;
- timer.setSingleShot(true);
-
- QNetworkAccessManager *manager = new QNetworkAccessManager(qApp);
- QUrl url(GPS_FIX_ADD_URL);
- Q_FOREACH(qint64 key, m_trackers.keys()) {
- struct gpsTracker gt = m_trackers.value(key);
- QDateTime dt = QDateTime::fromTime_t(gt.when, Qt::UTC);
- QUrlQuery data;
- data.addQueryItem("login", prefs.userid);
- data.addQueryItem("dive_date", dt.toString("yyyy-MM-dd"));
- data.addQueryItem("dive_time", dt.toString("hh:mm"));
- data.addQueryItem("dive_latitude", QString::number(gt.latitude.udeg / 1000000.0, 'f', 9));
- data.addQueryItem("dive_longitude", QString::number(gt.longitude.udeg / 1000000.0, 'f', 9));
- if (gt.name.isEmpty())
- gt.name = "Auto-created dive";
- data.addQueryItem("dive_name", gt.name);
- status(data.toString(QUrl::FullyEncoded).toUtf8());
- QNetworkRequest request;
- request.setUrl(url);
- request.setRawHeader("User-Agent", getUserAgent().toUtf8());
- request.setRawHeader("Accept", "text/json");
- request.setRawHeader("Content-type", "application/x-www-form-urlencoded");
- reply = manager->post(request, data.toString(QUrl::FullyEncoded).toUtf8());
- connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
- connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
- // somehoe I cannot get this to work with the new connect syntax:
- // connect(reply, &QNetworkReply::error, this, &GpsLocation::postError);
- connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
- this, SLOT(postError(QNetworkReply::NetworkError)));
- timer.start(10000);
- loop.exec();
- if (timer.isActive()) {
- timer.stop();
- if (reply->error() != QNetworkReply::NoError) {
- QString response = reply->readAll();
- if (!response.contains("Duplicate entry")) {
- status(QString("Server response:") + reply->readAll());
- break;
- }
- }
- } else {
- status("Uploading to server timed out");
- break;
- }
- reply->deleteLater();
- status(QString("completed sending gps fix %1 - response: ").arg(gt.idx) + reply->readAll());
- }
- // and now remove the ones that were locally deleted
- deleteFixesFromServer();
-}
-
-void GpsLocation::downloadFromServer()
-{
- QEventLoop loop;
- QTimer timer;
- timer.setSingleShot(true);
- QNetworkAccessManager *manager = new QNetworkAccessManager(qApp);
- QUrl url(QString(GPS_FIX_DOWNLOAD_URL "?login=%1").arg(prefs.userid));
- QNetworkRequest request;
- request.setUrl(url);
- request.setRawHeader("User-Agent", getUserAgent().toUtf8());
- request.setRawHeader("Accept", "text/json");
- request.setRawHeader("Content-type", "text/html");
- qDebug() << "downloadFromServer accessing" << url;
- reply = manager->get(request);
- connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
- connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
- connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
- this, SLOT(getUseridError(QNetworkReply::NetworkError)));
- timer.start(10000);
- loop.exec();
- if (timer.isActive()) {
- timer.stop();
- if (!reply->error()) {
- QString response = reply->readAll();
- QJsonDocument json = QJsonDocument::fromJson(response.toUtf8());
- QJsonObject object = json.object();
- if (object.value("download").toString() != "ok") {
- qDebug() << "problems downloading GPS fixes";
- return;
- }
- qDebug() << "already have" << m_trackers.count() << "GPS fixes";
- QJsonArray downloadedFixes = object.value("dives").toArray();
- qDebug() << downloadedFixes.count() << "GPS fixes downloaded";
- for (int i = 0; i < downloadedFixes.count(); i++) {
- QJsonObject fix = downloadedFixes[i].toObject();
- QDate date = QDate::fromString(fix.value("date").toString(), "yyyy-M-d");
- QTime time = QTime::fromString(fix.value("time").toString(), "hh:m:s");
- QString name = fix.value("name").toString();
- QString latitude = fix.value("latitude").toString();
- QString longitude = fix.value("longitude").toString();
- QDateTime timestamp;
- timestamp.setTimeSpec(Qt::UTC);
- timestamp.setDate(date);
- timestamp.setTime(time);
-
- struct gpsTracker gt;
- gt.when = timestamp.toMSecsSinceEpoch() / 1000;
- gt.latitude.udeg = lrint(latitude.toDouble() * 1000000);
- gt.longitude.udeg = lrint(longitude.toDouble() * 1000000);
- gt.name = name;
- // add this GPS fix to the QMap and the settings (remove existing fix at the same timestamp first)
- if (m_trackers.keys().contains(gt.when)) {
- qDebug() << "already have a fix at time stamp" << gt.when;
- replaceFixToStorage(gt);
- } else {
- addFixToStorage(gt);
- }
- }
- } else {
- qDebug() << "network error" << reply->error() << reply->errorString() << reply->readAll();
- }
- } else {
- qDebug() << "download timed out";
- status("Download from server timed out");
- }
- reply->deleteLater();
-}
diff --git a/core/gpslocation.h b/core/gpslocation.h
index b277091a3..f55e3bf9d 100644
--- a/core/gpslocation.h
+++ b/core/gpslocation.h
@@ -30,7 +30,6 @@ public:
static bool hasInstance();
bool applyLocations();
int getGpsNum() const;
- QString getUserid(QString user, QString passwd);
bool hasLocationsSource();
QString currentPosition();
void setGpsTimeThreshold(int seconds);
@@ -66,10 +65,7 @@ public slots:
void newPosition(QGeoPositionInfo pos);
void updateTimeout();
void positionSourceError(QGeoPositionInfoSource::Error error);
- void uploadToServer();
- void downloadFromServer();
void postError(QNetworkReply::NetworkError error);
- void getUseridError(QNetworkReply::NetworkError error);
#ifdef SUBSURFACE_MOBILE
void clearGpsData();
#endif