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

127 lines
3.6 KiB
QML
Raw Normal View History

2025-11-17 19:20:27 +04:00
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import QtQuick.Dialogs
import PageEnum 1.0
import Style 1.0
import "./"
import "../Controls2"
import "../Controls2/TextTypes"
import "../Config"
PageType {
id: root
2026-01-16 02:31:21 +04:00
property bool isSending: false
function getAddedDeviceName() {
try {
var obj = JSON.parse(TransferController.pendingQrCode)
if (obj && obj.name && obj.name.length > 0) {
return obj.name
}
} catch (e) {}
return qsTr("Device")
}
2025-11-17 19:20:27 +04:00
function getAvailableCount() {
var max = ApiAccountInfoModel.data("maxDeviceCount")
var active = ApiAccountInfoModel.data("activeDeviceCount")
if (!max || max <= 0) max = 7
if (!active || active < 0) active = 0
var remain = max - active
return remain > 0 ? remain : 0
}
ListViewType {
id: listView
anchors.fill: parent
anchors.topMargin: 20
header: ColumnLayout {
width: listView.width
2026-01-16 02:31:21 +04:00
BackButtonType {
backButtonFunction: function() {
if (root.isSending) {
TransferController.stopWaitForConfig()
}
PageController.closePage()
}
}
2025-11-17 19:20:27 +04:00
BaseHeaderType {
Layout.fillWidth: true
Layout.rightMargin: 16
Layout.leftMargin: 16
headerText: qsTr("Add a new device to the subscription?")
descriptionText: qsTr("Devices available with Amnezia Premium: (%1)").arg(getAvailableCount())
2025-11-17 19:20:27 +04:00
}
BasicButtonType {
Layout.fillWidth: true
Layout.leftMargin: 16
Layout.rightMargin: 16
Layout.topMargin: 16
text: qsTr("Add Device")
2026-01-16 02:31:21 +04:00
enabled: !root.isSending && root.getAvailableCount() > 0 && TransferController.pendingQrCode !== ""
2025-11-17 19:20:27 +04:00
clickedFunc: function() {
if (TransferController.pendingQrCode !== "") {
2026-01-16 02:31:21 +04:00
root.isSending = true
2025-11-17 19:20:27 +04:00
TransferController.onTransferQrScanned(TransferController.pendingQrCode)
}
}
}
BasicButtonType {
Layout.fillWidth: true
Layout.leftMargin: 16
Layout.rightMargin: 16
Layout.topMargin: 8
defaultColor: AmneziaStyle.color.transparent
hoveredColor: AmneziaStyle.color.translucentWhite
pressedColor: AmneziaStyle.color.sheerWhite
textColor: AmneziaStyle.color.paleGray
borderColor: AmneziaStyle.color.paleGray
borderWidth: 1
text: qsTr("Cancel")
2026-01-16 02:31:21 +04:00
enabled: !root.isSending
2025-11-17 19:20:27 +04:00
clickedFunc: function() {
PageController.closePage()
}
}
}
}
2025-11-28 12:45:50 +04:00
Connections {
target: TransferController
function onPostStarted() {
2026-01-16 02:31:21 +04:00
PageController.showNotificationMessage(qsTr("Sending configuration..."))
2025-11-28 12:45:50 +04:00
}
function onPostSucceeded() {
2026-01-16 02:31:21 +04:00
root.isSending = false
PageController.showNotificationMessage(qsTr("%1 has been added to your subscription").arg(root.getAddedDeviceName()))
PageController.closePage()
2026-01-16 02:31:21 +04:00
PageController.closePage()
2025-11-28 12:45:50 +04:00
}
function onPostFailed(message) {
2026-01-16 02:31:21 +04:00
root.isSending = false
2025-11-28 12:45:50 +04:00
PageController.showErrorMessage(message)
}
}
2025-11-17 19:20:27 +04:00
}