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

305 lines
10 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
2024-04-18 17:54:55 +04:00
defaultActiveFocusItem: focusItem
Connections {
target: PageController
function onGoToPageSettingsServerServices() {
tabBar.currentIndex = root.pageSettingsServerServices
}
}
2023-06-01 11:25:33 +08:00
SortFilterProxyModel {
id: proxyServersModel
sourceModel: ServersModel
filters: [
ValueFilter {
roleName: "isCurrentlyProcessed"
value: true
}
]
}
2024-04-18 17:54:55 +04:00
Item {
id: focusItem
KeyNavigation.tab: header
}
2023-06-01 11:25:33 +08:00
ColumnLayout {
anchors.fill: parent
spacing: 16
Repeater {
id: header
model: proxyServersModel
2024-04-18 17:54:55 +04:00
activeFocusOnTab: true
onFocusChanged: {
header.itemAt(0).focusItem.forceActiveFocus()
}
2023-06-05 15:49:10 +08:00
delegate: ColumnLayout {
2024-04-18 17:54:55 +04:00
property alias focusItem: backButton
2023-06-05 15:49:10 +08:00
id: content
2023-06-01 11:25:33 +08:00
Layout.topMargin: 20
2023-06-05 15:49:10 +08:00
BackButtonType {
2024-04-18 17:54:55 +04:00
id: backButton
KeyNavigation.tab: headerContent.actionButton
backButtonFunction: function() {
if (nestedStackView.currentIndex === root.pageSettingsApiServerInfo &&
ServersModel.getProcessedServerData("isCountrySelectionAvailable")) {
nestedStackView.currentIndex = root.pageSettingsApiLanguageList
} else {
PageController.closePage()
}
}
2023-06-05 15:49:10 +08:00
}
HeaderType {
2024-04-18 17:54:55 +04:00
id: headerContent
2023-06-05 15:49:10 +08:00
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"
2023-06-01 11:25:33 +08:00
2023-06-05 15:49:10 +08:00
headerText: name
descriptionText: {
if (ServersModel.getProcessedServerData("isServerFromGatewayApi")) {
return ApiServicesModel.getSelectedServiceData("serviceDescription")
} else if (ServersModel.getProcessedServerData("isServerFromTelegramApi")) {
return serverDescription
} else if (ServersModel.isProcessedServerHasWriteAccess()) {
return credentialsLogin + " · " + hostName
} else {
return hostName
}
}
2023-06-01 11:25:33 +08:00
2024-04-18 17:54:55 +04:00
KeyNavigation.tab: tabBar
2023-06-05 15:49:10 +08:00
actionButtonFunction: function() {
if (nestedStackView.currentIndex === root.pageSettingsApiLanguageList) {
nestedStackView.currentIndex = root.pageSettingsApiServerInfo
} else {
serverNameEditDrawer.open()
}
}
}
2024-02-16 15:24:06 +05:00
DrawerType2 {
id: serverNameEditDrawer
2024-02-16 15:24:06 +05:00
parent: root
2024-02-16 15:24:06 +05:00
anchors.fill: parent
expandedHeight: root.height * 0.35
2024-04-18 17:54:55 +04:00
onClosed: {
if (!GC.isMobile()) {
headerContent.actionButton.forceActiveFocus()
}
}
2024-02-16 15:24:06 +05:00
expandedContent: ColumnLayout {
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
2024-02-16 15:24:06 +05:00
anchors.topMargin: 32
anchors.leftMargin: 16
anchors.rightMargin: 16
2024-02-16 15:24:06 +05:00
Connections {
target: serverNameEditDrawer
enabled: !GC.isMobile()
2024-02-16 15:24:06 +05:00
function onOpened() {
serverName.textField.forceActiveFocus()
}
}
2024-04-18 17:54:55 +04:00
Item {
id: focusItem1
KeyNavigation.tab: serverName.textField
}
TextFieldWithHeaderType {
id: serverName
Layout.fillWidth: true
headerText: qsTr("Server name")
textFieldText: name
textField.maximumLength: 30
checkEmptyText: true
KeyNavigation.tab: saveButton
}
BasicButtonType {
id: saveButton
Layout.fillWidth: true
text: qsTr("Save")
2024-04-18 17:54:55 +04:00
KeyNavigation.tab: focusItem1
clickedFunc: function() {
if (serverName.textFieldText === "") {
return
}
if (serverName.textFieldText !== name) {
name = serverName.textFieldText
}
2024-02-16 15:24:06 +05:00
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
2023-06-01 11:25:33 +08:00
Layout.preferredWidth: root.width
Layout.preferredHeight: root.height - tabBar.implicitHeight - header.implicitHeight
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
}
}