diff options
-rw-r--r-- | qt-mobile/qml/StartPage.qml | 2 | ||||
-rw-r--r-- | qt-mobile/qmlmanager.cpp | 58 | ||||
-rw-r--r-- | qt-mobile/qmlmanager.h | 7 |
3 files changed, 62 insertions, 5 deletions
diff --git a/qt-mobile/qml/StartPage.qml b/qt-mobile/qml/StartPage.qml index 361c917bf..74da73ba8 100644 --- a/qt-mobile/qml/StartPage.qml +++ b/qt-mobile/qml/StartPage.qml @@ -20,7 +20,7 @@ Item { id: welcomeText Layout.fillWidth: true 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 Layout.columnSpan: 2 } diff --git a/qt-mobile/qmlmanager.cpp b/qt-mobile/qmlmanager.cpp index 13749caa4..15510bf5e 100644 --- a/qt-mobile/qmlmanager.cpp +++ b/qt-mobile/qmlmanager.cpp @@ -10,6 +10,7 @@ #include "pref.h" #include "qthelper.h" #include "qt-gui.h" +#include "git-access.h" QMLManager *QMLManager::m_instance = NULL; @@ -20,14 +21,30 @@ static void appendTextToLogStandalone(const char *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() : m_locationServiceEnabled(false), reply(0), mgr(0) { m_instance = this; + m_startPageText = tr("Searching for dive data"); // create location manager service locationProvider = new GpsLocation(&appendTextToLogStandalone, this); + set_git_update_cb(&gitProgressCB); } void QMLManager::finishSetup() @@ -40,6 +57,8 @@ void QMLManager::finishSetup() if (!same_string(prefs.cloud_storage_email, "") && !same_string(prefs.cloud_storage_password, "")) 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); setTimeThreshold(prefs.time_threshold / 60); @@ -150,6 +169,7 @@ void QMLManager::provideAuth(QNetworkReply *reply, QAuthenticator *auth) void QMLManager::handleSslErrors(const QList<QSslError> &errors) { + setStartPageText(tr("Cannot open cloud storage: Error creating https connection")); Q_FOREACH(QSslError e, errors) { qDebug() << e.errorString(); } @@ -159,7 +179,9 @@ void QMLManager::handleSslErrors(const QList<QSslError> &errors) 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->deleteLater(); } @@ -185,16 +207,30 @@ void QMLManager::retrieveUserid() 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() { if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute) != 302) { appendTextToLog(QString("Cloud storage connection not working correctly: ") + reply->readAll()); + setStartPageText(tr("Cannot connect to cloud storage")); return; } appendTextToLog("Cloud credentials valid, loading dives..."); + loadDiveProgress(0); QString url; if (getCloudURL(url)) { - appendTextToLog(get_error_string()); + QString errorString(get_error_string()); + appendTextToLog(errorString); + setStartPageText(tr("Cloud storage error: %1").arg(errorString)); return; } clear_dive_file_data(); @@ -208,8 +244,9 @@ void QMLManager::loadDivesWithValidCredentials() set_filename(fileNamePrt.data(), true); } else { report_error("failed to open file %s", fileNamePrt.data()); - const char *error_string = get_error_string(); - appendTextToLog(error_string); + QString errorString(get_error_string()); + appendTextToLog(errorString); + setStartPageText(tr("Cloud storage error: %1").arg(errorString)); return; } process_dives(false, false); @@ -222,6 +259,8 @@ void QMLManager::loadDivesWithValidCredentials() DiveListModel::instance()->addDive(d); } 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); } @@ -393,3 +432,14 @@ void QMLManager::setLoadFromCloud(bool done) m_loadFromCloud = done; emit loadFromCloudChanged(); } + +QString QMLManager::startPageText() const +{ + return m_startPageText; +} + +void QMLManager::setStartPageText(QString text) +{ + m_startPageText = text; + emit startPageTextChanged(); +} diff --git a/qt-mobile/qmlmanager.h b/qt-mobile/qmlmanager.h index bd6884894..37161c832 100644 --- a/qt-mobile/qmlmanager.h +++ b/qt-mobile/qmlmanager.h @@ -18,6 +18,7 @@ class QMLManager : public QObject Q_PROPERTY(int distanceThreshold READ distanceThreshold WRITE setDistanceThreshold NOTIFY distanceThresholdChanged) Q_PROPERTY(int timeThreshold READ timeThreshold WRITE setTimeThreshold NOTIFY timeThresholdChanged) Q_PROPERTY(bool loadFromCloud READ loadFromCloud WRITE setLoadFromCloud NOTIFY loadFromCloudChanged) + Q_PROPERTY(QString startPageText READ startPageText WRITE setStartPageText NOTIFY startPageTextChanged) public: QMLManager(); ~QMLManager(); @@ -45,6 +46,9 @@ public: bool loadFromCloud() const; void setLoadFromCloud(bool done); + QString startPageText() const; + void setStartPageText(QString text); + QString logText() const; void setLogText(const QString &logText); void appendTextToLog(const QString &newText); @@ -61,6 +65,7 @@ public slots: void retrieveUserid(); void loadDives(); void loadDivesWithValidCredentials(); + void loadDiveProgress(int percent); void provideAuth(QNetworkReply *reply, QAuthenticator *auth); void commitChanges(QString diveId, QString suit, QString buddy, QString diveMaster, QString notes); void saveChanges(); @@ -74,6 +79,7 @@ private: QString m_cloudUserName; QString m_cloudPassword; QString m_ssrfGpsWebUserid; + QString m_startPageText; bool m_saveCloudPassword; QString m_logText; bool m_locationServiceEnabled; @@ -95,6 +101,7 @@ signals: void timeThresholdChanged(); void distanceThresholdChanged(); void loadFromCloudChanged(); + void startPageTextChanged(); }; #endif |