diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2016-04-05 21:36:56 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2016-04-05 22:57:16 -0700 |
commit | 8b670c3f3f937ca7b491e3e44f462a86b1509f53 (patch) | |
tree | 66e83dc63fb4fa2bce89ffc6cb63e3eae34a66ba /mobile-widgets | |
parent | 8af45342863f096aee1359b1702c774035466c58 (diff) | |
download | subsurface-8b670c3f3f937ca7b491e3e44f462a86b1509f53.tar.gz |
QML UI: restructure (and fix) the saveChanges logic
We first want to save any exiting unsaved changes to the local repository
(and ONLY to the local repository). After that we want to make sure that
we are syncing remotely, fetch the remote and then (possibly after a
merge) push the changes to the remote. In the end we reset the previous
"local git only" preference which we overwrote for this manual forced
sync.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'mobile-widgets')
-rw-r--r-- | mobile-widgets/qmlmanager.cpp | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index 0fc3c65a7..9b9c15ef2 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -359,9 +359,6 @@ void QMLManager::loadDivesWithValidCredentials() setAccessingCloud(-1); return; } - clear_dive_file_data(); - DiveListModel::instance()->clear(); - appendTextToLog("Cloud sync brought newer data, reloading the dive list"); int error = parse_file(fileNamePrt.data()); @@ -725,28 +722,38 @@ void QMLManager::saveChanges() appendTextToLog("Save operation already in progress."); return; } - appendTextToLog("Saving dives."); - git_storage_update_progress(0, "saveChanges"); // reset the timers QString fileName; if (getCloudURL(fileName)) { appendTextToLog(get_error_string()); return; } - if (prefs.git_local_only == false) { - setAccessingCloud(0); - qApp->processEvents(); // make sure that the notification is actually shown - } alreadySaving = true; - if (save_dives(fileName.toUtf8().data())) { - appendTextToLog(get_error_string()); - setAccessingCloud(-1); - alreadySaving = false; - return; + bool glo = prefs.git_local_only; + bool cbs = prefs.cloud_background_sync; + if (unsaved_changes()) { + appendTextToLog("Saving dives locally."); + git_storage_update_progress(0, "saving dives locally"); // reset the timers + prefs.git_local_only = true; + prefs.cloud_background_sync = false; + if (save_dives(fileName.toUtf8().data())) { + appendTextToLog(get_error_string()); + setAccessingCloud(-1); + prefs.git_local_only = glo; + prefs.cloud_background_sync = cbs; + alreadySaving = false; + return; + } + } else { + git_storage_update_progress(0, "no unsaved changes, sync with remote"); } + prefs.git_local_only = false; + loadDivesWithValidCredentials(); setAccessingCloud(-1); - appendTextToLog("Updated dive list saved."); + appendTextToLog("synced dive list."); set_filename(fileName.toUtf8().data(), true); mark_divelist_changed(false); + prefs.git_local_only = glo; + prefs.cloud_background_sync = cbs; alreadySaving = false; } |