diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2016-04-03 18:33:40 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2016-04-04 14:18:41 -0700 |
commit | bb74144860b14d23f26ebd3dd72e4654342282ae (patch) | |
tree | b61f9b3406452e2722f9fc77cecfb642ed819e73 | |
parent | 616842c8c00654718ba3390b055eb946aaa4cff4 (diff) | |
download | subsurface-bb74144860b14d23f26ebd3dd72e4654342282ae.tar.gz |
QML UI: allow user to disable automatic cloud sync
This is useful if you are in an area with slow or spotty network and if
you are fine with just saving to the phone. In order to sync to the cloud
you either have to manually sync via the menu or turn this back on and
hide the application.
The commit also removes the old refresh from the Manage dives menu as the
semantic of that was possibly destructive now that we no longer
immediately save changes to git - those could be thrown away by selecting
refresh before the app had a chance to save them.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | qt-mobile/qml/main.qml | 18 | ||||
-rw-r--r-- | qt-mobile/qmlmanager.cpp | 29 | ||||
-rw-r--r-- | qt-mobile/qmlmanager.h | 7 |
3 files changed, 34 insertions, 20 deletions
diff --git a/qt-mobile/qml/main.qml b/qt-mobile/qml/main.qml index 6b6116611..f4f6ea28b 100644 --- a/qt-mobile/qml/main.qml +++ b/qt-mobile/qml/main.qml @@ -20,6 +20,7 @@ Kirigami.ApplicationWindow { property alias accessingCloud: manager.accessingCloud property QtObject notification: null property bool showingDiveList: false + property alias syncToCloud: manager.syncToCloud onAccessingCloudChanged: { if (accessingCloud >= 0) { // we now keep updating this to show progress, so timing out after 30 seconds is more useful @@ -133,19 +134,24 @@ Kirigami.ApplicationWindow { } } Kirigami.Action { - text: "Refresh" + text: "Manual sync with cloud" onTriggered: { globalDrawer.close() detailsWindow.endEditMode() - manager.loadDives(); + manager.saveChanges(); } } Kirigami.Action { - text: "Upload to cloud" + text: syncToCloud ? "Disable auto cloud sync" : "Enable auto cloud sync" onTriggered: { - globalDrawer.close() - detailsWindow.endEditMode() - manager.saveChanges(); + syncToCloud = !syncToCloud + if (!syncToCloud) { + var alertText = "Turning off automatic sync to cloud causes all data to only be stored locally.\n" + alertText += "This can be very useful in situations with limited or no network access.\n" + alertText += "Please chose 'Manual sync with cloud' if you have network connectivity\n" + alertText += "and want to sync your data to cloud storage." + showPassiveNotification(alertText, 10000) + } } } }, diff --git a/qt-mobile/qmlmanager.cpp b/qt-mobile/qmlmanager.cpp index b8683de43..ef6ba659d 100644 --- a/qt-mobile/qmlmanager.cpp +++ b/qt-mobile/qmlmanager.cpp @@ -72,6 +72,7 @@ QMLManager::QMLManager() : m_locationServiceEnabled(false), qDebug() << QStringLiteral("build with Qt Version %1, runtime from Qt Version %2").arg(QT_VERSION_STR).arg(qVersion()); setStartPageText(tr("Starting...")); setAccessingCloud(-1); + setSyncToCloud(true); // create location manager service locationProvider = new GpsLocation(&appendTextToLogStandalone, this); set_git_update_cb(&gitProgressCB); @@ -103,13 +104,7 @@ void QMLManager::applicationStateChanged(Qt::ApplicationState state) // make sure the user sees that we are saving data if they come back // while this is running alreadySaving = true; - bool cbs = prefs.cloud_background_sync; - bool glo = prefs.git_local_only; - prefs.cloud_background_sync = true; - prefs.git_local_only = false; saveChanges(); - prefs.cloud_background_sync = cbs; - prefs.git_local_only = glo; alreadySaving = false; appendTextToLog(QString::number(timer.elapsed() / 1000.0,'f', 3) + ": done saving to git local / remote"); mark_divelist_changed(false); @@ -120,10 +115,11 @@ void QMLManager::openLocalThenRemote(QString url) { clear_dive_file_data(); QByteArray fileNamePrt = QFile::encodeName(url); + bool glo = prefs.git_local_only; prefs.git_local_only = true; int error = parse_file(fileNamePrt.data()); setAccessingCloud(-1); - prefs.git_local_only = false; + prefs.git_local_only = glo; if (error) { appendTextToLog(QStringLiteral("loading dives from cache failed %1").arg(error)); } else { @@ -255,12 +251,6 @@ void QMLManager::tryRetrieveDataFromBackend() checkCredentialsAndExecute(&QMLManager::retrieveUserid); } -void QMLManager::loadDives() -{ - setAccessingCloud(0); - checkCredentialsAndExecute(&QMLManager::loadDivesWithValidCredentials); -} - void QMLManager::provideAuth(QNetworkReply *reply, QAuthenticator *auth) { if (auth->user() == QString(prefs.cloud_storage_email) && @@ -1049,6 +1039,19 @@ void QMLManager::setAccessingCloud(int status) emit accessingCloudChanged(); } +bool QMLManager::syncToCloud() const +{ + return m_syncToCloud; +} + +void QMLManager::setSyncToCloud(bool status) +{ + m_syncToCloud = status; + prefs.git_local_only = !status; + prefs.cloud_background_sync = status; + emit syncToCloudChanged(); +} + qreal QMLManager::lastDevicePixelRatio() { return m_lastDevicePixelRatio; diff --git a/qt-mobile/qmlmanager.h b/qt-mobile/qmlmanager.h index 15954e9ec..7c56119d5 100644 --- a/qt-mobile/qmlmanager.h +++ b/qt-mobile/qmlmanager.h @@ -23,6 +23,7 @@ class QMLManager : public QObject { Q_PROPERTY(bool verboseEnabled READ verboseEnabled WRITE setVerboseEnabled NOTIFY verboseEnabledChanged) Q_PROPERTY(credentialStatus_t credentialStatus READ credentialStatus WRITE setCredentialStatus NOTIFY credentialStatusChanged) Q_PROPERTY(int accessingCloud READ accessingCloud WRITE setAccessingCloud NOTIFY accessingCloudChanged) + Q_PROPERTY(bool syncToCloud READ syncToCloud WRITE setSyncToCloud NOTIFY syncToCloudChanged) public: QMLManager(); @@ -72,6 +73,9 @@ public: int accessingCloud() const; void setAccessingCloud(int status); + bool syncToCloud() const; + void setSyncToCloud(bool status); + typedef void (QMLManager::*execute_function_type)(); public slots: @@ -83,7 +87,6 @@ public slots: void handleError(QNetworkReply::NetworkError nError); void handleSslErrors(const QList<QSslError> &errors); void retrieveUserid(); - void loadDives(); void loadDivesWithValidCredentials(); void loadDiveProgress(int percent); void provideAuth(QNetworkReply *reply, QAuthenticator *auth); @@ -134,6 +137,7 @@ private: struct dive *deletedDive; struct dive_trip *deletedTrip; int m_accessingCloud; + bool m_syncToCloud; credentialStatus_t m_credentialStatus; qreal m_lastDevicePixelRatio; QElapsedTimer timer; @@ -151,6 +155,7 @@ signals: void startPageTextChanged(); void credentialStatusChanged(); void accessingCloudChanged(); + void syncToCloudChanged(); void sendScreenChanged(QScreen *screen); }; |