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

556 lines
20 KiB
QML
Raw Normal View History

import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
2023-05-11 14:50:50 +08:00
import SortFilterProxyModel 0.2
import PageEnum 1.0
2023-05-11 14:50:50 +08:00
import ProtocolEnum 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
2024-04-18 17:54:55 +04:00
defaultActiveFocusItem: focusItem
Connections {
target: PageController
function onRestorePageHomeState(isContainerInstalled) {
2024-02-16 15:24:06 +05:00
drawer.open()
if (isContainerInstalled) {
2023-10-23 21:30:30 +05:00
containersDropDown.rootButtonClickedFunction()
}
}
}
2023-09-06 13:37:37 +05:00
Item {
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 {
anchors.fill: parent
anchors.topMargin: 34
2024-02-21 18:27:27 +07:00
anchors.bottomMargin: 34
2024-04-18 17:54:55 +04:00
Item {
id: focusItem
KeyNavigation.tab: loggingButton.visible ?
loggingButton :
connectButton
}
2024-03-20 21:22:29 +07:00
BasicButtonType {
2024-04-18 17:54:55 +04:00
id: 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
2024-04-18 17:54:55 +04:00
Keys.onEnterPressed: loggingButton.clicked()
Keys.onReturnPressed: loggingButton.clicked()
KeyNavigation.tab: connectButton
2024-03-20 21:22:29 +07:00
onClicked: {
PageController.goToPage(PageEnum.PageSettingsLogging)
}
2024-02-21 18:27:27 +07:00
}
2024-03-20 21:22:29 +07:00
ConnectButton {
id: connectButton
2024-03-25 21:52:38 +05:00
Layout.fillHeight: true
Layout.alignment: Qt.AlignCenter
2024-04-18 17:54:55 +04:00
KeyNavigation.tab: splitTunnelingButton
2024-03-20 21:22:29 +07:00
}
BasicButtonType {
2024-04-18 17:54:55 +04:00
id: splitTunnelingButton
2024-03-25 21:52:38 +05:00
Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom
Layout.bottomMargin: 34
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-07-07 13:42:38 +03:00
leftImageColor: AmneziaStyle.color.transparent
2024-03-20 21:22:29 +07:00
borderWidth: 0
buttonTextLabel.lineHeight: 20
buttonTextLabel.font.pixelSize: 14
buttonTextLabel.font.weight: 500
2024-04-01 17:07:33 +05:00
property bool isSplitTunnelingEnabled: SitesModel.isTunnelingEnabled || AppSplitTunnelingModel.isTunnelingEnabled ||
ServersModel.isDefaultServerDefaultContainerHasSplitTunneling
2024-03-20 21:22:29 +07:00
text: isSplitTunnelingEnabled ? qsTr("Split tunneling enabled") : qsTr("Split tunneling disabled")
imageSource: isSplitTunnelingEnabled ? "qrc:/images/controls/split-tunneling.svg" : ""
rightImageSource: "qrc:/images/controls/chevron-down.svg"
2024-04-18 17:54:55 +04:00
Keys.onEnterPressed: splitTunnelingButton.clicked()
Keys.onReturnPressed: splitTunnelingButton.clicked()
KeyNavigation.tab: drawer
2024-03-20 21:22:29 +07:00
onClicked: {
homeSplitTunnelingDrawer.open()
}
2024-02-21 18:27:27 +07:00
2024-03-20 21:22:29 +07:00
HomeSplitTunnelingDrawer {
id: homeSplitTunnelingDrawer
parent: root
2024-04-18 17:54:55 +04:00
onClosed: {
if (!GC.isMobile()) {
focusItem.forceActiveFocus()
}
}
2024-03-20 21:22:29 +07:00
}
2024-02-21 18:27:27 +07:00
}
}
}
2024-02-16 15:24:06 +05:00
DrawerType2 {
id: drawer
anchors.fill: parent
2024-04-18 17:54:55 +04:00
onClosed: {
if (!GC.isMobile()) {
focusItem.forceActiveFocus()
}
}
2024-04-16 16:01:45 +05:00
collapsedContent: Item {
implicitHeight: Qt.platform.os !== "ios" ? root.height * 0.9 : screen.height * 0.77
Component.onCompleted: {
drawer.expandedHeight = implicitHeight
}
2024-04-18 17:54:55 +04:00
Connections {
target: drawer
enabled: !GC.isMobile()
function onActiveFocusChanged() {
if (drawer.activeFocus && !drawer.isOpened) {
collapsedButtonChevron.forceActiveFocus()
}
}
}
ColumnLayout {
id: collapsed
anchors.left: parent.left
anchors.right: parent.right
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 {
Layout.topMargin: 14
Layout.leftMargin: 24
Layout.rightMargin: 24
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
spacing: 0
Connections {
target: drawer
function onEntered() {
if (drawer.isCollapsed) {
collapsedButtonChevron.backgroundColor = collapsedButtonChevron.hoveredColor
collapsedButtonHeader.opacity = 0.8
} else {
collapsedButtonHeader.opacity = 1
}
}
function onExited() {
if (drawer.isCollapsed) {
collapsedButtonChevron.backgroundColor = collapsedButtonChevron.defaultColor
collapsedButtonHeader.opacity = 1
} else {
collapsedButtonHeader.opacity = 1
}
}
function onPressed(pressed, entered) {
if (drawer.isCollapsed) {
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
Layout.maximumWidth: drawer.width - 48 - 18 - 12
maximumLineCount: 2
elide: Qt.ElideRight
2023-10-19 09:27:39 +08:00
text: ServersModel.defaultServerName
horizontalAlignment: Qt.AlignHCenter
2023-10-19 09:27:39 +08:00
2024-04-18 17:54:55 +04:00
KeyNavigation.tab: tabBar
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
2023-10-19 09:27:39 +08:00
Layout.leftMargin: 8
2023-10-19 09:27:39 +08:00
visible: drawer.isCollapsed
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
2024-04-18 17:54:55 +04:00
Keys.onEnterPressed: collapsedButtonChevron.clicked()
Keys.onReturnPressed: collapsedButtonChevron.clicked()
Keys.onTabPressed: lastItemTabClicked()
onClicked: {
if (drawer.isCollapsed) {
drawer.open()
}
2024-02-16 15:24:06 +05:00
}
}
}
2023-10-19 09:27:39 +08:00
RowLayout {
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
Layout.bottomMargin: drawer.isCollapsed ? 44 : ServersModel.isDefaultServerFromApi ? 89 : 44
spacing: 0
Image {
Layout.rightMargin: 8
visible: source !== ""
source: ServersModel.defaultServerImagePathCollapsed
}
LabelTextType {
id: collapsedServerMenuDescription
text: drawer.isCollapsed ? ServersModel.defaultServerDescriptionCollapsed : ServersModel.defaultServerDescriptionExpanded
}
}
}
2023-10-19 09:27:39 +08:00
2024-04-18 17:54:55 +04:00
Connections {
target: drawer
enabled: !GC.isMobile()
function onIsCollapsedChanged() {
if (!drawer.isCollapsed) {
focusItem1.forceActiveFocus()
}
}
}
2024-02-16 15:24:06 +05:00
ColumnLayout {
id: 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: !ServersModel.isDefaultServerFromApi
2024-04-18 17:54:55 +04:00
Item {
id: focusItem1
KeyNavigation.tab: containersDropDown
}
2024-02-16 15:24:06 +05:00
DropDownType {
id: containersDropDown
rootButtonImageColor: AmneziaStyle.color.midnightBlack
rootButtonBackgroundColor: AmneziaStyle.color.paleGray
2024-02-16 15:24:06 +05:00
rootButtonBackgroundHoveredColor: Qt.rgba(215, 216, 219, 0.8)
rootButtonBackgroundPressedColor: Qt.rgba(215, 216, 219, 0.65)
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-02-19 19:54:15 +05:00
text: ServersModel.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() {
containersDropDown.open()
}
2024-02-16 15:24:06 +05:00
drawerParent: root
2024-04-18 17:54:55 +04:00
KeyNavigation.tab: serversMenuContent
2024-02-16 15:24:06 +05:00
listView: HomeContainersListView {
2024-04-18 17:54:55 +04:00
id: containersListView
2024-02-16 15:24:06 +05:00
rootWidth: root.width
2024-04-18 17:54:55 +04:00
onVisibleChanged: {
if (containersDropDown.visible && !GC.isMobile()) {
focusItem1.forceActiveFocus()
}
}
2024-02-16 15:24:06 +05:00
Connections {
target: ServersModel
2023-05-11 14:50:50 +08:00
2024-02-19 19:54:15 +05:00
function onDefaultServerIndexChanged() {
2024-02-16 15:24:06 +05:00
updateContainersModelFilters()
}
}
2024-02-16 15:24:06 +05:00
function updateContainersModelFilters() {
2024-02-19 19:54:15 +05:00
if (ServersModel.isDefaultServerHasWriteAccess()) {
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
}
ListView {
id: serversMenuContent
2024-02-16 15:24:06 +05:00
anchors.top: serversMenuHeader.bottom
anchors.right: parent.right
2024-02-16 15:24:06 +05:00
anchors.left: parent.left
2024-03-25 22:30:44 +05:00
anchors.bottom: parent.bottom
2024-02-16 15:24:06 +05:00
anchors.topMargin: 16
2024-03-25 22:30:44 +05:00
model: ServersModel
currentIndex: ServersModel.defaultIndex
2024-02-16 15:24:06 +05:00
ScrollBar.vertical: ScrollBar {
id: scrollBar
2024-03-25 22:30:44 +05:00
policy: serversMenuContent.height >= serversMenuContent.contentHeight ? ScrollBar.AlwaysOff : ScrollBar.AlwaysOn
}
2024-04-18 17:54:55 +04:00
activeFocusOnTab: true
focus: true
property int focusItemIndex: 0
onActiveFocusChanged: {
if (activeFocus) {
serversMenuContent.focusItemIndex = 0
serversMenuContent.itemAtIndex(focusItemIndex).forceActiveFocus()
}
}
onFocusItemIndexChanged: {
const focusedElement = serversMenuContent.itemAtIndex(focusItemIndex)
if (focusedElement) {
if (focusedElement.y + focusedElement.height > serversMenuContent.height) {
serversMenuContent.contentY = focusedElement.y + focusedElement.height - serversMenuContent.height
} else {
serversMenuContent.contentY = 0
}
}
}
2024-02-16 15:24:06 +05:00
Keys.onUpPressed: scrollBar.decrease()
Keys.onDownPressed: scrollBar.increase()
2024-04-18 17:54:55 +04:00
Connections {
target: drawer
enabled: !GC.isMobile()
function onIsCollapsedChanged() {
if (drawer.isCollapsed) {
const item = serversMenuContent.itemAtIndex(serversMenuContent.focusItemIndex)
if (item) { item.serverRadioButtonProperty.focus = false }
}
}
}
2024-03-25 22:30:44 +05:00
Connections {
target: ServersModel
function onDefaultServerIndexChanged(serverIndex) {
serversMenuContent.currentIndex = serverIndex
2024-02-09 23:23:26 +05:00
}
2024-03-25 22:30:44 +05:00
}
2024-02-09 23:23:26 +05:00
2024-03-25 22:30:44 +05:00
clip: true
2024-03-25 22:30:44 +05:00
delegate: Item {
id: menuContentDelegate
2024-03-25 22:30:44 +05:00
property variant delegateData: model
2024-04-18 17:54:55 +04:00
property VerticalRadioButton serverRadioButtonProperty: serverRadioButton
2024-03-25 22:30:44 +05:00
implicitWidth: serversMenuContent.width
implicitHeight: serverRadioButtonContent.implicitHeight
2024-04-18 17:54:55 +04:00
onActiveFocusChanged: {
if (activeFocus) {
serverRadioButton.forceActiveFocus()
}
}
2024-03-25 22:30:44 +05:00
ColumnLayout {
id: serverRadioButtonContent
2024-03-25 22:30:44 +05:00
anchors.fill: parent
anchors.rightMargin: 16
anchors.leftMargin: 16
2024-03-25 22:30:44 +05:00
spacing: 0
2024-03-25 22:30:44 +05:00
RowLayout {
Layout.fillWidth: true
VerticalRadioButton {
id: serverRadioButton
2024-03-25 22:30:44 +05:00
Layout.fillWidth: true
2024-03-25 22:30:44 +05:00
text: name
descriptionText: serverDescription
2024-03-25 22:30:44 +05:00
checked: index === serversMenuContent.currentIndex
checkable: !ConnectionController.isConnected
2024-02-16 15:24:06 +05:00
2024-03-25 22:30:44 +05:00
ButtonGroup.group: serversRadioButtonGroup
2024-02-16 15:24:06 +05:00
2024-03-25 22:30:44 +05:00
onClicked: {
if (ConnectionController.isConnected) {
PageController.showNotificationMessage(qsTr("Unable change server while there is an active connection"))
return
}
2024-02-16 15:24:06 +05:00
2024-03-25 22:30:44 +05:00
serversMenuContent.currentIndex = index
2024-03-25 22:30:44 +05:00
ServersModel.defaultIndex = index
}
2024-03-25 22:30:44 +05:00
MouseArea {
anchors.fill: serverRadioButton
cursorShape: Qt.PointingHandCursor
enabled: false
}
2024-04-18 17:54:55 +04:00
Keys.onTabPressed: serverInfoButton.forceActiveFocus()
Keys.onEnterPressed: serverRadioButton.clicked()
Keys.onReturnPressed: serverRadioButton.clicked()
2024-03-25 22:30:44 +05:00
}
2024-03-25 22:30:44 +05:00
ImageButtonType {
2024-04-18 17:54:55 +04:00
id: serverInfoButton
2024-03-25 22:30:44 +05:00
image: "qrc:/images/controls/settings.svg"
imageColor: AmneziaStyle.color.paleGray
2023-05-11 14:50:50 +08:00
2024-03-25 22:30:44 +05:00
implicitWidth: 56
implicitHeight: 56
2024-03-25 22:30:44 +05:00
z: 1
2023-05-15 13:38:17 +08:00
2024-04-18 17:54:55 +04:00
Keys.onTabPressed: {
if (serversMenuContent.focusItemIndex < serversMenuContent.count - 1) {
serversMenuContent.focusItemIndex++
serversMenuContent.itemAtIndex(serversMenuContent.focusItemIndex).forceActiveFocus()
} else {
focusItem1.forceActiveFocus()
serversMenuContent.contentY = 0
}
}
Keys.onEnterPressed: serverInfoButton.clicked()
Keys.onReturnPressed: serverInfoButton.clicked()
2024-03-25 22:30:44 +05:00
onClicked: function() {
ServersModel.processedIndex = index
PageController.goToPage(PageEnum.PageSettingsServerInfo)
drawer.close()
2024-02-16 15:24:06 +05:00
}
2023-05-15 13:38:17 +08:00
}
}
2024-03-25 22:30:44 +05:00
DividerType {
Layout.fillWidth: true
Layout.leftMargin: 0
Layout.rightMargin: 0
}
}
}
}
}
}
}