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

334 lines
12 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
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 contentVisible
2023-06-13 20:03:20 +09:00
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-02-16 15:24:06 +05:00
expandedContent: Item {
implicitHeight: root.expandedHeight
2023-06-13 20:03:20 +09:00
Connections {
target: root
function onOpened() {
header.forceActiveFocus()
}
}
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
KeyNavigation.tab: shareButton
2023-07-04 09:58:19 +09:00
}
FlickableType {
anchors.top: header.bottom
2023-06-13 20:03:20 +09:00
anchors.bottom: parent.bottom
contentHeight: content.height + 32
ColumnLayout {
id: content
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
anchors.leftMargin: 16
anchors.rightMargin: 16
2024-02-16 15:24:06 +05:00
visible: root.contentVisible
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
2023-07-25 16:56:10 +09:00
text: qsTr("Share")
imageSource: "qrc:/images/controls/share-2.svg"
2023-06-13 20:03:20 +09:00
KeyNavigation.tab: copyConfigTextButton
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
defaultColor: "transparent"
hoveredColor: Qt.rgba(1, 1, 1, 0.08)
pressedColor: Qt.rgba(1, 1, 1, 0.12)
disabledColor: "#878B91"
textColor: "#D7D8DB"
borderWidth: 1
text: qsTr("Copy")
imageSource: "qrc:/images/controls/copy.svg"
KeyNavigation.tab: copyNativeConfigStringButton.visible ? copyNativeConfigStringButton : showSettingsButton
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-02-16 15:24:06 +05:00
visible: false
2023-11-25 13:02:02 +07:00
defaultColor: "transparent"
hoveredColor: Qt.rgba(1, 1, 1, 0.08)
pressedColor: Qt.rgba(1, 1, 1, 0.12)
disabledColor: "#878B91"
textColor: "#D7D8DB"
borderWidth: 1
text: qsTr("Copy config string")
imageSource: "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
2023-06-13 20:03:20 +09:00
defaultColor: "transparent"
hoveredColor: Qt.rgba(1, 1, 1, 0.08)
pressedColor: Qt.rgba(1, 1, 1, 0.12)
disabledColor: "#878B91"
textColor: "#D7D8DB"
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-02-16 15:24:06 +05:00
configContentDrawer.open()
2023-06-13 20:03:20 +09:00
}
KeyNavigation.tab: header
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-02-16 15:24:06 +05:00
expandedContent: Item {
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"))
}
}
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-02-16 15:24:06 +05:00
backButtonFunction: function() {
2024-02-23 22:51:46 +05:00
configContentDrawer.close()
}
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-02-16 15:24:06 +05:00
color: "#D7D8DB"
selectionColor: "#633303"
selectedTextColor: "#D7D8DB"
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 {
color: "transparent"
}
}
}
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
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] : ""
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
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
}
}
}
}
}