Warning, /plasma-mobile/plasma-dialer/plasma-dialer/src/qml/USSDSheet.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2021 Alexey Andreyev <aa13q@ya.ru>
0002 //
0003 // SPDX-License-Identifier: LicenseRef-KDE-Accepted-GPL
0004 
0005 import QtQuick
0006 import QtQuick.Controls as Controls
0007 import QtQuick.Layouts
0008 
0009 import org.kde.kirigami as Kirigami
0010 
0011 Kirigami.OverlaySheet {
0012 
0013     id: ussdSheet
0014 
0015     property bool isError: false
0016     property string messageText: ""
0017     property bool replyRequested: false
0018 
0019     signal responseReady(string response)
0020     signal cancelSessionRequested()
0021 
0022     function showNotification(text) {
0023         isError = false
0024         ussdSheet.messageText = text
0025     }
0026 
0027     function changeState(state) {
0028         ussdSheet.replyRequested = (state=="user-response")
0029         
0030         if (ussdSheet.replyRequested) {
0031             responseField.setFocus()          
0032         }
0033     }
0034 
0035     function showError(errorMessage) {
0036         isError = true
0037         ussdSheet.messageText = errorMessage
0038     }
0039 
0040     function onSheetOpenChanged() {
0041         if (!ussdSheet.sheetOpen) {
0042             ussdSheet.messageText = ""
0043         }
0044     }
0045 
0046     header: Kirigami.Heading {
0047         text: isError ? i18n("USSD Error") : i18n("USSD Message")
0048     }
0049 
0050     footer: Loader {
0051         Component {
0052             id: responseFieldComponent
0053             Kirigami.ActionTextField {
0054                 id: responseField
0055                 visible: ussdSheet.replyRequested
0056                 placeholderText: i18n("Write response...")
0057                 inputMethodHints: Qt.ImhPreferNumbers
0058                 onAccepted: text !== "" && sendAction.triggered()
0059                 rightActions: [
0060                     Kirigami.Action {
0061                         id: sendAction
0062                         text: i18n("Send")
0063                         icon.name: "document-send"
0064                         enabled: responseField.text !== ""
0065                         onTriggered: {
0066                             ussdSheet.responseReady(responseField.text)
0067                             responseField.text = ""
0068                         }
0069                     }
0070                 ]
0071             }
0072         }
0073 
0074         Component {
0075             id: cancelButtonComponent
0076             Controls.Button {
0077                 icon.name: "dialog-close"
0078                 text: i18n("Cancel USSD session")
0079                 onClicked: {
0080                     ussdSheet.cancelSessionRequested()
0081                     ussdSheet.close()
0082                 }
0083             }
0084         }
0085 
0086         sourceComponent: ussdSheet.isError ? cancelButtonComponent : responseFieldComponent
0087     }
0088 
0089     Controls.BusyIndicator {
0090         anchors.centerIn: columnLayout
0091         width: Kirigami.Units.gridUnit * 2
0092         height: width
0093         visible: (ussdSheet.messageText === "")
0094     }
0095 
0096     ColumnLayout {
0097         id: columnLayout
0098         spacing: Kirigami.Units.largeSpacing * 5
0099         Layout.fillWidth: true
0100 
0101         Controls.Label {
0102             Layout.fillWidth: true
0103             wrapMode: Text.WordWrap
0104             text: ussdSheet.messageText
0105         }
0106     }
0107 }