Warning, /plasma-bigscreen/plasma-remotecontrollers/kcm/ui/main.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2020 Aditya Mehra <aix.m@outlook.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 
0006 */
0007 
0008 import QtQuick.Layouts 1.14
0009 import QtQuick 2.14
0010 import QtQuick.Window 2.14
0011 import QtQuick.Controls 2.14
0012 import org.kde.kirigami 2.20 as Kirigami
0013 import org.kde.plasma.components 3.0 as PlasmaComponents
0014 import org.kde.kcmutils as KCM
0015 import org.kde.private.kcm.remotecontrollers 1.0
0016 import "delegates" as Delegates
0017 
0018 KCM.ScrollViewKCM {
0019     id: root
0020     title: i18n("Remote Controllers")
0021 
0022     Component.onCompleted: {
0023         connectionView.forceActiveFocus();
0024     }
0025     
0026     Connections {
0027         target: kcm.devicesModel
0028 
0029         function onDevicesChanged() {
0030             if(connectionView.count > 0) {
0031                 deviceSetupView.deviceName = connectionView.model.get(connectionView.currentIndex).deviceName
0032                 deviceSetupView.deviceIcon = connectionView.model.get(connectionView.currentIndex).deviceIconName
0033                 deviceSetupView.deviceType = connectionView.model.get(connectionView.currentIndex).deviceType
0034             }
0035         }
0036     }
0037 
0038     ColumnLayout {
0039         width: parent.width
0040         height: parent.height
0041 
0042         Kirigami.FormLayout {
0043             Layout.fillWidth: true
0044             Layout.preferredHeight: connectionView.implicitHeight
0045             
0046             ComboBox {
0047                 id: connectionView
0048                 focus: true
0049                 model:  kcm.devicesModel
0050                 Layout.alignment: Qt.AlignTop
0051                 Layout.preferredHeight: Kirigami.Units.gridUnit * 4
0052                 Kirigami.FormData.label: i18n("Device:")
0053                 textRole: "deviceName"
0054                 visible: connectionView.count > 0 ? 1 : 0
0055                 delegate: Delegates.DeviceDelegate{}
0056 
0057                 Keys.onDownPressed: {
0058                     if(!connectionView.popup.opened) {
0059                         deviceSetupView.forceActiveFocus();
0060                     }
0061                 }
0062 
0063                 Behavior on x {
0064                     NumberAnimation {
0065                         duration: Kirigami.Units.longDuration * 2
0066                         easing.type: Easing.InOutQuad
0067                     }
0068                 }
0069 
0070                 Component.onCompleted: connectionView.currentIndex = 0
0071                 onCountChanged: connectionView.currentIndex = 0
0072                 onCurrentIndexChanged: {
0073                     if(connectionView.currentIndex > -1) {
0074                         deviceSetupView.deviceName = connectionView.model.get(connectionView.currentIndex).deviceName
0075                         deviceSetupView.deviceIcon = connectionView.model.get(connectionView.currentIndex).deviceIconName
0076                         deviceSetupView.deviceType = connectionView.model.get(connectionView.currentIndex).deviceType
0077                     }
0078                 }
0079             }
0080         }
0081 
0082         DeviceSetupView {
0083             id: deviceSetupView
0084             visible: connectionView.count > 0 ? 1 : 0
0085             Layout.fillWidth: true                
0086             Layout.fillHeight: true
0087         }
0088 
0089         Item {
0090             id: noViewAvailable
0091             visible: connectionView.count == 0 ? 1 : 0
0092 
0093             Kirigami.Heading {
0094                 text: i18n("No remote controllers available.")
0095                 horizontalAlignment: Text.AlignHCenter
0096                 verticalAlignment: Text.AlignVCenter
0097                 level: 2
0098                 Layout.fillWidth: true
0099                 Layout.fillHeight: true
0100             }
0101         }
0102     }
0103 
0104     Popup {
0105         id: keySetupPopUp
0106         x: (parent.width - width)  / 2
0107         y: (parent.height - height) / 2
0108         width: parent.width * 0.70
0109         height: parent.height * 0.10
0110         property var keyType
0111 
0112         function keyCodeRecieved(keyCode) {
0113             kcm.setCecKeyConfig(keyType[1], keyCode)
0114             keySetupPopUp.close()
0115         }
0116 
0117         onOpened: {
0118             kcm.acquireNoOp()
0119             var getCecKey = kcm.cecKeyFromRemotePress()
0120             keyCodeRecieved(getCecKey)
0121         }
0122 
0123         onClosed: {
0124             kcm.releaseNoOp()
0125         }
0126 
0127         contentItem: Item {
0128             anchors.fill: parent
0129 
0130             PlasmaComponents.Label {
0131                 anchors.centerIn: parent
0132                 text: i18n("Select Key On Your TV Remote For %1", (keySetupPopUp.keyType ? keySetupPopUp.keyType[0] : ""))
0133             }
0134         }
0135     }
0136 
0137     Popup {
0138         id: keySetupGamepadPopUp
0139         x: (parent.width - width)  / 2
0140         y: (parent.height - height) / 2
0141         width: parent.width * 0.70
0142         height: parent.height * 0.10
0143         property var keyType
0144 
0145         onOpened: {
0146             kcm.setNoop()
0147         }
0148 
0149         onClosed: {
0150             kcm.releaseNoOp()
0151         }
0152 
0153         Connections {
0154             target: kcm
0155             function onGamepadKeyPressed(keyCode) {
0156                 if(keySetupGamepadPopUp.opened) {
0157                     if(kcm.gamepadKeyConfig("ButtonEnter") == keyCode) {
0158                         deviceSetupView.ignoreEvent = true       
0159                     }
0160                     kcm.setGamepadKeyConfig(keySetupGamepadPopUp.keyType[1], keyCode)
0161                     keySetupGamepadPopUp.close()
0162                 }
0163             }
0164         }
0165 
0166         contentItem: Item {
0167             anchors.fill: parent
0168 
0169             PlasmaComponents.Label {
0170                 anchors.centerIn: parent
0171                 text: i18n("Select Key On Your Gamepad For %1", (keySetupGamepadPopUp.keyType ? keySetupGamepadPopUp.keyType[0] : ""))
0172             }
0173         }
0174     }
0175 }