From dbed88bd810c545a100840d02f2e72168680ed72 Mon Sep 17 00:00:00 2001 From: Jan Mulder Date: Wed, 27 Sep 2017 19:11:23 +0200 Subject: [PATCH] QML UI: rework single credential page to two pages This commit tries to implement most of issue #515. It reworks the one credential page, which its dynamic PIN part, into two pages. Main driver of selecting one of the two pages is the showPin boolean. Page 1 contains the email/passwd field (and the option to use a no cloud setup). Page 2 only contains the PIN part (and the option to cancel the process). The Kirigami central button does not seem very handy here. We need, for example, a cancel, sign-in and register, only register, etc. buttons, which are not easy to handle in specific icons. Therefore, normal pushbuttons are chosen to deal with user interaction, and the Kirigami button is removed from these pages. Signed-off-by: Jan Mulder --- mobile-widgets/qml/CloudCredentials.qml | 66 ++++++++++++++++++++++--- mobile-widgets/qml/DiveList.qml | 5 +- mobile-widgets/qml/StartPage.qml | 42 ++++++++++------ mobile-widgets/qmlmanager.cpp | 2 + 4 files changed, 93 insertions(+), 22 deletions(-) diff --git a/mobile-widgets/qml/CloudCredentials.qml b/mobile-widgets/qml/CloudCredentials.qml index 121dcfe2e..720783142 100644 --- a/mobile-widgets/qml/CloudCredentials.qml +++ b/mobile-widgets/qml/CloudCredentials.qml @@ -53,6 +53,7 @@ Item { Kirigami.Label { text: qsTr("Email") + visible: !rootItem.showPin font.pointSize: subsurfaceTheme.smallPointSize color: subsurfaceTheme.secondaryTextColor } @@ -60,16 +61,15 @@ Item { TextField { id: login text: manager.cloudUserName + visible: !rootItem.showPin Layout.fillWidth: true inputMethodHints: Qt.ImhEmailCharactersOnly | Qt.ImhNoAutoUppercase - onEditingFinished: { - saveCredentials() - } } Kirigami.Label { text: qsTr("Password") + visible: !rootItem.showPin font.pointSize: subsurfaceTheme.smallPointSize color: subsurfaceTheme.secondaryTextColor } @@ -77,14 +77,12 @@ Item { TextField { id: password text: manager.cloudPassword + visible: !rootItem.showPin echoMode: TextInput.PasswordEchoOnEdit inputMethodHints: Qt.ImhSensitiveData | Qt.ImhHiddenText | Qt.ImhNoAutoUppercase Layout.fillWidth: true - onEditingFinished: { - saveCredentials() - } } Kirigami.Label { @@ -97,5 +95,61 @@ Item { Layout.fillWidth: true visible: rootItem.showPin } + + RowLayout { + anchors.left: parent.left + anchors.right: parent.right + anchors.margins: Kirigami.Units.smallSpacing + spacing: Kirigami.Units.smallSpacing + visible: rootItem.showPin + SsrfButton { + id:registerpin + text: qsTr("Register") + onClicked: { + saveCredentials() + } + } + Kirigami.Label { + text: "" // Spacer between 2 button groups + Layout.fillWidth: true + } + SsrfButton { + id: cancelpin + text: qsTr("Cancel") + onClicked: { + manager.cancelCredentialsPinSetup() + rootItem.returnTopPage() + } + } + } + + RowLayout { + anchors.left: parent.left + anchors.right: parent.right + anchors.margins: Kirigami.Units.smallSpacing + spacing: Kirigami.Units.smallSpacing + visible: !rootItem.showPin + + SsrfButton { + id:signin_register_normal + text: qsTr("Sign-in or Register") + onClicked: { + saveCredentials() + } + } + Kirigami.Label { + text: "" // Spacer between 2 button groups + Layout.fillWidth: true + } + SsrfButton { + id: toNoCloudMode + text: qsTr("No cloud mode") + onClicked: { + manager.syncToCloud = false + manager.credentialStatus = QMLManager.CS_NOCLOUD + manager.saveCloudCredentials() + } + } + } } } diff --git a/mobile-widgets/qml/DiveList.qml b/mobile-widgets/qml/DiveList.qml index 9442bf9b7..b1444ee8b 100644 --- a/mobile-widgets/qml/DiveList.qml +++ b/mobile-widgets/qml/DiveList.qml @@ -271,8 +271,8 @@ Kirigami.ScrollablePage { Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration } } function setupActions() { if (visible) { - page.actions.main = page.saveAction - page.actions.right = page.offlineAction + page.actions.main = null + page.actions.right = null page.title = qsTr("Cloud credentials") } else if(manager.credentialStatus === QMLManager.CS_VERIFIED || manager.credentialStatus === QMLManager.CS_NOCLOUD) { page.actions.main = page.downloadFromDCAction @@ -358,6 +358,7 @@ Kirigami.ScrollablePage { onTriggered: { manager.syncToCloud = false manager.credentialStatus = QMLManager.CS_NOCLOUD + manager.saveCloudCredentials() } } diff --git a/mobile-widgets/qml/StartPage.qml b/mobile-widgets/qml/StartPage.qml index e988fb9e9..f23510522 100644 --- a/mobile-widgets/qml/StartPage.qml +++ b/mobile-widgets/qml/StartPage.qml @@ -11,18 +11,12 @@ Kirigami.ScrollablePage { function saveCredentials() { cloudCredentials.saveCredentials() } ColumnLayout { - Kirigami.Label { - id: explanationText + CloudCredentials { + id: cloudCredentials Layout.fillWidth: true Layout.margins: Kirigami.Units.gridUnit - Layout.topMargin: Kirigami.Units.gridUnit * 3 - text: qsTr("To use Subsurface-mobile with Subsurface cloud storage, please enter your cloud credentials.\n") + - qsTr("If this is the first time you use Subsurface cloud storage, enter a valid email (all lower case) " + - "and a password of your choice (letters and numbers). " + - "The server will send a PIN to the email address provided that you will have to enter here.\n\n") + - qsTr("To use Subsurface-mobile only with local data on this device, tap " + - "on the no cloud icon below.") - wrapMode: Text.WordWrap + Layout.topMargin: 0 + property int headingLevel: 3 } Kirigami.Label { id: messageArea @@ -32,12 +26,32 @@ Kirigami.ScrollablePage { text: manager.startPageText wrapMode: Text.WordWrap } - CloudCredentials { - id: cloudCredentials + Kirigami.Label { + id: explanationTextBasic + visible: !showPin Layout.fillWidth: true Layout.margins: Kirigami.Units.gridUnit - Layout.topMargin: 0 - property int headingLevel: 3 + Layout.topMargin: Kirigami.Units.gridUnit * 3 + text: qsTr("To use Subsurface-mobile with Subsurface cloud storage, please enter your cloud credentials.\n\n") + + qsTr("If this is the first time you use Subsurface cloud storage, enter a valid email (all lower case) " + + "and a password of your choice (letters and numbers).\n\n") + + qsTr("To use Subsurface-mobile only with local data on this device, select " + + "the no cloud buttton above.") + wrapMode: Text.WordWrap + } + Kirigami.Label { + id: explanationTextPin + visible: showPin + Layout.fillWidth: true + Layout.margins: Kirigami.Units.gridUnit + Layout.topMargin: Kirigami.Units.gridUnit * 3 + text: qsTr("Thank you for registering with Subsurface. We sent ") + manager.cloudUserName + + qsTr(" a PIN code to complete the registration. ") + + qsTr("If you do not receive an email from us within 15 minutes, please check " + + "the correct spelling of your email address and your spam box first.\n\n" + + "In case of any problems regarding cloud account setup, please contact us " + + "at our user forum \(https://subsurface-divelog.org/user-forum/\).\n\n") + wrapMode: Text.WordWrap } Item { width: Kirigami.Units.gridUnit; height: 3 * Kirigami.Units.gridUnit} } diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index 15b4eafe5..982861ba0 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -267,6 +267,7 @@ void QMLManager::finishSetup() openLocalThenRemote(url); } else if (!same_string(existing_filename, "") && credentialStatus() != CS_UNKNOWN) { setCredentialStatus(CS_NOCLOUD); + saveCloudCredentials(); appendTextToLog(tr("working in no-cloud mode")); int error = parse_file(existing_filename); if (error) { @@ -337,6 +338,7 @@ void QMLManager::saveCloudCredentials() s.beginGroup("CloudStorage"); s.setValue("email", cloudUser); s.setValue("password", cloudPwd); + s.setValue("cloud_verification_status", credentialStatus()); s.sync(); if (!same_string(prefs.cloud_storage_email, qPrintable(cloudUser))) { free(prefs.cloud_storage_email);