2023-05-06 06:52:23 +03:00
import QtQuick
2023-06-13 20:03:20 +09:00
import QtQuick . Controls
import QtQuick . Layouts
import QtQuick . Dialogs
2023-05-06 06:52:23 +03:00
2023-06-13 20:03:20 +09:00
import SortFilterProxyModel 0.2
2023-05-06 06:52:23 +03:00
2023-06-13 20:03:20 +09:00
import PageEnum 1.0
import ContainerProps 1.0
import "./"
import "../Controls2"
import "../Controls2/TextTypes"
import "../Components"
PageType {
id: root
2023-07-05 10:15:38 +09:00
enum ConfigType {
AmneziaConnection ,
2023-07-24 16:31:04 +09:00
AmneziaFullAccess ,
2023-07-05 10:15:38 +09:00
OpenVpn ,
WireGuard
}
2023-06-13 20:03:20 +09:00
Connections {
target: ExportController
2023-07-05 10:15:38 +09:00
function onGenerateConfig ( type ) {
2023-09-16 08:05:43 +08:00
shareConnectionDrawer . needCloseButton = false
2023-07-04 09:58:19 +09:00
shareConnectionDrawer . open ( )
shareConnectionDrawer . contentVisible = false
PageController . showBusyIndicator ( true )
2023-07-05 10:15:38 +09:00
switch ( type ) {
case PageShare.ConfigType.AmneziaConnection: ExportController . generateConnectionConfig ( ) ; break ;
2023-07-24 16:31:04 +09:00
case PageShare.ConfigType.AmneziaFullAccess: {
if ( Qt . platform . os === "android" ) {
ExportController . generateFullAccessConfigAndroid ( ) ;
} else {
ExportController . generateFullAccessConfig ( ) ;
}
break ;
}
2023-08-22 14:37:29 +05:00
case PageShare.ConfigType.OpenVpn: {
ExportController . generateOpenVpnConfig ( ) ;
shareConnectionDrawer . configCaption = qsTr ( "Save OpenVPN config" )
shareConnectionDrawer . configExtension = ".ovpn"
shareConnectionDrawer . configFileName = "amnezia_for_openvpn"
break ;
}
case PageShare.ConfigType.WireGuard: {
ExportController . generateWireGuardConfig ( ) ;
shareConnectionDrawer . configCaption = qsTr ( "Save WireGuard config" )
shareConnectionDrawer . configExtension = ".conf"
shareConnectionDrawer . configFileName = "amnezia_for_wireguard"
break ;
}
2023-06-13 20:03:20 +09:00
}
2023-07-05 10:15:38 +09:00
2023-07-04 09:58:19 +09:00
PageController . showBusyIndicator ( false )
2023-09-16 08:05:43 +08:00
shareConnectionDrawer . needCloseButton = true
PageController . showTopCloseButton ( true )
2023-07-04 09:58:19 +09:00
shareConnectionDrawer . contentVisible = true
}
function onExportErrorOccurred ( errorMessage ) {
shareConnectionDrawer . close ( )
PageController . showErrorMessage ( errorMessage )
2023-06-13 20:03:20 +09:00
}
}
2023-07-24 16:31:04 +09:00
property string fullConfigServerSelectorText
property string connectionServerSelectorText
2023-06-13 20:03:20 +09:00
property bool showContent: false
2023-07-31 00:13:08 +09:00
property bool shareButtonEnabled: true
2023-06-13 20:03:20 +09:00
property list < QtObject > connectionTypesModel: [
amneziaConnectionFormat
]
QtObject {
id: amneziaConnectionFormat
2023-07-31 12:54:59 +09:00
property string name: qsTr ( "For the AmneziaVPN app" )
2023-07-05 10:15:38 +09:00
property var type: PageShare . ConfigType . AmneziaConnection
2023-06-13 20:03:20 +09:00
}
QtObject {
id: openVpnConnectionFormat
property string name: qsTr ( "OpenVpn native format" )
2023-07-05 10:15:38 +09:00
property var type: PageShare . ConfigType . OpenVpn
2023-06-13 20:03:20 +09:00
}
QtObject {
id: wireGuardConnectionFormat
property string name: qsTr ( "WireGuard native format" )
2023-07-05 10:15:38 +09:00
property var type: PageShare . ConfigType . WireGuard
2023-06-13 20:03:20 +09:00
}
FlickableType {
2023-06-20 10:25:24 +09:00
anchors.top: parent . top
anchors.bottom: parent . bottom
2023-06-13 20:03:20 +09:00
contentHeight: content . height
ColumnLayout {
id: content
anchors.top: parent . top
anchors.left: parent . left
anchors.right: parent . right
anchors.rightMargin: 16
anchors.leftMargin: 16
2023-08-26 10:08:50 +03:00
spacing: 0
2023-06-13 20:03:20 +09:00
HeaderType {
Layout.fillWidth: true
2023-08-26 10:08:50 +03:00
Layout.topMargin: 24
2023-06-13 20:03:20 +09:00
headerText: qsTr ( "VPN Access" )
}
Rectangle {
id: accessTypeSelector
property int currentIndex
Layout.topMargin: 32
implicitWidth: accessTypeSelectorContent . implicitWidth
implicitHeight: accessTypeSelectorContent . implicitHeight
color: "#1C1D21"
radius: 16
RowLayout {
id: accessTypeSelectorContent
spacing: 0
HorizontalRadioButton {
checked: accessTypeSelector . currentIndex === 0
implicitWidth: ( root . width - 32 ) / 2
text: qsTr ( "Connection" )
onClicked: {
accessTypeSelector . currentIndex = 0
2023-07-24 16:31:04 +09:00
serverSelector . text = root . connectionServerSelectorText
2023-06-13 20:03:20 +09:00
}
}
HorizontalRadioButton {
checked: root . currentIndex === 1
implicitWidth: ( root . width - 32 ) / 2
2023-07-31 12:54:59 +09:00
text: qsTr ( "Full access" )
2023-06-13 20:03:20 +09:00
onClicked: {
accessTypeSelector . currentIndex = 1
2023-07-24 16:31:04 +09:00
serverSelector . text = root . fullConfigServerSelectorText
2023-07-31 00:13:08 +09:00
root . shareButtonEnabled = true
2023-06-13 20:03:20 +09:00
}
}
}
}
ParagraphTextType {
Layout.fillWidth: true
2023-06-20 10:25:24 +09:00
Layout.topMargin: 24
2023-08-26 10:08:50 +03:00
Layout.bottomMargin: 24
2023-06-13 20:03:20 +09:00
2023-06-16 13:43:55 +09:00
text: accessTypeSelector . currentIndex === 0 ? qsTr ( "VPN access without the ability to manage the server" ) :
2023-10-14 18:21:49 +05:00
qsTr ( "Access to server management. The user with whom you share full access to the connection will be able to add and remove your protocols and services to the server, as well as change settings." )
2023-06-13 20:03:20 +09:00
color: "#878B91"
}
DropDownType {
id: serverSelector
2023-09-17 15:01:31 +05:00
signal severSelectorIndexChanged
property int currentIndex: 0
2023-06-13 20:03:20 +09:00
Layout.fillWidth: true
2023-08-26 10:08:50 +03:00
Layout.topMargin: 16
2023-06-13 20:03:20 +09:00
drawerHeight: 0.4375
2023-10-09 22:39:32 +05:00
descriptionText: qsTr ( "Server" )
2023-06-13 20:03:20 +09:00
headerText: qsTr ( "Server" )
2023-09-17 15:01:31 +05:00
listView: ListViewWithRadioButtonType {
id: serverSelectorListView
2023-06-13 20:03:20 +09:00
2023-09-17 15:01:31 +05:00
rootWidth: root . width
imageSource: "qrc:/images/controls/check.svg"
2023-06-13 20:03:20 +09:00
2023-06-23 15:24:40 +09:00
model: SortFilterProxyModel {
id: proxyServersModel
sourceModel: ServersModel
filters: [
ValueFilter {
roleName: "hasWriteAccess"
value: true
}
]
}
currentIndex: 0
2023-06-13 20:03:20 +09:00
clickedFunction: function ( ) {
2023-07-24 16:31:04 +09:00
handler ( )
2023-09-17 15:01:31 +05:00
if ( serverSelector . currentIndex !== serverSelectorListView . currentIndex ) {
serverSelector . currentIndex = serverSelectorListView . currentIndex
serverSelector . severSelectorIndexChanged ( )
}
if ( accessTypeSelector . currentIndex !== 0 ) {
2023-07-31 12:54:59 +09:00
shareConnectionDrawer . headerText = qsTr ( "Accessing " ) + serverSelector . text
2023-10-02 22:04:18 +05:00
shareConnectionDrawer . configContentHeaderText = qsTr ( "File with accessing settings to " ) + serverSelector . text
2023-07-24 16:31:04 +09:00
}
2023-09-17 15:01:31 +05:00
serverSelector . menuVisible = false
2023-06-13 20:03:20 +09:00
}
Component.onCompleted: {
2023-07-24 16:31:04 +09:00
handler ( )
2023-10-02 22:04:18 +05:00
serverSelector . severSelectorIndexChanged ( )
2023-07-24 16:31:04 +09:00
}
function handler ( ) {
2023-06-13 20:03:20 +09:00
serverSelector . text = selectedText
2023-07-24 16:31:04 +09:00
root . fullConfigServerSelectorText = selectedText
root . connectionServerSelectorText = selectedText
2023-08-02 21:46:02 +09:00
ServersModel . currentlyProcessedIndex = proxyServersModel . mapToSource ( currentIndex )
2023-06-13 20:03:20 +09:00
}
}
2023-09-17 15:01:31 +05:00
}
DropDownType {
id: protocolSelector
2023-06-13 20:03:20 +09:00
2023-10-02 22:04:18 +05:00
visible: accessTypeSelector . currentIndex === 0
2023-09-17 15:01:31 +05:00
Layout.fillWidth: true
Layout.topMargin: 16
drawerHeight: 0.5
2023-06-13 20:03:20 +09:00
2023-10-03 23:28:44 +05:00
descriptionText: qsTr ( "Protocol" )
2023-09-17 15:01:31 +05:00
headerText: qsTr ( "Protocol" )
2023-06-13 20:03:20 +09:00
2023-09-17 15:01:31 +05:00
listView: ListViewWithRadioButtonType {
id: protocolSelectorListView
2023-06-13 20:03:20 +09:00
2023-09-17 15:01:31 +05:00
rootWidth: root . width
imageSource: "qrc:/images/controls/check.svg"
2023-06-13 20:03:20 +09:00
2023-09-17 15:01:31 +05:00
model: SortFilterProxyModel {
id: proxyContainersModel
sourceModel: ContainersModel
filters: [
ValueFilter {
roleName: "isInstalled"
value: true
} ,
ValueFilter {
roleName: "isShareable"
value: true
2023-06-13 20:03:20 +09:00
}
2023-09-17 15:01:31 +05:00
]
}
currentIndex: 0
clickedFunction: function ( ) {
handler ( )
protocolSelector . menuVisible = false
}
Component.onCompleted: {
if ( accessTypeSelector . currentIndex === 0 ) {
handler ( )
2023-06-13 20:03:20 +09:00
}
}
2023-09-17 15:01:31 +05:00
Connections {
target: serverSelector
2023-06-13 20:03:20 +09:00
2023-09-17 15:01:31 +05:00
function onSeverSelectorIndexChanged ( ) {
protocolSelectorListView . currentIndex = 0
protocolSelectorListView . triggerCurrentItem ( )
}
}
2023-06-13 20:03:20 +09:00
2023-09-17 15:01:31 +05:00
function handler ( ) {
if ( ! proxyContainersModel . count ) {
root . shareButtonEnabled = false
return
} else {
root . shareButtonEnabled = true
}
2023-06-13 20:03:20 +09:00
2023-09-17 15:01:31 +05:00
protocolSelector . text = selectedText
root . connectionServerSelectorText = serverSelector . text
2023-06-13 20:03:20 +09:00
2023-09-17 15:01:31 +05:00
shareConnectionDrawer . headerText = qsTr ( "Connection to " ) + serverSelector . text
shareConnectionDrawer . configContentHeaderText = qsTr ( "File with connection settings to " ) + serverSelector . text
ContainersModel . setCurrentlyProcessedContainerIndex ( proxyContainersModel . mapToSource ( currentIndex ) )
2023-06-13 20:03:20 +09:00
2023-09-17 15:01:31 +05:00
fillConnectionTypeModel ( )
}
function fillConnectionTypeModel ( ) {
root . connectionTypesModel = [ amneziaConnectionFormat ]
var index = proxyContainersModel . mapToSource ( currentIndex )
if ( index === ContainerProps . containerFromString ( "amnezia-openvpn" ) ) {
root . connectionTypesModel . push ( openVpnConnectionFormat )
2023-10-16 13:43:27 +05:00
} else if ( index === ContainerProps . containerFromString ( "amnezia-wireguard" ) ) {
2023-09-17 15:01:31 +05:00
root . connectionTypesModel . push ( wireGuardConnectionFormat )
2023-06-13 20:03:20 +09:00
}
}
}
}
DropDownType {
2023-06-23 15:24:40 +09:00
id: exportTypeSelector
2023-06-13 20:03:20 +09:00
2023-08-16 12:11:34 +05:00
property int currentIndex: 0
2023-06-13 20:03:20 +09:00
Layout.fillWidth: true
Layout.topMargin: 16
drawerHeight: 0.4375
visible: accessTypeSelector . currentIndex === 0
2023-06-27 19:07:42 +09:00
enabled: root . connectionTypesModel . length > 1
2023-06-13 20:03:20 +09:00
descriptionText: qsTr ( "Connection format" )
headerText: qsTr ( "Connection format" )
2023-08-16 22:45:05 +05:00
listView: ListViewWithRadioButtonType {
2023-08-19 13:12:54 +05:00
onCurrentIndexChanged: {
exportTypeSelector . currentIndex = currentIndex
exportTypeSelector . text = selectedText
}
2023-08-16 12:11:34 +05:00
2023-06-13 20:03:20 +09:00
rootWidth: root . width
2023-08-19 13:12:54 +05:00
imageSource: "qrc:/images/controls/check.svg"
2023-06-13 20:03:20 +09:00
2023-06-27 19:07:42 +09:00
model: root . connectionTypesModel
2023-08-19 13:12:54 +05:00
currentIndex: 0
2023-06-13 20:03:20 +09:00
clickedFunction: function ( ) {
2023-06-23 15:24:40 +09:00
exportTypeSelector . text = selectedText
exportTypeSelector . currentIndex = currentIndex
exportTypeSelector . menuVisible = false
2023-06-13 20:03:20 +09:00
}
Component.onCompleted: {
2023-06-23 15:24:40 +09:00
exportTypeSelector . text = selectedText
exportTypeSelector . currentIndex = currentIndex
2023-06-13 20:03:20 +09:00
}
}
}
ShareConnectionDrawer {
id: shareConnectionDrawer
}
BasicButtonType {
Layout.fillWidth: true
2023-08-26 10:08:50 +03:00
Layout.topMargin: 40
2023-06-13 20:03:20 +09:00
2023-07-13 11:29:26 +09:00
enabled: shareButtonEnabled
2023-06-13 20:03:20 +09:00
text: qsTr ( "Share" )
2023-08-16 12:11:34 +05:00
imageSource: "qrc:/images/controls/share-2.svg"
2023-06-13 20:03:20 +09:00
onClicked: {
if ( accessTypeSelector . currentIndex === 0 ) {
2023-07-05 10:15:38 +09:00
ExportController . generateConfig ( root . connectionTypesModel [ exportTypeSelector . currentIndex ] . type )
2023-06-13 20:03:20 +09:00
} else {
2023-07-05 10:15:38 +09:00
ExportController . generateConfig ( PageShare . ConfigType . AmneziaFullAccess )
2023-06-13 20:03:20 +09:00
}
}
}
}
}
2023-05-06 06:52:23 +03:00
}