diff options
author | Jan Mulder <jlmulder@xs4all.nl> | 2017-08-03 14:55:09 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2017-09-04 07:38:30 -0700 |
commit | 9a2d503d3b3d2c0a4631ef6c26dcf1c6785a4e56 (patch) | |
tree | 31270a689b6d00666553a0cc71ee9bbb27a70a7a /mobile-widgets | |
parent | 7e2803d6dd65016bfd925345adf3abdfbbbe6056 (diff) | |
download | subsurface-9a2d503d3b3d2c0a4631ef6c26dcf1c6785a4e56.tar.gz |
Unify credential states
Having two different enums around with more or less the same
definition has lead to unclear code. After removing two not needed
states on the mobile end, the remaining step to one enum for the
credential state becomes almost is simple rename operation.
Unfortunately, I do not know a way to embed a plain C enum
from pref.h into the QMLManager object. So after this, there
are still 2 enums around, but now identical.
This commit is not changing any functionality.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
Diffstat (limited to 'mobile-widgets')
-rw-r--r-- | mobile-widgets/qml/DiveList.qml | 11 | ||||
-rw-r--r-- | mobile-widgets/qml/main.qml | 14 | ||||
-rw-r--r-- | mobile-widgets/qmlmanager.cpp | 40 | ||||
-rw-r--r-- | mobile-widgets/qmlmanager.h | 29 |
4 files changed, 48 insertions, 46 deletions
diff --git a/mobile-widgets/qml/DiveList.qml b/mobile-widgets/qml/DiveList.qml index 1dccb5b75..be659e6b9 100644 --- a/mobile-widgets/qml/DiveList.qml +++ b/mobile-widgets/qml/DiveList.qml @@ -24,7 +24,7 @@ Kirigami.ScrollablePage { supportsRefreshing: true onRefreshingChanged: { if (refreshing) { - if (manager.credentialStatus === QMLManager.VALID) { + if (manager.credentialStatus === QMLManager.CS_VERIFIED) { console.log("User pulled down dive list - syncing with cloud storage") detailsWindow.endEditMode() manager.saveChangesCloud(true) @@ -266,7 +266,7 @@ Kirigami.ScrollablePage { StartPage { id: startPage anchors.fill: parent - opacity: credentialStatus === QMLManager.NOCLOUD || (credentialStatus === QMLManager.VALID) ? 0 : 1 + opacity: credentialStatus === QMLManager.CS_NOCLOUD || (credentialStatus === QMLManager.CS_VERIFIED) ? 0 : 1 visible: opacity > 0 Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration } } function setupActions() { @@ -274,7 +274,7 @@ Kirigami.ScrollablePage { page.actions.main = page.saveAction page.actions.right = page.offlineAction page.title = qsTr("Cloud credentials") - } else if(manager.credentialStatus === QMLManager.VALID || manager.credentialStatus === QMLManager.NOCLOUD) { + } else if(manager.credentialStatus === QMLManager.CS_VERIFIED || manager.credentialStatus === QMLManager.CS_NOCLOUD) { page.actions.main = page.downloadFromDCAction page.actions.right = page.addDiveAction page.title = qsTr("Dive list") @@ -289,6 +289,7 @@ Kirigami.ScrollablePage { onVisibleChanged: { setupActions(); } + Component.onCompleted: { setupActions(); } @@ -355,12 +356,12 @@ Kirigami.ScrollablePage { iconName: "qrc:/qml/nocloud.svg" onTriggered: { manager.syncToCloud = false - manager.credentialStatus = QMLManager.NOCLOUD + manager.credentialStatus = QMLManager.CS_NOCLOUD } } onBackRequested: { - if (startPage.visible && diveListView.count > 0 && manager.credentialStatus !== QMLManager.INVALID) { + if (startPage.visible && diveListView.count > 0 && manager.credentialStatus !== QMLManager.CS_INCORRECT_USER_PASSWD) { manager.credentialStatus = oldStatus event.accepted = true; } diff --git a/mobile-widgets/qml/main.qml b/mobile-widgets/qml/main.qml index e34e89e50..1cf1ea35d 100644 --- a/mobile-widgets/qml/main.qml +++ b/mobile-widgets/qml/main.qml @@ -117,10 +117,10 @@ Kirigami.ApplicationWindow { text: qsTr("Dive list") onTriggered: { manager.appendTextToLog("requested dive list with credential status " + manager.credentialStatus) - if (manager.credentialStatus == QMLManager.UNKNOWN) { + if (manager.credentialStatus == QMLManager.CS_UNKNOWN) { // the user has asked to change credentials - if the credentials before that // were valid, go back to dive list - if (oldStatus == QMLManager.VALID) { + if (oldStatus == QMLManager.CS_VERIFIED) { manager.credentialStatus = oldStatus } } @@ -134,7 +134,7 @@ Kirigami.ApplicationWindow { Kirigami.Action { iconName: "icons/ic_add.svg" text: qsTr("Add dive manually") - enabled: manager.credentialStatus === QMLManager.VALID || manager.credentialStatus === QMLManager.NOCLOUD + enabled: manager.credentialStatus === QMLManager.CS_VERIFIED || manager.credentialStatus === QMLManager.CS_NOCLOUD onTriggered: { returnTopPage() // otherwise odd things happen with the page stack startAddDive() @@ -159,13 +159,13 @@ Kirigami.ApplicationWindow { Kirigami.Action { iconName: "icons/cloud_sync.svg" text: qsTr("Manual sync with cloud") - enabled: manager.credentialStatus === QMLManager.VALID || manager.credentialStatus === QMLManager.NOCLOUD + enabled: manager.credentialStatus === QMLManager.CS_VERIFIED || manager.credentialStatus === QMLManager.CS_NOCLOUD onTriggered: { - if (manager.credentialStatus === QMLManager.NOCLOUD) { + if (manager.credentialStatus === QMLManager.CS_NOCLOUD) { returnTopPage() oldStatus = manager.credentialStatus manager.startPageText = "Enter valid cloud storage credentials" - manager.credentialStatus = QMLManager.UNKNOWN + manager.credentialStatus = QMLManager.CS_UNKNOWN globalDrawer.close() } else { globalDrawer.close() @@ -178,7 +178,7 @@ Kirigami.ApplicationWindow { Kirigami.Action { iconName: syncToCloud ? "icons/ic_cloud_off.svg" : "icons/ic_cloud_done.svg" text: syncToCloud ? qsTr("Offline mode") : qsTr("Enable auto cloud sync") - enabled: manager.credentialStatus !== QMLManager.NOCLOUD + enabled: manager.credentialStatus !== QMLManager.CS_NOCLOUD onTriggered: { syncToCloud = !syncToCloud if (!syncToCloud) { diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index 62eae8e8c..7a132a13e 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -84,7 +84,7 @@ QMLManager::QMLManager() : m_locationServiceEnabled(false), deletedTrip(0), m_updateSelectedDive(-1), m_selectedDiveTimestamp(0), - m_credentialStatus(UNKNOWN), + m_credentialStatus(CS_UNKNOWN), alreadySaving(false), m_device_data(new DCDeviceData(this)), m_libdcLog(false) @@ -174,8 +174,8 @@ void QMLManager::openLocalThenRemote(QString url) setNotificationText(tr("Opening local data file failed")); } else { // if we can load from the cache, we know that we have a valid cloud account - if (credentialStatus() == UNKNOWN) - setCredentialStatus(VALID); + if (credentialStatus() == CS_UNKNOWN) + setCredentialStatus(CS_VERIFIED); prefs.unit_system = git_prefs.unit_system; if (git_prefs.unit_system == IMPERIAL) git_prefs.units = IMPERIAL_units; @@ -193,8 +193,8 @@ void QMLManager::openLocalThenRemote(QString url) appendTextToLog(QStringLiteral("%1 dives loaded from cache").arg(dive_table.nr)); setNotificationText(tr("%1 dives loaded from local dive data file").arg(dive_table.nr)); } - if (oldStatus() == NOCLOUD) { - // if we switch to credentials from NOCLOUD, we take things online temporarily + if (oldStatus() == CS_NOCLOUD) { + // if we switch to credentials from CS_NOCLOUD, we take things online temporarily prefs.git_local_only = false; appendTextToLog(QStringLiteral("taking things online to be able to switch to cloud account")); } @@ -231,7 +231,7 @@ void QMLManager::finishSetup() alreadySaving = true; openLocalThenRemote(url); } else if (!same_string(existing_filename, "")) { - setCredentialStatus(NOCLOUD); + setCredentialStatus(CS_NOCLOUD); appendTextToLog(tr("working in no-cloud mode")); int error = parse_file(existing_filename); if (error) { @@ -245,7 +245,7 @@ void QMLManager::finishSetup() appendTextToLog(QString("working in no-cloud mode, finished loading %1 dives from %2").arg(dive_table.nr).arg(existing_filename)); } } else { - setCredentialStatus(UNKNOWN); + setCredentialStatus(CS_UNKNOWN); appendTextToLog(tr("no cloud credentials")); setStartPageText(RED_FONT + tr("Please enter valid cloud credentials.") + END_FONT); } @@ -414,7 +414,7 @@ void QMLManager::provideAuth(QNetworkReply *reply, QAuthenticator *auth) // OK, credentials have been tried and didn't work, so they are invalid appendTextToLog("Cloud credentials are invalid"); setStartPageText(RED_FONT + tr("Cloud credentials are invalid") + END_FONT); - setCredentialStatus(INVALID); + setCredentialStatus(CS_INCORRECT_USER_PASSWD); reply->disconnect(); reply->abort(); reply->deleteLater(); @@ -455,7 +455,7 @@ void QMLManager::retrieveUserid() revertToNoCloudIfNeeded(); return; } - setCredentialStatus(VALID); + setCredentialStatus(CS_VERIFIED); QString userid(prefs.userid); if (userid.isEmpty()) { if (same_string(prefs.cloud_storage_email, "") || same_string(prefs.cloud_storage_password, "")) { @@ -474,7 +474,7 @@ void QMLManager::retrieveUserid() s.setValue("subsurface_webservice_uid", prefs.userid); s.sync(); } - setCredentialStatus(VALID); + setCredentialStatus(CS_VERIFIED); setStartPageText(tr("Cloud credentials valid, loading dives...")); // this only gets called with "alreadySaving" already locked loadDivesWithValidCredentials(); @@ -529,7 +529,7 @@ 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 (oldStatus() == NOCLOUD) { + if (oldStatus() == CS_NOCLOUD) { git_storage_update_progress(qPrintable(tr("Loading dives from local storage ('no cloud' mode)"))); dive_table.preexisting = dive_table.nr; mergeLocalRepo(); @@ -557,11 +557,11 @@ void QMLManager::revertToNoCloudIfNeeded() currentGitLocalOnly = false; prefs.git_local_only = true; } - if (oldStatus() == NOCLOUD) { + if (oldStatus() == CS_NOCLOUD) { // we tried to switch to a cloud account and had previously used local data, // but connecting to the cloud account (and subsequently merging the local // and cloud data) failed - so let's delete the cloud credentials and go - // back to 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 if (syncToCloud() == false) { appendTextToLog(QStringLiteral("taking things back offline since sync with cloud failed")); @@ -573,7 +573,7 @@ void QMLManager::revertToNoCloudIfNeeded() prefs.cloud_storage_password = NULL; setCloudUserName(""); setCloudPassword(""); - setCredentialStatus(NOCLOUD); + setCredentialStatus(CS_NOCLOUD); set_filename(NOCLOUD_LOCALSTORAGE, true); setStartPageText(RED_FONT + tr("Failed to connect to cloud server, reverting to no cloud status") + END_FONT); } @@ -1004,7 +1004,7 @@ void QMLManager::changesNeedSaving() void QMLManager::saveChangesLocal() { if (unsaved_changes()) { - if (credentialStatus() == NOCLOUD) { + if (credentialStatus() == CS_NOCLOUD) { if (same_string(existing_filename, "")) { char *filename = NOCLOUD_LOCALSTORAGE; if (git_create_local_repo(filename)) @@ -1367,27 +1367,27 @@ void QMLManager::setStartPageText(const QString& text) emit startPageTextChanged(); } -QMLManager::credentialStatus_t QMLManager::credentialStatus() const +QMLManager::cloud_status_qml QMLManager::credentialStatus() const { return m_credentialStatus; } -void QMLManager::setCredentialStatus(const credentialStatus_t value) +void QMLManager::setCredentialStatus(const cloud_status_qml value) { if (m_credentialStatus != value) { - if (value == NOCLOUD) + if (value == CS_NOCLOUD) appendTextToLog("Switching to no cloud mode"); m_credentialStatus = value; emit credentialStatusChanged(); } } -QMLManager::credentialStatus_t QMLManager::oldStatus() const +QMLManager::cloud_status_qml QMLManager::oldStatus() const { return m_oldStatus; } -void QMLManager::setOldStatus(const credentialStatus_t value) +void QMLManager::setOldStatus(const cloud_status_qml value) { if (m_oldStatus != value) { m_oldStatus = value; diff --git a/mobile-widgets/qmlmanager.h b/mobile-widgets/qmlmanager.h index fc468baf4..dec9e6502 100644 --- a/mobile-widgets/qmlmanager.h +++ b/mobile-widgets/qmlmanager.h @@ -16,7 +16,7 @@ class QMLManager : public QObject { Q_OBJECT - Q_ENUMS(credentialStatus_t) + Q_ENUMS(cloud_status_qml) Q_PROPERTY(QString cloudUserName READ cloudUserName WRITE setCloudUserName NOTIFY cloudUserNameChanged) Q_PROPERTY(QString cloudPassword READ cloudPassword WRITE setCloudPassword NOTIFY cloudPasswordChanged) Q_PROPERTY(QString cloudPin READ cloudPin WRITE setCloudPin NOTIFY cloudPinChanged) @@ -29,8 +29,8 @@ class QMLManager : public QObject { Q_PROPERTY(bool loadFromCloud READ loadFromCloud WRITE setLoadFromCloud NOTIFY loadFromCloudChanged) Q_PROPERTY(QString startPageText READ startPageText WRITE setStartPageText NOTIFY startPageTextChanged) Q_PROPERTY(bool verboseEnabled READ verboseEnabled WRITE setVerboseEnabled NOTIFY verboseEnabledChanged) - Q_PROPERTY(credentialStatus_t credentialStatus READ credentialStatus WRITE setCredentialStatus NOTIFY credentialStatusChanged) - Q_PROPERTY(credentialStatus_t oldStatus READ oldStatus WRITE setOldStatus NOTIFY oldStatusChanged) + Q_PROPERTY(cloud_status_qml credentialStatus READ credentialStatus WRITE setCredentialStatus NOTIFY credentialStatusChanged) + Q_PROPERTY(cloud_status_qml oldStatus READ oldStatus WRITE setOldStatus NOTIFY oldStatusChanged) Q_PROPERTY(QString notificationText READ notificationText WRITE setNotificationText NOTIFY notificationTextChanged) Q_PROPERTY(bool syncToCloud READ syncToCloud WRITE setSyncToCloud NOTIFY syncToCloudChanged) Q_PROPERTY(int updateSelectedDive READ updateSelectedDive WRITE setUpdateSelectedDive NOTIFY updateSelectedDiveChanged) @@ -48,11 +48,12 @@ public: QMLManager(); ~QMLManager(); - enum credentialStatus_t { - UNKNOWN, - INVALID, - VALID, - NOCLOUD + enum cloud_status_qml { + CS_UNKNOWN, + CS_INCORRECT_USER_PASSWD, + CS_NEED_TO_VERIFY, + CS_VERIFIED, + CS_NOCLOUD }; static QMLManager *instance(); @@ -91,11 +92,11 @@ public: QString startPageText() const; void setStartPageText(const QString& text); - credentialStatus_t credentialStatus() const; - void setCredentialStatus(const credentialStatus_t value); + cloud_status_qml credentialStatus() const; + void setCredentialStatus(const cloud_status_qml value); - credentialStatus_t oldStatus() const; - void setOldStatus(const credentialStatus_t value); + cloud_status_qml oldStatus() const; + void setOldStatus(const cloud_status_qml value); QString logText() const; void setLogText(const QString &logText); @@ -207,8 +208,8 @@ private: bool m_syncToCloud; int m_updateSelectedDive; int m_selectedDiveTimestamp; - credentialStatus_t m_credentialStatus; - credentialStatus_t m_oldStatus; + cloud_status_qml m_credentialStatus; + cloud_status_qml m_oldStatus; qreal m_lastDevicePixelRatio; QElapsedTimer timer; bool alreadySaving; |