harbour-fernschreiber/qml/pages/OverviewPage.qml

164 lines
4.9 KiB
QML
Raw Normal View History

2020-08-10 15:17:29 +03:00
/*
Copyright (C) 2020 Sebastian J. Wolf
This file is part of Fernschreiber.
Fernschreiber is free software: you can redistribute it and/or modify
2020-08-10 15:17:29 +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.
Fernschreiber is distributed in the hope that it will be useful,
2020-08-10 15:17:29 +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.5
import QtGraphicalEffects 1.0
import QtMultimedia 5.0
import Sailfish.Silica 1.0
import Nemo.Notifications 1.0
import WerkWolf.Fernschreiber 1.0
2020-08-10 15:17:29 +03:00
Page {
id: overviewPage
allowedOrientations: Orientation.All
property bool initializationCompleted: false;
property bool loading: true;
property int authorizationState: TelegramAPI.Closed
property int connectionState: TelegramAPI.WaitingForNetwork
onStatusChanged: {
console.log("[OverviewPage] Status changed: " + status + ", initialization completed: " + initializationCompleted);
if (status === PageStatus.Active && initializationCompleted) {
updateContent();
}
}
BusyLabel {
text: qsTr("Loading...")
running: overviewPage.loading
}
function setPageStatus() {
switch (overviewPage.connectionState) {
case TelegramAPI.WaitingForNetwork:
pageStatus.color = "red";
2020-08-13 23:32:35 +03:00
pageHeader.title = qsTr("Waiting for network...");
break;
case TelegramAPI.Connecting:
pageStatus.color = "gold";
2020-08-13 23:32:35 +03:00
pageHeader.title = qsTr("Connecting to network...");
break;
case TelegramAPI.ConnectingToProxy:
pageStatus.color = "gold";
2020-08-13 23:32:35 +03:00
pageHeader.title = qsTr("Connecting to proxy...");
break;
case TelegramAPI.ConnectionReady:
pageStatus.color = "green";
pageHeader.title = qsTr("Fernschreiber");
break;
case TelegramAPI.Updating:
pageStatus.color = "lightblue";
2020-08-13 23:32:35 +03:00
pageHeader.title = qsTr("Updating content...");
break;
}
}
2020-08-13 23:32:35 +03:00
function updateContent() {
2020-08-16 18:38:51 +03:00
tdLibWrapper.getChats();
2020-08-18 00:44:37 +03:00
}
function initializePage() {
overviewPage.authorizationState = tdLibWrapper.getAuthorizationState();
overviewPage.handleAuthorizationState();
overviewPage.connectionState = tdLibWrapper.getConnectionState();
overviewPage.setPageStatus();
}
function handleAuthorizationState() {
switch (overviewPage.authorizationState) {
case TelegramAPI.WaitPhoneNumber:
2020-08-18 00:44:37 +03:00
overviewPage.loading = false;
pageStack.push(Qt.resolvedUrl("../pages/InitializationPage.qml"));
break;
case TelegramAPI.WaitCode:
overviewPage.loading = false;
pageStack.push(Qt.resolvedUrl("../pages/InitializationPage.qml"));
break;
case TelegramAPI.AuthorizationReady:
overviewPage.loading = false;
overviewPage.initializationCompleted = true;
2020-08-18 00:44:37 +03:00
overviewPage.updateContent();
break;
default:
// Nothing ;)
2020-08-18 00:44:37 +03:00
}
2020-08-13 23:32:35 +03:00
}
Connections {
target: tdLibWrapper
onAuthorizationStateChanged: {
overviewPage.authorizationState = authorizationState;
handleAuthorizationState();
}
onConnectionStateChanged: {
overviewPage.connectionState = connectionState;
setPageStatus();
}
}
Component.onCompleted: {
2020-08-18 00:44:37 +03:00
initializePage();
}
2020-08-10 15:17:29 +03:00
SilicaFlickable {
id: aboutContainer
contentHeight: column.height
anchors.fill: parent
visible: !overviewPage.loading
2020-08-10 15:17:29 +03:00
PullDownMenu {
MenuItem {
text: qsTr("About Fernschreiber")
onClicked: pageStack.push(Qt.resolvedUrl("../pages/AboutPage.qml"))
}
}
Column {
id: column
width: parent.width
spacing: Theme.paddingLarge
Row {
width: parent.width
GlassItem {
id: pageStatus
width: Theme.itemSizeMedium
height: Theme.itemSizeMedium
color: "red"
falloffRadius: 0.1
radius: 0.2
cache: false
}
PageHeader {
id: pageHeader
title: qsTr("Fernschreiber")
width: parent.width - pageStatus.width
}
2020-08-10 15:17:29 +03:00
}
VerticalScrollDecorator {}
}
}
}