aboutsummaryrefslogtreecommitdiffstats
path: root/core/gpslocation.cpp
diff options
context:
space:
mode:
authorGravatar Jan Mulder <jlmulder@xs4all.nl>2018-09-11 15:38:38 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-09-11 15:38:20 -0700
commitbb0ac5f7784acec930b5131bfb25f0c4b5fa2f3b (patch)
treec2bd8760b17ec3bfd192bd02d03d32a39c5d7618 /core/gpslocation.cpp
parentcc72a606bb9a64a0d251e06c19cf8b8dd7b131ed (diff)
downloadsubsurface-bb0ac5f7784acec930b5131bfb25f0c4b5fa2f3b.tar.gz
cleanup[4/6], mobile: remove superfluous code from gpslocation
Despite the fast that this code is sitting in core, its used mainly from mobile. In 987e221f8e6b7b, the buttons to interact with the GPS webservice were deleted from the UI. Now, delete all the code that was used under these buttons. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
Diffstat (limited to 'core/gpslocation.cpp')
-rw-r--r--core/gpslocation.cpp213
1 files changed, 0 insertions, 213 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();
-}