From 7ec9c206b5cbf6b4ddbfc17aae9f683483a55ca7 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Mon, 18 Jun 2018 18:14:05 +0900 Subject: QML UI: store nocloud data when adding cloud credentials We want to allow people to keep dives they collected without a cloud account. The code was mostly there, we just got confused about the existing status because we ran through this twice (no cloud -> unknown -> verified). This way we explicitly remember this kind of transition. Fixes #1404 Signed-off-by: Dirk Hohndel --- mobile-widgets/qmlmanager.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'mobile-widgets') diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index 90cf97b2b..b27fe4b37 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -37,6 +37,7 @@ #include "core/ssrf.h" QMLManager *QMLManager::m_instance = NULL; +bool noCloudToCloud = false; #define RED_FONT QLatin1Literal("") #define END_FONT QLatin1Literal("") @@ -442,6 +443,12 @@ void QMLManager::saveCloudCredentials() free((void *)prefs.cloud_storage_password); prefs.cloud_storage_password = copy_qstring(QMLPrefs::instance()->cloudPassword()); } + if (QMLPrefs::instance()->oldStatus() == QMLPrefs::CS_NOCLOUD && cloudCredentialsChanged && dive_table.nr) { + // we came from NOCLOUD and are connecting to a cloud account; + // since we already have dives in the table, let's remember that so we can keep them + noCloudToCloud = true; + appendTextToLog("transitioning from no-cloud to cloud and have dives"); + } if (QMLPrefs::instance()->cloudUserName().isEmpty() || QMLPrefs::instance()->cloudPassword().isEmpty()) { setStartPageText(RED_FONT + tr("Please enter valid cloud credentials.") + END_FONT); @@ -624,7 +631,13 @@ void QMLManager::loadDivesWithValidCredentials() } appendTextToLog("Cloud sync brought newer data, reloading the dive list"); - clear_dive_file_data(); + // if we aren't switching from no-cloud mode, let's clear the dive data + if (!noCloudToCloud) { + appendTextToLog("Clear out in memory dive data"); + clear_dive_file_data(); + } else { + appendTextToLog("Switching from no cloud mode; keep in memory dive data"); + } if (git != dummy_git_repository) { appendTextToLog(QString("have repository and branch %1").arg(branch)); error = git_load_dives(git, branch); @@ -649,13 +662,14 @@ successful_exit: 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 (QMLPrefs::instance()->oldStatus() == QMLPrefs::CS_NOCLOUD) { + if (noCloudToCloud) { git_storage_update_progress(qPrintable(tr("Loading dives from local storage ('no cloud' mode)"))); dive_table.preexisting = dive_table.nr; mergeLocalRepo(); DiveListModel::instance()->clear(); DiveListModel::instance()->addAllDives(); appendTextToLog(QStringLiteral("%1 dives loaded after importing nocloud local storage").arg(dive_table.nr)); + noCloudToCloud = false; saveChangesLocal(); if (m_syncToCloud == false) { appendTextToLog(QStringLiteral("taking things back offline now that storage is synced")); -- cgit v1.2.3-70-g09d2