2020-08-10 15:17:29 +03:00
|
|
|
/*
|
2020-10-19 20:34:47 +03:00
|
|
|
Copyright (C) 2020 Sebastian J. Wolf and other contributors
|
2020-08-10 15:17:29 +03:00
|
|
|
|
|
|
|
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-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.
|
|
|
|
|
2020-08-13 18:08:14 +03:00
|
|
|
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/>.
|
|
|
|
*/
|
2020-10-31 22:49:03 +03:00
|
|
|
import QtQuick 2.6
|
2020-08-10 15:17:29 +03:00
|
|
|
import Sailfish.Silica 1.0
|
2020-08-17 00:31:20 +03:00
|
|
|
import WerkWolf.Fernschreiber 1.0
|
2020-10-26 17:15:53 +03:00
|
|
|
import "../components"
|
2020-09-24 10:55:05 +03:00
|
|
|
import "../js/functions.js" as Functions
|
2020-08-10 15:17:29 +03:00
|
|
|
|
|
|
|
CoverBackground {
|
|
|
|
|
|
|
|
id: coverPage
|
|
|
|
|
2020-08-17 00:31:20 +03:00
|
|
|
property int unreadMessages: 0
|
|
|
|
property int unreadChats: 0
|
2021-02-25 03:57:24 +03:00
|
|
|
readonly property bool authenticated: tdLibWrapper.authorizationState === TelegramAPI.AuthorizationReady
|
2020-08-17 00:31:20 +03:00
|
|
|
property int connectionState: TelegramAPI.WaitingForNetwork
|
|
|
|
|
|
|
|
function setUnreadInfoText() {
|
|
|
|
|
2021-01-31 22:23:59 +03:00
|
|
|
unreadMessagesText.text = qsTr("unread messages", "", coverPage.unreadMessages);
|
|
|
|
unreadChatsText.text = qsTr("chats", "", coverPage.unreadChats)
|
2020-08-17 00:31:20 +03:00
|
|
|
|
|
|
|
switch (coverPage.connectionState) {
|
|
|
|
case TelegramAPI.WaitingForNetwork:
|
|
|
|
connectionStateText.text = qsTr("Waiting for network...");
|
|
|
|
break;
|
|
|
|
case TelegramAPI.Connecting:
|
|
|
|
connectionStateText.text = qsTr("Connecting to network...");
|
|
|
|
break;
|
|
|
|
case TelegramAPI.ConnectingToProxy:
|
|
|
|
connectionStateText.text = qsTr("Connecting to proxy...");
|
|
|
|
break;
|
|
|
|
case TelegramAPI.ConnectionReady:
|
|
|
|
connectionStateText.text = qsTr("Connected");
|
|
|
|
break;
|
|
|
|
case TelegramAPI.Updating:
|
|
|
|
connectionStateText.text = qsTr("Updating content...");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
coverPage.connectionState = tdLibWrapper.getConnectionState();
|
2020-10-01 01:55:26 +03:00
|
|
|
coverPage.unreadMessages = tdLibWrapper.getUnreadMessageInformation().unread_count || 0;
|
2021-01-10 15:35:34 +03:00
|
|
|
coverPage.unreadChats = tdLibWrapper.getUnreadChatInformation().unread_count || 0;
|
2020-08-17 00:31:20 +03:00
|
|
|
setUnreadInfoText();
|
|
|
|
}
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
target: tdLibWrapper
|
|
|
|
onUnreadMessageCountUpdated: {
|
2020-08-18 00:44:37 +03:00
|
|
|
coverPage.unreadMessages = messageCountInformation.unread_count;
|
|
|
|
setUnreadInfoText();
|
2020-08-17 00:31:20 +03:00
|
|
|
}
|
|
|
|
onUnreadChatCountUpdated: {
|
2020-08-18 00:44:37 +03:00
|
|
|
coverPage.unreadChats = chatCountInformation.unread_count;
|
|
|
|
setUnreadInfoText();
|
2020-08-17 00:31:20 +03:00
|
|
|
}
|
|
|
|
onAuthorizationStateChanged: {
|
|
|
|
setUnreadInfoText();
|
|
|
|
}
|
|
|
|
onConnectionStateChanged: {
|
|
|
|
coverPage.connectionState = connectionState;
|
|
|
|
setUnreadInfoText();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-10 15:35:34 +03:00
|
|
|
Connections {
|
|
|
|
target: chatListModel
|
|
|
|
onUnreadStateChanged: {
|
|
|
|
coverPage.unreadMessages = unreadMessagesCount;
|
|
|
|
coverPage.unreadChats = unreadChatsCount;
|
|
|
|
setUnreadInfoText();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-26 17:15:53 +03:00
|
|
|
BackgroundImage {
|
2020-08-10 15:17:29 +03:00
|
|
|
id: backgroundImage
|
2020-10-26 17:15:53 +03:00
|
|
|
width: parent.height - Theme.paddingLarge
|
|
|
|
height: width
|
|
|
|
sourceDimension: width
|
2020-08-10 15:17:29 +03:00
|
|
|
anchors {
|
|
|
|
verticalCenter: parent.verticalCenter
|
2020-10-26 17:15:53 +03:00
|
|
|
centerIn: undefined
|
2020-08-10 15:17:29 +03:00
|
|
|
bottom: parent.bottom
|
|
|
|
bottomMargin: Theme.paddingMedium
|
|
|
|
right: parent.right
|
|
|
|
rightMargin: Theme.paddingMedium
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-17 00:31:20 +03:00
|
|
|
Column {
|
|
|
|
anchors.fill: parent
|
2020-09-30 22:41:49 +03:00
|
|
|
anchors.margins: Theme.paddingLarge
|
2020-08-17 00:31:20 +03:00
|
|
|
spacing: Theme.paddingMedium
|
|
|
|
visible: coverPage.authenticated
|
|
|
|
Row {
|
|
|
|
width: parent.width
|
|
|
|
spacing: Theme.paddingMedium
|
|
|
|
Text {
|
|
|
|
id: unreadMessagesCountText
|
|
|
|
font.pixelSize: Theme.fontSizeHuge
|
|
|
|
color: Theme.primaryColor
|
2020-09-24 10:55:05 +03:00
|
|
|
text: Functions.getShortenedCount(coverPage.unreadMessages)
|
2020-08-17 00:31:20 +03:00
|
|
|
}
|
2020-11-22 02:39:49 +03:00
|
|
|
Label {
|
2020-08-17 00:31:20 +03:00
|
|
|
id: unreadMessagesText
|
2021-01-31 22:23:59 +03:00
|
|
|
font.pixelSize: Theme.fontSizeExtraSmall
|
2020-08-17 00:31:20 +03:00
|
|
|
width: parent.width - unreadMessagesCountText.width - Theme.paddingMedium
|
|
|
|
wrapMode: Text.Wrap
|
|
|
|
anchors.verticalCenter: unreadMessagesCountText.verticalCenter
|
2020-08-20 19:45:56 +03:00
|
|
|
maximumLineCount: 2
|
2020-11-22 02:39:49 +03:00
|
|
|
truncationMode: TruncationMode.Fade
|
2020-08-17 00:31:20 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Row {
|
|
|
|
width: parent.width
|
|
|
|
spacing: Theme.paddingMedium
|
2020-08-18 00:44:37 +03:00
|
|
|
visible: coverPage.authenticated && coverPage.unreadMessages > 1
|
2020-08-17 00:31:20 +03:00
|
|
|
Text {
|
|
|
|
id: inText
|
2021-01-31 22:23:59 +03:00
|
|
|
font.pixelSize: Theme.fontSizeExtraSmall
|
2020-08-17 00:31:20 +03:00
|
|
|
color: Theme.primaryColor
|
|
|
|
text: qsTr("in")
|
|
|
|
anchors.verticalCenter: unreadChatsCountText.verticalCenter
|
|
|
|
}
|
|
|
|
Text {
|
|
|
|
id: unreadChatsCountText
|
|
|
|
font.pixelSize: Theme.fontSizeHuge
|
|
|
|
color: Theme.primaryColor
|
2020-09-24 10:55:05 +03:00
|
|
|
text: Functions.getShortenedCount(coverPage.unreadChats)
|
2020-08-17 00:31:20 +03:00
|
|
|
}
|
|
|
|
Text {
|
|
|
|
id: unreadChatsText
|
2021-01-31 22:23:59 +03:00
|
|
|
font.pixelSize: Theme.fontSizeExtraSmall
|
2020-08-17 00:31:20 +03:00
|
|
|
color: Theme.primaryColor
|
2020-09-24 10:55:05 +03:00
|
|
|
width: parent.width - unreadChatsCountText.width - inText.width - ( 2 * Theme.paddingMedium )
|
2020-08-17 00:31:20 +03:00
|
|
|
wrapMode: Text.Wrap
|
|
|
|
anchors.verticalCenter: unreadChatsCountText.verticalCenter
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Text {
|
|
|
|
id: connectionStateText
|
|
|
|
font.pixelSize: Theme.fontSizeLarge
|
|
|
|
color: Theme.highlightColor
|
|
|
|
visible: coverPage.authenticated
|
|
|
|
width: parent.width
|
2020-08-29 22:39:57 +03:00
|
|
|
maximumLineCount: 3
|
2020-08-17 00:31:20 +03:00
|
|
|
wrapMode: Text.Wrap
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-10 15:17:29 +03:00
|
|
|
}
|