Warning, /plasma/xdg-desktop-portal-kde/src/ScreenChooserDialog.qml is written in an unsupported language. File is not indexed.

0001 /*  This file is part of the KDE project
0002     SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez <aleixpol@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 pragma ComponentBehavior: Bound
0008 
0009 import QtQuick
0010 import QtQuick.Layouts
0011 import QtQuick.Controls as QQC2
0012 import org.kde.kirigami as Kirigami
0013 import org.kde.plasma.workspace.dialogs as PWD
0014 import org.kde.taskmanager 0.1 as TaskManager
0015 
0016 PWD.SystemDialog {
0017     id: root
0018 
0019     property alias outputsModel: outputsView.model
0020     property alias windowsModel: windowsView.model
0021     property bool multiple: false
0022     property alias allowRestore: allowRestoreItem.checked
0023 
0024     iconName: "video-display"
0025     acceptable: (outputsModel && outputsModel.hasSelection) || (windowsModel && windowsModel.hasSelection)
0026 
0027     signal clearSelection()
0028 
0029     ColumnLayout {
0030         spacing: 0
0031 
0032         QQC2.TabBar {
0033             id: tabView
0034             Layout.fillWidth: true
0035             visible: root.outputsModel && root.windowsModel
0036             currentIndex: outputsView.count > 0 ? 0 : 1
0037 
0038             QQC2.TabButton {
0039                 text: i18n("Screens")
0040             }
0041             QQC2.TabButton {
0042                 text: i18n("Windows")
0043             }
0044         }
0045 
0046         QQC2.Frame {
0047             Layout.fillWidth: true
0048             Layout.fillHeight: true
0049             Layout.preferredHeight: Kirigami.Units.gridUnit * 20
0050             Layout.preferredWidth: Kirigami.Units.gridUnit * 30
0051 
0052             Kirigami.Theme.inherit: false
0053             Kirigami.Theme.colorSet: Kirigami.Theme.View
0054 
0055             background: Rectangle {
0056                 color: Kirigami.Theme.backgroundColor
0057                 border.color: Qt.alpha(Kirigami.Theme.textColor, 0.3)
0058                 border.width: 1
0059             }
0060 
0061             StackLayout {
0062                 anchors.fill: parent
0063                 currentIndex: tabView.currentIndex
0064 
0065                 QQC2.ScrollView {
0066                     contentWidth: availableWidth
0067                     contentHeight: outputsLayout.height
0068                     Kirigami.CardsLayout {
0069                         id: outputsLayout
0070                         anchors {
0071                             left: parent.left;
0072                             right: parent.right;
0073                         }
0074                         Repeater {
0075                             id: outputsView
0076                             model: null
0077                             PipeWireDelegate {
0078                                 id: delegate
0079 
0080                                 required property int index
0081                                 required property var model
0082 
0083                                 function selectAndAccept(): void {
0084                                     root.clearSelection()
0085                                     outputsView.model.setData(outputsView.model.index(model.row, 0), Qt.Checked, Qt.CheckStateRole)
0086                                     dialogButtonBox.accepted()
0087                                 }
0088 
0089                                 banner {
0090                                     title: model.display
0091                                     titleIcon: model.decoration
0092                                     titleLevel: 3
0093                                 }
0094                                 checkable: root.multiple
0095                                 checked: model.checked === Qt.Checked
0096                                 nodeId: waylandItem.nodeId
0097 
0098                                 TaskManager.ScreencastingRequest {
0099                                     id: waylandItem
0100                                     outputName: delegate.model.name
0101                                 }
0102 
0103                                 // Only active if this is a multi-select dialog
0104                                 onToggled: {
0105                                     const to = model.checked !== Qt.Checked ? Qt.Checked : Qt.Unchecked;
0106                                     outputsView.model.setData(outputsView.model.index(model.row, 0), to, Qt.CheckStateRole)
0107                                 }
0108 
0109                                 // If this is isn't a multi-select dialog, accept on click
0110                                 // since the cards are functioning as buttons
0111                                 onClicked: {
0112                                     if (!root.multiple) {
0113                                         selectAndAccept()
0114                                     }
0115                                 }
0116 
0117                                 // If this is a multi-select dialog, let people choose just
0118                                 // one thing quickly by double-clicking
0119                                 onDoubleClicked: {
0120                                     if (root.multiple) {
0121                                         selectAndAccept()
0122                                     }
0123                                 }
0124                             }
0125                         }
0126                     }
0127                 }
0128                 QQC2.ScrollView {
0129                     contentWidth: availableWidth
0130                     contentHeight: windowsLayout.height
0131                     Kirigami.CardsLayout {
0132                         id: windowsLayout
0133                         anchors {
0134                             left: parent.left;
0135                             right: parent.right;
0136                         }
0137                         Repeater {
0138                             id: windowsView
0139                             model: null
0140                             PipeWireDelegate {
0141                                 id: delegate
0142 
0143                                 required property int index
0144                                 required property var model
0145 
0146                                 function selectAndAccept(): void {
0147                                     root.clearSelection()
0148                                     windowsView.model.setData(windowsView.model.index(model.row, 0), Qt.Checked, Qt.CheckStateRole)
0149                                     dialogButtonBox.accepted()
0150                                 }
0151 
0152                                 banner {
0153                                     title: model.display ?? ""
0154                                     titleIcon: model.decoration ?? ""
0155                                     titleLevel: 3
0156                                 }
0157                                 checkable: root.multiple
0158                                 checked: model.checked === Qt.Checked
0159                                 nodeId: waylandItem.nodeId
0160 
0161                                 TaskManager.ScreencastingRequest {
0162                                     id: waylandItem
0163                                     uuid: delegate.model.Uuid
0164                                 }
0165 
0166                                 // Only active if this is a multi-select dialog
0167                                 onToggled: {
0168                                     const to = model.checked !== Qt.Checked ? Qt.Checked : Qt.Unchecked;
0169                                     windowsView.model.setData(windowsView.model.index(model.row, 0), to, Qt.CheckStateRole)
0170                                 }
0171 
0172                                 // If this is isn't a multi-select dialog, accept on click
0173                                 // since the cards are functioning as buttons
0174                                 onClicked: {
0175                                     if (!root.multiple) {
0176                                         selectAndAccept()
0177                                     }
0178                                 }
0179 
0180                                 // If this is a multi-select dialog, let people choose just
0181                                 // one thing quickly by double-clicking
0182                                 onDoubleClicked: {
0183                                     if (root.multiple) {
0184                                         selectAndAccept()
0185                                     }
0186                                 }
0187                             }
0188                         }
0189                     }
0190                 }
0191             }
0192         }
0193 
0194         QQC2.CheckBox {
0195             id: allowRestoreItem
0196             checked: true
0197             text: i18n("Allow restoring on future sessions")
0198         }
0199     }
0200 
0201     standardButtons: root.multiple ? QQC2.DialogButtonBox.Ok | QQC2.DialogButtonBox.Cancel: null
0202 
0203     Component.onCompleted: {
0204         if (root.multiple) {
0205             dialogButtonBox.standardButton(QQC2.DialogButtonBox.Ok).text = i18n("Share")
0206         }
0207 
0208         // If there's only one thing in the list, pre-select it to save the user a click
0209         if (outputsView.count === 1 && windowsView.count === 0) {
0210             outputsView.model.setData(outputsView.model.index(0, 0), Qt.Checked, Qt.CheckStateRole);
0211         } else if (windowsView.count === 1 && outputsView.count === 0) {
0212             windowsView.model.setData(outputsView.model.index(0, 0), Qt.Checked, Qt.CheckStateRole);
0213         }
0214     }
0215 }