diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2015-11-18 13:14:19 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-11-18 13:14:19 -0800 |
commit | 74b15922f306872d948e722d6f2a0bb18f978436 (patch) | |
tree | b9a75d611accff8a725b604cb7ea4114fd8ea890 /qt-mobile/qmlmanager.cpp | |
parent | 18e52c1da402138a2204419bb008beb7271333bb (diff) | |
download | subsurface-74b15922f306872d948e722d6f2a0bb18f978436.tar.gz |
Location service: retrieve the userid using the cloud storage API
This should actually not be in the mobile section at all. This needs to be
available on the desktop as well.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-mobile/qmlmanager.cpp')
-rw-r--r-- | qt-mobile/qmlmanager.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/qt-mobile/qmlmanager.cpp b/qt-mobile/qmlmanager.cpp index bbc5939c7..da6b01b1c 100644 --- a/qt-mobile/qmlmanager.cpp +++ b/qt-mobile/qmlmanager.cpp @@ -25,6 +25,12 @@ QMLManager::QMLManager() : setCloudUserName(prefs.cloud_storage_email); setCloudPassword(prefs.cloud_storage_password); setSaveCloudPassword(prefs.save_password_local); + // if the cloud credentials are valid, we should get the GPS Webservice ID as well + if (!same_string(prefs.cloud_storage_email, "") && + !same_string(prefs.cloud_storage_password, "") && + same_string(prefs.userid, "")) + locationProvider->getUserid(prefs.cloud_storage_email, prefs.cloud_storage_password); + setDistanceThreshold(prefs.distance_threshold); setTimeThreshold(prefs.time_threshold / 60); if (!same_string(prefs.cloud_storage_email, "") && !same_string(prefs.cloud_storage_password, "")) @@ -38,6 +44,7 @@ QMLManager::~QMLManager() void QMLManager::savePreferences() { QSettings s; + bool cloudCredentialsChanged = false; s.beginGroup("LocationService"); s.setValue("time_threshold", timeThreshold() * 60); prefs.time_threshold = timeThreshold() * 60; @@ -53,15 +60,32 @@ void QMLManager::savePreferences() if (!same_string(prefs.cloud_storage_email, qPrintable(cloudUserName()))) { free(prefs.cloud_storage_email); prefs.cloud_storage_email = strdup(qPrintable(cloudUserName())); + cloudCredentialsChanged = true; } if (saveCloudPassword() != prefs.save_password_local) prefs.save_password_local = saveCloudPassword(); + + cloudCredentialsChanged |= !same_string(prefs.cloud_storage_password, qPrintable(cloudPassword())); + if (saveCloudPassword()) { if (!same_string(prefs.cloud_storage_password, qPrintable(cloudPassword()))) { free(prefs.cloud_storage_password); prefs.cloud_storage_password = strdup(qPrintable(cloudPassword())); } } + // if the cloud credentials are valid, we should get the GPS Webservice ID as well + if (!same_string(prefs.cloud_storage_email, "") && + !same_string(prefs.cloud_storage_password, "")) { + if (same_string(prefs.userid, "") || cloudCredentialsChanged) { + QString userid = locationProvider->getUserid(prefs.cloud_storage_email, prefs.cloud_storage_password); + if (!userid.isEmpty()) { + // overwrite the existing userid + free(prefs.userid); + prefs.userid = strdup(qPrintable(userid)); + s.setValue("subsurface_webservice_uid", prefs.userid); + } + } + } } void QMLManager::loadDives() |