diff options
-rw-r--r-- | core/gpslocation.cpp | 213 | ||||
-rw-r--r-- | core/gpslocation.h | 4 | ||||
-rw-r--r-- | mobile-widgets/qmlmanager.cpp | 33 | ||||
-rw-r--r-- | mobile-widgets/qmlmanager.h | 3 |
4 files changed, 1 insertions, 252 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 diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index f5e7cff11..a7ef0e420 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -490,8 +490,6 @@ void QMLManager::saveCloudCredentials() } else if (cloudCredentialsChanged) { // let's make sure there are no unsaved changes saveChangesLocal(); - free((void *)prefs.userid); - prefs.userid = NULL; syncLoadFromCloud(); QString url; getCloudURL(url); @@ -622,25 +620,7 @@ void QMLManager::retrieveUserid() revertToNoCloudIfNeeded(); return; } - QMLPrefs::instance()->setCredentialStatus(qPref::CS_VERIFIED); - QString userid(prefs.userid); - if (userid.isEmpty()) { - if (empty_string(prefs.cloud_storage_email) || empty_string(prefs.cloud_storage_password)) { - appendTextToLog("cloud user name or password are empty, can't retrieve web user id"); - revertToNoCloudIfNeeded(); - return; - } - appendTextToLog(QStringLiteral("calling getUserid with user %1").arg(prefs.cloud_storage_email)); - userid = locationProvider->getUserid(prefs.cloud_storage_email, prefs.cloud_storage_password); - } - if (!userid.isEmpty()) { - // overwrite the existing userid - free((void *)prefs.userid); - prefs.userid = copy_qstring(userid); - QSettings s; - s.setValue("subsurface_webservice_uid", prefs.userid); - s.sync(); - } + QMLPrefs::instance()->setCredentialStatus(qPref::CS_VERIFIED); setStartPageText(tr("Cloud credentials valid, loading dives...")); // this only gets called with "alreadySaving" already locked @@ -1390,17 +1370,6 @@ void QMLManager::applyGpsData() refreshDiveList(); } -void QMLManager::sendGpsData() -{ - locationProvider->uploadToServer(); -} - -void QMLManager::downloadGpsData() -{ - locationProvider->downloadFromServer(); - populateGpsData(); -} - void QMLManager::populateGpsData() { if (GpsListModel::instance()) diff --git a/mobile-widgets/qmlmanager.h b/mobile-widgets/qmlmanager.h index 48e6540b5..4b96621ba 100644 --- a/mobile-widgets/qmlmanager.h +++ b/mobile-widgets/qmlmanager.h @@ -168,8 +168,6 @@ public slots: QString addDive(); void addDiveAborted(int id); void applyGpsData(); - void sendGpsData(); - void downloadGpsData(); void populateGpsData(); void cancelDownloadDC(); void clearGpsData(); @@ -200,7 +198,6 @@ private: SuitCompletionModel suitModel; DiveMasterCompletionModel divemasterModel; LocationInformationModel locationModel; - QString m_ssrfGpsWebUserid; QString m_startPageText; QString m_logText; QString m_lastError; |