moved handling of connection states from qml in connectionController

- added a check for already installed containers before installing the server/container
- added a button to scan the server for installed containers
- added separation for read/write and readonly servers for pageHome
This commit is contained in:
vladimir.kuznetsov 2023-06-21 20:56:00 +09:00
parent 3a264e6baf
commit 249be451f7
21 changed files with 466 additions and 245 deletions

View file

@ -15,7 +15,7 @@ Button {
}
}
text: qsTr("Connect")
text: ConnectionController.connectionStateText
background: Item {
clip: true
@ -26,13 +26,21 @@ Button {
Image {
id: border
source: connectionProccess.running ? "/images/connectionProgress.svg" :
ConnectionController.isConnected ? "/images/connectionOff.svg" : "/images/connectionOn.svg"
source: {
if (ConnectionController.isConnectionInProgress) {
return "/images/connectionProgress.svg"
} else if (ConnectionController.isConnected) {
return "/images/connectionOff.svg"
} else {
return "/images/connectionOn.svg"
}
}
RotationAnimator {
id: connectionProccess
target: border
running: false
running: ConnectionController.isConnectionInProgress
from: 0
to: 360
loops: Animation.Infinite
@ -67,63 +75,12 @@ Button {
}
onClicked: {
connectionProccess.running ? ConnectionController.closeConnection() : ConnectionController.openConnection()
}
Connections {
target: ConnectionController
function onConnectionStateChanged(state) {
switch(state) {
case ConnectionState.Unknown: {
console.log("Unknown")
break
}
case ConnectionState.Disconnected: {
console.log("Disconnected")
connectionProccess.running = false
root.text = qsTr("Connect")
ConnectionController.isConnected = false
break
}
case ConnectionState.Preparing: {
console.log("Preparing")
connectionProccess.running = true
root.text = qsTr("Connection...")
break
}
case ConnectionState.Connecting: {
console.log("Connecting")
connectionProccess.running = true
root.text = qsTr("Connection...")
break
}
case ConnectionState.Connected: {
console.log("Connected")
connectionProccess.running = false
root.text = qsTr("Disconnect")
ConnectionController.isConnected = true
break
}
case ConnectionState.Disconnecting: {
console.log("Disconnecting")
connectionProccess.running = true
root.text = qsTr("Disconnection...")
break
}
case ConnectionState.Reconnecting: {
console.log("Reconnecting")
connectionProccess.running = true
root.text = qsTr("Reconnection...")
break
}
case ConnectionState.Error: {
console.log("Error")
connectionProccess.running = false
root.text = qsTr("Connect")
PageController.showErrorMessage(ConnectionController.getLastConnectionError())
break
}
}
if (ConnectionController.isConnectionInProgress) {
ConnectionController.closeConnection()
} else if (ConnectionController.isConnected) {
ConnectionController.closeConnection()
} else {
ConnectionController.openConnection()
}
}
}

View file

@ -141,6 +141,7 @@ DrawerType {
Layout.bottomMargin: 16
padding: 0
leftPadding: 0
height: 24
color: "#D7D8DB"

View file

@ -2,6 +2,8 @@ import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import "TextTypes"
Item {
id: root
@ -34,15 +36,10 @@ Item {
anchors.fill: backgroud
ColumnLayout {
Text {
LabelTextType {
text: root.headerText
color: "#878b91"
font.pixelSize: 13
font.weight: 400
font.family: "PT Root UI VF"
font.letterSpacing: 0.02
height: 16
Layout.fillWidth: true
Layout.rightMargin: 16
Layout.leftMargin: 16

View file

@ -0,0 +1,12 @@
import QtQuick
Text {
height: 20
color: "#D7D8DB"
font.pixelSize: 14
font.weight: Font.Normal
font.family: "PT Root UI VF"
wrapMode: Text.WordWrap
}

View file

@ -21,8 +21,8 @@ PageType {
property string borderColor: "#2C2D30"
property string currentServerName: serversMenuContent.currentItem.delegateData.name
property string currentServerHostName: serversMenuContent.currentItem.delegateData.hostName
property string currentServerName
property string currentServerHostName
property string currentContainerName
ConnectButton {
@ -93,7 +93,15 @@ PageType {
Layout.bottomMargin: 44
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
text: root.currentContainerName + " | " + root.currentServerHostName
text: {
var string = ""
if (SettingsController.isAmneziaDnsEnabled()) {
string += "Amnezia DNS | "
}
string += root.currentContainerName + " | " + root.currentServerHostName
return string
}
}
}
@ -153,6 +161,8 @@ PageType {
headerBackButtonImage: "qrc:/images/controls/arrow-left.svg"
rootButtonClickedFunction: function() {
// todo check if server index changed before set Currently processed
// todo make signal slot for change server index in containersModel
ServersModel.setCurrentlyProcessedServerIndex(serversMenuContent.currentIndex)
ContainersModel.setCurrentlyProcessedServerIndex(serversMenuContent.currentIndex)
containersDropDown.menuVisible = true
@ -161,20 +171,45 @@ PageType {
listView: HomeContainersListView {
rootWidth: root.width
Connections {
target: ServersModel
function onCurrentlyProcessedServerIndexChanged() {
updateContainersModelFilters()
}
function updateContainersModelFilters() {
if (ServersModel.isCurrentlyProcessedServerHasWriteAccess()) {
proxyContainersModel.filters = [serviceTypeFilter, supportedFilter]
} else {
proxyContainersModel.filters = installedFilter
}
}
}
ValueFilter {
id: serviceTypeFilter
roleName: "serviceType"
value: ProtocolEnum.Vpn
}
ValueFilter {
id: supportedFilter
roleName: "isSupported"
value: true
}
ValueFilter {
id: installedFilter
roleName: "isInstalled"
value: true
}
model: SortFilterProxyModel {
id: proxyContainersModel
sourceModel: ContainersModel
filters: [
ValueFilter {
roleName: "serviceType"
value: ProtocolEnum.Vpn
},
ValueFilter {
roleName: "isSupported"
value: true
}
]
Component.onCompleted: updateContainersModelFilters()
}
currentIndex: ContainersModel.getDefaultContainer()
}
}
@ -272,6 +307,9 @@ PageType {
isDefault = true
ContainersModel.setCurrentlyProcessedServerIndex(index)
root.currentServerName = name
root.currentServerHostName = hostName
}
MouseArea {
@ -302,6 +340,13 @@ PageType {
Layout.fillWidth: true
}
}
Component.onCompleted: {
if (serversMenuContent.currentIndex === index) {
root.currentServerName = name
root.currentServerHostName = hostName
}
}
}
}
}

View file

@ -14,6 +14,21 @@ import "../Components"
PageType {
id: root
Connections {
target: InstallController
function onScanServerFinished(isInstalledContainerFound) {
var message = ""
if (isInstalledContainerFound) {
message = qsTr("All installed containers have been added to the application")
} else {
message = qsTr("Не найдено установленных контейнеров")
}
PageController.showErrorMessage(message)
}
}
FlickableType {
id: fl
anchors.top: parent.top
@ -30,8 +45,8 @@ PageType {
LabelWithButtonType {
Layout.fillWidth: true
text: "Clear Amnezia cache"
descriptionText: "May be needed when changing other settings"
text: qsTr("Clear Amnezia cache")
descriptionText: qsTr("May be needed when changing other settings")
clickedFunction: function() {
questionDrawer.headerText = qsTr("Clear cached profiles?")
@ -52,6 +67,19 @@ PageType {
DividerType {}
LabelWithButtonType {
Layout.fillWidth: true
text: qsTr("Проверить сервер на наличие ранее установленных сервисов Amnezia")
descriptionText: qsTr("Добавим их в приложение, если они не отображались")
clickedFunction: function() {
InstallController.scanServerForInstalledContainers()
}
}
DividerType {}
LabelWithButtonType {
Layout.fillWidth: true

View file

@ -7,6 +7,7 @@ import PageEnum 1.0
import "./"
import "../Controls2"
import "../Config"
import "../Controls2/TextTypes"
PageType {
id: root
@ -42,28 +43,32 @@ PageType {
HeaderType {
Layout.fillWidth: true
headerText: "Подключение к серверу"
headerText: qsTr("Server connection")
}
TextFieldWithHeaderType {
id: hostname
Layout.fillWidth: true
headerText: "Server IP address [:port]"
headerText: qsTr("Server IP address [:port]")
textFieldPlaceholderText: qsTr("Enter the address in the format 255.255.255.255:88")
textField.validator: RegularExpressionValidator {
regularExpression: InstallController.ipAddressPortRegExp()
}
}
TextFieldWithHeaderType {
id: username
Layout.fillWidth: true
headerText: "Login to connect via SSH"
headerText: qsTr("Login to connect via SSH")
}
TextFieldWithHeaderType {
id: secretData
Layout.fillWidth: true
headerText: "Password / Private key"
headerText: qsTr("Password / Private key")
textField.echoMode: TextInput.Password
}
@ -71,7 +76,7 @@ PageType {
Layout.fillWidth: true
Layout.topMargin: 24
text: qsTr("Настроить сервер простым образом")
text: qsTr("Set up a server the easy way")
onClicked: function() {
InstallController.setShouldCreateServer(true)
@ -92,7 +97,7 @@ PageType {
textColor: "#D7D8DB"
borderWidth: 1
text: qsTr("Выбрать протокол для установки")
text: qsTr("Select protocol to install")
onClicked: function() {
InstallController.setShouldCreateServer(true)

View file

@ -24,7 +24,7 @@ PageType {
PageController.showErrorMessage(errorMessage)
}
function onInstallContainerFinished() {
function onInstallContainerFinished(isInstalledContainerFound) {
goToStartPage()
if (stackView.currentItem.objectName === PageController.getPagePath(PageEnum.PageHome)) {
PageController.restorePageHomeState(true)
@ -34,9 +34,15 @@ PageType {
} else {
goToPage(PageEnum.PageHome)
}
if (isInstalledContainerFound) {
//todo change to info message
PageController.showErrorMessage(qsTr("The container you are trying to install is already installed on the server. " +
"All installed containers have been added to the application"))
}
}
function onInstallServerFinished() {
function onInstallServerFinished(isInstalledContainerFound) {
goToStartPage()
if (stackView.currentItem.objectName === PageController.getPagePath(PageEnum.PageHome)) {
PageController.restorePageHomeState()
@ -46,6 +52,19 @@ PageType {
var pagePath = PageController.getPagePath(PageEnum.PageStart)
stackView.replace(pagePath, { "objectName" : pagePath })
}
if (isInstalledContainerFound) {
PageController.showErrorMessage(qsTr("The container you are trying to install is already installed on the server. " +
"All installed containers have been added to the application"))
}
}
function onServerAlreadyExists(serverIndex) {
goToStartPage()
ServersModel.setCurrentlyProcessedServerIndex(serverIndex)
goToPage(PageEnum.PageSettingsServerInfo, false)
PageController.showErrorMessage(qsTr("The server has already been added to the application"))
}
}

View file

@ -20,6 +20,11 @@ PageType {
tabBarStackView.goToTabBarPage(PageController.getPagePath(PageEnum.PageHome))
}
function onGoToPageSettings() {
tabBar.currentIndex = 2
tabBarStackView.goToTabBarPage(PageController.getPagePath(PageEnum.PageSettings))
}
function onShowErrorMessage(errorMessage) {
popupErrorMessage.popupErrorMessageText = errorMessage
popupErrorMessage.open()