Files
amnezia-client/client/ui/qml/Pages2/PageHome.qml
T

483 lines
18 KiB
QML
Raw Normal View History

import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import Qt5Compat.GraphicalEffects
2023-05-11 14:50:50 +08:00
import SortFilterProxyModel 0.2
import PageEnum 1.0
import ContainerProps 1.0
import ContainersModelFilters 1.0
2024-07-07 13:42:38 +03:00
import Style 1.0
import "./"
import "../Controls2"
import "../Controls2/TextTypes"
import "../Config"
import "../Components"
PageType {
id: root
property var containersDropDownRef: null
2025-11-11 17:03:27 +03:00
Connections {
target: Qt.application
function onStateChanged() {
if (Qt.application.state !== Qt.ApplicationActive) {
if (drawer.isOpened) {
drawer.closeTriggered()
}
if (homeSplitTunnelingDrawer.isOpened) {
homeSplitTunnelingDrawer.closeTriggered()
}
}
}
}
Connections {
2024-12-31 04:16:52 +01:00
objectName: "pageControllerConnections"
target: PageController
function onRestorePageHomeState(isContainerInstalled) {
2024-12-31 04:16:52 +01:00
drawer.openTriggered()
if (isContainerInstalled && root.containersDropDownRef) {
root.containersDropDownRef.rootButtonClickedFunction()
}
}
}
2025-05-13 12:29:33 +08:00
2023-09-06 13:37:37 +05:00
Item {
2024-12-31 04:16:52 +01:00
objectName: "homeColumnItem"
anchors.fill: parent
2024-02-16 15:24:06 +05:00
anchors.bottomMargin: drawer.collapsedHeight
2023-09-06 13:37:37 +05:00
2024-03-20 21:22:29 +07:00
ColumnLayout {
2024-12-31 04:16:52 +01:00
objectName: "homeColumnLayout"
2024-03-20 21:22:29 +07:00
anchors.fill: parent
anchors.topMargin: 12 + PageController.safeAreaTopMargin
anchors.bottomMargin: 16
2024-03-20 21:22:29 +07:00
BasicButtonType {
2024-04-18 17:54:55 +04:00
id: loggingButton
2024-12-31 04:16:52 +01:00
objectName: "loggingButton"
2024-03-20 21:22:29 +07:00
property bool isLoggingEnabled: SettingsController.isLoggingEnabled
2024-02-21 18:27:27 +07:00
2024-03-20 21:22:29 +07:00
Layout.alignment: Qt.AlignHCenter
2024-02-21 18:27:27 +07:00
2024-03-20 21:22:29 +07:00
implicitHeight: 36
2024-02-21 18:27:27 +07:00
2024-07-07 13:42:38 +03:00
defaultColor: AmneziaStyle.color.transparent
hoveredColor: AmneziaStyle.color.translucentWhite
pressedColor: AmneziaStyle.color.sheerWhite
disabledColor: AmneziaStyle.color.mutedGray
textColor: AmneziaStyle.color.mutedGray
2024-03-20 21:22:29 +07:00
borderWidth: 0
2024-02-21 18:27:27 +07:00
2024-03-20 21:22:29 +07:00
visible: isLoggingEnabled ? true : false
text: qsTr("Logging enabled")
2024-02-21 18:27:27 +07:00
Keys.onEnterPressed: this.clicked()
Keys.onReturnPressed: this.clicked()
2024-04-18 17:54:55 +04:00
2024-03-20 21:22:29 +07:00
onClicked: {
PageController.goToPage(PageEnum.PageSettingsLogging)
}
2024-02-21 18:27:27 +07:00
}
2025-10-07 23:15:06 +08:00
BasicButtonType {
id: devGatewayButton
objectName: "devGatewayButton"
property bool isDevGatewayEnabled: SettingsController.isDevGatewayEnv
Layout.alignment: Qt.AlignHCenter
implicitHeight: 36
defaultColor: AmneziaStyle.color.transparent
hoveredColor: AmneziaStyle.color.translucentWhite
pressedColor: AmneziaStyle.color.sheerWhite
disabledColor: AmneziaStyle.color.mutedGray
textColor: AmneziaStyle.color.mutedGray
borderWidth: 0
visible: SettingsController.isDevModeEnabled && isDevGatewayEnabled
text: qsTr("Dev gateway enabled")
Keys.onEnterPressed: this.clicked()
Keys.onReturnPressed: this.clicked()
onClicked: {
PageController.goToPage(PageEnum.PageDevMenu)
}
}
2024-03-20 21:22:29 +07:00
ConnectButton {
id: connectButton
2024-12-31 04:16:52 +01:00
objectName: "connectButton"
2024-03-25 21:52:38 +05:00
Layout.fillHeight: true
Layout.alignment: Qt.AlignCenter
2024-03-20 21:22:29 +07:00
}
BasicButtonType {
2024-04-18 17:54:55 +04:00
id: splitTunnelingButton
2024-12-31 04:16:52 +01:00
objectName: "splitTunnelingButton"
2024-03-25 21:52:38 +05:00
Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom
2024-03-20 21:22:29 +07:00
leftPadding: 16
rightPadding: 16
implicitHeight: 36
2024-07-07 13:42:38 +03:00
defaultColor: AmneziaStyle.color.transparent
hoveredColor: AmneziaStyle.color.translucentWhite
pressedColor: AmneziaStyle.color.sheerWhite
disabledColor: AmneziaStyle.color.mutedGray
textColor: AmneziaStyle.color.mutedGray
2024-03-20 21:22:29 +07:00
borderWidth: 0
buttonTextLabel.lineHeight: 20
buttonTextLabel.font.pixelSize: 14
buttonTextLabel.font.weight: 500
property bool isSplitTunnelingEnabled: IpSplitTunnelingController.isSplitTunnelingEnabled || AppSplitTunnelingController.isSplitTunnelingEnabled ||
ServersUiController.isDefaultServerDefaultContainerHasSplitTunneling
2024-03-20 21:22:29 +07:00
text: isSplitTunnelingEnabled ? qsTr("Split tunneling enabled") : qsTr("Split tunneling disabled")
leftImageSource: isSplitTunnelingEnabled ? "qrc:/images/controls/split-tunneling.svg" : ""
2024-12-19 10:36:20 +03:00
leftImageColor: ""
2024-03-20 21:22:29 +07:00
rightImageSource: "qrc:/images/controls/chevron-down.svg"
Keys.onEnterPressed: this.clicked()
Keys.onReturnPressed: this.clicked()
2024-04-18 17:54:55 +04:00
2024-03-20 21:22:29 +07:00
onClicked: {
2024-12-31 04:16:52 +01:00
homeSplitTunnelingDrawer.openTriggered()
2024-03-20 21:22:29 +07:00
}
2024-02-21 18:27:27 +07:00
2024-03-20 21:22:29 +07:00
HomeSplitTunnelingDrawer {
id: homeSplitTunnelingDrawer
2024-12-31 04:16:52 +01:00
objectName: "homeSplitTunnelingDrawer"
2024-04-18 17:54:55 +04:00
2024-12-31 04:16:52 +01:00
parent: root
2024-03-20 21:22:29 +07:00
}
2024-02-21 18:27:27 +07:00
}
2025-11-03 10:26:22 +08:00
AdLabel {
id: adLabel
Layout.fillWidth: true
Layout.preferredHeight: adLabel.contentHeight
Layout.leftMargin: 16
Layout.rightMargin: 16
Layout.topMargin: 22
}
2024-02-21 18:27:27 +07:00
}
}
2024-02-16 15:24:06 +05:00
DrawerType2 {
id: drawer
2024-12-31 04:16:52 +01:00
objectName: "drawerProtocol"
2024-02-16 15:24:06 +05:00
anchors.fill: parent
2024-12-31 04:16:52 +01:00
collapsedStateContent: Item {
objectName: "ProtocolDrawerCollapsedContent"
2024-04-18 17:54:55 +04:00
implicitHeight: Qt.platform.os !== "ios" ? root.height * 0.9 : screen.height * 0.77
Component.onCompleted: {
drawer.expandedHeight = implicitHeight
}
2024-12-31 04:16:52 +01:00
ColumnLayout {
id: collapsed
2024-12-31 04:16:52 +01:00
objectName: "collapsedColumnLayout"
anchors.left: parent.left
anchors.right: parent.right
spacing: 0
Component.onCompleted: {
drawer.collapsedHeight = collapsed.implicitHeight
}
DividerType {
Layout.topMargin: 10
Layout.fillWidth: false
Layout.preferredWidth: 20
Layout.preferredHeight: 2
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
}
RowLayout {
2024-12-31 04:16:52 +01:00
objectName: "rowLayout"
Layout.topMargin: 14
Layout.leftMargin: 24
Layout.rightMargin: 24
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
spacing: 0
Connections {
2024-12-31 04:16:52 +01:00
objectName: "drawerConnections"
target: drawer
2024-12-31 04:16:52 +01:00
function onCursorEntered() {
if (drawer.isCollapsedStateActive) {
collapsedButtonChevron.backgroundColor = collapsedButtonChevron.hoveredColor
collapsedButtonHeader.opacity = 0.8
} else {
collapsedButtonHeader.opacity = 1
}
}
2024-12-31 04:16:52 +01:00
function onCursorExited() {
if (drawer.isCollapsedStateActive) {
collapsedButtonChevron.backgroundColor = collapsedButtonChevron.defaultColor
collapsedButtonHeader.opacity = 1
} else {
collapsedButtonHeader.opacity = 1
}
}
function onPressed(pressed, entered) {
2024-12-31 04:16:52 +01:00
if (drawer.isCollapsedStateActive) {
collapsedButtonChevron.backgroundColor = pressed ? collapsedButtonChevron.pressedColor : entered ? collapsedButtonChevron.hoveredColor : collapsedButtonChevron.defaultColor
collapsedButtonHeader.opacity = 0.7
} else {
collapsedButtonHeader.opacity = 1
}
}
2024-02-16 15:24:06 +05:00
}
2023-08-26 10:08:50 +03:00
Header1TextType {
id: collapsedButtonHeader
2024-12-31 04:16:52 +01:00
objectName: "collapsedButtonHeader"
Layout.maximumWidth: drawer.width - 48 - 18 - 12
maximumLineCount: 2
elide: Qt.ElideRight
2023-10-19 09:27:39 +08:00
text: ServersUiController.defaultServerName
horizontalAlignment: Qt.AlignHCenter
2023-10-19 09:27:39 +08:00
Behavior on opacity {
PropertyAnimation { duration: 200 }
}
2024-02-16 15:24:06 +05:00
}
2023-10-19 09:27:39 +08:00
ImageButtonType {
id: collapsedButtonChevron
2024-12-31 04:16:52 +01:00
objectName: "collapsedButtonChevron"
2023-10-19 09:27:39 +08:00
Layout.leftMargin: 8
2023-10-19 09:27:39 +08:00
2024-12-31 04:16:52 +01:00
visible: drawer.isCollapsedStateActive()
2023-10-19 09:27:39 +08:00
hoverEnabled: false
image: "qrc:/images/controls/chevron-down.svg"
imageColor: AmneziaStyle.color.paleGray
2023-10-19 09:27:39 +08:00
icon.width: 18
icon.height: 18
backgroundRadius: 16
horizontalPadding: 4
topPadding: 4
bottomPadding: 3
Keys.onEnterPressed: this.clicked()
Keys.onReturnPressed: this.clicked()
2024-04-18 17:54:55 +04:00
onClicked: {
2024-12-31 04:16:52 +01:00
if (drawer.isCollapsedStateActive()) {
drawer.openTriggered()
}
2024-02-16 15:24:06 +05:00
}
}
}
2023-10-19 09:27:39 +08:00
RowLayout {
2024-12-31 04:16:52 +01:00
objectName: "rowLayoutLabel"
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
Layout.topMargin: 8
Layout.bottomMargin: drawer.isCollapsedStateActive ? 44 : ServersUiController.isDefaultServerFromApi ? 61 : 16
spacing: 0
BasicButtonType {
enabled: (ServersUiController.defaultServerImagePathCollapsed !== "") && drawer.isCollapsedStateActive
hoverEnabled: enabled
implicitHeight: 36
leftPadding: 16
rightPadding: 16
defaultColor: AmneziaStyle.color.transparent
hoveredColor: AmneziaStyle.color.translucentWhite
pressedColor: AmneziaStyle.color.sheerWhite
disabledColor: AmneziaStyle.color.transparent
textColor: AmneziaStyle.color.mutedGray
buttonTextLabel.lineHeight: 16
buttonTextLabel.font.pixelSize: 13
buttonTextLabel.font.weight: 400
text: drawer.isCollapsedStateActive ? ServersUiController.defaultServerDescriptionCollapsed : ServersUiController.defaultServerDescriptionExpanded
leftImageSource: ServersUiController.defaultServerImagePathCollapsed
leftImageColor: ""
changeLeftImageSize: false
rightImageSource: hoverEnabled ? "qrc:/images/controls/chevron-down.svg" : ""
Keys.onEnterPressed: this.clicked()
Keys.onReturnPressed: this.clicked()
onClicked: {
2026-05-28 10:57:08 +08:00
ServersUiController.setProcessedServerId(ServersUiController.defaultServerId)
2026-05-28 10:57:08 +08:00
if (ServersUiController.isServerFromApi(ServersUiController.processedServerId)) {
if (ServersUiController.isServerCountrySelectionAvailable(ServersUiController.processedServerId)) {
PageController.goToPage(PageEnum.PageSettingsApiAvailableCountries)
} else {
PageController.showBusyIndicator(true)
2026-05-28 10:57:08 +08:00
let result = SubscriptionUiController.getAccountInfo(ServersUiController.processedServerId, false)
PageController.showBusyIndicator(false)
if (!result) {
return
}
PageController.goToPage(PageEnum.PageSettingsApiServerInfo)
}
} else {
PageController.goToPage(PageEnum.PageSettingsServerInfo)
}
}
}
}
}
2023-10-19 09:27:39 +08:00
2024-02-16 15:24:06 +05:00
ColumnLayout {
id: serversMenuHeader
2024-12-31 04:16:52 +01:00
objectName: "serversMenuHeader"
2023-10-19 09:27:39 +08:00
anchors.top: collapsed.bottom
2024-02-16 15:24:06 +05:00
anchors.right: parent.right
anchors.left: parent.left
2023-10-19 11:22:52 +08:00
2024-02-16 15:24:06 +05:00
RowLayout {
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
spacing: 8
visible: !ServersUiController.isDefaultServerFromApi
2024-02-16 15:24:06 +05:00
DropDownType {
id: containersDropDown
2024-12-31 04:16:52 +01:00
objectName: "containersDropDown"
2024-02-16 15:24:06 +05:00
Component.onCompleted: root.containersDropDownRef = containersDropDown
rootButtonImageColor: AmneziaStyle.color.midnightBlack
rootButtonBackgroundColor: AmneziaStyle.color.paleGray
2024-11-06 09:57:39 +04:00
rootButtonBackgroundHoveredColor: AmneziaStyle.color.mistyGray
rootButtonBackgroundPressedColor: AmneziaStyle.color.cloudyGray
2024-07-07 13:42:38 +03:00
rootButtonHoveredBorderColor: AmneziaStyle.color.transparent
rootButtonDefaultBorderColor: AmneziaStyle.color.transparent
2024-02-16 15:24:06 +05:00
rootButtonTextTopMargin: 8
rootButtonTextBottomMargin: 8
2024-12-31 04:16:52 +01:00
enabled: drawer.isOpened
text: ServersUiController.defaultServerDefaultContainerName
textColor: AmneziaStyle.color.midnightBlack
2024-02-16 15:24:06 +05:00
headerText: qsTr("VPN protocol")
headerBackButtonImage: "qrc:/images/controls/arrow-left.svg"
rootButtonClickedFunction: function() {
2024-12-31 04:16:52 +01:00
containersDropDown.openTriggered()
2024-02-16 15:24:06 +05:00
}
2024-02-16 15:24:06 +05:00
drawerParent: root
2024-02-16 15:24:06 +05:00
listView: HomeContainersListView {
2024-04-18 17:54:55 +04:00
id: containersListView
2024-12-31 04:16:52 +01:00
objectName: "containersListView"
2024-02-16 15:24:06 +05:00
rootWidth: root.width
2024-02-16 15:24:06 +05:00
Connections {
2024-12-31 04:16:52 +01:00
objectName: "rowLayoutConnections"
target: ServersUiController
2023-05-11 14:50:50 +08:00
2026-05-28 10:57:08 +08:00
function onDefaultServerIdChanged() {
2024-02-16 15:24:06 +05:00
updateContainersModelFilters()
}
}
2024-02-16 15:24:06 +05:00
function updateContainersModelFilters() {
2026-05-28 10:57:08 +08:00
if (ServersUiController.isServerHasWriteAccess(ServersUiController.defaultServerId)) {
2024-02-19 19:54:15 +05:00
proxyDefaultServerContainersModel.filters = ContainersModelFilters.getWriteAccessProtocolsListFilters()
2024-02-16 15:24:06 +05:00
} else {
2024-02-19 19:54:15 +05:00
proxyDefaultServerContainersModel.filters = ContainersModelFilters.getReadAccessProtocolsListFilters()
2024-02-16 15:24:06 +05:00
}
}
2024-02-16 15:24:06 +05:00
model: SortFilterProxyModel {
2024-02-19 19:54:15 +05:00
id: proxyDefaultServerContainersModel
sourceModel: DefaultServerContainersModel
2024-03-04 02:28:10 +03:00
sorters: [
RoleSorter { roleName: "isInstalled"; sortOrder: Qt.DescendingOrder }
]
}
2024-02-16 15:24:06 +05:00
Component.onCompleted: updateContainersModelFilters()
}
2023-05-11 14:50:50 +08:00
}
}
2024-02-16 15:24:06 +05:00
Header2Type {
Layout.fillWidth: true
Layout.topMargin: 48
Layout.leftMargin: 16
Layout.rightMargin: 16
2024-02-16 15:24:06 +05:00
headerText: qsTr("Servers")
}
}
2024-03-25 22:30:44 +05:00
ButtonGroup {
id: serversRadioButtonGroup
2024-12-31 04:16:52 +01:00
objectName: "serversRadioButtonGroup"
2024-03-25 22:30:44 +05:00
}
2024-12-31 04:16:52 +01:00
ServersListView {
2024-03-25 22:30:44 +05:00
id: serversMenuContent
2024-12-31 04:16:52 +01:00
objectName: "serversMenuContent"
2024-12-31 04:16:52 +01:00
isFocusable: false
2024-04-18 17:54:55 +04:00
Connections {
target: drawer
2024-12-31 04:16:52 +01:00
// this item shouldn't be focused when drawer is closed
function onIsOpenedChanged() {
serversMenuContent.isFocusable = drawer.isOpened
}
}
}
}
}
}