summaryrefslogtreecommitdiffstats
path: root/mobile-widgets
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2016-06-13 15:21:51 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2016-06-13 15:25:17 -0700
commitd2f9803883ff1453e71a29e358fd5368f650fb62 (patch)
tree38151dfd967c93a6d9e740aaee55674c7ffb1228 /mobile-widgets
parentf7daadb1cd5aa85237a64f406528183eae7d0d3d (diff)
downloadsubsurface-d2f9803883ff1453e71a29e358fd5368f650fb62.tar.gz
QML UI: serialize checking credentials
If we run the backend to verify credentials without waiting for it to finish, the redirect might happen before we know if the credentials are invalid, unverified or verified - which will cause us to give the wrong information to the user. Yes, this additional wait is annoying, but I can't come up with a better way to do this and avoid incorrect information. At least the UI isn't hung while we wait. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'mobile-widgets')
-rw-r--r--mobile-widgets/qmlmanager.cpp41
1 files changed, 29 insertions, 12 deletions
diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp
index 266981219..d527f53c2 100644
--- a/mobile-widgets/qmlmanager.cpp
+++ b/mobile-widgets/qmlmanager.cpp
@@ -9,6 +9,7 @@
#include <QRegularExpression>
#include <QApplication>
#include <QElapsedTimer>
+#include <QTimer>
#include "qt-models/divelistmodel.h"
#include "qt-models/gpslistmodel.h"
@@ -305,6 +306,34 @@ void QMLManager::checkCredentialsAndExecute(execute_function_type execute)
appendTextToLog("Have credentials, let's see if they are valid");
CloudStorageAuthenticate *csa = new CloudStorageAuthenticate(this);
csa->backend(prefs.cloud_storage_email, prefs.cloud_storage_password);
+ // let's wait here for the signal to avoid too many more nested functions
+ QTimer myTimer;
+ myTimer.setSingleShot(true);
+ QEventLoop loop;
+ connect(csa, &CloudStorageAuthenticate::finishedAuthenticate, &loop, &QEventLoop::quit);
+ connect(&myTimer, &QTimer::timeout, &loop, &QEventLoop::quit);
+ myTimer.start(5000);
+ loop.exec();
+ if (!myTimer.isActive()) {
+ // got no response from the server
+ setStartPageText(RED_FONT + tr("No response from cloud server to validate the credentials") + END_FONT);
+ revertToNoCloudIfNeeded();
+ return;
+ }
+ myTimer.stop();
+ if (prefs.cloud_verification_status == CS_NEED_TO_VERIFY) {
+ // here we need to enter the PIN
+ appendTextToLog(QStringLiteral("Need to verify the email address - enter PIN in desktop app"));
+ setStartPageText(RED_FONT + tr("Cannot connect to cloud storage - cloud account not verified") + END_FONT);
+ revertToNoCloudIfNeeded();
+ return;
+ } else if (prefs.cloud_verification_status != CS_VERIFIED) {
+ appendTextToLog(QString("Cloud account verification failed - status %1").arg(prefs.cloud_verification_status));
+ setStartPageText(RED_FONT + tr("Cannot connect to cloud storage - check developer log") + END_FONT);
+ revertToNoCloudIfNeeded();
+ return;
+ }
+ // now check the redirect URL to make sure everything is set up on the cloud server
connect(manager(), &QNetworkAccessManager::authenticationRequired, this, &QMLManager::provideAuth, Qt::UniqueConnection);
QUrl url(CLOUDREDIRECTURL);
request = QNetworkRequest(url);
@@ -370,18 +399,6 @@ void QMLManager::retrieveUserid()
revertToNoCloudIfNeeded();
return;
}
- if (prefs.cloud_verification_status == CS_NEED_TO_VERIFY) {
- // here we need to enter the PIN
- appendTextToLog(QStringLiteral("Need to verify the email address - enter PIN in desktop app"));
- setStartPageText(RED_FONT + tr("Cannot connect to cloud storage - cloud account not verified") + END_FONT);
- revertToNoCloudIfNeeded();
- return;
- } else if (prefs.cloud_verification_status != CS_VERIFIED) {
- appendTextToLog(QString("Cloud account verification failed - status %1").arg(prefs.cloud_verification_status));
- setStartPageText(RED_FONT + tr("Cannot connect to cloud storage - check developer log") + END_FONT);
- revertToNoCloudIfNeeded();
- return;
- }
setCredentialStatus(VALID);
QString userid(prefs.userid);
if (userid.isEmpty()) {