QML UI: new property to tell the UI that we are accessing cloud storage

This can then be used to give the user visual feedback (instead of them
just thinking the app is hung).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2016-03-02 17:13:42 -08:00
parent 605d085573
commit 1f0b716021
2 changed files with 26 additions and 1 deletions

View file

@ -53,6 +53,7 @@ QMLManager::QMLManager() : m_locationServiceEnabled(false),
qDebug() << "Starting" << getUserAgent(); qDebug() << "Starting" << getUserAgent();
qDebug() << QStringLiteral("build with Qt Version %1, runtime from Qt Version %2").arg(QT_VERSION_STR).arg(qVersion()); qDebug() << QStringLiteral("build with Qt Version %1, runtime from Qt Version %2").arg(QT_VERSION_STR).arg(qVersion());
setStartPageText(tr("Starting...")); setStartPageText(tr("Starting..."));
setAccessingCloud(false);
// create location manager service // create location manager service
locationProvider = new GpsLocation(&appendTextToLogStandalone, this); locationProvider = new GpsLocation(&appendTextToLogStandalone, this);
set_git_update_cb(&gitProgressCB); set_git_update_cb(&gitProgressCB);
@ -88,6 +89,7 @@ void QMLManager::openLocalThenRemote(QString url)
appendTextToLog(QStringLiteral("%1 dives loaded from cache").arg(i)); appendTextToLog(QStringLiteral("%1 dives loaded from cache").arg(i));
} }
appendTextToLog(QStringLiteral("have cloud credentials, trying to connect")); appendTextToLog(QStringLiteral("have cloud credentials, trying to connect"));
setAccessingCloud(true);
tryRetrieveDataFromBackend(); tryRetrieveDataFromBackend();
} }
@ -250,6 +252,7 @@ void QMLManager::retrieveUserid()
{ {
if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute) != 302) { if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute) != 302) {
appendTextToLog(QStringLiteral("Cloud storage connection not working correctly: ") + reply->readAll()); appendTextToLog(QStringLiteral("Cloud storage connection not working correctly: ") + reply->readAll());
setAccessingCloud(false);
return; return;
} }
setCredentialStatus(VALID); setCredentialStatus(VALID);
@ -288,6 +291,7 @@ void QMLManager::loadDivesWithValidCredentials()
if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute) != 302) { if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute) != 302) {
appendTextToLog(QStringLiteral("Cloud storage connection not working correctly: ") + reply->readAll()); appendTextToLog(QStringLiteral("Cloud storage connection not working correctly: ") + reply->readAll());
setStartPageText(tr("Cannot connect to cloud storage")); setStartPageText(tr("Cannot connect to cloud storage"));
setAccessingCloud(false);
return; return;
} }
setCredentialStatus(VALID); setCredentialStatus(VALID);
@ -299,6 +303,7 @@ void QMLManager::loadDivesWithValidCredentials()
QString errorString(get_error_string()); QString errorString(get_error_string());
appendTextToLog(errorString); appendTextToLog(errorString);
setStartPageText(tr("Cloud storage error: %1").arg(errorString)); setStartPageText(tr("Cloud storage error: %1").arg(errorString));
setAccessingCloud(false);
return; return;
} }
QByteArray fileNamePrt = QFile::encodeName(url); QByteArray fileNamePrt = QFile::encodeName(url);
@ -306,6 +311,7 @@ void QMLManager::loadDivesWithValidCredentials()
qDebug() << "local cache was current, no need to modify dive list"; qDebug() << "local cache was current, no need to modify dive list";
appendTextToLog("Cloud sync shows local cache was current"); appendTextToLog("Cloud sync shows local cache was current");
setLoadFromCloud(true); setLoadFromCloud(true);
setAccessingCloud(false);
return; return;
} }
clear_dive_file_data(); clear_dive_file_data();
@ -322,6 +328,7 @@ void QMLManager::loadDivesWithValidCredentials()
QString errorString(get_error_string()); QString errorString(get_error_string());
appendTextToLog(errorString); appendTextToLog(errorString);
setStartPageText(tr("Cloud storage error: %1").arg(errorString)); setStartPageText(tr("Cloud storage error: %1").arg(errorString));
setAccessingCloud(false);
return; return;
} }
prefs.unit_system = informational_prefs.unit_system; prefs.unit_system = informational_prefs.unit_system;
@ -340,6 +347,7 @@ void QMLManager::loadDivesWithValidCredentials()
if (dive_table.nr == 0) if (dive_table.nr == 0)
setStartPageText(tr("Cloud storage open successfully. No dives in dive list.")); setStartPageText(tr("Cloud storage open successfully. No dives in dive list."));
setLoadFromCloud(true); setLoadFromCloud(true);
setAccessingCloud(false);
} }
void QMLManager::refreshDiveList() void QMLManager::refreshDiveList()
@ -930,3 +938,14 @@ QString QMLManager::getVersion() const
return versionRe.cap(1); return versionRe.cap(1);
} }
bool QMLManager::accessingCloud() const
{
return m_accessingCloud;
}
void QMLManager::setAccessingCloud(bool status)
{
m_accessingCloud = status;
emit accessingCloudChanged();
}

View file

@ -21,6 +21,8 @@ class QMLManager : public QObject {
Q_PROPERTY(QString startPageText READ startPageText WRITE setStartPageText NOTIFY startPageTextChanged) Q_PROPERTY(QString startPageText READ startPageText WRITE setStartPageText NOTIFY startPageTextChanged)
Q_PROPERTY(bool verboseEnabled READ verboseEnabled WRITE setVerboseEnabled NOTIFY verboseEnabledChanged) Q_PROPERTY(bool verboseEnabled READ verboseEnabled WRITE setVerboseEnabled NOTIFY verboseEnabledChanged)
Q_PROPERTY(credentialStatus_t credentialStatus READ credentialStatus WRITE setCredentialStatus NOTIFY credentialStatusChanged) Q_PROPERTY(credentialStatus_t credentialStatus READ credentialStatus WRITE setCredentialStatus NOTIFY credentialStatusChanged)
Q_PROPERTY(bool accessingCloud READ accessingCloud WRITE setAccessingCloud NOTIFY accessingCloudChanged)
public: public:
QMLManager(); QMLManager();
~QMLManager(); ~QMLManager();
@ -70,6 +72,9 @@ public:
void setLogText(const QString &logText); void setLogText(const QString &logText);
void appendTextToLog(const QString &newText); void appendTextToLog(const QString &newText);
bool accessingCloud() const;
void setAccessingCloud(bool status);
typedef void (QMLManager::*execute_function_type)(); typedef void (QMLManager::*execute_function_type)();
public slots: public slots:
@ -129,7 +134,7 @@ private:
QNetworkRequest request; QNetworkRequest request;
struct dive *deletedDive; struct dive *deletedDive;
struct dive_trip *deletedTrip; struct dive_trip *deletedTrip;
bool m_accessingCloud;
credentialStatus_t m_credentialStatus; credentialStatus_t m_credentialStatus;
signals: signals:
@ -144,6 +149,7 @@ signals:
void loadFromCloudChanged(); void loadFromCloudChanged();
void startPageTextChanged(); void startPageTextChanged();
void credentialStatusChanged(); void credentialStatusChanged();
void accessingCloudChanged();
}; };
#endif #endif