Warning, /utilities/fielding/src/ui/Main.qml is written in an unsupported language. File is not indexed.
0001 // SPDX-FileCopyrightText: 2022 Felipe Kinoshita <kinofhek@gmail.com>
0002 // SPDX-License-Identifier: GPL-3.0-or-later
0003
0004 import QtQuick 2.15
0005 import QtQuick.Controls 2.15 as QQC2
0006 import QtQuick.Layouts 1.15
0007 import org.kde.kirigami 2.19 as Kirigami
0008 import org.kde.syntaxhighlighting 1.0
0009
0010 import org.kde.fielding
0011 import org.kde.fielding.config
0012
0013 Kirigami.ApplicationWindow {
0014 id: root
0015
0016 title: i18n("Fielding")
0017
0018 width: Kirigami.Units.gridUnit * 42
0019 height: Kirigami.Units.gridUnit * 32
0020 minimumWidth: Kirigami.Units.gridUnit * 20
0021 minimumHeight: Kirigami.Units.gridUnit * 20
0022
0023 Timer {
0024 id: saveWindowGeometryTimer
0025 interval: 1000
0026 onTriggered: App.saveWindowGeometry(root)
0027 }
0028
0029 Connections {
0030 id: saveWindowGeometryConnections
0031 enabled: false // Disable on startup to avoid writing wrong values if the window is hidden
0032 target: root
0033
0034 function onClosing() { App.saveWindowGeometry(root) }
0035 function onWidthChanged() { saveWindowGeometryTimer.restart() }
0036 function onHeightChanged() { saveWindowGeometryTimer.restart() }
0037 function onXChanged() { saveWindowGeometryTimer.restart() }
0038 function onYChanged() { saveWindowGeometryTimer.restart() }
0039 }
0040
0041 Loader {
0042 active: !Kirigami.Settings.isMobile
0043 source: Qt.resolvedUrl("GlobalMenu.qml")
0044 }
0045
0046 pageStack.initialPage: Kirigami.Page {
0047 id: page
0048
0049 padding: 0
0050 titleDelegate: PageHeader {}
0051
0052 QQC2.SplitView {
0053 anchors.fill: parent
0054
0055 handle: Rectangle {
0056 implicitWidth: Kirigami.Units.largeSpacing
0057 implicitHeight: Kirigami.Units.largeSpacing
0058 color: Kirigami.Theme.backgroundColor
0059
0060 Kirigami.Separator {
0061 anchors.top: parent.top
0062 anchors.bottom: parent.bottom
0063 anchors.left: parent.left
0064 }
0065
0066 Kirigami.Separator {
0067 anchors.top: parent.top
0068 anchors.bottom: parent.bottom
0069 anchors.right: parent.right
0070 }
0071 }
0072
0073 QQC2.ScrollView {
0074 QQC2.SplitView.minimumWidth: Kirigami.Units.gridUnit * 10
0075 QQC2.SplitView.preferredWidth: Kirigami.Units.gridUnit * 17
0076 QQC2.SplitView.fillHeight: true
0077
0078 QQC2.TextArea {
0079 id: bodyTextArea
0080
0081 wrapMode: Text.Wrap
0082
0083 onEditingFinished: {
0084 if (text.length > 0) {
0085 Controller.setData(JSON.parse(text))
0086 }
0087 }
0088
0089 placeholderText: i18n("Request body...")
0090
0091 background: Rectangle {
0092 Kirigami.Theme.colorSet: Kirigami.Theme.View
0093 Kirigami.Theme.inherit: false
0094 color: Kirigami.Theme.backgroundColor
0095 }
0096
0097 Kirigami.SpellCheck.enabled: false
0098
0099 SyntaxHighlighter {
0100 textEdit: bodyTextArea
0101 definition: "JSON"
0102 }
0103 }
0104 }
0105
0106 QQC2.ScrollView {
0107 QQC2.SplitView.fillWidth: true
0108 QQC2.SplitView.fillHeight: true
0109 QQC2.SplitView.minimumWidth: Kirigami.Units.gridUnit * 10
0110
0111 QQC2.TextArea {
0112 id: responseTextArea
0113
0114 wrapMode: Text.Wrap
0115
0116 readOnly: true
0117
0118 background: Rectangle {
0119 Kirigami.Theme.colorSet: Kirigami.Theme.View
0120 Kirigami.Theme.inherit: false
0121 color: Kirigami.Theme.backgroundColor
0122
0123 Kirigami.PlaceholderMessage {
0124 anchors.centerIn: parent
0125 visible: responseTextArea.text.length <= 0
0126 width: parent.width - Kirigami.Units.largeSpacing * 4
0127 text: i18n("No Response Yet")
0128 explanation: i18n("Your request response will appear here")
0129 }
0130 }
0131
0132 SyntaxHighlighter {
0133 textEdit: responseTextArea
0134 definition: "JSON"
0135 }
0136
0137 Connections {
0138 target: Controller
0139
0140 function onResponse(response) {
0141 responseTextArea.text = response
0142 }
0143 }
0144 }
0145 }
0146 }
0147
0148 footer: QQC2.ToolBar {
0149 implicitHeight: content.implicitHeight + Kirigami.Units.smallSpacing * 2
0150 position: QQC2.ToolBar.Footer
0151
0152 RowLayout {
0153 id: content
0154 anchors.fill: parent
0155
0156 QQC2.Label {
0157 id: statusLabel
0158 Layout.alignment: Qt.AlignLeft
0159 visible: false
0160 text: i18n("Status: ")
0161 }
0162 QQC2.Label {
0163 id: statusLabelCodeText
0164 Layout.alignment: Qt.AlignLeft
0165 }
0166
0167 Item {
0168 Layout.fillWidth: true
0169 }
0170
0171 Connections {
0172 target: Controller
0173
0174 function onStatus(statusCode, statusText) {
0175 statusLabelCodeText.text = `${statusCode} ${statusText}`
0176 statusLabel.visible = true
0177
0178 if (statusCode >= 100 && statusCode <= 199) {
0179 statusLabelCodeText.color = Kirigami.Theme.disabledTextColor
0180 } else if (statusCode >= 200 && statusCode <= 299) {
0181 statusLabelCodeText.color = Kirigami.Theme.positiveTextColor
0182 } else if (statusCode >= 300 && statusCode <= 399) {
0183 statusLabelCodeText.color = Kirigami.Theme.linkColor
0184 } else if (statusCode >= 400 && statusCode <= 499) {
0185 statusLabelCodeText.color = Kirigami.Theme.negativeTextColor
0186 } else if (statusCode >= 500 && statusCode <= 599) {
0187 statusLabelCodeText.color = Kirigami.Theme.neutralTextColor
0188 } else {
0189 statusLabelCodeText.color = Kirigami.Theme.textColor
0190 }
0191 }
0192 }
0193 }
0194 }
0195 }
0196
0197 Component.onCompleted: {
0198 if (!Kirigami.Settings.isMobile) {
0199 saveWindowGeometryConnections.enabled = true
0200 }
0201 }
0202 }