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

0001 /*
0002  * SPDX-FileCopyrightText: 2020 Arjen Hiemstra <ahiemstra@heimr.nl>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005  */
0006 
0007 import QtQuick
0008 import QtQuick.Controls
0009 import QtQuick.Layouts
0010 
0011 
0012 import org.kde.kirigami as Kirigami
0013 import org.kde.newstuff as NewStuff
0014 
0015 import org.kde.ksysguard.faces as Faces
0016 import org.kde.ksysguard.page
0017 
0018 Kirigami.ScrollablePage {
0019     id: page
0020 
0021     property FaceLoader loader
0022 
0023     property int activeSection: 0
0024 
0025     title: i18nc("@title:window %1 is face name", "Configure %1", loader.controller.title)
0026 
0027     Kirigami.ColumnView.fillWidth: false
0028 
0029     actions: [
0030         Kirigami.Action {
0031             icon.name: "dialog-close"
0032             text: i18nc("@action", "Close")
0033             onTriggered: applicationWindow().pageStack.pop()
0034 
0035             displayHint: Kirigami.DisplayHint.KeepVisible
0036         },
0037 
0038         Kirigami.Action {
0039             text: i18nc("@action", "Load Preset…")
0040             icon.name: "document-new-from-template"
0041             onTriggered: loadPresetDialog.open()
0042         },
0043 
0044         NewStuff.Action {
0045             text: i18nc("@action", "Get new presets…")
0046             configFile: "systemmonitor-presets.knsrc"
0047             pageStack: applicationWindow().pageStack.layers
0048             onEntryEvent: (entry, event) => {
0049                 if (event == NewStuff.Engine.StatusChangedEvent) {
0050                     Qt.callLater(loader.controller.availablePresetsModel.reload)
0051                 }
0052             }
0053         },
0054 
0055         Kirigami.Action {
0056             text: i18nc("@action", "Save Settings as Preset")
0057             icon.name: "document-save-as-template"
0058             onTriggered: {
0059                 loader.controller.savePreset()
0060                 message.text = i18nc("@info:status %1 is preset name", "Saved settings as preset %1.", loader.controller.title)
0061                 message.visible = true
0062             }
0063         },
0064 
0065         Kirigami.Action {
0066             text: i18nc("@action", "Add Chart as Desktop Widget")
0067             icon.name: "document-export"
0068             enabled: WidgetExporter.plasmashellAvailable
0069             onTriggered: {
0070                 WidgetExporter.exportAsWidget(loader)
0071             }
0072         },
0073 
0074         Kirigami.Action { separator: true },
0075 
0076         NewStuff.Action {
0077             text: i18nc("@action", "Get new display styles…")
0078             configFile: "systemmonitor-faces.knsrc"
0079             pageStack: applicationWindow().pageStack.layers
0080             onEntryEvent: (entry, event) => {
0081                 if (event == NewStuff.Engine.StatusChangedEvent) {
0082                     Qt.callLater(loader.controller.availableFacesModel.reload)
0083                 }
0084             }
0085         }
0086     ]
0087 
0088     DialogLoader {
0089         id: loadPresetDialog
0090         sourceComponent: LoadPresetDialog {
0091 
0092             controller: loader.controller
0093 
0094             onAccepted: {
0095                 loader.controller.title = selectedTitle;
0096                 if (selectedFace) {
0097                     loader.controller.faceId = selectedFace
0098                 }
0099                 loader.controller.loadPreset(selectedPreset);
0100                 message.text = i18nc("@info:status %1 is preset name", "Loaded preset %1.", selectedTitle);
0101                 message.visible = true
0102             }
0103         }
0104     }
0105 
0106     ColumnLayout {
0107         id: layout
0108 
0109         Kirigami.InlineMessage {
0110             id: message
0111             Layout.fillWidth: true
0112             showCloseButton: true
0113         }
0114 
0115         Label {
0116             Layout.fillWidth: true
0117             text: i18nc("@label:textbox", "Title")
0118 
0119             CheckBox {
0120                 id: showTitleCheckbox
0121                 anchors.right: parent.right
0122                 anchors.verticalCenter: parent.verticalCenter
0123                 text: i18nc("@option:check", "Show Title")
0124                 checked: page.loader.controller.showTitle
0125                 onToggled: page.loader.controller.showTitle = checked
0126             }
0127         }
0128 
0129         TextField {
0130             id: titleField
0131 
0132             text: page.loader.controller.title
0133 
0134             Layout.fillWidth: true
0135 
0136             onTextEdited: page.loader.controller.title = text
0137         }
0138 
0139         Label {
0140             Layout.fillWidth: true
0141             text: i18nc("@label:textbox", "Display Style")
0142         }
0143 
0144         ComboBox {
0145             id: faceCombo
0146 
0147             property string faceId: page.loader.controller.faceId
0148 
0149             model: page.loader.controller.availableFacesModel
0150             textRole: "display"
0151             currentIndex: {
0152                 // TODO just make an indexOf invokable on the model?
0153                 for (var i = 0; i < count; ++i) {
0154                     if (model.pluginId(i) === faceId) {
0155                         return i;
0156                     }
0157                 }
0158                 return -1;
0159             }
0160             onActivated: (index) => {
0161                 page.loader.controller.faceId = model.pluginId(index);
0162             }
0163 
0164             Layout.fillWidth: true
0165         }
0166 
0167         Label {
0168             Layout.fillWidth: true
0169             text: i18nc("@label", "Minimum time between updates:")
0170         }
0171 
0172         SpinBox {
0173             id: updateRateLimitSpinBox
0174 
0175             Layout.fillWidth: true
0176 
0177             from: 0
0178             to: 600000
0179             stepSize: 500
0180             editable: true
0181 
0182             value: page.loader.controller.updateRateLimit
0183 
0184             textFromValue: function(value, locale) {
0185                 if (value <= 0) {
0186                     return i18n("No Limit");
0187                 } else {
0188                     var seconds = value / 1000;
0189                     if (seconds == 1) { // Manual plural handling because i18ndp doesn't handle floats :(
0190                         return i18n("1 second");
0191                     } else {
0192                         return i18n("%1 seconds", seconds);
0193                     }
0194                 }
0195             }
0196             valueFromText: function(value, locale) {
0197                 // Don't use fromLocaleString here since it will error out on extra
0198                 // characters like the (potentially translated) seconds that gets
0199                 // added above. Instead parseInt ignores non-numeric characters.
0200                 var v = parseInt(value)
0201                 if (isNaN(v)) {
0202                     return 0;
0203                 } else {
0204                     return v * 1000;
0205                 }
0206             }
0207 
0208             onValueModified: page.loader.controller.updateRateLimit = value
0209         }
0210 
0211         Item {
0212             id: configContainer
0213 
0214             Layout.fillWidth: true
0215             implicitHeight: children.length > 0 ? children[0].implicitHeight : 0
0216 
0217             children: loader.controller.faceConfigUi
0218 
0219             Connections {
0220                 target: loader.controller.faceConfigUi
0221 
0222                 function onConfigurationChanged() {
0223                     loader.controller.faceConfigUi.saveConfig()
0224                     loader.dataObject.markDirty()
0225                 }
0226             }
0227 
0228             Binding {
0229                 target: configContainer.children[0]
0230                 property: "width"
0231                 value: configContainer.width
0232             }
0233         }
0234 
0235         Item {
0236             id: sensorsContainer
0237 
0238             Layout.fillWidth: true
0239             implicitHeight: children.length > 0 ? children[0].implicitHeight : 0
0240 
0241             children: loader.controller.sensorsConfigUi
0242 
0243             Connections {
0244                 target: loader.controller.sensorsConfigUi
0245 
0246                 function onConfigurationChanged() {
0247                     loader.controller.sensorsConfigUi.saveConfig()
0248                     loader.dataObject.markDirty()
0249                 }
0250             }
0251 
0252             Binding {
0253                 target: sensorsContainer.children[0]
0254                 property: "width"
0255                 value: sensorsContainer.width
0256             }
0257         }
0258 
0259         Item { Layout.fillHeight: true; width: 1 }
0260     }
0261 }