From 8414f8392690861b98ea59e9f412ca18e2b25f67 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sat, 4 Apr 2020 14:23:39 -0700 Subject: [PATCH] mobile/cleanup: create helper function to hide verbose casts The strange enum casts (that apparently we needed in order to have strongly typed enums in QML) are really ugly and confusing in the code. Since we had this three times it seemed worth to create a little helper that hides this nonsense. Signed-off-by: Dirk Hohndel --- mobile-widgets/qmlmanager.cpp | 11 ++++++++--- mobile-widgets/qmlmanager.h | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index 11e71c5a2..99811d66c 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -511,7 +511,7 @@ void QMLManager::finishSetup() openLocalThenRemote(url); } else if (!empty_string(existing_filename) && qPrefCloudStorage::cloud_verification_status() != qPrefCloudStorage::CS_UNKNOWN) { - setOldStatus((qPrefCloudStorage::cloud_status)qPrefCloudStorage::cloud_verification_status()); + rememberOldStatus(); set_filename(qPrintable(nocloud_localstorage())); qPrefCloudStorage::set_cloud_verification_status(qPrefCloudStorage::CS_NOCLOUD); saveCloudCredentials(qPrefCloudStorage::cloud_storage_email(), qPrefCloudStorage::cloud_storage_password(), qPrefCloudStorage::cloud_storage_pin()); @@ -619,7 +619,7 @@ void QMLManager::saveCloudCredentials(const QString &newEmail, const QString &ne git_local_only = false; loadDivesWithValidCredentials(); } - setOldStatus((qPrefCloudStorage::cloud_status)qPrefCloudStorage::cloud_verification_status()); + rememberOldStatus(); } bool QMLManager::verifyCredentials(QString email, QString password, QString pin) @@ -756,7 +756,7 @@ void QMLManager::revertToNoCloudIfNeeded() prefs.cloud_storage_password = NULL; qPrefCloudStorage::set_cloud_storage_email(""); qPrefCloudStorage::set_cloud_storage_password(""); - setOldStatus((qPrefCloudStorage::cloud_status)qPrefCloudStorage::cloud_verification_status()); + rememberOldStatus(); qPrefCloudStorage::set_cloud_verification_status(qPrefCloudStorage::CS_NOCLOUD); set_filename(qPrintable(nocloud_localstorage())); setStartPageText(RED_FONT + tr("Failed to connect to cloud server, reverting to no cloud status") + END_FONT); @@ -2160,6 +2160,11 @@ void QMLManager::setOldStatus(const qPrefCloudStorage::cloud_status value) } } +void QMLManager::rememberOldStatus() +{ + setOldStatus((qPrefCloudStorage::cloud_status)qPrefCloudStorage::cloud_verification_status()); +} + void QMLManager::divesChanged(const QVector &dives, DiveField field) { Q_UNUSED(field) diff --git a/mobile-widgets/qmlmanager.h b/mobile-widgets/qmlmanager.h index e37f1c474..fd353cb76 100644 --- a/mobile-widgets/qmlmanager.h +++ b/mobile-widgets/qmlmanager.h @@ -170,6 +170,7 @@ public: #endif qPrefCloudStorage::cloud_status oldStatus() const; void setOldStatus(const qPrefCloudStorage::cloud_status value); + void rememberOldStatus(); public slots: void appInitialized();