From 4a04a555136f5477853cfe13890b25ee64ca5795 Mon Sep 17 00:00:00 2001 From: nephros Date: Sun, 12 Dec 2021 18:28:05 +0100 Subject: [PATCH 1/7] Move Session options to Settings page --- harbour-fernschreiber.pro | 2 +- .../settingsPage/SettingsSession.qml | 248 ++++++++++++++++++ qml/pages/AboutPage.qml | 90 +------ qml/pages/ActiveSessionsPage.qml | 203 -------------- qml/pages/SettingsPage.qml | 1 + 5 files changed, 251 insertions(+), 293 deletions(-) create mode 100644 qml/components/settingsPage/SettingsSession.qml delete mode 100644 qml/pages/ActiveSessionsPage.qml diff --git a/harbour-fernschreiber.pro b/harbour-fernschreiber.pro index d19ecd1..f87ac30 100644 --- a/harbour-fernschreiber.pro +++ b/harbour-fernschreiber.pro @@ -117,11 +117,11 @@ DISTFILES += qml/harbour-fernschreiber.qml \ qml/components/settingsPage/SettingsAppearance.qml \ qml/components/settingsPage/SettingsBehavior.qml \ qml/components/settingsPage/SettingsPrivacy.qml \ + qml/components/settingsPage/SettingsSession.qml \ qml/components/settingsPage/SettingsStorage.qml \ qml/components/settingsPage/SettingsUserProfile.qml \ qml/js/debug.js \ qml/js/functions.js \ - qml/pages/ActiveSessionsPage.qml \ qml/pages/ChatInformationPage.qml \ qml/pages/ChatPage.qml \ qml/pages/ChatSelectionPage.qml \ diff --git a/qml/components/settingsPage/SettingsSession.qml b/qml/components/settingsPage/SettingsSession.qml new file mode 100644 index 0000000..e099977 --- /dev/null +++ b/qml/components/settingsPage/SettingsSession.qml @@ -0,0 +1,248 @@ +/* + Copyright (C) 2020-21 Sebastian J. Wolf and other contributors + + 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.6 +import Sailfish.Silica 1.0 +import WerkWolf.Fernschreiber 1.0 +import "../../components" +import "../../js/twemoji.js" as Emoji +import "../../js/functions.js" as Functions + +AccordionItem { + text: qsTr("Sessions") + Component { + Column { + id: activeSessionsItem + bottomPadding: Theme.paddingMedium + property variant activeSessions; + property bool loaded : false; + readonly property var userInformation : tdLibWrapper.userInformation + + Component.onCompleted: { + if (!activeSessions) { + tdLibWrapper.getActiveSessions(); + } else { + activeSessionsItem.loaded = true; + } + } + + Connections { + target: tdLibWrapper + onSessionsReceived: { + activeSessionsItem.activeSessions = sessions; + activeSessionsItem.loaded = true; + } + onOkReceived: { + if (request === "terminateSession") { + appNotification.show(qsTr("Session was terminated")); + activeSessionsItem.loaded = false; + tdLibWrapper.getActiveSessions(); + } + } + } + + ResponsiveGrid { + bottomPadding: Theme.paddingMedium + + Loader { + id: userInformationLoader + active: tdLibWrapper.authorizationState === TelegramAPI.AuthorizationReady + width: parent.width + sourceComponent: Component { + Column { + spacing: Theme.paddingSmall + + Text { + x: Theme.horizontalPageMargin + width: parent.width - ( 2 * Theme.horizontalPageMargin ) + horizontalAlignment: Text.AlignHCenter + text: qsTr("Logged in as %1").arg(Emoji.emojify(activeSessionsItem.userInformation.first_name + " " + activeSessionsItem.userInformation.last_name, Theme.fontSizeSmall)) + font.pixelSize: Theme.fontSizeSmall + wrapMode: Text.Wrap + color: Theme.primaryColor + textFormat: Text.StyledText + anchors { + horizontalCenter: parent.horizontalCenter + } + } + + ProfileThumbnail { + photoData: ((typeof activeSessionsItem.userInformation.profile_photo !== "undefined") ? activeSessionsItem.userInformation.profile_photo.small : {}) + width: Theme.itemSizeExtraLarge + height: Theme.itemSizeExtraLarge + replacementStringHint: activeSessionsItem.userInformation.first_name + " " + activeSessionsItem.userInformation.last_name + anchors { + horizontalCenter: parent.horizontalCenter + } + } + + Label { + x: Theme.horizontalPageMargin + width: parent.width - ( 2 * Theme.horizontalPageMargin ) + horizontalAlignment: Text.AlignHCenter + text: qsTr("Phone number: +%1").arg(activeSessionsItem.userInformation.phone_number) + font.pixelSize: Theme.fontSizeSmall + wrapMode: Text.Wrap + anchors { + horizontalCenter: parent.horizontalCenter + } + } + + BackgroundItem { + id: logOutItem + width: parent.width + function showRemorseItem() { + remorse.execute(logOutItem, qsTr("Logged out"), function() { + tdLibWrapper.logout(); + pageStack.pop(); + }); + } + RemorseItem { id: remorse } + Button { + id: logOutButton + text: qsTr("Log Out") + anchors.horizontalCenter: parent.horizontalCenter + onClicked: logOutItem.showRemorseItem() + } + } + Separator { + width: parent.width + color: Theme.primaryColor + horizontalAlignment: Qt.AlignHCenter + } + } + } + } + + Loader { + id: sessionInformationLoader + active: tdLibWrapper.authorizationState === TelegramAPI.AuthorizationReady + width: parent.width + sourceComponent: Component { + SilicaListView { + id: activeSessionsListView + width: parent.width + // TODO/FIXME: do a proper height calculation here: + height: Theme.itemSizeLarge * 5 + clip: true + + model: activeSessionsItem.activeSessions + delegate: ListItem { + id: activeSessionListItem + width: parent.width + contentHeight: activeSessionColumn.height + ( 2 * Theme.paddingMedium ) + + menu: ContextMenu { + hasContent: !modelData.is_current + MenuItem { + onClicked: { + var sessionId = modelData.id; + Remorse.itemAction(activeSessionListItem, qsTr("Terminating session"), function() { tdLibWrapper.terminateSession(sessionId); }); + } + text: qsTr("Terminate Session") + } + } + + Rectangle { + height: parent.height - Theme.paddingSmall + width: parent.width + anchors.centerIn: parent + visible: modelData.is_current + color: Theme.rgba(Theme.highlightBackgroundColor, Theme.opacityFaint) + } + + Column { + id: activeSessionColumn + width: parent.width - ( 2 * Theme.horizontalPageMargin ) + spacing: Theme.paddingSmall + anchors.verticalCenter: parent.verticalCenter + anchors.horizontalCenter: parent.horizontalCenter + + Label { + width: parent.width + property string hltext: modelData.is_current ? " (" + qsTr("this app") + ")" : "" + text: Theme.highlightText( modelData.application_name + " " + modelData.application_version + hltext, hltext, Theme.highlightColor) + font.pixelSize: modelData.is_current ? Theme.fontSizeMedium : Theme.fontSizeSmall + font.bold: true + color: Theme.primaryColor + maximumLineCount: 1 + elide: Text.ElideRight + anchors { + horizontalCenter: parent.horizontalCenter + } + } + + Label { + width: parent.width + text: modelData.device_model + ", " + (modelData.platform + " " + modelData.system_version).trim() + font.pixelSize: Theme.fontSizeSmall + color: Theme.primaryColor + maximumLineCount: 1 + truncationMode: TruncationMode.Fade + anchors { + horizontalCenter: parent.horizontalCenter + } + } + + Label { + width: parent.width + text: qsTr("IP address: %1, origin: %2").arg(modelData.ip).arg(modelData.country) + font.pixelSize: Theme.fontSizeExtraSmall + color: Theme.secondaryColor + maximumLineCount: 1 + truncationMode: TruncationMode.Fade + anchors { + horizontalCenter: parent.horizontalCenter + } + } + + Label { + width: parent.width + text: qsTr("Active since: %1, last online: %2").arg(Functions.getDateTimeTimepoint(modelData.log_in_date)).arg(Functions.getDateTimeElapsed(modelData.last_active_date)) + font.pixelSize: Theme.fontSizeExtraSmall + color: Theme.primaryColor + maximumLineCount: 1 + truncationMode: TruncationMode.Fade + anchors { + horizontalCenter: parent.horizontalCenter + } + } + } + + Separator { + id: separator + anchors { + bottom: parent.bottom + } + + width: parent.width + color: Theme.primaryColor + horizontalAlignment: Qt.AlignHCenter + } + + } + + VerticalScrollDecorator {} + } + } + } + } + } + } +} diff --git a/qml/pages/AboutPage.qml b/qml/pages/AboutPage.qml index 0ae1d4a..fc5e44a 100644 --- a/qml/pages/AboutPage.qml +++ b/qml/pages/AboutPage.qml @@ -1,3 +1,4 @@ + /* Copyright (C) 2020-21 Sebastian J. Wolf and other contributors @@ -20,14 +21,11 @@ import QtQuick 2.6 import Sailfish.Silica 1.0 import WerkWolf.Fernschreiber 1.0 import "../components" -import "../js/twemoji.js" as Emoji Page { id: aboutPage allowedOrientations: Orientation.All - readonly property var userInformation : tdLibWrapper.userInformation - SilicaFlickable { id: aboutContainer contentHeight: column.height @@ -156,92 +154,6 @@ Page { } } - Loader { - id: userInformationLoader - active: tdLibWrapper.authorizationState === TelegramAPI.AuthorizationReady - width: parent.width - sourceComponent: Component { - Column { - - spacing: Theme.paddingSmall - - Text { - x: Theme.horizontalPageMargin - width: parent.width - ( 2 * Theme.horizontalPageMargin ) - horizontalAlignment: Text.AlignHCenter - text: qsTr("Logged in as %1").arg(Emoji.emojify(aboutPage.userInformation.first_name + " " + aboutPage.userInformation.last_name, Theme.fontSizeSmall)) - font.pixelSize: Theme.fontSizeSmall - wrapMode: Text.Wrap - color: Theme.primaryColor - textFormat: Text.StyledText - anchors { - horizontalCenter: parent.horizontalCenter - } - } - - ProfileThumbnail { - photoData: ((typeof aboutPage.userInformation.profile_photo !== "undefined") ? aboutPage.userInformation.profile_photo.small : {}) - width: Theme.itemSizeExtraLarge - height: Theme.itemSizeExtraLarge - replacementStringHint: aboutPage.userInformation.first_name + " " + aboutPage.userInformation.last_name - anchors { - horizontalCenter: parent.horizontalCenter - } - } - - Label { - x: Theme.horizontalPageMargin - width: parent.width - ( 2 * Theme.horizontalPageMargin ) - horizontalAlignment: Text.AlignHCenter - text: qsTr("Phone number: +%1").arg(aboutPage.userInformation.phone_number) - font.pixelSize: Theme.fontSizeSmall - wrapMode: Text.Wrap - anchors { - horizontalCenter: parent.horizontalCenter - } - } - BackgroundItem { - width: parent.width - - BackgroundItem { - id: logOutItem - width: parent.width - function showRemorseItem() { - remorse.execute(logOutItem, qsTr("Logged out"), function() { - tdLibWrapper.logout(); - pageStack.pop(); - }); - } - RemorseItem { - id: remorse - } - Button { - id: logOutButton - text: qsTr("Log Out") - anchors { - horizontalCenter: parent.horizontalCenter - } - onClicked: { - logOutItem.showRemorseItem(); - } - } - } - } - - Button { - id: activeSessionsButton - text: qsTr("Active Sessions") - anchors { - horizontalCenter: parent.horizontalCenter - } - onClicked: { - pageStack.push(Qt.resolvedUrl("ActiveSessionsPage.qml")); - } - } - } - } - } - Button { text: qsTr("Terms of Service") anchors { diff --git a/qml/pages/ActiveSessionsPage.qml b/qml/pages/ActiveSessionsPage.qml deleted file mode 100644 index 78ebd04..0000000 --- a/qml/pages/ActiveSessionsPage.qml +++ /dev/null @@ -1,203 +0,0 @@ -/* - Copyright (C) 2020-21 Sebastian J. Wolf and other contributors - - 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.6 -import Sailfish.Silica 1.0 -import "../components" -import "../js/twemoji.js" as Emoji -import "../js/functions.js" as Functions - -Page { - id: activeSessionsPage - allowedOrientations: Orientation.All - - property variant activeSessions; - property bool loaded : false; - - Component.onCompleted: { - if (!activeSessions) { - tdLibWrapper.getActiveSessions(); - } else { - activeSessionsPage.loaded = true; - } - } - - Connections { - target: tdLibWrapper - onSessionsReceived: { - activeSessionsPage.activeSessions = sessions; - activeSessionsPage.loaded = true; - } - onOkReceived: { - if (request === "terminateSession") { - appNotification.show(qsTr("Session was terminated")); - activeSessionsPage.loaded = false; - tdLibWrapper.getActiveSessions(); - } - } - } - - SilicaFlickable { - id: activeSessionsFlickable - anchors.fill: parent - - Column { - anchors.fill: parent - - PageHeader { - id: activeSessionsHeader - title: qsTr("Active Sessions") - } - - SilicaListView { - id: activeSessionsListView - width: parent.width - height: parent.height - activeSessionsHeader.height - - clip: true - - model: activeSessionsPage.activeSessions - delegate: ListItem { - id: activeSessionListItem - width: parent.width - contentHeight: activeSessionColumn.height + ( 2 * Theme.paddingMedium ) - - menu: ContextMenu { - hasContent: !modelData.is_current - MenuItem { - onClicked: { - var sessionId = modelData.id; - Remorse.itemAction(activeSessionListItem, qsTr("Terminating session"), function() { tdLibWrapper.terminateSession(sessionId); }); - } - text: qsTr("Terminate Session") - } - } - - Column { - id: activeSessionColumn - width: parent.width - ( 2 * Theme.horizontalPageMargin ) - spacing: Theme.paddingSmall - anchors.verticalCenter: parent.verticalCenter - anchors.horizontalCenter: parent.horizontalCenter - - Label { - width: parent.width - text: qsTr("This app") - font.pixelSize: Theme.fontSizeMedium - font.bold: true - visible: modelData.is_current - color: Theme.highlightColor - anchors { - horizontalCenter: parent.horizontalCenter - } - } - - Label { - width: parent.width - text: modelData.application_name + " " + modelData.application_version - font.pixelSize: Theme.fontSizeMedium - font.bold: true - color: Theme.primaryColor - maximumLineCount: 1 - elide: Text.ElideRight - anchors { - horizontalCenter: parent.horizontalCenter - } - } - - Label { - width: parent.width - text: modelData.device_model + ", " + (modelData.platform + " " + modelData.system_version).trim() - font.pixelSize: Theme.fontSizeSmall - color: Theme.primaryColor - maximumLineCount: 1 - truncationMode: TruncationMode.Fade - anchors { - horizontalCenter: parent.horizontalCenter - } - } - - Label { - width: parent.width - text: qsTr("IP address: %1, origin: %2").arg(modelData.ip).arg(modelData.country) - font.pixelSize: Theme.fontSizeExtraSmall - color: Theme.secondaryColor - maximumLineCount: 1 - truncationMode: TruncationMode.Fade - anchors { - horizontalCenter: parent.horizontalCenter - } - } - - Label { - width: parent.width - text: qsTr("Active since: %1, last online: %2").arg(Functions.getDateTimeTimepoint(modelData.log_in_date)).arg(Functions.getDateTimeElapsed(modelData.last_active_date)) - font.pixelSize: Theme.fontSizeExtraSmall - color: Theme.primaryColor - maximumLineCount: 1 - truncationMode: TruncationMode.Fade - anchors { - horizontalCenter: parent.horizontalCenter - } - } - } - - Separator { - id: separator - anchors { - bottom: parent.bottom - } - - width: parent.width - color: Theme.primaryColor - horizontalAlignment: Qt.AlignHCenter - } - - } - - VerticalScrollDecorator {} - } - } - - Column { - - opacity: visible ? 1 : 0 - Behavior on opacity { FadeAnimation {} } - visible: !activeSessionsPage.loaded - width: parent.width - height: loadingLabel.height + loadingBusyIndicator.height + Theme.paddingMedium - - spacing: Theme.paddingMedium - anchors.verticalCenter: parent.verticalCenter - - InfoLabel { - id: loadingLabel - text: qsTr("Getting active sessions...") - } - - BusyIndicator { - id: loadingBusyIndicator - anchors.horizontalCenter: parent.horizontalCenter - running: !activeSessionsPage.loaded - size: BusyIndicatorSize.Large - } - } - - } -} - diff --git a/qml/pages/SettingsPage.qml b/qml/pages/SettingsPage.qml index b1cf4f9..bd1d384 100644 --- a/qml/pages/SettingsPage.qml +++ b/qml/pages/SettingsPage.qml @@ -46,6 +46,7 @@ Page { Accordion { flickable: settingsContainer SettingsUserProfile { expanded: true; asynchronous: false } + SettingsSession {} SettingsPrivacy {} SettingsBehavior {} SettingsAppearance {} From f8bc0df74aac2116f3156be9c61c8cbf24152d68 Mon Sep 17 00:00:00 2001 From: nephros Date: Mon, 13 Dec 2021 11:59:22 +0100 Subject: [PATCH 2/7] Tweak dimensions, fix ResponsiveGrid --- .../settingsPage/SettingsSession.qml | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/qml/components/settingsPage/SettingsSession.qml b/qml/components/settingsPage/SettingsSession.qml index e099977..d20c654 100644 --- a/qml/components/settingsPage/SettingsSession.qml +++ b/qml/components/settingsPage/SettingsSession.qml @@ -59,14 +59,16 @@ AccordionItem { ResponsiveGrid { bottomPadding: Theme.paddingMedium + width: parent.width Loader { id: userInformationLoader active: tdLibWrapper.authorizationState === TelegramAPI.AuthorizationReady - width: parent.width + width: parent.columnWidth sourceComponent: Component { Column { - spacing: Theme.paddingSmall + anchors.topMargin: Theme.paddingMedium + spacing: Theme.paddingMedium Text { x: Theme.horizontalPageMargin @@ -121,11 +123,6 @@ AccordionItem { onClicked: logOutItem.showRemorseItem() } } - Separator { - width: parent.width - color: Theme.primaryColor - horizontalAlignment: Qt.AlignHCenter - } } } } @@ -133,16 +130,23 @@ AccordionItem { Loader { id: sessionInformationLoader active: tdLibWrapper.authorizationState === TelegramAPI.AuthorizationReady - width: parent.width + width: parent.columnWidth sourceComponent: Component { SilicaListView { id: activeSessionsListView width: parent.width - // TODO/FIXME: do a proper height calculation here: - height: Theme.itemSizeLarge * 5 + // one activeSessionListItem is about 1.52 times itemSizeLarge + // show max 5 items at a time + height: Theme.itemSizeLarge * 1.5 * Math.min(5 , activeSessionsItem.activeSessions.length ) clip: true model: activeSessionsItem.activeSessions + headerPositioning: ListView.OverlayHeader + header: Separator { + width: parent.width + color: Theme.primaryColor + horizontalAlignment: Qt.AlignHCenter + } delegate: ListItem { id: activeSessionListItem width: parent.width From 3786a0cb3f492741ee5d8b96307432409e643f10 Mon Sep 17 00:00:00 2001 From: nephros Date: Wed, 15 Dec 2021 10:36:26 +0100 Subject: [PATCH 3/7] Sessions: remove profile info, restore list design --- .../settingsPage/SettingsSession.qml | 298 +++++++----------- 1 file changed, 115 insertions(+), 183 deletions(-) diff --git a/qml/components/settingsPage/SettingsSession.qml b/qml/components/settingsPage/SettingsSession.qml index d20c654..b24f119 100644 --- a/qml/components/settingsPage/SettingsSession.qml +++ b/qml/components/settingsPage/SettingsSession.qml @@ -57,193 +57,125 @@ AccordionItem { } } - ResponsiveGrid { - bottomPadding: Theme.paddingMedium + Loader { + id: sessionInformationLoader + active: tdLibWrapper.authorizationState === TelegramAPI.AuthorizationReady width: parent.width + sourceComponent: Component { + SilicaListView { + id: activeSessionsListView + width: parent.width + // one activeSessionListItem is about 1.52 times itemSizeLarge + // show max 5 items at a time + height: Theme.itemSizeLarge * 1.5 * Math.min(5 , activeSessionsItem.activeSessions.length ) + clip: true - Loader { - id: userInformationLoader - active: tdLibWrapper.authorizationState === TelegramAPI.AuthorizationReady - width: parent.columnWidth - sourceComponent: Component { - Column { - anchors.topMargin: Theme.paddingMedium - spacing: Theme.paddingMedium - - Text { - x: Theme.horizontalPageMargin - width: parent.width - ( 2 * Theme.horizontalPageMargin ) - horizontalAlignment: Text.AlignHCenter - text: qsTr("Logged in as %1").arg(Emoji.emojify(activeSessionsItem.userInformation.first_name + " " + activeSessionsItem.userInformation.last_name, Theme.fontSizeSmall)) - font.pixelSize: Theme.fontSizeSmall - wrapMode: Text.Wrap - color: Theme.primaryColor - textFormat: Text.StyledText - anchors { - horizontalCenter: parent.horizontalCenter - } - } - - ProfileThumbnail { - photoData: ((typeof activeSessionsItem.userInformation.profile_photo !== "undefined") ? activeSessionsItem.userInformation.profile_photo.small : {}) - width: Theme.itemSizeExtraLarge - height: Theme.itemSizeExtraLarge - replacementStringHint: activeSessionsItem.userInformation.first_name + " " + activeSessionsItem.userInformation.last_name - anchors { - horizontalCenter: parent.horizontalCenter - } - } - - Label { - x: Theme.horizontalPageMargin - width: parent.width - ( 2 * Theme.horizontalPageMargin ) - horizontalAlignment: Text.AlignHCenter - text: qsTr("Phone number: +%1").arg(activeSessionsItem.userInformation.phone_number) - font.pixelSize: Theme.fontSizeSmall - wrapMode: Text.Wrap - anchors { - horizontalCenter: parent.horizontalCenter - } - } - - BackgroundItem { - id: logOutItem - width: parent.width - function showRemorseItem() { - remorse.execute(logOutItem, qsTr("Logged out"), function() { - tdLibWrapper.logout(); - pageStack.pop(); - }); - } - RemorseItem { id: remorse } - Button { - id: logOutButton - text: qsTr("Log Out") - anchors.horizontalCenter: parent.horizontalCenter - onClicked: logOutItem.showRemorseItem() - } - } - } - } - } - - Loader { - id: sessionInformationLoader - active: tdLibWrapper.authorizationState === TelegramAPI.AuthorizationReady - width: parent.columnWidth - sourceComponent: Component { - SilicaListView { - id: activeSessionsListView + model: activeSessionsItem.activeSessions + headerPositioning: ListView.OverlayHeader + header: Separator { width: parent.width - // one activeSessionListItem is about 1.52 times itemSizeLarge - // show max 5 items at a time - height: Theme.itemSizeLarge * 1.5 * Math.min(5 , activeSessionsItem.activeSessions.length ) - clip: true - - model: activeSessionsItem.activeSessions - headerPositioning: ListView.OverlayHeader - header: Separator { - width: parent.width - color: Theme.primaryColor - horizontalAlignment: Qt.AlignHCenter - } - delegate: ListItem { - id: activeSessionListItem - width: parent.width - contentHeight: activeSessionColumn.height + ( 2 * Theme.paddingMedium ) - - menu: ContextMenu { - hasContent: !modelData.is_current - MenuItem { - onClicked: { - var sessionId = modelData.id; - Remorse.itemAction(activeSessionListItem, qsTr("Terminating session"), function() { tdLibWrapper.terminateSession(sessionId); }); - } - text: qsTr("Terminate Session") - } - } - - Rectangle { - height: parent.height - Theme.paddingSmall - width: parent.width - anchors.centerIn: parent - visible: modelData.is_current - color: Theme.rgba(Theme.highlightBackgroundColor, Theme.opacityFaint) - } - - Column { - id: activeSessionColumn - width: parent.width - ( 2 * Theme.horizontalPageMargin ) - spacing: Theme.paddingSmall - anchors.verticalCenter: parent.verticalCenter - anchors.horizontalCenter: parent.horizontalCenter - - Label { - width: parent.width - property string hltext: modelData.is_current ? " (" + qsTr("this app") + ")" : "" - text: Theme.highlightText( modelData.application_name + " " + modelData.application_version + hltext, hltext, Theme.highlightColor) - font.pixelSize: modelData.is_current ? Theme.fontSizeMedium : Theme.fontSizeSmall - font.bold: true - color: Theme.primaryColor - maximumLineCount: 1 - elide: Text.ElideRight - anchors { - horizontalCenter: parent.horizontalCenter - } - } - - Label { - width: parent.width - text: modelData.device_model + ", " + (modelData.platform + " " + modelData.system_version).trim() - font.pixelSize: Theme.fontSizeSmall - color: Theme.primaryColor - maximumLineCount: 1 - truncationMode: TruncationMode.Fade - anchors { - horizontalCenter: parent.horizontalCenter - } - } - - Label { - width: parent.width - text: qsTr("IP address: %1, origin: %2").arg(modelData.ip).arg(modelData.country) - font.pixelSize: Theme.fontSizeExtraSmall - color: Theme.secondaryColor - maximumLineCount: 1 - truncationMode: TruncationMode.Fade - anchors { - horizontalCenter: parent.horizontalCenter - } - } - - Label { - width: parent.width - text: qsTr("Active since: %1, last online: %2").arg(Functions.getDateTimeTimepoint(modelData.log_in_date)).arg(Functions.getDateTimeElapsed(modelData.last_active_date)) - font.pixelSize: Theme.fontSizeExtraSmall - color: Theme.primaryColor - maximumLineCount: 1 - truncationMode: TruncationMode.Fade - anchors { - horizontalCenter: parent.horizontalCenter - } - } - } - - Separator { - id: separator - anchors { - bottom: parent.bottom - } - - width: parent.width - color: Theme.primaryColor - horizontalAlignment: Qt.AlignHCenter - } - - } - - VerticalScrollDecorator {} + color: Theme.primaryColor + horizontalAlignment: Qt.AlignHCenter } + delegate: ListItem { + id: activeSessionListItem + width: parent.width + contentHeight: activeSessionColumn.height + ( 2 * Theme.paddingMedium ) + + menu: ContextMenu { + hasContent: !modelData.is_current + MenuItem { + onClicked: { + var sessionId = modelData.id; + Remorse.itemAction(activeSessionListItem, qsTr("Terminating session"), function() { tdLibWrapper.terminateSession(sessionId); }); + } + text: qsTr("Terminate Session") + } + } + + Column { + id: activeSessionColumn + width: parent.width - ( 2 * Theme.horizontalPageMargin ) + spacing: Theme.paddingSmall + anchors.verticalCenter: parent.verticalCenter + anchors.horizontalCenter: parent.horizontalCenter + + Label { + width: parent.width + text: qsTr("This app") + font.pixelSize: Theme.fontSizeMedium + font.bold: true + visible: modelData.is_current + color: Theme.highlightColor + anchors { + horizontalCenter: parent.horizontalCenter + } + } + + Label { + width: parent.width + text: modelData.application_name + " " + modelData.application_version + font.pixelSize: Theme.fontSizeMedium + font.bold: true + color: Theme.primaryColor + maximumLineCount: 1 + elide: Text.ElideRight + anchors { + horizontalCenter: parent.horizontalCenter + } + } + + Label { + width: parent.width + text: modelData.device_model + ", " + (modelData.platform + " " + modelData.system_version).trim() + font.pixelSize: Theme.fontSizeSmall + color: Theme.primaryColor + maximumLineCount: 1 + truncationMode: TruncationMode.Fade + anchors { + horizontalCenter: parent.horizontalCenter + } + } + + Label { + width: parent.width + text: qsTr("IP address: %1, origin: %2").arg(modelData.ip).arg(modelData.country) + font.pixelSize: Theme.fontSizeExtraSmall + color: Theme.secondaryColor + maximumLineCount: 1 + truncationMode: TruncationMode.Fade + anchors { + horizontalCenter: parent.horizontalCenter + } + } + + Label { + width: parent.width + text: qsTr("Active since: %1, last online: %2").arg(Functions.getDateTimeTimepoint(modelData.log_in_date)).arg(Functions.getDateTimeElapsed(modelData.last_active_date)) + font.pixelSize: Theme.fontSizeExtraSmall + color: Theme.primaryColor + maximumLineCount: 1 + truncationMode: TruncationMode.Fade + anchors { + horizontalCenter: parent.horizontalCenter + } + } + } + + Separator { + id: separator + anchors { + bottom: parent.bottom + } + + width: parent.width + color: Theme.primaryColor + horizontalAlignment: Qt.AlignHCenter + } + + } + + VerticalScrollDecorator {} } } } From f33162801c1b5554b70d86d287f2c045ee66736d Mon Sep 17 00:00:00 2001 From: nephros Date: Wed, 15 Dec 2021 11:55:29 +0100 Subject: [PATCH 4/7] Settings: add login info and logout to Profile --- .../settingsPage/SettingsSession.qml | 2 - .../settingsPage/SettingsUserProfile.qml | 96 +++++++++++++++++++ 2 files changed, 96 insertions(+), 2 deletions(-) diff --git a/qml/components/settingsPage/SettingsSession.qml b/qml/components/settingsPage/SettingsSession.qml index b24f119..8318ada 100644 --- a/qml/components/settingsPage/SettingsSession.qml +++ b/qml/components/settingsPage/SettingsSession.qml @@ -21,7 +21,6 @@ import QtQuick 2.6 import Sailfish.Silica 1.0 import WerkWolf.Fernschreiber 1.0 import "../../components" -import "../../js/twemoji.js" as Emoji import "../../js/functions.js" as Functions AccordionItem { @@ -32,7 +31,6 @@ AccordionItem { bottomPadding: Theme.paddingMedium property variant activeSessions; property bool loaded : false; - readonly property var userInformation : tdLibWrapper.userInformation Component.onCompleted: { if (!activeSessions) { diff --git a/qml/components/settingsPage/SettingsUserProfile.qml b/qml/components/settingsPage/SettingsUserProfile.qml index 0b6f901..d7d7424 100644 --- a/qml/components/settingsPage/SettingsUserProfile.qml +++ b/qml/components/settingsPage/SettingsUserProfile.qml @@ -23,6 +23,7 @@ import Sailfish.Pickers 1.0 import WerkWolf.Fernschreiber 1.0 import "../" import "../../pages/" +import "../../js/twemoji.js" as Emoji import "../../js/functions.js" as Functions AccordionItem { @@ -34,13 +35,24 @@ AccordionItem { readonly property var userInformation: tdLibWrapper.getUserInformation() property bool uploadInProgress: false + property variant activeSessions; + property bool loaded : false; Component.onCompleted: { tdLibWrapper.getUserProfilePhotos(userInformation.id, 100, 0); + if (!activeSessions) { + tdLibWrapper.getActiveSessions(); + } else { + accordionContent.loaded = true; + } } Connections { target: tdLibWrapper + onSessionsReceived: { + accordionContent.activeSessions = sessions; + accordionContent.loaded = true; + } onOwnUserUpdated: { firstNameEditArea.text = userInformation.first_name; lastNameEditArea.text = userInformation.last_name; @@ -62,6 +74,11 @@ AccordionItem { } } onOkReceived: { + if (request === "terminateSession") { + appNotification.show(qsTr("Session was terminated")); + accordionContent.loaded = false; + tdLibWrapper.getActiveSessions(); + } if (request === "deleteProfilePhoto") { tdLibWrapper.getUserProfilePhotos(userInformation.id, 100, 0); } @@ -256,6 +273,85 @@ AccordionItem { } } } + + SectionHeader { + horizontalAlignment: Text.AlignLeft + text: qsTr("Logged in as") + } + + Row { + width: parent.width - ( 2 * Theme.horizontalPageMargin ) + spacing: Theme.paddingMedium + + Loader { + id: userInformationLoader + active: tdLibWrapper.authorizationState === TelegramAPI.AuthorizationReady + width: parent.width / 2 + sourceComponent: Component { + Column { + width: parent.width + spacing: Theme.paddingMedium + anchors.topMargin: Theme.paddingMedium + + Text { + anchors.horizontalCenter: parent.horizontalCenter + horizontalAlignment: Text.AlignHCenter + text: Emoji.emojify(accordionContent.userInformation.first_name + " " + accordionContent.userInformation.last_name, Theme.fontSizeSmall) + font.pixelSize: Theme.fontSizeSmall + wrapMode: Text.Wrap + color: Theme.primaryColor + textFormat: Text.StyledText + anchors { + horizontalCenter: parent.horizontalCenter + } + } + + ProfileThumbnail { + photoData: ((typeof accordionContent.userInformation.profile_photo !== "undefined") ? accordionContent.userInformation.profile_photo.small : {}) + anchors.horizontalCenter: parent.horizontalCenter + width: Theme.itemSizeSmall + height: Theme.itemSizeSmall + replacementStringHint: accordionContent.userInformation.first_name + " " + accordionContent.userInformation.last_name + anchors { + horizontalCenter: parent.horizontalCenter + } + } + + Label { + width: accordionContent.width / 2 - Theme.horizontalPageMargin + anchors.horizontalCenter: parent.horizontalCenter + horizontalAlignment: Text.AlignHCenter + text: qsTr("Phone number: +%1").arg(accordionContent.userInformation.phone_number) + font.pixelSize: Theme.fontSizeSmall + wrapMode: Text.Wrap + anchors { + horizontalCenter: parent.horizontalCenter + } + } + } + } + } + BackgroundItem { + id: logOutItem + width: parent.width / 2 + height: userInformationLoader.height + anchors.verticalCenter: parent.verticalCenter + enabled: userInformationLoader.status == Loader.Ready + function showRemorseItem() { + remorse.execute(logOutItem, qsTr("Logged out"), function() { + tdLibWrapper.logout(); + pageStack.pop(); + }); + } + RemorseItem { id: remorse } + Button { + id: logOutButton + text: qsTr("Log Out") + anchors.centerIn: parent + onClicked: logOutItem.showRemorseItem() + } + } + } } } } From 313a4d38272ea269ca553830b6bbeaf2b2c1476e Mon Sep 17 00:00:00 2001 From: nephros Date: Wed, 15 Dec 2021 11:57:48 +0100 Subject: [PATCH 5/7] fixup! Settings: add login info and logout to Profile --- qml/components/settingsPage/SettingsUserProfile.qml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/qml/components/settingsPage/SettingsUserProfile.qml b/qml/components/settingsPage/SettingsUserProfile.qml index d7d7424..c5414e0 100644 --- a/qml/components/settingsPage/SettingsUserProfile.qml +++ b/qml/components/settingsPage/SettingsUserProfile.qml @@ -74,11 +74,6 @@ AccordionItem { } } onOkReceived: { - if (request === "terminateSession") { - appNotification.show(qsTr("Session was terminated")); - accordionContent.loaded = false; - tdLibWrapper.getActiveSessions(); - } if (request === "deleteProfilePhoto") { tdLibWrapper.getUserProfilePhotos(userInformation.id, 100, 0); } From 8349cb43772d1bc630027de9c880b63f723a47bf Mon Sep 17 00:00:00 2001 From: nephros Date: Wed, 15 Dec 2021 12:02:32 +0100 Subject: [PATCH 6/7] fixup! fixup! Settings: add login info and logout to Profile --- qml/components/settingsPage/SettingsUserProfile.qml | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/qml/components/settingsPage/SettingsUserProfile.qml b/qml/components/settingsPage/SettingsUserProfile.qml index c5414e0..cfc0066 100644 --- a/qml/components/settingsPage/SettingsUserProfile.qml +++ b/qml/components/settingsPage/SettingsUserProfile.qml @@ -35,24 +35,13 @@ AccordionItem { readonly property var userInformation: tdLibWrapper.getUserInformation() property bool uploadInProgress: false - property variant activeSessions; - property bool loaded : false; Component.onCompleted: { tdLibWrapper.getUserProfilePhotos(userInformation.id, 100, 0); - if (!activeSessions) { - tdLibWrapper.getActiveSessions(); - } else { - accordionContent.loaded = true; - } } Connections { target: tdLibWrapper - onSessionsReceived: { - accordionContent.activeSessions = sessions; - accordionContent.loaded = true; - } onOwnUserUpdated: { firstNameEditArea.text = userInformation.first_name; lastNameEditArea.text = userInformation.last_name; From a5e5e36083fc6e56fb9043596bd3a3618201e91b Mon Sep 17 00:00:00 2001 From: nephros Date: Wed, 15 Dec 2021 12:17:05 +0100 Subject: [PATCH 7/7] Use Remorse.popupAction instead of RemorseItem RemorseItem sets anchors which we can't have in a Column --- qml/components/settingsPage/SettingsUserProfile.qml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/qml/components/settingsPage/SettingsUserProfile.qml b/qml/components/settingsPage/SettingsUserProfile.qml index cfc0066..5191256 100644 --- a/qml/components/settingsPage/SettingsUserProfile.qml +++ b/qml/components/settingsPage/SettingsUserProfile.qml @@ -321,18 +321,14 @@ AccordionItem { height: userInformationLoader.height anchors.verticalCenter: parent.verticalCenter enabled: userInformationLoader.status == Loader.Ready - function showRemorseItem() { - remorse.execute(logOutItem, qsTr("Logged out"), function() { - tdLibWrapper.logout(); - pageStack.pop(); - }); - } - RemorseItem { id: remorse } Button { id: logOutButton text: qsTr("Log Out") anchors.centerIn: parent - onClicked: logOutItem.showRemorseItem() + onClicked: Remorse.popupAction(settingsPage, qsTr("Logged out"), function() { + tdLibWrapper.logout(); + pageStack.pop(); + }); } } }