2020-08-13 11:15:26 +03:00
|
|
|
/*
|
|
|
|
Copyright (C) 2020 Sebastian J. Wolf
|
|
|
|
|
|
|
|
This file is part of Fernschreiber.
|
|
|
|
|
2020-08-13 18:08:14 +03:00
|
|
|
Fernschreiber is free software: you can redistribute it and/or modify
|
2020-08-13 11:15:26 +03:00
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
2020-08-13 18:08:14 +03:00
|
|
|
Fernschreiber is distributed in the hope that it will be useful,
|
2020-08-13 11:15:26 +03:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Fernschreiber. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
import QtQuick 2.2
|
|
|
|
import Sailfish.Silica 1.0
|
2020-08-13 16:35:43 +03:00
|
|
|
import WerkWolf.Fernschreiber 1.0
|
2020-08-13 11:15:26 +03:00
|
|
|
|
|
|
|
Page {
|
|
|
|
id: initializationPage
|
|
|
|
allowedOrientations: Orientation.All
|
2020-08-18 00:44:37 +03:00
|
|
|
backNavigation: false
|
2020-08-13 11:15:26 +03:00
|
|
|
|
2020-08-13 16:35:43 +03:00
|
|
|
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;
|
2020-09-16 23:36:43 +03:00
|
|
|
enterPasswordColumn.visible = false;
|
|
|
|
}
|
|
|
|
if (initializationPage.authorizationState === TelegramAPI.WaitPassword) {
|
|
|
|
welcomeFlickable.visible = false;
|
|
|
|
enterPinColumn.visible = false;
|
|
|
|
enterPasswordColumn.visible = true;
|
2020-08-13 16:35:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
target: tdLibWrapper
|
|
|
|
onAuthorizationStateChanged: {
|
|
|
|
switch (authorizationState) {
|
|
|
|
case TelegramAPI.WaitCode:
|
|
|
|
initializationPage.loading = false;
|
|
|
|
enterPinColumn.visible = true;
|
2020-09-16 23:36:43 +03:00
|
|
|
enterPasswordColumn.visible = false;
|
|
|
|
break;
|
|
|
|
case TelegramAPI.WaitPassword:
|
|
|
|
initializationPage.loading = false;
|
|
|
|
enterPinColumn.visible = false;
|
|
|
|
enterPasswordColumn.visible = true;
|
2020-08-13 16:35:43 +03:00
|
|
|
break;
|
|
|
|
case TelegramAPI.AuthorizationReady:
|
2020-08-18 00:44:37 +03:00
|
|
|
initializationPage.loading = false;
|
2020-08-18 12:11:03 +03:00
|
|
|
pageStack.completeAnimation();
|
2020-08-18 00:44:37 +03:00
|
|
|
pageStack.pop();
|
2020-08-13 16:35:43 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// Nothing ;)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-13 11:15:26 +03:00
|
|
|
Column {
|
|
|
|
y: ( parent.height - ( errorInfoLabel.height + fernschreiberErrorImage.height + errorOkButton.height + ( 3 * Theme.paddingSmall ) ) ) / 2
|
|
|
|
width: parent.width
|
|
|
|
id: pinErrorColumn
|
|
|
|
spacing: Theme.paddingSmall
|
|
|
|
|
|
|
|
Behavior on opacity { NumberAnimation {} }
|
|
|
|
opacity: visible ? 1 : 0
|
|
|
|
visible: false
|
|
|
|
|
|
|
|
Image {
|
|
|
|
id: fernschreiberErrorImage
|
|
|
|
source: "../../images/fernschreiber.png"
|
|
|
|
anchors {
|
|
|
|
horizontalCenter: parent.horizontalCenter
|
|
|
|
}
|
|
|
|
|
|
|
|
fillMode: Image.PreserveAspectFit
|
2020-08-29 17:32:43 +03:00
|
|
|
asynchronous: true
|
2020-08-13 11:15:26 +03:00
|
|
|
width: 1/2 * parent.width
|
|
|
|
}
|
|
|
|
|
|
|
|
InfoLabel {
|
|
|
|
id: errorInfoLabel
|
|
|
|
font.pixelSize: Theme.fontSizeLarge
|
|
|
|
text: ""
|
|
|
|
}
|
|
|
|
|
|
|
|
Button {
|
|
|
|
id: errorOkButton
|
|
|
|
text: qsTr("OK")
|
|
|
|
anchors {
|
|
|
|
horizontalCenter: parent.horizontalCenter
|
|
|
|
}
|
|
|
|
onClicked: {
|
|
|
|
pinErrorColumn.visible = false;
|
|
|
|
welcomeFlickable.visible = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-16 23:36:43 +03:00
|
|
|
Column {
|
|
|
|
y: ( parent.height - ( fernschreiberPasswordImage.height + enterPasswordLabel.height + enterPasswordField.height + enterPasswordButton.height + ( 3 * Theme.paddingSmall ) ) ) / 2
|
|
|
|
width: parent.width
|
|
|
|
id: enterPasswordColumn
|
|
|
|
spacing: Theme.paddingSmall
|
|
|
|
|
|
|
|
Behavior on opacity { NumberAnimation {} }
|
|
|
|
opacity: visible ? true : false
|
|
|
|
visible: false
|
|
|
|
|
|
|
|
Image {
|
|
|
|
id: fernschreiberPasswordImage
|
|
|
|
source: "../../images/fernschreiber.png"
|
|
|
|
anchors {
|
|
|
|
horizontalCenter: parent.horizontalCenter
|
|
|
|
}
|
|
|
|
|
|
|
|
fillMode: Image.PreserveAspectFit
|
|
|
|
asynchronous: true
|
|
|
|
width: 1/2 * parent.width
|
|
|
|
}
|
|
|
|
|
|
|
|
InfoLabel {
|
|
|
|
id: enterPasswordLabel
|
|
|
|
font.pixelSize: Theme.fontSizeLarge
|
|
|
|
text: qsTr("Please enter your password:")
|
|
|
|
}
|
|
|
|
|
|
|
|
TextField {
|
|
|
|
id: enterPasswordField
|
|
|
|
anchors {
|
|
|
|
horizontalCenter: parent.horizontalCenter
|
|
|
|
}
|
|
|
|
font.pixelSize: Theme.fontSizeLarge
|
|
|
|
width: parent.width - 2 * Theme.horizontalPageMargin
|
|
|
|
horizontalAlignment: TextInput.AlignHCenter
|
|
|
|
}
|
|
|
|
|
|
|
|
Button {
|
|
|
|
id: enterPasswordButton
|
|
|
|
text: qsTr("OK")
|
|
|
|
anchors {
|
|
|
|
horizontalCenter: parent.horizontalCenter
|
|
|
|
}
|
|
|
|
onClicked: {
|
|
|
|
initializationPage.loading = true;
|
|
|
|
enterPasswordColumn.visible = false;
|
|
|
|
tdLibWrapper.setAuthenticationPassword(enterPasswordField.text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-13 11:15:26 +03:00
|
|
|
Column {
|
|
|
|
y: ( parent.height - ( fernschreiberPinImage.height + enterPinLabel.height + enterPinField.height + enterPinButton.height + ( 3 * Theme.paddingSmall ) ) ) / 2
|
|
|
|
width: parent.width
|
|
|
|
id: enterPinColumn
|
|
|
|
spacing: Theme.paddingSmall
|
|
|
|
|
|
|
|
Behavior on opacity { NumberAnimation {} }
|
|
|
|
opacity: visible ? true : false
|
|
|
|
visible: false
|
|
|
|
|
|
|
|
Image {
|
|
|
|
id: fernschreiberPinImage
|
|
|
|
source: "../../images/fernschreiber.png"
|
|
|
|
anchors {
|
|
|
|
horizontalCenter: parent.horizontalCenter
|
|
|
|
}
|
|
|
|
|
|
|
|
fillMode: Image.PreserveAspectFit
|
2020-08-29 17:32:43 +03:00
|
|
|
asynchronous: true
|
2020-08-13 11:15:26 +03:00
|
|
|
width: 1/2 * parent.width
|
|
|
|
}
|
|
|
|
|
|
|
|
InfoLabel {
|
|
|
|
id: enterPinLabel
|
|
|
|
font.pixelSize: Theme.fontSizeLarge
|
2020-08-13 16:35:43 +03:00
|
|
|
text: qsTr("Please enter the code that you received:")
|
2020-08-13 11:15:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
TextField {
|
|
|
|
id: enterPinField
|
|
|
|
anchors {
|
|
|
|
horizontalCenter: parent.horizontalCenter
|
|
|
|
}
|
|
|
|
inputMethodHints: Qt.ImhDigitsOnly
|
|
|
|
font.pixelSize: Theme.fontSizeExtraLarge
|
|
|
|
width: parent.width - 4 * Theme.paddingLarge
|
|
|
|
horizontalAlignment: TextInput.AlignHCenter
|
|
|
|
}
|
|
|
|
|
|
|
|
Button {
|
|
|
|
id: enterPinButton
|
|
|
|
text: qsTr("OK")
|
|
|
|
anchors {
|
|
|
|
horizontalCenter: parent.horizontalCenter
|
|
|
|
}
|
|
|
|
onClicked: {
|
2020-08-13 16:35:43 +03:00
|
|
|
initializationPage.loading = true;
|
2020-08-13 11:15:26 +03:00
|
|
|
enterPinColumn.visible = false;
|
2020-08-13 16:35:43 +03:00
|
|
|
tdLibWrapper.setAuthenticationCode(enterPinField.text);
|
2020-08-13 11:15:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Column {
|
|
|
|
y: ( parent.height - ( fernschreiberLinkingErrorImage.height + linkingErrorInfoLabel.height + errorOkButton.height + ( 3 * Theme.paddingSmall ) ) ) / 2
|
|
|
|
width: parent.width
|
|
|
|
id: linkingErrorColumn
|
|
|
|
spacing: Theme.paddingSmall
|
|
|
|
|
|
|
|
Behavior on opacity { NumberAnimation {} }
|
|
|
|
opacity: visible ? true : false
|
|
|
|
visible: false
|
|
|
|
|
|
|
|
Image {
|
|
|
|
id: fernschreiberLinkingErrorImage
|
|
|
|
source: "../../images/fernschreiber.png"
|
|
|
|
anchors {
|
|
|
|
horizontalCenter: parent.horizontalCenter
|
|
|
|
}
|
|
|
|
|
|
|
|
fillMode: Image.PreserveAspectFit
|
2020-08-29 17:32:43 +03:00
|
|
|
asynchronous: true
|
2020-08-13 11:15:26 +03:00
|
|
|
width: 1/2 * parent.width
|
|
|
|
}
|
|
|
|
|
|
|
|
InfoLabel {
|
|
|
|
id: linkingErrorInfoLabel
|
|
|
|
font.pixelSize: Theme.fontSizeLarge
|
2020-08-13 16:35:43 +03:00
|
|
|
text: qsTr("Unable to authenticate you with the entered code.")
|
2020-08-13 11:15:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Button {
|
|
|
|
id: enterPinAgainButton
|
2020-08-13 16:35:43 +03:00
|
|
|
text: qsTr("Enter code again")
|
2020-08-13 11:15:26 +03:00
|
|
|
anchors {
|
|
|
|
horizontalCenter: parent.horizontalCenter
|
|
|
|
}
|
|
|
|
onClicked: {
|
|
|
|
linkingErrorColumn.visible = false;
|
|
|
|
enterPinColumn.visible = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Button {
|
|
|
|
id: restartAuthenticationButton
|
|
|
|
text: qsTr("Restart authentication")
|
|
|
|
anchors {
|
|
|
|
horizontalCenter: parent.horizontalCenter
|
|
|
|
}
|
|
|
|
onClicked: {
|
|
|
|
linkingErrorColumn.visible = false;
|
|
|
|
welcomeFlickable.visible = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SilicaFlickable {
|
|
|
|
id: welcomeFlickable
|
2020-08-13 16:35:43 +03:00
|
|
|
contentHeight: welcomeColumn.height
|
2020-08-13 11:15:26 +03:00
|
|
|
Behavior on opacity { NumberAnimation {} }
|
2020-08-18 00:44:37 +03:00
|
|
|
anchors.fill: parent
|
2020-08-13 11:15:26 +03:00
|
|
|
opacity: visible ? 1 : 0
|
|
|
|
|
|
|
|
Column {
|
2020-08-13 16:35:43 +03:00
|
|
|
id: welcomeColumn
|
2020-08-13 11:15:26 +03:00
|
|
|
width: parent.width
|
2020-08-18 00:44:37 +03:00
|
|
|
spacing: Theme.paddingSmall
|
2020-08-13 11:15:26 +03:00
|
|
|
|
|
|
|
PageHeader {
|
|
|
|
title: qsTr("Welcome to Fernschreiber!")
|
|
|
|
}
|
|
|
|
|
|
|
|
Image {
|
|
|
|
id: fernschreiberImage
|
|
|
|
source: "../../images/fernschreiber.png"
|
|
|
|
anchors {
|
|
|
|
horizontalCenter: parent.horizontalCenter
|
|
|
|
}
|
|
|
|
|
|
|
|
fillMode: Image.PreserveAspectFit
|
2020-08-29 17:32:43 +03:00
|
|
|
asynchronous: true
|
2020-08-13 11:15:26 +03:00
|
|
|
width: 1/2 * parent.width
|
|
|
|
}
|
|
|
|
|
|
|
|
Label {
|
2020-08-18 00:44:37 +03:00
|
|
|
id: enterPhoneNumberLabel
|
2020-08-13 11:15:26 +03:00
|
|
|
wrapMode: Text.Wrap
|
|
|
|
x: Theme.horizontalPageMargin
|
|
|
|
width: parent.width - ( 2 * Theme.horizontalPageMargin )
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
text: qsTr("Please enter your phone number to continue.")
|
|
|
|
font.pixelSize: Theme.fontSizeMedium
|
|
|
|
anchors {
|
|
|
|
horizontalCenter: parent.horizontalCenter
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TextField {
|
|
|
|
id: phoneNumberTextField
|
|
|
|
placeholderText: "Use the international format, e.g. +4912342424242"
|
|
|
|
inputMethodHints: Qt.ImhDialableCharactersOnly
|
|
|
|
labelVisible: false
|
|
|
|
width: parent.width
|
|
|
|
}
|
|
|
|
|
|
|
|
Button {
|
2020-08-18 00:44:37 +03:00
|
|
|
id: continueWithPhoneNumberButton
|
2020-08-13 11:15:26 +03:00
|
|
|
text: qsTr("Continue")
|
|
|
|
anchors {
|
|
|
|
horizontalCenter: parent.horizontalCenter
|
|
|
|
}
|
|
|
|
enabled: phoneNumberTextField.text.match(/\+[1-9][0-9]{4,}/g)
|
|
|
|
onClicked: {
|
2020-08-13 16:35:43 +03:00
|
|
|
initializationPage.loading = true;
|
|
|
|
welcomeFlickable.visible = false;
|
2020-08-13 11:15:26 +03:00
|
|
|
tdLibWrapper.setAuthenticationPhoneNumber(phoneNumberTextField.text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2020-08-18 00:44:37 +03:00
|
|
|
|
2020-08-13 11:15:26 +03:00
|
|
|
}
|
|
|
|
|