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

346 lines
11 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
import "./"
import "../Controls2"
import "../Controls2/TextTypes"
import "../Config"
import "../Components"
PageType {
id: root
property string defaultColor: "#1C1D21"
property string borderColor: "#2C2D30"
property string defaultServerName: ServersModel.defaultServerName
property string defaultServerHostName: ServersModel.defaultServerHostName
property string defaultContainerName: ContainersModel.defaultContainerName
2023-09-06 13:37:37 +05:00
Item {
anchors.top: parent.top
anchors.bottom: buttonBackground.top
anchors.right: parent.right
anchors.left: parent.left
2023-09-06 13:37:37 +05:00
ConnectButton {
anchors.centerIn: parent
}
}
2023-06-01 11:25:33 +08:00
Connections {
target: PageController
function onRestorePageHomeState(isContainerInstalled) {
menu.visible = true
if (isContainerInstalled) {
containersDropDown.menuVisible = true
}
}
}
Rectangle {
id: buttonBackground
anchors.fill: buttonContent
radius: 16
color: root.defaultColor
border.color: root.borderColor
border.width: 1
Rectangle {
width: parent.radius
height: parent.radius
anchors.bottom: parent.bottom
anchors.right: parent.right
anchors.left: parent.left
color: parent.color
}
}
ColumnLayout {
id: buttonContent
anchors.right: parent.right
anchors.left: parent.left
anchors.bottom: parent.bottom
RowLayout {
Layout.topMargin: 24
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
2023-08-26 10:08:50 +03:00
spacing: 0
Header1TextType {
text: root.defaultServerName
}
Image {
Layout.preferredWidth: 18
Layout.preferredHeight: 18
2023-08-26 10:08:50 +03:00
Layout.leftMargin: 12
source: "qrc:/images/controls/chevron-down.svg"
}
}
LabelTextType {
Layout.bottomMargin: 44
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
text: {
var description = ""
if (ServersModel.isDefaultServerHasWriteAccess()) {
if (SettingsController.isAmneziaDnsEnabled()
&& ContainersModel.isAmneziaDnsContainerInstalled(ServersModel.getDefaultServerIndex())) {
description += "Amnezia DNS | "
}
} else {
2023-07-14 13:14:50 +09:00
if (ServersModel.isDefaultServerConfigContainsAmneziaDns()) {
description += "Amnezia DNS | "
}
}
description += root.defaultContainerName + " | " + root.defaultServerHostName
return description
}
}
}
MouseArea {
anchors.fill: buttonBackground
cursorShape: Qt.PointingHandCursor
hoverEnabled: true
onClicked: {
menu.visible = true
}
}
2023-06-01 11:25:33 +08:00
DrawerType {
id: menu
2023-09-06 13:37:37 +05:00
interactive: true
dragMargin: buttonBackground.height + 56 // page start tabBar height
width: parent.width
2023-06-13 20:03:20 +09:00
height: parent.height * 0.9
ColumnLayout {
id: serversMenuHeader
anchors.top: parent.top
anchors.right: parent.right
anchors.left: parent.left
Header1TextType {
Layout.topMargin: 24
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
text: root.defaultServerName
}
LabelTextType {
Layout.bottomMargin: 24
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
text: root.defaultServerHostName
}
RowLayout {
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
spacing: 8
DropDownType {
id: containersDropDown
2023-05-11 14:50:50 +08:00
rootButtonImageColor: "#0E0E11"
rootButtonBackgroundColor: "#D7D8DB"
2023-08-08 19:10:14 +05:00
rootButtonHoveredBorderColor: "transparent"
rootButtonPressedBorderColor: "transparent"
2023-08-26 10:08:50 +03:00
rootButtonTextTopMargin: 8
rootButtonTextBottomMargin: 8
text: root.defaultContainerName
textColor: "#0E0E11"
headerText: qsTr("VPN protocol")
2023-05-11 14:50:50 +08:00
headerBackButtonImage: "qrc:/images/controls/arrow-left.svg"
rootButtonClickedFunction: function() {
ServersModel.currentlyProcessedIndex = serversMenuContent.currentIndex
containersDropDown.menuVisible = true
}
2023-06-01 11:25:33 +08:00
listView: HomeContainersListView {
rootWidth: root.width
2023-05-11 14:50:50 +08:00
Connections {
target: ServersModel
function onCurrentlyProcessedServerIndexChanged() {
updateContainersModelFilters()
}
}
function updateContainersModelFilters() {
if (ServersModel.isCurrentlyProcessedServerHasWriteAccess()) {
proxyContainersModel.filters = ContainersModelFilters.getWriteAccessProtocolsListFilters()
} else {
proxyContainersModel.filters = ContainersModelFilters.getReadAccessProtocolsListFilters()
}
}
model: SortFilterProxyModel {
id: proxyContainersModel
sourceModel: ContainersModel
}
Component.onCompleted: updateContainersModelFilters()
currentIndex: ContainersModel.getDefaultContainer()
2023-05-11 14:50:50 +08:00
}
}
}
Header2Type {
2023-05-11 14:50:50 +08:00
Layout.fillWidth: true
Layout.topMargin: 48
Layout.leftMargin: 16
Layout.rightMargin: 16
2023-05-11 14:50:50 +08:00
actionButtonImage: "qrc:/images/controls/plus.svg"
headerText: qsTr("Servers")
actionButtonFunction: function() {
menu.visible = false
connectionTypeSelection.visible = true
}
}
ConnectionTypeSelectionDrawer {
id: connectionTypeSelection
}
}
FlickableType {
anchors.top: serversMenuHeader.bottom
anchors.topMargin: 16
contentHeight: col.implicitHeight
Column {
id: col
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
spacing: 16
ButtonGroup {
id: serversRadioButtonGroup
}
ListView {
id: serversMenuContent
width: parent.width
height: serversMenuContent.contentItem.height
model: ServersModel
currentIndex: ServersModel.defaultIndex
clip: true
interactive: false
delegate: Item {
id: menuContentDelegate
property variant delegateData: model
implicitWidth: serversMenuContent.width
2023-06-01 11:25:33 +08:00
implicitHeight: serverRadioButtonContent.implicitHeight
2023-06-01 11:25:33 +08:00
ColumnLayout {
id: serverRadioButtonContent
2023-06-13 20:03:20 +09:00
anchors.fill: parent
2023-06-01 11:25:33 +08:00
anchors.rightMargin: 16
anchors.leftMargin: 16
2023-06-01 11:25:33 +08:00
spacing: 0
RowLayout {
2023-06-01 11:25:33 +08:00
VerticalRadioButton {
id: serverRadioButton
2023-06-01 11:25:33 +08:00
Layout.fillWidth: true
2023-06-01 11:25:33 +08:00
text: name
descriptionText: {
var description = ""
if (hasWriteAccess) {
if (SettingsController.isAmneziaDnsEnabled()
&& ContainersModel.isAmneziaDnsContainerInstalled(index)) {
description += "AmneziaDNS | "
}
} else {
if (containsAmneziaDns) {
description += "AmneziaDNS | "
}
}
return description += hostName
}
2023-06-01 11:25:33 +08:00
checked: index === serversMenuContent.currentIndex
2023-06-01 11:25:33 +08:00
ButtonGroup.group: serversRadioButtonGroup
2023-06-01 11:25:33 +08:00
onClicked: {
serversMenuContent.currentIndex = index
ServersModel.currentlyProcessedIndex = index
ServersModel.defaultIndex = index
2023-06-01 11:25:33 +08:00
}
2023-06-01 11:25:33 +08:00
MouseArea {
anchors.fill: serverRadioButton
cursorShape: Qt.PointingHandCursor
enabled: false
}
}
ImageButtonType {
image: "qrc:/images/controls/settings.svg"
2023-08-26 10:08:50 +03:00
imageColor: "#D7D8DB"
2023-06-01 11:25:33 +08:00
implicitWidth: 56
implicitHeight: 56
2023-05-11 14:50:50 +08:00
2023-06-01 11:25:33 +08:00
z: 1
2023-06-01 11:25:33 +08:00
onClicked: function() {
ServersModel.currentlyProcessedIndex = index
2023-09-06 13:37:37 +05:00
PageController.goToPage(PageEnum.PageSettingsServerInfo)
2023-06-01 11:25:33 +08:00
menu.visible = false
}
}
2023-05-11 14:50:50 +08:00
}
2023-05-15 13:38:17 +08:00
2023-06-01 11:25:33 +08:00
DividerType {
Layout.fillWidth: true
2023-05-15 13:38:17 +08:00
}
}
}
}
}
}
}
}