2024-08-20 16:54:05 +07:00
import QtQuick
import QtQuick . Controls
import QtQuick . Layouts
import QtQuick . Dialogs
2025-01-31 10:06:35 +07:00
import SortFilterProxyModel 0.2
2024-08-20 16:54:05 +07:00
import PageEnum 1.0
import Style 1.0
import "./"
import "../Controls2"
import "../Controls2/TextTypes"
import "../Config"
import "../Components"
PageType {
id: root
2025-01-26 14:13:30 +07:00
property list < QtObject > labelsModel: [
2025-02-06 15:26:47 +07:00
statusObject ,
2025-01-26 14:13:30 +07:00
endDateObject ,
2025-02-06 15:26:47 +07:00
deviceCountObject
2025-01-26 14:13:30 +07:00
]
2024-08-20 16:54:05 +07:00
2025-01-26 14:13:30 +07:00
QtObject {
2025-02-06 15:26:47 +07:00
id: statusObject
2024-08-20 16:54:05 +07:00
2025-03-05 06:11:31 +03:00
readonly property string title: qsTr ( "Subscription Status" )
2025-02-06 15:26:47 +07:00
readonly property string contentKey: "subscriptionStatus"
2025-02-28 18:17:43 +03:00
readonly property string objectImageSource: "qrc:/images/controls/info.svg"
2025-08-26 20:31:41 +08:00
readonly property bool isRichText: true
2025-01-26 14:13:30 +07:00
}
2024-08-20 16:54:05 +07:00
2025-01-26 14:13:30 +07:00
QtObject {
id: endDateObject
2024-08-20 16:54:05 +07:00
2025-03-05 06:11:31 +03:00
readonly property string title: qsTr ( "Valid Until" )
2025-01-26 14:13:30 +07:00
readonly property string contentKey: "endDate"
readonly property string objectImageSource: "qrc:/images/controls/history.svg"
2025-08-26 20:31:41 +08:00
readonly property bool isRichText: false
2025-01-26 14:13:30 +07:00
}
2024-08-20 16:54:05 +07:00
2025-01-26 14:13:30 +07:00
QtObject {
2025-02-06 15:26:47 +07:00
id: deviceCountObject
2024-08-20 16:54:05 +07:00
2025-03-05 06:11:31 +03:00
readonly property string title: qsTr ( "Active Connections" )
2025-02-06 15:26:47 +07:00
readonly property string contentKey: "connectedDevices"
2025-02-28 18:17:43 +03:00
readonly property string objectImageSource: "qrc:/images/controls/monitor.svg"
2025-08-26 20:31:41 +08:00
readonly property bool isRichText: false
2025-01-26 14:13:30 +07:00
}
2024-12-09 09:32:49 +03:00
2025-01-31 10:06:35 +07:00
property var processedServer
2026-03-24 17:45:02 +03:00
property bool isSubscriptionExpired: false
property bool isSubscriptionExpiringSoon: false
2026-04-08 11:21:12 +07:00
property bool isSubscriptionRenewalAvailable: false
property bool isInAppPurchase: false
2026-03-24 17:45:02 +03:00
function updateSubscriptionState ( ) {
root . isSubscriptionExpired = ApiAccountInfoModel . data ( "isSubscriptionExpired" )
root . isSubscriptionExpiringSoon = ApiAccountInfoModel . data ( "isSubscriptionExpiringSoon" )
2026-04-08 11:21:12 +07:00
root . isSubscriptionRenewalAvailable = ApiAccountInfoModel . data ( "isSubscriptionRenewalAvailable" )
root . isInAppPurchase = ApiAccountInfoModel . data ( "isInAppPurchase" )
2026-03-24 17:45:02 +03:00
}
Component.onCompleted: {
root . updateSubscriptionState ( )
}
Connections {
target: ApiAccountInfoModel
function onModelReset ( ) {
root . updateSubscriptionState ( )
}
}
2026-05-28 10:57:08 +08:00
Connections {
target: ServersUiController
function onProcessedServerIdChanged ( ) {
root . processedServer = proxyServersModel . get ( 0 )
}
}
2025-01-31 10:06:35 +07:00
Connections {
target: ServersModel
2026-05-28 10:57:08 +08:00
function onModelReset ( ) {
2025-01-31 10:06:35 +07:00
root . processedServer = proxyServersModel . get ( 0 )
}
}
SortFilterProxyModel {
id: proxyServersModel
objectName: "proxyServersModel"
sourceModel: ServersModel
filters: [
ValueFilter {
2026-05-28 10:57:08 +08:00
roleName: "serverId"
value: ServersUiController . processedServerId
2025-01-31 10:06:35 +07:00
}
]
Component.onCompleted: {
root . processedServer = proxyServersModel . get ( 0 )
}
}
2025-02-06 15:26:47 +07:00
ListViewType {
2025-01-26 14:13:30 +07:00
id: listView
2024-08-20 16:54:05 +07:00
2025-01-31 10:06:35 +07:00
anchors.fill: parent
model: labelsModel
header: ColumnLayout {
width: listView . width
spacing: 4
BackButtonType {
id: backButton
objectName: "backButton"
2026-04-30 14:53:03 +08:00
Layout.topMargin: 20 + PageController . safeAreaTopMargin
2025-01-31 10:06:35 +07:00
}
2025-05-02 23:54:36 -07:00
HeaderTypeWithButton {
2025-01-31 10:06:35 +07:00
id: headerContent
objectName: "headerContent"
Layout.fillWidth: true
Layout.leftMargin: 16
Layout.rightMargin: 16
2026-04-08 11:21:12 +07:00
Layout.bottomMargin: root . isSubscriptionExpired || root . isSubscriptionExpiringSoon ? 0 : 10
2025-01-31 10:06:35 +07:00
actionButtonImage: "qrc:/images/controls/edit-3.svg"
2026-05-28 10:57:08 +08:00
headerText: root . processedServer != null ? root.processedServer.name : ""
2025-01-31 10:06:35 +07:00
actionButtonFunction: function ( ) {
serverNameEditDrawer . openTriggered ( )
}
}
2026-03-24 17:45:02 +03:00
2026-04-08 11:21:12 +07:00
ParagraphTextType {
2026-03-24 17:45:02 +03:00
visible: root . isSubscriptionExpired || root . isSubscriptionExpiringSoon
Layout.fillWidth: true
Layout.leftMargin: 16
Layout.rightMargin: 16
2026-04-08 11:21:12 +07:00
Layout.topMargin: 12
2026-03-24 17:45:02 +03:00
text: root . isSubscriptionExpired
? qsTr ( "Subscription expired" )
: qsTr ( "Subscription expiring soon" )
color: root . isSubscriptionExpired
? AmneziaStyle.color.vibrantRed
: AmneziaStyle . color . goldenApricot
}
2026-03-25 07:34:42 +03:00
ParagraphTextType {
visible: ApiAccountInfoModel . data ( "serviceDescription" ) !== ""
Layout.fillWidth: true
Layout.leftMargin: 16
Layout.rightMargin: 16
Layout.topMargin: 16
Layout.bottomMargin: root . isSubscriptionExpired || root . isSubscriptionExpiringSoon ? 0 : 10
text: ApiAccountInfoModel . data ( "serviceDescription" )
color: AmneziaStyle . color . mutedGray
}
2026-03-24 17:45:02 +03:00
BasicButtonType {
2026-04-08 11:21:12 +07:00
visible: ( root . isSubscriptionExpired || root . isSubscriptionExpiringSoon )
&& root . isSubscriptionRenewalAvailable && ! root . isInAppPurchase
2026-03-24 17:45:02 +03:00
Layout.fillWidth: true
Layout.leftMargin: 16
Layout.rightMargin: 16
Layout.topMargin: 8
Layout.bottomMargin: 8
text: qsTr ( "Renew subscription" )
defaultColor: AmneziaStyle . color . paleGray
hoveredColor: AmneziaStyle . color . lightGray
pressedColor: AmneziaStyle . color . mutedGray
textColor: AmneziaStyle . color . midnightBlack
clickedFunc: function ( ) {
2026-05-28 10:57:08 +08:00
SubscriptionUiController . getRenewalLink ( ServersUiController . processedServerId )
2026-03-24 17:45:02 +03:00
}
}
2025-01-31 10:06:35 +07:00
}
2025-01-26 14:13:30 +07:00
delegate: ColumnLayout {
width: listView . width
spacing: 0
2024-08-20 16:54:05 +07:00
2025-02-22 14:42:09 +07:00
Connections {
target: ApiAccountInfoModel
function onModelReset ( ) {
delegateItem . rightText = ApiAccountInfoModel . data ( contentKey )
}
}
2024-08-20 16:54:05 +07:00
LabelWithImageType {
2025-02-22 14:42:09 +07:00
id: delegateItem
2024-08-20 16:54:05 +07:00
Layout.fillWidth: true
Layout.margins: 16
2025-01-26 14:13:30 +07:00
imageSource: objectImageSource
leftText: title
2025-02-06 15:26:47 +07:00
rightText: ApiAccountInfoModel . data ( contentKey )
2025-08-26 20:31:41 +08:00
rightTextFormat: isRichText ? Text.RichText : Text . PlainText
2025-01-26 14:13:30 +07:00
visible: rightText !== ""
2024-08-20 16:54:05 +07:00
}
2025-01-26 14:13:30 +07:00
}
footer: ColumnLayout {
2025-02-10 15:10:59 +07:00
id: footer
2025-01-26 14:13:30 +07:00
width: listView . width
spacing: 0
2024-08-20 16:54:05 +07:00
2025-02-10 15:10:59 +07:00
readonly property bool isVisibleForAmneziaFree: ApiAccountInfoModel . data ( "isComponentVisible" )
2026-04-08 11:21:12 +07:00
BasicButtonType {
2026-03-25 07:34:42 +03:00
visible: ! root . isSubscriptionExpired && ! root . isSubscriptionExpiringSoon
2026-04-08 11:21:12 +07:00
&& root . isSubscriptionRenewalAvailable && ! root . isInAppPurchase
2026-03-25 07:34:42 +03:00
2026-04-08 11:21:12 +07:00
Layout.alignment: Qt . AlignHCenter
Layout.topMargin: 16
Layout.bottomMargin: 16
2026-03-25 07:34:42 +03:00
2026-04-08 11:21:12 +07:00
implicitHeight: 25
defaultColor: AmneziaStyle . color . transparent
hoveredColor: AmneziaStyle . color . translucentWhite
pressedColor: AmneziaStyle . color . sheerWhite
textColor: AmneziaStyle . color . goldenApricot
leftImageSource: "qrc:/images/controls/refresh-cw.svg"
leftImageColor: AmneziaStyle . color . goldenApricot
text: qsTr ( "Renew subscription" )
2026-03-25 07:34:42 +03:00
2026-04-08 11:21:12 +07:00
clickedFunc: function ( ) {
2026-05-28 10:57:08 +08:00
SubscriptionUiController . getRenewalLink ( ServersUiController . processedServerId )
2026-03-25 07:34:42 +03:00
}
}
DividerType {
visible: ! root . isSubscriptionExpired && ! root . isSubscriptionExpiringSoon
2026-04-08 11:21:12 +07:00
&& root . isSubscriptionRenewalAvailable && ! root . isInAppPurchase
2026-03-25 07:34:42 +03:00
}
2025-07-03 09:58:23 +08:00
SwitcherType {
id: switcher
2026-05-28 10:57:08 +08:00
readonly property bool isVlessProtocol: SubscriptionUiController . isVlessProtocol ( ServersUiController . processedServerId )
readonly property bool isProtocolSwitchBlocked: ServersUiController . isDefaultServerCurrentlyProcessed ( ) && ConnectionController . isConnected
2025-07-03 09:58:23 +08:00
Layout.fillWidth: true
Layout.topMargin: 24
Layout.rightMargin: 16
Layout.leftMargin: 16
2026-05-15 09:58:23 +03:00
Layout.bottomMargin: 24
2025-07-03 09:58:23 +08:00
visible: ApiAccountInfoModel . data ( "isProtocolSelectionSupported" )
2026-04-08 08:45:51 +04:00
enabled: ! switcher . isProtocolSwitchBlocked
2025-07-03 09:58:23 +08:00
text: qsTr ( "Use VLESS protocol" )
checked: switcher . isVlessProtocol
onToggled: function ( ) {
2026-04-30 14:53:03 +08:00
if ( ServersUiController . isDefaultServerCurrentlyProcessed ( ) && ConnectionController . isConnected ) {
2025-07-03 09:58:23 +08:00
PageController . showNotificationMessage ( qsTr ( "Cannot change protocol during active connection" ) )
} else {
PageController . showBusyIndicator ( true )
2026-05-28 10:57:08 +08:00
SubscriptionUiController . setCurrentProtocol ( ServersUiController . processedServerId , switcher . isVlessProtocol ? "awg" : "vless" )
SubscriptionUiController . updateServiceFromGateway ( ServersUiController . processedServerId , "" , "" , true )
2025-07-03 09:58:23 +08:00
PageController . showBusyIndicator ( false )
}
}
}
2026-03-25 07:34:42 +03:00
DividerType {
visible: footer . isVisibleForAmneziaFree
}
2025-02-28 18:17:43 +03:00
WarningType {
id: warning
2026-03-25 07:34:42 +03:00
Layout.topMargin: 24
2025-02-28 18:17:43 +03:00
Layout.rightMargin: 16
Layout.leftMargin: 16
Layout.fillWidth: true
backGroundColor: AmneziaStyle . color . translucentRichBrown
textString: qsTr ( "Configurations have been updated for some countries. Download and install the updated configuration files" )
iconPath: "qrc:/images/controls/alert-circle.svg"
2025-08-04 10:13:22 +04:00
visible: {
for ( let i = 0 ; i < ApiCountryModel . count ; ++ i ) {
if ( ApiCountryModel . get ( i ) . isWorkerExpired )
return true ;
}
return false ;
}
2025-02-28 18:17:43 +03:00
}
2025-02-06 15:26:47 +07:00
LabelWithButtonType {
2025-02-07 22:22:14 +07:00
id: vpnKey
2024-08-20 16:54:05 +07:00
Layout.fillWidth: true
2026-03-25 07:34:42 +03:00
Layout.topMargin: warning . visible ? 16 : 0
2024-08-20 16:54:05 +07:00
2025-08-01 17:02:12 +04:00
visible: footer . isVisibleForAmneziaFree
2025-02-06 15:26:47 +07:00
2025-03-05 06:11:31 +03:00
text: qsTr ( "Subscription Key" )
2025-02-06 15:26:47 +07:00
rightImageSource: "qrc:/images/controls/chevron-right.svg"
clickedFunction: function ( ) {
2025-08-01 17:02:12 +04:00
PageController . goToPage ( PageEnum . PageSettingsApiSubscriptionKey )
2025-02-12 12:43:11 +07:00
PageController . showBusyIndicator ( true )
2026-05-28 10:57:08 +08:00
SubscriptionUiController . prepareVpnKeyExport ( ServersUiController . processedServerId )
2025-02-12 12:43:11 +07:00
PageController . showBusyIndicator ( false )
2024-08-20 16:54:05 +07:00
}
2025-02-06 15:26:47 +07:00
}
2025-02-07 22:22:14 +07:00
DividerType {
2025-08-01 17:02:12 +04:00
visible: footer . isVisibleForAmneziaFree
2025-02-07 22:22:14 +07:00
}
2025-02-06 15:26:47 +07:00
LabelWithButtonType {
Layout.fillWidth: true
2025-02-10 15:10:59 +07:00
visible: footer . isVisibleForAmneziaFree
2025-02-06 15:26:47 +07:00
2025-03-05 06:11:31 +03:00
text: qsTr ( "Configuration Files" )
2024-08-20 16:54:05 +07:00
2025-03-04 13:33:35 +07:00
descriptionText: qsTr ( "Manage configuration files" )
2025-02-06 15:26:47 +07:00
rightImageSource: "qrc:/images/controls/chevron-right.svg"
2025-01-26 14:13:30 +07:00
2025-02-06 15:26:47 +07:00
clickedFunction: function ( ) {
2026-04-30 14:53:03 +08:00
SubscriptionUiController . updateApiCountryModel ( )
2025-02-07 22:22:14 +07:00
PageController . goToPage ( PageEnum . PageSettingsApiNativeConfigs )
2024-08-20 16:54:05 +07:00
}
}
2025-02-10 15:10:59 +07:00
DividerType {
visible: footer . isVisibleForAmneziaFree
}
2025-02-06 15:26:47 +07:00
2025-02-28 18:17:43 +03:00
LabelWithButtonType {
Layout.fillWidth: true
visible: footer . isVisibleForAmneziaFree
2025-03-05 06:11:31 +03:00
text: qsTr ( "Active Devices" )
2025-02-28 18:17:43 +03:00
2025-03-04 13:33:35 +07:00
descriptionText: qsTr ( "Manage currently connected devices" )
2025-02-28 18:17:43 +03:00
rightImageSource: "qrc:/images/controls/chevron-right.svg"
clickedFunction: function ( ) {
2026-04-30 14:53:03 +08:00
SubscriptionUiController . updateApiDevicesModel ( )
2025-02-28 18:17:43 +03:00
PageController . goToPage ( PageEnum . PageSettingsApiDevices )
}
}
DividerType {
visible: footer . isVisibleForAmneziaFree
}
2024-08-20 16:54:05 +07:00
LabelWithButtonType {
Layout.fillWidth: true
2025-02-10 15:10:59 +07:00
Layout.topMargin: footer . isVisibleForAmneziaFree ? 0 : 32
2024-08-20 16:54:05 +07:00
2025-02-06 15:26:47 +07:00
text: qsTr ( "Support" )
rightImageSource: "qrc:/images/controls/chevron-right.svg"
clickedFunction: function ( ) {
PageController . goToPage ( PageEnum . PageSettingsApiSupport )
}
}
DividerType { }
2024-08-20 16:54:05 +07:00
2025-02-06 15:26:47 +07:00
LabelWithButtonType {
Layout.fillWidth: true
2024-08-20 16:54:05 +07:00
2025-03-04 13:33:35 +07:00
visible: footer . isVisibleForAmneziaFree
2025-02-21 14:15:23 +07:00
text: qsTr ( "How to connect on another device" )
2025-02-06 15:26:47 +07:00
rightImageSource: "qrc:/images/controls/chevron-right.svg"
2024-08-20 16:54:05 +07:00
clickedFunction: function ( ) {
2025-02-06 15:26:47 +07:00
PageController . goToPage ( PageEnum . PageSettingsApiInstructions )
2024-08-20 16:54:05 +07:00
}
}
2025-03-04 13:33:35 +07:00
DividerType {
visible: footer . isVisibleForAmneziaFree
}
2025-02-06 15:26:47 +07:00
2024-08-20 16:54:05 +07:00
BasicButtonType {
id: resetButton
Layout.alignment: Qt . AlignHCenter
Layout.topMargin: 24
Layout.bottomMargin: 16
Layout.leftMargin: 8
implicitHeight: 32
defaultColor: "transparent"
2024-11-06 09:57:39 +04:00
hoveredColor: AmneziaStyle . color . translucentWhite
pressedColor: AmneziaStyle . color . sheerWhite
2024-08-20 16:54:05 +07:00
textColor: AmneziaStyle . color . vibrantRed
text: qsTr ( "Reload API config" )
clickedFunc: function ( ) {
var headerText = qsTr ( "Reload API config?" )
var yesButtonText = qsTr ( "Continue" )
var noButtonText = qsTr ( "Cancel" )
var yesButtonFunction = function ( ) {
2026-04-30 14:53:03 +08:00
if ( ServersUiController . isDefaultServerCurrentlyProcessed ( ) && ConnectionController . isConnected ) {
2024-08-20 16:54:05 +07:00
PageController . showNotificationMessage ( qsTr ( "Cannot reload API config during active connection" ) )
} else {
PageController . showBusyIndicator ( true )
2026-05-28 10:57:08 +08:00
SubscriptionUiController . updateServiceFromGateway ( ServersUiController . processedServerId , "" , "" , true )
2024-08-20 16:54:05 +07:00
PageController . showBusyIndicator ( false )
}
}
var noButtonFunction = function ( ) {
2025-02-20 13:44:19 +07:00
}
showQuestionDrawer ( headerText , "" , yesButtonText , noButtonText , yesButtonFunction , noButtonFunction )
}
}
BasicButtonType {
id: revokeButton
Layout.alignment: Qt . AlignHCenter
Layout.bottomMargin: 16
Layout.leftMargin: 8
implicitHeight: 32
2025-02-21 14:15:23 +07:00
visible: footer . isVisibleForAmneziaFree
2025-02-20 13:44:19 +07:00
defaultColor: "transparent"
hoveredColor: AmneziaStyle . color . translucentWhite
pressedColor: AmneziaStyle . color . sheerWhite
textColor: AmneziaStyle . color . vibrantRed
2025-03-04 13:33:35 +07:00
text: qsTr ( "Unlink this device" )
2025-02-20 13:44:19 +07:00
clickedFunc: function ( ) {
2025-03-04 13:33:35 +07:00
var headerText = qsTr ( "Are you sure you want to unlink this device?" )
2025-05-12 10:31:41 +03:00
var descriptionText = qsTr ( "This will unlink the device from your subscription. You can reconnect it anytime by pressing \"Reload API config\" in subscription settings on device." )
2025-02-20 13:44:19 +07:00
var yesButtonText = qsTr ( "Continue" )
var noButtonText = qsTr ( "Cancel" )
var yesButtonFunction = function ( ) {
2026-04-30 14:53:03 +08:00
if ( ServersUiController . isDefaultServerCurrentlyProcessed ( ) && ConnectionController . isConnected ) {
2025-03-04 13:33:35 +07:00
PageController . showNotificationMessage ( qsTr ( "Cannot unlink device during active connection" ) )
2025-02-20 13:44:19 +07:00
} else {
PageController . showBusyIndicator ( true )
2026-05-28 10:57:08 +08:00
if ( SubscriptionUiController . deactivateDevice ( ServersUiController . processedServerId ) ) {
SubscriptionUiController . getAccountInfo ( ServersUiController . processedServerId , true )
2025-02-20 13:44:19 +07:00
}
PageController . showBusyIndicator ( false )
2024-08-20 16:54:05 +07:00
}
}
2025-02-20 13:44:19 +07:00
var noButtonFunction = function ( ) {
}
2024-08-20 16:54:05 +07:00
2025-02-28 18:17:43 +03:00
showQuestionDrawer ( headerText , descriptionText , yesButtonText , noButtonText , yesButtonFunction , noButtonFunction )
2024-08-20 16:54:05 +07:00
}
}
BasicButtonType {
id: removeButton
Layout.alignment: Qt . AlignHCenter
Layout.bottomMargin: 16
Layout.leftMargin: 8
implicitHeight: 32
defaultColor: "transparent"
2024-11-06 09:57:39 +04:00
hoveredColor: AmneziaStyle . color . translucentWhite
pressedColor: AmneziaStyle . color . sheerWhite
2024-08-20 16:54:05 +07:00
textColor: AmneziaStyle . color . vibrantRed
text: qsTr ( "Remove from application" )
clickedFunc: function ( ) {
var headerText = qsTr ( "Remove from application?" )
var yesButtonText = qsTr ( "Continue" )
var noButtonText = qsTr ( "Cancel" )
var yesButtonFunction = function ( ) {
2026-04-30 14:53:03 +08:00
if ( ServersUiController . isDefaultServerCurrentlyProcessed ( ) && ConnectionController . isConnected ) {
2024-08-20 16:54:05 +07:00
PageController . showNotificationMessage ( qsTr ( "Cannot remove server during active connection" ) )
} else {
PageController . showBusyIndicator ( true )
2026-05-28 10:57:08 +08:00
SubscriptionUiController . removeServer ( ServersUiController . processedServerId )
2024-08-20 16:54:05 +07:00
PageController . showBusyIndicator ( false )
}
}
var noButtonFunction = function ( ) {
}
showQuestionDrawer ( headerText , "" , yesButtonText , noButtonText , yesButtonFunction , noButtonFunction )
}
}
}
}
2025-02-12 12:43:11 +07:00
2025-08-01 17:02:12 +04:00
RenameServerDrawer {
id: serverNameEditDrawer
2025-02-12 12:43:11 +07:00
anchors.fill: parent
2025-08-01 17:02:12 +04:00
expandedHeight: parent . height * 0.35
2026-05-28 10:57:08 +08:00
serverNameText: root . processedServer != null ? root.processedServer.name : ""
2025-02-12 12:43:11 +07:00
}
2024-08-20 16:54:05 +07:00
}