From 40883549414e47d38a1eaeaa701e3e977e265fd0 Mon Sep 17 00:00:00 2001 From: Cyril Anisimov Date: Sun, 3 Nov 2024 17:48:51 +0100 Subject: [PATCH] refactor page logging settings for focus navigation --- client/ui/qml/Pages2/PageSettingsLogging.qml | 278 ++++++++----------- 1 file changed, 122 insertions(+), 156 deletions(-) diff --git a/client/ui/qml/Pages2/PageSettingsLogging.qml b/client/ui/qml/Pages2/PageSettingsLogging.qml index 33074dfae..4b2d7d42d 100644 --- a/client/ui/qml/Pages2/PageSettingsLogging.qml +++ b/client/ui/qml/Pages2/PageSettingsLogging.qml @@ -23,30 +23,122 @@ PageType { anchors.left: parent.left anchors.right: parent.right anchors.topMargin: 20 + } - onFocusChanged: { - console.debug("MOVE THIS LOGIC TO CPP!") - if (activeFocus) { - if (fl) { - fl.ensureVisible(this) - } + QtObject { + id: clientLogs + + property string title: qsTr("Client logs") + property string description: qsTr("AmneziaVPN logs") + property bool isVisible: true + property var openLogsHandler: function() { + SettingsController.openLogsFolder() + } + property var exportLogsHandler: function() { + var fileName = "" + if (GC.isMobile()) { + fileName = "AmneziaVPN.log" + } else { + fileName = SystemController.getFileName(qsTr("Save"), + qsTr("Logs files (*.log)"), + StandardPaths.standardLocations(StandardPaths.DocumentsLocation) + "/AmneziaVPN", + true, + ".log") + } + if (fileName !== "") { + PageController.showBusyIndicator(true) + SettingsController.exportLogsFile(fileName) + PageController.showBusyIndicator(false) + PageController.showNotificationMessage(qsTr("Logs file saved")) } } } - FlickableType { - id: fl + QtObject { + id: serviceLogs + + property string title: qsTr("Service logs") + property string description: qsTr("AmneziaVPN-service logs") + property bool isVisible: !GC.isMobile() + property var openLogsHandler: function() { + SettingsController.openServiceLogsFolder() + } + property var exportLogsHandler: function() { + var fileName = "" + if (GC.isMobile()) { + fileName = "AmneziaVPN-service.log" + } else { + fileName = SystemController.getFileName(qsTr("Save"), + qsTr("Logs files (*.log)"), + StandardPaths.standardLocations(StandardPaths.DocumentsLocation) + "/AmneziaVPN-service", + true, + ".log") + } + if (fileName !== "") { + PageController.showBusyIndicator(true) + SettingsController.exportServiceLogsFile(fileName) + PageController.showBusyIndicator(false) + PageController.showNotificationMessage(qsTr("Logs file saved")) + } + } + } + + property list logTypes: [ + clientLogs, + serviceLogs + ] + + ListView { + id: listView anchors.top: backButton.bottom anchors.bottom: parent.bottom - contentHeight: content.height + anchors.right: parent.right + anchors.left: parent.left + + property bool isFocusable: true + + Keys.onTabPressed: { + FocusController.nextKeyTabItem() + } + + Keys.onBacktabPressed: { + FocusController.previousKeyTabItem() + } + + Keys.onUpPressed: { + FocusController.nextKeyUpItem() + } + + Keys.onDownPressed: { + FocusController.nextKeyDownItem() + } + + Keys.onLeftPressed: { + FocusController.nextKeyLeftItem() + } + + Keys.onRightPressed: { + FocusController.nextKeyRightItem() + } + + ScrollBar.vertical: ScrollBar { + policy: ScrollBar.AsNeeded + } + + model: logTypes + spacing: 24 + snapMode: ListView.SnapOneItem + + reuseItems: true + + clip: true - ColumnLayout { - id: content + header: ColumnLayout { + id: headerContent + + width: listView.width - anchors.top: parent.top - anchors.left: parent.left - anchors.right: parent.right spacing: 0 HeaderType { @@ -76,14 +168,11 @@ PageType { SettingsController.isLoggingEnabled = checked } } - - parentFlickable: fl } DividerType {} LabelWithButtonType { - // id: labelWithButton2 Layout.fillWidth: true Layout.topMargin: -8 @@ -101,125 +190,47 @@ PageType { SettingsController.clearLogs() PageController.showBusyIndicator(false) PageController.showNotificationMessage(qsTr("Logs have been cleaned up")) - if (!GC.isMobile()) { - focusItem.forceActiveFocus() - } } + var noButtonFunction = function() { - // if (!GC.isMobile()) { - // focusItem.forceActiveFocus() - // } + } showQuestionDrawer(headerText, "", yesButtonText, noButtonText, yesButtonFunction, noButtonFunction) } } + } - ListItemTitleType { - Layout.fillWidth: true - Layout.topMargin: 8 - Layout.leftMargin: 16 - Layout.rightMargin: 16 - - text: qsTr("Client logs") - } - - ParagraphTextType { - Layout.fillWidth: true - Layout.topMargin: 8 - Layout.leftMargin: 16 - Layout.rightMargin: 16 - - color: AmneziaStyle.color.mutedGray - text: qsTr("AmneziaVPN logs") - } - - LabelWithButtonType { - // id: labelWithButton2 - Layout.fillWidth: true - Layout.topMargin: -8 - Layout.bottomMargin: -8 - - text: qsTr("Open logs folder") - leftImageSource: "qrc:/images/controls/folder-open.svg" - isSmallLeftImage: true - - clickedFunction: function() { - SettingsController.openLogsFolder() - } - } - - DividerType {} - - LabelWithButtonType { - // id: labelWithButton2 - Layout.fillWidth: true - Layout.topMargin: -8 - Layout.bottomMargin: -8 - - text: qsTr("Export logs") - leftImageSource: "qrc:/images/controls/save.svg" - isSmallLeftImage: true + delegate: ColumnLayout { + id: delegateContent - onFocusChanged: { - console.debug("MOVE THIS LOGIC TO CPP!") - if (activeFocus) { - if (fl) { - fl.ensureVisible(this) - } - } - } + width: listView.width - clickedFunction: function() { - var fileName = "" - if (GC.isMobile()) { - fileName = "AmneziaVPN.log" - } else { - fileName = SystemController.getFileName(qsTr("Save"), - qsTr("Logs files (*.log)"), - StandardPaths.standardLocations(StandardPaths.DocumentsLocation) + "/AmneziaVPN", - true, - ".log") - } - if (fileName !== "") { - PageController.showBusyIndicator(true) - SettingsController.exportLogsFile(fileName) - PageController.showBusyIndicator(false) - PageController.showNotificationMessage(qsTr("Logs file saved")) - } - } - } + spacing: 0 - DividerType {} + visible: isVisible ListItemTitleType { - visible: !GC.isMobile() - Layout.fillWidth: true - Layout.topMargin: 32 + Layout.topMargin: 8 Layout.leftMargin: 16 Layout.rightMargin: 16 - text: qsTr("Service logs") + text: title } ParagraphTextType { - visible: !GC.isMobile() - Layout.fillWidth: true Layout.topMargin: 8 Layout.leftMargin: 16 Layout.rightMargin: 16 color: AmneziaStyle.color.mutedGray - text: qsTr("AmneziaVPN-service logs") + + text: description } LabelWithButtonType { - // id: labelWithButton2 - - visible: !GC.isMobile() - Layout.fillWidth: true Layout.topMargin: -8 Layout.bottomMargin: -8 @@ -228,29 +239,12 @@ PageType { leftImageSource: "qrc:/images/controls/folder-open.svg" isSmallLeftImage: true - onFocusChanged: { - console.debug("MOVE THIS LOGIC TO CPP!") - if (activeFocus) { - if (fl) { - fl.ensureVisible(this) - } - } - } - - clickedFunction: function() { - SettingsController.openServiceLogsFolder() - } + clickedFunction: openLogsHandler } - DividerType { - visible: !GC.isMobile() - } + DividerType {} LabelWithButtonType { - // id: labelWithButton2 - - visible: !GC.isMobile() - Layout.fillWidth: true Layout.topMargin: -8 Layout.bottomMargin: -8 @@ -259,38 +253,10 @@ PageType { leftImageSource: "qrc:/images/controls/save.svg" isSmallLeftImage: true - onFocusChanged: { - console.debug("MOVE THIS LOGIC TO CPP!") - if (activeFocus) { - if (fl) { - fl.ensureVisible(this) - } - } - } - - clickedFunction: function() { - var fileName = "" - if (GC.isMobile()) { - fileName = "AmneziaVPN-service.log" - } else { - fileName = SystemController.getFileName(qsTr("Save"), - qsTr("Logs files (*.log)"), - StandardPaths.standardLocations(StandardPaths.DocumentsLocation) + "/AmneziaVPN-service", - true, - ".log") - } - if (fileName !== "") { - PageController.showBusyIndicator(true) - SettingsController.exportServiceLogsFile(fileName) - PageController.showBusyIndicator(false) - PageController.showNotificationMessage(qsTr("Logs file saved")) - } - } + clickedFunction: exportLogsHandler } - DividerType { - visible: !GC.isMobile() - } + DividerType {} } } }