summaryrefslogtreecommitdiffstats
path: root/qt-mobile/qmlmanager.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2016-02-10 17:45:23 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2016-02-10 21:00:43 -0800
commite26e50f2e4a9ce78e345d06345d437d67aaa2451 (patch)
tree0936624f12547bdc9a5ad0208698d5c6cd7ace0a /qt-mobile/qmlmanager.cpp
parentb7e353b7f66f3a9eba923cd07a26dced2e512053 (diff)
downloadsubsurface-e26e50f2e4a9ce78e345d06345d437d67aaa2451.tar.gz
Better tracking of the status of the credentials
There are several parts of the UI that will do better if they know if the credentials that we have are incomplete (e.g., no password), invalid (server rejected them), valid (server accepted them) or potentially valid (we found a local cache for the email address, so that's likely correct, but because we are offline we cannot (or have not yet) verify the passord). So far this is specific for the mobile UI - it might make sense to try and use the same backend code and status tracking for desktop and mobile. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-mobile/qmlmanager.cpp')
-rw-r--r--qt-mobile/qmlmanager.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/qt-mobile/qmlmanager.cpp b/qt-mobile/qmlmanager.cpp
index 5aa10edfe..0231e7775 100644
--- a/qt-mobile/qmlmanager.cpp
+++ b/qt-mobile/qmlmanager.cpp
@@ -42,6 +42,7 @@ extern "C" int gitProgressCB(int percent)
QMLManager::QMLManager() : m_locationServiceEnabled(false),
m_verboseEnabled(false),
+ m_credentialStatus(UNKNOWN),
reply(0)
{
m_instance = this;
@@ -68,6 +69,9 @@ void QMLManager::openLocalThenRemote(QString url)
if (error) {
appendTextToLog(QStringLiteral("loading dives from cache failed %1").arg(error));
} else {
+ // if we can load from the cache, we know that we have at least a valid email
+ if (credentialStatus() == UNKNOWN)
+ setCredentialStatus(VALID_EMAIL);
prefs.unit_system = informational_prefs.unit_system;
if (informational_prefs.unit_system == IMPERIAL)
informational_prefs.units = IMPERIAL_units;
@@ -98,6 +102,7 @@ void QMLManager::finishSetup()
getCloudURL(url) == 0) {
openLocalThenRemote(url);
} else {
+ setCredentialStatus(INCOMPLETE);
appendTextToLog(QStringLiteral("no cloud credentials"));
setStartPageText(tr("Please enter valid cloud credentials."));
}
@@ -202,6 +207,7 @@ void QMLManager::provideAuth(QNetworkReply *reply, QAuthenticator *auth)
// OK, credentials have been tried and didn't work, so they are invalid
appendTextToLog("Cloud credentials are invalid");
setStartPageText(tr("Cloud credentials are invalid"));
+ setCredentialStatus(INVALID);
reply->disconnect();
reply->abort();
reply->deleteLater();
@@ -236,6 +242,7 @@ void QMLManager::retrieveUserid()
appendTextToLog(QStringLiteral("Cloud storage connection not working correctly: ") + reply->readAll());
return;
}
+ setCredentialStatus(VALID);
QString userid(prefs.userid);
if (userid.isEmpty()) {
if (same_string(prefs.cloud_storage_email, "") || same_string(prefs.cloud_storage_password, "")) {
@@ -273,6 +280,7 @@ void QMLManager::loadDivesWithValidCredentials()
setStartPageText(tr("Cannot connect to cloud storage"));
return;
}
+ setCredentialStatus(VALID);
appendTextToLog("Cloud credentials valid, loading dives...");
loadDiveProgress(0);
QString url;
@@ -765,6 +773,22 @@ void QMLManager::setStartPageText(const QString& text)
emit startPageTextChanged();
}
+// this is an enum, but I don't know how to do enums in QML
+QMLManager::credentialStatus_t QMLManager::credentialStatus() const
+{
+ return m_credentialStatus;
+}
+
+void QMLManager::setCredentialStatus(const credentialStatus_t value)
+{
+ qDebug() << "setting credentialStatus to" << value;
+ if (m_credentialStatus != value) {
+ m_credentialStatus = value;
+ qDebug() << "and emitting the changed signal";
+ emit credentialStatusChanged();
+ }
+}
+
void QMLManager::showMap(const QString& location)
{
if (!location.isEmpty()) {