Files
amnezia-client/client/ui/qml/Components/ShareConnectionDrawer.qml
T

371 lines
13 KiB
QML
Raw Normal View History

2023-06-13 20:03:20 +09:00
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import QtQuick.Dialogs
2023-08-30 15:10:44 +05:00
import QtCore
2023-06-13 20:03:20 +09:00
import SortFilterProxyModel 0.2
import PageEnum 1.0
import ContainerProps 1.0
2024-07-07 13:42:38 +03:00
import Style 1.0
2023-06-13 20:03:20 +09:00
import "./"
import "../Controls2"
import "../Controls2/TextTypes"
2023-09-02 17:04:35 -04:00
import "../Config"
import "../Components"
2023-06-13 20:03:20 +09:00
2024-02-16 15:24:06 +05:00
DrawerType2 {
2023-06-13 20:03:20 +09:00
id: root
2024-02-16 15:24:06 +05:00
property string headerText
property string configContentHeaderText
property string shareButtonText: qsTr("Share")
property string copyButtonText: qsTr("Copy")
property bool showSettingsButtonVisible: true
2023-08-22 14:37:29 +05:00
property string configExtension: ".vpn"
property string configCaption: qsTr("Save AmneziaVPN config")
property string configFileName: "amnezia_config"
2023-08-22 14:37:29 +05:00
2024-02-16 15:24:06 +05:00
expandedHeight: parent.height * 0.9
2023-06-13 20:03:20 +09:00
onClosed: {
2023-08-22 14:37:29 +05:00
configExtension = ".vpn"
configCaption = qsTr("Save AmneziaVPN config")
configFileName = "amnezia_config"
2023-08-22 14:37:29 +05:00
}
2024-12-31 04:16:52 +01:00
expandedStateContent: Item {
2024-02-16 15:24:06 +05:00
implicitHeight: root.expandedHeight
2023-06-13 20:03:20 +09:00
2023-07-04 09:58:19 +09:00
Header2Type {
id: header
2023-06-13 20:03:20 +09:00
anchors.top: parent.top
2023-07-04 09:58:19 +09:00
anchors.left: parent.left
anchors.right: parent.right
anchors.topMargin: 20
anchors.leftMargin: 16
anchors.rightMargin: 16
2024-02-16 15:24:06 +05:00
headerText: root.headerText
2023-07-04 09:58:19 +09:00
}
2024-12-31 04:16:52 +01:00
ListView {
id: listView
2023-07-04 09:58:19 +09:00
anchors.top: header.bottom
2023-06-13 20:03:20 +09:00
anchors.bottom: parent.bottom
2024-12-31 04:16:52 +01:00
anchors.left: parent.left
anchors.right: parent.right
property bool isFocusable: true
2023-06-13 20:03:20 +09:00
2024-12-31 04:16:52 +01:00
ScrollBar.vertical: ScrollBarType {}
2023-06-13 20:03:20 +09:00
2024-12-31 04:16:52 +01:00
model: 1
2023-06-13 20:03:20 +09:00
2024-12-31 04:16:52 +01:00
clip: true
reuseItems: true
header: ColumnLayout {
width: listView.width
2023-06-13 20:03:20 +09:00
BasicButtonType {
id: shareButton
2023-06-13 20:03:20 +09:00
Layout.fillWidth: true
Layout.topMargin: 16
2024-12-31 04:16:52 +01:00
Layout.leftMargin: 16
Layout.rightMargin: 16
2023-06-13 20:03:20 +09:00
text: root.shareButtonText
leftImageSource: "qrc:/images/controls/share-2.svg"
2023-06-13 20:03:20 +09:00
clickedFunc: function() {
var fileName = ""
2023-09-02 17:04:35 -04:00
if (GC.isMobile()) {
fileName = configFileName + configExtension
2023-09-01 17:29:48 +03:00
} else {
fileName = SystemController.getFileName(configCaption,
qsTr("Config files (*" + configExtension + ")"),
StandardPaths.standardLocations(StandardPaths.DocumentsLocation) + "/" + configFileName,
true,
configExtension)
2023-09-01 17:29:48 +03:00
}
if (fileName !== "") {
PageController.showBusyIndicator(true)
ExportController.exportConfig(fileName)
PageController.showBusyIndicator(false)
2023-08-30 15:10:44 +05:00
}
2023-06-13 20:03:20 +09:00
}
}
BasicButtonType {
2024-02-16 15:24:06 +05:00
id: copyConfigTextButton
2023-06-13 20:03:20 +09:00
Layout.fillWidth: true
Layout.topMargin: 8
2024-12-31 04:16:52 +01:00
Layout.leftMargin: 16
Layout.rightMargin: 16
2023-06-13 20:03:20 +09: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.paleGray
2023-06-13 20:03:20 +09:00
borderWidth: 1
text: root.copyButtonText
leftImageSource: "qrc:/images/controls/copy.svg"
2024-04-18 17:54:55 +04:00
Keys.onReturnPressed: { copyConfigTextButton.clicked() }
Keys.onEnterPressed: { copyConfigTextButton.clicked() }
2023-06-13 20:03:20 +09:00
}
2023-11-25 13:02:02 +07:00
BasicButtonType {
2024-02-16 15:24:06 +05:00
id: copyNativeConfigStringButton
2023-11-25 13:02:02 +07:00
Layout.fillWidth: true
Layout.topMargin: 8
2024-12-31 04:16:52 +01:00
Layout.leftMargin: 16
Layout.rightMargin: 16
2023-11-25 13:02:02 +07:00
2024-02-16 15:24:06 +05:00
visible: false
2023-11-25 13:02:02 +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.paleGray
2023-11-25 13:02:02 +07:00
borderWidth: 1
text: qsTr("Copy config string")
leftImageSource: "qrc:/images/controls/copy.svg"
KeyNavigation.tab: showSettingsButton
2023-11-25 13:02:02 +07:00
}
2023-06-13 20:03:20 +09:00
BasicButtonType {
id: showSettingsButton
2023-06-13 20:03:20 +09:00
Layout.fillWidth: true
2023-10-03 23:28:44 +05:00
Layout.topMargin: 24
2024-12-31 04:16:52 +01:00
Layout.leftMargin: 16
Layout.rightMargin: 16
2023-06-13 20:03:20 +09:00
visible: root.showSettingsButtonVisible
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.paleGray
borderWidth: 1
2023-06-13 20:03:20 +09:00
2023-10-03 23:28:44 +05:00
text: qsTr("Show connection settings")
2023-06-13 20:03:20 +09:00
clickedFunc: function() {
2024-12-31 04:16:52 +01:00
configContentDrawer.openTriggered()
2023-06-13 20:03:20 +09:00
}
}
2024-02-16 15:24:06 +05:00
DrawerType2 {
id: configContentDrawer
2023-06-13 20:03:20 +09:00
2024-02-16 15:24:06 +05:00
parent: root.parent
anchors.fill: parent
expandedHeight: parent.height * 0.9
2023-06-13 20:03:20 +09:00
2024-12-31 04:16:52 +01:00
expandedStateContent: Item {
2024-02-16 15:24:06 +05:00
id: configContentContainer
2023-06-13 20:03:20 +09:00
2024-02-16 15:24:06 +05:00
implicitHeight: configContentDrawer.expandedHeight
2023-06-13 20:03:20 +09:00
2024-02-16 15:24:06 +05:00
Connections {
target: copyNativeConfigStringButton
function onClicked() {
nativeConfigString.selectAll()
nativeConfigString.copy()
nativeConfigString.select(0, 0)
PageController.showNotificationMessage(qsTr("Copied"))
}
}
2023-06-13 20:03:20 +09:00
2024-02-16 15:24:06 +05:00
Connections {
target: copyConfigTextButton
function onClicked() {
configText.selectAll()
configText.copy()
configText.select(0, 0)
PageController.showNotificationMessage(qsTr("Copied"))
2024-04-18 17:54:55 +04:00
header.forceActiveFocus()
2024-02-16 15:24:06 +05:00
}
}
2023-06-13 20:03:20 +09:00
2024-02-16 15:24:06 +05:00
BackButtonType {
id: backButton
2023-06-13 20:03:20 +09:00
2024-02-16 15:24:06 +05:00
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
anchors.topMargin: 16
2023-06-13 20:03:20 +09:00
2024-12-31 04:16:52 +01:00
backButtonFunction: function() { configContentDrawer.closeTriggered() }
2024-02-16 15:24:06 +05:00
}
2023-06-13 20:03:20 +09:00
2024-02-16 15:24:06 +05:00
FlickableType {
anchors.top: backButton.bottom
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
contentHeight: configContent.implicitHeight + configContent.anchors.topMargin + configContent.anchors.bottomMargin
ColumnLayout {
id: configContent
anchors.fill: parent
anchors.rightMargin: 16
anchors.leftMargin: 16
Header2Type {
id: configContentHeader
Layout.fillWidth: true
Layout.topMargin: 16
headerText: root.configContentHeaderText
}
TextField {
id: nativeConfigString
visible: false
text: ExportController.nativeConfigString
onTextChanged: {
copyNativeConfigStringButton.visible = nativeConfigString.text !== ""
}
}
2023-11-25 13:02:02 +07:00
2024-02-16 15:24:06 +05:00
TextArea {
id: configText
2024-02-16 15:24:06 +05:00
Layout.fillWidth: true
Layout.topMargin: 16
Layout.bottomMargin: 16
2024-02-16 15:24:06 +05:00
padding: 0
leftPadding: 0
height: 24
2023-06-13 20:03:20 +09:00
2024-02-16 15:24:06 +05:00
readOnly: true
2024-04-18 17:54:55 +04:00
activeFocusOnTab: false
color: AmneziaStyle.color.paleGray
selectionColor: AmneziaStyle.color.richBrown
selectedTextColor: AmneziaStyle.color.paleGray
2024-02-16 15:24:06 +05:00
font.pixelSize: 16
font.weight: Font.Medium
font.family: "PT Root UI VF"
2024-02-16 15:24:06 +05:00
text: ExportController.config
2024-02-16 15:24:06 +05:00
wrapMode: Text.Wrap
2024-02-16 15:24:06 +05:00
background: Rectangle {
2024-07-07 13:42:38 +03:00
color: AmneziaStyle.color.transparent
2024-02-16 15:24:06 +05:00
}
}
}
2023-06-13 20:03:20 +09:00
}
}
}
2024-12-31 04:16:52 +01:00
}
delegate: ColumnLayout {
width: listView.width
2023-06-13 20:03:20 +09:00
Rectangle {
id: qrCodeContainer
2023-06-13 20:03:20 +09:00
Layout.fillWidth: true
Layout.preferredHeight: width
Layout.topMargin: 20
2024-12-31 04:16:52 +01:00
Layout.leftMargin: 16
Layout.rightMargin: 16
2023-06-13 20:03:20 +09:00
visible: ExportController.qrCodesCount > 0
2023-06-13 20:03:20 +09:00
color: "white"
Image {
anchors.fill: parent
smooth: false
source: ExportController.qrCodesCount ? ExportController.qrCodes[0] : ""
2024-12-31 04:16:52 +01:00
property bool isFocusable: true
Keys.onTabPressed: {
FocusController.nextKeyTabItem()
}
Keys.onBacktabPressed: {
FocusController.previousKeyTabItem()
}
Keys.onUpPressed: {
FocusController.nextKeyUpItem()
}
Keys.onDownPressed: {
FocusController.nextKeyDownItem()
}
Keys.onLeftPressed: {
FocusController.nextKeyLeftItem()
}
Keys.onRightPressed: {
FocusController.nextKeyRightItem()
}
2023-06-13 20:03:20 +09:00
Timer {
property int index: 0
2023-06-13 20:03:20 +09:00
interval: 1000
running: ExportController.qrCodesCount > 0
2023-06-13 20:03:20 +09:00
repeat: true
onTriggered: {
if (ExportController.qrCodesCount > 0) {
index++
if (index >= ExportController.qrCodesCount) {
index = 0
}
parent.source = ExportController.qrCodes[index]
2023-06-13 20:03:20 +09:00
}
}
}
Behavior on source {
PropertyAnimation { duration: 200 }
}
}
}
ParagraphTextType {
Layout.fillWidth: true
Layout.topMargin: 24
Layout.bottomMargin: 32
2024-12-31 04:16:52 +01:00
Layout.leftMargin: 16
Layout.rightMargin: 16
2023-06-13 20:03:20 +09:00
visible: ExportController.qrCodesCount > 0
2023-06-13 20:03:20 +09:00
horizontalAlignment: Text.AlignHCenter
text: qsTr("To read the QR code in the Amnezia app, select \"Add server\" → \"I have data to connect\" → \"QR code, key or settings file\"")
2023-06-13 20:03:20 +09:00
}
}
}
}
}