From 01de67a5a6f62f0c7d0b5b381c053e6db16f4e96 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sat, 13 Jun 2020 13:45:06 -0700 Subject: mobile: track if we have changes that aren't synced to cloud If we haven't connected at all to the cloud server we assume that there are local changes. And whenever we save changes only locally, we also set that flag. Signed-off-by: Dirk Hohndel --- mobile-widgets/qmlmanager.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'mobile-widgets/qmlmanager.cpp') diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index f338e5ba5..be4dc4ec3 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -304,6 +304,9 @@ QMLManager::QMLManager() : m_locationServiceEnabled(false), // get updates to the undo/redo texts connect(Command::getUndoStack(), &QUndoStack::undoTextChanged, this, &QMLManager::undoTextChanged); connect(Command::getUndoStack(), &QUndoStack::redoTextChanged, this, &QMLManager::redoTextChanged); + + // we start out with clean data + updateHaveLocalChanges(false); } void QMLManager::applicationStateChanged(Qt::ApplicationState state) @@ -401,6 +404,8 @@ void QMLManager::openLocalThenRemote(QString url) if (git_local_only && qPrefCloudStorage::cloud_verification_status() != qPrefCloudStorage::CS_NOCLOUD) appendTextToLog(QStringLiteral("have cloud credentials, but user asked not to connect to network")); + // if we were unable to sync with the remote, we assume that there are local changes + updateHaveLocalChanges(!git_remote_sync_successful); updateAllGlobalLists(); setDiveListProcessing(false); // this could have added a new local cache directory @@ -527,6 +532,7 @@ void QMLManager::finishSetup() } else { // successfully opened the local file, now add thigs to the dive list consumeFinishedLoad(); + updateHaveLocalChanges(true); appendTextToLog(QString("working in no-cloud mode, finished loading %1 dives from %2").arg(dive_table.nr).arg(existing_filename)); } } else { @@ -718,6 +724,7 @@ void QMLManager::loadDivesWithValidCredentials() consumeFinishedLoad(); } setLoadFromCloud(true); + // if we came from local storage mode, let's merge the local data into the local cache // for the remote data - which then later gets merged with the remote data if necessary if (noCloudToCloud) { @@ -732,6 +739,8 @@ void QMLManager::loadDivesWithValidCredentials() git_local_only = true; } } + // if we successfully synced with the cloud, update that status + updateHaveLocalChanges(!git_remote_sync_successful); // if we got here just for an initial connection to the cloud, reset to offline if (currentGitLocalOnly) { currentGitLocalOnly = false; @@ -1346,6 +1355,7 @@ void QMLManager::saveChangesLocal() } mark_divelist_changed(false); Command::setClean(); + updateHaveLocalChanges(true); } else { appendTextToLog("local save requested with no unsaved changes"); } @@ -2237,3 +2247,8 @@ QStringList QMLManager::cloudCacheList() const } return result; } + +void QMLManager::updateHaveLocalChanges(bool status) +{ + localChanges = status; +} -- cgit v1.2.3-70-g09d2