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

491 lines
15 KiB
QML
Raw Normal View History

2023-08-08 19:10:14 +05:00
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
2023-08-30 15:10:44 +05:00
import QtQuick.Dialogs
import QtCore
2023-08-08 19:10:14 +05:00
import SortFilterProxyModel 0.2
import PageEnum 1.0
import ProtocolEnum 1.0
import ContainerProps 1.0
2024-07-07 13:42:38 +03:00
import Style 1.0
2023-08-08 19:10:14 +05:00
import "./"
import "../Controls2"
import "../Controls2/TextTypes"
import "../Config"
import "../Components"
PageType {
id: root
property var isServerFromTelegramApi: ServersModel.getDefaultServerData("isServerFromTelegramApi")
2024-02-19 19:54:15 +05:00
2024-04-06 22:29:51 +07:00
property bool pageEnabled
Component.onCompleted: {
2024-02-21 18:27:27 +07:00
if (ConnectionController.isConnected) {
PageController.showNotificationMessage(qsTr("Cannot change split tunneling settings during active connection"))
root.pageEnabled = false
} else if (ServersModel.isDefaultServerDefaultContainerHasSplitTunneling) {
PageController.showNotificationMessage(qsTr("Default server does not support split tunneling function"))
2024-02-21 18:27:27 +07:00
root.pageEnabled = false
} else {
root.pageEnabled = true
}
}
2023-08-08 19:10:14 +05:00
Connections {
target: SitesController
function onFinished(message) {
PageController.showNotificationMessage(message)
}
function onErrorOccurred(errorMessage) {
PageController.showErrorMessage(errorMessage)
}
}
QtObject {
id: routeMode
property int allSites: 0
property int onlyForwardSites: 1
property int allExceptSites: 2
}
property list<QtObject> routeModesModel: [
onlyForwardSites,
allExceptSites
]
QtObject {
id: onlyForwardSites
2024-01-30 20:35:05 +02:00
property string name: qsTr("Only the sites listed here will be accessed through the VPN")
2023-08-08 19:10:14 +05:00
property int type: routeMode.onlyForwardSites
}
QtObject {
id: allExceptSites
2023-10-12 01:15:05 +01:00
property string name: qsTr("Addresses from the list should not be accessed via VPN")
2023-08-08 19:10:14 +05:00
property int type: routeMode.allExceptSites
}
function getRouteModesModelIndex() {
var currentRouteMode = SitesModel.routeMode
if ((routeMode.onlyForwardSites === currentRouteMode) || (routeMode.allSites === currentRouteMode)) {
return 0
} else if (routeMode.allExceptSites === currentRouteMode) {
return 1
}
}
ColumnLayout {
id: header
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
2025-11-04 11:43:36 +08:00
anchors.topMargin: 20 + SettingsController.safeAreaTopMargin
2023-08-08 19:10:14 +05:00
BackButtonType {
2024-04-18 17:54:55 +04:00
id: backButton
2023-08-08 19:10:14 +05:00
}
2025-05-02 23:54:36 -07:00
HeaderTypeWithSwitcher {
Layout.fillWidth: true
Layout.leftMargin: 16
Layout.rightMargin: 16
2023-08-08 19:10:14 +05:00
2025-05-02 23:54:36 -07:00
headerText: qsTr("Split tunneling")
2024-04-18 17:54:55 +04:00
2025-05-02 23:54:36 -07:00
enabled: root.pageEnabled
showSwitcher: true
switcher {
2024-04-18 17:54:55 +04:00
checked: SitesModel.isTunnelingEnabled
2025-05-02 23:54:36 -07:00
enabled: root.pageEnabled
}
switcherFunction: function(checked) {
SitesModel.toggleSplitTunneling(checked)
selector.text = root.routeModesModel[getRouteModesModelIndex()].name
2023-08-08 19:10:14 +05:00
}
}
DropDownType {
id: selector
Layout.fillWidth: true
Layout.topMargin: 32
Layout.leftMargin: 16
Layout.rightMargin: 16
drawerHeight: 0.4375
2024-02-16 15:24:06 +05:00
drawerParent: root
2023-08-08 19:10:14 +05:00
enabled: root.pageEnabled
2023-08-08 19:10:14 +05:00
headerText: qsTr("Mode")
2023-08-16 22:45:05 +05:00
listView: ListViewWithRadioButtonType {
2023-08-08 19:10:14 +05:00
rootWidth: root.width
model: root.routeModesModel
selectedIndex: getRouteModesModelIndex()
2023-08-08 19:10:14 +05:00
clickedFunction: function() {
selector.text = selectedText
2024-12-31 04:16:52 +01:00
selector.closeTriggered()
if (SitesModel.routeMode !== root.routeModesModel[selectedIndex].type) {
SitesModel.routeMode = root.routeModesModel[selectedIndex].type
2023-08-08 19:10:14 +05:00
}
}
Component.onCompleted: {
2024-12-31 04:16:52 +01:00
if (root.routeModesModel[selectedIndex].type === SitesModel.routeMode) {
2023-08-08 19:10:14 +05:00
selector.text = selectedText
} else {
selector.text = root.routeModesModel[0].name
}
}
Connections {
target: SitesModel
function onRouteModeChanged() {
2024-12-31 04:16:52 +01:00
selectedIndex = getRouteModesModelIndex()
2023-08-08 19:10:14 +05:00
}
}
}
}
}
ListViewType {
2024-12-31 04:16:52 +01:00
id: listView
2025-09-29 05:49:19 +03:00
ScrollBar.vertical: ScrollBarType { policy: ScrollBar.AlwaysOn }
2023-08-08 19:10:14 +05:00
anchors.top: header.bottom
anchors.topMargin: 16
anchors.bottom: parent.bottom
anchors.bottomMargin: addSiteButton.implicitHeight + 48 + (searchField.textField.activeFocus ? 0 : SettingsController.imeHeight)
2023-08-08 19:10:14 +05:00
2024-12-31 04:16:52 +01:00
width: parent.width
2023-08-08 19:10:14 +05:00
2024-12-31 04:16:52 +01:00
enabled: root.pageEnabled
clip: true
2023-08-08 19:10:14 +05:00
2024-12-31 04:16:52 +01:00
model: SortFilterProxyModel {
id: proxySitesModel
sourceModel: SitesModel
filters: [
AnyOf {
RegExpFilter {
roleName: "url"
pattern: ".*" + searchField.textField.text + ".*"
caseSensitivity: Qt.CaseInsensitive
}
RegExpFilter {
roleName: "ip"
pattern: ".*" + searchField.textField.text + ".*"
caseSensitivity: Qt.CaseInsensitive
}
2024-04-01 18:45:00 +07:00
}
2024-12-31 04:16:52 +01:00
]
}
2023-08-08 19:10:14 +05:00
2024-12-31 04:16:52 +01:00
delegate: ColumnLayout {
width: listView.width
2023-08-08 19:10:14 +05:00
2024-12-31 04:16:52 +01:00
LabelWithButtonType {
id: site
Layout.fillWidth: true
text: url
descriptionText: ip
rightImageSource: "qrc:/images/controls/trash.svg"
rightImageColor: AmneziaStyle.color.paleGray
clickedFunction: function() {
var headerText = qsTr("Remove ") + url + "?"
var yesButtonText = qsTr("Continue")
var noButtonText = qsTr("Cancel")
var yesButtonFunction = function() {
SitesController.removeSite(proxySitesModel.mapToSource(index))
if (!GC.isMobile()) {
2024-04-18 17:54:55 +04:00
site.rightButton.forceActiveFocus()
}
}
2024-12-31 04:16:52 +01:00
var noButtonFunction = function() {
if (!GC.isMobile()) {
site.rightButton.forceActiveFocus()
2023-08-08 19:10:14 +05:00
}
}
2024-12-31 04:16:52 +01:00
showQuestionDrawer(headerText, "", yesButtonText, noButtonText, yesButtonFunction, noButtonFunction)
2023-08-08 19:10:14 +05:00
}
}
2024-04-18 17:54:55 +04:00
2024-12-31 04:16:52 +01:00
DividerType {}
2023-08-08 19:10:14 +05:00
}
}
Rectangle {
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
height: addSiteButton.implicitHeight + 48
color: AmneziaStyle.color.midnightBlack
RowLayout {
id: addSiteButton
enabled: root.pageEnabled
2023-08-08 19:10:14 +05:00
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.right: parent.right
anchors.topMargin: 24
anchors.rightMargin: 16
anchors.leftMargin: 16
anchors.bottomMargin: 24
2023-08-08 19:10:14 +05:00
TextFieldWithHeaderType {
id: searchField
Layout.fillWidth: true
rightButtonClickedOnEnter: true
2023-08-08 19:10:14 +05:00
textField.placeholderText: qsTr("website or IP")
buttonImageSource: "qrc:/images/controls/plus.svg"
2023-08-08 19:10:14 +05:00
clickedFunc: function() {
PageController.showBusyIndicator(true)
SitesController.addSite(textField.text)
textField.text = ""
PageController.showBusyIndicator(false)
}
2023-08-08 19:10:14 +05:00
}
ImageButtonType {
id: addSiteButtonImage
implicitWidth: 56
implicitHeight: 56
2023-08-08 19:10:14 +05:00
image: "qrc:/images/controls/more-vertical.svg"
imageColor: AmneziaStyle.color.paleGray
2023-08-08 19:10:14 +05:00
onClicked: function () {
moreActionsDrawer.openTriggered()
}
2024-04-18 17:54:55 +04:00
Keys.onReturnPressed: addSiteButtonImage.clicked()
Keys.onEnterPressed: addSiteButtonImage.clicked()
}
2023-08-08 19:10:14 +05:00
}
}
2024-02-16 15:24:06 +05:00
DrawerType2 {
2023-08-08 19:10:14 +05:00
id: moreActionsDrawer
2024-02-16 15:24:06 +05:00
anchors.fill: parent
expandedHeight: parent.height * 0.4375
2023-08-08 19:10:14 +05:00
2024-12-31 04:16:52 +01:00
expandedStateContent: ColumnLayout {
2024-02-16 15:24:06 +05:00
id: moreActionsDrawerContent
2023-08-08 19:10:14 +05:00
2024-02-16 15:24:06 +05:00
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
2023-08-08 19:10:14 +05:00
2024-02-16 15:24:06 +05:00
Header2Type {
Layout.fillWidth: true
Layout.margins: 16
2023-08-08 19:10:14 +05:00
headerText: qsTr("Additional options")
2024-02-16 15:24:06 +05:00
}
2023-08-08 19:10:14 +05:00
2024-02-16 15:24:06 +05:00
LabelWithButtonType {
2024-04-18 17:54:55 +04:00
id: importSitesButton
2024-02-16 15:24:06 +05:00
Layout.fillWidth: true
2023-08-08 19:10:14 +05:00
2024-02-16 15:24:06 +05:00
text: qsTr("Import")
rightImageSource: "qrc:/images/controls/chevron-right.svg"
2023-08-08 19:10:14 +05:00
2024-02-16 15:24:06 +05:00
clickedFunction: function() {
2024-12-31 04:16:52 +01:00
importSitesDrawer.openTriggered()
2023-08-08 19:10:14 +05:00
}
2024-02-16 15:24:06 +05:00
}
2023-08-08 19:10:14 +05:00
2024-02-16 15:24:06 +05:00
DividerType {}
LabelWithButtonType {
2024-04-18 17:54:55 +04:00
id: exportSitesButton
2024-02-16 15:24:06 +05:00
Layout.fillWidth: true
text: qsTr("Save site list")
clickedFunction: function() {
var fileName = ""
if (GC.isMobile()) {
fileName = "amnezia_sites.json"
} else {
fileName = SystemController.getFileName(qsTr("Save sites"),
qsTr("Sites files (*.json)"),
StandardPaths.standardLocations(StandardPaths.DocumentsLocation) + "/amnezia_sites",
true,
".json")
}
if (fileName !== "") {
PageController.showBusyIndicator(true)
SitesController.exportSites(fileName)
2024-12-31 04:16:52 +01:00
moreActionsDrawer.closeTriggered()
2024-02-16 15:24:06 +05:00
PageController.showBusyIndicator(false)
2023-08-08 19:10:14 +05:00
}
}
}
2024-02-16 15:24:06 +05:00
DividerType {}
LabelWithButtonType {
id: clearSitesButton
Layout.fillWidth: true
text: qsTr("Clear site list")
clickedFunction: function() {
var headerText = qsTr("Clear site list?")
var descriptionText = qsTr("All sites will be removed from list.")
var yesButtonText = qsTr("Continue")
var noButtonText = qsTr("Cancel")
var yesButtonFunction = function() {
PageController.showBusyIndicator(true)
SitesController.removeSites()
PageController.showBusyIndicator(false)
}
var noButtonFunction = function() {
}
showQuestionDrawer(headerText, descriptionText, yesButtonText, noButtonText, yesButtonFunction, noButtonFunction)
}
}
DividerType {}
2023-08-08 19:10:14 +05:00
}
}
2024-02-16 15:24:06 +05:00
DrawerType2 {
2023-08-08 19:10:14 +05:00
id: importSitesDrawer
2024-02-16 15:24:06 +05:00
anchors.fill: parent
expandedHeight: parent.height * 0.4375
2023-08-08 19:10:14 +05:00
2024-12-31 04:16:52 +01:00
expandedStateContent: Item {
2024-02-16 15:24:06 +05:00
implicitHeight: importSitesDrawer.expandedHeight
2023-08-08 19:10:14 +05:00
2024-02-16 15:24:06 +05:00
BackButtonType {
id: importSitesDrawerBackButton
2023-08-08 19:10:14 +05:00
2024-02-16 15:24:06 +05:00
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
anchors.topMargin: 16
backButtonFunction: function() {
2024-12-31 04:16:52 +01:00
importSitesDrawer.closeTriggered()
2024-02-16 15:24:06 +05:00
}
onFocusChanged: {
if (this.activeFocus) {
importSitesDrawerListView.positionViewAtBeginning()
}
}
2023-08-08 19:10:14 +05:00
}
ListViewType {
id: importSitesDrawerListView
2024-02-16 15:24:06 +05:00
anchors.top: importSitesDrawerBackButton.bottom
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
2023-08-08 19:10:14 +05:00
header: ColumnLayout {
width: importSitesDrawerListView.width
2023-08-08 19:10:14 +05:00
2024-02-16 15:24:06 +05:00
Header2Type {
Layout.fillWidth: true
Layout.margins: 16
2023-08-08 19:10:14 +05:00
2024-02-16 15:24:06 +05:00
headerText: qsTr("Import a list of sites")
}
}
model: importOptions
delegate: ColumnLayout {
width: importSitesDrawerListView.width
2023-08-08 19:10:14 +05:00
2024-02-16 15:24:06 +05:00
LabelWithButtonType {
Layout.fillWidth: true
Layout.leftMargin: 16
Layout.rightMargin: 16
2023-08-08 19:10:14 +05:00
text: title
2023-08-08 19:10:14 +05:00
2024-02-16 15:24:06 +05:00
clickedFunction: function() {
clickedHandler()
}
2023-08-08 19:10:14 +05:00
}
2024-02-16 15:24:06 +05:00
DividerType {}
}
}
}
}
2023-08-08 19:10:14 +05:00
property list<QtObject> importOptions: [
replaceOption,
addOption,
]
2023-09-06 22:20:59 +05:00
QtObject {
id: replaceOption
readonly property string title: qsTr("Replace site list")
readonly property var clickedHandler: function() {
var fileName = SystemController.getFileName(qsTr("Open sites file"),
qsTr("Sites files (*.json)"))
if (fileName !== "") {
root.importSites(fileName, true)
}
}
}
QtObject {
id: addOption
readonly property string title: qsTr("Add imported sites to existing ones")
readonly property var clickedHandler: function() {
var fileName = SystemController.getFileName(qsTr("Open sites file"),
qsTr("Sites files (*.json)"))
if (fileName !== "") {
root.importSites(fileName, false)
2023-08-08 19:10:14 +05:00
}
}
}
function importSites(fileName, replaceExistingSites) {
PageController.showBusyIndicator(true)
SitesController.importSites(fileName, replaceExistingSites)
PageController.showBusyIndicator(false)
importSitesDrawer.closeTriggered()
moreActionsDrawer.closeTriggered()
}
2023-08-08 19:10:14 +05:00
}