diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2016-02-09 07:53:22 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2016-02-09 07:53:22 -0800 |
commit | 87f62dfaa8a0c92c02ff7e5811f182a639a96dfa (patch) | |
tree | 5bf3725598c364e2908e67addd0467103ce74366 /qt-mobile | |
parent | 0cc9ad0619760c003575935f5a26d4bede5bbe7e (diff) | |
download | subsurface-87f62dfaa8a0c92c02ff7e5811f182a639a96dfa.tar.gz |
QML UI: load from cache first when changing cloud credentials
We need to execute the same sequence of steps both when starting the app
and when switching cloud credentials. This way things will work correctly
when the device is offline and the user wants to switch accounts.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-mobile')
-rw-r--r-- | qt-mobile/qmlmanager.cpp | 55 | ||||
-rw-r--r-- | qt-mobile/qmlmanager.h | 1 |
2 files changed, 32 insertions, 24 deletions
diff --git a/qt-mobile/qmlmanager.cpp b/qt-mobile/qmlmanager.cpp index d720be61e..76b4e7a93 100644 --- a/qt-mobile/qmlmanager.cpp +++ b/qt-mobile/qmlmanager.cpp @@ -58,6 +58,33 @@ QMLManager::QMLManager() : m_locationServiceEnabled(false), syncLoadFromCloud(); } +void QMLManager::openLocalThenRemote(QString url) +{ + clear_dive_file_data(); + QByteArray fileNamePrt = QFile::encodeName(url); + prefs.git_local_only = true; + int error = parse_file(fileNamePrt.data()); + prefs.git_local_only = false; + if (error) { + appendTextToLog(QStringLiteral("loading dives from cache failed %1").arg(error)); + } else { + prefs.unit_system = informational_prefs.unit_system; + if (informational_prefs.unit_system == IMPERIAL) + informational_prefs.units = IMPERIAL_units; + prefs.units = informational_prefs.units; + int i; + struct dive *d; + process_dives(false, false); + DiveListModel::instance()->clear(); + for_each_dive (i, d) { + DiveListModel::instance()->addDive(d); + } + appendTextToLog(QStringLiteral("%1 dives loaded from cache").arg(i)); + } + appendTextToLog(QStringLiteral("have cloud credentials, trying to connect")); + tryRetrieveDataFromBackend(); +} + void QMLManager::finishSetup() { // Initialize cloud credentials. @@ -69,29 +96,7 @@ void QMLManager::finishSetup() if (!same_string(prefs.cloud_storage_email, "") && !same_string(prefs.cloud_storage_password, "") && getCloudURL(url) == 0) { - clear_dive_file_data(); - QByteArray fileNamePrt = QFile::encodeName(url); - prefs.git_local_only = true; - int error = parse_file(fileNamePrt.data()); - prefs.git_local_only = false; - if (error) { - appendTextToLog(QStringLiteral("loading dives from cache failed %1").arg(error)); - } else { - prefs.unit_system = informational_prefs.unit_system; - if (informational_prefs.unit_system == IMPERIAL) - informational_prefs.units = IMPERIAL_units; - prefs.units = informational_prefs.units; - int i; - struct dive *d; - process_dives(false, false); - DiveListModel::instance()->clear(); - for_each_dive (i, d) { - DiveListModel::instance()->addDive(d); - } - appendTextToLog(QStringLiteral("%1 dives loaded from cache").arg(i)); - } - appendTextToLog(QStringLiteral("have cloud credentials, trying to connect")); - tryRetrieveDataFromBackend(); + openLocalThenRemote(url); } else { appendTextToLog(QStringLiteral("no cloud credentials, tell user no dives found")); setStartPageText(tr("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.")); @@ -154,7 +159,9 @@ void QMLManager::saveCloudCredentials() free(prefs.userid); prefs.userid = NULL; syncLoadFromCloud(); - tryRetrieveDataFromBackend(); + QString url; + getCloudURL(url); + openLocalThenRemote(url); } } diff --git a/qt-mobile/qmlmanager.h b/qt-mobile/qmlmanager.h index 4d9b9cc8c..a29a74648 100644 --- a/qt-mobile/qmlmanager.h +++ b/qt-mobile/qmlmanager.h @@ -85,6 +85,7 @@ public slots: void populateGpsData(); void clearGpsData(); void finishSetup(); + void openLocalThenRemote(QString url); void showMap(const QString& location); QString getNumber(const QString& diveId); QString getDate(const QString& diveId); |