From 6b68d8a276c8c0d49e8dc28163842113e4d30b88 Mon Sep 17 00:00:00 2001 From: "Sebastian J. Wolf" Date: Thu, 13 Aug 2020 15:35:43 +0200 Subject: [PATCH] First successful authentication, yeah! :) --- qml/pages/InitializationPage.qml | 78 ++++++++++++++---------- qml/pages/OverviewPage.qml | 23 +++++++ src/tdlibwrapper.cpp | 9 +++ src/tdlibwrapper.h | 1 + translations/harbour-fernschreiber-de.ts | 36 ++++++----- translations/harbour-fernschreiber.ts | 36 ++++++----- 6 files changed, 119 insertions(+), 64 deletions(-) diff --git a/qml/pages/InitializationPage.qml b/qml/pages/InitializationPage.qml index a1d050b..ccdcc4a 100644 --- a/qml/pages/InitializationPage.qml +++ b/qml/pages/InitializationPage.qml @@ -18,11 +18,48 @@ */ import QtQuick 2.2 import Sailfish.Silica 1.0 +import WerkWolf.Fernschreiber 1.0 Page { id: initializationPage allowedOrientations: Orientation.All + property bool loading: true + property int authorizationState: TelegramAPI.Closed + + BusyLabel { + text: qsTr("Loading...") + running: initializationPage.loading + } + + Component.onCompleted: { + initializationPage.authorizationState = tdLibWrapper.getAuthorizationState(); + initializationPage.loading = false; + if (initializationPage.authorizationState === TelegramAPI.WaitCode) { + welcomeFlickable.visible = false; + enterPinColumn.visible = true; + } + } + + Connections { + target: tdLibWrapper + onAuthorizationStateChanged: { + switch (authorizationState) { + case TelegramAPI.WaitCode: + initializationPage.loading = false; + enterPinColumn.visible = true; + break; + case TelegramAPI.AuthorizationReady: + overviewPage.loading = false; + pageStack.clear(); + pageStack.push(Qt.resolvedUrl("../pages/OverviewPage.qml")); + break; + default: + // Nothing ;) + } + } + } + Column { y: ( parent.height - ( errorInfoLabel.height + fernschreiberErrorImage.height + errorOkButton.height + ( 3 * Theme.paddingSmall ) ) ) / 2 width: parent.width @@ -87,7 +124,7 @@ Page { InfoLabel { id: enterPinLabel font.pixelSize: Theme.fontSizeLarge - text: qsTr("Please enter the PIN that you received:") + text: qsTr("Please enter the code that you received:") } TextField { @@ -108,8 +145,9 @@ Page { horizontalCenter: parent.horizontalCenter } onClicked: { - //accountModel.enterPin(enterPinField.text) + initializationPage.loading = true; enterPinColumn.visible = false; + tdLibWrapper.setAuthenticationCode(enterPinField.text); } } } @@ -138,12 +176,12 @@ Page { InfoLabel { id: linkingErrorInfoLabel font.pixelSize: Theme.fontSizeLarge - text: qsTr("Unable to authenticate you with the entered PIN.") + text: qsTr("Unable to authenticate you with the entered code.") } Button { id: enterPinAgainButton - text: qsTr("Enter PIN again") + text: qsTr("Enter code again") anchors { horizontalCenter: parent.horizontalCenter } @@ -169,38 +207,12 @@ Page { SilicaFlickable { id: welcomeFlickable anchors.fill: parent - contentHeight: column.height + contentHeight: welcomeColumn.height Behavior on opacity { NumberAnimation {} } opacity: visible ? 1 : 0 -// Connections { -// target: accountModel -// onPinRequestSuccessful: { -// console.log("URL: " + url) -// Qt.openUrlExternally(url) -// welcomeFlickable.visible = false -// enterPinColumn.visible = true -// } -// onPinRequestError: { -// errorInfoLabel.text = errorMessage -// welcomeFlickable.visible = false -// pinErrorColumn.visible = true -// console.log("Error Message: " + errorMessage) -// } -// onLinkingSuccessful: { -// console.log("Linking successful, moving on to my tweets...") -// pageStack.clear() -// pageStack.push(overviewPage) -// } -// onLinkingFailed: { -// enterPinColumn.visible = false -// linkingErrorColumn.visible = true -// console.log("Linking error, proceeding to error page!") -// } -// } - Column { - id: column + id: welcomeColumn width: parent.width spacing: Theme.paddingLarge @@ -246,6 +258,8 @@ Page { } enabled: phoneNumberTextField.text.match(/\+[1-9][0-9]{4,}/g) onClicked: { + initializationPage.loading = true; + welcomeFlickable.visible = false; tdLibWrapper.setAuthenticationPhoneNumber(phoneNumberTextField.text); } } diff --git a/qml/pages/OverviewPage.qml b/qml/pages/OverviewPage.qml index bd82927..1bb9b6a 100644 --- a/qml/pages/OverviewPage.qml +++ b/qml/pages/OverviewPage.qml @@ -29,6 +29,8 @@ Page { allowedOrientations: Orientation.All property bool loading: true; + property int authorizationState: TelegramAPI.Closed + property int connectionState: TelegramAPI.WaitingForNetwork BusyLabel { text: qsTr("Loading...") @@ -44,10 +46,31 @@ Page { pageStack.clear(); pageStack.push(Qt.resolvedUrl("../pages/InitializationPage.qml")); break; + case TelegramAPI.WaitCode: + overviewPage.loading = false; + pageStack.clear(); + pageStack.push(Qt.resolvedUrl("../pages/InitializationPage.qml")); + break; + case TelegramAPI.AuthorizationReady: + overviewPage.loading = false; + break; default: // Nothing ;) } + overviewPage.authorizationState = authorizationState; } + onConnectionStateChanged: { + overviewPage.connectionState = connectionState; + } + } + + Component.onCompleted: { + overviewPage.authorizationState = tdLibWrapper.getAuthorizationState(); + if (overviewPage.authorizationState === TelegramAPI.AuthorizationReady) { + overviewPage.loading = false; + } + + overviewPage.connectionState = tdLibWrapper.getConnectionState(); } SilicaFlickable { diff --git a/src/tdlibwrapper.cpp b/src/tdlibwrapper.cpp index bdaa85a..8b13f30 100644 --- a/src/tdlibwrapper.cpp +++ b/src/tdlibwrapper.cpp @@ -89,6 +89,15 @@ void TDLibWrapper::setAuthenticationPhoneNumber(const QString &phoneNumber) this->sendRequest(requestObject); } +void TDLibWrapper::setAuthenticationCode(const QString &authenticationCode) +{ + qDebug() << "[TDLibWrapper] Set authentication code " << authenticationCode; + QVariantMap requestObject; + requestObject.insert("@type", "checkAuthenticationCode"); + requestObject.insert("code", authenticationCode); + this->sendRequest(requestObject); +} + void TDLibWrapper::handleVersionDetected(const QString &version) { this->version = version; diff --git a/src/tdlibwrapper.h b/src/tdlibwrapper.h index e32cf4d..6540719 100644 --- a/src/tdlibwrapper.h +++ b/src/tdlibwrapper.h @@ -63,6 +63,7 @@ public: Q_INVOKABLE TDLibWrapper::AuthorizationState getAuthorizationState(); Q_INVOKABLE TDLibWrapper::ConnectionState getConnectionState(); Q_INVOKABLE void setAuthenticationPhoneNumber(const QString &phoneNumber); + Q_INVOKABLE void setAuthenticationCode(const QString &authenticationCode); signals: void versionDetected(const QString &version); diff --git a/translations/harbour-fernschreiber-de.ts b/translations/harbour-fernschreiber-de.ts index f9fe1fe..599ee3d 100644 --- a/translations/harbour-fernschreiber-de.ts +++ b/translations/harbour-fernschreiber-de.ts @@ -66,22 +66,6 @@ OK - - Please enter the PIN that you received: - - - - Unable to authenticate you with the entered PIN. - - - - Enter PIN again - - - - Restart authentication - - Welcome to Fernschreiber! @@ -94,6 +78,26 @@ Continue + + Please enter the code that you received: + + + + Loading... + + + + Unable to authenticate you with the entered code. + + + + Enter code again + + + + Restart authentication + + OverviewPage diff --git a/translations/harbour-fernschreiber.ts b/translations/harbour-fernschreiber.ts index f9fe1fe..599ee3d 100644 --- a/translations/harbour-fernschreiber.ts +++ b/translations/harbour-fernschreiber.ts @@ -66,22 +66,6 @@ OK - - Please enter the PIN that you received: - - - - Unable to authenticate you with the entered PIN. - - - - Enter PIN again - - - - Restart authentication - - Welcome to Fernschreiber! @@ -94,6 +78,26 @@ Continue + + Please enter the code that you received: + + + + Loading... + + + + Unable to authenticate you with the entered code. + + + + Enter code again + + + + Restart authentication + + OverviewPage