Mobile: factor out syncToCloud [3/3]

After the previous commits, we now have a preference that nicely
preserves the state of the UI, and we have the well known git_local_only
global, that is used to denote whether we want to use to local repo
only, or we want to interact with the online cloud as well.

This commit gets rid of the now superfluous syncToCloud logic. Instead
we simply set the git_local_only directly.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
This commit is contained in:
Jan Mulder 2018-10-09 10:23:24 +02:00 committed by Dirk Hohndel
parent 87b8155576
commit a95e658946
5 changed files with 14 additions and 21 deletions

View file

@ -1,3 +1,4 @@
- Mobile: preserve manual/auto sync with cloud [#1725]
- Performance: calculate full statistics only when needed - Performance: calculate full statistics only when needed
- HTML export: write statistics of exported dives only - HTML export: write statistics of exported dives only
- Desktop: fix calculation of surface interval in the case of overlappimg dives - Desktop: fix calculation of surface interval in the case of overlappimg dives

View file

@ -143,7 +143,7 @@ Item {
id: toNoCloudMode id: toNoCloudMode
text: qsTr("No cloud mode") text: qsTr("No cloud mode")
onClicked: { onClicked: {
manager.syncToCloud = false manager.setGitLocalOnly(true)
PrefCloudStorage.cloud_auto_sync = false PrefCloudStorage.cloud_auto_sync = false
prefs.credentialStatus = CloudStatus.CS_NOCLOUD prefs.credentialStatus = CloudStatus.CS_NOCLOUD
manager.saveCloudCredentials() manager.saveCloudCredentials()

View file

@ -28,7 +28,6 @@ Kirigami.ApplicationWindow {
} }
property alias oldStatus: prefs.oldStatus property alias oldStatus: prefs.oldStatus
property alias notificationText: manager.notificationText property alias notificationText: manager.notificationText
property alias syncToCloud: manager.syncToCloud
property alias locationServiceEnabled: manager.locationServiceEnabled property alias locationServiceEnabled: manager.locationServiceEnabled
property alias pluggedInDeviceName: manager.pluggedInDeviceName property alias pluggedInDeviceName: manager.pluggedInDeviceName
property alias showPin: prefs.showPin property alias showPin: prefs.showPin
@ -279,7 +278,7 @@ Kirigami.ApplicationWindow {
visible: prefs.credentialStatus !== CloudStatus.CS_NOCLOUD visible: prefs.credentialStatus !== CloudStatus.CS_NOCLOUD
onTriggered: { onTriggered: {
PrefCloudStorage.cloud_auto_sync = !PrefCloudStorage.cloud_auto_sync PrefCloudStorage.cloud_auto_sync = !PrefCloudStorage.cloud_auto_sync
syncToCloud = PrefCloudStorage.cloud_auto_sync manager.setGitLocalOnly(PrefCloudStorage.cloud_auto_sync)
if (!PrefCloudStorage.cloud_auto_sync) { if (!PrefCloudStorage.cloud_auto_sync) {
showPassiveNotification(qsTr("Turning off automatic sync to cloud causes all data to only be \ showPassiveNotification(qsTr("Turning off automatic sync to cloud causes all data to only be \
stored locally. This can be very useful in situations with limited or no network access. Please choose 'Manual sync with cloud' \ stored locally. This can be very useful in situations with limited or no network access. Please choose 'Manual sync with cloud' \

View file

@ -375,7 +375,7 @@ void QMLManager::finishSetup()
// Initialize cloud credentials. // Initialize cloud credentials.
QMLPrefs::instance()->setCloudUserName(qPrefCloudStorage::cloud_storage_email()); QMLPrefs::instance()->setCloudUserName(qPrefCloudStorage::cloud_storage_email());
QMLPrefs::instance()->setCloudPassword(qPrefCloudStorage::cloud_storage_password()); QMLPrefs::instance()->setCloudPassword(qPrefCloudStorage::cloud_storage_password());
setSyncToCloud(!git_local_only); git_local_only = !prefs.cloud_auto_sync;
QMLPrefs::instance()->setCredentialStatus((qPrefCloudStorage::cloud_status) prefs.cloud_verification_status); QMLPrefs::instance()->setCredentialStatus((qPrefCloudStorage::cloud_status) prefs.cloud_verification_status);
// if the cloud credentials are valid, we should get the GPS Webservice ID as well // if the cloud credentials are valid, we should get the GPS Webservice ID as well
QString url; QString url;
@ -679,9 +679,9 @@ successful_exit:
noCloudToCloud = false; noCloudToCloud = false;
mark_divelist_changed(true); mark_divelist_changed(true);
saveChangesLocal(); saveChangesLocal();
if (m_syncToCloud == false) { if (git_local_only == false) {
appendTextToLog(QStringLiteral("taking things back offline now that storage is synced")); appendTextToLog(QStringLiteral("taking things back offline now that storage is synced"));
git_local_only = m_syncToCloud; git_local_only = true;
} }
} }
// if we got here just for an initial connection to the cloud, reset to offline // if we got here just for an initial connection to the cloud, reset to offline
@ -705,9 +705,9 @@ void QMLManager::revertToNoCloudIfNeeded()
// and cloud data) failed - so let's delete the cloud credentials and go // and cloud data) failed - so let's delete the cloud credentials and go
// back to CS_NOCLOUD mode in order to prevent us from losing the locally stored // back to CS_NOCLOUD mode in order to prevent us from losing the locally stored
// dives // dives
if (m_syncToCloud == false) { if (git_local_only == true) {
appendTextToLog(QStringLiteral("taking things back offline since sync with cloud failed")); appendTextToLog(QStringLiteral("taking things back offline since sync with cloud failed"));
git_local_only = m_syncToCloud; git_local_only = false;
} }
free((void *)prefs.cloud_storage_email); free((void *)prefs.cloud_storage_email);
prefs.cloud_storage_email = NULL; prefs.cloud_storage_email = NULL;
@ -1492,13 +1492,6 @@ void QMLManager::setNotificationText(QString text)
emit notificationTextChanged(); emit notificationTextChanged();
} }
void QMLManager::setSyncToCloud(bool status)
{
m_syncToCloud = status;
git_local_only = !status;
emit syncToCloudChanged();
}
void QMLManager::setUpdateSelectedDive(int idx) void QMLManager::setUpdateSelectedDive(int idx)
{ {
m_updateSelectedDive = idx; m_updateSelectedDive = idx;
@ -1764,6 +1757,11 @@ int QMLManager::getConnectionIndex(const QString &deviceSubstr)
return connectionListModel.indexOf(deviceSubstr); return connectionListModel.indexOf(deviceSubstr);
} }
void QMLManager::setGitLocalOnly(const bool &value)
{
git_local_only = value;
}
void QMLManager::showDownloadPage(QString deviceString) void QMLManager::showDownloadPage(QString deviceString)
{ {
// we pass the indices for the three combo boxes for vendor, product, and connection // we pass the indices for the three combo boxes for vendor, product, and connection

View file

@ -28,7 +28,6 @@ class QMLManager : public QObject {
Q_PROPERTY(QString startPageText MEMBER m_startPageText WRITE setStartPageText NOTIFY startPageTextChanged) Q_PROPERTY(QString startPageText MEMBER m_startPageText WRITE setStartPageText NOTIFY startPageTextChanged)
Q_PROPERTY(bool verboseEnabled MEMBER m_verboseEnabled WRITE setVerboseEnabled NOTIFY verboseEnabledChanged) Q_PROPERTY(bool verboseEnabled MEMBER m_verboseEnabled WRITE setVerboseEnabled NOTIFY verboseEnabledChanged)
Q_PROPERTY(QString notificationText MEMBER m_notificationText WRITE setNotificationText NOTIFY notificationTextChanged) Q_PROPERTY(QString notificationText MEMBER m_notificationText WRITE setNotificationText NOTIFY notificationTextChanged)
Q_PROPERTY(bool syncToCloud MEMBER m_syncToCloud WRITE setSyncToCloud NOTIFY syncToCloudChanged)
Q_PROPERTY(int updateSelectedDive MEMBER m_updateSelectedDive WRITE setUpdateSelectedDive NOTIFY updateSelectedDiveChanged) Q_PROPERTY(int updateSelectedDive MEMBER m_updateSelectedDive WRITE setUpdateSelectedDive NOTIFY updateSelectedDiveChanged)
Q_PROPERTY(int selectedDiveTimestamp MEMBER m_selectedDiveTimestamp WRITE setSelectedDiveTimestamp NOTIFY selectedDiveTimestampChanged) Q_PROPERTY(int selectedDiveTimestamp MEMBER m_selectedDiveTimestamp WRITE setSelectedDiveTimestamp NOTIFY selectedDiveTimestampChanged)
Q_PROPERTY(QStringList suitList READ suitList NOTIFY suitListChanged) Q_PROPERTY(QStringList suitList READ suitList NOTIFY suitListChanged)
@ -88,6 +87,7 @@ public:
Q_INVOKABLE int getDetectedVendorIndex(); Q_INVOKABLE int getDetectedVendorIndex();
Q_INVOKABLE int getDetectedProductIndex(const QString &currentVendorText); Q_INVOKABLE int getDetectedProductIndex(const QString &currentVendorText);
Q_INVOKABLE int getConnectionIndex(const QString &deviceSubstr); Q_INVOKABLE int getConnectionIndex(const QString &deviceSubstr);
Q_INVOKABLE void setGitLocalOnly(const bool &value);
static QMLManager *instance(); static QMLManager *instance();
Q_INVOKABLE void registerError(QString error); Q_INVOKABLE void registerError(QString error);
@ -115,9 +115,6 @@ public:
QString notificationText() const; QString notificationText() const;
void setNotificationText(QString text); void setNotificationText(QString text);
bool syncToCloud() const;
void setSyncToCloud(bool status);
int updateSelectedDive() const; int updateSelectedDive() const;
void setUpdateSelectedDive(int idx); void setUpdateSelectedDive(int idx);
@ -210,7 +207,6 @@ private:
struct dive *deletedDive; struct dive *deletedDive;
struct dive_trip *deletedTrip; struct dive_trip *deletedTrip;
QString m_notificationText; QString m_notificationText;
bool m_syncToCloud;
int m_updateSelectedDive; int m_updateSelectedDive;
int m_selectedDiveTimestamp; int m_selectedDiveTimestamp;
qreal m_lastDevicePixelRatio; qreal m_lastDevicePixelRatio;
@ -241,7 +237,6 @@ signals:
void loadFromCloudChanged(); void loadFromCloudChanged();
void startPageTextChanged(); void startPageTextChanged();
void notificationTextChanged(); void notificationTextChanged();
void syncToCloudChanged();
void updateSelectedDiveChanged(); void updateSelectedDiveChanged();
void selectedDiveTimestampChanged(); void selectedDiveTimestampChanged();
void sendScreenChanged(QScreen *screen); void sendScreenChanged(QScreen *screen);