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

308 lines
9.8 KiB
QML
Raw Normal View History

2023-06-01 11:25:33 +08:00
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import SortFilterProxyModel 0.2
import PageEnum 1.0
import ProtocolEnum 1.0
import ContainerProps 1.0
import ProtocolProps 1.0
2024-07-07 13:42:38 +03:00
import Style 1.0
2023-06-01 11:25:33 +08:00
import "./"
import "../Controls2"
import "../Controls2/TextTypes"
import "../Config"
import "../Components"
PageType {
id: root
property int pageSettingsServerProtocols: 0
property int pageSettingsServerServices: 1
property int pageSettingsServerData: 2
property int pageSettingsApiServerInfo: 3
property int pageSettingsApiLanguageList: 4
property var processedServer
2024-04-18 17:54:55 +04:00
defaultActiveFocusItem: focusItem
Connections {
target: PageController
function onGoToPageSettingsServerServices() {
tabBar.currentIndex = root.pageSettingsServerServices
}
}
Connections {
target: ServersModel
function onProcessedServerChanged() {
root.processedServer = proxyServersModel.get(0)
}
}
2023-06-01 11:25:33 +08:00
SortFilterProxyModel {
id: proxyServersModel
objectName: "proxyServersModel"
2023-06-01 11:25:33 +08:00
sourceModel: ServersModel
filters: [
ValueFilter {
roleName: "isCurrentlyProcessed"
value: true
}
]
Component.onCompleted: {
root.processedServer = proxyServersModel.get(0)
}
2023-06-01 11:25:33 +08:00
}
2024-04-18 17:54:55 +04:00
Item {
id: focusItem
//KeyNavigation.tab: header
2024-04-18 17:54:55 +04:00
}
2023-06-01 11:25:33 +08:00
ColumnLayout {
anchors.fill: parent
spacing: 4
2024-04-18 17:54:55 +04:00
BackButtonType {
id: backButton
2024-04-18 17:54:55 +04:00
Layout.topMargin: 20
KeyNavigation.tab: headerContent.actionButton
2024-04-18 17:54:55 +04:00
backButtonFunction: function() {
if (nestedStackView.currentIndex === root.pageSettingsApiServerInfo &&
root.processedServer.isCountrySelectionAvailable) {
nestedStackView.currentIndex = root.pageSettingsApiLanguageList
} else {
PageController.closePage()
}
}
}
2023-06-05 15:49:10 +08:00
HeaderType {
id: headerContent
Layout.fillWidth: true
Layout.leftMargin: 16
Layout.rightMargin: 16
2023-06-01 11:25:33 +08:00
actionButtonImage: nestedStackView.currentIndex === root.pageSettingsApiLanguageList ? "qrc:/images/controls/settings.svg"
: "qrc:/images/controls/edit-3.svg"
headerText: root.processedServer.name
descriptionText: {
if (root.processedServer.isServerFromGatewayApi) {
if (nestedStackView.currentIndex === root.pageSettingsApiLanguageList) {
return qsTr("Subscription is valid until ") + ApiServicesModel.getSelectedServiceData("endDate")
} else {
return ApiServicesModel.getSelectedServiceData("serviceDescription")
}
} else if (root.processedServer.isServerFromTelegramApi) {
return root.processedServer.serverDescription
} else if (root.processedServer.hasWriteAccess) {
return root.processedServer.credentialsLogin + " · " + root.processedServer.hostName
} else {
return root.processedServer.hostName
2023-06-05 15:49:10 +08:00
}
}
2023-06-05 15:49:10 +08:00
KeyNavigation.tab: tabBar
2024-04-18 17:54:55 +04:00
actionButtonFunction: function() {
if (nestedStackView.currentIndex === root.pageSettingsApiLanguageList) {
nestedStackView.currentIndex = root.pageSettingsApiServerInfo
} else {
serverNameEditDrawer.open()
}
}
}
DrawerType2 {
id: serverNameEditDrawer
parent: root
anchors.fill: parent
expandedHeight: root.height * 0.35
onClosed: {
if (!GC.isMobile()) {
headerContent.actionButton.forceActiveFocus()
}
}
2024-04-18 17:54:55 +04:00
expandedContent: ColumnLayout {
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
anchors.topMargin: 32
anchors.leftMargin: 16
anchors.rightMargin: 16
Connections {
target: serverNameEditDrawer
enabled: !GC.isMobile()
function onOpened() {
serverName.textField.forceActiveFocus()
}
}
2024-02-16 15:24:06 +05:00
Item {
id: focusItem1
KeyNavigation.tab: serverName.textField
}
2024-04-18 17:54:55 +04:00
TextFieldWithHeaderType {
id: serverName
Layout.fillWidth: true
headerText: qsTr("Server name")
textFieldText: root.processedServer.name
textField.maximumLength: 30
checkEmptyText: true
KeyNavigation.tab: saveButton
}
BasicButtonType {
id: saveButton
Layout.fillWidth: true
text: qsTr("Save")
KeyNavigation.tab: focusItem1
clickedFunc: function() {
if (serverName.textFieldText === "") {
return
}
if (serverName.textFieldText !== root.processedServer.name) {
ServersModel.setProcessedServerData("name", serverName.textFieldText);
}
serverNameEditDrawer.close()
2023-06-05 15:49:10 +08:00
}
2023-06-01 11:25:33 +08:00
}
}
}
TabBar {
id: tabBar
Layout.fillWidth: true
currentIndex: (ServersModel.getProcessedServerData("isServerFromTelegramApi")
&& !ServersModel.getProcessedServerData("hasInstalledContainers")) ?
root.pageSettingsServerData : root.pageSettingsServerProtocols
2023-06-01 11:25:33 +08:00
background: Rectangle {
2024-07-07 13:42:38 +03:00
color: AmneziaStyle.color.transparent
2023-06-01 11:25:33 +08:00
}
visible: !ServersModel.getProcessedServerData("isServerFromGatewayApi")
2024-04-18 17:54:55 +04:00
activeFocusOnTab: true
onFocusChanged: {
if (activeFocus) {
protocolsTab.forceActiveFocus()
}
}
2023-06-01 11:25:33 +08:00
TabButtonType {
2024-04-18 17:54:55 +04:00
id: protocolsTab
visible: protocolsPage.installedProtocolsCount
width: protocolsPage.installedProtocolsCount ? undefined : 0
isSelected: tabBar.currentIndex === root.pageSettingsServerProtocols
2023-06-01 11:25:33 +08:00
text: qsTr("Protocols")
2024-04-18 17:54:55 +04:00
KeyNavigation.tab: servicesTab
Keys.onReturnPressed: tabBar.currentIndex = root.pageSettingsServerProtocols
Keys.onEnterPressed: tabBar.currentIndex = root.pageSettingsServerProtocols
2023-06-01 11:25:33 +08:00
}
2023-06-01 11:25:33 +08:00
TabButtonType {
2024-04-18 17:54:55 +04:00
id: servicesTab
visible: servicesPage.installedServicesCount
width: servicesPage.installedServicesCount ? undefined : 0
isSelected: tabBar.currentIndex === root.pageSettingsServerServices
2023-06-01 11:25:33 +08:00
text: qsTr("Services")
2024-04-18 17:54:55 +04:00
KeyNavigation.tab: dataTab
Keys.onReturnPressed: tabBar.currentIndex = root.pageSettingsServerServices
Keys.onEnterPressed: tabBar.currentIndex = root.pageSettingsServerServices
2023-06-01 11:25:33 +08:00
}
2023-06-01 11:25:33 +08:00
TabButtonType {
2024-04-18 17:54:55 +04:00
id: dataTab
isSelected: tabBar.currentIndex === root.pageSettingsServerData
2024-03-26 20:05:04 +02:00
text: qsTr("Management")
2024-04-18 17:54:55 +04:00
Keys.onReturnPressed: tabBar.currentIndex = root.pageSettingsServerData
Keys.onEnterPressed: tabBar.currentIndex = root.pageSettingsServerData
Keys.onTabPressed: function() {
if (nestedStackView.currentIndex === root.pageSettingsServerProtocols) {
return protocolsPage
} else if (nestedStackView.currentIndex === root.pageSettingsServerProtocols) {
return servicesPage
} else {
return dataPage
}
}
2023-06-01 11:25:33 +08:00
}
}
StackLayout {
id: nestedStackView
Layout.fillWidth: true
2023-06-01 11:25:33 +08:00
currentIndex: ServersModel.getProcessedServerData("isServerFromGatewayApi") ?
(ServersModel.getProcessedServerData("isCountrySelectionAvailable") ?
root.pageSettingsApiLanguageList : root.pageSettingsApiServerInfo) : tabBar.currentIndex
2023-06-01 11:25:33 +08:00
PageSettingsServerProtocols {
id: protocolsPage
2023-06-01 11:25:33 +08:00
stackView: root.stackView
2024-04-18 17:54:55 +04:00
onLastItemTabClickedSignal: lastItemTabClicked(focusItem)
2023-06-01 11:25:33 +08:00
}
2023-06-01 11:25:33 +08:00
PageSettingsServerServices {
id: servicesPage
2023-06-01 11:25:33 +08:00
stackView: root.stackView
2024-04-18 17:54:55 +04:00
onLastItemTabClickedSignal: lastItemTabClicked(focusItem)
2023-06-01 11:25:33 +08:00
}
2023-06-01 11:25:33 +08:00
PageSettingsServerData {
2024-04-18 17:54:55 +04:00
id: dataPage
2023-06-01 11:25:33 +08:00
stackView: root.stackView
2024-04-18 17:54:55 +04:00
onLastItemTabClickedSignal: lastItemTabClicked(focusItem)
2023-06-01 11:25:33 +08:00
}
PageSettingsApiServerInfo {
id: apiInfoPage
stackView: root.stackView
// onLastItemTabClickedSignal: lastItemTabClicked(focusItem)
}
PageSettingsApiLanguageList {
id: apiLanguageListPage
stackView: root.stackView
// onLastItemTabClickedSignal: lastItemTabClicked(focusItem)
}
2023-06-01 11:25:33 +08:00
}
2024-04-18 17:54:55 +04:00
2023-06-01 11:25:33 +08:00
}
}