Warning, /plasma/plasma-systemmonitor/src/page/MissingSensorsDialog.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  * SPDX-FileCopyrightText: 2022 Arjen Hiemstra <ahiemstra@heimr.nl>
0003  * SPDX-FileCopyrightText: 2023 Nate Graham <nate@kde.org>
0004  *
0005  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006  */
0007 
0008 import QtQuick
0009 import QtQuick.Controls
0010 import QtQuick.Layouts
0011 
0012 import org.kde.kirigami as Kirigami
0013 
0014 import org.kde.ksysguard.page
0015 import org.kde.ksysguard.faces as Faces
0016 
0017 Kirigami.Dialog {
0018     id: dialog
0019 
0020     property var missingSensors: { }
0021     property var sensorReplacement: { }
0022 
0023     title: i18nc("@title", "Replace Missing Sensors")
0024 
0025     preferredWidth: Kirigami.Units.gridUnit * 30
0026     preferredHeight: Kirigami.Units.gridUnit * 30
0027 
0028     focus: true
0029 
0030     // We already have a cancel button in the footer
0031     showCloseButton: false
0032 
0033     standardButtons: Dialog.Save | Dialog.Cancel
0034 
0035     onAccepted: {
0036         let result = []
0037 
0038         for (let i = 0; i < sensorsModel.count; ++i) {
0039             let entry = sensorsModel.get(i)
0040             if (!entry.replacement) {
0041                 continue
0042             }
0043 
0044             result.push({
0045                 "face": entry.face,
0046                 "sensor": entry.sensor,
0047                 "replacement": entry.replacement
0048             })
0049         }
0050 
0051         sensorReplacement = result
0052     }
0053 
0054     onMissingSensorsChanged: {
0055         sensorsModel.clear();
0056         missingSensors.sort((first, second) => first.title.localeCompare(second.title))
0057         for (let entry of missingSensors) {
0058             entry.replacement = ""
0059             sensorsModel.append(entry)
0060         }
0061     }
0062 
0063     ListView {
0064         model: ListModel { id: sensorsModel }
0065 
0066         section.property: "title"
0067         section.delegate: Kirigami.ListSectionHeader {
0068             required property string section
0069             label: section
0070         }
0071 
0072         clip: true
0073 
0074         delegate: ItemDelegate {
0075             id: delegate
0076 
0077             width: ListView.view.width
0078 
0079             text: model.sensor
0080 
0081             contentItem: RowLayout {
0082                 spacing: Kirigami.Units.smallSpacing
0083 
0084                 Label {
0085                     Layout.fillWidth: true
0086                     text: delegate.text
0087                     textFormat: Text.MarkdownText
0088                 }
0089 
0090                 Faces.Choices {
0091                     Layout.preferredWidth: delegate.width * 0.5
0092 
0093                     supportsColors: false
0094                     maxAllowedSensors: 1
0095                     labelsEditable: false
0096                     labels: { }
0097 
0098                     onSelectedChanged: {
0099                         if (selected.length > 0) {
0100                             sensorsModel.setProperty(index, "replacement", selected[0])
0101                         }
0102                     }
0103                 }
0104             }
0105         }
0106     }
0107 }
0108