diff --git a/harbour-fernschreiber.pro b/harbour-fernschreiber.pro
index 16e9acb..ee0e2a1 100644
--- a/harbour-fernschreiber.pro
+++ b/harbour-fernschreiber.pro
@@ -20,6 +20,7 @@ SOURCES += src/harbour-fernschreiber.cpp \
DISTFILES += qml/harbour-fernschreiber.qml \
qml/pages/CoverPage.qml \
+ qml/pages/InitializationPage.qml \
qml/pages/OverviewPage.qml \
qml/pages/AboutPage.qml \
rpm/harbour-fernschreiber.changes.in \
diff --git a/qml/pages/InitializationPage.qml b/qml/pages/InitializationPage.qml
new file mode 100644
index 0000000..a1d050b
--- /dev/null
+++ b/qml/pages/InitializationPage.qml
@@ -0,0 +1,267 @@
+/*
+ Copyright (C) 2020 Sebastian J. Wolf
+
+ This file is part of Fernschreiber.
+
+ fernschreiber is free software: you can redistribute it and/or modify
+ 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.
+
+ fernschreiber is distributed in the hope that it will be useful,
+ 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 .
+*/
+import QtQuick 2.2
+import Sailfish.Silica 1.0
+
+Page {
+ id: initializationPage
+ allowedOrientations: Orientation.All
+
+ 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
+ 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;
+ }
+ }
+ }
+
+ 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
+ width: 1/2 * parent.width
+ }
+
+ InfoLabel {
+ id: enterPinLabel
+ font.pixelSize: Theme.fontSizeLarge
+ text: qsTr("Please enter the PIN that you received:")
+ }
+
+ 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: {
+ //accountModel.enterPin(enterPinField.text)
+ enterPinColumn.visible = false;
+ }
+ }
+ }
+
+ 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
+ width: 1/2 * parent.width
+ }
+
+ InfoLabel {
+ id: linkingErrorInfoLabel
+ font.pixelSize: Theme.fontSizeLarge
+ text: qsTr("Unable to authenticate you with the entered PIN.")
+ }
+
+ Button {
+ id: enterPinAgainButton
+ text: qsTr("Enter PIN again")
+ 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
+ anchors.fill: parent
+ contentHeight: column.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
+ width: parent.width
+ spacing: Theme.paddingLarge
+
+ PageHeader {
+ title: qsTr("Welcome to Fernschreiber!")
+ }
+
+ Image {
+ id: fernschreiberImage
+ source: "../../images/fernschreiber.png"
+ anchors {
+ horizontalCenter: parent.horizontalCenter
+ }
+
+ fillMode: Image.PreserveAspectFit
+ width: 1/2 * parent.width
+ }
+
+ Label {
+ 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 {
+ text: qsTr("Continue")
+ anchors {
+ horizontalCenter: parent.horizontalCenter
+ }
+ enabled: phoneNumberTextField.text.match(/\+[1-9][0-9]{4,}/g)
+ onClicked: {
+ tdLibWrapper.setAuthenticationPhoneNumber(phoneNumberTextField.text);
+ }
+ }
+
+ Label {
+ id: separatorLabelPhoneNumber
+ x: Theme.horizontalPageMargin
+ width: parent.width - ( 2 * Theme.horizontalPageMargin )
+ font.pixelSize: Theme.fontSizeExtraSmall
+ anchors {
+ horizontalCenter: parent.horizontalCenter
+ }
+ }
+
+ }
+
+ }
+}
+
diff --git a/qml/pages/OverviewPage.qml b/qml/pages/OverviewPage.qml
index c74487a..bd82927 100644
--- a/qml/pages/OverviewPage.qml
+++ b/qml/pages/OverviewPage.qml
@@ -21,16 +21,40 @@ import QtGraphicalEffects 1.0
import QtMultimedia 5.0
import Sailfish.Silica 1.0
import Nemo.Notifications 1.0
+import WerkWolf.Fernschreiber 1.0
Page {
id: overviewPage
allowedOrientations: Orientation.All
+ property bool loading: true;
+
+ BusyLabel {
+ text: qsTr("Loading...")
+ running: overviewPage.loading
+ }
+
+ Connections {
+ target: tdLibWrapper
+ onAuthorizationStateChanged: {
+ switch (authorizationState) {
+ case TelegramAPI.WaitPhoneNumber:
+ overviewPage.loading = false;
+ pageStack.clear();
+ pageStack.push(Qt.resolvedUrl("../pages/InitializationPage.qml"));
+ break;
+ default:
+ // Nothing ;)
+ }
+ }
+ }
+
SilicaFlickable {
id: aboutContainer
contentHeight: column.height
anchors.fill: parent
+ visible: !overviewPage.loading
PullDownMenu {
MenuItem {
diff --git a/src/harbour-fernschreiber.cpp b/src/harbour-fernschreiber.cpp
index 00d6f34..b307378 100644
--- a/src/harbour-fernschreiber.cpp
+++ b/src/harbour-fernschreiber.cpp
@@ -40,6 +40,7 @@ int main(int argc, char *argv[])
TDLibWrapper tdLibWrapper;
context->setContextProperty("tdLibWrapper", &tdLibWrapper);
+ qmlRegisterType("WerkWolf.Fernschreiber", 1, 0, "TelegramAPI");
view->setSource(SailfishApp::pathTo("qml/harbour-fernschreiber.qml"));
view->show();
diff --git a/src/tdlibreceiver.cpp b/src/tdlibreceiver.cpp
index 76d2a0f..1dd7e3b 100644
--- a/src/tdlibreceiver.cpp
+++ b/src/tdlibreceiver.cpp
@@ -1,3 +1,21 @@
+/*
+ Copyright (C) 2020 Sebastian J. Wolf
+
+ This file is part of Fernschreiber.
+
+ fernschreiber is free software: you can redistribute it and/or modify
+ 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.
+
+ fernschreiber is distributed in the hope that it will be useful,
+ 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 .
+*/
#include "tdlibreceiver.h"
TDLibReceiver::TDLibReceiver(void *tdLibClient, QObject *parent) : QThread(parent)
diff --git a/src/tdlibreceiver.h b/src/tdlibreceiver.h
index 90e5a09..fa5d18d 100644
--- a/src/tdlibreceiver.h
+++ b/src/tdlibreceiver.h
@@ -1,3 +1,21 @@
+/*
+ Copyright (C) 2020 Sebastian J. Wolf
+
+ This file is part of Fernschreiber.
+
+ fernschreiber is free software: you can redistribute it and/or modify
+ 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.
+
+ fernschreiber is distributed in the hope that it will be useful,
+ 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 .
+*/
#ifndef TDLIBRECEIVER_H
#define TDLIBRECEIVER_H
diff --git a/src/tdlibwrapper.cpp b/src/tdlibwrapper.cpp
index 96dee15..bdaa85a 100644
--- a/src/tdlibwrapper.cpp
+++ b/src/tdlibwrapper.cpp
@@ -76,6 +76,19 @@ TDLibWrapper::ConnectionState TDLibWrapper::getConnectionState()
return this->connectionState;
}
+void TDLibWrapper::setAuthenticationPhoneNumber(const QString &phoneNumber)
+{
+ qDebug() << "[TDLibWrapper] Set authentication phone number " << phoneNumber;
+ QVariantMap requestObject;
+ requestObject.insert("@type", "setAuthenticationPhoneNumber");
+ requestObject.insert("phone_number", phoneNumber);
+ QVariantMap phoneNumberSettings;
+ phoneNumberSettings.insert("allow_flash_call", false);
+ phoneNumberSettings.insert("is_current_phone_number", true);
+ requestObject.insert("settings", phoneNumberSettings);
+ this->sendRequest(requestObject);
+}
+
void TDLibWrapper::handleVersionDetected(const QString &version)
{
this->version = version;
@@ -97,7 +110,7 @@ void TDLibWrapper::handleAuthorizationStateChanged(const QString &authorizationS
}
if (authorizationState == "authorizationStateReady") {
- this->authorizationState = AuthorizationState::Ready;
+ this->authorizationState = AuthorizationState::AuthorizationReady;
}
if (authorizationState == "authorizationStateWaitCode") {
@@ -149,7 +162,7 @@ void TDLibWrapper::handleConnectionStateChanged(const QString &connectionState)
this->connectionState = ConnectionState::ConnectingToProxy;
}
if (connectionState == "connectionStateReady") {
- this->connectionState = ConnectionState::IsReady;
+ this->connectionState = ConnectionState::ConnectionReady;
}
if (connectionState == "connectionStateUpdating") {
this->connectionState = ConnectionState::Updating;
diff --git a/src/tdlibwrapper.h b/src/tdlibwrapper.h
index 951099d..e32cf4d 100644
--- a/src/tdlibwrapper.h
+++ b/src/tdlibwrapper.h
@@ -1,3 +1,21 @@
+/*
+ Copyright (C) 2020 Sebastian J. Wolf
+
+ This file is part of Fernschreiber.
+
+ fernschreiber is free software: you can redistribute it and/or modify
+ 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.
+
+ fernschreiber is distributed in the hope that it will be useful,
+ 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 .
+*/
#ifndef TDLIBWRAPPER_H
#define TDLIBWRAPPER_H
@@ -20,7 +38,7 @@ public:
Closed,
Closing,
LoggingOut,
- Ready,
+ AuthorizationReady,
WaitCode,
WaitEncryptionKey,
WaitOtherDeviceConfirmation,
@@ -29,19 +47,22 @@ public:
WaitRegistration,
WaitTdlibParameters
};
+ Q_ENUM(AuthorizationState)
enum ConnectionState {
Connecting,
ConnectingToProxy,
- IsReady,
+ ConnectionReady,
Updating,
WaitingForNetwork
};
+ Q_ENUM(ConnectionState)
Q_INVOKABLE void sendRequest(const QVariantMap &requestObject);
Q_INVOKABLE QString getVersion();
Q_INVOKABLE TDLibWrapper::AuthorizationState getAuthorizationState();
Q_INVOKABLE TDLibWrapper::ConnectionState getConnectionState();
+ Q_INVOKABLE void setAuthenticationPhoneNumber(const QString &phoneNumber);
signals:
void versionDetected(const QString &version);
diff --git a/translations/harbour-fernschreiber-de.ts b/translations/harbour-fernschreiber-de.ts
index 0ab953f..f9fe1fe 100644
--- a/translations/harbour-fernschreiber-de.ts
+++ b/translations/harbour-fernschreiber-de.ts
@@ -60,6 +60,41 @@
+
+ InitializationPage
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
OverviewPage
@@ -70,5 +105,9 @@
+
+
+
+
diff --git a/translations/harbour-fernschreiber.ts b/translations/harbour-fernschreiber.ts
index 0ab953f..f9fe1fe 100644
--- a/translations/harbour-fernschreiber.ts
+++ b/translations/harbour-fernschreiber.ts
@@ -60,6 +60,41 @@
+
+ InitializationPage
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
OverviewPage
@@ -70,5 +105,9 @@
+
+
+
+