summaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--qt-mobile/qmlmanager.cpp24
-rw-r--r--qt-mobile/qmlmanager.h16
2 files changed, 40 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()) {
diff --git a/qt-mobile/qmlmanager.h b/qt-mobile/qmlmanager.h
index 6cd468260..2d44bfc4e 100644
--- a/qt-mobile/qmlmanager.h
+++ b/qt-mobile/qmlmanager.h
@@ -9,6 +9,7 @@
class QMLManager : public QObject {
Q_OBJECT
+ Q_ENUMS(credentialStatus_t)
Q_PROPERTY(QString cloudUserName READ cloudUserName WRITE setCloudUserName NOTIFY cloudUserNameChanged)
Q_PROPERTY(QString cloudPassword READ cloudPassword WRITE setCloudPassword NOTIFY cloudPasswordChanged)
Q_PROPERTY(bool saveCloudPassword READ saveCloudPassword WRITE setSaveCloudPassword NOTIFY saveCloudPasswordChanged)
@@ -19,10 +20,19 @@ class QMLManager : public QObject {
Q_PROPERTY(bool loadFromCloud READ loadFromCloud WRITE setLoadFromCloud NOTIFY loadFromCloudChanged)
Q_PROPERTY(QString startPageText READ startPageText WRITE setStartPageText NOTIFY startPageTextChanged)
Q_PROPERTY(bool verboseEnabled READ verboseEnabled WRITE setVerboseEnabled NOTIFY verboseEnabledChanged)
+ Q_PROPERTY(credentialStatus_t credentialStatus READ credentialStatus WRITE setCredentialStatus NOTIFY credentialStatusChanged)
public:
QMLManager();
~QMLManager();
+ enum credentialStatus_t {
+ INCOMPLETE,
+ UNKNOWN,
+ INVALID,
+ VALID_EMAIL,
+ VALID
+ };
+
static QMLManager *instance();
QString cloudUserName() const;
@@ -53,6 +63,9 @@ public:
QString startPageText() const;
void setStartPageText(const QString& text);
+ credentialStatus_t credentialStatus() const;
+ void setCredentialStatus(const credentialStatus_t value);
+
QString logText() const;
void setLogText(const QString &logText);
void appendTextToLog(const QString &newText);
@@ -112,6 +125,8 @@ private:
QNetworkReply *reply;
QNetworkRequest request;
+ credentialStatus_t m_credentialStatus;
+
signals:
void cloudUserNameChanged();
void cloudPasswordChanged();
@@ -123,6 +138,7 @@ signals:
void distanceThresholdChanged();
void loadFromCloudChanged();
void startPageTextChanged();
+ void credentialStatusChanged();
};
#endif