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 <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2020-06-13 13:45:06 -07:00
parent 8b478a969d
commit 01de67a5a6
2 changed files with 17 additions and 0 deletions

View file

@ -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;
}

View file

@ -263,9 +263,11 @@ private:
bool checkDuration(const DiveObjectHelper &myDive, struct dive *d, QString duration);
bool checkDepth(const DiveObjectHelper &myDive, struct dive *d, QString depth);
bool currentGitLocalOnly;
bool localChanges;
QString m_progressMessage;
bool m_btEnabled;
void updateAllGlobalLists();
void updateHaveLocalChanges(bool status);
location_t getGps(QString &gps);
QString m_pluggedInDeviceName;