Skip to content

Commit

Permalink
refactor page logging settings for focus navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
CyAn84 committed Nov 3, 2024
1 parent e300f84 commit 4088354
Showing 1 changed file with 122 additions and 156 deletions.
278 changes: 122 additions & 156 deletions client/ui/qml/Pages2/PageSettingsLogging.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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<QtObject> 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 {
Expand Down Expand Up @@ -76,14 +168,11 @@ PageType {
SettingsController.isLoggingEnabled = checked
}
}

parentFlickable: fl
}

DividerType {}

LabelWithButtonType {
// id: labelWithButton2
Layout.fillWidth: true
Layout.topMargin: -8

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 {}
}
}
}

0 comments on commit 4088354

Please sign in to comment.