Files
amnezia-client/client/ui/qml/main.qml
T

327 lines
9.5 KiB
QML
Raw Normal View History

2021-07-28 16:13:29 +07:00
import QtQuick 2.14
import QtQuick.Window 2.14
import QtQuick.Controls 2.12
2021-08-19 01:27:22 +03:00
import QtQuick.Controls.Material 2.12
2021-08-09 00:41:52 +07:00
import PageEnum 1.0
2021-07-28 16:13:29 +07:00
import Qt.labs.platform 1.1
2021-09-14 00:39:07 +03:00
import Qt.labs.folderlistmodel 2.12
2021-07-28 16:13:29 +07:00
import QtQuick.Dialogs 1.1
import "./"
2021-08-19 01:27:22 +03:00
import "Pages"
2021-09-06 12:30:26 +03:00
import "Pages/Protocols"
2021-08-19 01:27:22 +03:00
import "Config"
2021-07-28 16:13:29 +07:00
2021-09-13 17:36:48 +03:00
Window {
2021-09-14 00:39:07 +03:00
property var pages: ({})
2021-09-16 16:19:14 +03:00
property var protocolPages: ({})
2021-08-19 01:27:22 +03:00
2021-07-28 16:13:29 +07:00
id: root
visible: true
width: GC.screenWidth
height: GC.isDesktop() ? GC.screenHeight + titleBar.height : GC.screenHeight
2021-09-13 17:36:48 +03:00
Keys.enabled: true
2021-08-09 00:41:52 +07:00
onClosing: {
2021-09-13 17:36:48 +03:00
console.debug("QML onClosing signal")
2021-08-09 00:41:52 +07:00
UiLogic.onCloseWindow()
}
2021-08-19 01:27:22 +03:00
//flags: Qt.FramelessWindowHint
2021-07-28 16:13:29 +07:00
title: "AmneziaVPN"
function gotoPage(page, reset, slide) {
if (reset) {
2021-08-09 00:41:52 +07:00
if (page === PageEnum.ServerSettings) {
2021-09-08 14:23:02 +03:00
ServerSettingsLogic.updatePage();
}
if (page === PageEnum.ShareConnection) {
2021-07-28 16:13:29 +07:00
}
2021-08-09 00:41:52 +07:00
if (page === PageEnum.Wizard) {
2021-09-08 14:23:02 +03:00
WizardLogic.radioButtonMediumChecked = true
2021-07-28 16:13:29 +07:00
}
2021-08-09 00:41:52 +07:00
if (page === PageEnum.WizardHigh) {
2021-09-08 14:23:02 +03:00
WizardLogic.updatePage();
2021-07-28 16:13:29 +07:00
}
2021-08-09 00:41:52 +07:00
if (page === PageEnum.ServerConfiguring) {
2021-09-08 14:23:02 +03:00
ServerConfiguringLogic.progressBarValue = 0;
2021-07-28 16:13:29 +07:00
}
2021-08-09 00:41:52 +07:00
if (page === PageEnum.GeneralSettings) {
2021-09-08 13:52:36 +03:00
GeneralSettingsLogic.updatePage();
2021-07-28 16:13:29 +07:00
}
2021-08-09 00:41:52 +07:00
if (page === PageEnum.ServersList) {
2021-09-08 14:23:02 +03:00
ServerListLogic.updatePage();
2021-07-28 16:13:29 +07:00
}
2021-08-09 00:41:52 +07:00
if (page === PageEnum.Start) {
2021-09-04 12:53:58 +03:00
StartPageLogic.pushButtonBackFromStartVisible = !pageLoader.empty
2021-09-08 14:23:02 +03:00
StartPageLogic.updatePage();
2021-07-28 16:13:29 +07:00
}
2021-08-09 00:41:52 +07:00
if (page === PageEnum.NewServerProtocols) {
2021-09-07 22:11:43 +03:00
NewServerProtocolsLogic.updatePage()
2021-07-28 16:13:29 +07:00
}
2021-09-07 19:26:58 +03:00
if (page === PageEnum.ServerContainers) {
ServerContainersLogic.updateServerContainersPage()
2021-07-28 16:13:29 +07:00
}
2021-08-09 00:41:52 +07:00
if (page === PageEnum.AppSettings) {
2021-09-07 22:11:43 +03:00
AppSettingsLogic.updatePage()
2021-07-28 16:13:29 +07:00
}
2021-08-09 00:41:52 +07:00
if (page === PageEnum.NetworkSettings) {
2021-09-07 22:11:43 +03:00
NetworkSettingsLogic.updatePage()
2021-07-28 16:13:29 +07:00
}
2021-08-09 00:41:52 +07:00
if (page === PageEnum.Sites) {
2021-09-03 20:17:13 +03:00
SitesLogic.updateSitesPage()
2021-07-28 16:13:29 +07:00
}
2021-08-09 00:41:52 +07:00
if (page === PageEnum.Vpn) {
2021-09-07 21:01:56 +03:00
VpnLogic.updateVpnPage()
2021-07-28 16:13:29 +07:00
}
}
if (slide) {
2021-09-14 00:39:07 +03:00
pageLoader.push(pages[page], {}, StackView.PushTransition)
2021-07-28 16:13:29 +07:00
} else {
2021-09-14 00:39:07 +03:00
pageLoader.push(pages[page], {}, StackView.Immediate)
2021-07-28 16:13:29 +07:00
}
}
function close_page() {
if (pageLoader.depth <= 1) {
return
}
pageLoader.pop()
}
function set_start_page(page, slide) {
pageLoader.clear()
if (slide) {
2021-09-14 00:39:07 +03:00
pageLoader.push(pages[page], {}, StackView.PushTransition)
2021-07-28 16:13:29 +07:00
} else {
2021-09-14 00:39:07 +03:00
pageLoader.push(pages[page], {}, StackView.Immediate)
2021-07-28 16:13:29 +07:00
}
2021-08-09 00:41:52 +07:00
if (page === PageEnum.Start) {
2021-07-28 16:13:29 +07:00
UiLogic.pushButtonBackFromStartVisible = !pageLoader.empty
2021-09-08 14:23:02 +03:00
UiLogic.updatePage();
2021-07-28 16:13:29 +07:00
}
}
TitleBar {
id: titleBar
anchors.top: root.top
visible: GC.isDesktop()
DragHandler {
grabPermissions: TapHandler.CanTakeOverFromAnything
onActiveChanged: {
if (active) {
root.startSystemMove();
}
}
target: null
}
onCloseButtonClicked: {
2021-08-09 00:41:52 +07:00
if (UiLogic.currentPageValue === PageEnum.Start ||
UiLogic.currentPageValue === PageEnum.NewServer) {
2021-07-28 16:13:29 +07:00
Qt.quit()
} else {
root.hide()
}
}
}
Rectangle {
y: GC.isDesktop() ? titleBar.height : 0
2021-08-19 01:27:22 +03:00
anchors.fill: parent
2021-07-28 16:13:29 +07:00
color: "white"
}
StackView {
id: pageLoader
y: GC.isDesktop() ? titleBar.height : 0
2021-08-19 01:27:22 +03:00
anchors.fill: parent
2021-09-13 17:36:48 +03:00
focus: true
2021-08-19 01:27:22 +03:00
2021-08-09 00:41:52 +07:00
// initialItem: page_servers
2021-07-28 16:13:29 +07:00
onCurrentItemChanged: {
2021-09-14 00:39:07 +03:00
UiLogic.currentPageValue = currentItem.page
2021-07-28 16:13:29 +07:00
}
2021-09-13 17:36:48 +03:00
Keys.onReleased: {
if (event.key === Qt.Key_Back || event.key === Qt.Key_Escape) {
console.debug("Back button captured")
if (UiLogic.currentPageValue !== PageEnum.VPN &&
UiLogic.currentPageValue !== PageEnum.ServerConfiguring &&
!(UiLogic.currentPageValue === PageEnum.Start && pageLoader.depth < 2)) {
close_page();
}
// TODO: fix
//if (ui->stackedWidget_main->currentWidget()->isEnabled()) {
// closePage();
//}
event.accepted = true
}
}
2021-07-28 16:13:29 +07:00
}
2021-09-14 00:39:07 +03:00
FolderListModel {
id: folderModelPages
folder: "qrc:/ui/qml/Pages/"
nameFilters: ["*.qml"]
showDirs: false
onStatusChanged: if (status == FolderListModel.Ready) {
for (var i=0; i<folderModelPages.count; i++) {
createPagesObjects(folderModelPages.get(i, "filePath"));
}
UiLogic.initalizeUiLogic()
}
2021-07-28 16:13:29 +07:00
}
2021-09-14 00:39:07 +03:00
FolderListModel {
id: folderModelProtocols
folder: "qrc:/ui/qml/Pages/Protocols/"
nameFilters: ["*.qml"]
showDirs: false
onStatusChanged: if (status == FolderListModel.Ready) {
for (var i=0; i<folderModelProtocols.count; i++) {
createPagesObjects(folderModelProtocols.get(i, "filePath"));
}
}
2021-07-28 16:13:29 +07:00
}
2021-09-14 00:39:07 +03:00
function createPagesObjects(file) {
var c = Qt.createComponent("qrc" + file);
var finishCreation = function (component){
if (component.status == Component.Ready) {
var obj = component.createObject(root);
if (obj == null) {
console.debug("Error creating object " + component.url);
}
else {
obj.visible = false
pages[obj.page] = obj
}
} else if (component.status == Component.Error) {
console.debug("Error loading component:", component.errorString());
}
}
var lambdaFunc = function(){
finishCreation(c)
}
if (c.status == Component.Ready)
finishCreation(c);
else {
console.debug("Warning: Pages components are not ready");
c.statusChanged.connect(lambdaFunc);
}
}
2021-07-28 16:13:29 +07:00
Connections {
target: UiLogic
onGoToPage: {
root.gotoPage(page, reset, slide)
}
onClosePage: {
root.close_page()
}
onSetStartPage: {
root.set_start_page(page, slide)
}
2021-08-09 00:41:52 +07:00
onShowPublicKeyWarning: {
publicKeyWarning.visible = true
}
onShowConnectErrorDialog: {
connectErrorDialog.visible = true
}
onShow: {
root.show()
}
onHide: {
root.hide()
}
2021-07-28 16:13:29 +07:00
}
MessageDialog {
id: closePrompt
// x: (root.width - width) / 2
// y: (root.height - height) / 2
title: qsTr("Exit")
text: qsTr("Do you really want to quit?")
standardButtons: StandardButton.Yes | StandardButton.No
onYes: {
Qt.quit()
}
visible: false
}
SystemTrayIcon {
visible: true
icon.source: UiLogic.trayIconUrl
onActivated: {
if (Qt.platform.os == "osx" ||
Qt.platform.os == "linux") {
if (reason === SystemTrayIcon.DoubleClick ||
reason === SystemTrayIcon.Trigger) {
root.show()
root.raise()
root.requestActivate()
}
}
}
menu: Menu {
MenuItem {
iconSource: "qrc:/images/tray/application.png"
text: qsTr("Show") + " " + "AmneziaVPN"
onTriggered: {
root.show()
root.raise()
}
}
MenuSeparator { }
MenuItem {
text: qsTr("Connect")
enabled: UiLogic.trayActionConnectEnabled
onTriggered: {
UiLogic.onConnect()
}
}
MenuItem {
text: qsTr("Disconnect")
enabled: UiLogic.trayActionDisconnectEnabled
onTriggered: {
UiLogic.onDisconnect()
}
}
MenuSeparator { }
MenuItem {
iconSource: "qrc:/images/tray/link.png"
text: qsTr("Visit Website")
onTriggered: {
Qt.openUrlExternally("https://amnezia.org")
}
}
MenuItem {
iconSource: "qrc:/images/tray/cancel.png"
text: qsTr("Quit") + " " + "AmneziaVPN"
onTriggered: {
closePrompt.open()
}
}
}
}
2021-08-09 00:41:52 +07:00
MessageDialog {
id: publicKeyWarning
title: "AmneziaVPN"
text: qsTr("It's public key. Private key required")
visible: false
}
MessageDialog {
id: connectErrorDialog
title: "AmneziaVPN"
text: UiLogic.dialogConnectErrorText
visible: false
}
2021-07-28 16:13:29 +07:00
}