From 8b670c3f3f937ca7b491e3e44f462a86b1509f53 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Tue, 5 Apr 2016 21:36:56 -0700 Subject: 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 --- mobile-widgets/qmlmanager.cpp | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) (limited to 'mobile-widgets/qmlmanager.cpp') 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; } -- cgit v1.2.3-70-g09d2