QML UI: show better message about dive list at start

Now the message should make more sense. First it tells you that it's looking
for dives. Then you get some progress during the git download, and error
messages if things failed.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2015-12-14 23:00:19 -08:00
parent 7aab635585
commit a26eda9700
3 changed files with 62 additions and 5 deletions

View file

@ -20,7 +20,7 @@ Item {
id: welcomeText id: welcomeText
Layout.fillWidth: true Layout.fillWidth: true
Layout.bottomMargin: MobileComponents.Units.largeSpacing Layout.bottomMargin: MobileComponents.Units.largeSpacing
text: "No recorded dives found. You can download your dives to this device from the Subsurface cloud storage service, from your dive computer, or add them manually." text: manager.startPageText
wrapMode: Text.WordWrap wrapMode: Text.WordWrap
Layout.columnSpan: 2 Layout.columnSpan: 2
} }

View file

@ -10,6 +10,7 @@
#include "pref.h" #include "pref.h"
#include "qthelper.h" #include "qthelper.h"
#include "qt-gui.h" #include "qt-gui.h"
#include "git-access.h"
QMLManager *QMLManager::m_instance = NULL; QMLManager *QMLManager::m_instance = NULL;
@ -20,14 +21,30 @@ static void appendTextToLogStandalone(const char *text)
mgr->appendTextToLog(QString(text)); mgr->appendTextToLog(QString(text));
} }
extern "C" int gitProgressCB(int percent)
{
static int lastPercent = -10;
if (percent - lastPercent >= 10) {
lastPercent += 10;
QMLManager *mgr = QMLManager::instance();
if (mgr)
mgr->loadDiveProgress(percent);
}
// return 0 so that we don't end the download
return 0;
}
QMLManager::QMLManager() : QMLManager::QMLManager() :
m_locationServiceEnabled(false), m_locationServiceEnabled(false),
reply(0), reply(0),
mgr(0) mgr(0)
{ {
m_instance = this; m_instance = this;
m_startPageText = tr("Searching for dive data");
// create location manager service // create location manager service
locationProvider = new GpsLocation(&appendTextToLogStandalone, this); locationProvider = new GpsLocation(&appendTextToLogStandalone, this);
set_git_update_cb(&gitProgressCB);
} }
void QMLManager::finishSetup() void QMLManager::finishSetup()
@ -40,6 +57,8 @@ void QMLManager::finishSetup()
if (!same_string(prefs.cloud_storage_email, "") && if (!same_string(prefs.cloud_storage_email, "") &&
!same_string(prefs.cloud_storage_password, "")) !same_string(prefs.cloud_storage_password, ""))
tryRetrieveDataFromBackend(); tryRetrieveDataFromBackend();
else
m_startPageText = "No recorded dives found. You can download your dives to this device from the Subsurface cloud storage service, from your dive computer, or add them manually.";
setDistanceThreshold(prefs.distance_threshold); setDistanceThreshold(prefs.distance_threshold);
setTimeThreshold(prefs.time_threshold / 60); setTimeThreshold(prefs.time_threshold / 60);
@ -150,6 +169,7 @@ void QMLManager::provideAuth(QNetworkReply *reply, QAuthenticator *auth)
void QMLManager::handleSslErrors(const QList<QSslError> &errors) void QMLManager::handleSslErrors(const QList<QSslError> &errors)
{ {
setStartPageText(tr("Cannot open cloud storage: Error creating https connection"));
Q_FOREACH(QSslError e, errors) { Q_FOREACH(QSslError e, errors) {
qDebug() << e.errorString(); qDebug() << e.errorString();
} }
@ -159,7 +179,9 @@ void QMLManager::handleSslErrors(const QList<QSslError> &errors)
void QMLManager::handleError(QNetworkReply::NetworkError nError) void QMLManager::handleError(QNetworkReply::NetworkError nError)
{ {
qDebug() << "handleError" << nError << reply->errorString(); QString errorString = reply->errorString();
qDebug() << "handleError" << nError << errorString;
setStartPageText(tr("Cannot open cloud storage: %1").arg(errorString));
reply->abort(); reply->abort();
reply->deleteLater(); reply->deleteLater();
} }
@ -185,16 +207,30 @@ void QMLManager::retrieveUserid()
loadDivesWithValidCredentials(); loadDivesWithValidCredentials();
} }
void QMLManager::loadDiveProgress(int percent)
{
QString text(tr("Loading dive list from cloud storage."));
while(percent > 0) {
text.append(".");
percent -= 10;
}
setStartPageText(text);
}
void QMLManager::loadDivesWithValidCredentials() void QMLManager::loadDivesWithValidCredentials()
{ {
if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute) != 302) { if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute) != 302) {
appendTextToLog(QString("Cloud storage connection not working correctly: ") + reply->readAll()); appendTextToLog(QString("Cloud storage connection not working correctly: ") + reply->readAll());
setStartPageText(tr("Cannot connect to cloud storage"));
return; return;
} }
appendTextToLog("Cloud credentials valid, loading dives..."); appendTextToLog("Cloud credentials valid, loading dives...");
loadDiveProgress(0);
QString url; QString url;
if (getCloudURL(url)) { if (getCloudURL(url)) {
appendTextToLog(get_error_string()); QString errorString(get_error_string());
appendTextToLog(errorString);
setStartPageText(tr("Cloud storage error: %1").arg(errorString));
return; return;
} }
clear_dive_file_data(); clear_dive_file_data();
@ -208,8 +244,9 @@ void QMLManager::loadDivesWithValidCredentials()
set_filename(fileNamePrt.data(), true); set_filename(fileNamePrt.data(), true);
} else { } else {
report_error("failed to open file %s", fileNamePrt.data()); report_error("failed to open file %s", fileNamePrt.data());
const char *error_string = get_error_string(); QString errorString(get_error_string());
appendTextToLog(error_string); appendTextToLog(errorString);
setStartPageText(tr("Cloud storage error: %1").arg(errorString));
return; return;
} }
process_dives(false, false); process_dives(false, false);
@ -222,6 +259,8 @@ void QMLManager::loadDivesWithValidCredentials()
DiveListModel::instance()->addDive(d); DiveListModel::instance()->addDive(d);
} }
appendTextToLog(QString("%1 dives loaded").arg(i)); appendTextToLog(QString("%1 dives loaded").arg(i));
if (dive_table.nr == 0)
setStartPageText(tr("Cloud storage open successfully. No dives in dive list."));
setLoadFromCloud(true); setLoadFromCloud(true);
} }
@ -393,3 +432,14 @@ void QMLManager::setLoadFromCloud(bool done)
m_loadFromCloud = done; m_loadFromCloud = done;
emit loadFromCloudChanged(); emit loadFromCloudChanged();
} }
QString QMLManager::startPageText() const
{
return m_startPageText;
}
void QMLManager::setStartPageText(QString text)
{
m_startPageText = text;
emit startPageTextChanged();
}

View file

@ -18,6 +18,7 @@ class QMLManager : public QObject
Q_PROPERTY(int distanceThreshold READ distanceThreshold WRITE setDistanceThreshold NOTIFY distanceThresholdChanged) Q_PROPERTY(int distanceThreshold READ distanceThreshold WRITE setDistanceThreshold NOTIFY distanceThresholdChanged)
Q_PROPERTY(int timeThreshold READ timeThreshold WRITE setTimeThreshold NOTIFY timeThresholdChanged) Q_PROPERTY(int timeThreshold READ timeThreshold WRITE setTimeThreshold NOTIFY timeThresholdChanged)
Q_PROPERTY(bool loadFromCloud READ loadFromCloud WRITE setLoadFromCloud NOTIFY loadFromCloudChanged) Q_PROPERTY(bool loadFromCloud READ loadFromCloud WRITE setLoadFromCloud NOTIFY loadFromCloudChanged)
Q_PROPERTY(QString startPageText READ startPageText WRITE setStartPageText NOTIFY startPageTextChanged)
public: public:
QMLManager(); QMLManager();
~QMLManager(); ~QMLManager();
@ -45,6 +46,9 @@ public:
bool loadFromCloud() const; bool loadFromCloud() const;
void setLoadFromCloud(bool done); void setLoadFromCloud(bool done);
QString startPageText() const;
void setStartPageText(QString text);
QString logText() const; QString logText() const;
void setLogText(const QString &logText); void setLogText(const QString &logText);
void appendTextToLog(const QString &newText); void appendTextToLog(const QString &newText);
@ -61,6 +65,7 @@ public slots:
void retrieveUserid(); void retrieveUserid();
void loadDives(); void loadDives();
void loadDivesWithValidCredentials(); void loadDivesWithValidCredentials();
void loadDiveProgress(int percent);
void provideAuth(QNetworkReply *reply, QAuthenticator *auth); void provideAuth(QNetworkReply *reply, QAuthenticator *auth);
void commitChanges(QString diveId, QString suit, QString buddy, QString diveMaster, QString notes); void commitChanges(QString diveId, QString suit, QString buddy, QString diveMaster, QString notes);
void saveChanges(); void saveChanges();
@ -74,6 +79,7 @@ private:
QString m_cloudUserName; QString m_cloudUserName;
QString m_cloudPassword; QString m_cloudPassword;
QString m_ssrfGpsWebUserid; QString m_ssrfGpsWebUserid;
QString m_startPageText;
bool m_saveCloudPassword; bool m_saveCloudPassword;
QString m_logText; QString m_logText;
bool m_locationServiceEnabled; bool m_locationServiceEnabled;
@ -95,6 +101,7 @@ signals:
void timeThresholdChanged(); void timeThresholdChanged();
void distanceThresholdChanged(); void distanceThresholdChanged();
void loadFromCloudChanged(); void loadFromCloudChanged();
void startPageTextChanged();
}; };
#endif #endif