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 banner { 0084 title: model.display 0085 titleIcon: model.decoration 0086 titleLevel: 3 0087 } 0088 checkable: true 0089 checked: model.checked === Qt.Checked 0090 nodeId: waylandItem.nodeId 0091 0092 TaskManager.ScreencastingRequest { 0093 id: waylandItem 0094 outputName: delegate.model.name 0095 } 0096 0097 onToggled: { 0098 const to = model.checked !== Qt.Checked ? Qt.Checked : Qt.Unchecked; 0099 if (!root.multiple && to === Qt.Checked) { 0100 root.clearSelection() 0101 } 0102 outputsView.model.setData(outputsView.model.index(model.row, 0), to, Qt.CheckStateRole) 0103 } 0104 0105 // double clicking always means selecting only the clicked item and confirming 0106 onDoubleClicked: { 0107 root.clearSelection() 0108 outputsView.model.setData(outputsView.model.index(model.row, 0), Qt.Checked, Qt.CheckStateRole) 0109 dialogButtonBox.accepted() 0110 } 0111 } 0112 } 0113 } 0114 } 0115 QQC2.ScrollView { 0116 contentWidth: availableWidth 0117 contentHeight: windowsLayout.height 0118 Kirigami.CardsLayout { 0119 id: windowsLayout 0120 anchors { 0121 left: parent.left; 0122 right: parent.right; 0123 } 0124 Repeater { 0125 id: windowsView 0126 model: null 0127 PipeWireDelegate { 0128 id: delegate 0129 0130 required property int index 0131 required property var model 0132 0133 banner { 0134 title: model.display ?? "" 0135 titleIcon: model.decoration ?? "" 0136 titleLevel: 3 0137 } 0138 checkable: true 0139 checked: model.checked === Qt.Checked 0140 nodeId: waylandItem.nodeId 0141 0142 TaskManager.ScreencastingRequest { 0143 id: waylandItem 0144 uuid: delegate.model.Uuid 0145 } 0146 0147 onToggled: { 0148 const to = model.checked !== Qt.Checked ? Qt.Checked : Qt.Unchecked; 0149 if (!root.multiple && to === Qt.Checked) { 0150 root.clearSelection() 0151 } 0152 windowsView.model.setData(windowsView.model.index(model.row, 0), to, Qt.CheckStateRole) 0153 } 0154 0155 // double clicking always means selecting only the clicked item and confirming 0156 onDoubleClicked: { 0157 root.clearSelection() 0158 windowsView.model.setData(windowsView.model.index(model.row, 0), Qt.Checked, Qt.CheckStateRole) 0159 dialogButtonBox.accepted() 0160 } 0161 } 0162 } 0163 } 0164 } 0165 } 0166 } 0167 0168 QQC2.CheckBox { 0169 id: allowRestoreItem 0170 checked: true 0171 text: i18n("Allow restoring on future sessions") 0172 } 0173 } 0174 0175 standardButtons: QQC2.DialogButtonBox.Ok | QQC2.DialogButtonBox.Cancel 0176 0177 Component.onCompleted: { 0178 dialogButtonBox.standardButton(QQC2.DialogButtonBox.Ok).text = i18n("Share") 0179 0180 // If there's only one thing in the list, pre-select it to save the user a click 0181 if (outputsView.count === 1 && windowsView.count === 0) { 0182 outputsView.model.setData(outputsView.model.index(0, 0), Qt.Checked, Qt.CheckStateRole); 0183 } else if (windowsView.count === 1 && outputsView.count === 0) { 0184 windowsView.model.setData(outputsView.model.index(0, 0), Qt.Checked, Qt.CheckStateRole); 0185 } 0186 } 0187 }