mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
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 987e221f8e
, 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>
This commit is contained in:
parent
cc72a606bb
commit
bb0ac5f778
4 changed files with 1 additions and 252 deletions
|
@ -207,45 +207,6 @@ void GpsLocation::status(QString msg)
|
||||||
(*showMessageCB)(qPrintable(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
|
int GpsLocation::getGpsNum() const
|
||||||
{
|
{
|
||||||
return m_trackers.count();
|
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()));
|
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();
|
|
||||||
}
|
|
||||||
|
|
|
@ -30,7 +30,6 @@ public:
|
||||||
static bool hasInstance();
|
static bool hasInstance();
|
||||||
bool applyLocations();
|
bool applyLocations();
|
||||||
int getGpsNum() const;
|
int getGpsNum() const;
|
||||||
QString getUserid(QString user, QString passwd);
|
|
||||||
bool hasLocationsSource();
|
bool hasLocationsSource();
|
||||||
QString currentPosition();
|
QString currentPosition();
|
||||||
void setGpsTimeThreshold(int seconds);
|
void setGpsTimeThreshold(int seconds);
|
||||||
|
@ -66,10 +65,7 @@ public slots:
|
||||||
void newPosition(QGeoPositionInfo pos);
|
void newPosition(QGeoPositionInfo pos);
|
||||||
void updateTimeout();
|
void updateTimeout();
|
||||||
void positionSourceError(QGeoPositionInfoSource::Error error);
|
void positionSourceError(QGeoPositionInfoSource::Error error);
|
||||||
void uploadToServer();
|
|
||||||
void downloadFromServer();
|
|
||||||
void postError(QNetworkReply::NetworkError error);
|
void postError(QNetworkReply::NetworkError error);
|
||||||
void getUseridError(QNetworkReply::NetworkError error);
|
|
||||||
#ifdef SUBSURFACE_MOBILE
|
#ifdef SUBSURFACE_MOBILE
|
||||||
void clearGpsData();
|
void clearGpsData();
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -490,8 +490,6 @@ void QMLManager::saveCloudCredentials()
|
||||||
} else if (cloudCredentialsChanged) {
|
} else if (cloudCredentialsChanged) {
|
||||||
// let's make sure there are no unsaved changes
|
// let's make sure there are no unsaved changes
|
||||||
saveChangesLocal();
|
saveChangesLocal();
|
||||||
free((void *)prefs.userid);
|
|
||||||
prefs.userid = NULL;
|
|
||||||
syncLoadFromCloud();
|
syncLoadFromCloud();
|
||||||
QString url;
|
QString url;
|
||||||
getCloudURL(url);
|
getCloudURL(url);
|
||||||
|
@ -622,25 +620,7 @@ void QMLManager::retrieveUserid()
|
||||||
revertToNoCloudIfNeeded();
|
revertToNoCloudIfNeeded();
|
||||||
return;
|
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);
|
QMLPrefs::instance()->setCredentialStatus(qPref::CS_VERIFIED);
|
||||||
setStartPageText(tr("Cloud credentials valid, loading dives..."));
|
setStartPageText(tr("Cloud credentials valid, loading dives..."));
|
||||||
// this only gets called with "alreadySaving" already locked
|
// this only gets called with "alreadySaving" already locked
|
||||||
|
@ -1390,17 +1370,6 @@ void QMLManager::applyGpsData()
|
||||||
refreshDiveList();
|
refreshDiveList();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QMLManager::sendGpsData()
|
|
||||||
{
|
|
||||||
locationProvider->uploadToServer();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QMLManager::downloadGpsData()
|
|
||||||
{
|
|
||||||
locationProvider->downloadFromServer();
|
|
||||||
populateGpsData();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QMLManager::populateGpsData()
|
void QMLManager::populateGpsData()
|
||||||
{
|
{
|
||||||
if (GpsListModel::instance())
|
if (GpsListModel::instance())
|
||||||
|
|
|
@ -168,8 +168,6 @@ public slots:
|
||||||
QString addDive();
|
QString addDive();
|
||||||
void addDiveAborted(int id);
|
void addDiveAborted(int id);
|
||||||
void applyGpsData();
|
void applyGpsData();
|
||||||
void sendGpsData();
|
|
||||||
void downloadGpsData();
|
|
||||||
void populateGpsData();
|
void populateGpsData();
|
||||||
void cancelDownloadDC();
|
void cancelDownloadDC();
|
||||||
void clearGpsData();
|
void clearGpsData();
|
||||||
|
@ -200,7 +198,6 @@ private:
|
||||||
SuitCompletionModel suitModel;
|
SuitCompletionModel suitModel;
|
||||||
DiveMasterCompletionModel divemasterModel;
|
DiveMasterCompletionModel divemasterModel;
|
||||||
LocationInformationModel locationModel;
|
LocationInformationModel locationModel;
|
||||||
QString m_ssrfGpsWebUserid;
|
|
||||||
QString m_startPageText;
|
QString m_startPageText;
|
||||||
QString m_logText;
|
QString m_logText;
|
||||||
QString m_lastError;
|
QString m_lastError;
|
||||||
|
|
Loading…
Add table
Reference in a new issue