Files
amnezia-client/client/ui/qml/Pages/PageServerContainers.qml
T

463 lines
16 KiB
QML
Raw Normal View History

2021-07-28 16:13:29 +07:00
import QtQuick 2.12
import QtQuick.Controls 2.12
2021-10-28 15:31:54 +03:00
import QtQuick.Dialogs 1.1
2021-09-19 14:31:38 +03:00
import QtQuick.Layouts 1.15
2021-09-16 16:19:14 +03:00
import SortFilterProxyModel 0.2
import ContainerProps 1.0
import ProtocolProps 1.0
2021-09-14 00:39:07 +03:00
import PageEnum 1.0
import ProtocolEnum 1.0
2021-07-28 16:13:29 +07:00
import "./"
2021-08-19 01:27:22 +03:00
import "../Controls"
import "../Config"
2021-09-10 22:19:00 +03:00
import "InstallSettings"
2021-07-28 16:13:29 +07:00
2021-09-14 00:39:07 +03:00
PageBase {
2021-07-28 16:13:29 +07:00
id: root
2021-09-14 00:39:07 +03:00
page: PageEnum.ServerContainers
logic: ServerContainersLogic
2021-09-08 13:52:36 +03:00
enabled: ServerContainersLogic.pageEnabled
function resetPage() {
container_selector.selectedIndex = -1
}
Connections {
target: logic
function onUpdatePage() {
root.resetPage()
}
}
2021-09-08 15:09:16 +03:00
BackButton {
2021-07-28 16:13:29 +07:00
id: back
}
2021-09-08 21:24:09 +03:00
Caption {
2021-09-10 22:19:00 +03:00
id: caption
text: container_selector.selectedIndex > 0 ? qsTr("Install new service") : qsTr("Installed services")
2021-07-28 16:13:29 +07:00
}
SelectContainer {
id: container_selector
2022-02-04 17:49:48 +03:00
onAboutToHide: {
pageLoader.focus = true
}
onContainerSelected: {
var containerProto = ContainerProps.defaultProtocol(c_index)
2021-09-24 13:14:35 +03:00
if (ProtocolProps.defaultPort(containerProto) < 0) {
tf_port_num.enabled = false
tf_port_num.text = qsTr("Default")
}
else tf_port_num.text = ProtocolProps.defaultPort(containerProto)
cb_port_proto.currentIndex = ProtocolProps.defaultTransportProto(containerProto)
tf_port_num.enabled = ProtocolProps.defaultPortChangeable(containerProto)
cb_port_proto.enabled = ProtocolProps.defaultTransportProtoChangeable(containerProto)
}
}
Column {
id: c1
visible: container_selector.selectedIndex > 0
width: parent.width
2021-09-10 22:19:00 +03:00
anchors.top: caption.bottom
anchors.topMargin: 10
2021-07-28 16:13:29 +07:00
Caption {
font.pixelSize: 22
text: UiLogic.containerName(container_selector.selectedIndex)
}
Text {
width: parent.width
anchors.topMargin: 10
padding: 10
font.family: "Lato"
font.styleName: "normal"
font.pixelSize: 16
color: "#181922"
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
wrapMode: Text.Wrap
text: UiLogic.containerDesc(container_selector.selectedIndex)
}
}
Rectangle {
id: frame_settings
visible: container_selector.selectedIndex > 0
width: parent.width
anchors.top: c1.bottom
anchors.topMargin: 10
border.width: 1
border.color: "lightgray"
anchors.bottomMargin: 5
anchors.horizontalCenter: parent.horizontalCenter
radius: 2
Grid {
id: grid
visible: container_selector.selectedIndex > 0
anchors.fill: parent
columns: 2
horizontalItemAlignment: Grid.AlignHCenter
verticalItemAlignment: Grid.AlignVCenter
topPadding: 5
leftPadding: 10
spacing: 5
LabelType {
width: 130
text: qsTr("Port")
}
TextFieldType {
id: tf_port_num
width: parent.width - 130 - parent.spacing - parent.leftPadding * 2
}
LabelType {
width: 130
text: qsTr("Network Protocol")
}
ComboBoxType {
id: cb_port_proto
width: parent.width - 130 - parent.spacing - parent.leftPadding * 2
model: [
qsTr("udp"),
qsTr("tcp"),
]
}
}
}
BlueButtonType {
id: pb_cancel_add
visible: container_selector.selectedIndex > 0
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: pb_continue_add.top
anchors.bottomMargin: 20
2021-09-10 22:19:00 +03:00
width: parent.width - 40
height: 40
text: qsTr("Cancel")
2021-09-10 22:19:00 +03:00
font.pixelSize: 16
onClicked: container_selector.selectedIndex = -1
2021-07-28 16:13:29 +07:00
}
BlueButtonType {
id: pb_continue_add
visible: container_selector.selectedIndex > 0
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: parent.bottom
anchors.bottomMargin: 20
width: parent.width - 40
height: 40
text: qsTr("Continue")
font.pixelSize: 16
onClicked: {
let cont = container_selector.selectedIndex
let tp = ProtocolProps.transportProtoFromString(cb_port_proto.currentText)
let port = tf_port_num.text
ServerContainersLogic.onPushButtonContinueClicked(cont, port, tp)
}
2021-09-10 22:19:00 +03:00
}
2021-09-10 22:19:00 +03:00
Flickable {
visible: container_selector.selectedIndex <= 0
2021-07-28 16:13:29 +07:00
clip: true
2021-09-10 22:19:00 +03:00
width: parent.width
anchors.top: caption.bottom
anchors.bottom: pb_add_container.top
2021-09-10 22:19:00 +03:00
contentHeight: col.height
2021-07-28 16:13:29 +07:00
Column {
visible: container_selector.selectedIndex <= 0
2021-09-10 22:19:00 +03:00
id: col
anchors {
left: parent.left;
right: parent.right;
}
topPadding: 20
spacing: 10
2021-08-09 00:41:52 +07:00
2021-09-10 22:19:00 +03:00
Caption {
id: cap1
text: qsTr("Installed Protocols and Services")
2021-09-10 22:19:00 +03:00
font.pixelSize: 20
2021-07-28 16:13:29 +07:00
}
2021-08-09 00:41:52 +07:00
2021-09-16 16:19:14 +03:00
SortFilterProxyModel {
id: proxyContainersModel
sourceModel: UiLogic.containersModel
filters: ValueFilter {
roleName: "is_installed_role"
value: true
}
}
SortFilterProxyModel {
id: proxyProtocolsModel
sourceModel: UiLogic.protocolsModel
filters: ValueFilter {
roleName: "is_installed_role"
value: true
}
}
2021-09-10 22:19:00 +03:00
ListView {
2021-09-16 16:19:14 +03:00
id: tb_c
2021-09-10 22:19:00 +03:00
x: 10
2021-09-19 14:31:38 +03:00
width: parent.width - 10
2021-09-16 16:19:14 +03:00
height: tb_c.contentItem.height
currentIndex: -1
spacing: 5
2021-09-10 22:19:00 +03:00
clip: true
interactive: false
2021-09-16 16:19:14 +03:00
model: proxyContainersModel
2021-08-09 00:41:52 +07:00
2021-09-10 22:19:00 +03:00
delegate: Item {
2021-09-16 16:19:14 +03:00
implicitWidth: tb_c.width - 10
implicitHeight: c_item.height
2021-09-10 22:19:00 +03:00
Item {
2021-09-16 16:19:14 +03:00
id: c_item
2021-09-10 22:19:00 +03:00
width: parent.width
2021-09-19 14:31:38 +03:00
height: row_container.height + tb_p.height
2021-07-28 16:13:29 +07:00
anchors.left: parent.left
2021-09-10 22:19:00 +03:00
Rectangle {
anchors.top: parent.top
width: parent.width
height: 1
color: "lightgray"
2021-09-16 16:19:14 +03:00
visible: index !== tb_c.currentIndex
2021-08-09 00:41:52 +07:00
}
2021-09-10 22:19:00 +03:00
Rectangle {
2021-09-19 14:31:38 +03:00
anchors.top: row_container.top
anchors.bottom: row_container.bottom
2021-09-16 16:19:14 +03:00
anchors.left: parent.left
anchors.right: parent.right
2021-08-09 00:41:52 +07:00
2021-09-16 16:19:14 +03:00
color: "#63B4FB"
visible: index === tb_c.currentIndex
2021-08-09 00:41:52 +07:00
}
2021-09-10 22:19:00 +03:00
2021-09-19 14:31:38 +03:00
RowLayout {
id: row_container
//width: parent.width
2021-09-16 16:19:14 +03:00
anchors.left: parent.left
anchors.right: parent.right
2021-09-19 14:31:38 +03:00
// anchors.top: lb_container_name.top
// anchors.bottom: lb_container_name.bottom
Text {
id: lb_container_name
text: name_role
font.pixelSize: 17
//font.bold: true
color: "#100A44"
topPadding: 5
bottomPadding: 5
leftPadding: 10
verticalAlignment: Text.AlignVCenter
wrapMode: Text.WordWrap
Layout.fillWidth: true
MouseArea {
enabled: col.visible
2021-09-19 14:31:38 +03:00
anchors.top: lb_container_name.top
anchors.bottom: lb_container_name.bottom
anchors.left: parent.left
anchors.right: parent.right
propagateComposedEvents: true
onClicked: {
if (tb_c.currentIndex === index) tb_c.currentIndex = -1
else tb_c.currentIndex = index
UiLogic.protocolsModel.setSelectedDockerContainer(proxyContainersModel.mapToSource(index))
}
}
2021-09-16 16:19:14 +03:00
}
2021-09-19 14:31:38 +03:00
ImageButtonType {
2021-10-28 15:31:54 +03:00
id: button_remove
visible: index === tb_c.currentIndex
2021-09-19 14:31:38 +03:00
Layout.alignment: Qt.AlignRight
checkable: true
2021-10-28 15:31:54 +03:00
icon.source: "qrc:/images/delete.png"
2021-09-19 14:31:38 +03:00
implicitWidth: 30
implicitHeight: 30
checked: default_role
2021-10-28 15:31:54 +03:00
MessageDialog {
id: dialogRemove
standardButtons: StandardButton.Yes | StandardButton.Cancel
title: "AmneziaVPN"
text: qsTr("Remove container") + " " + name_role + "?" + "\n" + qsTr("This action will erase all data of this container on the server.")
onAccepted: {
tb_c.currentIndex = -1
ServerContainersLogic.onPushButtonRemoveClicked(proxyContainersModel.mapToSource(index))
}
2021-09-19 14:31:38 +03:00
}
2021-10-28 15:31:54 +03:00
onClicked: dialogRemove.open()
VisibleBehavior on visible { }
2021-09-19 14:31:38 +03:00
}
ImageButtonType {
id: button_share
visible: index === tb_c.currentIndex
2021-09-19 14:31:38 +03:00
Layout.alignment: Qt.AlignRight
icon.source: "qrc:/images/share.png"
implicitWidth: 30
implicitHeight: 30
onClicked: {
ServerContainersLogic.onPushButtonShareClicked(proxyContainersModel.mapToSource(index))
}
VisibleBehavior on visible { }
}
ImageButtonType {
2021-10-28 15:31:54 +03:00
id: button_default
visible: service_type_role == ProtocolEnum.Vpn
Layout.alignment: Qt.AlignRight
checkable: true
2021-10-28 15:31:54 +03:00
img.source: checked ? "qrc:/images/check.png" : "qrc:/images/uncheck.png"
implicitWidth: 30
implicitHeight: 30
checked: default_role
onClicked: {
2021-10-28 15:31:54 +03:00
ServerContainersLogic.onPushButtonDefaultClicked(proxyContainersModel.mapToSource(index))
}
2021-09-19 14:31:38 +03:00
}
2021-09-16 16:19:14 +03:00
}
2021-09-19 14:31:38 +03:00
2021-09-16 16:19:14 +03:00
ListView {
id: tb_p
currentIndex: -1
visible: index === tb_c.currentIndex
x: 10
2021-09-19 14:31:38 +03:00
anchors.top: row_container.bottom
2021-09-16 16:19:14 +03:00
width: parent.width - 40
height: visible ? tb_p.contentItem.height : 0
spacing: 0
clip: true
interactive: false
model: proxyProtocolsModel
VisibleBehavior on visible { }
2021-09-16 16:19:14 +03:00
delegate: Item {
id: dp_item
implicitWidth: tb_p.width - 10
implicitHeight: p_item.height
Item {
id: p_item
width: parent.width
height: lb_protocol_name.height
anchors.left: parent.left
Rectangle {
anchors.top: parent.top
width: parent.width
height: 1
color: "lightgray"
visible: index !== tb_p.currentIndex
}
// Rectangle {
// anchors.top: lb_protocol_name.top
// anchors.bottom: lb_protocol_name.bottom
// width: parent.width
// color: "#63B4FB"
// visible: index === tb_p.currentIndex
// }
// Text {
// id: lb_protocol_name
// text: name_role
// font.pixelSize: 16
// topPadding: 5
// bottomPadding: 5
// leftPadding: 10
// verticalAlignment: Text.AlignVCenter
// wrapMode: Text.WordWrap
// }
SettingButtonType {
id: lb_protocol_name
// anchors.top: lb_protocol_name.top
// anchors.bottom: lb_protocol_name.bottom
topPadding: 10
bottomPadding: 10
leftPadding: 10
anchors.left: parent.left
width: parent.width
height: 30
text: qsTr(name_role + " settings")
textItem.font.pixelSize: 16
icon.source: "qrc:/images/settings.png"
onClicked: {
2021-09-16 19:49:50 +03:00
tb_p.currentIndex = index
ServerContainersLogic.onPushButtonProtoSettingsClicked(
proxyContainersModel.mapToSource(tb_c.currentIndex),
proxyProtocolsModel.mapToSource(tb_p.currentIndex))
2021-09-16 16:19:14 +03:00
}
}
}
}
2021-08-09 00:41:52 +07:00
}
2021-07-28 16:13:29 +07:00
}
}
}
}
}
2021-09-10 22:19:00 +03:00
BlueButtonType {
id: pb_add_container
visible: container_selector.selectedIndex < 0
2021-09-10 22:19:00 +03:00
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: parent.bottom
anchors.topMargin: 10
anchors.bottomMargin: 20
2021-09-10 22:19:00 +03:00
width: parent.width - 40
height: 40
text: qsTr("Install new protocols container")
font.pixelSize: 16
onClicked: container_selector.visible ? container_selector.close() : container_selector.open()
2021-09-10 22:19:00 +03:00
}
2021-07-28 16:13:29 +07:00
}